FileDocCategorySizeDatePackage
LabelView.javaAPI DocJava SE 6 API8808Tue Jun 10 00:26:58 BST 2008javax.swing.text

LabelView

public class LabelView extends GlyphView implements TabableView
A LabelView 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.
author
Timothy Prinzing
version
1.70 04/07/06

Fields Summary
private Font
font
private Color
fg
private Color
bg
private boolean
underline
private boolean
strike
private boolean
superscript
private boolean
subscript
Constructors Summary
public LabelView(Element elem)
Constructs a new view wrapped on an element.

param
elem the element

	super(elem);
    
Methods Summary
public voidchangedUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)
Gives notification from the document that attributes were changed in a location that this view is responsible for.

param
e the change information from the associated document
param
a the current allocation of the view
param
f the factory to use to rebuild if the view has children
see
View#changedUpdate

	font = null;
        super.changedUpdate(e, a, f);
    
public java.awt.ColorgetBackground()
Fetches the background color to use to render the glyphs. This is implemented to return a cached background color, which defaults to null.

return
the cached background color
since
1.3

	sync();
	return bg;
    
public java.awt.FontgetFont()
Fetches the font that the glyphs should be based upon. This is implemented to return a cached font.

return
the cached font

	sync();
	return font;
    
protected java.awt.FontMetricsgetFontMetrics()
Fetches the FontMetrics used for this view.

deprecated
FontMetrics are not used for glyph rendering when running in the JDK.

	sync();
        Container c = getContainer();
        return (c != null) ? c.getFontMetrics(font) :
            Toolkit.getDefaultToolkit().getFontMetrics(font);
    
public java.awt.ColorgetForeground()
Fetches the foreground color to use to render the glyphs. This is implemented to return a cached foreground color, which defaults to null.

return
the cached foreground color
since
1.3

	sync();
	return fg;
    
public booleanisStrikeThrough()
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.

return
the value of the cached strikeThrough property
since
1.3

	sync();
	return strike;
    
public booleanisSubscript()
Determines if the glyphs should be rendered as superscript.

return
the value of the cached subscript 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.

return
the value of the cached subscript property
since
1.3

	sync();
	return subscript;
    
public booleanisSuperscript()
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.

return
the value of the cached superscript property
since
1.3

	sync();
	return superscript;
    
public booleanisUnderline()
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.

return
the value of the cached underline property
since
1.3

	sync();
	return underline;
    
protected voidsetBackground(java.awt.Color 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.

param
bg background color, or null
see
#setPropertiesFromAttributes
since
1.5

        this.bg = bg;
    
protected voidsetPropertiesFromAttributes()
Sets the cached properties from the attributes.

	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");
	    }
	}
     
protected voidsetStrikeThrough(boolean 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.

param
s true if the view has a strike/line through it, otherwise false
see
#isStrikeThrough

	strike = s;
    
protected voidsetSubscript(boolean 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.

param
s true if the view represents a subscript, otherwise false
see
#isSubscript

	subscript = s;
    
protected voidsetSuperscript(boolean 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.

param
s true if the view represents a superscript, otherwise false
see
#isSuperscript

	superscript = s;
    
protected voidsetUnderline(boolean 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.

param
u true if the view is underlined, otherwise false
see
#isUnderline

	underline = u;
    
final voidsync()
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.

	if (font == null) {
	    setPropertiesFromAttributes();
	}