KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > progra > charting > AbstractChart


1 /*
2     JOpenChart Java Charting Library and Toolkit
3     Copyright (C) 2001 Sebastian Müller
4     http://jopenchart.sourceforge.net
5
6     This library is free software; you can redistribute it and/or
7     modify it under the terms of the GNU Lesser General Public
8     License as published by the Free Software Foundation; either
9     version 2.1 of the License, or (at your option) any later version.
10
11     This library is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     Lesser General Public License for more details.
15
16     You should have received a copy of the GNU Lesser General Public
17     License along with this library; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  
20     AbstractChart.java
21     Created on 22. Juni 2001, 00:05
22  */

23
24 package de.progra.charting;
25
26 import de.progra.charting.event.ChartDataModelListener;
27 import de.progra.charting.render.AbstractChartRenderer;
28 import de.progra.charting.render.AbstractRenderer;
29 import de.progra.charting.render.RowColorModel;
30 import java.awt.Rectangle JavaDoc;
31 import java.awt.Graphics2D JavaDoc;
32 import de.progra.charting.model.ChartDataModel;
33 import java.util.Map JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36
37 /** Implements the standard getter and setter methods for a chart.
38  * @author mueller
39  * @version 1.0
40  */

41 public abstract class AbstractChart extends AbstractRenderer implements Chart {
42
43     protected HashMap JavaDoc renderer = new HashMap JavaDoc();
44     
45     protected Rectangle JavaDoc bounds;
46     protected Legend legend;
47     protected CoordSystem coord;
48     protected Title title;
49     protected RowColorModel rcModel;
50     
51     protected ChartDataModel model;
52     
53     /** Creates new AbstractChart */
54     public AbstractChart() {
55     }
56
57     /** Adds a ChartRenderer with a specific z-coordinate.
58      * @param render the ChartRenderer
59      * @param z the z-coordinate, the highest coordinate is in front.
60      */

61     public void addChartRenderer(AbstractChartRenderer render, int z) {
62         renderer.put(new Integer JavaDoc(z), render);
63         render.setRowColorModel(rcModel);
64     }
65     
66     /** Returns the Map of all ChartRenderers.
67      * @return a <CODE>java.util.Map</CODE> with all ChartRenderers
68      */

69     public Map JavaDoc getChartRenderer() {
70         return renderer;
71     }
72     
73     /** Returns the ChartRenderer with a specific z-coordinate.
74      * @param z the z-coordinate
75      * @return the ChartRenderer or null.
76      */

77     public AbstractChartRenderer getChartRenderer(int z) {
78         return (AbstractChartRenderer)renderer.get(new Integer JavaDoc(z));
79     }
80     
81     /** Returns the coordinate system.
82      * @return a CoordSystem object or null if there is none.
83      */

84     public CoordSystem getCoordSystem() {
85         return coord;
86     }
87     
88     /** Returns this chart's legend.
89      * @return the Legend object.
90      */

91     public Legend getLegend() {
92         return legend;
93     }
94     
95     /** Returns the title for this chart.
96      * @return a Title object.
97      */

98     public Title getTitle() {
99         return title;
100     }
101     
102     /** Returns the RowColorModel for this chart.
103      * @return a RowColorModel object.
104      */

105     public RowColorModel getRowColorModel() {
106         return rcModel;
107     }
108     
109     /** Sets the Map with all ChartRenderers. The keys
110      * have to be the z-coordinates of the ChartRenderers.
111      * @param render a <CODE>java.util.Map</CODE> with all ChartRenderers.
112      */

113     public void setChartRenderer(Map JavaDoc render) {
114         Iterator JavaDoc i = render.values().iterator();
115         int z = 0;
116         while(i.hasNext()) {
117             addChartRenderer((AbstractChartRenderer)i.next(), z);
118         }
119     }
120     
121     /** Sets the coordinate system for this chart,
122      * which can be null if the ChartRenderer
123      * doesn't need a coordinate system, e.g. if it's a
124      * PieChart.
125      * @param c the CoordSystem object
126      */

127     public void setCoordSystem(CoordSystem c) {
128         coord = c;
129     }
130     
131     /** Sets the legend for this chart.
132      * @param l the Legend
133      */

134     public void setLegend(Legend l) {
135         legend = l;
136     }
137     
138     /** Sets the title for this chart.
139      * @param t the Title object
140      */

141     public void setTitle(Title t) {
142         title = t;
143     }
144     
145     /** Sets the RowColorModel for this chart.
146      * @param rcm the new RowColorModel
147      */

148     public void setRowColorModel(RowColorModel rcm) {
149         this.rcModel = rcm;
150     }
151         
152     /** Stores the ChartDataModel for this Chart.
153      * @param model the ChartDataModel
154      */

155     public void setChartDataModel(ChartDataModel model) {
156         this.model = model;
157     }
158     
159     /** Returns the ChartDataModel.
160      * @return the ChartDataModel for the Chart
161      */

162     public ChartDataModel getChartDataModel() {
163         return model;
164     }
165     
166     /** Sets the Bounds for this Chart. This is important for rendering the chart and
167      * always has to be done before rendering.
168      * @param r the <CODE>Rectangle</CODE> object defining this chart's bounds.
169      */

170     public void setBounds(Rectangle JavaDoc r) {
171         this.bounds = r;
172     }
173     
174     /** Returns the Bounds for the Chart.
175      * @return a <CODE>Rectangle</CODE> object defining this chart's bounds.
176      */

177     public Rectangle JavaDoc getBounds() {
178         return bounds;
179     }
180     
181     /** This method is called by the paint method to do the actual painting.
182      * The painting is supposed to start at point (0,0) and the size is
183      * always the same as the preferred size. The paint method performs
184      * the possible scaling.
185      * @param g the <CODE>Graphics2D</CODE> object to paint in.
186      */

187     public void paintDefault(Graphics2D JavaDoc g) {
188     }
189     
190     /** Does the layout of the title, legend and coordinate system and
191      * calls the render method of all those including the ChartRenderers.
192      * @param g the <CODE>Graphics2D</CODE> object to paint in.
193      */

194     public void render(Graphics2D JavaDoc g) {}
195 }
Popular Tags