本文整理汇总了Java中org.fife.ui.rtextarea.RTextArea.getLineOfOffset方法的典型用法代码示例。如果您正苦于以下问题:Java RTextArea.getLineOfOffset方法的具体用法?Java RTextArea.getLineOfOffset怎么用?Java RTextArea.getLineOfOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fife.ui.rtextarea.RTextArea
的用法示例。
在下文中一共展示了RTextArea.getLineOfOffset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWordStart
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
protected int getWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs==start) {
return start;
}
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--;
}
doc.getText(start, end-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs-start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
char nextCh = offs==end ? 0 : seg.array[seg.getIndex() + 1];
// The "word" is a group of letters and/or digits
int languageIndex = 0; // TODO
if (doc.isIdentifierChar(languageIndex, ch)) {
if (offs!=end && !doc.isIdentifierChar(languageIndex, nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// The "word" is whitespace
else if (Character.isWhitespace(ch)) {
if (offs!=end && !Character.isWhitespace(nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" a single "something else" char (operator,
// etc.).
offs -= firstIndex - seg.getIndex() + 1;//seg.getEndIndex() - seg.getIndex();
if (ch!=Segment.DONE && nextCh!='\n') {
offs++;
}
return offs;
}
示例2: getPreviousWordStart
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
protected int getPreviousWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs==start) {
return start-1; // Just delete the newline
}
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--;
}
doc.getText(start, end-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs-start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
// Always strip off whitespace first
if (Character.isWhitespace(ch)) {
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// The "word" is a group of letters and/or digits
int languageIndex = 0; // TODO
if (doc.isIdentifierChar(languageIndex, ch)) {
do {
ch = seg.previous();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// The "word" is a series of symbols.
else {
while (!Character.isWhitespace(ch) &&
!doc.isIdentifierChar(languageIndex, ch)
&& ch!=Segment.DONE) {
ch = seg.previous();
}
}
if (ch==Segment.DONE) {
return start; // Removed last "token" of the line
}
offs -= firstIndex - seg.getIndex();
return offs;
}
示例3: getWordEnd
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
protected int getWordEnd(RTextArea textArea, int offs)
throws BadLocationException {
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
if (offs==doc.getLength()) {
return offs;
}
int line = textArea.getLineOfOffset(offs);
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--; // Hide newline
}
if (offs==end) {
return end;
}
doc.getText(offs, end-offs, seg);
// Determine the "type" of char at offs - letter/digit,
// whitespace or other
char ch = seg.first();
// The "word" is a group of letters and/or digits
int languageIndex = 0; // TODO
if (doc.isIdentifierChar(languageIndex, ch)) {
do {
ch = seg.next();
} while (doc.isIdentifierChar(languageIndex, ch));
}
// The "word" is whitespace.
else if (Character.isWhitespace(ch)) {
do {
ch = seg.next();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" is a single character of some other type
// (operator, etc.).
offs += seg.getIndex() - seg.getBeginIndex();
return offs;
}
示例4: getWordStart
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
protected int getWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs == 0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs == start) {
return start;
}
int end = textArea.getLineEndOffset(line);
if (line != textArea.getLineCount() - 1) {
end--;
}
doc.getText(start, end - start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs - start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
char nextCh = offs == end ? 0 : seg.array[seg.getIndex() + 1];
// The "word" is a group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
if (offs != end && !Character.isLetterOrDigit(nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (Character.isLetterOrDigit(ch));
}
// The "word" is whitespace
else if (Character.isWhitespace(ch)) {
if (offs != end && !Character.isWhitespace(nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" a single "something else" char (operator,
// etc.).
offs -= firstIndex - seg.getIndex() + 1;// seg.getEndIndex() - seg.getIndex();
if (ch != Segment.DONE && nextCh != '\n') {
offs++;
}
return offs;
}
示例5: getWordEnd
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
protected int getWordEnd(RTextArea textArea, int offs)
throws BadLocationException {
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
if (offs == doc.getLength()) {
return offs;
}
int line = textArea.getLineOfOffset(offs);
int end = textArea.getLineEndOffset(line);
if (line != textArea.getLineCount() - 1) {
end--; // Hide newline
}
if (offs == end) {
return end;
}
doc.getText(offs, end - offs, seg);
// Determine the "type" of char at offs - letter/digit,
// whitespace or other
char ch = seg.first();
// The "word" is a group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
do {
ch = seg.next();
} while (Character.isLetterOrDigit(ch));
}
// The "word" is whitespace.
else if (Character.isWhitespace(ch)) {
do {
ch = seg.next();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" is a single character of some other type
// (operator, etc.).
offs += seg.getIndex() - seg.getBeginIndex();
return offs;
}
示例6: getNextWord
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
/**
* Overridden to do better with skipping "words" in code.
*/
protected int getNextWord(RTextArea textArea, int offs)
throws BadLocationException {
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
if (offs == doc.getLength()) {
return offs;
}
int line = textArea.getLineOfOffset(offs);
int end = textArea.getLineEndOffset(line);
if (offs == end) {
return offs + 1; // Start of next line.
}
doc.getText(offs, end - offs, seg);
// Determine the "type" of char at offs - letter/digit,
// whitespace or other
char ch = seg.first();
// Skip the group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
do {
ch = seg.next();
} while (Character.isLetterOrDigit(ch));
}
// Skip groups of "anything else" (operators, etc.).
else if (!Character.isWhitespace(ch)) {
do {
ch = seg.next();
} while (ch != Segment.DONE &&
!(Character.isLetterOrDigit(ch) ||
Character.isWhitespace(ch)));
}
// Skip any trailing whitespace
while (Character.isWhitespace(ch)) {
ch = seg.next();
}
offs += seg.getIndex() - seg.getBeginIndex();
return offs;
}
示例7: getPreviousWord
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
/**
* Overridden to do better with skipping "words" in code.
*/
protected int getPreviousWord(RTextArea textArea, int offs)
throws BadLocationException {
if (offs == 0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs == start) {
return start - 1; // End of previous line.
}
doc.getText(start, offs - start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other
char ch = seg.last();
// Skip any "leading" whitespace
while (Character.isWhitespace(ch)) {
ch = seg.previous();
}
// Skip the group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
do {
ch = seg.previous();
} while (Character.isLetterOrDigit(ch));
}
// Skip groups of "anything else" (operators, etc.).
else if (!Character.isWhitespace(ch)) {
do {
ch = seg.previous();
} while (ch != Segment.DONE &&
!(Character.isLetterOrDigit(ch) ||
Character.isWhitespace(ch)));
}
offs -= seg.getEndIndex() - seg.getIndex();
if (ch != Segment.DONE) {
offs++;
}
return offs;
}
示例8: find
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
private int find(Result result, Pattern pattern, Result prev, boolean startFromTopOfFile) throws BadLocationException
{
int startPos;
RTextArea textArea;
String searchText;
if (selectionOnlyRadioButton.isSelected())
{
result.fileId = MAIN_GUI.tabPane.getSelectedIndex() == 0 ? -1 : MAIN_GUI.includeFiles.getSelectedIndex();
textArea = getTextAreaFromFileId(result.fileId);
startPos = prev != null && prev.fileId == result.fileId ? prev.endPos : startFromTopOfFile ? 0 : textArea.getSelectionStart();
if (startPos >= textArea.getSelectionEnd()) return 0;
searchText = textArea.getText(startPos, textArea.getSelectionEnd() - startPos);
}
else
{
textArea = getTextAreaFromFileId(result.fileId);
startPos = prev != null && prev.fileId == result.fileId ? prev.endPos : startFromTopOfFile ? 0 : textArea.getSelectionStart();
searchText = textArea.getText(startPos, textArea.getDocument().getLength() - startPos);
}
if (pattern != null)
{
Matcher matcher = pattern.matcher(searchText);
if (!matcher.find()) return -1;
result.findText = matcher.group();
result.startPos = matcher.start() + startPos;
result.endPos = matcher.end() + startPos;
result.lineNr = textArea.getLineOfOffset(result.startPos);
return 1;
}
else
{
int index;
result.findText = String.valueOf(findBox.getEditor().getItem());
if (!ignoreCaseCheckBox.isSelected()) index = searchText.indexOf(result.findText);
else index = searchText.toLowerCase().indexOf(result.findText.toLowerCase());
if (index == -1) return -1;
result.startPos = startPos + index;
result.endPos = result.startPos + result.findText.length();
result.lineNr = textArea.getLineOfOffset(result.startPos);
return 1;
}
}
示例9: getWordStart
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
protected int getWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs==start) {
return start;
}
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--;
}
doc.getText(start, end-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs-start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
char nextCh = offs==end ? 0 : seg.array[seg.getIndex() + 1];
// The "word" is a group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
if (offs!=end && !Character.isLetterOrDigit(nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (Character.isLetterOrDigit(ch));
}
// The "word" is whitespace
else if (Character.isWhitespace(ch)) {
if (offs!=end && !Character.isWhitespace(nextCh)) {
return offs;
}
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" a single "something else" char (operator,
// etc.).
offs -= firstIndex - seg.getIndex() + 1;//seg.getEndIndex() - seg.getIndex();
if (ch!=Segment.DONE && nextCh!='\n') {
offs++;
}
return offs;
}
示例10: getPreviousWordStart
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
protected int getPreviousWordStart(RTextArea textArea, int offs)
throws BadLocationException {
if (offs==0) {
return offs;
}
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
int line = textArea.getLineOfOffset(offs);
int start = textArea.getLineStartOffset(line);
if (offs==start) {
return start-1; // Just delete the newline
}
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--;
}
doc.getText(start, end-start, seg);
// Determine the "type" of char at offs - lower case, upper case,
// whitespace or other. We take special care here as we're starting
// in the middle of the Segment to check whether we're already at
// the "beginning" of a word.
int firstIndex = seg.getBeginIndex() + (offs-start) - 1;
seg.setIndex(firstIndex);
char ch = seg.current();
// Always strip off whitespace first
if (Character.isWhitespace(ch)) {
do {
ch = seg.previous();
} while (Character.isWhitespace(ch));
}
// The "word" is a group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
do {
ch = seg.previous();
} while (Character.isLetterOrDigit(ch));
}
// The "word" is a series of symbols.
else {
while (!Character.isWhitespace(ch) &&
!Character.isLetterOrDigit(ch)
&& ch!=Segment.DONE) {
ch = seg.previous();
}
}
if (ch==Segment.DONE) {
return start; // Removed last "token" of the line
}
offs -= firstIndex - seg.getIndex();
return offs;
}
示例11: getWordEnd
import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
protected int getWordEnd(RTextArea textArea, int offs)
throws BadLocationException {
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
if (offs==doc.getLength()) {
return offs;
}
int line = textArea.getLineOfOffset(offs);
int end = textArea.getLineEndOffset(line);
if (line!=textArea.getLineCount()-1) {
end--; // Hide newline
}
if (offs==end) {
return end;
}
doc.getText(offs, end-offs, seg);
// Determine the "type" of char at offs - letter/digit,
// whitespace or other
char ch = seg.first();
// The "word" is a group of letters and/or digits
if (Character.isLetterOrDigit(ch)) {
do {
ch = seg.next();
} while (Character.isLetterOrDigit(ch));
}
// The "word" is whitespace.
else if (Character.isWhitespace(ch)) {
do {
ch = seg.next();
} while (Character.isWhitespace(ch));
}
// Otherwise, the "word" is a single character of some other type
// (operator, etc.).
offs += seg.getIndex() - seg.getBeginIndex();
return offs;
}