KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > Marker


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * -----------
23  * Marker.java
24  * -----------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Nicolas Brodu;
29  *
30  * $Id: Marker.java,v 1.9 2003/11/05 11:26:19 mungady Exp $
31  *
32  * Changes (since 2-Jul-2002)
33  * --------------------------
34  * 02-Jul-2002 : Added extra constructor, standard header and Javadoc comments (DG);
35  * 20-Aug-2002 : Added the outline stroke attribute (DG);
36  * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
37  * 16-Oct-2002 : Added new constructor (DG);
38  * 26-Mar-2003 : Implemented Serializable (DG);
39  * 21-May-2003 : Added labels (DG);
40  * 11-Sep-2003 : Implemented Cloneable (NB);
41  * 05-Nov-2003 : Added checks to ensure some attributes are never null (DG);
42  *
43  */

44
45 package org.jfree.chart;
46
47 import java.awt.Color JavaDoc;
48 import java.awt.Font JavaDoc;
49 import java.awt.Paint JavaDoc;
50 import java.awt.Stroke JavaDoc;
51 import java.io.IOException JavaDoc;
52 import java.io.ObjectInputStream JavaDoc;
53 import java.io.ObjectOutputStream JavaDoc;
54 import java.io.Serializable JavaDoc;
55
56 import org.jfree.io.SerialUtilities;
57 import org.jfree.util.ObjectUtils;
58
59 /**
60  * A constant value that is drawn on a chart as a marker, usually as a horizontal or a vertical
61  * line.
62  * <P>
63  * In addition to a value, this class defines paint attributes to give some control over the
64  * appearance of the marker. The renderer can, however, override these settings if it chooses.
65  *
66  * @author David Gilbert
67  */

68 public class Marker implements Serializable JavaDoc, Cloneable JavaDoc {
69
70     /** The constant value. */
71     private double value;
72
73     /** The outline paint. */
74     private transient Paint JavaDoc outlinePaint;
75
76     /** The outline stroke. */
77     private transient Stroke JavaDoc outlineStroke;
78
79     /** The paint. */
80     private transient Paint JavaDoc paint;
81
82     /** The alpha transparency. */
83     private float alpha;
84
85     /** The label. */
86     private String JavaDoc label = null;
87
88     /** The label font. */
89     private Font JavaDoc labelFont;
90
91     /** The label paint. */
92     private transient Paint JavaDoc labelPaint;
93
94     /** The label position. */
95     private MarkerLabelPosition labelPosition = MarkerLabelPosition.TOP_LEFT;
96
97     /**
98      * Constructs a new marker.
99      *
100      * @param value the value.
101      */

102     public Marker(double value) {
103         this(value, Color.gray, new java.awt.BasicStroke JavaDoc(0.5f), Color.gray, 0.80f);
104     }
105
106     /**
107      * Constructs a new marker.
108      *
109      * @param value the value.
110      * @param outlinePaint the paint.
111      */

112     public Marker(double value, Paint JavaDoc outlinePaint) {
113         this(value, outlinePaint, new java.awt.BasicStroke JavaDoc(0.5f), Color.red, 0.80f);
114     }
115
116     /**
117      * Constructs a new marker.
118      *
119      * @param value the value.
120      * @param outlinePaint the outline paint (<code>null</code> not permitted).
121      * @param outlineStroke the outline stroke (<code>null</code> not permitted).
122      * @param paint the paint (<code>null</code> not permitted).
123      * @param alpha the alpha transparency.
124      */

125     public Marker(double value, Paint JavaDoc outlinePaint, Stroke JavaDoc outlineStroke,
126                   Paint JavaDoc paint, float alpha) {
127
128         // check arguments...
129
if (outlinePaint == null) {
130             throw new IllegalArgumentException JavaDoc("Marker(...) : null outlinePaint not permitted.");
131         }
132         if (outlineStroke == null) {
133             throw new IllegalArgumentException JavaDoc("Marker(...) : null outlineStroke not permitted.");
134         }
135         if (paint == null) {
136             throw new IllegalArgumentException JavaDoc("Marker(...) : null paint not permitted.");
137         }
138         
139         this.value = value;
140         this.outlinePaint = outlinePaint;
141         this.outlineStroke = outlineStroke;
142         this.paint = paint;
143         this.alpha = alpha;
144         
145         this.labelFont = new Font JavaDoc("SansSerif", Font.PLAIN, 9);
146         this.labelPaint = Color.black;
147         
148     }
149
150     /**
151      * Returns the value.
152      *
153      * @return the value.
154      */

155     public double getValue() {
156         return this.value;
157     }
158
159     /**
160      * Returns the outline paint.
161      *
162      * @return the outline paint.
163      */

164     public Paint JavaDoc getOutlinePaint() {
165         return this.outlinePaint;
166     }
167
168     /**
169      * Returns the outline stroke.
170      *
171      * @return the outline stroke.
172      */

173     public Stroke JavaDoc getOutlineStroke() {
174         return this.outlineStroke;
175     }
176
177     /**
178      * Returns the paint.
179      *
180      * @return the paint.
181      */

182     public Paint JavaDoc getPaint() {
183         return this.paint;
184     }
185
186     /**
187      * Returns the alpha transparency.
188      *
189      * @return the alpha transparency.
190      */

191     public float getAlpha() {
192         return this.alpha;
193     }
194
195     /**
196      * Returns the label (if <code>null</code> no label is displayed).
197      *
198      * @return The label (possibly <code>null</code>).
199      */

200     public String JavaDoc getLabel() {
201         return this.label;
202     }
203
204     /**
205      * Sets the label (if <code>null</code> no label is displayed).
206      *
207      * @param label the label (<code>null</code> permitted).
208      */

209     public void setLabel(String JavaDoc label) {
210         this.label = label;
211     }
212
213     /**
214      * Returns the label font.
215      *
216      * @return the label font (never <code>null</code>).
217      */

218     public Font JavaDoc getLabelFont() {
219         return this.labelFont;
220     }
221
222     /**
223      * Sets the label font.
224      *
225      * @param font the font (<code>null</code> not permitted).
226      */

227     public void setLabelFont(Font JavaDoc font) {
228         if (paint == null) {
229             throw new IllegalArgumentException JavaDoc("Marker.setLabelFont(...): null not permitted.");
230         }
231         this.labelFont = font;
232     }
233
234     /**
235      * Returns the label paint.
236      *
237      * @return the label paint (never </code>null</code>).
238      */

239     public Paint JavaDoc getLabelPaint() {
240         return this.labelPaint;
241     }
242
243     /**
244      * Sets the label paint.
245      *
246      * @param paint the paint (<code>null</code> not permitted).
247      */

248     public void setLabelPaint(Paint JavaDoc paint) {
249         if (paint == null) {
250             throw new IllegalArgumentException JavaDoc("Marker.setLabelPaint(...): null not permitted.");
251         }
252         this.labelPaint = paint;
253     }
254
255     /**
256      * Returns the label position.
257      *
258      * @return The label position.
259      */

260     public MarkerLabelPosition getLabelPosition() {
261         return this.labelPosition;
262     }
263
264     /**
265      * Sets the label position.
266      *
267      * @param position the position.
268      */

269     public void setLabelPosition(MarkerLabelPosition position) {
270         this.labelPosition = position;
271     }
272
273     /**
274      * Tests an object for equality with this instance.
275      *
276      * @param object the object to test.
277      *
278      * @return A boolean.
279      */

280     public boolean equals(Object JavaDoc object) {
281         
282         if (object == null) {
283             return false;
284         }
285         
286         if (object == this) {
287             return true;
288         }
289         
290         if (object instanceof Marker) {
291             Marker marker = (Marker) object;
292             boolean b0 = (this.value == marker.value);
293             boolean b1 = ObjectUtils.equal(this.outlinePaint, marker.outlinePaint);
294             boolean b2 = ObjectUtils.equal(this.outlineStroke, marker.outlineStroke);
295             boolean b3 = ObjectUtils.equal(this.paint, marker.paint);
296             boolean b4 = (this.alpha == marker.alpha);
297             boolean b5 = ObjectUtils.equal(this.label, marker.label);
298             boolean b6 = ObjectUtils.equal(this.labelFont, marker.labelFont);
299             boolean b7 = ObjectUtils.equal(this.labelPaint, marker.labelPaint);
300             boolean b8 = (this.labelPosition == marker.labelPosition);
301
302             return b0 && b1 && b2 && b3 && b4 && b5 && b6 && b7 && b8;
303         }
304         
305         return false;
306             
307     }
308     
309     /**
310      * Provides serialization support.
311      *
312      * @param stream the output stream.
313      *
314      * @throws IOException if there is an I/O error.
315      */

316     private void writeObject(ObjectOutputStream JavaDoc stream) throws IOException JavaDoc {
317
318         stream.defaultWriteObject();
319         SerialUtilities.writePaint(this.outlinePaint, stream);
320         SerialUtilities.writeStroke(this.outlineStroke, stream);
321         SerialUtilities.writePaint(this.paint, stream);
322
323     }
324
325     /**
326      * Provides serialization support.
327      *
328      * @param stream the input stream.
329      *
330      * @throws IOException if there is an I/O error.
331      * @throws ClassNotFoundException if there is a classpath problem.
332      */

333     private void readObject(ObjectInputStream JavaDoc stream) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
334
335         stream.defaultReadObject();
336         this.outlinePaint = SerialUtilities.readPaint(stream);
337         this.outlineStroke = SerialUtilities.readStroke(stream);
338         this.paint = SerialUtilities.readPaint(stream);
339
340     }
341
342 }
343
Popular Tags