KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > plot > AbstractSymbolFactory


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.plot;
20
21 import jcckit.graphic.GraphPoint;
22 import jcckit.graphic.GraphicAttributes;
23 import jcckit.graphic.GraphicalElement;
24 import jcckit.util.ConfigParameters;
25 import jcckit.util.Factory;
26
27 /**
28  * Abstract superclass of all {@link SymbolFactory SymbolFactories}.
29  * Subclasses have to implement {@link #createPlainSymbol createPlainSymbol()}.
30  *
31  * @author Franz-Josef Elmer
32  */

33 public abstract class AbstractSymbolFactory implements SymbolFactory {
34   /** Size of all symbols. */
35   protected final double _size;
36   
37   /** Attributes of all symbols. */
38   protected final GraphicAttributes _attributes;
39
40   /**
41    * Creates an instance from the specified configuration parameters.
42    * <table border=1 cellpadding=5>
43    * <tr><th>Key &amp; Default Value</th><th>Type</th><th>Mandatory</th>
44    * <th>Description</th></tr>
45    * <tr><td><tt>size = </tt>0.01</td>
46    * <td><tt>double</tt></td><td>no</td>
47    * <td>Size of the symbol in device-independent units.</td></tr>
48    * <tr><td><tt>attributes</tt></td>
49    * <td><tt>ConfigParameters</tt></td><td>no</td>
50    * <td>Configuration parameters for the attributes of the symbol.
51    * <tt>className</tt> has to be a class which is an instance of
52    * {@link GraphicAttributes}.</td></tr>
53    * </table>
54    */

55   public AbstractSymbolFactory(ConfigParameters config) {
56     _size = config.getDouble(SIZE_KEY, DEFAULT_SIZE);
57     _attributes = (GraphicAttributes) Factory.createOrGet(
58                                         config.getNode(ATTRIBUTES_KEY), null);
59   }
60
61   /**
62    * Creates a symbol.
63    * Evaluate <tt>hintFromPreviousPoint</tt> if it is a {@link AttributesHint}.
64    * Calls {@link #createSymbol(GraphPoint, GraphicAttributes, Hint, Hint)}.
65    * @param point Symbol position.
66    * @param hintFromPreviousPoint Hint from the previous point.
67    * @param hintFromPreviousCurve Hint from the previous curve.
68    */

69   public Symbol createSymbol(GraphPoint point, Hint hintFromPreviousPoint,
70                              Hint hintFromPreviousCurve) {
71     GraphicAttributes attributes = _attributes;
72     Hint hintForNextPoint = hintFromPreviousPoint;
73     if (hintFromPreviousPoint instanceof AttributesHint) {
74       attributes = ((AttributesHint) hintFromPreviousPoint).getAttributes();
75       hintForNextPoint
76           = ((AttributesHint) hintFromPreviousPoint).getNextHint();
77     }
78     return createSymbol(point, attributes, hintForNextPoint,
79                         hintFromPreviousCurve);
80   }
81
82   /**
83    * Creates a symbol.
84    * Uses {@link #createPlainSymbol createPlainSymbol()}.
85    * @param point Symbol position.
86    * @param attributes Symbol attributes.
87    * @param hintForNextPoint Hint for the next point. Will be delivered
88    * unchanged in the return <tt>Symbol</tt> object.
89    * @param hintFromPreviousCurve Hint from the previous curve.
90    * Will be delivered unchanged in the return <tt>Symbol</tt> object.
91    * Subclasses may override this behavior.
92    */

93   protected Symbol createSymbol(GraphPoint point, GraphicAttributes attributes,
94                                 Hint hintForNextPoint,
95                                 Hint hintFromPreviousCurve) {
96     return new Symbol(createPlainSymbol(point, _size, attributes),
97                       hintForNextPoint, hintFromPreviousCurve);
98   }
99
100   /**
101    * Creates a symbol for the legend at the specified position.
102    * Uses {@link #createPlainSymbol createPlainSymbol()}
103    * @param centerPosition Center position of the symbol.
104    * @param size The size of the symbol. Will be ignored because the value
105    * given in the constructor will be used.
106    */

107   public GraphicalElement createLegendSymbol(GraphPoint centerPosition,
108                                              double size) {
109     return createPlainSymbol(centerPosition, _size, _attributes);
110   }
111
112   /**
113    * Creates the graphical element of the plain symbol.
114    * @param centerPosition Center position of the symbol.
115    * @param size The size of the symbol.
116    * @param attributes The attributes of the symbol.
117    */

118   protected abstract GraphicalElement createPlainSymbol(
119       GraphPoint centerPosition, double size, GraphicAttributes attributes);
120 }
121
Popular Tags