Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ------------------- 28: * CategoryMarker.java 29: * ------------------- 30: * (C) Copyright 2005, 2006, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): Nicolas Brodu; 34: * 35: * $Id: CategoryMarker.java,v 1.1.2.4 2006/10/24 15:39:20 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 20-May-2005 : Version 1 (DG); 40: * 19-Aug-2005 : Implemented equals(), fixed bug in constructor (DG); 41: * ------------- JFREECHART 1.0.x --------------------------------------------- 42: * 05-Sep-2006 : Added MarkerChangeListener support (DG); 43: * 44: */ 45: 46: package org.jfree.chart.plot; 47: 48: import java.awt.BasicStroke; 49: import java.awt.Color; 50: import java.awt.Paint; 51: import java.awt.Stroke; 52: import java.io.Serializable; 53: 54: import org.jfree.chart.event.MarkerChangeEvent; 55: import org.jfree.ui.LengthAdjustmentType; 56: 57: /** 58: * A marker for a category. 59: * <br><br> 60: * Note that for serialization to work correctly, the category key must be an 61: * instance of a serializable class. 62: * 63: * @see CategoryPlot#addDomainMarker(CategoryMarker) 64: */ 65: public class CategoryMarker extends Marker implements Cloneable, Serializable { 66: 67: /** The category key. */ 68: private Comparable key; 69: 70: /** 71: * A hint that the marker should be drawn as a line rather than a region. 72: */ 73: private boolean drawAsLine = false; 74: 75: /** 76: * Creates a new category marker for the specified category. 77: * 78: * @param key the category key. 79: */ 80: public CategoryMarker(Comparable key) { 81: this(key, Color.gray, new BasicStroke(1.0f)); 82: } 83: 84: /** 85: * Creates a new category marker. 86: * 87: * @param key the key. 88: * @param paint the paint (<code>null</code> not permitted). 89: * @param stroke the stroke (<code>null</code> not permitted). 90: */ 91: public CategoryMarker(Comparable key, Paint paint, Stroke stroke) { 92: this(key, paint, stroke, paint, stroke, 1.0f); 93: } 94: 95: /** 96: * Creates a new category marker. 97: * 98: * @param key the key. 99: * @param paint the paint (<code>null</code> not permitted). 100: * @param stroke the stroke (<code>null</code> not permitted). 101: * @param outlinePaint the outline paint (<code>null</code> permitted). 102: * @param outlineStroke the outline stroke (<code>null</code> permitted). 103: * @param alpha the alpha transparency. 104: */ 105: public CategoryMarker(Comparable key, Paint paint, Stroke stroke, 106: Paint outlinePaint, Stroke outlineStroke, 107: 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: }