Source for org.jfree.data.xy.VectorDataItem

   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:  * VectorDataItem.java
  29:  * -------------------
  30:  * (C) Copyright 2007, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * Changes
  36:  * -------
  37:  * 30-Jan-2007 : Version 1 (DG);
  38:  * 24-May-2007 : Added getVector(), renamed getDeltaX() --> getVectorX(), 
  39:  *               and likewise for getDeltaY() (DG);
  40:  * 25-May-2007 : Moved from experimental to the main source tree (DG);
  41:  *
  42:  */
  43: 
  44: package org.jfree.data.xy;
  45: 
  46: import org.jfree.data.ComparableObjectItem;
  47: 
  48: /**
  49:  * A data item representing data in the form (x, y, deltaX, deltaY), intended
  50:  * for use by the {@link VectorSeries} class.
  51:  * 
  52:  * @since 1.0.6
  53:  */
  54: public class VectorDataItem extends ComparableObjectItem {
  55: 
  56:     /** 
  57:      * Creates a new instance of <code>YIntervalItem</code>.
  58:      *
  59:      * @param x  the x-value.
  60:      * @param y  the y-value.
  61:      * @param deltaX  the vector x.
  62:      * @param deltaY  the vector y.
  63:      */
  64:     public VectorDataItem(double x, double y, double deltaX, double deltaY) {
  65:         super(new XYCoordinate(x, y), new Vector(deltaX, deltaY));
  66:     }
  67:     
  68:     /**
  69:      * Returns the x-value.
  70:      *
  71:      * @return The x-value (never <code>null</code>).
  72:      */
  73:     public double getXValue() {
  74:         XYCoordinate xy = (XYCoordinate) getComparable();
  75:         return xy.getX();
  76:     }
  77:     
  78:     /**
  79:      * Returns the y-value.
  80:      *
  81:      * @return The y-value.
  82:      */
  83:     public double getYValue() {
  84:         XYCoordinate xy = (XYCoordinate) getComparable();
  85:         return xy.getY();
  86:     }
  87:     
  88:     /**
  89:      * Returns the vector.
  90:      * 
  91:      * @return The vector (possibly <code>null</code>).
  92:      */
  93:     public Vector getVector() {
  94:         return (Vector) getObject();
  95:     }
  96:     
  97:     /**
  98:      * Returns the x-component for the vector.
  99:      * 
 100:      * @return The x-component.
 101:      */
 102:     public double getVectorX() {
 103:         Vector vi = (Vector) getObject();
 104:         if (vi != null) {
 105:             return vi.getX();
 106:         }
 107:         else {
 108:             return Double.NaN;
 109:         }
 110:     }
 111:     
 112:     /**
 113:      * Returns the y-component for the vector.
 114:      * 
 115:      * @return The y-component.
 116:      */
 117:     public double getVectorY() {
 118:         Vector vi = (Vector) getObject();
 119:         if (vi != null) {
 120:             return vi.getY();
 121:         }
 122:         else {
 123:             return Double.NaN;
 124:         }
 125:     }
 126:     
 127: }