001: /*
002: * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
003: *
004: * This library is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2.1 of the License, or
007: * (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details
013: * (http://www.gnu.org/copyleft/lesser.html).
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package jcckit.plot;
020:
021: import jcckit.graphic.GraphPoint;
022: import jcckit.graphic.GraphicAttributes;
023: import jcckit.graphic.GraphicalElement;
024: import jcckit.util.ConfigParameters;
025: import jcckit.util.Factory;
026:
027: /**
028: * Abstract superclass of all {@link SymbolFactory SymbolFactories}.
029: * Subclasses have to implement {@link #createPlainSymbol createPlainSymbol()}.
030: *
031: * @author Franz-Josef Elmer
032: */
033: public abstract class AbstractSymbolFactory implements SymbolFactory {
034: /** Size of all symbols. */
035: protected final double _size;
036:
037: /** Attributes of all symbols. */
038: protected final GraphicAttributes _attributes;
039:
040: /**
041: * Creates an instance from the specified configuration parameters.
042: * <table border=1 cellpadding=5>
043: * <tr><th>Key & Default Value</th><th>Type</th><th>Mandatory</th>
044: * <th>Description</th></tr>
045: * <tr><td><tt>size = </tt>0.01</td>
046: * <td><tt>double</tt></td><td>no</td>
047: * <td>Size of the symbol in device-independent units.</td></tr>
048: * <tr><td><tt>attributes</tt></td>
049: * <td><tt>ConfigParameters</tt></td><td>no</td>
050: * <td>Configuration parameters for the attributes of the symbol.
051: * <tt>className</tt> has to be a class which is an instance of
052: * {@link GraphicAttributes}.</td></tr>
053: * </table>
054: */
055: public AbstractSymbolFactory(ConfigParameters config) {
056: _size = config.getDouble(SIZE_KEY, DEFAULT_SIZE);
057: _attributes = (GraphicAttributes) Factory.createOrGet(config
058: .getNode(ATTRIBUTES_KEY), null);
059: }
060:
061: /**
062: * Creates a symbol.
063: * Evaluate <tt>hintFromPreviousPoint</tt> if it is a {@link AttributesHint}.
064: * Calls {@link #createSymbol(GraphPoint, GraphicAttributes, Hint, Hint)}.
065: * @param point Symbol position.
066: * @param hintFromPreviousPoint Hint from the previous point.
067: * @param hintFromPreviousCurve Hint from the previous curve.
068: */
069: public Symbol createSymbol(GraphPoint point,
070: Hint hintFromPreviousPoint, Hint hintFromPreviousCurve) {
071: GraphicAttributes attributes = _attributes;
072: Hint hintForNextPoint = hintFromPreviousPoint;
073: if (hintFromPreviousPoint instanceof AttributesHint) {
074: attributes = ((AttributesHint) hintFromPreviousPoint)
075: .getAttributes();
076: hintForNextPoint = ((AttributesHint) hintFromPreviousPoint)
077: .getNextHint();
078: }
079: return createSymbol(point, attributes, hintForNextPoint,
080: hintFromPreviousCurve);
081: }
082:
083: /**
084: * Creates a symbol.
085: * Uses {@link #createPlainSymbol createPlainSymbol()}.
086: * @param point Symbol position.
087: * @param attributes Symbol attributes.
088: * @param hintForNextPoint Hint for the next point. Will be delivered
089: * unchanged in the return <tt>Symbol</tt> object.
090: * @param hintFromPreviousCurve Hint from the previous curve.
091: * Will be delivered unchanged in the return <tt>Symbol</tt> object.
092: * Subclasses may override this behavior.
093: */
094: protected Symbol createSymbol(GraphPoint point,
095: GraphicAttributes attributes, Hint hintForNextPoint,
096: Hint hintFromPreviousCurve) {
097: return new Symbol(createPlainSymbol(point, _size, attributes),
098: hintForNextPoint, hintFromPreviousCurve);
099: }
100:
101: /**
102: * Creates a symbol for the legend at the specified position.
103: * Uses {@link #createPlainSymbol createPlainSymbol()}
104: * @param centerPosition Center position of the symbol.
105: * @param size The size of the symbol. Will be ignored because the value
106: * given in the constructor will be used.
107: */
108: public GraphicalElement createLegendSymbol(
109: GraphPoint centerPosition, double size) {
110: return createPlainSymbol(centerPosition, _size, _attributes);
111: }
112:
113: /**
114: * Creates the graphical element of the plain symbol.
115: * @param centerPosition Center position of the symbol.
116: * @param size The size of the symbol.
117: * @param attributes The attributes of the symbol.
118: */
119: protected abstract GraphicalElement createPlainSymbol(
120: GraphPoint centerPosition, double size,
121: GraphicAttributes attributes);
122: }
|