Source for org.jfree.chart.axis.DateTick

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2007, 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:  * DateTick.java
  29:  * -------------
  30:  * (C) Copyright 2003-2007, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * Changes
  36:  * -------
  37:  * 07-Nov-2003 : Version 1 (DG);
  38:  * 13-May-2004 : Added equals() method (DG);
  39:  *
  40:  */
  41: 
  42: package org.jfree.chart.axis;
  43: 
  44: import java.util.Date;
  45: 
  46: import org.jfree.ui.TextAnchor;
  47: import org.jfree.util.ObjectUtilities;
  48: 
  49: /**
  50:  * A tick used by the {@link DateAxis} class.
  51:  */
  52: public class DateTick extends ValueTick {
  53: 
  54:     /** The date. */
  55:     private Date date;
  56:     
  57:     /**
  58:      * Creates a new date tick.
  59:      * 
  60:      * @param date  the date.
  61:      * @param label  the label.
  62:      * @param textAnchor  the part of the label that is aligned to the anchor 
  63:      *                    point.
  64:      * @param rotationAnchor  defines the rotation point relative to the text.
  65:      * @param angle  the rotation angle (in radians).
  66:      */
  67:     public DateTick(Date date, String label,
  68:                     TextAnchor textAnchor, TextAnchor rotationAnchor, 
  69:                     double angle) {
  70:                         
  71:         super(date.getTime(), label, textAnchor, rotationAnchor, angle);
  72:         this.date = date;
  73:             
  74:     }
  75:     
  76:     /**
  77:      * Returns the date.
  78:      * 
  79:      * @return The date.
  80:      */
  81:     public Date getDate() {
  82:         return this.date;
  83:     }
  84: 
  85:     /**
  86:      * Tests this tick for equality with an arbitrary object.
  87:      * 
  88:      * @param obj  the object to test (<code>null</code> permitted).
  89:      * 
  90:      * @return A boolean.
  91:      */
  92:     public boolean equals(Object obj) {
  93:         if (obj == this) {
  94:             return true;   
  95:         }
  96:         if (obj instanceof DateTick && super.equals(obj)) {
  97:             DateTick dt = (DateTick) obj;
  98:             if (!ObjectUtilities.equal(this.date, dt.date)) {
  99:                 return false;   
 100:             }
 101:             return true;
 102:         }
 103:         return false;
 104:     }
 105:     
 106:     /**
 107:      * Returns a hash code for this object.
 108:      * 
 109:      * @return A hash code.
 110:      */
 111:     public int hashCode() {
 112:         return this.date.hashCode();
 113:     }
 114:     
 115: }