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


Java RSyntaxTextArea.getLineOfOffset方法代碼示例

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


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

示例1: findOpenFoldClosestTo

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
private Fold findOpenFoldClosestTo(Point p) {

		Fold fold = null;

		RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
		if (rsta.isCodeFoldingEnabled()) { // Should always be true
			int offs = rsta.viewToModel(p); // TODO: Optimize me
			if (offs>-1) {
				try {
					int line = rsta.getLineOfOffset(offs);
					FoldManager fm = rsta.getFoldManager();
					fold = fm.getFoldForLine(line);
					if (fold==null) {
						fold = fm.getDeepestOpenFoldContaining(offs);
					}
				} catch (BadLocationException ble) {
					ble.printStackTrace(); // Never happens
				}
			}
		}
	
		return fold;

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

示例2: find

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
private void find(RSyntaxTextArea textArea) {

        try {
            int offset = currentLine < textArea.getLineCount() ? textArea.getLineStartOffset(currentLine) : 0;
            String searchTerm = tfSearchEditor.getText();
            String text = textArea.getText();
            int foundIndex = -1;
            int flags = (checkboxRegexp.isSelected() ? 0 : Pattern.LITERAL)
                    | (checkboxMatchCase.isSelected() ? 0 : Pattern.CASE_INSENSITIVE);
            Pattern p = Pattern.compile(searchTerm, flags);
            Matcher matcher = p.matcher(text);
            matcher.region(offset, text.length());
            if (matcher.find()) {
                foundIndex = matcher.start();
            } else if (checkboxWrap.isSelected() && offset > 0) {
                matcher.region(0, offset);
                if (matcher.find()) {
                    foundIndex = matcher.start();
                }
            }
            if (foundIndex != -1) {
                int lineOfOffset = textArea.getLineOfOffset(foundIndex);
                // textArea.setActiveLineRange(lineOfOffset, lineOfOffset);
                textArea.setCurrentLine(lineOfOffset);
                // textArea.setCaretPosition(foundIndex + searchTerm.length());
                parent.repaint();
                parent.fireStepChanged(lineOfOffset);
                currentLine = lineOfOffset + 1;
            } else {
                JOptionPane.showMessageDialog(parent, "Search String not found.");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
開發者ID:intuit,項目名稱:Tank,代碼行數:37,代碼來源:FindReplaceDialog.java

示例3: checkStringLiteralMember

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的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

示例4: getToolTipText

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
/**
 * Overridden to show the content of a collapsed fold on mouse-overs.
 *
 * @param e The mouse location.
 */
@Override
public String getToolTipText(MouseEvent e) {

	String text = null;

	RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
	if (rsta.isCodeFoldingEnabled()) {
		FoldManager fm = rsta.getFoldManager();
		int pos = rsta.viewToModel(new Point(0, e.getY()));
		if (pos>=0) { // Not -1
			int line = 0;
			try {
				line = rsta.getLineOfOffset(pos);
			} catch (BadLocationException ble) {
				ble.printStackTrace(); // Never happens
				return null;
			}
			Fold fold = fm.getFoldForLine(line);
			if (fold!=null && fold.isCollapsed()) {

				int endLine = fold.getEndLine();
				if (fold.getLineCount()>25) { // Not too big
					endLine = fold.getStartLine() + 25;
				}

				StringBuilder sb = new StringBuilder("<html><nobr>");
				while (line<=endLine && line<rsta.getLineCount()) { // Sanity
					Token t = rsta.getTokenListForLine(line);
					while (t!=null && t.isPaintable()) {
						t.appendHTMLRepresentation(sb, rsta, true, true);
						t = t.getNextToken();
					}
					sb.append("<br>");
					line++;
				}

				text = sb.toString();

			}
		}
	}

	return text;

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

示例5: checkForLinkableToken

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
/**
 * Checks if the token at the specified offset is possibly a "click-able"
 * region.
 *
 * @param textArea The text area.
 * @param offs The offset, presumably at the mouse position.
 * @return A result object.
 */
private IsLinkableCheckResult checkForLinkableToken(
		RSyntaxTextArea textArea, int offs) {

	IsLinkableCheckResult result = null;

	if (offs>=0) {

		try {

			int line = textArea.getLineOfOffset(offs);
			Token first = textArea.getTokenListForLine(line);
			Token prev = null;

			for (Token t=first; t!=null && t.isPaintable(); t=t.getNextToken()) {

				if (t.containsPosition(offs)) {

					// RSTA's tokens are pooled and re-used, so we must
					// defensively make a copy of the one we want to keep!
					Token token = new TokenImpl(t);
					boolean isMethod = false;

					if (prev==null) {
						prev = RSyntaxUtilities.getPreviousImportantToken(textArea, line-1);
					}
					if (prev!=null && prev.isSingleChar('.')) {
						// Not a field or method defined in this class.
						break;
					}

					Token next = RSyntaxUtilities.getNextImportantToken(
							t.getNextToken(), textArea, line);
					if (next!=null && next.isSingleChar(Token.SEPARATOR, '(')) {
						isMethod = true;
					}

					result = new IsLinkableCheckResult(token, isMethod);
					break;

				}

				else if (!t.isCommentOrWhitespace()) {
					prev = t;
				}

			}

		} catch (BadLocationException ble) {
			ble.printStackTrace(); // Never happens
		}

	}

	return result;

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

示例6: checkForVarDereference

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; //導入方法依賴的package包/類
/**
 * Checks if the token at the specified offset is possibly a "click-able"
 * region.
 *
 * @param textArea The text area.
 * @param offs The offset, presumably at the mouse position.
 * @return A result object.
 */
private Token checkForVarDereference(RSyntaxTextArea textArea, int offs) {

	if (offs>=0) {

		RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument();

		try {

			int line = textArea.getLineOfOffset(offs);
			Token first = textArea.getTokenListForLine(line);
			Token prev = null;
			Token prev2 = null;

			for (Token t=first; t!=null && t.isPaintable(); t=t.getNextToken()) {
				if (t.containsPosition(offs)) {
					if (prev==null) {
						prev = RSyntaxUtilities.getPreviousImportantToken(
								doc, line-1);
					}
					break;
				}
				else if (!t.isCommentOrWhitespace()) {
					prev2 = prev;
					prev = t;
				}
			}

			// Sigh, if only Tokens could be a doubly-linked list...
			// Scan back again to get what variable is dereferenced.
			if (prev!=null && prev.is(Token.OPERATOR, ARROW)) {

				// Common case - user had it all on one line, e.g.
				// "Link->PressA"
				if (prev2!=null) {
					//System.out.println("Common case!");
					return prev2;
				}

				// Uncommon case - user had the "->" on one line and e.g.
				// "PressA" on another line.
				int arrowOffs = prev.getOffset();
				line = textArea.getLineOfOffset(arrowOffs);
				first = textArea.getTokenListForLine(line);
				prev = null;

				for (Token t=first; t!=null && t.isPaintable(); t=t.getNextToken()) {
					if (t.getOffset()==arrowOffs) {
						if (prev==null) {
							prev = RSyntaxUtilities.getPreviousImportantToken(
									doc, line-1);
						}
						if (prev!=null) {
							return prev;
						}
					}
					else if (!t.isCommentOrWhitespace()) {
						prev = t;
					}
				}

			}

		} catch (BadLocationException ble) {
			ble.printStackTrace(); // Never happens
		}

	}

	return null;

}
 
開發者ID:bobbylight,項目名稱:ZScriptLanguageSupport,代碼行數:80,代碼來源:ZScriptLinkGenerator.java


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