From: <mu...@us...> - 2009-01-13 08:33:25
|
Revision: 1779 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1779&view=rev Author: mungady Date: 2009-01-13 08:33:23 +0000 (Tue, 13 Jan 2009) Log Message: ----------- 2009-01-13 David Gilbert <dav...@ob...> Bug 2502355: * source/org/jfree/chart/ChartPanel.java (zoomInBoth): Change notify flag to ensure plot sends only one event, (zoomOutBoth): Likewise, (zoom): Likewise, (restoreAutoBounds): Likewise, * source/org/jfree/chart/plot/Plot.java (notify): New field, (Plot): Initialise new field, (isNotify): New method, (setNotify): Likewise, (notifyListeners): Check notify flag, * tests/org/jfree/chart/junit/ChartPanelTests.java (chartChangeEvents): New field, (chartChanged): New method, (test2502355_zoom): New test, (test2502355_zoomInBoth): Likewise, (test2502355_zoomOutBoth): Likewise, (test2502355_restoreAutoBounds): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Plot.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/junit/ChartPanelTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2009-01-13 08:01:15 UTC (rev 1778) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2009-01-13 08:33:23 UTC (rev 1779) @@ -1,5 +1,27 @@ 2009-01-13 David Gilbert <dav...@ob...> + Bug 2502355: + * source/org/jfree/chart/ChartPanel.java + (zoomInBoth): Change notify flag to ensure plot sends only one event, + (zoomOutBoth): Likewise, + (zoom): Likewise, + (restoreAutoBounds): Likewise, + * source/org/jfree/chart/plot/Plot.java + (notify): New field, + (Plot): Initialise new field, + (isNotify): New method, + (setNotify): Likewise, + (notifyListeners): Check notify flag, + * tests/org/jfree/chart/junit/ChartPanelTests.java + (chartChangeEvents): New field, + (chartChanged): New method, + (test2502355_zoom): New test, + (test2502355_zoomInBoth): Likewise, + (test2502355_zoomOutBoth): Likewise, + (test2502355_restoreAutoBounds): Likewise. + +2009-01-13 David Gilbert <dav...@ob...> + * source/org/jfree/data/time/TimeSeries.java (TimeSeries(Comparable, Class)): Deprecated, (TimeSeries(Comparable, String, String, Class)): Likewise, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java 2009-01-13 08:01:15 UTC (rev 1778) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/ChartPanel.java 2009-01-13 08:33:23 UTC (rev 1779) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------- * ChartPanel.java * --------------- - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrzej Porebski; @@ -143,6 +143,8 @@ * 18-Sep-2008 : Modified creation of chart buffer (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); + * 13-Jan-2008 : Fixed zooming methods to trigger only one plot + * change event (DG); * */ @@ -1785,8 +1787,18 @@ * @param y the y value (in screen coordinates). */ public void zoomInBoth(double x, double y) { + Plot plot = this.chart.getPlot(); + if (plot == null) { + return; + } + // here we tweak the notify flag on the plot so that only + // one notification happens even though we update multiple + // axes... + boolean savedNotify = plot.isNotify(); + plot.setNotify(false); zoomInDomain(x, y); zoomInRange(x, y); + plot.setNotify(savedNotify); } /** @@ -1832,8 +1844,18 @@ * @param y the y value (in screen coordinates). */ public void zoomOutBoth(double x, double y) { + Plot plot = this.chart.getPlot(); + if (plot == null) { + return; + } + // here we tweak the notify flag on the plot so that only + // one notification happens even though we update multiple + // axes... + boolean savedNotify = plot.isNotify(); + plot.setNotify(false); zoomOutDomain(x, y); zoomOutRange(x, y); + plot.setNotify(savedNotify); } /** @@ -1900,6 +1922,11 @@ Plot p = this.chart.getPlot(); if (p instanceof Zoomable) { + // here we tweak the notify flag on the plot so that only + // one notification happens even though we update multiple + // axes... + boolean savedNotify = p.isNotify(); + p.setNotify(false); Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); @@ -1909,6 +1936,7 @@ z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } + p.setNotify(savedNotify); } } @@ -1919,8 +1947,18 @@ * Restores the auto-range calculation on both axes. */ public void restoreAutoBounds() { + Plot plot = this.chart.getPlot(); + if (plot == null) { + return; + } + // here we tweak the notify flag on the plot so that only + // one notification happens even though we update multiple + // axes... + boolean savedNotify = plot.isNotify(); + plot.setNotify(false); restoreAutoDomainBounds(); restoreAutoRangeBounds(); + plot.setNotify(savedNotify); } /** Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Plot.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Plot.java 2009-01-13 08:01:15 UTC (rev 1778) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/plot/Plot.java 2009-01-13 08:33:23 UTC (rev 1779) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------- * Plot.java * --------- - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Sylvain Vieujot; @@ -122,6 +122,7 @@ * taking into account orientation (DG); * 25-Mar-2008 : Added fireChangeEvent() method - see patch 1914411 (DG); * 15-Aug-2008 : Added setDrawingSupplier() method with notify flag (DG); + * 13-Jan-2009 : Added notify flag (DG); * */ @@ -148,11 +149,13 @@ import javax.swing.event.EventListenerList; +import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItemCollection; import org.jfree.chart.LegendItemSource; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.event.AxisChangeEvent; import org.jfree.chart.event.AxisChangeListener; +import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeEventType; import org.jfree.chart.event.MarkerChangeEvent; import org.jfree.chart.event.MarkerChangeListener; @@ -174,10 +177,9 @@ import org.jfree.util.PublicCloneable; /** - * The base class for all plots in JFreeChart. The - * {@link org.jfree.chart.JFreeChart} class delegates the drawing of axes and - * data to the plot. This base class provides facilities common to most plot - * types. + * The base class for all plots in JFreeChart. The {@link JFreeChart} class + * delegates the drawing of axes and data to the plot. This base class + * provides facilities common to most plot types. */ public abstract class Plot implements AxisChangeListener, DatasetChangeListener, MarkerChangeListener, LegendItemSource, @@ -278,6 +280,15 @@ private transient EventListenerList listenerList; /** + * A flag that controls whether or not the plot will notify listeners + * of changes (defaults to true, but sometimes it is useful to disable + * this). + * + * @since 1.0.13 + */ + private boolean notify; + + /** * Creates a new plot. */ protected Plot() { @@ -298,6 +309,7 @@ this.drawingSupplier = new DefaultDrawingSupplier(); + this.notify = true; this.listenerList = new EventListenerList(); } @@ -883,6 +895,38 @@ } /** + * Returns a flag that controls whether or not change events are sent to + * registered listeners. + * + * @return A boolean. + * + * @see #setNotify(boolean) + * + * @since 1.0.13 + */ + public boolean isNotify() { + return this.notify; + } + + /** + * Sets a flag that controls whether or not listeners receive + * {@link PlotChangeEvent} notifications. + * + * @param notify a boolean. + * + * @see #isNotify() + * + * @since 1.0.13 + */ + public void setNotify(boolean notify) { + this.notify = notify; + // if the flag is being set to true, there may be queued up changes... + if (notify) { + notifyListeners(new PlotChangeEvent(this)); + } + } + + /** * Registers an object for notification of changes to the plot. * * @param listener the object to be registered. @@ -910,6 +954,11 @@ * @param event information about the change event. */ public void notifyListeners(PlotChangeEvent event) { + // if the 'notify' flag has been switched to false, we don't notify + // the listeners + if (!this.notify) { + return; + } Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == PlotChangeListener.class) { @@ -1260,6 +1309,9 @@ if (!this.drawingSupplier.equals(that.drawingSupplier)) { return false; } + if (this.notify != that.notify) { + return false; + } return true; } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/junit/ChartPanelTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/junit/ChartPanelTests.java 2009-01-13 08:01:15 UTC (rev 1778) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/junit/ChartPanelTests.java 2009-01-13 08:33:23 UTC (rev 1779) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------- * ChartPanelTests.java * -------------------- - * (C) Copyright 2004, 2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2004-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,12 +35,15 @@ * Changes * ------- * 13-Jul-2004 : Version 1 (DG); + * 12-Jan-2009 : Added test2502355() (DG); * */ package org.jfree.chart.junit; +import java.awt.geom.Rectangle2D; import java.util.EventListener; +import java.util.List; import javax.swing.event.CaretListener; @@ -48,18 +51,36 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartMouseEvent; import org.jfree.chart.ChartMouseListener; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; +import org.jfree.chart.event.ChartChangeEvent; +import org.jfree.chart.event.ChartChangeListener; +import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; +import org.jfree.data.xy.DefaultXYDataset; /** * Tests for the {@link ChartPanel} class. */ -public class ChartPanelTests extends TestCase implements ChartMouseListener { +public class ChartPanelTests extends TestCase + implements ChartChangeListener, ChartMouseListener { + private List chartChangeEvents = new java.util.ArrayList(); + /** + * Receives a chart change event and stores it in a list for later + * inspection. + * + * @param event the event. + */ + public void chartChanged(ChartChangeEvent event) { + this.chartChangeEvents.add(event); + } + + /** * Returns the tests as a test suite. * * @return The test suite. @@ -151,4 +172,63 @@ // ignore } + /** + * Checks that a call to the zoom() method generates just one + * ChartChangeEvent. + */ + public void test2502355_zoom() { + DefaultXYDataset dataset = new DefaultXYDataset(); + JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", + "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + ChartPanel panel = new ChartPanel(chart); + chart.addChangeListener(this); + this.chartChangeEvents.clear(); + panel.zoom(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); + assertEquals(1, this.chartChangeEvents.size()); + } + + /** + * Checks that a call to the zoomInBoth() method generates just one + * ChartChangeEvent. + */ + public void test2502355_zoomInBoth() { + DefaultXYDataset dataset = new DefaultXYDataset(); + JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", + "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + ChartPanel panel = new ChartPanel(chart); + chart.addChangeListener(this); + this.chartChangeEvents.clear(); + panel.zoomInBoth(1.0, 2.0); + assertEquals(1, this.chartChangeEvents.size()); + } + + /** + * Checks that a call to the zoomOutBoth() method generates just one + * ChartChangeEvent. + */ + public void test2502355_zoomOutBoth() { + DefaultXYDataset dataset = new DefaultXYDataset(); + JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", + "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + ChartPanel panel = new ChartPanel(chart); + chart.addChangeListener(this); + this.chartChangeEvents.clear(); + panel.zoomOutBoth(1.0, 2.0); + assertEquals(1, this.chartChangeEvents.size()); + } + + /** + * Checks that a call to the restoreAutoBounds() method generates just one + * ChartChangeEvent. + */ + public void test2502355_restoreAutoBounds() { + DefaultXYDataset dataset = new DefaultXYDataset(); + JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", + "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + ChartPanel panel = new ChartPanel(chart); + chart.addChangeListener(this); + this.chartChangeEvents.clear(); + panel.restoreAutoBounds(); + assertEquals(1, this.chartChangeEvents.size()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |