当前位置: 首页>>代码示例>>Java>>正文


Java Element.getElementCount方法代码示例

本文整理汇总了Java中javax.swing.text.Element.getElementCount方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getElementCount方法的具体用法?Java Element.getElementCount怎么用?Java Element.getElementCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.Element的用法示例。


在下文中一共展示了Element.getElementCount方法的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: actionPerformed

import javax.swing.text.Element; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
	String trTag = "<tr>";
	Element tr =
		document
			.getParagraphElement(editor.getCaretPosition())
			.getParentElement()
			.getParentElement();
	for (int i = 0; i < tr.getElementCount(); i++)
		if (tr.getElement(i).getName().toUpperCase().equals("TD"))
			trTag += "<td><p></p></td>";
	trTag += "</tr>";

	/*
	 * HTMLEditorKit.InsertHTMLTextAction hta = new
	 * HTMLEditorKit.InsertHTMLTextAction("insertTR",trTag,
	 * HTML.Tag.TABLE, HTML.Tag.TR);
	 */
	try {
		document.insertAfterEnd(tr, trTag);
		//editorKit.insertHTML(document, editor.getCaretPosition(),
		// trTag, 3, 0, HTML.Tag.TR);
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:26,代码来源:HTMLEditor.java

示例3: getRowStart

import javax.swing.text.Element; //导入方法依赖的package包/类
/** Get the starting position of the row while providing relative count
* of row how the given position should be shifted. This is the most
* efficient way how to move by lines in the document based on some
* position. There is no similair getRowEnd() method that would have
* shifting parameter.
* @param doc document to operate on
* @param offset position in document where to start searching
* @param lineShift shift the given offset forward/back relatively
*  by some amount of lines
* @return position of the start of the row or -1 for invalid position
* @deprecated Deprecated without replacement
*/
public static int getRowStart(BaseDocument doc, int offset, int lineShift)
throws BadLocationException {
    checkOffsetValid(doc, offset);
    if (lineShift != 0) {
        Element lineRoot = doc.getParagraphElement(0).getParentElement();
        int line = lineRoot.getElementIndex(offset);
        line += lineShift;
        if (line < 0 || line >= lineRoot.getElementCount()) {
            return -1; // invalid line shift
        }
        return lineRoot.getElement(line).getStartOffset();

    } else { // no shift
        return doc.getParagraphElement(offset).getStartOffset();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:Utilities.java

示例4: removeTrailingWhitespace

import javax.swing.text.Element; //导入方法依赖的package包/类
private static void removeTrailingWhitespace(Document doc) throws Exception {
    Element lineRoot = DocumentUtilities.getParagraphRootElement(doc);
    CharSequence docText = DocumentUtilities.getText(doc);
    int lineCount = lineRoot.getElementCount();
    for (int i = 0; i < lineCount; i++) {
        Element lineElem = lineRoot.getElement(i);
        int lineStartOffset = lineElem.getStartOffset();
        int lineLastOffset = lineElem.getEndOffset() - 1;
        int offset;
        for (offset = lineLastOffset - 1; offset >= lineStartOffset; offset--) {
            char c = docText.charAt(offset);
            // Currently only remove ' ' and '\t' - may be revised
            if (c != ' ' && c != '\t') {
                break;
            }
        }
        // Increase offset (either below lineStartOffset or on non-white char)
        offset++;
        if (offset < lineLastOffset) {
            doc.remove(offset, lineLastOffset - offset);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:TrailingWhitespaceRemoveTest.java

示例5: getRowStart

import javax.swing.text.Element; //导入方法依赖的package包/类
public static int getRowStart(Document doc, int offset, int lineShift)
throws BadLocationException {
    
    checkOffsetValid(doc, offset);

    if (lineShift != 0) {
        Element lineRoot = doc.getDefaultRootElement();
        int line = lineRoot.getElementIndex(offset);
        line += lineShift;
        if (line < 0 || line >= lineRoot.getElementCount()) {
            return -1; // invalid line shift
        }
        return lineRoot.getElement(line).getStartOffset();

    } else { // no shift
        return doc.getDefaultRootElement().getElement(
               doc.getDefaultRootElement().getElementIndex(offset)).getStartOffset();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:DocUtils.java

示例6: reindent

import javax.swing.text.Element; //导入方法依赖的package包/类
public void reindent() throws BadLocationException {
    Document doc = context.document();
    int startOffset = context.startOffset();
    int endOffset = context.endOffset();
    
    pushFormattingContextDocument(doc);
    try {
        // Original formatter does not have reindentation of multiple lines
        // so reformat start line and continue for each line.
        Element lineRootElem = lineRootElement(doc);
        Position endPos = doc.createPosition(endOffset);
        do {
            startOffset = formatter.indentLine(doc, startOffset);
            int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
            if (startLineIndex >= lineRootElem.getElementCount())
                break;
            Element lineElem = lineRootElem.getElement(startLineIndex);
            startOffset = lineElem.getStartOffset(); // Move to next line
        } while (startOffset < endPos.getOffset());
    } finally {
        popFormattingContextDocument(doc);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:LegacyFormattersProvider.java

示例7: setPreferredWidth

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 *  Calculate the width needed to display the maximum line number
 */
private void setPreferredWidth()
{
	Element root = component.getDocument().getDefaultRootElement();
	int lines = root.getElementCount();
	int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);

	//  Update sizes when number of digits in the line number changes

	if (lastDigits != digits)
	{
		lastDigits = digits;
		FontMetrics fontMetrics = getFontMetrics( getFont() );
		int width = fontMetrics.charWidth( '0' ) * digits;
		Insets insets = getInsets();
		int preferredWidth = insets.left + insets.right + width;

		Dimension d = getPreferredSize();
		d.setSize(preferredWidth, HEIGHT);
		setPreferredSize( d );
		setSize( d );
	}
}
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:26,代码来源:TextLineNumber.java

示例8: addParserHighlight

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Adds a highlight from a parser.
 *
 * @param notice The notice from a {@link Parser}.
 * @return A tag with which to reference the highlight.
 * @throws BadLocationException
 * @see #clearParserHighlights()
 * @see #clearParserHighlights(Parser)
 */
HighlightInfo addParserHighlight(ParserNotice notice, HighlightPainter p)
							throws BadLocationException {

	Document doc = textArea.getDocument();
	TextUI mapper = textArea.getUI();

	int start = notice.getOffset();
	int end = 0;
	if (start==-1) { // Could just define an invalid line number
		int line = notice.getLine();
		Element root = doc.getDefaultRootElement();
		if (line>=0 && line<root.getElementCount()) {
			Element elem = root.getElement(line);
			start = elem.getStartOffset();
			end = elem.getEndOffset();
		}
	}
	else {
		end = start + notice.getLength();
	}

	// Always layered highlights for parser highlights.
	SyntaxLayeredHighlightInfoImpl i = new SyntaxLayeredHighlightInfoImpl();
	i.setPainter(p);
	i.setStartOffset(doc.createPosition(start));
	// HACK: Use "end-1" to prevent chars the user types at the "end" of
	// the highlight to be absorbed into the highlight (default Highlight
	// behavior).
	i.setEndOffset(doc.createPosition(end-1));
	i.notice = notice;//i.color = notice.getColor();

	parserHighlights.add(i);
	mapper.damageRange(textArea, start, end);
	return i;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:46,代码来源:RSyntaxTextAreaHighlighter.java

示例9: reloadChildren

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
     * Load the children in the selected range of offsets.
     * <br>
     * Some implementations may reload all the present children if necessary.
     *
     * @param index index at which the views should be added/replaced.
     * @param removeLength number of removed children views. It is useful
     *  when rebuilding children for a portion of the view.
     * @param startOffset starting offset of the loading. It can be -1
     *  to indicate the loading from <code>View.getStartOffset()</code>.
     * @param endOffset ending offset of the loading. It can be -1
     *  to indicate the loading till <code>View.getEndOffset()</code>.
     */
    protected void reloadChildren(int index, int removeLength, int startOffset, int endOffset) {
        if (useCustomReloadChildren()) {
            if (startOffset == -1) {
                startOffset = getStartOffset();
            }
            if (endOffset == -1) {
                endOffset = getEndOffset();
            }

            customReloadChildren(index, removeLength, startOffset, endOffset);

        } else { // element load of children
            Element elem = getElement();
            int startIndex;
            if (startOffset == -1) {
                startIndex = 0;
            } else {
                if (index == 0) {
                    if (startOffset != getStartOffset()) {
                        throw new IllegalArgumentException("Invalid startOffset=" + startOffset); // NOI18N
                    }
                } else {
                    if (startOffset != getView(index - 1).getEndOffset()) {
                        throw new IllegalArgumentException("Invalid startOffset=" + startOffset); // NOI18N
                    }
                }
                startIndex = index;
            }

            int endIndex = (endOffset == -1)
                ? elem.getElementCount()
                : elem.getElementIndex(endOffset - 1) + 1;

// TODO uncomment            assert (startIndex == index);

            elementReloadChildren(index, removeLength, endIndex - startIndex);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:GapBoxView.java

示例10: lineInfosToString

import javax.swing.text.Element; //导入方法依赖的package包/类
public static String lineInfosToString(Document doc) {
    StringBuffer sb = new StringBuffer();
    Element lineRoot = getLineRoot(doc);
    int lineCount = lineRoot.getElementCount();
    for (int i = 0; i < lineCount; i++) {
        LineElement elem = (LineElement)lineRoot.getElement(i);
        sb.append("[" + i + "]: lineStartOffset=" + elem.getStartOffset() // NOI18N
            + ", info: " + (Syntax.StateInfo) elem.legacyGetAttributesObject() + "\n"); // NOI18N
    }
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:FixLineSyntaxState.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: getLineStartFromIndex

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Return start offset of the line with the given index.
 *
 * @param lineIndex line index starting from 0
 * @return start offset of the line or -1 if lineIndex was invalid
 */
public static int getLineStartFromIndex(@NonNull LineDocument doc, int lineIndex) {
    Element lineRoot = doc.getParagraphElement(0).getParentElement();
    if (lineIndex < 0 || lineIndex >= lineRoot.getElementCount()) {
        return -1; // invalid line number
    } else {
        return lineRoot.getElement(lineIndex).getStartOffset();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:LineDocumentUtils.java

示例13: actionPerformed

import javax.swing.text.Element; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
	String trTag = "<tr>";
	Element tr =
		document
			.getParagraphElement(editor.getCaretPosition())
			.getParentElement()
			.getParentElement();
	for (int i = 0; i < tr.getElementCount(); i++)
	{
		if (tr.getElement(i).getName().toUpperCase().equals("TD"))
			trTag += "<td><p></p></td>";
	}
	trTag += "</tr>";

	/*
	 * HTMLEditorKit.InsertHTMLTextAction hta = new
	 * HTMLEditorKit.InsertHTMLTextAction("insertTR",trTag,
	 * HTML.Tag.TABLE, HTML.Tag.TR);
	 */
	try {
		document.insertAfterEnd(tr, trTag);
		//editorKit.insertHTML(document, editor.getCaretPosition(),
		// trTag, 3, 0, HTML.Tag.TR);
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:ser316asu,项目名称:SER316-Aachen,代码行数:28,代码来源:HTMLEditor.java

示例14: findFirstElement

import javax.swing.text.Element; //导入方法依赖的package包/类
private static Element findFirstElement(Element e, String name) {
    String elementName = e.getName();
    if (elementName != null && elementName.equalsIgnoreCase(name)) {
        return e;
    }
    for (int i = 0; i < e.getElementCount(); i++) {
        Element result = findFirstElement(e.getElement(i), name);
        if (result != null) {
            return result;
        }
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:bug8048110.java

示例15: getOffsetY

import javax.swing.text.Element; //导入方法依赖的package包/类
private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics)
	throws BadLocationException
{
	//  Get the bounding rectangle of the row

	Rectangle r = component.modelToView( rowStartOffset );
	int lineHeight = fontMetrics.getHeight();
	int y = r.y + r.height;
	int descent = 0;

	//  The text needs to be positioned above the bottom of the bounding
	//  rectangle based on the descent of the font(s) contained on the row.

	if (r.height == lineHeight)  // default font is being used
	{
		descent = fontMetrics.getDescent();
	}
	else  // We need to check all the attributes for font changes
	{
		if (fonts == null)
			fonts = new HashMap<String, FontMetrics>();

		Element root = component.getDocument().getDefaultRootElement();
		int index = root.getElementIndex( rowStartOffset );
		Element line = root.getElement( index );

		for (int i = 0; i < line.getElementCount(); i++)
		{
			Element child = line.getElement(i);
			AttributeSet as = child.getAttributes();
			String fontFamily = (String)as.getAttribute(StyleConstants.FontFamily);
			Integer fontSize = (Integer)as.getAttribute(StyleConstants.FontSize);
			String key = fontFamily + fontSize;

			FontMetrics fm = fonts.get( key );

			if (fm == null)
			{
				Font font = new Font(fontFamily, Font.PLAIN, fontSize);
				fm = component.getFontMetrics( font );
				fonts.put(key, fm);
			}

			descent = Math.max(descent, fm.getDescent());
		}
	}

	return y - descent;
}
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:50,代码来源:TextLineNumber.java


注:本文中的javax.swing.text.Element.getElementCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。