本文整理匯總了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);
}
}
}
}
示例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());
}
示例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());
}