当前位置: 首页>>代码示例>>Java>>正文


Java RTextArea.getLineOfOffset方法代码示例

本文整理汇总了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;

}
 
开发者ID:curiosag,项目名称:ftc,代码行数:62,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:curiosag,项目名称:ftc,代码行数:60,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:curiosag,项目名称:ftc,代码行数:47,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:intuit,项目名称:Tank,代码行数:60,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:intuit,项目名称:Tank,代码行数:45,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:intuit,项目名称:Tank,代码行数:48,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:intuit,项目名称:Tank,代码行数:52,代码来源:RSyntaxTextAreaEditorKit.java

示例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;
    }
}
 
开发者ID:dries007,项目名称:j8051,代码行数:43,代码来源:FindAndReplace.java

示例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;

}
 
开发者ID:Nanonid,项目名称:RSyntaxTextArea,代码行数:60,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:Nanonid,项目名称:RSyntaxTextArea,代码行数:58,代码来源:RSyntaxTextAreaEditorKit.java

示例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;

}
 
开发者ID:Nanonid,项目名称:RSyntaxTextArea,代码行数:45,代码来源:RSyntaxTextAreaEditorKit.java


注:本文中的org.fife.ui.rtextarea.RTextArea.getLineOfOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。