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