KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > PlotRenderingInfo


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  * PlotRenderingInfo.java
28  * ----------------------
29  * (C) Copyright 2003, 2004, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: PlotRenderingInfo.java,v 1.5 2005/05/19 14:03:40 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 16-Sep-2003 : Version 1 (DG);
39  * 23-Sep-2003 : Added Javadocs (DG);
40  * 12-Nov-2004 : Added getSubplotCount() and findSubplot() methods (DG);
41  *
42  */

43  
44 package org.jfree.chart.plot;
45
46 import java.awt.geom.Point2D JavaDoc;
47 import java.awt.geom.Rectangle2D JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.io.ObjectInputStream JavaDoc;
50 import java.io.ObjectOutputStream JavaDoc;
51 import java.io.Serializable JavaDoc;
52 import java.util.List JavaDoc;
53
54 import org.jfree.chart.ChartRenderingInfo;
55 import org.jfree.io.SerialUtilities;
56 import org.jfree.util.ObjectUtilities;
57
58 /**
59  * Stores information about the dimensions of a plot and its subplots.
60  */

61 public class PlotRenderingInfo implements Cloneable JavaDoc, Serializable JavaDoc {
62
63     /** For serialization. */
64     private static final long serialVersionUID = 8446720134379617220L;
65     
66     /** The owner of this info. */
67     private transient ChartRenderingInfo owner;
68     
69     /** The plot area. */
70     private transient Rectangle2D JavaDoc plotArea;
71     
72     /** The data area. */
73     private transient Rectangle2D JavaDoc dataArea;
74     
75     /**
76      * Storage for the plot rendering info objects belonging to the subplots.
77      */

78     private List JavaDoc subplotInfo;
79       
80     /**
81      * Default constructor.
82      *
83      * @param owner the owner.
84      */

85     public PlotRenderingInfo(ChartRenderingInfo owner) {
86         this.owner = owner;
87         this.dataArea = new Rectangle2D.Double JavaDoc();
88         this.subplotInfo = new java.util.ArrayList JavaDoc();
89     }
90     
91     /**
92      * Returns the owner.
93      *
94      * @return The owner.
95      */

96     public ChartRenderingInfo getOwner() {
97         return this.owner;
98     }
99     
100     /**
101      * Returns the plot area (in Java2D space).
102      *
103      * @return The plot area.
104      */

105     public Rectangle2D JavaDoc getPlotArea() {
106         return this.plotArea;
107     }
108     
109     /**
110      * Sets the plot area.
111      *
112      * @param area the plot area (in Java2D space)
113      */

114     public void setPlotArea(Rectangle2D JavaDoc area) {
115         this.plotArea = area;
116     }
117     
118     /**
119      * Returns the plot's data area (in Java2D space).
120      *
121      * @return The data area.
122      */

123     public Rectangle2D JavaDoc getDataArea() {
124         return this.dataArea;
125     }
126     
127     /**
128      * Sets the data area.
129      *
130      * @param area the data area (in Java2D space).
131      */

132     public void setDataArea(Rectangle2D JavaDoc area) {
133         this.dataArea = area;
134     }
135     
136     /**
137      * Returns the number of subplots.
138      *
139      * @return The subplot count.
140      */

141     public int getSubplotCount() {
142         return this.subplotInfo.size();
143     }
144     
145     /**
146      * Adds the info for a subplot.
147      *
148      * @param info the subplot info.
149      */

150     public void addSubplotInfo(PlotRenderingInfo info) {
151         this.subplotInfo.add(info);
152     }
153     
154     /**
155      * Returns the info for a subplot.
156      *
157      * @param index the subplot index.
158      *
159      * @return The info.
160      */

161     public PlotRenderingInfo getSubplotInfo(int index) {
162         return (PlotRenderingInfo) this.subplotInfo.get(index);
163     }
164     
165     /**
166      * Returns the index of the subplot that contains the specified
167      * (x, y) point (the "source" point). The source point will usually
168      * come from a mouse click on a {@link org.jfree.chart.ChartPanel},
169      * and this method is then used to determine the subplot that
170      * contains the source point.
171      *
172      * @param source the source point (in Java2D space).
173      *
174      * @return The subplot index (or -1 if no subplot contains the point).
175      */

176     public int getSubplotIndex(Point2D JavaDoc source) {
177         int subplotCount = getSubplotCount();
178         for (int i = 0; i < subplotCount; i++) {
179             PlotRenderingInfo info = getSubplotInfo(i);
180             Rectangle2D JavaDoc area = info.getDataArea();
181             if (area.contains(source)) {
182                 return i;
183             }
184         }
185         return -1;
186     }
187     
188     /**
189      * Tests this instance for equality against an arbitrary object.
190      *
191      * @param obj the object (<code>null</code> permitted).
192      *
193      * @return A boolean.
194      */

195     public boolean equals(Object JavaDoc obj) {
196         if (this == obj) {
197             return true;
198         }
199         if (!(obj instanceof PlotRenderingInfo)) {
200             return false;
201         }
202         PlotRenderingInfo that = (PlotRenderingInfo) obj;
203         if (!ObjectUtilities.equal(this.dataArea, that.dataArea)) {
204             return false;
205         }
206         if (!ObjectUtilities.equal(this.plotArea, that.plotArea)) {
207             return false;
208         }
209         if (!ObjectUtilities.equal(this.subplotInfo, that.subplotInfo)) {
210             return false;
211         }
212         return true;
213     }
214     
215     /**
216      * Returns a clone of this object.
217      *
218      * @return A clone.
219      *
220      * @throws CloneNotSupportedException if there is a problem cloning.
221      */

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

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

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