001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-present, by David Gilbert 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-present, by David Gilbert and Contributors. 031 * 032 * Original Author: David Gilbert; 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 private int firstItemIndex; 056 057 /** 058 * The last item in the current series that will be displayed. 059 */ 060 private int lastItemIndex; 061 062 /** 063 * A line object that the renderer can reuse to save instantiating a lot 064 * of objects. 065 */ 066 public Line2D workingLine; 067 068 /** 069 * A flag that controls whether the plot should pass ALL data items to the 070 * renderer, or just the items that will be visible. 071 */ 072 private boolean processVisibleItemsOnly; 073 074 /** 075 * Creates a new state. 076 * 077 * @param info the plot rendering info. 078 */ 079 public XYItemRendererState(PlotRenderingInfo info) { 080 super(info); 081 this.workingLine = new Line2D.Double(); 082 this.processVisibleItemsOnly = true; 083 } 084 085 /** 086 * Returns the flag that controls whether the plot passes all data 087 * items in each series to the renderer, or just the visible items. The 088 * default value is {@code true}. 089 * 090 * @return A boolean. 091 * 092 * @see #setProcessVisibleItemsOnly(boolean) 093 */ 094 public boolean getProcessVisibleItemsOnly() { 095 return this.processVisibleItemsOnly; 096 } 097 098 /** 099 * Sets the flag that controls whether the plot passes all data 100 * items in each series to the renderer, or just the visible items. 101 * 102 * @param flag the new flag value. 103 */ 104 public void setProcessVisibleItemsOnly(boolean flag) { 105 this.processVisibleItemsOnly = flag; 106 } 107 108 /** 109 * Returns the first item index (this is updated with each call to 110 * {@link #startSeriesPass(XYDataset, int, int, int, int, int)}. 111 * 112 * @return The first item index. 113 */ 114 public int getFirstItemIndex() { 115 return this.firstItemIndex; 116 } 117 118 /** 119 * Returns the last item index (this is updated with each call to 120 * {@link #startSeriesPass(XYDataset, int, int, int, int, int)}. 121 * 122 * @return The last item index. 123 */ 124 public int getLastItemIndex() { 125 return this.lastItemIndex; 126 } 127 128 /** 129 * This method is called by the {@link XYPlot} when it starts a pass 130 * through the (visible) items in a series. The default implementation 131 * records the first and last item indices - override this method to 132 * implement additional specialised behaviour. 133 * 134 * @param dataset the dataset. 135 * @param series the series index. 136 * @param firstItem the index of the first item in the series. 137 * @param lastItem the index of the last item in the series. 138 * @param pass the pass index. 139 * @param passCount the number of passes. 140 * 141 * @see #endSeriesPass(XYDataset, int, int, int, int, int) 142 */ 143 public void startSeriesPass(XYDataset dataset, int series, int firstItem, 144 int lastItem, int pass, int passCount) { 145 this.firstItemIndex = firstItem; 146 this.lastItemIndex = lastItem; 147 } 148 149 /** 150 * This method is called by the {@link XYPlot} when it ends a pass 151 * through the (visible) items in a series. The default implementation 152 * does nothing, but you can override this method to implement specialised 153 * behaviour. 154 * 155 * @param dataset the dataset. 156 * @param series the series index. 157 * @param firstItem the index of the first item in the series. 158 * @param lastItem the index of the last item in the series. 159 * @param pass the pass index. 160 * @param passCount the number of passes. 161 * 162 * @see #startSeriesPass(XYDataset, int, int, int, int, int) 163 */ 164 public void endSeriesPass(XYDataset dataset, int series, int firstItem, 165 int lastItem, int pass, int passCount) { 166 // do nothing...this is just a hook for subclasses 167 } 168 169}