Example usage for javax.swing.text AttributeSet isDefined

List of usage examples for javax.swing.text AttributeSet isDefined

Introduction

In this page you can find the example usage for javax.swing.text AttributeSet isDefined.

Prototype

public boolean isDefined(Object attrName);

Source Link

Document

Checks whether the named attribute has a value specified in the set without resolving through another attribute set.

Usage

From source file:Main.java

private void listAttributes(AttributeSet attributes) {
    Enumeration e = attributes.getAttributeNames();
    while (e.hasMoreElements()) {
        Object name = e.nextElement();
        Object value = attributes.getAttribute(name);
        if (!attributes.containsAttribute(name.toString(), value)) {
            System.out.println("containsAttribute() fails");
        }//from  ww w . j  av  a  2s  . co  m
        if (!attributes.isDefined(name.toString())) {
            System.out.println("isDefined() fails");
        }
        System.out.println(name + "=" + value);
    }
}

From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java

@Override
protected Map<Attribute, Object> getAttributes(AttributeSet attrSet) {
    Map<Attribute, Object> attrMap = new HashMap<Attribute, Object>();
    if (attrSet.isDefined(StyleConstants.FontFamily)) {
        attrMap.put(TextAttribute.FAMILY, StyleConstants.getFontFamily(attrSet));
    }/*from w  w w. j av  a2s.  c o  m*/

    if (attrSet.isDefined(StyleConstants.Bold)) {
        attrMap.put(TextAttribute.WEIGHT,
                StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
    }

    if (attrSet.isDefined(StyleConstants.Italic)) {
        attrMap.put(TextAttribute.POSTURE, StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE
                : TextAttribute.POSTURE_REGULAR);
    }

    if (attrSet.isDefined(StyleConstants.Underline)) {
        attrMap.put(TextAttribute.UNDERLINE,
                StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null);
    }

    if (attrSet.isDefined(StyleConstants.StrikeThrough)) {
        attrMap.put(TextAttribute.STRIKETHROUGH,
                StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null);
    }

    if (attrSet.isDefined(StyleConstants.FontSize)) {
        attrMap.put(TextAttribute.SIZE, StyleConstants.getFontSize(attrSet));
    }

    if (attrSet.isDefined(StyleConstants.Foreground)) {
        attrMap.put(TextAttribute.FOREGROUND, StyleConstants.getForeground(attrSet));
    }

    if (attrSet.isDefined(StyleConstants.Background)) {
        attrMap.put(TextAttribute.BACKGROUND, StyleConstants.getBackground(attrSet));
    }

    //FIXME: why StyleConstants.isSuperscript(attrSet) does return false
    if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet)) {
        attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
    }

    if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet)) {
        attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
    }

    return attrMap;
}

From source file:com.hexidec.ekit.component.RelativeImageView.java

/** Method looks up an integer-valued attribute (not recursive!)
  *///from  w  w w  . j  a va 2 s. com
private int getIntAttr(HTML.Attribute name, int iDefault) {
    AttributeSet attr = fElement.getAttributes();
    if (attr.isDefined(name)) {
        int i;
        String val = (String) attr.getAttribute(name);
        if (val == null) {
            i = iDefault;
        } else {
            try {
                i = Math.max(0, Integer.parseInt(val));
            } catch (NumberFormatException nfe) {
                i = iDefault;
            }
        }
        return i;
    } else {
        return iDefault;
    }
}

From source file:com.hexidec.ekit.component.RelativeImageView.java

/** Method tests whether the image within a link
  *///  w  ww .ja v a2 s. c  om
boolean isLink() {
    AttributeSet anchorAttr = (AttributeSet) fElement.getAttributes().getAttribute(HTML.Tag.A);
    if (anchorAttr != null) {
        return anchorAttr.isDefined(HTML.Attribute.HREF);
    }
    return false;
}

From source file:org.pmedv.core.components.RelativeImageView.java

/**
 * Method tests whether the image within a link
 *//*from   w w w  .j av  a 2 s .  co  m*/
boolean isLink() {

    AttributeSet anchorAttr = (AttributeSet) fElement.getAttributes().getAttribute(HTML.Tag.A);
    if (anchorAttr != null) {
        return anchorAttr.isDefined(HTML.Attribute.HREF);
    }
    return false;
}

From source file:org.pmedv.core.components.RelativeImageView.java

/**
 * Method looks up an integer-valued attribute (not recursive!)
 * /*from w ww. ja va 2  s. com*/
 * @param name
 *            HTML.Attribute name
 * @param iDefault
 *            default int value
 * @return returns int value of the given attribute or the default if the
 *         given attribute was not found.
 */
private int getIntAttr(HTML.Attribute name, int iDefault) {

    AttributeSet myAttr = fElement.getAttributes();
    if (myAttr.isDefined(name)) {
        int i;
        String val = (String) myAttr.getAttribute(name);
        if (val == null) {
            i = iDefault;
        } else {
            try {
                i = Math.max(0, Integer.parseInt(val));
            } catch (NumberFormatException nfe) {
                log.debug("setting i to default value.");
                i = iDefault;
            }
        }
        return i;
    } else {
        return iDefault;
    }
}