1:
42:
43: package ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68:
69:
72: public class CategoryLineAnnotation implements CategoryAnnotation,
73: Cloneable, Serializable {
74:
75:
76: static final long serialVersionUID = 3477740483341587984L;
77:
78:
79: private Comparable category1;
80:
81:
82: private double value1;
83:
84:
85: private Comparable category2;
86:
87:
88: private double value2;
89:
90:
91: private transient Paint paint = Color.black;
92:
93:
94: private transient Stroke stroke = new BasicStroke(1.0f);
95:
96:
107: public CategoryLineAnnotation(Comparable category1, double value1,
108: Comparable category2, double value2,
109: Paint paint, Stroke stroke) {
110: if (category1 == null) {
111: throw new IllegalArgumentException("Null 'category1' argument.");
112: }
113: if (category2 == null) {
114: throw new IllegalArgumentException("Null 'category2' argument.");
115: }
116: if (paint == null) {
117: throw new IllegalArgumentException("Null 'paint' argument.");
118: }
119: if (stroke == null) {
120: throw new IllegalArgumentException("Null 'stroke' argument.");
121: }
122: this.category1 = category1;
123: this.value1 = value1;
124: this.category2 = category2;
125: this.value2 = value2;
126: this.paint = paint;
127: this.stroke = stroke;
128: }
129:
130:
137: public Comparable getCategory1() {
138: return this.category1;
139: }
140:
141:
148: public void setCategory1(Comparable category) {
149: if (category == null) {
150: throw new IllegalArgumentException("Null 'category' argument.");
151: }
152: this.category1 = category;
153: }
154:
155:
162: public double getValue1() {
163: return this.value1;
164: }
165:
166:
173: public void setValue1(double value) {
174: this.value1 = value;
175: }
176:
177:
184: public Comparable getCategory2() {
185: return this.category2;
186: }
187:
188:
195: public void setCategory2(Comparable category) {
196: if (category == null) {
197: throw new IllegalArgumentException("Null 'category' argument.");
198: }
199: this.category2 = category;
200: }
201:
202:
209: public double getValue2() {
210: return this.value2;
211: }
212:
213:
220: public void setValue2(double value) {
221: this.value2 = value;
222: }
223:
224:
231: public Paint getPaint() {
232: return this.paint;
233: }
234:
235:
242: public void setPaint(Paint paint) {
243: if (paint == null) {
244: throw new IllegalArgumentException("Null 'paint' argument.");
245: }
246: this.paint = paint;
247: }
248:
249:
256: public Stroke getStroke() {
257: return this.stroke;
258: }
259:
260:
267: public void setStroke(Stroke stroke) {
268: if (stroke == null) {
269: throw new IllegalArgumentException("Null 'stroke' argument.");
270: }
271: this.stroke = stroke;
272: }
273:
274:
283: public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
284: CategoryAxis domainAxis, ValueAxis rangeAxis) {
285:
286: CategoryDataset dataset = plot.getDataset();
287: int catIndex1 = dataset.getColumnIndex(this.category1);
288: int catIndex2 = dataset.getColumnIndex(this.category2);
289: int catCount = dataset.getColumnCount();
290:
291: double lineX1 = 0.0f;
292: double lineY1 = 0.0f;
293: double lineX2 = 0.0f;
294: double lineY2 = 0.0f;
295: PlotOrientation orientation = plot.getOrientation();
296: RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
297: plot.getDomainAxisLocation(), orientation);
298: RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
299: plot.getRangeAxisLocation(), orientation);
300:
301: if (orientation == PlotOrientation.HORIZONTAL) {
302: lineY1 = domainAxis.getCategoryJava2DCoordinate(
303: CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea,
304: domainEdge);
305: lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
306: lineY2 = domainAxis.getCategoryJava2DCoordinate(
307: CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea,
308: domainEdge);
309: lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
310: }
311: else if (orientation == PlotOrientation.VERTICAL) {
312: lineX1 = domainAxis.getCategoryJava2DCoordinate(
313: CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea,
314: domainEdge);
315: lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
316: lineX2 = domainAxis.getCategoryJava2DCoordinate(
317: CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea,
318: domainEdge);
319: lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
320: }
321: g2.setPaint(this.paint);
322: g2.setStroke(this.stroke);
323: g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2);
324: }
325:
326:
333: public boolean equals(Object obj) {
334: if (obj == this) {
335: return true;
336: }
337: if (!(obj instanceof CategoryLineAnnotation)) {
338: return false;
339: }
340: CategoryLineAnnotation that = (CategoryLineAnnotation) obj;
341: if (!this.category1.equals(that.getCategory1())) {
342: return false;
343: }
344: if (this.value1 != that.getValue1()) {
345: return false;
346: }
347: if (!this.category2.equals(that.getCategory2())) {
348: return false;
349: }
350: if (this.value2 != that.getValue2()) {
351: return false;
352: }
353: if (!PaintUtilities.equal(this.paint, that.paint)) {
354: return false;
355: }
356: if (!ObjectUtilities.equal(this.stroke, that.stroke)) {
357: return false;
358: }
359: return true;
360: }
361:
362:
367: public int hashCode() {
368: int result = 193;
369: result = 37 * result + this.category1.hashCode();
370: long temp = Double.doubleToLongBits(this.value1);
371: result = 37 * result + (int) (temp ^ (temp >>> 32));
372: result = 37 * result + this.category2.hashCode();
373: temp = Double.doubleToLongBits(this.value2);
374: result = 37 * result + (int) (temp ^ (temp >>> 32));
375: result = 37 * result + HashUtilities.hashCodeForPaint(this.paint);
376: result = 37 * result + this.stroke.hashCode();
377: return result;
378: }
379:
380:
388: public Object clone() throws CloneNotSupportedException {
389: return super.clone();
390: }
391:
392:
399: private void writeObject(ObjectOutputStream stream) throws IOException {
400: stream.defaultWriteObject();
401: SerialUtilities.writePaint(this.paint, stream);
402: SerialUtilities.writeStroke(this.stroke, stream);
403: }
404:
405:
413: private void readObject(ObjectInputStream stream)
414: throws IOException, ClassNotFoundException {
415: stream.defaultReadObject();
416: this.paint = SerialUtilities.readPaint(stream);
417: this.stroke = SerialUtilities.readStroke(stream);
418: }
419:
420: }