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


Java Element.getElement方法代碼示例

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


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

示例1: lineHeight

import javax.swing.text.Element; //導入方法依賴的package包/類
private int lineHeight() {
    if (lineHeight < 0) {
        Element root = editor.getDocument().getDefaultRootElement();
        if (root.getElementCount()>0) {
            Element elem = root.getElement(0);
            try {
                int y1 = editor.modelToView(elem.getStartOffset()).y;
                int y2 = editor.modelToView(elem.getEndOffset()).y;
                lineHeight = y2-y1;
            } catch (BadLocationException blex) {
                Logger.getLogger(CustomCodeView.class.getName()).log(Level.INFO, blex.getMessage(), blex);
            }
        }
        if (lineHeight <= 0) {
            // fallback
            lineHeight = editor.getFontMetrics(editor.getFont()).getHeight();
        }
    }
    return lineHeight;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CustomCodeView.java

示例2: getSelectionStart

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Returns the offset where the selection starts on the specified line.
 */
public int getSelectionStart(int line) {
	if (line == selectionStartLine) {
		return selectionStart;
	} else if (rectSelect) {
		Element map = document.getDefaultRootElement();
		int start = selectionStart - map.getElement(selectionStartLine).getStartOffset();

		Element lineElement = map.getElement(line);
		int lineStart = lineElement.getStartOffset();
		int lineEnd = lineElement.getEndOffset() - 1;
		return Math.min(lineEnd, lineStart + start);
	} else {
		return getLineStartOffset(line);
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:19,代碼來源:JEditTextArea.java

示例3: getWordEnd

import javax.swing.text.Element; //導入方法依賴的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:Thecarisma,項目名稱:powertext,代碼行數:22,代碼來源:RSyntaxTextAreaEditorKit.java

示例4: appendOffset

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Get string representation of an offset for debugging purposes
 * in form "offset[line:column]". Both lines and columns start counting from 1
 * like in the editor's status bar. Tabs are expanded when counting the column.
 *
 * @param sb valid string builder to which text will be appended or null in which case
 *  the method itself will create a string builder and it will return it.
 * @param doc non-null document in which the offset is located.
 * @param offset offset in the document.
 * @return non-null string builder to which the description was added.
 * @since 1.27
 */
public static StringBuilder appendOffset(StringBuilder sb, Document doc, int offset) {
    if (sb == null) {
        sb = new StringBuilder(50);
    }
    sb.append(offset).append('[');
    if (offset < 0) { // Offset too low
        sb.append("<0");
    } else if (offset > doc.getLength() + 1) { // +1 for AbstractDocument-based docs
        sb.append(">").append(doc.getLength());
    } else { // Valid offset
        Element paragraphRoot = getParagraphRootElement(doc);
        int lineIndex = paragraphRoot.getElementIndex(offset);
        Element lineElem = paragraphRoot.getElement(lineIndex);
        sb.append(lineIndex + 1).append(':'); // Line
        sb.append(visualColumn(doc, lineElem.getStartOffset(), offset) + 1); // Column
    }
    sb.append(']');
    return sb;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:DocumentUtilities.java

示例5: setSharedSegment

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Makes our private <code>Segment s</code> point to the text in our
 * document referenced by the specified element.  Note that
 * <code>line</code> MUST be a valid line number in the document.
 *
 * @param line The line number you want to get.
 */
private void setSharedSegment(int line) {

	Element map = getDefaultRootElement();
	//int numLines = map.getElementCount();

	Element element = map.getElement(line);
	if (element==null) {
		throw new InternalError("Invalid line number: " + line);
	}
	int startOffset = element.getStartOffset();
	//int endOffset = (line==numLines-1 ?
	//			element.getEndOffset()-1 : element.getEndOffset() - 1);
	int endOffset = element.getEndOffset()-1; // Why always "-1"?
	try {
		getText(startOffset, endOffset-startOffset, s);
	} catch (BadLocationException ble) {
		throw new InternalError("Text range not in document: " +
							startOffset + "-" + endOffset);
	}

}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:29,代碼來源:RSyntaxDocument.java

示例6: invoke

import javax.swing.text.Element; //導入方法依賴的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.
 */
@Override
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:Thecarisma,項目名稱:powertext,代碼行數:40,代碼來源:StaticCodeTemplate.java

示例7: getPathForIndex

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Returns a TreePath to the element at <code>position</code>.
 */
protected TreePath getPathForIndex(int position, Object root,
        Element rootElement) {
    TreePath path = new TreePath(root);
    Element child = rootElement.getElement(rootElement.getElementIndex(
            position));

    path = path.pathByAddingChild(rootElement);
    path = path.pathByAddingChild(child);
    while (!child.isLeaf()) {
        child = child.getElement(child.getElementIndex(position));
        path = path.pathByAddingChild(child);
    }
    return path;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:ElementTreePanel.java

示例8: doError

import javax.swing.text.Element; //導入方法依賴的package包/類
private void doError(SAXParseException e, ParserNotice.Level level) {
	int line = e.getLineNumber() - 1;
	Element root = doc.getDefaultRootElement();
	Element elem = root.getElement(line);
	int offs = elem.getStartOffset();
	int len = elem.getEndOffset() - offs;
	if (line==root.getElementCount()-1) {
		len++;
	}
	DefaultParserNotice pn = new DefaultParserNotice(XmlParser.this,
									e.getMessage(), line, offs, len);
	pn.setLevel(level);
	result.addNotice(pn);
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:15,代碼來源:XmlParser.java

示例9: getTextLineNumber

import javax.swing.text.Element; //導入方法依賴的package包/類
protected String getTextLineNumber(int rowStartOffset)
{
	Element root = component.getDocument().getDefaultRootElement();
	int index = root.getElementIndex( rowStartOffset );
	Element line = root.getElement( index );

	if (line.getStartOffset() == rowStartOffset)
		return String.valueOf(index + 1);
	else
		return "";
}
 
開發者ID:BlidiWajdi,項目名稱:Mujeed-Arabic-Prolog,代碼行數:12,代碼來源:TextLineNumber.java

示例10: getWordStart

import javax.swing.text.Element; //導入方法依賴的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:Thecarisma,項目名稱:powertext,代碼行數:10,代碼來源:RSyntaxTextAreaEditorKit.java

示例11: loadChildren

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Loads all of the children to initialize the view.
 * This is called by the <code>setParent</code> method.
 * Subclasses can re-implement this to initialize their
 * child views in a different manner.  The default
 * implementation creates a child view for each
 * child element.
 *
 * @param f the view factory
 */
@Override
protected void loadChildren(ViewFactory f) {
	Element e = getElement();
	int n = e.getElementCount();
	if (n > 0) {
		View[] added = new View[n];
		for (int i = 0; i < n; i++) {
			added[i] = new WrappedLine(e.getElement(i));
		}
		replace(0, 0, added);
	}
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:23,代碼來源:WrappedSyntaxView.java

示例12: noticeContainsPosition

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Returns whether a parser notice contains the specified offset.
 *
 * @param notice The notice.
 * @param offs The offset.
 * @return Whether the notice contains the offset.
 */
private boolean noticeContainsPosition(ParserNotice notice, int offs){
	if (notice.getKnowsOffsetAndLength()) {
		return notice.containsPosition(offs);
	}
	Document doc = textArea.getDocument();
	Element root = doc.getDefaultRootElement();
	int line = notice.getLine();
	if (line<0) { // Defensive against possible bad user-defined notices.
		return false;
	}
	Element elem = root.getElement(line);
	return elem != null && offs>=elem.getStartOffset() && offs<elem.getEndOffset();
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:21,代碼來源:ParserManager.java

示例13: getRangeForLine

import javax.swing.text.Element; //導入方法依賴的package包/類
static int[] getRangeForLine(final Accessible a, final int lineIndex) {
    Accessible sa = CAccessible.getSwingAccessible(a);
    if (!(sa instanceof JTextComponent)) return null;

    final JTextComponent jc = (JTextComponent) sa;
    final Element root = jc.getDocument().getDefaultRootElement();
    final Element line = root.getElement(lineIndex);
    if (line == null) return null;

    return new int[] { line.getStartOffset(), line.getEndOffset() };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:CAccessibleText.java

示例14: getTokenListForLine

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Returns a token list for the specified segment of text representing
 * the specified line number.  This method is basically a wrapper for
 * <code>tokenMaker.getTokenList</code> that takes into account the last
 * token on the previous line to assure token accuracy.
 *
 * @param line The line number of <code>text</code> in the document,
 *        &gt;= 0.
 * @return A token list representing the specified line.
 */
public final Token getTokenListForLine(int line) {

	tokenRetrievalCount++;
	if (line==lastLine && cachedTokenList!=null) {
		if (DEBUG_TOKEN_CACHING) {
			useCacheCount++;
			System.err.println("--- Using cached line; ratio now: " +
					useCacheCount + "/" + tokenRetrievalCount);
		}
		return cachedTokenList;
	}
	lastLine = line;

	Element map = getDefaultRootElement();
	Element elem = map.getElement(line);
	int startOffset = elem.getStartOffset();
	//int endOffset = (line==map.getElementCount()-1 ? elem.getEndOffset() - 1:
	//									elem.getEndOffset() - 1);
	int endOffset = elem.getEndOffset() - 1; // Why always "-1"?
	try {
		getText(startOffset,endOffset-startOffset, s);
	} catch (BadLocationException ble) {
		ble.printStackTrace();
		return null;
	}
	int initialTokenType = line==0 ? Token.NULL :
							getLastTokenTypeOnLine(line-1);

	//return tokenMaker.getTokenList(s, initialTokenType, startOffset);
	cachedTokenList = tokenMaker.getTokenList(s, initialTokenType, startOffset);
	return cachedTokenList;

}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:44,代碼來源:RSyntaxDocument.java

示例15: getParagraphElement

import javax.swing.text.Element; //導入方法依賴的package包/類
/**
 * Get the paragraph element for the given document.
 *
 * @param doc non-null document instance.
 * @param offset offset in the document >=0
 * @return paragraph element containing the given offset.
 */
public static Element getParagraphElement(Document doc, int offset) {
    Element paragraph;
    if (doc instanceof StyledDocument) {
        paragraph = ((StyledDocument)doc).getParagraphElement(offset);
    } else {
        Element rootElem = doc.getDefaultRootElement();
        int index = rootElem.getElementIndex(offset);
        paragraph = rootElem.getElement(index);
        if ((offset < paragraph.getStartOffset()) || (offset >= paragraph.getEndOffset())) {
            paragraph = null;
        }
    }
    return paragraph;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:DocumentUtilities.java


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