KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > ChartRenderingInfo


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -----------------------
27  * ChartRenderingInfo.java
28  * -----------------------
29  * (C) Copyright 2002-2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: ChartRenderingInfo.java,v 1.4 2005/05/19 15:40:56 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 22-Jan-2002 : Version 1 (DG);
39  * 05-Feb-2002 : Added a new constructor, completed Javadoc comments (DG);
40  * 05-Mar-2002 : Added a clear() method (DG);
41  * 23-May-2002 : Renamed DrawInfo --> ChartRenderingInfo (DG);
42  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
43  * 17-Sep-2003 : Added PlotRenderingInfo (DG);
44  *
45  */

46
47 package org.jfree.chart;
48
49 import java.awt.geom.Rectangle2D JavaDoc;
50 import java.io.IOException JavaDoc;
51 import java.io.ObjectInputStream JavaDoc;
52 import java.io.ObjectOutputStream JavaDoc;
53 import java.io.Serializable JavaDoc;
54
55 import org.jfree.chart.entity.EntityCollection;
56 import org.jfree.chart.entity.StandardEntityCollection;
57 import org.jfree.chart.plot.PlotRenderingInfo;
58 import org.jfree.io.SerialUtilities;
59 import org.jfree.util.ObjectUtilities;
60
61 /**
62  * A structure for storing rendering information from one call to the
63  * JFreeChart.draw() method.
64  * <P>
65  * An instance of the {@link JFreeChart} class can draw itself within an
66  * arbitrary rectangle on any <code>Graphics2D</code>. It is assumed that
67  * client code will sometimes render the same chart in more than one view, so
68  * the {@link JFreeChart} instance does not retain any information about its
69  * rendered dimensions. This information can be useful sometimes, so you have
70  * the option to collect the information at each call to
71  * <code>JFreeChart.draw()</code>, by passing an instance of this
72  * <code>ChartRenderingInfo</code> class.
73  */

74 public class ChartRenderingInfo implements Cloneable JavaDoc, Serializable JavaDoc {
75
76     /** For serialization. */
77     private static final long serialVersionUID = 2751952018173406822L;
78     
79     /** The area in which the chart is drawn. */
80     private transient Rectangle2D JavaDoc chartArea;
81
82     /** Rendering info for the chart's plot (and subplots, if any). */
83     private PlotRenderingInfo plotInfo;
84     
85     /** The area in which the plot and axes are drawn. */
86     private transient Rectangle2D JavaDoc plotArea;
87
88     /**
89      * Storage for the chart entities. Since retaining entity information for
90      * charts with a large number of data points consumes a lot of memory, it
91      * is intended that you can set this to <code>null</code> to prevent the
92      * information being collected.
93      */

94     private EntityCollection entities;
95
96     /**
97      * Constructs a new ChartRenderingInfo structure that can be used to
98      * collect information about the dimensions of a rendered chart.
99      */

100     public ChartRenderingInfo() {
101         this(new StandardEntityCollection());
102     }
103
104     /**
105      * Constructs a new instance. If an entity collection is supplied, it will
106      * be populated with information about the entities in a chart. If it is
107      * <code>null</code>, no entity information (including tool tips) will
108      * be collected.
109      *
110      * @param entities an entity collection (<code>null</code> permitted).
111      */

112     public ChartRenderingInfo(EntityCollection entities) {
113         this.chartArea = new Rectangle2D.Double JavaDoc();
114         this.plotArea = new Rectangle2D.Double JavaDoc();
115         this.plotInfo = new PlotRenderingInfo(this);
116         this.entities = entities;
117     }
118
119     /**
120      * Returns the area in which the chart was drawn.
121      *
122      * @return The area in which the chart was drawn.
123      */

124     public Rectangle2D JavaDoc getChartArea() {
125         return this.chartArea;
126     }
127
128     /**
129      * Sets the area in which the chart was drawn.
130      *
131      * @param area the chart area.
132      */

133     public void setChartArea(Rectangle2D JavaDoc area) {
134         this.chartArea.setRect(area);
135     }
136
137     /**
138      * Returns the area in which the plot (and axes, if any) were drawn.
139      *
140      * @return The plot area.
141      */

142     public Rectangle2D JavaDoc getPlotArea() {
143         return this.plotArea;
144     }
145
146     /**
147      * Sets the area in which the plot and axes were drawn.
148      *
149      * @param area the plot area.
150      */

151     public void setPlotArea(Rectangle2D JavaDoc area) {
152         this.plotArea.setRect(area);
153     }
154
155     /**
156      * Returns the collection of entities maintained by this instance.
157      *
158      * @return The entity collection (possibly <code>null</code>.
159      */

160     public EntityCollection getEntityCollection() {
161         return this.entities;
162     }
163
164     /**
165      * Sets the entity collection.
166      *
167      * @param entities the entity collection (<code>null</code> permitted).
168      */

169     public void setEntityCollection(EntityCollection entities) {
170         this.entities = entities;
171     }
172
173     /**
174      * Clears the information recorded by this object.
175      */

176     public void clear() {
177
178         this.chartArea.setRect(0.0, 0.0, 0.0, 0.0);
179         this.plotArea.setRect(0.0, 0.0, 0.0, 0.0);
180         this.plotInfo = new PlotRenderingInfo(this);
181         if (this.entities != null) {
182             this.entities.clear();
183         }
184
185     }
186   
187     /**
188      * Returns the rendering info for the chart's plot.
189      *
190      * @return The rendering info for the plot.
191      */

192     public PlotRenderingInfo getPlotInfo() {
193         return this.plotInfo;
194     }
195     
196     /**
197      * Tests this object for equality with an arbitrary object.
198      *
199      * @param obj the object to test against (<code>null</code> permitted).
200      *
201      * @return A boolean.
202      */

203     public boolean equals(Object JavaDoc obj) {
204         if (obj == this) {
205             return true;
206         }
207         if (obj instanceof ChartRenderingInfo) {
208             ChartRenderingInfo cri = (ChartRenderingInfo) obj;
209             if (!ObjectUtilities.equal(this.chartArea, cri.chartArea)) {
210                 return false;
211             }
212             return true;
213         }
214         return false;
215     }
216     
217     /**
218      * Returns a clone of this object.
219      *
220      * @return A clone.
221      *
222      * @throws CloneNotSupportedException if the object cannot be cloned.
223      */

224     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
225         return super.clone();
226     }
227
228     /**
229      * Provides serialization support.
230      *
231      * @param stream the output stream.
232      *
233      * @throws IOException if there is an I/O error.
234      */

235     private void writeObject(ObjectOutputStream JavaDoc stream) throws IOException JavaDoc {
236         stream.defaultWriteObject();
237         SerialUtilities.writeShape(this.chartArea, stream);
238         SerialUtilities.writeShape(this.plotArea, stream);
239     }
240
241     /**
242      * Provides serialization support.
243      *
244      * @param stream the input stream.
245      *
246      * @throws IOException if there is an I/O error.
247      * @throws ClassNotFoundException if there is a classpath problem.
248      */

249     private void readObject(ObjectInputStream JavaDoc stream)
250         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
251         stream.defaultReadObject();
252         this.chartArea = (Rectangle2D JavaDoc) SerialUtilities.readShape(stream);
253         this.plotArea = (Rectangle2D JavaDoc) SerialUtilities.readShape(stream);
254     }
255         
256 }
257
Popular Tags