Source for org.jfree.chart.needle.ShipNeedle

   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:  * ShipNeedle.java
  29:  * ---------------
  30:  * (C) Copyright 2002-2006, by the Australian Antarctic Division and 
  31:  *                          Contributors.
  32:  *
  33:  * Original Author:  Bryan Scott (for the Australian Antarctic Division);
  34:  * Contributor(s):   David Gilbert (for Object Refinery Limited);
  35:  *
  36:  * $Id: ShipNeedle.java,v 1.4.2.3 2006/08/02 10:40:57 mungady Exp $
  37:  *
  38:  * Changes:
  39:  * --------
  40:  * 25-Sep-2002 : Version 1, contributed by Bryan Scott (DG);
  41:  * 27-Mar-2003 : Implemented Serializable (DG);
  42:  * 09-Sep-2003 : Added equals() method (DG);
  43:  * 08-Jun-2005 : Implemented Cloneable (DG);
  44:  *
  45:  */
  46: 
  47: package org.jfree.chart.needle;
  48: 
  49: import java.awt.Graphics2D;
  50: import java.awt.geom.Arc2D;
  51: import java.awt.geom.GeneralPath;
  52: import java.awt.geom.Point2D;
  53: import java.awt.geom.Rectangle2D;
  54: import java.io.Serializable;
  55: 
  56: /**
  57:  * A needle in the shape of a ship, for use with the 
  58:  * {@link org.jfree.chart.plot.CompassPlot} class.
  59:  */
  60: public class ShipNeedle extends MeterNeedle 
  61:                         implements Cloneable, Serializable {
  62: 
  63:     /** For serialization. */
  64:     private static final long serialVersionUID = 149554868169435612L;
  65:     
  66:     /**
  67:      * Draws the needle.
  68:      *
  69:      * @param g2  the graphics device.
  70:      * @param plotArea  the plot area.
  71:      * @param rotate  the rotation point.
  72:      * @param angle  the angle.
  73:      */
  74:     protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 
  75:                               Point2D rotate, double angle) {
  76: 
  77:         GeneralPath shape = new GeneralPath();
  78:         shape.append(new Arc2D.Double(-9.0, -7.0, 10, 14, 0.0, 25.5, 
  79:                 Arc2D.OPEN), true);
  80:         shape.append(new Arc2D.Double(0.0, -7.0, 10, 14, 154.5, 25.5, 
  81:                 Arc2D.OPEN), true);
  82:         shape.closePath();
  83:         getTransform().setToTranslation(plotArea.getMinX(), plotArea.getMaxY());
  84:         getTransform().scale(plotArea.getWidth(), plotArea.getHeight() / 3);
  85:         shape.transform(getTransform());
  86: 
  87:         if ((rotate != null) && (angle != 0)) {
  88:             /// we have rotation
  89:             getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
  90:             shape.transform(getTransform());
  91:         }
  92: 
  93:         defaultDisplay(g2, shape);
  94:     }
  95: 
  96:     /**
  97:      * Tests another object for equality with this object.
  98:      * 
  99:      * @param object  the object to test.
 100:      * 
 101:      * @return A boolean.
 102:      */
 103:     public boolean equals(Object object) {
 104:         if (object == null) {
 105:             return false;
 106:         }
 107:         if (object == this) {
 108:             return true;
 109:         }
 110:         if (super.equals(object) && object instanceof ShipNeedle) {
 111:             return true;
 112:         }
 113:         return false;
 114:     }
 115: 
 116:     /**
 117:      * Returns a clone of this needle.
 118:      * 
 119:      * @return A clone.
 120:      * 
 121:      * @throws CloneNotSupportedException if the <code>ShipNeedle</code> 
 122:      *     cannot be cloned (in theory, this should not happen).
 123:      */
 124:     public Object clone() throws CloneNotSupportedException {
 125:         return super.clone();   
 126:     }
 127: 
 128: }
 129: