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