下面列出了javax.swing.text.View#getAttributes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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.");
}
}
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;
}
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.");
}
}
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;
}