    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2008, 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     * VectorDataItem.java
    029     * -------------------
    030     * (C) Copyright 2007, 2008, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * Changes
    036     * -------
    037     * 30-Jan-2007 : Version 1 (DG);
    038     * 24-May-2007 : Added getVector(), renamed getDeltaX() --> getVectorX(),
    039     *               and likewise for getDeltaY() (DG);
    040     * 25-May-2007 : Moved from experimental to the main source tree (DG);
    041     *
    042     */
    043
    044    package org.jfree.data.xy;
    045
    046    import org.jfree.data.ComparableObjectItem;
    047
    048    /**
    049     * A data item representing data in the form (x, y, deltaX, deltaY), intended
    050     * for use by the {@link VectorSeries} class.
    051     *
    052     * @since 1.0.6
    053     */
    054    public class VectorDataItem extends ComparableObjectItem {
    055
    056        /**
    057         * Creates a new instance of <code>YIntervalItem</code>.
    058         *
    059         * @param x  the x-value.
    060         * @param y  the y-value.
    061         * @param deltaX  the vector x.
    062         * @param deltaY  the vector y.
    063         */
    064        public VectorDataItem(double x, double y, double deltaX, double deltaY) {
    065            super(new XYCoordinate(x, y), new Vector(deltaX, deltaY));
    066        }
    067
    068        /**
    069         * Returns the x-value.
    070         *
    071         * @return The x-value (never <code>null</code>).
    072         */
    073        public double getXValue() {
    074            XYCoordinate xy = (XYCoordinate) getComparable();
    075            return xy.getX();
    076        }
    077
    078        /**
    079         * Returns the y-value.
    080         *
    081         * @return The y-value.
    082         */
    083        public double getYValue() {
    084            XYCoordinate xy = (XYCoordinate) getComparable();
    085            return xy.getY();
    086        }
    087
    088        /**
    089         * Returns the vector.
    090         *
    091         * @return The vector (possibly <code>null</code>).
    092         */
    093        public Vector getVector() {
    094            return (Vector) getObject();
    095        }
    096
    097        /**
    098         * Returns the x-component for the vector.
    099         *
    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    }