Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / text / LabelView.java
blob4890735b92503ae59b09ae15f018e73601c21d00
1 /* LabelView.java -- A view to render styled text
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.text;
41 import java.awt.Color;
42 import java.awt.Font;
43 import java.awt.FontMetrics;
44 import java.awt.Shape;
46 import javax.swing.event.DocumentEvent;
48 /**
49 * A {@link GlyphView} that caches the textattributes for most effective
50 * rendering.
52 * @author Roman Kennke (kennke@aicas.com)
54 public class LabelView extends GlyphView
57 /**
58 * The background color.
60 Color background;
62 /**
63 * The foreground color.
65 Color foreground;
67 /**
68 * The background color.
70 Font font;
72 /**
73 * The strikethrough flag.
75 boolean strikeThrough;
77 /**
78 * The underline flag.
80 boolean underline;
82 /**
83 * The subscript flag.
85 boolean subscript;
87 /**
88 * The superscript flag.
90 boolean superscript;
92 /**
93 * Creates a new <code>GlyphView</code> for the given <code>Element</code>.
95 * @param element the element that is rendered by this GlyphView
97 public LabelView(Element element)
99 super(element);
100 setPropertiesFromAttributes();
104 * Loads the properties of this label view from the element's text
105 * attributes. This method is called from the constructor and the
106 * {@link #changedUpdate} method
108 protected void setPropertiesFromAttributes()
110 Element el = getElement();
111 AttributeSet atts = el.getAttributes();
112 background = StyleConstants.getBackground(atts);
113 foreground = StyleConstants.getForeground(atts);
114 strikeThrough = StyleConstants.isStrikeThrough(atts);
115 subscript = StyleConstants.isSubscript(atts);
116 superscript = StyleConstants.isSuperscript(atts);
117 underline = StyleConstants.isUnderline(atts);
119 // Determine the font.
120 String family = StyleConstants.getFontFamily(atts);
121 int size = StyleConstants.getFontSize(atts);
122 int style = Font.PLAIN;
123 if (StyleConstants.isBold(atts))
124 style |= Font.BOLD;
125 if (StyleConstants.isItalic(atts))
126 style |= Font.ITALIC;
127 font = new Font(family, style, size);
131 * Receives notification when text attributes change in the chunk of
132 * text that this view is responsible for. This simply calls
133 * {@link #setPropertiesFromAttributes()}.
135 * @param e the document event
136 * @param a the allocation of this view
137 * @param vf the view factory to use for creating new views
139 public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf)
141 setPropertiesFromAttributes();
145 * Returns the background color for the glyphs.
147 * @return the background color for the glyphs
149 public Color getBackground()
151 return background;
155 * Sets the background color for the glyphs. A value of <code>null</code>
156 * means the background of the parent view should shine through.
158 * @param bg the background to set or <code>null</code>
160 * @since 1.5
162 protected void setBackground(Color bg)
164 background = bg;
168 * Returns the foreground color for the glyphs.
170 * @return the foreground color for the glyphs
172 public Color getForeground()
174 return foreground;
178 * Returns the font for the glyphs.
180 * @return the font for the glyphs
182 public Font getFont()
184 return font;
188 * Returns the font metrics of the current font.
190 * @return the font metrics of the current font
192 * @deprecated this is not used anymore
194 protected FontMetrics getFontMetrics()
196 return getContainer().getGraphics().getFontMetrics(font);
200 * Returns <code>true</code> if the glyphs are rendered underlined,
201 * <code>false</code> otherwise.
203 * @return <code>true</code> if the glyphs are rendered underlined,
204 * <code>false</code> otherwise
206 public boolean isUnderline()
208 return underline;
212 * Sets the underline flag.
214 * @param flag <code>true</code> if the glyphs are rendered underlined,
215 * <code>false</code> otherwise
217 protected void setUnderline(boolean flag)
219 underline = flag;
223 * Returns <code>true</code> if the glyphs are rendered as subscript,
224 * <code>false</code> otherwise.
226 * @return <code>true</code> if the glyphs are rendered as subscript,
227 * <code>false</code> otherwise
229 public boolean isSubscript()
231 return subscript;
235 * Sets the subscript flag.
237 * @param flag <code>true</code> if the glyphs are rendered as subscript,
238 * <code>false</code> otherwise
240 protected void setSubscript(boolean flag)
242 subscript = flag;
246 * Returns <code>true</code> if the glyphs are rendered as superscript,
247 * <code>false</code> otherwise.
249 * @return <code>true</code> if the glyphs are rendered as superscript,
250 * <code>false</code> otherwise
252 public boolean isSuperscript()
254 return superscript;
258 * Sets the superscript flag.
260 * @param flag <code>true</code> if the glyphs are rendered as superscript,
261 * <code>false</code> otherwise
263 protected void setSuperscript(boolean flag)
265 superscript = flag;
269 * Returns <code>true</code> if the glyphs are rendered strike-through,
270 * <code>false</code> otherwise.
272 * @return <code>true</code> if the glyphs are rendered strike-through,
273 * <code>false</code> otherwise
275 public boolean isStrikeThrough()
277 return strikeThrough;
281 * Sets the strike-through flag.
283 * @param flag <code>true</code> if the glyphs are rendered strike-through,
284 * <code>false</code> otherwise
286 protected void setStrikeThrough(boolean flag)
288 strikeThrough = flag;