001: /*
002: JOpenChart Java Charting Library and Toolkit
003: Copyright (C) 2001 Sebastian Müller
004: http://jopenchart.sourceforge.net
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: ChartRenderer.java
021: Created on 26. Juni 2001, 22:52
022: */
023:
024: package de.progra.charting.render;
025:
026: import java.awt.Rectangle;
027: import de.progra.charting.CoordSystem;
028: import java.awt.geom.AffineTransform;
029: import java.awt.Shape;
030: import de.progra.charting.PointToPixelTranslator;
031: import java.awt.Graphics2D;
032: import java.awt.Dimension;
033: import de.progra.charting.model.ChartDataModel;
034:
035: /**
036: * This class is the superclass for all the different ChartRenderer.
037: * @author mueller
038: * @version 1.0
039: */
040: public abstract class AbstractChartRenderer implements Renderer {
041:
042: protected Rectangle bounds;
043:
044: protected CoordSystem coord;
045:
046: protected PointToPixelTranslator p;
047:
048: protected ChartDataModel model;
049:
050: protected RowColorModel rcm;
051:
052: /** Creates new AbstractChartRenderer
053: * @param model the DataModel that should be rendered
054: */
055: protected AbstractChartRenderer(ChartDataModel model) {
056: this .model = model;
057: }
058:
059: /** Creates new AbstractChartRenderer
060: * @param rcm the RowColorModel that defines the correspondence between row titles and colors
061: * @param p the Object used to translate values into points
062: * @param model the DataModel that should be rendered
063: * @deprecated Use the constructor
064: <code>AbstractChartRenderer(CoordSystem cs,
065: ChartDataModel model)</code>
066: * instead.
067: */
068: public AbstractChartRenderer(PointToPixelTranslator p,
069: ChartDataModel model) {
070: this (model);
071: this .p = p;
072: }
073:
074: /** Creates new AbstractChartRenderer
075: * @param cs the CoordSystem which contains the AffineTransforms to translate
076: * into pixel space
077: * @param rcm the RowColorModel that defines the correspondence between row titles and colors
078: * @param model the DataModel that should be rendered
079: */
080: public AbstractChartRenderer(CoordSystem cs, ChartDataModel model) {
081: this (model);
082: this .coord = cs;
083: }
084:
085: /** Gets the bounds for this renderer.
086: * @return the bounds of this renderer. If <code>setBounds</code> has not
087: * been called before, the bounds computed from
088: * <code>getPreferredSize</code> is returned.
089: */
090: public Rectangle getBounds() {
091: return bounds;
092: }
093:
094: /** Returns the preferred size needed for the renderer.
095: * @return a non-null Dimension object
096: */
097: public Dimension getPreferredSize() {
098: return new Dimension(Integer.MIN_VALUE, Integer.MIN_VALUE);
099: }
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 g) {
108: Rectangle bounds = getBounds();
109: Shape clip = g.getClip();
110: g.setClip((int) bounds.getX(), (int) bounds.getY(),
111: (int) bounds.getWidth(), (int) bounds.getHeight());
112: renderChart(g);
113: g.setClip(clip);
114: }
115:
116: /** Finally renders the chart in the clipped rectangle. */
117: public abstract void renderChart(Graphics2D g);
118:
119: /** Sets the bounds the layout manager has assigned to
120: * this renderer. Those, of course, have to be
121: * considered in the rendering process.
122: * @param bounds the new bounds for the renderer.
123: */
124: public void setBounds(Rectangle bounds) {
125: this .bounds = bounds;
126: }
127:
128: /** Sets the ChartDataModel whose DataSets are rendered.
129: * @param model the ChartDataModel
130: */
131: public void setChartDataModel(ChartDataModel model) {
132: this .model = model;
133: }
134:
135: /** Returns the ChartDataModel whose DataSets are rendered.
136: * @return a ChartDataModel which contains the Chart's data
137: */
138: public ChartDataModel getChartDataModel() {
139: return model;
140: }
141:
142: /** Sets the PointToPixelTranslator.
143: * @param p the PointToPixelTranslator
144: * @deprecated Has been made obsolete by using AffineTransforms
145: */
146: public void setPointToPixelTranslator(PointToPixelTranslator p) {
147: this .p = p;
148: }
149:
150: /** Returns the PointToPixelTranslator.
151: * @return the PointToPixelTranslator currently in use
152: * @deprecated Has been made obsolete by using AffineTransforms
153: */
154: public PointToPixelTranslator getPointToPixelTranslator() {
155: return p;
156: }
157:
158: /** Returns the current CoordSystem. */
159: public CoordSystem getCoordSystem() {
160: return coord;
161: }
162:
163: /** Sets the CoordSystem which contains the AffineTransforms to
164: * translate into pixel space.
165: * @param cs the new CoordSystem
166: */
167: public void setCoordSystem(CoordSystem cs) {
168: coord = cs;
169: }
170:
171: /** Returns the currently defined AffineTransform for any y-axis.
172: * @param axis the y-axis to be used.
173: */
174: public AffineTransform getTransform(int axis) {
175: return getCoordSystem().getTransform(axis);
176: }
177:
178: /** Sets a RowColorModel to define the correlation of row titles and colors used for the Legend.
179: * @param rcm the RowColorModel
180: */
181: public void setRowColorModel(RowColorModel rcm) {
182: this .rcm = rcm;
183: }
184:
185: /** Returns the RowColorModel currently in use.
186: * @return a RowColorModel
187: */
188: public RowColorModel getRowColorModel() {
189: return rcm;
190: }
191: }
|