    001/* ===========================================================
    002 * Orson Charts : a 3D chart library for the Java(tm) platform
    003 * ===========================================================
    004 *
    005 * (C)opyright 2013-2022, by David Gilbert.  All rights reserved.
    006 *
    007 * https://github.com/jfree/orson-charts
    008 *
    009 * This program is free software: you can redistribute it and/or modify
    010 * it under the terms of the GNU General Public License as published by
    011 * the Free Software Foundation, either version 3 of the License, or
    012 * (at your option) any later version.
    013 *
    014 * This program is distributed in the hope that it will be useful,
    015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    017 * GNU General Public License for more details.
    018 *
    019 * You should have received a copy of the GNU General Public License
    020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    021 *
    022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    023 * Other names may be trademarks of their respective owners.]
    024 *
    025 * If you do not wish to be bound by the terms of the GPL, an alternative
    026 * commercial license can be purchased.  For details, please see visit the
    027 * Orson Charts home page:
    028 *
    029 * http://www.object-refinery.com/orsoncharts/index.html
    030 *
    031 */
    032
    033package org.jfree.chart3d.marker;
    034
    035import java.awt.geom.Point2D;
    036
    037/**
    038 * A data object that represents a line within a {@link MarkerData} structure.
    039 *
    040 * @since 1.2
    041 */
    042public class MarkerLine {
    043
    044    /** The relative position along the axis (in the range 0.0 to 1.0). */
    045    private double pos;
    046
    047    /**
    048     * A flag indicating whether or not the line is pegged at the boundary of
    049     * the axis.  If the line is pegged, then it is not drawn (since it lies
    050     * outside the visible range of the chart.
    051     */
    052    private boolean pegged;
    053
    054    /** The vertex index for the start of the line. */
    055    private int v0;
    056
    057    /** The vertex index for the end of the line. */
    058    private int v1;
    059
    060    /** The projected start point. */
    061    private Point2D startPoint;
    062
    063    /** The projected end point. */
    064    private Point2D endPoint;
    065
    066    /**
    067     * Creates a new marker line.
    068     *
    069     * @param pos  the relative position (in the range 0.0 to 1.0).
    070     * @param pegged  a flag indicating whether or not the line has been
    071     *     pegged to the end of the range.
    072     */
    073    public MarkerLine(double pos, boolean pegged) {
    074        this(pos, pegged, -1, -1);
    075    }
    076
    077    /**
    078     * Creates a new marker line with vertex indices.
    079     *
    080     * @param pos  the relative position (in the range 0.0 to 1.0).
    081     * @param pegged  a flag indicating whether or not the line has been
    082     *     pegged to the end of the range.
    083     * @param v0  the index of the first vertex.
    084     * @param v1  the index of the second vertex.
    085     */
    086    public MarkerLine(double pos, boolean pegged, int v0, int v1) {
    087        this.pos = pos;
    088        this.pegged = pegged;
    089        this.v0 = v0;
    090        this.v1 = v1;
    091        this.startPoint = null;
    092        this.endPoint = null;
    093    }
    094
    095    /**
    096     * Returns the relative position of the line along the axis.
    097     *
    098     * @return The relative position of the line along the axis.
    099     */
    100    public double getPos() {
    101        return this.pos;
    102    }
    103
    104    /**
    105     * Returns {@code true} if the line is pegged, and {@code false}
    106     * otherwise.  This is used for range markers to indicate that the value
    107     * represented by the line falls outside the current axis range, so the
    108     * line has been moved to the nearest axis boundary ("pegged" to the axis
    109     * range).
    110     *
    111     * @return A boolean.
    112     */
    113    public boolean isPegged() {
    114        return this.pegged;
    115    }
    116
    117    /**
    118     * Returns the index of the vertex for the start of the line.
    119     *
    120     * @return The index.
    121     */
    122    public int getV0() {
    123        return this.v0;
    124    }
    125
    126    /**
    127     * Sets the index of the vertex for the start of the line.
    128     *
    129     * @param v0  the index.
    130     */
    131    public void setV0(int v0) {
    132        this.v0 = v0;
    133    }
    134
    135    /**
    136     * Returns the index of the vertex for the end of the line.
    137     *
    138     * @return The index.
    139     */
    140    public int getV1() {
    141        return this.v1;
    142    }
    143
    144    /**
    145     * Sets the index of the vertex for the end of the line.
    146     *
    147     * @param v1  the index.
    148     */
    149    public void setV1(int v1) {
    150        this.v1 = v1;
    151    }
    152
    153    /**
    154     * Returns the projected starting point for the line.
    155     *
    156     * @return The projected starting point (possibly {@code null}).
    157     */
    158    Point2D getStartPoint() {
    159        return this.startPoint;
    160    }
    161
    162    /**
    163     * Sets the projected starting point for the line.
    164     *
    165     * @param pt  the projected point.
    166     */
    167    public void setStartPoint(Point2D pt) {
    168        this.startPoint = pt;
    169    }
    170
    171    /**
    172     * Returns the projected ending point for the line.
    173     *
    174     * @return The projected ending point (possibly {@code null}).
    175     */
    176    Point2D getEndPoint() {
    177        return this.endPoint;
    178    }
    179
    180    /**
    181     * Sets the projected ending point for the line.
    182     *
    183     * @param pt  the projected point.
    184     */
    185    public void setEndPoint(Point2D pt) {
    186        this.endPoint = pt;
    187    }
    188
    189}