001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2005, 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, 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.2 2005/10/25 20:52:08 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     *
042     */
043    
044    package org.jfree.chart.plot;
045    
046    import java.awt.BasicStroke;
047    import java.awt.Color;
048    import java.awt.Paint;
049    import java.awt.Stroke;
050    import java.io.Serializable;
051    
052    import org.jfree.ui.LengthAdjustmentType;
053    
054    /**
055     * A marker for a category.
056     * 
057     * @see CategoryPlot#addDomainMarker(CategoryMarker)
058     */
059    public class CategoryMarker extends Marker implements Cloneable, Serializable {
060    
061        /** The category key. */
062        private Comparable key;
063        
064        /** 
065         * A hint that the marker should be drawn as a line rather than a region. 
066         */
067        private boolean drawAsLine = false;
068        
069        /**
070         * Creates a new category marker.
071         * 
072         * @param key  the category key.
073         */
074        public CategoryMarker(Comparable key) {
075            this(key, Color.gray, new BasicStroke(1.0f));    
076        }
077        
078        /**
079         * Creates a new category marker.
080         * 
081         * @param key  the key.
082         * @param paint  the paint (<code>null</code> not permitted).
083         * @param stroke  the stroke (<code>null</code> not permitted).
084         */
085        public CategoryMarker(Comparable key, Paint paint, Stroke stroke) {
086            this(key, paint, stroke, paint, stroke, 0.5f);
087        }
088        
089        /**
090         * Creates a new category marker.
091         * 
092         * @param key  the key.
093         * @param paint  the paint (<code>null</code> not permitted).
094         * @param stroke  the stroke (<code>null</code> not permitted).
095         * @param outlinePaint  the outline paint (<code>null</code> permitted).
096         * @param outlineStroke  the outline stroke (<code>null</code> permitted).
097         * @param alpha  the alpha transparency.
098         */
099        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    }