Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2005, 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, 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.2 2005/10/25 20:52:08 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: * 42: */ 43: 44: package org.jfree.chart.plot; 45: 46: import java.awt.BasicStroke; 47: import java.awt.Color; 48: import java.awt.Paint; 49: import java.awt.Stroke; 50: import java.io.Serializable; 51: 52: import org.jfree.ui.LengthAdjustmentType; 53: 54: /** 55: * A marker for a category. 56: * 57: * @see CategoryPlot#addDomainMarker(CategoryMarker) 58: */ 59: public class CategoryMarker extends Marker implements Cloneable, Serializable { 60: 61: /** The category key. */ 62: private Comparable key; 63: 64: /** 65: * A hint that the marker should be drawn as a line rather than a region. 66: */ 67: private boolean drawAsLine = false; 68: 69: /** 70: * Creates a new category marker. 71: * 72: * @param key the category key. 73: */ 74: public CategoryMarker(Comparable key) { 75: this(key, Color.gray, new BasicStroke(1.0f)); 76: } 77: 78: /** 79: * Creates a new category marker. 80: * 81: * @param key the key. 82: * @param paint the paint (<code>null</code> not permitted). 83: * @param stroke the stroke (<code>null</code> not permitted). 84: */ 85: public CategoryMarker(Comparable key, Paint paint, Stroke stroke) { 86: this(key, paint, stroke, paint, stroke, 0.5f); 87: } 88: 89: /** 90: * Creates a new category marker. 91: * 92: * @param key the key. 93: * @param paint the paint (<code>null</code> not permitted). 94: * @param stroke the stroke (<code>null</code> not permitted). 95: * @param outlinePaint the outline paint (<code>null</code> permitted). 96: * @param outlineStroke the outline stroke (<code>null</code> permitted). 97: * @param alpha the alpha transparency. 98: */ 99: public CategoryMarker(Comparable key, Paint paint, Stroke stroke, 100: Paint outlinePaint, Stroke outlineStroke, 101: float alpha) { 102: super(paint, stroke, outlinePaint, outlineStroke, alpha); 103: this.key = key; 104: setLabelOffsetType(LengthAdjustmentType.EXPAND); 105: } 106: 107: /** 108: * Returns the key. 109: * 110: * @return The key. 111: */ 112: public Comparable getKey() { 113: return this.key; 114: } 115: 116: /** 117: * Returns the flag that controls whether the marker is drawn as a region 118: * or a line. 119: * 120: * @return A line. 121: */ 122: public boolean getDrawAsLine() { 123: return this.drawAsLine; 124: } 125: 126: /** 127: * Sets the flag that controls whether the marker is drawn as a region or 128: * as a line. 129: * 130: * @param drawAsLine the flag. 131: */ 132: public void setDrawAsLine(boolean drawAsLine) { 133: this.drawAsLine = drawAsLine; 134: } 135: 136: /** 137: * Tests the marker for equality with an arbitrary object. 138: * 139: * @param obj the object (<code>null</code> permitted). 140: * 141: * @return A boolean. 142: */ 143: public boolean equals(Object obj) { 144: if (obj == null) { 145: return false; 146: } 147: if (!(obj instanceof CategoryMarker)) { 148: return false; 149: } 150: if (!super.equals(obj)) { 151: return false; 152: } 153: CategoryMarker that = (CategoryMarker) obj; 154: if (!this.key.equals(that.key)) { 155: return false; 156: } 157: if (this.drawAsLine != that.drawAsLine) { 158: return false; 159: } 160: return true; 161: } 162: 163: }