Java Code Examples for javax.swing.text.View#getAttributes()

The following examples show how to use javax.swing.text.View#getAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementBoxView.java    From SwingBox with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the box reference from properties.
 * 
 * @param v
 *            just a view.
 * @return the box set in properties, if there is one.
 */
public static final Box getBox(View v)
{
    if (v instanceof CSSBoxView) return getBox((CSSBoxView) v);

    AttributeSet attr = v.getAttributes();
    if (attr == null)
    {
        throw new NullPointerException("AttributeSet of " + v.getClass().getName() + "@"
                            + Integer.toHexString(v.hashCode()) + " is set to NULL.");
    }
    Object obj = attr.getAttribute(Constants.ATTRIBUTE_BOX_REFERENCE);
    if (obj != null && obj instanceof Box)
    {
        return (Box) obj;
    }
    else
    {
        throw new IllegalArgumentException("Box reference in attributes is not an instance of a Box.");
    }

}
 
Example 2
Source File: ImageView.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public Color getForeground() {
    View parent;
    if (fg == null && (parent = getParent()) != null) {
        Document doc = getDocument();
        AttributeSet attr = parent.getAttributes();

        if (attr != null && (doc instanceof StyledDocument)) {
            fg = ((StyledDocument)doc).getForeground(attr);
        }
    }
    return fg;
}
 
Example 3
Source File: bug4960629.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void test() {
    View root = ((View)label.getClientProperty(BasicHTML.propertyKey))
            .getView(0);
    int n = root.getViewCount();
    View v  = root.getView(n - 1);
    AttributeSet attrs = v.getAttributes();
    StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet();
    Font font = ss.getFont(attrs);
    System.out.println(font.getSize());
    passed = (font.getSize() == 12);
    if(!passed) {
        throw new RuntimeException("Test failed.");
    }
}
 
Example 4
Source File: ImageView.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Color getForeground() {
    View parent;
    if (fg == null && (parent = getParent()) != null) {
        Document doc = getDocument();
        AttributeSet attr = parent.getAttributes();

        if (attr != null && (doc instanceof StyledDocument)) {
            fg = ((StyledDocument)doc).getForeground(attr);
        }
    }
    return fg;
}