KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > progra > charting > render > AbstractChartRenderer


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     ChartRenderer.java
21     Created on 26. Juni 2001, 22:52
22 */

23
24 package de.progra.charting.render;
25
26 import java.awt.Rectangle JavaDoc;
27 import de.progra.charting.CoordSystem;
28 import java.awt.geom.AffineTransform JavaDoc;
29 import java.awt.Shape JavaDoc;
30 import de.progra.charting.PointToPixelTranslator;
31 import java.awt.Graphics2D JavaDoc;
32 import java.awt.Dimension JavaDoc;
33 import de.progra.charting.model.ChartDataModel;
34
35 /**
36  * This class is the superclass for all the different ChartRenderer.
37  * @author mueller
38  * @version 1.0
39  */

40 public abstract class AbstractChartRenderer implements Renderer {
41
42     protected Rectangle JavaDoc bounds;
43     
44     protected CoordSystem coord;
45     
46     protected PointToPixelTranslator p;
47     
48     protected ChartDataModel model;
49   
50     protected RowColorModel rcm;
51     
52     /** Creates new AbstractChartRenderer
53      * @param model the DataModel that should be rendered
54      */

55     protected AbstractChartRenderer(ChartDataModel model) {
56         this.model = model;
57     }
58     
59     /** Creates new AbstractChartRenderer
60      * @param rcm the RowColorModel that defines the correspondence between row titles and colors
61      * @param p the Object used to translate values into points
62      * @param model the DataModel that should be rendered
63      * @deprecated Use the constructor
64         <code>AbstractChartRenderer(CoordSystem cs,
65                                     ChartDataModel model)</code>
66      * instead.
67      */

68     public AbstractChartRenderer(PointToPixelTranslator p, ChartDataModel model) {
69         this(model);
70         this.p = p;
71     }
72     
73     /** Creates new AbstractChartRenderer
74      * @param cs the CoordSystem which contains the AffineTransforms to translate
75      * into pixel space
76      * @param rcm the RowColorModel that defines the correspondence between row titles and colors
77      * @param model the DataModel that should be rendered
78      */

79     public AbstractChartRenderer(CoordSystem cs,
80                                  ChartDataModel model) {
81         this(model);
82         this.coord = cs;
83     }
84
85     /** Gets the bounds for this renderer.
86      * @return the bounds of this renderer. If <code>setBounds</code> has not
87      * been called before, the bounds computed from
88      * <code>getPreferredSize</code> is returned.
89      */

90     public Rectangle JavaDoc getBounds() {
91         return bounds;
92     }
93     
94     /** Returns the preferred size needed for the renderer.
95      * @return a non-null Dimension object
96      */

97     public Dimension JavaDoc getPreferredSize() {
98         return new Dimension JavaDoc(Integer.MIN_VALUE, Integer.MIN_VALUE);
99     }
100     
101     /** Calls <code>renderChart(g)</code> and crops the output to the desired
102      * bounds. This way you can manually set small maximum and minimum values
103      * which automatically gets reflected in the CoordSystem but the ChartRenderer
104      * doesn't need to care.
105      * @param g the Graphics2D object in which to render
106      */

107     public void render(Graphics2D JavaDoc g) {
108         Rectangle JavaDoc bounds = getBounds();
109         Shape JavaDoc clip = g.getClip();
110         g.setClip((int)bounds.getX(), (int)bounds.getY(), (int)bounds.getWidth(), (int)bounds.getHeight());
111         renderChart(g);
112         g.setClip(clip);
113     }
114     
115     /** Finally renders the chart in the clipped rectangle. */
116     public abstract void renderChart(Graphics2D JavaDoc g);
117     
118     /** Sets the bounds the layout manager has assigned to
119      * this renderer. Those, of course, have to be
120      * considered in the rendering process.
121      * @param bounds the new bounds for the renderer.
122      */

123     public void setBounds(Rectangle JavaDoc bounds) {
124         this.bounds = bounds;
125     }
126     
127     /** Sets the ChartDataModel whose DataSets are rendered.
128      * @param model the ChartDataModel
129      */

130     public void setChartDataModel(ChartDataModel model) {
131         this.model = model;
132     }
133     
134     /** Returns the ChartDataModel whose DataSets are rendered.
135      * @return a ChartDataModel which contains the Chart's data
136      */

137     public ChartDataModel getChartDataModel() {
138         return model;
139     }
140     
141     /** Sets the PointToPixelTranslator.
142      * @param p the PointToPixelTranslator
143      * @deprecated Has been made obsolete by using AffineTransforms
144      */

145     public void setPointToPixelTranslator(PointToPixelTranslator p) {
146         this.p = p;
147     }
148     
149     /** Returns the PointToPixelTranslator.
150      * @return the PointToPixelTranslator currently in use
151      * @deprecated Has been made obsolete by using AffineTransforms
152      */

153     public PointToPixelTranslator getPointToPixelTranslator() {
154         return p;
155     }
156     
157     /** Returns the current CoordSystem. */
158     public CoordSystem getCoordSystem() {
159         return coord;
160     }
161     
162     /** Sets the CoordSystem which contains the AffineTransforms to
163      * translate into pixel space.
164      * @param cs the new CoordSystem
165      */

166     public void setCoordSystem(CoordSystem cs) {
167         coord = cs;
168     }
169     
170     /** Returns the currently defined AffineTransform for any y-axis.
171      * @param axis the y-axis to be used.
172      */

173     public AffineTransform JavaDoc getTransform(int axis) {
174         return getCoordSystem().getTransform(axis);
175     }
176     
177     /** Sets a RowColorModel to define the correlation of row titles and colors used for the Legend.
178      * @param rcm the RowColorModel
179      */

180     public void setRowColorModel(RowColorModel rcm) {
181         this.rcm = rcm;
182     }
183     
184     /** Returns the RowColorModel currently in use.
185      * @return a RowColorModel
186      */

187     public RowColorModel getRowColorModel() {
188         return rcm;
189     }
190 }
191
Popular Tags