Source for org.jfree.chart.axis.Tick

   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:  * Tick.java
  29:  * ---------
  30:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   Nicolas Brodu;
  34:  *
  35:  * $Id: Tick.java,v 1.6.2.1 2005/10/25 20:37:34 mungady Exp $
  36:  *
  37:  * Changes (from 18-Sep-2001)
  38:  * --------------------------
  39:  * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG);
  40:  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
  41:  * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
  42:  * 26-Mar-2003 : Implemented Serializable (DG);
  43:  * 12-Sep-2003 : Implemented Cloneable (NB);
  44:  * 07-Nov-2003 : Added subclasses for particular types of ticks (DG);
  45:  *
  46:  */
  47: 
  48: package org.jfree.chart.axis;
  49: 
  50: import java.io.Serializable;
  51: 
  52: import org.jfree.ui.TextAnchor;
  53: import org.jfree.util.ObjectUtilities;
  54: 
  55: /**
  56:  * The base class used to represent labelled ticks along an axis.
  57:  */
  58: public abstract class Tick implements Serializable, Cloneable {
  59: 
  60:     /** For serialization. */
  61:     private static final long serialVersionUID = 6668230383875149773L;
  62:     
  63:     /** A text version of the tick value. */
  64:     private String text;
  65: 
  66:     /** The text anchor for the tick label. */
  67:     private TextAnchor textAnchor;
  68:     
  69:     /** The rotation anchor for the tick label. */
  70:     private TextAnchor rotationAnchor;
  71:         
  72:     /** The rotation angle. */
  73:     private double angle;
  74:     
  75:     /**
  76:      * Creates a new tick.
  77:      *
  78:      * @param text  the formatted version of the tick value.
  79:      * @param textAnchor  the text anchor (<code>null</code> not permitted).
  80:      * @param rotationAnchor  the rotation anchor (<code>null</code> not 
  81:      *                        permitted).
  82:      * @param angle  the angle. 
  83:      */
  84:     public Tick(String text, TextAnchor textAnchor, TextAnchor rotationAnchor, 
  85:                 double angle) {
  86:         if (textAnchor == null) {
  87:             throw new IllegalArgumentException("Null 'textAnchor' argument.");
  88:         }
  89:         if (rotationAnchor == null) {
  90:             throw new IllegalArgumentException(
  91:                 "Null 'rotationAnchor' argument."
  92:             );   
  93:         }
  94:         this.text = text;
  95:         this.textAnchor = textAnchor;
  96:         this.rotationAnchor = rotationAnchor;
  97:         this.angle = angle;
  98:     }
  99: 
 100:     /**
 101:      * Returns the text version of the tick value.
 102:      *
 103:      * @return A string (possibly <code>null</code>;
 104:      */
 105:     public String getText() {
 106:         return this.text;
 107:     }
 108: 
 109:     /**
 110:      * Returns the text anchor.
 111:      * 
 112:      * @return The text anchor (never <code>null</code>).
 113:      */
 114:     public TextAnchor getTextAnchor() {
 115:         return this.textAnchor;
 116:     }
 117: 
 118:     /**
 119:      * Returns the text anchor that defines the point around which the label is
 120:      * rotated.
 121:      * 
 122:      * @return A text anchor (never <code>null</code>).
 123:      */    
 124:     public TextAnchor getRotationAnchor() {
 125:         return this.rotationAnchor;
 126:     }
 127:     
 128:     /**
 129:      * Returns the angle.
 130:      * 
 131:      * @return The angle.
 132:      */
 133:     public double getAngle() {
 134:         return this.angle;
 135:     }
 136: 
 137:     /**
 138:      * Tests this tick for equality with an arbitrary object.
 139:      * 
 140:      * @param obj  the object (<code>null</code> permitted).
 141:      * 
 142:      * @return A boolean.
 143:      */
 144:     public boolean equals(Object obj) {
 145:         if (this == obj) {
 146:             return true;   
 147:         }
 148:         if (obj instanceof Tick) {
 149:             Tick t = (Tick) obj;   
 150:             if (!ObjectUtilities.equal(this.text, t.text)) {
 151:                 return false;   
 152:             }
 153:             if (!ObjectUtilities.equal(this.textAnchor, t.textAnchor)) {
 154:                 return false;   
 155:             }
 156:             if (!ObjectUtilities.equal(this.rotationAnchor, t.rotationAnchor)) {
 157:                 return false;   
 158:             }
 159:             if (!(this.angle == t.angle)) {
 160:                 return false;   
 161:             }
 162:             return true;
 163:         }
 164:         return false;
 165:     }
 166: 
 167:     /** 
 168:      * Returns a clone of the tick.
 169:      * 
 170:      * @return A clone.
 171:      * 
 172:      * @throws CloneNotSupportedException if there is a problem cloning.
 173:      */
 174:     public Object clone() throws CloneNotSupportedException {
 175:         Tick clone = (Tick) super.clone();
 176:         return clone;
 177:     }
 178: 
 179:     /**
 180:      * Returns a string representation of the tick.
 181:      * 
 182:      * @return A string.
 183:      */
 184:     public String toString() {
 185:         return this.text;
 186:     }
 187: }