I want to maintain all the data so that when the user selects 180 when it was 60 I do not have to fetch the data again.
Is there a more elegant way than what I have done below?
Code: Select all
import java.util.Locale;
import java.util.TimeZone;
import org.jfree.data.Range;
import org.jfree.data.time.TimePeriod;
import org.jfree.data.time.TimeTableXYDataset;
/**
* @author Matthew L. Wilson
* @version $Revision: 1.1 $ $Date: 2005/03/23 15:20:38 $
*/
public class BoundedTimeTableXYDataset extends TimeTableXYDataset
{
/** The number of timePeriods to display. * */
private int displayRange = -1;
/** The max number of timePeriods alowed to display. * */
private int maxDisplayRange = -1;
/**
* @see org.jfree.data.time.TimeTableXYDataset#BoundedTimeTableXYDataset()
*/
public BoundedTimeTableXYDataset()
{
super();
}
/**
* @see org.jfree.data.time.TimeTableXYDataset#BoundedTimeTableXYDataset(TimeZone)
*/
public BoundedTimeTableXYDataset(TimeZone zone)
{
super(zone);
}
/**
* @see org.jfree.data.time.TimeTableXYDataset#BoundedTimeTableXYDataset(TimeZone, Locale)
*/
public BoundedTimeTableXYDataset(TimeZone zone, Locale locale)
{
super(zone, locale);
}
/**
* Adds a new data item to the dataset and sends
* a {@link org.jfree.data.general.DatasetChangeEvent}
* to all registered listeners.
*
* @param period
* the time period.
* @param y
* the value for this period.
* @param seriesName
* the name of the series to add the value.
*/
public void add(TimePeriod period, double y, String seriesName)
{
add(period, new Double(y), seriesName, false);
if (maxDisplayRange > 0)
{
while (getItemCount() > maxDisplayRange)
{
TimePeriod timePeriod = getTimePeriod(0);
remove(timePeriod, seriesName, false);
}
}
fireDatasetChanged();
}
/**
* Returns the range of the values in this dataset's domain.
*
* @param includeInterval
* a flag that controls whether or not the x-intervals are taken into account.
* @return The range.
*/
public Range getDomainBounds(boolean includeInterval)
{
int count = getItemCount();
if (count == 0)
{
return null;
}
if (displayRange >= 0)
{
TimePeriod first = getTimePeriod(0);
TimePeriod last = getTimePeriod(count - 1);
if (count > displayRange)
{
first = getTimePeriod(count - displayRange);
}
return new Range(first.getStart().getTime(), last.getEnd().getTime());
}
else
{
return super.getDomainBounds(includeInterval);
}
}
//Setters and Getters
/**
* @return Returns the displayRange.
*/
public int getDisplayRange()
{
return displayRange;
}
/**
* @param displayRange
* The displayRange to set.
*/
public void setDisplayRange(int displayRange)
{
setDisplayRange(displayRange, true);
}
/**
* @param displayRange
* The displayRange to set.
*/
public void setDisplayRange(int displayRange, boolean notify)
{
this.displayRange = displayRange;
if (notify)
{
fireDatasetChanged();
}
}
/**
* @return Returns the maxDisplayRange.
*/
public int getMaxDisplayRange()
{
return maxDisplayRange;
}
/**
* @param maxDisplayRange
* The maxDisplayRange to set.
*/
public void setMaxDisplayRange(int maxDisplayRange)
{
this.maxDisplayRange = maxDisplayRange;
}
}