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