本文整理汇总了Java中org.fife.ui.rsyntaxtextarea.RSyntaxUtilities类的典型用法代码示例。如果您正苦于以下问题:Java RSyntaxUtilities类的具体用法?Java RSyntaxUtilities怎么用?Java RSyntaxUtilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RSyntaxUtilities类属于org.fife.ui.rsyntaxtextarea包,在下文中一共展示了RSyntaxUtilities类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的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: getDescription
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
private static String getDescription(BufferedReader r) throws IOException {
StringBuffer desc = new StringBuffer();
String line = null;
while ((line=r.readLine())!=null) {
if (line.startsWith(" *")) {
int nextSpace = line.indexOf(' ', 1);
line = line.substring(nextSpace+1).trim();
desc.append(line).append(' ');
}
else {
break;
}
}
String temp = desc.toString();
if (temp.startsWith("<html>")) {
return temp.substring("<html>".length());
}
return RSyntaxUtilities.escapeForHtml(temp, "<br>", false);
}
开发者ID:bobbylight,项目名称:ZScriptLanguageSupport,代码行数:20,代码来源:CodeCompletionLoader.java
示例3: LineNumberList
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
/**
* Constructs a new <code>LineNumberList</code>.
*
* @param textArea The text component for which line numbers will be
* displayed.
* @param numberColor The color to use for the line numbers. If this is
* <code>null</code>, gray will be used.
*/
public LineNumberList(RTextArea textArea, Color numberColor) {
super(textArea);
if (numberColor!=null) {
setForeground(numberColor);
}
else {
setForeground(Color.GRAY);
}
// Initialize currentLine; otherwise, the current line won't start
// off as highlighted.
currentLine = 0;
setLineNumberingStartIndex(1);
visibleRect = new Rectangle(); // Must be initialized
addMouseListener(this);
addMouseMotionListener(this);
aaHints = RSyntaxUtilities.getDesktopAntiAliasHints();
}
开发者ID:Nanonid,项目名称:RSyntaxTextArea,代码行数:33,代码来源:LineNumberList.java
示例4: paintEnabledText
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
@Override
protected void paintEnabledText(JLabel l, Graphics g, String s,
int textX, int textY) {
XmlTreeCellRenderer r = (XmlTreeCellRenderer)l;
Graphics2D g2d = (Graphics2D)g;
Map<?,?> hints = RSyntaxUtilities.getDesktopAntiAliasHints();
if (hints!=null) {
g2d.addRenderingHints(hints);
}
g2d.setColor(l.getForeground());
g2d.drawString(r.elem, textX, textY);
if (r.attr!=null) {
textX += g2d.getFontMetrics().stringWidth(r.elem + " ");
if (!r.selected) {
g2d.setColor(ATTR_COLOR);
}
g2d.drawString(r.attr, textX, textY);
}
g2d.dispose();
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:21,代码来源:XmlTreeCellRenderer.java
示例5: getReplacementText
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
@Override
protected String getReplacementText(Completion c, Document doc,
int start, int len) {
String replacement = super.getReplacementText(c, doc, start, len);
if(c instanceof JavaScriptShorthandCompletion)
{
try
{
int caret = textArea.getCaretPosition();
String leadingWS = RSyntaxUtilities.getLeadingWhitespace(doc, caret);
if (replacement.indexOf('\n')>-1) {
replacement = replacement.replaceAll("\n", "\n" + leadingWS);
}
}
catch(BadLocationException ble){}
}
return replacement;
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:21,代码来源:JavaScriptLanguageSupport.java
示例6: actionPerformedImpl
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
if (gutter!=null) {
int line = textArea.getCaretLineNumber();
try {
gutter.toggleBookmark(line);
} catch (BadLocationException ble) { // Never happens
UIManager.getLookAndFeel().
provideErrorFeedback(textArea);
ble.printStackTrace();
}
}
}
开发者ID:curiosag,项目名称:ftc,代码行数:15,代码来源:RTextAreaEditorKit.java
示例7: invoke
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的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
示例8: invoke
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的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
示例9: checkStringLiteralMember
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
/**
* Checks whether the user is typing a completion for a String member after
* a String literal.
*
* @param comp The text component.
* @param alreadyEntered The text already entered.
* @param cu The compilation unit being parsed.
* @param set The set to add possible completions to.
* @return Whether the user is indeed typing a completion for a String
* literal member.
*/
private boolean checkStringLiteralMember(JTextComponent comp,
String alreadyEntered,
CompilationUnit cu, Set set) {
boolean stringLiteralMember = false;
int offs = comp.getCaretPosition() - alreadyEntered.length() - 1;
if (offs>1) {
RSyntaxTextArea textArea = (RSyntaxTextArea)comp;
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
try {
//System.out.println(doc.charAt(offs) + ", " + doc.charAt(offs+1));
if (doc.charAt(offs)=='"' && doc.charAt(offs+1)=='.') {
int curLine = textArea.getLineOfOffset(offs);
Token list = textArea.getTokenListForLine(curLine);
Token prevToken = RSyntaxUtilities.getTokenAtOffset(list, offs);
if (prevToken!=null &&
prevToken.getType()==Token.LITERAL_STRING_DOUBLE_QUOTE) {
ClassFile cf = getClassFileFor(cu, "java.lang.String");
addCompletionsForExtendedClass(set, cu, cf,
cu.getPackageName(), null);
stringLiteralMember = true;
}
else {
System.out.println(prevToken);
}
}
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
}
return stringLiteralMember;
}
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:47,代码来源:SourceCompletionProvider.java
示例10: filter
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
/**
* Filters visible tree nodes based on the specified prefix.
*
* @param pattern The prefix, as a wildcard expression. If this is
* <code>null</code>, all possible children are shown.
*/
public void filter(String pattern) {
if ((pattern==null && this.pattern!=null) ||
(pattern!=null && this.pattern==null) ||
(pattern!=null && !pattern.equals(this.pattern.pattern()))) {
this.pattern = (pattern==null || pattern.length()==0) ? null :
RSyntaxUtilities.wildcardToPattern("^" + pattern, false, false);
Object root = getModel().getRoot();
if (root instanceof SourceTreeNode) {
((SourceTreeNode)root).filter(this.pattern);
}
((DefaultTreeModel)getModel()).reload();
expandInitialNodes();
}
}
开发者ID:pyros2097,项目名称:GdxStudio,代码行数:21,代码来源:AbstractSourceTree.java
示例11: gotoElementAtPath
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
private void gotoElementAtPath(TreePath path) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.
getLastPathComponent();
Object obj = node.getUserObject();
if (obj instanceof AbstractNode) {
AbstractNode astNode = (AbstractNode)obj;
int start = astNode.getStartOffset();
int end = astNode.getEndOffset();
DocumentRange range = new DocumentRange(start, end);
RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);
}
}
开发者ID:bobbylight,项目名称:ZScriptLanguageSupport,代码行数:13,代码来源:ZScriptOutlineTree.java
示例12: actionPerformedImpl
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
if (gutter!=null) {
int line = textArea.getCaretLineNumber();
try {
gutter.toggleBookmark(line);
} catch (BadLocationException ble) { // Never happens
UIManager.getLookAndFeel().
provideErrorFeedback(textArea);
ble.printStackTrace();
}
}
}
开发者ID:Nanonid,项目名称:RSyntaxTextArea,代码行数:14,代码来源:RTextAreaEditorKit.java
示例13: gotoElementAtPath
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
private void gotoElementAtPath(TreePath path) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.
getLastPathComponent();
Object obj = node.getUserObject();
if (obj instanceof ASTNode) {
ASTNode astNode = (ASTNode)obj;
int start = astNode.getNameStartOffset();
int end = astNode.getNameEndOffset();
DocumentRange range = new DocumentRange(start, end);
RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);
}
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:13,代码来源:JavaOutlineTree.java
示例14: checkStringLiteralMember
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
/**
* Checks whether the user is typing a completion for a String member after
* a String literal.
*
* @param comp The text component.
* @param alreadyEntered The text already entered.
* @param cu The compilation unit being parsed.
* @param set The set to add possible completions to.
* @return Whether the user is indeed typing a completion for a String
* literal member.
*/
private boolean checkStringLiteralMember(JTextComponent comp,
String alreadyEntered,
CompilationUnit cu, Set<Completion> set) {
boolean stringLiteralMember = false;
int offs = comp.getCaretPosition() - alreadyEntered.length() - 1;
if (offs>1) {
RSyntaxTextArea textArea = (RSyntaxTextArea)comp;
RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();
try {
//System.out.println(doc.charAt(offs) + ", " + doc.charAt(offs+1));
if (doc.charAt(offs)=='"' && doc.charAt(offs+1)=='.') {
int curLine = textArea.getLineOfOffset(offs);
Token list = textArea.getTokenListForLine(curLine);
Token prevToken = RSyntaxUtilities.getTokenAtOffset(list, offs);
if (prevToken!=null &&
prevToken.getType()==Token.LITERAL_STRING_DOUBLE_QUOTE) {
ClassFile cf = getClassFileFor(cu, "java.lang.String");
addCompletionsForExtendedClass(set, cu, cf,
cu.getPackageName(), null);
stringLiteralMember = true;
}
else {
System.out.println(prevToken);
}
}
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
}
return stringLiteralMember;
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:47,代码来源:SourceCompletionProvider.java
示例15: gotoElementAtPath
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
private void gotoElementAtPath(TreePath path) {
Object node = path.getLastPathComponent();
if (node instanceof XmlTreeNode) {
XmlTreeNode xtn = (XmlTreeNode)node;
DocumentRange range = new DocumentRange(xtn.getStartOffset(),
xtn.getEndOffset());
RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);
}
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:10,代码来源:XmlOutlineTree.java
示例16: gotoElementAtPath
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
private void gotoElementAtPath(TreePath path) {
Object node = path.getLastPathComponent();
if (node instanceof JavaScriptTreeNode) {
JavaScriptTreeNode jstn = (JavaScriptTreeNode)node;
int len = jstn.getLength();
if (len>-1) { // Should always be true
int offs = jstn.getOffset();
DocumentRange range = new DocumentRange(offs, offs+len);
RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);
}
}
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:13,代码来源:JavaScriptOutlineTree.java
示例17: actionPerformed
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
@Override
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:bobbylight,项目名称:RSTALanguageSupport,代码行数:28,代码来源:AbstractMarkupLanguageSupport.java
示例18: find
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
/**
* Finds the next instance of the string/regular expression specified
* from the caret position. If a match is found, it is selected in this
* text area.
*
* @param textArea The text area in which to search.
* @param context What to search for and all search options.
* @return The result of the operation.
* @throws PatternSyntaxException If this is a regular expression search
* but the search text is an invalid regular expression.
* @see #replace(RTextArea, SearchContext)
* @see #replaceAll(RTextArea, SearchContext)
*/
public static SearchResult find(JTextArea textArea, SearchContext context) {
// Always clear previous "mark all" highlights
if (textArea instanceof RTextArea || context.getMarkAll()) {
((RTextArea)textArea).clearMarkAllHighlights();
}
boolean doMarkAll = textArea instanceof RTextArea && context.getMarkAll();
String text = context.getSearchFor();
if (text==null || text.length()==0) {
if (doMarkAll) {
// Force "mark all" event to be broadcast so listeners know to
// clear their mark-all markers. The RSTA already cleared its
// highlights above, but cleraMarkAllHighlights() doesn't firs
// an event itself for performance reasons.
List<DocumentRange> emptyRangeList = Collections.emptyList();
((RTextArea)textArea).markAll(emptyRangeList);
}
return new SearchResult();
}
// Be smart about what position we're "starting" at. We don't want
// to find a match in the currently selected text (if any), so we
// start searching AFTER the selection if searching forward, and
// BEFORE the selection if searching backward.
Caret c = textArea.getCaret();
boolean forward = context.getSearchForward();
int start = forward ? Math.max(c.getDot(), c.getMark()) :
Math.min(c.getDot(), c.getMark());
String findIn = getFindInText(textArea, start, forward);
if (findIn==null || findIn.length()==0) {
return new SearchResult();
}
int markAllCount = 0;
if (doMarkAll) {
markAllCount = markAllImpl((RTextArea)textArea, context).
getMarkedCount();
}
SearchResult result = SearchEngine.findImpl(findIn, context);
if (result.wasFound() && !result.getMatchRange().isZeroLength()) {
// Without this, if JTextArea isn't in focus, selection
// won't appear selected.
textArea.getCaret().setSelectionVisible(true);
if (forward && start>-1) {
result.getMatchRange().translate(start);
}
RSyntaxUtilities.selectAndPossiblyCenter(textArea,
result.getMatchRange(), true);
}
result.setMarkedCount(markAllCount);
return result;
}
开发者ID:curiosag,项目名称:ftc,代码行数:71,代码来源:SearchEngine.java
示例19: getNextMatchPosRegExImpl
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
/**
* Searches <code>searchIn</code> for an occurrence of <code>regEx</code>
* either forwards or backwards, matching case or not.
*
* @param regEx The regular expression to look for.
* @param searchIn The string to search in.
* @param goForward Whether to search forward. If <code>false</code>,
* search backward.
* @param matchCase Whether or not to do a case-sensitive search for
* <code>regEx</code>.
* @param wholeWord If <code>true</code>, <code>regEx</code>
* occurrences embedded in longer words in <code>searchIn</code>
* don't count as matches.
* @param replaceStr The string that will replace the match found (if
* a match is found). The object returned will contain the
* replacement string with matched groups substituted. If this
* value is <code>null</code>, it is assumed this call is part of a
* "find" instead of a "replace" operation.
* @return If <code>replaceStr</code> is <code>null</code>, a
* <code>Point</code> representing the starting and ending points
* of the match. If it is non-<code>null</code>, an object with
* information about the match and the morphed string to replace
* it with. If no match is found, <code>null</code> is returned.
* @throws PatternSyntaxException If <code>regEx</code> is an invalid
* regular expression.
* @throws IndexOutOfBoundsException If <code>replaceStr</code> references
* an invalid group (less than zero or greater than the number of
* groups matched).
* @see #getNextMatchPos
*/
private static Object getNextMatchPosRegExImpl(String regEx,
CharSequence searchIn, boolean goForward,
boolean matchCase, boolean wholeWord,
String replaceStr) {
if (wholeWord) {
regEx = "\\b" + regEx + "\\b";
}
// Make a pattern that takes into account whether or not to match case.
int flags = Pattern.MULTILINE; // '^' and '$' are done per line.
flags = RSyntaxUtilities.getPatternFlags(matchCase, flags);
Pattern pattern = null;
try {
pattern = Pattern.compile(regEx, flags);
} catch (PatternSyntaxException pse) {
return null; // e.g. a "mark all" request with incomplete regex
}
// Make a Matcher to find the regEx instances.
Matcher m = pattern.matcher(searchIn);
// Search forwards
if (goForward) {
if (m.find()) {
if (replaceStr==null) { // Find, not replace.
return new Point(m.start(), m.end());
}
// Otherwise, replace
return new RegExReplaceInfo(m.group(0),
m.start(), m.end(),
getReplacementText(m, replaceStr));
}
}
// Search backwards
else {
List<?> matches = getMatches(m, replaceStr);
if (!matches.isEmpty()) {
return matches.get(matches.size()-1);
}
}
return null; // No match found
}
开发者ID:curiosag,项目名称:ftc,代码行数:77,代码来源:SearchEngine.java
示例20: init
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; //导入依赖的package包/类
@Override
protected void init() {
super.init();
// Initialize currentLine; otherwise, the current line won't start
// off as highlighted.
currentLine = 0;
setLineNumberingStartIndex(1);
visibleRect = new Rectangle(); // Must be initialized
addMouseListener(this);
addMouseMotionListener(this);
aaHints = RSyntaxUtilities.getDesktopAntiAliasHints();
}
开发者ID:curiosag,项目名称:ftc,代码行数:19,代码来源:LineNumberList.java
注:本文中的org.fife.ui.rsyntaxtextarea.RSyntaxUtilities类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论