KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > plot > PlotCanvas


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.data.DataPlot;
22 import jcckit.graphic.Anchor;
23 import jcckit.graphic.ClippingRectangle;
24 import jcckit.util.ConfigParameters;
25
26 /**
27  * An abstract canvas containg a single {@link Plot}.
28  * The canvas is specified by a {@link ClippingRectangle}, called
29  * <em>paper</em>. A horizontal and vertical {@link Anchor} determine
30  * the position of the paper on the actual device.
31  *
32  * @author Franz-Josef Elmer
33  */

34 public class PlotCanvas implements PlotListener {
35   /** Configuration parameter key. */
36   public static final String JavaDoc PAPER_KEY = "paper",
37                              HORIZONTAL_ANCHOR_KEY = "horizontalAnchor",
38                              VERTICAL_ANCHOR_KEY = "verticalAnchor",
39                              PLOT_KEY = "plot";
40   private final ClippingRectangle _paper;
41   private final Anchor _horizontalAnchor;
42   private final Anchor _verticalAnchor;
43   private final Plot _plot;
44
45   /**
46    * Creates an instance from the specified configuration parameters.
47    * <table border=1 cellpadding=5>
48    * <tr><th>Key &amp; Default Value</th><th>Type</th><th>Mandatory</th>
49    * <th>Description</th></tr>
50    * <tr><td><tt>horizontalAnchor = center</tt></td>
51    * <td><tt>String</tt></td><td>no</td>
52    * <td>Horizontal position of the paper relative to the device
53    * border. Possible values are <tt>left</tt>, <tt>center</tt>,
54    * and <tt>right</tt>.</td></tr>
55    * <tr><td><tt>paper = 0,&nbsp;0,&nbsp;1,&nbsp;0.6</tt></td>
56    * <td><tt>double[]</tt></td><td>no</td>
57    * <td>Rectangle defining the paper. The first two values determine
58    * the x- and y- coordinates (in device-independent units)
59    * of the lower-left corner. The last two values determine the
60    * upper-right corner.</td></tr>
61    * <tr><td><tt>plot = </tt>default values of {@link Plot}</td>
62    * <td><tt>ConfigParameters</tt></td><td>no</td>
63    * <td>Definition of the {@link Plot}.</td></tr>
64    * <tr><td><tt>verticalAnchor = center</tt></td>
65    * <td><tt>String</tt></td><td>no</td>
66    * <td>Vertical position of the paper relative to the device
67    * border. Possible values are <tt>top</tt>, <tt>center</tt>,
68    * and <tt>bottom</tt>.</td></tr>
69    * </table>
70    * <p>
71    * Note, that this instance registers itself at the
72    * wrapped {@link Plot} instance.
73    */

74   public PlotCanvas(ConfigParameters config) {
75     double[] paper = config.getDoubleArray(PAPER_KEY,
76                                            new double[] {0, 0, 1, 0.6});
77     _paper = new ClippingRectangle(paper[0], paper[1], paper[2], paper[3]);
78     _horizontalAnchor = Anchor.getHorizontalAnchor(config,
79                                   HORIZONTAL_ANCHOR_KEY, Anchor.CENTER);
80     _verticalAnchor = Anchor.getVerticalAnchor(config,
81                                   VERTICAL_ANCHOR_KEY, Anchor.CENTER);
82     _plot = new Plot(config.getNode(PLOT_KEY));
83     _plot.addPlotListener(this);
84   }
85
86   /** Returns the paper definition. */
87   public ClippingRectangle getPaper() {
88     return _paper;
89   }
90
91   /** Returns the horizontal anchor. */
92   public Anchor getHorizontalAnchor() {
93     return _horizontalAnchor;
94   }
95
96   /** Returns the vertical anchor. */
97   public Anchor getVerticalAnchor() {
98     return _verticalAnchor;
99   }
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
Popular Tags