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.data.DataPlot;
022: import jcckit.graphic.Anchor;
023: import jcckit.graphic.ClippingRectangle;
024: import jcckit.util.ConfigParameters;
025:
026: /**
027: * An abstract canvas containg a single {@link Plot}.
028: * The canvas is specified by a {@link ClippingRectangle}, called
029: * <em>paper</em>. A horizontal and vertical {@link Anchor} determine
030: * the position of the paper on the actual device.
031: *
032: * @author Franz-Josef Elmer
033: */
034: public class PlotCanvas implements PlotListener {
035: /** Configuration parameter key. */
036: public static final String PAPER_KEY = "paper",
037: HORIZONTAL_ANCHOR_KEY = "horizontalAnchor",
038: VERTICAL_ANCHOR_KEY = "verticalAnchor", PLOT_KEY = "plot";
039: private final ClippingRectangle _paper;
040: private final Anchor _horizontalAnchor;
041: private final Anchor _verticalAnchor;
042: private final Plot _plot;
043:
044: /**
045: * Creates an instance from the specified configuration parameters.
046: * <table border=1 cellpadding=5>
047: * <tr><th>Key & Default Value</th><th>Type</th><th>Mandatory</th>
048: * <th>Description</th></tr>
049: * <tr><td><tt>horizontalAnchor = center</tt></td>
050: * <td><tt>String</tt></td><td>no</td>
051: * <td>Horizontal position of the paper relative to the device
052: * border. Possible values are <tt>left</tt>, <tt>center</tt>,
053: * and <tt>right</tt>.</td></tr>
054: * <tr><td><tt>paper = 0, 0, 1, 0.6</tt></td>
055: * <td><tt>double[]</tt></td><td>no</td>
056: * <td>Rectangle defining the paper. The first two values determine
057: * the x- and y- coordinates (in device-independent units)
058: * of the lower-left corner. The last two values determine the
059: * upper-right corner.</td></tr>
060: * <tr><td><tt>plot = </tt>default values of {@link Plot}</td>
061: * <td><tt>ConfigParameters</tt></td><td>no</td>
062: * <td>Definition of the {@link Plot}.</td></tr>
063: * <tr><td><tt>verticalAnchor = center</tt></td>
064: * <td><tt>String</tt></td><td>no</td>
065: * <td>Vertical position of the paper relative to the device
066: * border. Possible values are <tt>top</tt>, <tt>center</tt>,
067: * and <tt>bottom</tt>.</td></tr>
068: * </table>
069: * <p>
070: * Note, that this instance registers itself at the
071: * wrapped {@link Plot} instance.
072: */
073: public PlotCanvas(ConfigParameters config) {
074: double[] paper = config.getDoubleArray(PAPER_KEY, new double[] {
075: 0, 0, 1, 0.6 });
076: _paper = new ClippingRectangle(paper[0], paper[1], paper[2],
077: paper[3]);
078: _horizontalAnchor = Anchor.getHorizontalAnchor(config,
079: HORIZONTAL_ANCHOR_KEY, Anchor.CENTER);
080: _verticalAnchor = Anchor.getVerticalAnchor(config,
081: VERTICAL_ANCHOR_KEY, Anchor.CENTER);
082: _plot = new Plot(config.getNode(PLOT_KEY));
083: _plot.addPlotListener(this );
084: }
085:
086: /** Returns the paper definition. */
087: public ClippingRectangle getPaper() {
088: return _paper;
089: }
090:
091: /** Returns the horizontal anchor. */
092: public Anchor getHorizontalAnchor() {
093: return _horizontalAnchor;
094: }
095:
096: /** Returns the vertical anchor. */
097: public Anchor getVerticalAnchor() {
098: return _verticalAnchor;
099: }
100:
101: /** Returns the plot. */
102: public Plot getPlot() {
103: return _plot;
104: }
105:
106: /**
107: * Connects the wrapped {@link Plot} instance with the specified
108: * {@link DataPlot}.
109: * @param dataPlot Data to be connected with this plot canvas.
110: * Can be <tt>null</tt> in order to disconnect this instance from
111: * a <tt>DataPlot</tt>.
112: */
113: public void connect(DataPlot dataPlot) {
114: _plot.connect(dataPlot);
115: }
116:
117: /**
118: * Handles the spcified event. Here nothing is done. But
119: * subclass may override this method.
120: */
121: public void plotChanged(PlotEvent event) {
122: }
123: }
|