is a styled chunk of text
that represents a view mapped over an element in the
text model. It caches the character level attributes
used for rendering.
Method from javax.swing.text.LabelView Detail: |
public void changedUpdate(DocumentEvent e,
Shape a,
ViewFactory f) {
font = null;
super.changedUpdate(e, a, f);
}
Gives notification from the document that attributes were changed
in a location that this view is responsible for. |
public Color getBackground() {
sync();
return bg;
}
Fetches the background color to use to render the glyphs.
This is implemented to return a cached background color,
which defaults to null . |
public Font getFont() {
sync();
return font;
}
Fetches the font that the glyphs should be based upon.
This is implemented to return a cached font. |
protected FontMetrics getFontMetrics() {
sync();
Container c = getContainer();
return (c != null) ? c.getFontMetrics(font) :
Toolkit.getDefaultToolkit().getFontMetrics(font);
} Deprecated! FontMetrics - are not used for glyph rendering
when running in the JDK.
Fetches the FontMetrics used for this view. |
public Color getForeground() {
sync();
return fg;
}
Fetches the foreground color to use to render the glyphs.
This is implemented to return a cached foreground color,
which defaults to null . |
public boolean isStrikeThrough() {
sync();
return strike;
}
Determines if the glyphs should have a strikethrough
line. If true, a line should be drawn through the center
of the glyphs. This is implemented to return the
cached strikeThrough property.
When you request this property, LabelView
re-syncs its state with the properties of the
Element 's AttributeSet .
If Element 's AttributeSet
does not have this property set, it will revert to false. |
public boolean isSubscript() {
sync();
return subscript;
}
Determines if the glyphs should be rendered as superscript. |
public boolean isSuperscript() {
sync();
return superscript;
}
Determines if the glyphs should be rendered as subscript.
When you request this property, LabelView
re-syncs its state with the properties of the
Element 's AttributeSet .
If Element 's AttributeSet
does not have this property set, it will revert to false. |
public boolean isUnderline() {
sync();
return underline;
}
Determines if the glyphs should be underlined. If true,
an underline should be drawn through the baseline. This
is implemented to return the cached underline property.
When you request this property, LabelView
re-syncs its state with the properties of the
Element 's AttributeSet .
If Element 's AttributeSet
does not have this property set, it will revert to false. |
protected void setBackground(Color bg) {
this.bg = bg;
}
Sets the background color for the view. This method is typically
invoked as part of configuring this View . If you need
to customize the background color you should override
setPropertiesFromAttributes and invoke this method. A
value of null indicates no background should be rendered, so that the
background of the parent View will show through. |
protected void setPropertiesFromAttributes() {
AttributeSet attr = getAttributes();
if (attr != null) {
Document d = getDocument();
if (d instanceof StyledDocument) {
StyledDocument doc = (StyledDocument) d;
font = doc.getFont(attr);
fg = doc.getForeground(attr);
if (attr.isDefined(StyleConstants.Background)) {
bg = doc.getBackground(attr);
} else {
bg = null;
}
setUnderline(StyleConstants.isUnderline(attr));
setStrikeThrough(StyleConstants.isStrikeThrough(attr));
setSuperscript(StyleConstants.isSuperscript(attr));
setSubscript(StyleConstants.isSubscript(attr));
} else {
throw new StateInvariantError("LabelView needs StyledDocument");
}
}
}
Sets the cached properties from the attributes. |
protected void setStrikeThrough(boolean s) {
strike = s;
}
Sets whether or not the view has a strike/line
through it.
Note that this setter is protected and is really
only meant if you need to update some additional
state when set. |
protected void setSubscript(boolean s) {
subscript = s;
}
Sets whether or not the view represents a
subscript.
Note that this setter is protected and is really
only meant if you need to update some additional
state when set. |
protected void setSuperscript(boolean s) {
superscript = s;
}
Sets whether or not the view represents a
superscript.
Note that this setter is protected and is really
only meant if you need to update some additional
state when set. |
protected void setUnderline(boolean u) {
underline = u;
}
Sets whether or not the view is underlined.
Note that this setter is protected and is really
only meant if you need to update some additional
state when set. |
final void sync() {
if (font == null) {
setPropertiesFromAttributes();
}
}
Synchronize the view's cached values with the model.
This causes the font, metrics, color, etc to be
re-cached if the cache has been invalidated. |