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


Java RTextArea.getDocument方法代码示例

本文整理汇总了Java中org.fife.ui.rtextarea.RTextArea.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java RTextArea.getDocument方法的具体用法?Java RTextArea.getDocument怎么用?Java RTextArea.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.fife.ui.rtextarea.RTextArea的用法示例。


在下文中一共展示了RTextArea.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getWordEnd

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
protected int getWordEnd(RTextArea textArea, int offs)
		throws BadLocationException {

	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = root.getElementIndex(offs);
	Element elem = root.getElement(line);
	int end = elem.getEndOffset() - 1;

	int wordEnd = offs;
	while (wordEnd <= end) {
		if (!isIdentifierChar(doc.charAt(wordEnd))) {
			break;
		}
		wordEnd++;
	}

	return wordEnd;

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

示例2: getPreviousWord

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
protected int getPreviousWord(RTextArea textArea, int offs)
		throws BadLocationException {

	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = root.getElementIndex(offs);
	Element elem = root.getElement(line);

	// If caret is at the beginning of a word, we should return the
	// previous word
	int start = elem.getStartOffset();
	if (offs > start) {
		char ch = doc.charAt(offs);
		if (isIdentifierChar(ch)) {
			offs--;
		}
	}
	else { // offs == start => previous word is on previous line
		if (line == 0) {
			return -1;
		}
		elem = root.getElement(--line);
		offs = elem.getEndOffset() - 1;
	}

	int prevWordStart = getPreviousWordStartInLine(doc, elem, offs);
	while (prevWordStart == -1 && line > 0) {
		line--;
		elem = root.getElement(line);
		prevWordStart = getPreviousWordStartInLine(doc, elem,
				elem.getEndOffset());
	}

	return prevWordStart;

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

示例3: getWordStart

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
protected int getWordStart(RTextArea textArea, int offs)
		throws BadLocationException {
	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = root.getElementIndex(offs);
	Element elem = root.getElement(line);
	return getWordStartImpl(doc, elem, offs);
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:10,代码来源:RSyntaxTextAreaEditorKit.java

示例4: 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

示例5: actionPerformedImpl

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

	if (!textArea.isEditable() || !textArea.isEnabled()) {
		UIManager.getLookAndFeel().provideErrorFeedback(textArea);
		return;
	}

	Document document = textArea.getDocument();
	Element map = document.getDefaultRootElement();
	Caret c = textArea.getCaret();
	int dot = c.getDot();
	int mark = c.getMark();
	int dotLine = map.getElementIndex(dot);
	int markLine = map.getElementIndex(mark);

	// If there is a multi-line selection, indent all lines in
	// the selection.
	if (dotLine!=markLine) {
		int first = Math.min(dotLine, markLine);
		int last = Math.max(dotLine, markLine);
		Element elem; int start;

		// Since we're using Document.insertString(), we must mimic the
		// soft tab behavior provided by RTextArea.replaceSelection().
		String replacement = "\t";
		if (textArea.getTabsEmulated()) {
			StringBuilder sb = new StringBuilder();
			int temp = textArea.getTabSize();
			for (int i=0; i<temp; i++) {
				sb.append(' ');
			}
			replacement = sb.toString();
		}

		textArea.beginAtomicEdit();
		try {
			for (int i=first; i<last; i++) {
				elem = map.getElement(i);
				start = elem.getStartOffset();
				document.insertString(start, replacement, null);
			}
			// Don't do the last line if the caret is at its
			// beginning.  We must call getDot() again and not just
			// use 'dot' as the caret's position may have changed
			// due to the insertion of the tabs above.
			elem = map.getElement(last);
			start = elem.getStartOffset();
			if (Math.max(c.getDot(), c.getMark())!=start) {
				document.insertString(start, replacement, null);
			}
		} catch (BadLocationException ble) { // Never happens.
			ble.printStackTrace();
			UIManager.getLookAndFeel().
							provideErrorFeedback(textArea);
		} finally {
			textArea.endAtomicEdit();
		}
	}
	else {
		textArea.replaceSelection("\t");
	}

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

示例6: getNextWord

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
/**
 * Overridden to do better with skipping "words" in code.
 */
@Override
protected int getNextWord(RTextArea textArea, int offs)
							throws BadLocationException {

	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	if (offs==doc.getLength()) {
		return offs;
	}

	Element root = doc.getDefaultRootElement();
	int line = root.getElementIndex(offs);
	int end = root.getElement(line).getEndOffset() - 1;
	if (offs==end) {// If we're already at the end of the line...
		RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
		if (rsta.isCodeFoldingEnabled()) { // Start of next visible line
			FoldManager fm = rsta.getFoldManager();
			int lineCount = root.getElementCount();
			while (++line<lineCount && fm.isLineHidden(line));
			if (line<lineCount) { // Found a lower visible line
				offs = root.getElement(line).getStartOffset();
			}
			// No lower visible line - we're already at last visible offset
			return offs;
		}
		else {
			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
	int languageIndex = 0;
	if (doc.isIdentifierChar(languageIndex, ch)) {
		do {
			ch = seg.next();
		} while (doc.isIdentifierChar(languageIndex, ch));
	}

	// Skip groups of "anything else" (operators, etc.).
	else if (!Character.isWhitespace(ch)) {
		do {
			ch = seg.next();
		} while (ch!=Segment.DONE &&
				!(doc.isIdentifierChar(languageIndex, ch) ||
						Character.isWhitespace(ch)));
	}

	// Skip any trailing whitespace
	while (Character.isWhitespace(ch)) {
		ch = seg.next();
	}

	offs += seg.getIndex() - seg.getBeginIndex();
	return offs;

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

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

示例8: 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

示例9: actionPerformedImpl

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

            if (!textArea.isEditable() || !textArea.isEnabled()) {
                UIManager.getLookAndFeel().provideErrorFeedback(textArea);
                return;
            }

            Document document = textArea.getDocument();
            Element map = document.getDefaultRootElement();
            Caret c = textArea.getCaret();
            int dot = c.getDot();
            int mark = c.getMark();
            int dotLine = map.getElementIndex(dot);
            int markLine = map.getElementIndex(mark);

            // If there is a multiline selection, indent all lines in
            // the selection.
            if (dotLine != markLine) {
                int first = Math.min(dotLine, markLine);
                int last = Math.max(dotLine, markLine);
                Element elem;
                int start;
                try {
                    for (int i = first; i < last; i++) {
                        elem = map.getElement(i);
                        start = elem.getStartOffset();
                        document.insertString(start, "\t", null);
                    }
                    // Don't do the last line if the caret is at its
                    // beginning. We must call getDot() again and not just
                    // use 'dot' as the caret's position may have changed
                    // due to the insertion of the tabs above.
                    elem = map.getElement(last);
                    start = elem.getStartOffset();
                    if (Math.max(c.getDot(), c.getMark()) != start) {
                        document.insertString(start, "\t", null);
                    }
                } catch (BadLocationException ble) { // Never happens.
                    ble.printStackTrace();
                    UIManager.getLookAndFeel().
                            provideErrorFeedback(textArea);
                }
            }
            else {
                textArea.replaceSelection("\t");
            }

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

示例10: 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

示例11: 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

示例12: actionPerformedImpl

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

	if (!textArea.isEditable() || !textArea.isEnabled())
		return;

	RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;

	if (RSyntaxTextArea.getTemplatesEnabled()) {

		Document doc = textArea.getDocument();
		if (doc != null) {

			try {

				CodeTemplateManager manager = RSyntaxTextArea.
									getCodeTemplateManager();
				CodeTemplate template =  manager==null ? null :
											manager.getTemplate(rsta);

				// A non-null template means modify the text to insert!
				if (template!=null) {
					template.invoke(rsta);
				}

				// No template - insert default text.  This is
				// exactly what DefaultKeyTypedAction does.
				else {
					doDefaultInsert(rsta);
				}

			} catch (BadLocationException ble) {
				UIManager.getLookAndFeel().
						provideErrorFeedback(textArea);
			}


		} // End of if (doc!=null).

	} // End of if (textArea.getTemplatesEnabled()).

	// If templates aren't enabled, just insert the text as usual.
	else {
		doDefaultInsert(rsta);
	}

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

示例13: actionPerformedImpl

import org.fife.ui.rtextarea.RTextArea; //导入方法依赖的package包/类
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {

            if (!textArea.isEditable() || !textArea.isEnabled())
                return;

            RSyntaxTextArea rsta = (RSyntaxTextArea) textArea;

            if (RSyntaxTextArea.getTemplatesEnabled()) {

                Document doc = textArea.getDocument();
                if (doc != null) {

                    try {

                        CodeTemplateManager manager = RSyntaxTextArea.
                                getCodeTemplateManager();
                        CodeTemplate template = manager == null ? null :
                                manager.getTemplate(rsta);

                        // A non-null template means modify the text to insert!
                        if (template != null) {
                            template.invoke(rsta);
                        }

                        // No template - insert default text. This is
                        // exactly what DefaultKeyTypedAction does.
                        else {
                            doDefaultInsert(rsta);
                        }

                    } catch (BadLocationException ble) {
                        UIManager.getLookAndFeel().
                                provideErrorFeedback(textArea);
                    }

                } // End of if (doc!=null).

            } // End of if (textArea.getTemplatesEnabled()).

            // If templates aren't enabled, just insert the text as usual.
            else {
                doDefaultInsert(rsta);
            }

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

示例14: 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

示例15: 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


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