001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -------------------
028: * CategoryMarker.java
029: * -------------------
030: * (C) Copyright 2005, 2006, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): Nicolas Brodu;
034: *
035: * $Id: CategoryMarker.java,v 1.1.2.4 2006/10/24 15:39:20 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 20-May-2005 : Version 1 (DG);
040: * 19-Aug-2005 : Implemented equals(), fixed bug in constructor (DG);
041: * ------------- JFREECHART 1.0.x ---------------------------------------------
042: * 05-Sep-2006 : Added MarkerChangeListener support (DG);
043: *
044: */
045:
046: package org.jfree.chart.plot;
047:
048: import java.awt.BasicStroke;
049: import java.awt.Color;
050: import java.awt.Paint;
051: import java.awt.Stroke;
052: import java.io.Serializable;
053:
054: import org.jfree.chart.event.MarkerChangeEvent;
055: import org.jfree.ui.LengthAdjustmentType;
056:
057: /**
058: * A marker for a category.
059: * <br><br>
060: * Note that for serialization to work correctly, the category key must be an
061: * instance of a serializable class.
062: *
063: * @see CategoryPlot#addDomainMarker(CategoryMarker)
064: */
065: public class CategoryMarker extends Marker implements Cloneable,
066: Serializable {
067:
068: /** The category key. */
069: private Comparable key;
070:
071: /**
072: * A hint that the marker should be drawn as a line rather than a region.
073: */
074: private boolean drawAsLine = false;
075:
076: /**
077: * Creates a new category marker for the specified category.
078: *
079: * @param key the category key.
080: */
081: public CategoryMarker(Comparable key) {
082: this (key, Color.gray, new BasicStroke(1.0f));
083: }
084:
085: /**
086: * Creates a new category marker.
087: *
088: * @param key the key.
089: * @param paint the paint (<code>null</code> not permitted).
090: * @param stroke the stroke (<code>null</code> not permitted).
091: */
092: public CategoryMarker(Comparable key, Paint paint, Stroke stroke) {
093: this (key, paint, stroke, paint, stroke, 1.0f);
094: }
095:
096: /**
097: * Creates a new category marker.
098: *
099: * @param key the key.
100: * @param paint the paint (<code>null</code> not permitted).
101: * @param stroke the stroke (<code>null</code> not permitted).
102: * @param outlinePaint the outline paint (<code>null</code> permitted).
103: * @param outlineStroke the outline stroke (<code>null</code> permitted).
104: * @param alpha the alpha transparency.
105: */
106: public CategoryMarker(Comparable key, Paint paint, Stroke stroke,
107: Paint outlinePaint, Stroke outlineStroke, float alpha) {
108: super (paint, stroke, outlinePaint, outlineStroke, alpha);
109: this .key = key;
110: setLabelOffsetType(LengthAdjustmentType.EXPAND);
111: }
112:
113: /**
114: * Returns the key.
115: *
116: * @return The key.
117: */
118: public Comparable getKey() {
119: return this .key;
120: }
121:
122: /**
123: * Sets the key and sends a {@link MarkerChangeEvent} to all registered
124: * listeners.
125: *
126: * @param key the key (<code>null</code> not permitted).
127: *
128: * @since 1.0.3
129: */
130: public void setKey(Comparable key) {
131: if (key == null) {
132: throw new IllegalArgumentException("Null 'key' argument.");
133: }
134: this .key = key;
135: notifyListeners(new MarkerChangeEvent(this ));
136: }
137:
138: /**
139: * Returns the flag that controls whether the marker is drawn as a region
140: * or a line.
141: *
142: * @return A line.
143: */
144: public boolean getDrawAsLine() {
145: return this .drawAsLine;
146: }
147:
148: /**
149: * Sets the flag that controls whether the marker is drawn as a region or
150: * as a line, and sends a {@link MarkerChangeEvent} to all registered
151: * listeners.
152: *
153: * @param drawAsLine the flag.
154: */
155: public void setDrawAsLine(boolean drawAsLine) {
156: this .drawAsLine = drawAsLine;
157: notifyListeners(new MarkerChangeEvent(this ));
158: }
159:
160: /**
161: * Tests the marker for equality with an arbitrary object.
162: *
163: * @param obj the object (<code>null</code> permitted).
164: *
165: * @return A boolean.
166: */
167: public boolean equals(Object obj) {
168: if (obj == null) {
169: return false;
170: }
171: if (!(obj instanceof CategoryMarker)) {
172: return false;
173: }
174: if (!super .equals(obj)) {
175: return false;
176: }
177: CategoryMarker that = (CategoryMarker) obj;
178: if (!this .key.equals(that.key)) {
179: return false;
180: }
181: if (this .drawAsLine != that.drawAsLine) {
182: return false;
183: }
184: return true;
185: }
186:
187: }
|