-
-
Notifications
You must be signed in to change notification settings - Fork 454
/
ChartRenderingInfo.java
244 lines (223 loc) · 7.87 KB
/
ChartRenderingInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2021, by David Gilbert and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* -----------------------
* ChartRenderingInfo.java
* -----------------------
* (C) Copyright 2002-2021, by David Gilbert.
*
* Original Author: David Gilbert;
* Contributor(s): -;
*
*/
package org.jfree.chart;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Objects;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.util.PublicCloneable;
import org.jfree.chart.util.SerialUtils;
/**
* A structure for storing rendering information from one call to the
* JFreeChart.draw() method.
* <P>
* An instance of the {@link JFreeChart} class can draw itself within an
* arbitrary rectangle on any {@code Graphics2D}. It is assumed that
* client code will sometimes render the same chart in more than one view, so
* the {@link JFreeChart} instance does not retain any information about its
* rendered dimensions. This information can be useful sometimes, so you have
* the option to collect the information at each call to
* {@code JFreeChart.draw()}, by passing an instance of this
* {@code ChartRenderingInfo} class.
*/
public class ChartRenderingInfo implements Cloneable, Serializable {
/** For serialization. */
private static final long serialVersionUID = 2751952018173406822L;
/** The area in which the chart is drawn. */
private transient Rectangle2D chartArea;
/** Rendering info for the chart's plot (and subplots, if any). */
private PlotRenderingInfo plotInfo;
/**
* Storage for the chart entities. Since retaining entity information for
* charts with a large number of data points consumes a lot of memory, it
* is intended that you can set this to {@code null} to prevent the
* information being collected.
*/
private EntityCollection entities;
/**
* Constructs a new ChartRenderingInfo structure that can be used to
* collect information about the dimensions of a rendered chart.
*/
public ChartRenderingInfo() {
this(new StandardEntityCollection());
}
/**
* Constructs a new instance. If an entity collection is supplied, it will
* be populated with information about the entities in a chart. If it is
* {@code null}, no entity information (including tool tips) will
* be collected.
*
* @param entities an entity collection ({@code null} permitted).
*/
public ChartRenderingInfo(EntityCollection entities) {
this.chartArea = new Rectangle2D.Double();
this.plotInfo = new PlotRenderingInfo(this);
this.entities = entities;
}
/**
* Returns the area in which the chart was drawn.
*
* @return The area in which the chart was drawn.
*
* @see #setChartArea(Rectangle2D)
*/
public Rectangle2D getChartArea() {
return this.chartArea;
}
/**
* Sets the area in which the chart was drawn.
*
* @param area the chart area.
*
* @see #getChartArea()
*/
public void setChartArea(Rectangle2D area) {
this.chartArea.setRect(area);
}
/**
* Returns the collection of entities maintained by this instance.
*
* @return The entity collection (possibly {@code null}).
*
* @see #setEntityCollection(EntityCollection)
*/
public EntityCollection getEntityCollection() {
return this.entities;
}
/**
* Sets the entity collection.
*
* @param entities the entity collection ({@code null} permitted).
*
* @see #getEntityCollection()
*/
public void setEntityCollection(EntityCollection entities) {
this.entities = entities;
}
/**
* Clears the information recorded by this object.
*/
public void clear() {
this.chartArea.setRect(0.0, 0.0, 0.0, 0.0);
this.plotInfo = new PlotRenderingInfo(this);
if (this.entities != null) {
this.entities.clear();
}
}
/**
* Returns the rendering info for the chart's plot.
*
* @return The rendering info for the plot.
*/
public PlotRenderingInfo getPlotInfo() {
return this.plotInfo;
}
/**
* Tests this object for equality with an arbitrary object.
*
* @param obj the object to test against ({@code null} permitted).
*
* @return A boolean.
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ChartRenderingInfo)) {
return false;
}
ChartRenderingInfo that = (ChartRenderingInfo) obj;
if (!Objects.equals(this.chartArea, that.chartArea)) {
return false;
}
if (!Objects.equals(this.plotInfo, that.plotInfo)) {
return false;
}
if (!Objects.equals(this.entities, that.entities)) {
return false;
}
return true;
}
/**
* Returns a clone of this object.
*
* @return A clone.
*
* @throws CloneNotSupportedException if the object cannot be cloned.
*/
@Override
public ChartRenderingInfo clone() throws CloneNotSupportedException {
ChartRenderingInfo clone = (ChartRenderingInfo) super.clone();
if (this.chartArea != null) {
clone.chartArea = (Rectangle2D) this.chartArea.clone();
}
if (this.entities instanceof PublicCloneable) {
PublicCloneable pc = (PublicCloneable) this.entities;
clone.entities = (EntityCollection) pc.clone();
}
return clone;
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
SerialUtils.writeShape(this.chartArea, stream);
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.chartArea = (Rectangle2D) SerialUtils.readShape(stream);
}
}