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


Java Element.getAttributes方法代码示例

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


在下文中一共展示了Element.getAttributes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mouseClicked

import javax.swing.text.Element; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    try {
        if (SwingUtilities.isLeftMouseButton(e)) {
            JTextPane pane = (JTextPane)e.getSource();
            StyledDocument doc = pane.getStyledDocument();
            Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
            AttributeSet as = elem.getAttributes();
            Link link = (Link)as.getAttribute(LINK_ATTRIBUTE);
            if (link != null) {
                link.onClick(elem.getDocument().getText(elem.getStartOffset(), elem.getEndOffset() - elem.getStartOffset()));
            }
        }
    } catch(Exception ex) {
        Support.LOG.log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:HyperlinkSupport.java

示例2: setElementProperties

import javax.swing.text.Element; //导入方法依赖的package包/类
void setElementProperties(Element el, String id, String cls, String sty) {
	ElementDialog dlg = new ElementDialog(null);
	//dlg.setLocation(linkActionB.getLocationOnScreen());
	Dimension dlgSize = dlg.getPreferredSize();
	Dimension frmSize = this.getSize();
	Point loc = this.getLocationOnScreen();
	dlg.setLocation(
		(frmSize.width - dlgSize.width) / 2 + loc.x,
		(frmSize.height - dlgSize.height) / 2 + loc.y);
	dlg.setModal(true);
	dlg.setTitle(Local.getString("Object properties"));
	dlg.idField.setText(id);
	dlg.classField.setText(cls);
	dlg.styleField.setText(sty);
	// Uncommented, returns a simple p into the header... fix needed ?
	//dlg.header.setText(el.getName());
	dlg.setVisible(true);
	if (dlg.CANCELLED)
		return;
	SimpleAttributeSet attrs = new SimpleAttributeSet(el.getAttributes());
	if (dlg.idField.getText().length() > 0)
		attrs.addAttribute(HTML.Attribute.ID, dlg.idField.getText());
	if (dlg.classField.getText().length() > 0)
		attrs.addAttribute(HTML.Attribute.CLASS, dlg.classField.getText());
	if (dlg.styleField.getText().length() > 0)
		attrs.addAttribute(HTML.Attribute.STYLE, dlg.styleField.getText());
	document.setParagraphAttributes(el.getStartOffset(), 0, attrs, true);
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:29,代码来源:HTMLEditor.java

示例3: mouseMoved

import javax.swing.text.Element; //导入方法依赖的package包/类
@Override
public void mouseMoved(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
    AttributeSet as = elem.getAttributes();
    if (StyleConstants.isUnderline(as)) {
        pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else {
        pane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:HyperlinkSupport.java

示例4: setElementProperties

import javax.swing.text.Element; //导入方法依赖的package包/类
void setElementProperties(Element el, String id, String cls, String sty) {
    ElementDialog dlg = new ElementDialog(null);
    //dlg.setLocation(linkActionB.getLocationOnScreen());
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = this.getSize();
    Point loc = this.getLocationOnScreen();
    dlg.setLocation(
        (frmSize.width - dlgSize.width) / 2 + loc.x,
        (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setModal(true);
    dlg.setTitle(Local.getString("Object properties"));
    dlg.idField.setText(id);
    dlg.classField.setText(cls);
    dlg.styleField.setText(sty);
    // Uncommented, returns a simple p into the header... fix needed ?
    //dlg.header.setText(el.getName());
    dlg.setVisible(true);
    if (dlg.CANCELLED)
        return;
    SimpleAttributeSet attrs = new SimpleAttributeSet(el.getAttributes());
    if (dlg.idField.getText().length() > 0)
        attrs.addAttribute(HTML.Attribute.ID, dlg.idField.getText());
    if (dlg.classField.getText().length() > 0)
        attrs.addAttribute(HTML.Attribute.CLASS, dlg.classField.getText());
    if (dlg.styleField.getText().length() > 0)
        attrs.addAttribute(HTML.Attribute.STYLE, dlg.styleField.getText());
    document.setParagraphAttributes(el.getStartOffset(), 0, attrs, true);
}
 
开发者ID:ser316asu,项目名称:SER316-Dresden,代码行数:29,代码来源:HTMLEditor.java

示例5: emptyTag

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Writes out all empty elements (all tags that have no
 * corresponding end tag).
 *
 * @param elem   an Element
 * @exception IOException on any I/O error
 * @exception BadLocationException if pos represents an invalid
 *            location within the document.
 */
protected void emptyTag(Element elem) throws BadLocationException, IOException {

    if (!inContent && !inPre) {
        indent();
    }

    AttributeSet attr = elem.getAttributes();
    closeOutUnwantedEmbeddedTags(attr);
    writeEmbeddedTags(attr);

    if (matchNameAttribute(attr, HTML.Tag.CONTENT)) {
        inContent = true;
        text(elem);
    }
    else if (matchNameAttribute(attr, HTML.Tag.COMMENT)) {
        comment(elem);
    }
    else {
        boolean isBlock = isBlockTag(elem.getAttributes());
        if (inContent && isBlock) {
            writeLineSeparator();
            indent();
        }

        Object nameTag = (attr != null) ? attr.getAttribute(StyleConstants.NameAttribute) : null;
        Object endTag = (attr != null) ? attr.getAttribute(HTML.Attribute.ENDTAG) : null;

        boolean outputEndTag = false;
        // If an instance of an UNKNOWN Tag, or an instance of a
        // tag that is only visible during editing
        //
        if (nameTag != null && endTag != null && (endTag instanceof String) && ((String) endTag).equals("true")) {
            outputEndTag = true;
        }

        if (completeDoc && matchNameAttribute(attr, HTML.Tag.HEAD)) {

            if (outputEndTag) {
                // Write out any styles.
                writeStyles(((HTMLDocument) getDocument()).getStyleSheet());
            }
            wroteHead = true;
        }

        write('<');
        if (outputEndTag) {
            write('/');
        }
        write(elem.getName());
        writeAttributes(attr);
        write('>');

        if (matchNameAttribute(attr, HTML.Tag.TITLE) && !outputEndTag) {
            Document doc = elem.getDocument();
            String title = (String) doc.getProperty(Document.TitleProperty);
            write(title);
        }

        else if (!inContent || isBlock) {
            writeLineSeparator();
            if (isBlock && inContent) {
                indent();
            }
        }
    }
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:76,代码来源:AltHTMLWriter.java

示例6: emptyTag

import javax.swing.text.Element; //导入方法依赖的package包/类
/**
 * Writes out all empty elements (all tags that have no
 * corresponding end tag).
 *
 * @param elem   an Element
 * @exception IOException on any I/O error
 * @exception BadLocationException if pos represents an invalid
 *            location within the document.
 */
protected void emptyTag(Element elem) throws BadLocationException, IOException {

    if (!inContent && !inPre) {
        indent();
    }

    AttributeSet attr = elem.getAttributes();
    closeOutUnwantedEmbeddedTags(attr);
    writeEmbeddedTags(attr);

    if (attr != null && matchNameAttribute(attr, HTML.Tag.CONTENT)) {
        inContent = true;
        text(elem);
    }
    else if (attr != null && matchNameAttribute(attr, HTML.Tag.COMMENT)) {
        comment(elem);
    }
    else {
        boolean isBlock = isBlockTag(elem.getAttributes());
        if (inContent && isBlock) {
            writeLineSeparator();
            indent();
        }

        Object nameTag = (attr != null) ? attr.getAttribute(StyleConstants.NameAttribute) : null;
        Object endTag = (attr != null) ? attr.getAttribute(HTML.Attribute.ENDTAG) : null;

        boolean outputEndTag = false;
        // If an instance of an UNKNOWN Tag, or an instance of a
        // tag that is only visible during editing
        //
        if (nameTag != null && endTag != null && (endTag instanceof String) && ((String) endTag).equals("true")) {
            outputEndTag = true;
        }

        if (completeDoc && matchNameAttribute(attr, HTML.Tag.HEAD)) {

            if (outputEndTag) {
                // Write out any styles.
                writeStyles(((HTMLDocument) getDocument()).getStyleSheet());
            }
            wroteHead = true;
        }

        write('<');
        if (outputEndTag) {
            write('/');
        }
        write(elem.getName());
        writeAttributes(attr);
        write('>');

        if (attr != null && matchNameAttribute(attr, HTML.Tag.TITLE) && !outputEndTag) {
            Document doc = elem.getDocument();
            String title = (String) doc.getProperty(Document.TitleProperty);
            write(title);
        }

        else if (!inContent || isBlock) {
            writeLineSeparator();
            if (isBlock && inContent) {
                indent();
            }
        }
    }
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:76,代码来源:AltHTMLWriter.java

示例7: setFontProperties

import javax.swing.text.Element; //导入方法依赖的package包/类
String setFontProperties(Element el, String text) {
	FontDialog dlg = new FontDialog(null);
	//dlg.setLocation(editor.getLocationOnScreen());
	Dimension dlgSize = dlg.getSize();
	Dimension frmSize = this.getSize();
	Point loc = this.getLocationOnScreen();
	dlg.setLocation(
		(frmSize.width - dlgSize.width) / 2 + loc.x,
		(frmSize.height - dlgSize.height) / 2 + loc.y);
	dlg.setModal(true);
	AttributeSet ea = el.getAttributes();
	/*
	 * if (ea.isDefined(HTML.Tag.FONT)) { String[] param =
	 * ea.getAttribute(HTML.Tag.FONT).toString().split(" "); for (int i = 0;
	 * i < param.length; i++) if (param[i].startsWith("face="))
	 * dlg.fontFamilyCB.setSelectedItem(param[i].split("=")[1]); else if
	 * (param[i].startsWith("size="))
	 * dlg.fontSizeCB.setSelectedItem(param[i].split("=")[1]); else if
	 * (param[i].startsWith("color=")) {
	 * dlg.colorField.setText(param[i].split("=")[1]);
	 * Util.setColorField(dlg.colorField); }
	 */
	if (ea.isDefined(StyleConstants.FontFamily))
		dlg.fontFamilyCB.setSelectedItem(
			ea.getAttribute(StyleConstants.FontFamily).toString());
	if (ea.isDefined(HTML.Tag.FONT)) {
		String s = ea.getAttribute(HTML.Tag.FONT).toString();
		String size =
			s.substring(s.indexOf("size=") + 5, s.indexOf("size=") + 6);
		dlg.fontSizeCB.setSelectedItem(size);
	}
	if (ea.isDefined(StyleConstants.Foreground)) {
		dlg.colorField.setText(
			Util.encodeColor(
				(Color) ea.getAttribute(StyleConstants.Foreground)));
		Util.setColorField(dlg.colorField);
		dlg.sample.setForeground(
			(Color) ea.getAttribute(StyleConstants.Foreground));
	}
	if (text != null)
		dlg.sample.setText(text);
	dlg.setVisible(true);
	if (dlg.CANCELLED)
		return null;
	String attrs = "";
	if (dlg.fontSizeCB.getSelectedIndex() > 0)
		attrs += "size=\"" + dlg.fontSizeCB.getSelectedItem() + "\"";
	if (dlg.fontFamilyCB.getSelectedIndex() > 0)
		attrs += "face=\"" + dlg.fontFamilyCB.getSelectedItem() + "\"";
	if (dlg.colorField.getText().length() > 0)
		attrs += "color=\"" + dlg.colorField.getText() + "\"";
	if (attrs.length() > 0)
		return " " + attrs;
	else
		return null;
}
 
开发者ID:ser316asu,项目名称:SER316-Munich,代码行数:57,代码来源:HTMLEditor.java

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