KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > graphic > BasicGraphicAttributes


1 /*
2  * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details
13  * (http://www.gnu.org/copyleft/lesser.html).
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package jcckit.graphic;
20
21 import jcckit.util.ConfigParameters;
22
23 import java.awt.Color JavaDoc;
24
25 /**
26  * The basic attributes of any {@link BasicGraphicalElement}. This is an
27  * extension of {@link ShapeAttributes} implementing {@link TextAttributes}.
28  *
29  * @author Franz-Josef Elmer
30  */

31 public class BasicGraphicAttributes extends ShapeAttributes
32                                     implements TextAttributes {
33   /** Configuration parameter key. */
34   public static final String JavaDoc TEXT_COLOR_KEY = "textColor",
35                              FONT_NAME_KEY = "fontName",
36                              FONT_STYLE_KEY = "fontStyle",
37                              FONT_SIZE_KEY = "fontSize",
38                              HORIZONTAL_ANCHOR_KEY = "horizontalAnchor",
39                              VERTICAL_ANCHOR_KEY = "verticalAnchor",
40                              ORIENTATION_ANGLE_KEY = "orientationAngle";
41
42   private final Color JavaDoc _textColor;
43   private final String JavaDoc _fontName;
44   private final FontStyle _fontStyle;
45   private final double _fontSize;
46   private final double _orientationAngle;
47   private final Anchor _horizontalAnchor;
48   private final Anchor _verticalAnchor;
49
50   /**
51    * Creates a new instance based on the specified configuration
52    * parameters.
53    * <table border=1 cellpadding=5>
54    * <tr><th>Key &amp; Default Value</th><th>Type</th><th>Mandatory</th>
55    * <th>Description</th></tr>
56    * <tr><td><tt>textColor = </tt><i>default foreground color of the
57    * renderer</i></td><td><tt>Color</tt></td><td>no</td>
58    * <td>The text color.</td></tr>
59    * <tr><td><tt>fontName = </tt><i>default font name of the
60    * renderer</i></td><td><tt>String</tt></td><td>no</td>
61    * <td>The name of the text font. The standard Java font name
62    * "Serif", "SansSerif", and "Monospaced" can be used.
63    * Other font names depend on the actual {@link Renderer}
64    * rendering the corresponding {@link BasicGraphicalElement}.
65    * </td></tr>
66    * <tr><td><tt>fontStyle = normal</tt></td><td><tt>String</tt>
67    * </td><td>no</td>
68    * <td>The font style. Possible values are:
69    * <ul><li><tt>normal</tt><li><tt>bold</tt><li><tt>italic</tt>
70    * <li><tt>bold italic</tt></ul>
71    * </td></tr>
72    * <tr><td><tt>fontSize = </tt><i>default font size of the
73    * renderer</i></td><td><tt>double</tt></td><td>no</td>
74    * <td>The font size in units of the device-independent
75    * coordinates.</td></tr>
76    * <tr><td><tt>orientationAngle = 0</tt></td><td><tt>double</tt></td>
77    * <td>no</td>
78    * <td>The orientation angle of the text (in degree).
79    * Zero means normal orientation whereas a positive value means
80    * a rotation in counter-clockweise direction.</td></tr>
81    * <tr><td><tt>horizontalAnchor = left</tt></td><td><tt>String</tt>
82    * </td><td>no</td>
83    * <td>Anchor for horizontal text position. Possible values are
84    * <tt>left</tt>, <tt>center</tt>, and <tt>right</tt>.</td></tr>
85    * <tr><td><tt>verticalAnchor = center</tt></td><td><tt>String</tt>
86    * </td><td>no</td>
87    * <td>Anchor for vertical text position. Possible values are
88    * <tt>top</tt>, <tt>center</tt>, and <tt>bottom</tt>.</td></tr>
89    * </table>
90    * Additional configuration parameters are explained in the
91    * {@link ShapeAttributes#ShapeAttributes constructor}
92    * of the superclass {@link ShapeAttributes}.
93    */

94   public BasicGraphicAttributes(ConfigParameters config) {
95     super(config);
96     _textColor = config.getColor(TEXT_COLOR_KEY, null);
97     _fontName = config.get(FONT_NAME_KEY, null);
98     _fontStyle = FontStyle.getFontStyle(config, FONT_STYLE_KEY,
99                                         FontStyle.NORMAL);
100     _fontSize = config.getDouble(FONT_SIZE_KEY, 0);
101     _orientationAngle = config.getDouble(ORIENTATION_ANGLE_KEY, 0);
102
103     _horizontalAnchor = Anchor.getHorizontalAnchor(config,
104                                   HORIZONTAL_ANCHOR_KEY, Anchor.LEFT_BOTTOM);
105     _verticalAnchor = Anchor.getVerticalAnchor(config,
106                                   VERTICAL_ANCHOR_KEY, Anchor.CENTER);
107   }
108
109   /**
110    * Creates a new instance.
111    * @param fillColor The fill color. May be <tt>null</tt>.
112    * @param lineColor The line color. May be <tt>null</tt>.
113    * @param lineThickness Thickness of the line.
114    * Negative numbers will be trimmed to zero.
115    * @param linePattern Line pattern. May be <tt>null</tt>.
116    * @param textColor The text color. May be <tt>null</tt>.
117    * @param fontName The font name. May be <tt>null</tt>.
118    * @param fontStyle The font style. May be <tt>null</tt>.
119    * @param fontSize The font size in units of the device-independent
120    * coordinates. May be <tt>null</tt>.
121    * @param orientationAngle Orientation angle of the text.
122    * @param horizontalAnchor Horizontal text anchor.
123    * @param verticalAnchor Vertical text anchor.
124    */

125   public BasicGraphicAttributes(Color JavaDoc fillColor, Color JavaDoc lineColor,
126                                 double lineThickness,
127                                 double[] linePattern, Color JavaDoc textColor,
128                                 String JavaDoc fontName, FontStyle fontStyle,
129                                 double fontSize, double orientationAngle,
130                                 Anchor horizontalAnchor,
131                                 Anchor verticalAnchor) {
132     super(fillColor, lineColor, lineThickness, linePattern);
133     _textColor = textColor;
134     _fontName = fontName;
135     _fontStyle = fontStyle;
136     _fontSize = fontSize;
137     _orientationAngle = orientationAngle;
138     _horizontalAnchor = horizontalAnchor;
139     _verticalAnchor = verticalAnchor;
140   }
141
142   /**
143    * Returns the text color.
144    * @return <tt>null</tt> means default color of the renderer.
145    */

146   public Color JavaDoc getTextColor() {
147     return _textColor;
148   }
149
150   /**
151    * Returns the font name.
152    * @return <tt>null</tt> means default font name of the renderer.
153    */

154   public String JavaDoc getFontName() {
155     return _fontName;
156   }
157
158   /**
159    * Returns the font style.
160    * @return <tt>null</tt> means default font style of the renderer.
161    */

162   public FontStyle getFontStyle() {
163     return _fontStyle;
164   }
165
166   /**
167    * Returns the font size in units of the device-independent coordinates.
168    */

169   public double getFontSize() {
170     return _fontSize;
171   }
172
173   /**
174    * Returns the orientation angle in degree. Zero means
175    * normal text orientation. Any positive angle means a
176    * counter-clockwise rotation of the text.
177    */

178   public double getOrientationAngle() {
179     return _orientationAngle;
180   }
181
182   /**
183    * Returns the anchor for horizontal position of the text.
184    * Note, that the anchor is related to the text <em>before</em>
185    * it is rotated by the orientation angle.
186    * @return one of the three instances of <tt>Anchor</tt>.
187    */

188   public Anchor getHorizontalAnchor() {
189     return _horizontalAnchor;
190   }
191
192   /**
193    * Returns the anchor for vertical position of the text.
194    * Note, that the anchor is related to the text <em>before</em>
195    * it is rotated by the orientation angle.
196    * @return one of the three instances of <tt>Anchor</tt>.
197    */

198   public Anchor getVerticalAnchor() {
199     return _verticalAnchor;
200   }
201 }
202
203
Popular Tags