當前位置: 首頁>>代碼示例>>Java>>正文


Java RSyntaxTextArea.getCaret方法代碼示例

本文整理匯總了Java中org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.getCaret方法的典型用法代碼示例。如果您正苦於以下問題:Java RSyntaxTextArea.getCaret方法的具體用法?Java RSyntaxTextArea.getCaret怎麽用?Java RSyntaxTextArea.getCaret使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.fife.ui.rsyntaxtextarea.RSyntaxTextArea的用法示例。


在下文中一共展示了RSyntaxTextArea.getCaret方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e) {

			RSyntaxTextArea textArea = (RSyntaxTextArea)getTextComponent(e);
			RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
			Caret c = textArea.getCaret();

			int dot = c.getDot(); // Get before "<" insertion
			boolean selection = dot!=c.getMark(); // Me too
			textArea.replaceSelection(">");

			// Don't automatically complete a tag if there was a selection
			if (!selection && getAutoAddClosingTags()) {

				Token t = doc.getTokenListForLine(textArea.getCaretLineNumber());
				t = RSyntaxUtilities.getTokenAtOffset(t, dot);
				if (t!=null && t.isSingleChar(Token.MARKUP_TAG_DELIMITER, '>')) {
					String tagName = discoverTagName(doc, dot);
					if (tagName!=null) {
						textArea.replaceSelection("</" + tagName + ">");
						textArea.setCaretPosition(dot+1);
					}
				}

			}

		}
 
開發者ID:pyros2097,項目名稱:GdxStudio,代碼行數:27,代碼來源:AbstractMarkupLanguageSupport.java

示例2: invoke

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
/**
 * Invokes this code template.  The changes are made to the given text
 * area.
 *
 * @param textArea The text area to operate on.
 * @throws BadLocationException If something bad happens.
 */
public void invoke(RSyntaxTextArea textArea) throws BadLocationException {

	Caret c = textArea.getCaret();
	int dot = c.getDot();
	int mark = c.getMark();
	int p0 = Math.min(dot, mark);
	int p1 = Math.max(dot, mark);
	RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
	Element map = doc.getDefaultRootElement();

	int lineNum = map.getElementIndex(dot);
	Element line = map.getElement(lineNum);
	int start = line.getStartOffset();
	int end = line.getEndOffset()-1; // Why always "-1"?
	String s = textArea.getText(start,end-start);
	int len = s.length();

	// endWS is the end of the leading whitespace
	// of the current line.
	int endWS = 0;
	while (endWS<len && RSyntaxUtilities.isWhitespace(s.charAt(endWS))) {
		endWS++;
	}
	s = s.substring(0, endWS);
	p0 -= getID().length();
	String beforeText = getBeforeTextIndented(s);
	String afterText = getAfterTextIndented(s);
	doc.replace(p0,p1-p0, beforeText+afterText, null);
	textArea.setCaretPosition(p0+beforeText.length());

}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:39,代碼來源:StaticCodeTemplate.java

示例3: invoke

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
/**
 * Invokes this code template. The changes are made to the given text area.
 * 
 * @param textArea
 *            The text area to operate on.
 * @throws BadLocationException
 *             If something bad happens.
 */
public void invoke(RSyntaxTextArea textArea) throws BadLocationException {

    Caret c = textArea.getCaret();
    int dot = c.getDot();
    int mark = c.getMark();
    int p0 = Math.min(dot, mark);
    int p1 = Math.max(dot, mark);
    RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
    Element map = doc.getDefaultRootElement();

    int lineNum = map.getElementIndex(dot);
    Element line = map.getElement(lineNum);
    int start = line.getStartOffset();
    int end = line.getEndOffset() - 1; // Why always "-1"?
    String s = textArea.getText(start, end - start);
    int len = s.length();

    // endWS is the end of the leading whitespace
    // of the current line.
    int endWS = 0;
    while (endWS < len && RSyntaxUtilities.isWhitespace(s.charAt(endWS))) {
        endWS++;
    }
    s = s.substring(0, endWS);
    p0 -= getID().length();
    String beforeText = getBeforeTextIndented(s);
    String afterText = getAfterTextIndented(s);
    doc.replace(p0, p1 - p0, beforeText + afterText, null);
    textArea.setCaretPosition(p0 + beforeText.length());

}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:40,代碼來源:StaticCodeTemplate.java


注:本文中的org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.getCaret方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。