001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2020, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ------------------------
028 * XYItemRendererState.java
029 * ------------------------
030 * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   Ulrich Voigt;
034 *                   Greg Darke;
035 *
036 */
037
038package org.jfree.chart.renderer.xy;
039
040import java.awt.geom.Line2D;
041
042import org.jfree.chart.plot.PlotRenderingInfo;
043import org.jfree.chart.plot.XYPlot;
044import org.jfree.chart.renderer.RendererState;
045import org.jfree.data.xy.XYDataset;
046
047/**
048 * The state for an {@link XYItemRenderer}.
049 */
050public class XYItemRendererState extends RendererState {
051
052    /**
053     * The first item in the series that will be displayed.
054     *
055     * @since 1.0.11
056     */
057    private int firstItemIndex;
058
059    /**
060     * The last item in the current series that will be displayed.
061     *
062     * @since 1.0.11
063     */
064    private int lastItemIndex;
065
066    /**
067     * A line object that the renderer can reuse to save instantiating a lot
068     * of objects.
069     */
070    public Line2D workingLine;
071
072    /**
073     * A flag that controls whether the plot should pass ALL data items to the
074     * renderer, or just the items that will be visible.
075     *
076     * @since 1.0.6
077     */
078    private boolean processVisibleItemsOnly;
079
080    /**
081     * Creates a new state.
082     *
083     * @param info  the plot rendering info.
084     */
085    public XYItemRendererState(PlotRenderingInfo info) {
086        super(info);
087        this.workingLine = new Line2D.Double();
088        this.processVisibleItemsOnly = true;
089    }
090
091    /**
092     * Returns the flag that controls whether the plot passes all data
093     * items in each series to the renderer, or just the visible items.  The
094     * default value is {@code true}.
095     *
096     * @return A boolean.
097     *
098     * @since 1.0.6
099     *
100     * @see #setProcessVisibleItemsOnly(boolean)
101     */
102    public boolean getProcessVisibleItemsOnly() {
103        return this.processVisibleItemsOnly;
104    }
105
106    /**
107     * Sets the flag that controls whether the plot passes all data
108     * items in each series to the renderer, or just the visible items.
109     *
110     * @param flag  the new flag value.
111     *
112     * @since 1.0.6
113     */
114    public void setProcessVisibleItemsOnly(boolean flag) {
115        this.processVisibleItemsOnly = flag;
116    }
117
118    /**
119     * Returns the first item index (this is updated with each call to
120     * {@link #startSeriesPass(XYDataset, int, int, int, int, int)}.
121     *
122     * @return The first item index.
123     *
124     * @since 1.0.11
125     */
126    public int getFirstItemIndex() {
127        return this.firstItemIndex;
128    }
129
130    /**
131     * Returns the last item index (this is updated with each call to
132     * {@link #startSeriesPass(XYDataset, int, int, int, int, int)}.
133     *
134     * @return The last item index.
135     *
136     * @since 1.0.11
137     */
138    public int getLastItemIndex() {
139        return this.lastItemIndex;
140    }
141
142    /**
143     * This method is called by the {@link XYPlot} when it starts a pass
144     * through the (visible) items in a series.  The default implementation
145     * records the first and last item indices - override this method to
146     * implement additional specialised behaviour.
147     *
148     * @param dataset  the dataset.
149     * @param series  the series index.
150     * @param firstItem  the index of the first item in the series.
151     * @param lastItem  the index of the last item in the series.
152     * @param pass  the pass index.
153     * @param passCount  the number of passes.
154     *
155     * @see #endSeriesPass(XYDataset, int, int, int, int, int)
156     *
157     * @since 1.0.11
158     */
159    public void startSeriesPass(XYDataset dataset, int series, int firstItem,
160            int lastItem, int pass, int passCount) {
161        this.firstItemIndex = firstItem;
162        this.lastItemIndex = lastItem;
163    }
164
165    /**
166     * This method is called by the {@link XYPlot} when it ends a pass
167     * through the (visible) items in a series.  The default implementation
168     * does nothing, but you can override this method to implement specialised
169     * behaviour.
170     *
171     * @param dataset  the dataset.
172     * @param series  the series index.
173     * @param firstItem  the index of the first item in the series.
174     * @param lastItem  the index of the last item in the series.
175     * @param pass  the pass index.
176     * @param passCount  the number of passes.
177     *
178     * @see #startSeriesPass(XYDataset, int, int, int, int, int)
179     *
180     * @since 1.0.11
181     */
182    public void endSeriesPass(XYDataset dataset, int series, int firstItem,
183            int lastItem, int pass, int passCount) {
184        // do nothing...this is just a hook for subclasses
185    }
186
187}