summaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/text/LabelView.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/text/LabelView.java')
-rw-r--r--libjava/classpath/javax/swing/text/LabelView.java78
1 files changed, 53 insertions, 25 deletions
diff --git a/libjava/classpath/javax/swing/text/LabelView.java b/libjava/classpath/javax/swing/text/LabelView.java
index 03279c4b2b5..7cfeae86229 100644
--- a/libjava/classpath/javax/swing/text/LabelView.java
+++ b/libjava/classpath/javax/swing/text/LabelView.java
@@ -39,9 +39,11 @@ exception statement from your version. */
package javax.swing.text;
import java.awt.Color;
+import java.awt.Container;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Shape;
+import java.awt.Toolkit;
import javax.swing.event.DocumentEvent;
@@ -90,6 +92,11 @@ public class LabelView extends GlyphView
boolean superscript;
/**
+ * Indicates if the attributes must be refetched.
+ */
+ private boolean valid;
+
+ /**
* Creates a new <code>GlyphView</code> for the given <code>Element</code>.
*
* @param element the element that is rendered by this GlyphView
@@ -97,7 +104,7 @@ public class LabelView extends GlyphView
public LabelView(Element element)
{
super(element);
- setPropertiesFromAttributes();
+ valid = false;
}
/**
@@ -107,28 +114,25 @@ public class LabelView extends GlyphView
*/
protected void setPropertiesFromAttributes()
{
- Element el = getElement();
- AttributeSet atts = el.getAttributes();
- // We cannot use StyleConstants.getBackground() here, because that returns
- // BLACK as default (when background == null). What we need is the
- // background setting of the text component instead, which is what we get
- // when background == null anyway.
- background = (Color) atts.getAttribute(StyleConstants.Background);
- foreground = StyleConstants.getForeground(atts);
- strikeThrough = StyleConstants.isStrikeThrough(atts);
- subscript = StyleConstants.isSubscript(atts);
- superscript = StyleConstants.isSuperscript(atts);
- underline = StyleConstants.isUnderline(atts);
-
- // Determine the font.
- String family = StyleConstants.getFontFamily(atts);
- int size = StyleConstants.getFontSize(atts);
- int style = Font.PLAIN;
- if (StyleConstants.isBold(atts))
- style |= Font.BOLD;
- if (StyleConstants.isItalic(atts))
- style |= Font.ITALIC;
- font = new Font(family, style, size);
+ AttributeSet atts = getAttributes();
+ setStrikeThrough(StyleConstants.isStrikeThrough(atts));
+ setSubscript(StyleConstants.isSubscript(atts));
+ setSuperscript(StyleConstants.isSuperscript(atts));
+ setUnderline(StyleConstants.isUnderline(atts));
+
+ // Determine the font and colors.
+ Document d = getDocument();
+ if (d instanceof StyledDocument)
+ {
+ StyledDocument doc = (StyledDocument) d;
+ font = doc.getFont(atts);
+ if (atts.isDefined(StyleConstants.Background))
+ background = doc.getBackground(atts);
+ else
+ background = null;
+ foreground = doc.getForeground(atts);
+ }
+ valid = true;
}
/**
@@ -142,7 +146,8 @@ public class LabelView extends GlyphView
*/
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf)
{
- setPropertiesFromAttributes();
+ valid = false;
+ super.changedUpdate(e, a, vf);
}
/**
@@ -152,6 +157,8 @@ public class LabelView extends GlyphView
*/
public Color getBackground()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return background;
}
@@ -175,6 +182,8 @@ public class LabelView extends GlyphView
*/
public Color getForeground()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return foreground;
}
@@ -185,6 +194,8 @@ public class LabelView extends GlyphView
*/
public Font getFont()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return font;
}
@@ -197,7 +208,16 @@ public class LabelView extends GlyphView
*/
protected FontMetrics getFontMetrics()
{
- return getContainer().getGraphics().getFontMetrics(font);
+ if (! valid)
+ setPropertiesFromAttributes();
+
+ Container c = getContainer();
+ FontMetrics fm;
+ if (c != null)
+ fm = c.getFontMetrics(font);
+ else
+ fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
+ return fm;
}
/**
@@ -209,6 +229,8 @@ public class LabelView extends GlyphView
*/
public boolean isUnderline()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return underline;
}
@@ -232,6 +254,8 @@ public class LabelView extends GlyphView
*/
public boolean isSubscript()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return subscript;
}
@@ -255,6 +279,8 @@ public class LabelView extends GlyphView
*/
public boolean isSuperscript()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return superscript;
}
@@ -278,6 +304,8 @@ public class LabelView extends GlyphView
*/
public boolean isStrikeThrough()
{
+ if (! valid)
+ setPropertiesFromAttributes();
return strikeThrough;
}