KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > graphic > ShapeAttributes


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  * Basic attributes for shapes.
27  *
28  * @author Franz-Josef Elmer
29  */

30 public class ShapeAttributes implements LineAttributes, FillAttributes {
31   /** Configuration parameter key. */
32   public static final String JavaDoc FILL_COLOR_KEY = "fillColor",
33                              LINE_COLOR_KEY = "lineColor",
34                              LINE_THICKNESS_KEY = "lineThickness",
35                              LINE_PATTERN_KEY = "linePattern";
36
37   private final Color JavaDoc _fillColor;
38   private final Color JavaDoc _lineColor;
39   private final double _lineThickness;
40   private final double[] _linePattern;
41
42   /**
43    * Creates a new instance based on the specified configuration
44    * parameters.
45    * <table border=1 cellpadding=5>
46    * <tr><th>Key &amp; Default Value</th><th>Type</th><th>Mandatory</th>
47    * <th>Description</th></tr>
48    * <tr><td><tt>fillColor = <i>no filling</i></tt></td><td><tt>Color</tt></td>
49    * <td>no</td><td>The fill color of the shape.</td></tr>
50    * <tr><td><tt>lineColor = <i>no line<i></tt></td><td><tt>Color</tt></td>
51    * <td>no</td><td>The color of a line, a polygon, or the border of a shape.</td></tr>
52    * <tr><td><tt>lineThickness = 0</tt></td><td><tt>double</tt></td>
53    * <td>no</td>
54    * <td>The thickness of a line. A thickness of zero means that
55    * the renderer will draw the thinest line possible.</td></tr>
56    * <tr><td><tt>linePattern = </tt><i>solid line</i></td>
57    * <td><tt>double[]</tt></td><td>no</td>
58    * <td>A sequence of lengths where the pen is alternatively
59    * down or up. For example, <tt>0.1 0.1</tt> will lead to a dashed
60    * line whereas <tt>0.02 0.02</tt> is the pattern of a dotted
61    * line and <tt>0.02 0.02 0.1 0.02</tt> of a dashed-dotted
62    * line.</td></tr>
63    * </table>
64    */

65   public ShapeAttributes(ConfigParameters config) {
66     this(config.getColor(FILL_COLOR_KEY, null),
67          config.getColor(LINE_COLOR_KEY, null),
68          config.getDouble(LINE_THICKNESS_KEY, 0),
69          config.getDoubleArray(LINE_PATTERN_KEY, null));
70   }
71
72   /**
73    * Creates a new instance.
74    * @param fillColor The fill color. May be <tt>null</tt>.
75    * @param lineColor The line color. May be <tt>null</tt>.
76    * @param lineThickness Thickness of the line.
77    * Negative numbers will be trimmed to zero.
78    * @param linePattern Line pattern. May be <tt>null</tt>.
79    */

80   public ShapeAttributes(Color JavaDoc fillColor, Color JavaDoc lineColor,
81                          double lineThickness, double[] linePattern) {
82     _fillColor = fillColor;
83     _lineColor = lineColor;
84     _lineThickness = Math.max(0, lineThickness);
85     _linePattern = linePattern;
86   }
87
88   public Color JavaDoc getFillColor() {
89     return _fillColor;
90   }
91
92   public Color JavaDoc getLineColor() {
93     return _lineColor;
94   }
95
96   public double getLineThickness() {
97     return _lineThickness;
98   }
99
100   public double[] getLinePattern() {
101     return _linePattern;
102   }
103 }
104
105
Popular Tags