From: <ne...@us...> - 2007-07-16 14:50:25
|
Revision: 129 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=129&view=rev Author: nenry Date: 2007-07-16 07:50:21 -0700 (Mon, 16 Jul 2007) Log Message: ----------- implemented SWT alpha channel. Modified Paths: -------------- trunk/ChangeLog trunk/swt/org/jfree/experimental/chart/swt/demo/SWTTimeSeriesDemo.java trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-12 09:21:36 UTC (rev 128) +++ trunk/ChangeLog 2007-07-16 14:50:21 UTC (rev 129) @@ -1,3 +1,9 @@ +2007-07-16 Henry Proudhon <hen...@in...> + + * source/swt/org/jfree/experimental/swt/SWTGraphics2D.java + (getComposite): Implemented, + (setComposite): Likewise. + 2007-07-12 David Gilbert <dav...@ob...> * experimental/org/jfree/experimental/chart/axis/LogAxis.java Modified: trunk/swt/org/jfree/experimental/chart/swt/demo/SWTTimeSeriesDemo.java =================================================================== --- trunk/swt/org/jfree/experimental/chart/swt/demo/SWTTimeSeriesDemo.java 2007-07-12 09:21:36 UTC (rev 128) +++ trunk/swt/org/jfree/experimental/chart/swt/demo/SWTTimeSeriesDemo.java 2007-07-16 14:50:21 UTC (rev 129) @@ -39,6 +39,7 @@ */ package org.jfree.experimental.chart.swt.demo; +import java.awt.BasicStroke; import java.awt.Color; import java.text.SimpleDateFormat; @@ -49,6 +50,7 @@ import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.plot.IntervalMarker; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; @@ -95,7 +97,8 @@ plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); - + //plot.setForegroundAlpha(0.5f); + XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; @@ -106,6 +109,11 @@ DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); + // code to test the alpha channel + IntervalMarker interv = new IntervalMarker(120, 150, + Color.blue, new BasicStroke(5.0f),null,null,0.2f); + plot.addRangeMarker(interv); + return chart; } Modified: trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java =================================================================== --- trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java 2007-07-12 09:21:36 UTC (rev 128) +++ trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java 2007-07-16 14:50:21 UTC (rev 129) @@ -44,11 +44,13 @@ * 23-May-2007 : removed resource leaks by adding a resource pool (CC); * 15-Jun-2007 : Fixed compile error for JDK 1.4 (DG); * 06-Jul-2007 : implemented clipping (HP); + * 16-Jul-2007 : implemented alpha channel (HP); * */ package org.jfree.experimental.swt; +import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; @@ -93,6 +95,8 @@ import org.eclipse.swt.graphics.Resource; import org.eclipse.swt.graphics.Transform; +import sun.java2d.loops.XORComposite; + /** * This is a class utility to draw Graphics2D stuff on a swt composite. * It is presently developed to use JFreeChart with the Standard @@ -413,7 +417,14 @@ * @see java.awt.Graphics2D#setComposite(java.awt.Composite) */ public void setComposite(Composite comp) { - // TODO Auto-generated method stub + //TODO handle XOR composite + if (comp instanceof AlphaComposite) { + int alpha = (int) (((AlphaComposite) comp).getAlpha()*0xFF); + this.gc.setAlpha(alpha); + } else { + System.out.println("warning, can only handle alpha composite at the moment."); + //this.gc.setXORMode(xor) + } } /** @@ -627,8 +638,8 @@ * @see java.awt.Graphics2D#getComposite() */ public Composite getComposite() { - // TODO Auto-generated method stub - return null; + // TODO verify if we need to handle XOR composite + return AlphaComposite.getInstance(AlphaComposite.XOR, this.gc.getAlpha()/0xFF); } /* (non-Javadoc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2007-07-25 09:25:16
|
Revision: 136 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=136&view=rev Author: nenry Date: 2007-07-25 02:25:13 -0700 (Wed, 25 Jul 2007) Log Message: ----------- pass mouse mouved events to listening ChartMouseListeners. Modified Paths: -------------- trunk/ChangeLog trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-18 14:01:19 UTC (rev 135) +++ trunk/ChangeLog 2007-07-25 09:25:13 UTC (rev 136) @@ -1,3 +1,8 @@ +2007-07-25 Henry Proudhon <hen...@in...> + + * source/swt/org/jfree/experimental/chart/swt/ChartComposite.java + pass mouse mouved events to listening ChartMouseListeners. + 2007-07-18 David Gilbert <dav...@ob...> * source/org/jfree/chart/demo/PieChartDemo1.java Modified: trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java =================================================================== --- trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java 2007-07-18 14:01:19 UTC (rev 135) +++ trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java 2007-07-25 09:25:13 UTC (rev 136) @@ -55,6 +55,7 @@ * as suggested by Christoph Beck, bug 1742002 (HP); * 06-Jul-2007 : Fixed bug in zooming with multiple plots (HP); * 06-Jul-2007 : check for null zoom point when restoring auto range and domain bounds (HP); + * 25-Jul-2007 : pass mouse mouved events to listening ChartMouseListeners (HP); */ package org.jfree.experimental.chart.swt; @@ -626,26 +627,29 @@ Listener listener = new Listener() { public void handleEvent (Event event) { + Object[] listeners; + ChartEntity entity = null; + java.awt.event.MouseEvent mouseEvent = null; + ChartMouseEvent chartEvent = null; + int x, y; switch (event.type) { case SWT.MouseDown: Rectangle scaledDataArea = getScreenDataArea(event.x, event.y); if (scaledDataArea == null) return; zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea); - Rectangle insets = getClientArea(); - int x = (int) ((event.x - insets.x) / scaleX); - int y = (int) ((event.y - insets.y) / scaleY); + x = (int) ((event.x - getClientArea().x) / scaleX); + y = (int) ((event.y - getClientArea().y) / scaleY); anchor = new Point2D.Double(x, y); chart.setNotify(true); // force a redraw canvas.redraw(); // new entity code... - Object[] listeners = chartMouseListeners.getListeners( + listeners = chartMouseListeners.getListeners( ChartMouseListener.class); if (listeners.length == 0) { return; } - ChartEntity entity = null; if (info != null) { EntityCollection entities = info.getEntityCollection(); @@ -653,16 +657,16 @@ entity = entities.getEntity(x, y); } } - java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event); - ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); + mouseEvent = SWTUtils.toAwtMouseEvent(event); + chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { - ((ChartMouseListener) - listeners[i]).chartMouseClicked(chartEvent); + ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); + ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent); } break; case SWT.MouseMove: // handle axis trace - if ( horizontalAxisTrace || verticalAxisTrace ) { + if (horizontalAxisTrace || verticalAxisTrace) { horizontalTraceLineY = event.y; verticalTraceLineX = event.x; canvas.redraw(); @@ -708,6 +712,30 @@ scaledDataArea.width, ymax - zoomPoint.y); } canvas.redraw(); + // pass mouse move event if some ChartMouseListener are listening + listeners = chartMouseListeners.getListeners( + ChartMouseListener.class); + if (listeners.length == 0) { + return; + } + + x = (int) ((event.x - getClientArea().x) / scaleX); + y = (int) ((event.y - getClientArea().y) / scaleY); + + if (info != null) { + EntityCollection entities + = info.getEntityCollection(); + if (entities != null) { + entity = entities.getEntity(x, y); + } + } + mouseEvent = SWTUtils.toAwtMouseEvent(event); + chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); + for (int i = listeners.length - 1; i >= 0; i -= 1) { + ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); + ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent); + } + break; case SWT.MouseUp: if (zoomRectangle == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-25 10:25:16
|
Revision: 139 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=139&view=rev Author: mungady Date: 2007-07-25 03:25:10 -0700 (Wed, 25 Jul 2007) Log Message: ----------- 2007-07-25 David Gilbert <dav...@ob...> * source/org/jfree/chart/axis/SymbolAxis.java (DEFAULT_GRID_BAND_ALTERNATE_PAINT): New field, (gridBandAlternatePaint): New field, (SymbolAxis): Initialise new field, (getGridBandAlternatePaint): New method, (setGridBandAlternatePaint): Likewise, (equals): Test new field, (writeObject): Handle new field, (readObject): Likewise, * tests/org/jfree/chart/axis/junit/SymbolAxisTests.java (testEquals): Added check for new field. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/axis/SymbolAxis.java trunk/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-25 10:16:42 UTC (rev 138) +++ trunk/ChangeLog 2007-07-25 10:25:10 UTC (rev 139) @@ -1,7 +1,21 @@ +2007-07-25 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/axis/SymbolAxis.java + (DEFAULT_GRID_BAND_ALTERNATE_PAINT): New field, + (gridBandAlternatePaint): New field, + (SymbolAxis): Initialise new field, + (getGridBandAlternatePaint): New method, + (setGridBandAlternatePaint): Likewise, + (equals): Test new field, + (writeObject): Handle new field, + (readObject): Likewise, + * tests/org/jfree/chart/axis/junit/SymbolAxisTests.java + (testEquals): Added check for new field. + 2007-07-25 Henry Proudhon <hen...@in...> * source/swt/org/jfree/experimental/chart/swt/ChartComposite.java - pass mouse mouved events to listening ChartMouseListeners. + pass mouse moved events to listening ChartMouseListeners. 2007-07-18 David Gilbert <dav...@ob...> Modified: trunk/source/org/jfree/chart/axis/SymbolAxis.java =================================================================== --- trunk/source/org/jfree/chart/axis/SymbolAxis.java 2007-07-25 10:16:42 UTC (rev 138) +++ trunk/source/org/jfree/chart/axis/SymbolAxis.java 2007-07-25 10:25:10 UTC (rev 139) @@ -74,6 +74,7 @@ * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 28-Feb-2007 : Fixed bug 1669302 (tick label overlap) (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); + * 25-Jul-2007 : Added new field for alternate grid band paint (DG); * */ @@ -119,15 +120,30 @@ public static final Paint DEFAULT_GRID_BAND_PAINT = new Color(232, 234, 232, 128); + /** + * The default paint for alternate grid bands. + * + * @since 1.0.7 + */ + public static final Paint DEFAULT_GRID_BAND_ALTERNATE_PAINT + = new Color(0, 0, 0, 0); // transparent + /** The list of symbols to display instead of the numeric values. */ private List symbols; + /** Flag that indicates whether or not grid bands are visible. */ + private boolean gridBandsVisible; + /** The paint used to color the grid bands (if the bands are visible). */ private transient Paint gridBandPaint; + + /** + * The paint used to fill the alternate grid bands. + * + * @since 1.0.7 + */ + private transient Paint gridBandAlternatePaint; - /** Flag that indicates whether or not grid bands are visible. */ - private boolean gridBandsVisible; - /** * Constructs a symbol axis, using default attribute values where * necessary. @@ -141,7 +157,7 @@ this.symbols = Arrays.asList(sv); this.gridBandsVisible = true; this.gridBandPaint = DEFAULT_GRID_BAND_PAINT; - + this.gridBandAlternatePaint = DEFAULT_GRID_BAND_ALTERNATE_PAINT; setAutoTickUnitSelection(false, false); setAutoRangeStickyZero(false); @@ -159,6 +175,34 @@ } /** + * Returns <code>true</code> if the grid bands are showing, and + * <code>false</code> otherwise. + * + * @return <code>true</code> if the grid bands are showing, and + * <code>false</code> otherwise. + * + * @see #setGridBandsVisible(boolean) + */ + public boolean isGridBandsVisible() { + return this.gridBandsVisible; + } + + /** + * Sets the visibility of the grid bands and notifies registered + * listeners that the axis has been modified. + * + * @param flag the new setting. + * + * @see #isGridBandsVisible() + */ + public void setGridBandsVisible(boolean flag) { + if (this.gridBandsVisible != flag) { + this.gridBandsVisible = flag; + notifyListeners(new AxisChangeEvent(this)); + } + } + + /** * Returns the paint used to color the grid bands. * * @return The grid band paint (never <code>null</code>). @@ -185,35 +229,40 @@ this.gridBandPaint = paint; notifyListeners(new AxisChangeEvent(this)); } - + /** - * Returns <code>true</code> if the grid bands are showing, and - * <code>false</code> otherwise. - * - * @return <code>true</code> if the grid bands are showing, and - * <code>false</code> otherwise. - * - * @see #setGridBandsVisible(boolean) + * Returns the paint used for alternate grid bands. + * + * @return The paint (never <code>null</code>). + * + * @see #setGridBandAlternatePaint(Paint) + * @see #getGridBandPaint() + * + * @since 1.0.7 */ - public boolean isGridBandsVisible() { - return this.gridBandsVisible; + public Paint getGridBandAlternatePaint() { + return this.gridBandAlternatePaint; } - + /** - * Sets the visibility of the grid bands and notifies registered - * listeners that the axis has been modified. - * - * @param flag the new setting. + * Sets the paint used for alternate grid bands and sends a + * {@link AxisChangeEvent} to all registered listeners. * - * @see #isGridBandsVisible() + * @param paint the paint (<code>null</code> not permitted). + * + * @see #getGridBandAlternatePaint() + * @see #setGridBandPaint(Paint) + * + * @since 1.0.7 */ - public void setGridBandsVisible(boolean flag) { - if (this.gridBandsVisible != flag) { - this.gridBandsVisible = flag; - notifyListeners(new AxisChangeEvent(this)); + public void setGridBandAlternatePaint(Paint paint) { + if (paint == null) { + throw new IllegalArgumentException("Null 'paint' argument."); } + this.gridBandAlternatePaint = paint; + notifyListeners(new AxisChangeEvent(this)); } - + /** * This operation is not supported by this axis. * @@ -734,6 +783,10 @@ if (!PaintUtilities.equal(this.gridBandPaint, that.gridBandPaint)) { return false; } + if (!PaintUtilities.equal(this.gridBandAlternatePaint, + that.gridBandAlternatePaint)) { + return false; + } return super.equals(obj); } @@ -747,6 +800,7 @@ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.gridBandPaint, stream); + SerialUtilities.writePaint(this.gridBandAlternatePaint, stream); } /** @@ -761,6 +815,7 @@ throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.gridBandPaint = SerialUtilities.readPaint(stream); + this.gridBandAlternatePaint = SerialUtilities.readPaint(stream); } } Modified: trunk/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java =================================================================== --- trunk/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java 2007-07-25 10:16:42 UTC (rev 138) +++ trunk/tests/org/jfree/chart/axis/junit/SymbolAxisTests.java 2007-07-25 10:25:10 UTC (rev 139) @@ -37,7 +37,8 @@ * Changes * ------- * 26-Mar-2003 : Version 1 (DG); - * + * 25-Jul-2007 : Added new field in testEquals() (DG); + * */ package org.jfree.chart.axis.junit; @@ -142,14 +143,19 @@ a2 = new SymbolAxis("Axis 2", new String[] {"C", "B"}); assertTrue(a1.equals(a2)); + a1.setGridBandsVisible(false); + assertFalse(a1.equals(a2)); + a2.setGridBandsVisible(false); + assertTrue(a1.equals(a2)); + a1.setGridBandPaint(Color.black); assertFalse(a1.equals(a2)); a2.setGridBandPaint(Color.black); assertTrue(a1.equals(a2)); - a1.setGridBandsVisible(false); + a1.setGridBandAlternatePaint(Color.red); assertFalse(a1.equals(a2)); - a2.setGridBandsVisible(false); + a2.setGridBandAlternatePaint(Color.red); assertTrue(a1.equals(a2)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-07-25 14:10:53
|
Revision: 143 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=143&view=rev Author: mungady Date: 2007-07-25 07:10:52 -0700 (Wed, 25 Jul 2007) Log Message: ----------- 2007-07-25 David Gilbert <dav...@ob...> Patch 1752205: * source/org/jfree/data/time/TimeTableXYDataset.java (clear): New method, * tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java (testClear): New method. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/data/time/TimeTableXYDataset.java trunk/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-25 14:02:45 UTC (rev 142) +++ trunk/ChangeLog 2007-07-25 14:10:52 UTC (rev 143) @@ -1,5 +1,13 @@ 2007-07-25 David Gilbert <dav...@ob...> + Patch 1752205: + * source/org/jfree/data/time/TimeTableXYDataset.java + (clear): New method, + * tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java + (testClear): New method. + +2007-07-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java: New file, contributed by Klaus Rheinwald. Modified: trunk/source/org/jfree/data/time/TimeTableXYDataset.java =================================================================== --- trunk/source/org/jfree/data/time/TimeTableXYDataset.java 2007-07-25 14:02:45 UTC (rev 142) +++ trunk/source/org/jfree/data/time/TimeTableXYDataset.java 2007-07-25 14:10:52 UTC (rev 143) @@ -31,6 +31,7 @@ * * Original Author: Andreas Schroeder; * Contributor(s): David Gilbert (for Object Refinery Limited); + * Rob Eden; * * $Id: TimeTableXYDataset.java,v 1.10.2.3 2007/03/09 15:43:09 mungady Exp $ * @@ -49,6 +50,7 @@ * 27-Jan-2005 : Modified to use TimePeriod rather than RegularTimePeriod (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 25-Jul-2007 : Added clear() method by Rob Eden, see patch 1752205 (DG); * */ @@ -252,6 +254,19 @@ } /** + * Removes all data items from the dataset and sends a + * {@link DatasetChangeEvent} to all registered listeners. + * + * @since 1.0.7 + */ + public void clear() { + if (this.values.getRowCount() > 0) { + this.values.clear(); + fireDatasetChanged(); + } + } + + /** * Returns the time period for the specified item. Bear in mind that all * series share the same set of time periods. * Modified: trunk/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java =================================================================== --- trunk/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java 2007-07-25 14:02:45 UTC (rev 142) +++ trunk/tests/org/jfree/data/time/junit/TimeTableXYDatasetTests.java 2007-07-25 14:10:52 UTC (rev 143) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,16 +27,17 @@ * ---------------------------- * TimeTableXYDatasetTests.java * ---------------------------- - * (C) Copyright 2004, by Object Refinery Limited. + * (C) Copyright 2004, 2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; + * Contributor(s): Rob Eden; * * $Id: TimeTableXYDatasetTests.java,v 1.1.2.1 2006/10/03 15:41:39 mungady Exp $ * * Changes * ------- * 15-Sep-2004 : Version 1 (DG); + * 25-Jul-2007 : Added test for clear() method, by Rob Eden (DG); * */ @@ -132,9 +133,8 @@ assertTrue(d1.equals(d2)); d1 = new TimeTableXYDataset(TimeZone.getTimeZone("GMT")); - d2 = new TimeTableXYDataset( - TimeZone.getTimeZone("America/Los_Angeles") - ); + d2 = new TimeTableXYDataset(TimeZone.getTimeZone( + "America/Los_Angeles")); assertFalse(d1.equals(d2)); } @@ -175,17 +175,32 @@ out.writeObject(d1); out.close(); - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); d2 = (TimeTableXYDataset) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertTrue(d1.equals(d2)); } + + /** + * Test clearing data. + */ + public void testClear() { + TimeTableXYDataset d = new TimeTableXYDataset(); + d.add(new Year(1999), 1.0, "Series 1"); + assertEquals(d.getItemCount(), 1); + assertEquals(d.getSeriesCount(), 1); + d.add(new Year(2000), 2.0, "Series 2"); + d.clear(); + // Make sure there's nothing left + assertEquals(0, d.getItemCount()); + assertEquals(0, d.getSeriesCount()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-01 09:47:07
|
Revision: 146 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=146&view=rev Author: mungady Date: 2007-08-01 02:47:04 -0700 (Wed, 01 Aug 2007) Log Message: ----------- 2007-07-31 David Gilbert <dav...@ob...> Bug 1763413: * source/org/jfree/chart/axis/PeriodAxis.java (drawTickLabels): Calculate tick label width correctly for inverted axis. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/axis/PeriodAxis.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-07-31 14:06:00 UTC (rev 145) +++ trunk/ChangeLog 2007-08-01 09:47:04 UTC (rev 146) @@ -1,5 +1,11 @@ 2007-07-31 David Gilbert <dav...@ob...> + Bug 1763413: + * source/org/jfree/chart/axis/PeriodAxis.java + (drawTickLabels): Calculate tick label width correctly for inverted axis. + +2007-07-31 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java (ignoreZeroValues): New field, (getIgnoreZeroValues): New method, Modified: trunk/source/org/jfree/chart/axis/PeriodAxis.java =================================================================== --- trunk/source/org/jfree/chart/axis/PeriodAxis.java 2007-07-31 14:06:00 UTC (rev 145) +++ trunk/source/org/jfree/chart/axis/PeriodAxis.java 2007-08-01 09:47:04 UTC (rev 146) @@ -52,6 +52,7 @@ * 22-Mar-2007 : Use new defaultAutoRange attribute (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); * 02-Jul-2007 : Added entity support for axis labels (DG); + * 31-Jul-2007 : Fix for inverted axis labelling (see bug 1763413) (DG); * */ @@ -810,7 +811,13 @@ g2.getFontMetrics()); double w = Math.max(b1.getWidth(), b2.getWidth()); long ww = Math.round(java2DToValue(dataArea.getX() + w + 5.0, - dataArea, edge)) - axisMin; + dataArea, edge)); + if (isInverted()) { + ww = axisMax - ww; + } + else { + ww = ww - axisMin; + } long length = p1.getLastMillisecond(this.calendar) - p1.getFirstMillisecond(this.calendar); int periods = (int) (ww / length) + 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-08-03 10:01:53
|
Revision: 157 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=157&view=rev Author: mungady Date: 2007-08-03 03:01:49 -0700 (Fri, 03 Aug 2007) Log Message: ----------- 2007-08-03 David Gilbert <dav...@ob...> Fix for bug 1766646: * source/org/jfree/chart/renderer/xy/XYBlockRenderer.java (findDomainBounds): Check for null, (findRangeBounds): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-08-03 10:00:43 UTC (rev 156) +++ trunk/ChangeLog 2007-08-03 10:01:49 UTC (rev 157) @@ -1,5 +1,12 @@ 2007-08-03 David Gilbert <dav...@ob...> + Fix for bug 1766646: + * source/org/jfree/chart/renderer/xy/XYBlockRenderer.java + (findDomainBounds): Check for null, + (findRangeBounds): Likewise. + +2007-08-03 David Gilbert <dav...@ob...> + * source/org/jfree/chart/LegendItem.java (LegendItem): Initialise GradientPaintTransformer. Modified: trunk/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java 2007-08-03 10:00:43 UTC (rev 156) +++ trunk/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java 2007-08-03 10:01:49 UTC (rev 157) @@ -40,6 +40,7 @@ * 02-Feb-2007 : Added getPaintScale() method (DG); * 09-Mar-2007 : Fixed cloning (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 03-Aug-2007 : Fix for bug 1766646 (DG); * */ @@ -277,12 +278,19 @@ * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). + * + * @see #findRangeBounds(XYDataset) */ public Range findDomainBounds(XYDataset dataset) { if (dataset != null) { Range r = DatasetUtilities.findDomainBounds(dataset, false); - return new Range(r.getLowerBound() + this.xOffset, - r.getUpperBound() + this.blockWidth + this.xOffset); + if (r == null) { + return null; + } + else { + return new Range(r.getLowerBound() + this.xOffset, + r.getUpperBound() + this.blockWidth + this.xOffset); + } } else { return null; @@ -297,12 +305,19 @@ * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). + * + * @see #findDomainBounds(XYDataset) */ public Range findRangeBounds(XYDataset dataset) { if (dataset != null) { Range r = DatasetUtilities.findRangeBounds(dataset, false); - return new Range(r.getLowerBound() + this.yOffset, - r.getUpperBound() + this.blockHeight + this.yOffset); + if (r == null) { + return null; + } + else { + return new Range(r.getLowerBound() + this.yOffset, + r.getUpperBound() + this.blockHeight + this.yOffset); + } } else { return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2007-08-27 15:47:14
|
Revision: 162 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=162&view=rev Author: nenry Date: 2007-08-27 03:36:34 -0700 (Mon, 27 Aug 2007) Log Message: ----------- Modified Paths: -------------- trunk/ChangeLog trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java trunk/swt/org/jfree/experimental/swt/SWTUtils.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-08-03 10:42:52 UTC (rev 161) +++ trunk/ChangeLog 2007-08-27 10:36:34 UTC (rev 162) @@ -1,3 +1,13 @@ +2007-08-27 Henry Proudhon <hen...@in...> + + * source/swt/org/jfree/experimental/chart/swt/ChartComposite.java + (ChartComposite): refactored class, now implements PaintListener, + MouseListener and MouseMovedListener; + (chart) Made the chart field be private again; + (addSWTListener): new method; + * source/swt/org/jfree/experimental/swt/SWTUtils.java + (toAwtMouseEvent): changed method signature. + 2007-08-03 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/XYSplineAndShapeRenderer.java Modified: trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java =================================================================== --- trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java 2007-08-03 10:42:52 UTC (rev 161) +++ trunk/swt/org/jfree/experimental/chart/swt/ChartComposite.java 2007-08-27 10:36:34 UTC (rev 162) @@ -56,12 +56,16 @@ * 06-Jul-2007 : Fixed bug in zooming with multiple plots (HP); * 06-Jul-2007 : check for null zoom point when restoring auto range and domain bounds (HP); * 25-Jul-2007 : pass mouse mouved events to listening ChartMouseListeners (HP); + * 27-Aug-2007 : refactored class, now implements PaintListener, MouseListener, + * MouseMoveListener. Made the chart field be private again and added + * new method addSWTListener to allow custom behavior. */ package org.jfree.experimental.chart.swt; import java.awt.Graphics; import java.awt.Point; +import java.awt.RenderingHints; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.print.PageFormat; @@ -75,19 +79,31 @@ import javax.swing.event.EventListenerList; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.DragDetectListener; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.HelpListener; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MenuDetectListener; import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.events.MouseWheelListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.internal.SWTEventListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.MessageBox; @@ -120,7 +136,10 @@ */ public class ChartComposite extends Composite implements ChartChangeListener, ChartProgressListener, + PaintListener, SelectionListener, + MouseListener, + MouseMoveListener, Printable { /** Default setting for buffer usage. */ @@ -184,9 +203,9 @@ public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE"; /** The chart that is displayed in the panel. */ - public JFreeChart chart; + private JFreeChart chart; - /** The canvas to display the chart */ + /** The canvas to display the chart. */ private Canvas canvas; /** Storage for registered (chart) mouse listeners. */ @@ -504,109 +523,12 @@ this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; this.setDisplayToolTips(tooltips); + // create the canvas and add the required listeners canvas = new Canvas(this, SWT.NO_BACKGROUND); - canvas.addPaintListener(new PaintListener() { + canvas.addPaintListener(this); + canvas.addMouseListener(this); + canvas.addMouseMoveListener(this); - public void paintControl(PaintEvent e) { - // first determine the size of the chart rendering area... - // TODO workout insets for SWT - Rectangle available = getBounds(); - // skip if chart is null - if (chart == null) { - canvas.drawBackground(e.gc, available.x, available.y, - available.width, available.height); - return; - } - SWTGraphics2D sg2 = new SWTGraphics2D(e.gc); - - // work out if scaling is required... - boolean scale = false; - int drawWidth = available.width; - int drawHeight = available.height; - if ( drawWidth == 0.0 || drawHeight == 0.0 ) return; - scaleX = 1.0; - scaleY = 1.0; - if (drawWidth < minimumDrawWidth) { - scaleX = (double) drawWidth / minimumDrawWidth; - drawWidth = minimumDrawWidth; - scale = true; - } - else if (drawWidth > maximumDrawWidth) { - scaleX = (double) drawWidth / maximumDrawWidth; - drawWidth = maximumDrawWidth; - scale = true; - } - if (drawHeight < minimumDrawHeight) { - scaleY = (double) drawHeight / minimumDrawHeight; - drawHeight = minimumDrawHeight; - scale = true; - } - else if (drawHeight > maximumDrawHeight) { - scaleY = (double) drawHeight / maximumDrawHeight; - drawHeight = maximumDrawHeight; - scale = true; - } - // are we using the chart buffer? - if (useBuffer) { - //SwtGraphics2D sg2 = new SwtGraphics2D( e.gc ); - chartBuffer = (org.eclipse.swt.graphics.Image) - canvas.getData("double-buffer-image"); - // do we need to fill the buffer? - if (chartBuffer == null - || chartBufferWidth != available.width - || chartBufferHeight != available.height ) { - chartBufferWidth = available.width; - chartBufferHeight = available.height; - if (chartBuffer != null) { - chartBuffer.dispose(); - } - chartBuffer = new org.eclipse.swt.graphics.Image( - getDisplay(), chartBufferWidth, - chartBufferHeight); - refreshBuffer = true; - } - - // do we need to redraw the buffer? - if (refreshBuffer) { - // Performs the actual drawing here ... - GC gci = new GC(chartBuffer); - SWTGraphics2D sg2d = new SWTGraphics2D(gci); - if (scale) { - sg2d.scale(scaleX, scaleY); - chart.draw(sg2d, new Rectangle2D.Double(0, 0, - drawWidth, drawHeight), getAnchor(), info); - } else { - chart.draw(sg2d, new Rectangle2D.Double(0, 0, - drawWidth, drawHeight), getAnchor(), info); - } - canvas.setData("double-buffer-image", chartBuffer); - sg2d.dispose(); - gci.dispose(); - refreshBuffer = false; - } - - // zap the buffer onto the canvas... - sg2.drawImage(chartBuffer, 0, 0); - } - // or redrawing the chart every time... - else { - chart.draw(sg2, new Rectangle2D.Double(0, 0, - getBounds().width, getBounds().height), getAnchor(), info); - } - Rectangle area = getScreenDataArea(); - //TODO see if we need to apply some line color and style to the axis traces - if (verticalAxisTrace && area.x < verticalTraceLineX - && area.x + area.width > verticalTraceLineX) - e.gc.drawLine(verticalTraceLineX, area.y, verticalTraceLineX, area.y + area.height); - if (horizontalAxisTrace && area.y < horizontalTraceLineY - && area.y + area.height > horizontalTraceLineY) - e.gc.drawLine(area.x, horizontalTraceLineY, area.x + area.width, horizontalTraceLineY); - verticalTraceLineX = 0; - horizontalTraceLineY = 0; - if (zoomRectangle != null) e.gc.drawRectangle(zoomRectangle); - sg2.dispose(); - } - } ); if (chart != null) { chart.addChangeListener(this); Plot plot = chart.getPlot(); @@ -625,176 +547,6 @@ if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); - Listener listener = new Listener() { - public void handleEvent (Event event) { - Object[] listeners; - ChartEntity entity = null; - java.awt.event.MouseEvent mouseEvent = null; - ChartMouseEvent chartEvent = null; - int x, y; - boolean hZoom = false; - boolean vZoom = false; - switch (event.type) { - case SWT.MouseDown: - - Rectangle scaledDataArea = getScreenDataArea(event.x, event.y); - if (scaledDataArea == null) return; - zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea); - x = (int) ((event.x - getClientArea().x) / scaleX); - y = (int) ((event.y - getClientArea().y) / scaleY); - - anchor = new Point2D.Double(x, y); - chart.setNotify(true); // force a redraw - canvas.redraw(); - - // new entity code - listeners = chartMouseListeners.getListeners( - ChartMouseListener.class); - if (listeners.length == 0) { - return; - } - - if (info != null) { - EntityCollection entities - = info.getEntityCollection(); - if (entities != null) { - entity = entities.getEntity(x, y); - } - } - - // pass mouse clicked event if some ChartMouseListener are listening - mouseEvent = SWTUtils.toAwtMouseEvent(event); - chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); - for (int i = listeners.length - 1; i >= 0; i -= 1) { - ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); - } - break; - case SWT.MouseMove: - - // handle axis trace - if (horizontalAxisTrace || verticalAxisTrace) { - horizontalTraceLineY = event.y; - verticalTraceLineX = event.x; - canvas.redraw(); - } - - // handle tool tips in a simple way - if (displayToolTips) { - String s = getToolTipText(new MouseEvent(event)); - if (s == null && canvas.getToolTipText() != null - || s!=null && !s.equals(canvas.getToolTipText())) - canvas.setToolTipText(s); - } - - // handle zoom box - if (zoomPoint != null) { - scaledDataArea = getScreenDataArea(zoomPoint.x, zoomPoint.y); - org.eclipse.swt.graphics.Point movingPoint - = getPointInRectangle(event.x, event.y, scaledDataArea); - if (orientation == PlotOrientation.HORIZONTAL) { - hZoom = rangeZoomable; - vZoom = domainZoomable; - } - else { - hZoom = domainZoomable; - vZoom = rangeZoomable; - } - if (hZoom && vZoom) { - // selected rectangle shouldn't extend outside the data area... - zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, - movingPoint.x - zoomPoint.x, movingPoint.y - zoomPoint.y); - } - else if (hZoom) { - zoomRectangle = new Rectangle(zoomPoint.x, scaledDataArea.y, - movingPoint.x - zoomPoint.x, scaledDataArea.height); - } - else if (vZoom) { - int ymax = Math.max(movingPoint.y, scaledDataArea.y); - zoomRectangle = new Rectangle( - scaledDataArea.x, zoomPoint.y, - scaledDataArea.width, ymax - zoomPoint.y); - } - canvas.redraw(); - } - - // new entity code - listeners = chartMouseListeners.getListeners( - ChartMouseListener.class); - if (listeners.length == 0) { - return; - } - - x = (int) ((event.x - getClientArea().x) / scaleX); - y = (int) ((event.y - getClientArea().y) / scaleY); - - if (info != null) { - EntityCollection entities - = info.getEntityCollection(); - if (entities != null) { - entity = entities.getEntity(x, y); - } - } - - // pass mouse move event if some ChartMouseListener are listening - mouseEvent = SWTUtils.toAwtMouseEvent(event); - chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); - for (int i = listeners.length - 1; i >= 0; i -= 1) { - ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent); - } - - break; - case SWT.MouseUp: - if (zoomRectangle == null) { - Rectangle screenDataArea = getScreenDataArea(event.x, event.y); - if (screenDataArea != null) { - zoomPoint = getPointInRectangle(event.x, event.y, screenDataArea); - } - if (popup != null && event.button == 3) { - org.eclipse.swt.graphics.Point pt = canvas.toDisplay(event.x, event.y); - displayPopupMenu(pt.x, pt.y); - } - } - else { - hZoom = false; - vZoom = false; - if (orientation == PlotOrientation.HORIZONTAL) { - hZoom = rangeZoomable; - vZoom = domainZoomable; - } - else { - hZoom = domainZoomable; - vZoom = rangeZoomable; - } - boolean zoomTrigger1 = hZoom - && Math.abs(zoomRectangle.width) - >= zoomTriggerDistance; - boolean zoomTrigger2 = vZoom - && Math.abs(zoomRectangle.height) - >= zoomTriggerDistance; - if (zoomTrigger1 || zoomTrigger2) { - // if the box has been drawn backwards, restore the auto bounds - if ((hZoom && (zoomRectangle.x + zoomRectangle.width < zoomPoint.x)) - || (vZoom && (zoomRectangle.y + zoomRectangle.height < zoomPoint.y))) - restoreAutoBounds(); - else { - zoom(zoomRectangle); - } - canvas.redraw(); - } - } - zoomPoint = null; - zoomRectangle = null; - break; - default: - zoomPoint = null; - zoomRectangle = null; - } - } - }; - canvas.addListener(SWT.MouseDown, listener); - canvas.addListener(SWT.MouseMove, listener); - canvas.addListener(SWT.MouseUp, listener); - this.enforceFileExtensions = true; } @@ -1497,7 +1249,7 @@ Menu result = new Menu(this); boolean separator = false; - if ( properties ) { + if (properties) { MenuItem propertiesItem = new MenuItem(result, SWT.PUSH); propertiesItem.setText(localizationResources.getString( "Properties...")); @@ -1505,8 +1257,7 @@ propertiesItem.addSelectionListener(this); separator = true; } - if (save) - { + if (save) { if (separator) { new MenuItem(result, SWT.SEPARATOR); separator = false; @@ -1549,17 +1300,17 @@ this.zoomInDomainMenuItem = new MenuItem(zoomInMenu, SWT.PUSH); this.zoomInDomainMenuItem.setText(localizationResources.getString( - "Domain_Axis" ) ); + "Domain_Axis")); this.zoomInDomainMenuItem.setData(ZOOM_IN_DOMAIN_COMMAND); this.zoomInDomainMenuItem.addSelectionListener(this); this.zoomInRangeMenuItem = new MenuItem(zoomInMenu, SWT.PUSH); this.zoomInRangeMenuItem.setText(localizationResources.getString( - "Range_Axis" ) ); + "Range_Axis")); this.zoomInRangeMenuItem.setData(ZOOM_IN_RANGE_COMMAND); this.zoomInRangeMenuItem.addSelectionListener(this); - Menu zoomOutMenu = new Menu( result ); + Menu zoomOutMenu = new Menu(result); MenuItem zoomOutMenuItem = new MenuItem(result, SWT.CASCADE); zoomOutMenuItem.setText(localizationResources.getString( "Zoom_Out")); @@ -1577,7 +1328,7 @@ this.zoomOutDomainMenuItem.setText(localizationResources.getString( "Domain_Axis")); this.zoomOutDomainMenuItem.setData(ZOOM_OUT_DOMAIN_COMMAND); - this.zoomOutDomainMenuItem.addSelectionListener( this ); + this.zoomOutDomainMenuItem.addSelectionListener(this); this.zoomOutRangeMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH); this.zoomOutRangeMenuItem.setText( @@ -1623,8 +1374,7 @@ * org.eclipse.swt.events.SelectionEvent) */ public void widgetDefaultSelected(SelectionEvent e) { - // TODO Auto-generated method stub - + this.widgetSelected(e); } /** @@ -1701,5 +1451,329 @@ */ return PAGE_EXISTS; } + + /** + * Hook an SWT listener on the canvas where the chart is drawn. + * The purpose of this method is to allow some degree of customization. + * @param listener The SWT listener to attach to the canvas. + */ + public void addSWTListener(SWTEventListener listener) { + if (listener instanceof ControlListener) { + this.canvas.addControlListener((ControlListener) listener); + } else if (listener instanceof DisposeListener) { + this.canvas.addDisposeListener((DisposeListener) listener); + } else if (listener instanceof DragDetectListener) { + this.canvas.addDragDetectListener((DragDetectListener) listener); + } else if (listener instanceof FocusListener) { + this.canvas.addFocusListener((FocusListener) listener); + } else if (listener instanceof HelpListener) { + this.canvas.addHelpListener((HelpListener) listener); + } else if (listener instanceof KeyListener) { + this.canvas.addKeyListener((KeyListener) listener); + } else if (listener instanceof MenuDetectListener) { + this.canvas.addMenuDetectListener((MenuDetectListener) listener); + } else if (listener instanceof MouseListener) { + this.canvas.addMouseListener((MouseListener) listener); + } else if (listener instanceof MouseMoveListener) { + this.canvas.addMouseMoveListener((MouseMoveListener) listener); + } else if (listener instanceof MouseTrackListener) { + this.canvas.addMouseTrackListener((MouseTrackListener) listener); + } else if (listener instanceof MouseWheelListener) { + this.canvas.addMouseWheelListener((MouseWheelListener) listener); + } else if (listener instanceof PaintListener) { + this.canvas.addPaintListener((PaintListener) listener); + } else if (listener instanceof TraverseListener) { + this.canvas.addTraverseListener((TraverseListener) listener); + } + } + /* (non-Javadoc) + * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent) + */ + public void mouseDoubleClick(MouseEvent event) { + // do nothing, override if necessary + } + + /* (non-Javadoc) + * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent) + */ + public void mouseDown(MouseEvent event) { + + Rectangle scaledDataArea = getScreenDataArea(event.x, event.y); + if (scaledDataArea == null) return; + zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea); + int x = (int) ((event.x - getClientArea().x) / scaleX); + int y = (int) ((event.y - getClientArea().y) / scaleY); + + anchor = new Point2D.Double(x, y); + chart.setNotify(true); // force a redraw + canvas.redraw(); + + // new entity code + ChartEntity entity = null; + if (info != null) { + EntityCollection entities + = info.getEntityCollection(); + if (entities != null) { + entity = entities.getEntity(x, y); + } + } + + Object[] listeners = chartMouseListeners.getListeners( + ChartMouseListener.class); + if (listeners.length == 0) { + return; + } + + // pass mouse down event if some ChartMouseListener are listening + java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event); + ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); + for (int i = listeners.length - 1; i >= 0; i -= 1) { + ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); + } + } + + /* (non-Javadoc) + * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent) + */ + public void mouseUp(MouseEvent event) { + + boolean hZoom, vZoom; + if (zoomRectangle == null) { + Rectangle screenDataArea = getScreenDataArea(event.x, event.y); + if (screenDataArea != null) { + zoomPoint = getPointInRectangle(event.x, event.y, screenDataArea); + } + if (popup != null && event.button == 3) { + org.eclipse.swt.graphics.Point pt = canvas.toDisplay(event.x, event.y); + displayPopupMenu(pt.x, pt.y); + } + } + else { + hZoom = false; + vZoom = false; + if (orientation == PlotOrientation.HORIZONTAL) { + hZoom = rangeZoomable; + vZoom = domainZoomable; + } + else { + hZoom = domainZoomable; + vZoom = rangeZoomable; + } + boolean zoomTrigger1 = hZoom + && Math.abs(zoomRectangle.width) + >= zoomTriggerDistance; + boolean zoomTrigger2 = vZoom + && Math.abs(zoomRectangle.height) + >= zoomTriggerDistance; + if (zoomTrigger1 || zoomTrigger2) { + // if the box has been drawn backwards, restore the auto bounds + if ((hZoom && (zoomRectangle.x + zoomRectangle.width < zoomPoint.x)) + || (vZoom && (zoomRectangle.y + zoomRectangle.height < zoomPoint.y))) + restoreAutoBounds(); + else { + zoom(zoomRectangle); + } + canvas.redraw(); + } + } + zoomPoint = null; + zoomRectangle = null; + } + + /* (non-Javadoc) + * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent) + */ + public void mouseMove(MouseEvent event) { + + // handle axis trace + if (horizontalAxisTrace || verticalAxisTrace) { + horizontalTraceLineY = event.y; + verticalTraceLineX = event.x; + canvas.redraw(); + } + + // handle tool tips in a simple way + if (displayToolTips) { + String s = getToolTipText(event); + if (s == null && canvas.getToolTipText() != null + || s!=null && !s.equals(canvas.getToolTipText())) + canvas.setToolTipText(s); + } + + // handle zoom box + boolean hZoom, vZoom; + if (zoomPoint != null) { + Rectangle scaledDataArea = getScreenDataArea(zoomPoint.x, zoomPoint.y); + org.eclipse.swt.graphics.Point movingPoint + = getPointInRectangle(event.x, event.y, scaledDataArea); + if (orientation == PlotOrientation.HORIZONTAL) { + hZoom = rangeZoomable; + vZoom = domainZoomable; + } + else { + hZoom = domainZoomable; + vZoom = rangeZoomable; + } + if (hZoom && vZoom) { + // selected rectangle shouldn't extend outside the data area... + zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, + movingPoint.x - zoomPoint.x, movingPoint.y - zoomPoint.y); + } + else if (hZoom) { + zoomRectangle = new Rectangle(zoomPoint.x, scaledDataArea.y, + movingPoint.x - zoomPoint.x, scaledDataArea.height); + } + else if (vZoom) { + int ymax = Math.max(movingPoint.y, scaledDataArea.y); + zoomRectangle = new Rectangle( + scaledDataArea.x, zoomPoint.y, + scaledDataArea.width, ymax - zoomPoint.y); + } + canvas.redraw(); + } + + // new entity code + ChartEntity entity = null; + int x = (int) ((event.x - getClientArea().x) / scaleX); + int y = (int) ((event.y - getClientArea().y) / scaleY); + + if (info != null) { + EntityCollection entities + = info.getEntityCollection(); + if (entities != null) { + entity = entities.getEntity(x, y); + } + } + + Object[] listeners = chartMouseListeners.getListeners( + ChartMouseListener.class); + if (listeners.length == 0) { + return; + } + + // pass mouse move event if some ChartMouseListener are listening + java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event); + ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); + for (int i = listeners.length - 1; i >= 0; i -= 1) { + ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent); + } + } + + /* (non-Javadoc) + * @see org.eclipse.swt.events.PaintListener#paintComponent(org.eclipse.swt.events.PaintEvent) + */ + public void paintControl(PaintEvent e) { + // first determine the size of the chart rendering area... + // TODO workout insets for SWT + Rectangle available = getBounds(); + // skip if chart is null + if (chart == null) { + canvas.drawBackground(e.gc, available.x, available.y, + available.width, available.height); + return; + } + SWTGraphics2D sg2 = new SWTGraphics2D(e.gc); + + // work out if scaling is required... + boolean scale = false; + int drawWidth = available.width; + int drawHeight = available.height; + if ( drawWidth == 0.0 || drawHeight == 0.0 ) return; + scaleX = 1.0; + scaleY = 1.0; + if (drawWidth < minimumDrawWidth) { + scaleX = (double) drawWidth / minimumDrawWidth; + drawWidth = minimumDrawWidth; + scale = true; + } + else if (drawWidth > maximumDrawWidth) { + scaleX = (double) drawWidth / maximumDrawWidth; + drawWidth = maximumDrawWidth; + scale = true; + } + if (drawHeight < minimumDrawHeight) { + scaleY = (double) drawHeight / minimumDrawHeight; + drawHeight = minimumDrawHeight; + scale = true; + } + else if (drawHeight > maximumDrawHeight) { + scaleY = (double) drawHeight / maximumDrawHeight; + drawHeight = maximumDrawHeight; + scale = true; + } + // are we using the chart buffer? + if (useBuffer) { + //SwtGraphics2D sg2 = new SwtGraphics2D( e.gc ); + chartBuffer = (org.eclipse.swt.graphics.Image) + canvas.getData("double-buffer-image"); + // do we need to fill the buffer? + if (chartBuffer == null + || chartBufferWidth != available.width + || chartBufferHeight != available.height ) { + chartBufferWidth = available.width; + chartBufferHeight = available.height; + if (chartBuffer != null) { + chartBuffer.dispose(); + } + chartBuffer = new org.eclipse.swt.graphics.Image( + getDisplay(), chartBufferWidth, + chartBufferHeight); + refreshBuffer = true; + } + + // do we need to redraw the buffer? + if (refreshBuffer) { + // Performs the actual drawing here ... + GC gci = new GC(chartBuffer); + // anti-aliasing + if (chart.getAntiAlias()) { + gci.setAntialias(SWT.ON); + } + if (chart.getTextAntiAlias() == RenderingHints.KEY_TEXT_ANTIALIASING) { + gci.setTextAntialias(SWT.ON); + } + SWTGraphics2D sg2d = new SWTGraphics2D(gci); + if (scale) { + sg2d.scale(scaleX, scaleY); + chart.draw(sg2d, new Rectangle2D.Double(0, 0, + drawWidth, drawHeight), getAnchor(), info); + } else { + chart.draw(sg2d, new Rectangle2D.Double(0, 0, + drawWidth, drawHeight), getAnchor(), info); + } + canvas.setData("double-buffer-image", chartBuffer); + sg2d.dispose(); + gci.dispose(); + refreshBuffer = false; + } + + // zap the buffer onto the canvas... + sg2.drawImage(chartBuffer, 0, 0); + } + // or redrawing the chart every time... + else { + if (chart.getAntiAlias()) { + e.gc.setAntialias(SWT.ON); + } + if (chart.getTextAntiAlias() == RenderingHints.KEY_TEXT_ANTIALIASING) { + e.gc.setTextAntialias(SWT.ON); + } + chart.draw(sg2, new Rectangle2D.Double(0, 0, + getBounds().width, getBounds().height), getAnchor(), info); + } + Rectangle area = getScreenDataArea(); + //TODO see if we need to apply some line color and style to the axis traces + if (verticalAxisTrace && area.x < verticalTraceLineX + && area.x + area.width > verticalTraceLineX) + e.gc.drawLine(verticalTraceLineX, area.y, verticalTraceLineX, area.y + area.height); + if (horizontalAxisTrace && area.y < horizontalTraceLineY + && area.y + area.height > horizontalTraceLineY) + e.gc.drawLine(area.x, horizontalTraceLineY, area.x + area.width, horizontalTraceLineY); + verticalTraceLineX = 0; + horizontalTraceLineY = 0; + if (zoomRectangle != null) e.gc.drawRectangle(zoomRectangle); + sg2.dispose(); + } + } Modified: trunk/swt/org/jfree/experimental/swt/SWTUtils.java =================================================================== --- trunk/swt/org/jfree/experimental/swt/SWTUtils.java 2007-08-03 10:42:52 UTC (rev 161) +++ trunk/swt/org/jfree/experimental/swt/SWTUtils.java 2007-08-27 10:36:34 UTC (rev 162) @@ -41,6 +41,7 @@ * added a new convert method for mouse events (HP); * 12-Jul-2007 : improved the mouse event conversion with buttons * and modifiers handling, patch sent by Christoph Beck (HP); + * 27-Aug-2007 : modified toAwtMouseEvent signature (HP). */ package org.jfree.experimental.swt; @@ -364,7 +365,7 @@ * @param event The swt event. * @return A AWT mouse event based on the given SWT event. */ - public static MouseEvent toAwtMouseEvent(org.eclipse.swt.widgets.Event event) { + public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) { int button = MouseEvent.NOBUTTON; switch (event.button) { case 1: button = MouseEvent.BUTTON1; break; @@ -385,4 +386,5 @@ event.time, modifiers, event.x, event.y, 1, false, button); return awtMouseEvent; } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-24 15:20:12
|
Revision: 175 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=175&view=rev Author: mungady Date: 2007-09-24 08:20:10 -0700 (Mon, 24 Sep 2007) Log Message: ----------- 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartPanel.java (paintComponent): Clear chart buffer before refreshing. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/ChartPanel.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-24 15:16:25 UTC (rev 174) +++ trunk/ChangeLog 2007-09-24 15:20:10 UTC (rev 175) @@ -1,6 +1,11 @@ 2007-09-24 David Gilbert <dav...@ob...> * source/org/jfree/chart/ChartPanel.java + (paintComponent): Clear chart buffer before refreshing. + +2007-09-24 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/ChartPanel.java (zoomAroundAnchor): New field, (getZoomAroundAnchor): New method, (setZoomAroundAnchor): Likewise, Modified: trunk/source/org/jfree/chart/ChartPanel.java =================================================================== --- trunk/source/org/jfree/chart/ChartPanel.java 2007-09-24 15:16:25 UTC (rev 174) +++ trunk/source/org/jfree/chart/ChartPanel.java 2007-09-24 15:20:10 UTC (rev 175) @@ -134,7 +134,8 @@ * 24-May-2007 : When the look-and-feel changes, update the popup menu if there * is one (DG); * 06-Jun-2007 : Fixed coordinates for drawing buffer image (DG); - * 24-Sep-2007 : Added zoomAroundAnchor flag (DG); + * 24-Sep-2007 : Added zoomAroundAnchor flag, and handle clearing of chart + * buffer (DG); * */ @@ -1249,20 +1250,24 @@ // are we using the chart buffer? if (this.useBuffer) { + // if buffer is being refreshed, it needs clearing unless it is + // new - use the following flag to track this... + boolean clearBuffer = true; + // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) - || (this.chartBufferHeight != available.getHeight()) - ) { + || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); - this.chartBuffer = createImage( - this.chartBufferWidth, this.chartBufferHeight); + this.chartBuffer = createImage(this.chartBufferWidth, + this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; + clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? @@ -1271,8 +1276,12 @@ Rectangle2D bufferArea = new Rectangle2D.Double( 0, 0, this.chartBufferWidth, this.chartBufferHeight); - Graphics2D bufferG2 - = (Graphics2D) this.chartBuffer.getGraphics(); + Graphics2D bufferG2 = (Graphics2D) + this.chartBuffer.getGraphics(); + if (clearBuffer) { + bufferG2.clearRect(0, 0, this.chartBufferWidth, + this.chartBufferHeight); + } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 10:47:01
|
Revision: 181 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=181&view=rev Author: mungady Date: 2007-09-26 03:46:58 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/XYPlot.java (getQuadrantPaint): Improve exception text, (setQuadrantPaint): Likewise, (getDomainAxisForDataset): Likewise, (getRangeAxisForDataset): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/plot/XYPlot.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-26 10:16:48 UTC (rev 180) +++ trunk/ChangeLog 2007-09-26 10:46:58 UTC (rev 181) @@ -1,5 +1,13 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/XYPlot.java + (getQuadrantPaint): Improve exception text, + (setQuadrantPaint): Likewise, + (getDomainAxisForDataset): Likewise, + (getRangeAxisForDataset): Likewise. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/Marker.java (readObject): Initialise listener list, * tests/org/jfree/chart/plot/junit/ValueMarkerTests.java Modified: trunk/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/XYPlot.java 2007-09-26 10:16:48 UTC (rev 180) +++ trunk/source/org/jfree/chart/plot/XYPlot.java 2007-09-26 10:46:58 UTC (rev 181) @@ -191,6 +191,7 @@ * 27-Jun-2007 : Updated drawDomainGridlines() method for renamed method in * XYItemRenderer interface. * 24-Sep-2007 : Added new zoom methods (DG); + * 26-Sep-2007 : Include index value in IllegalArgumentExceptions (DG); * */ @@ -2021,8 +2022,8 @@ */ public Paint getQuadrantPaint(int index) { if (index < 0 || index > 3) { - throw new IllegalArgumentException( - "The index should be in the range 0 to 3."); + throw new IllegalArgumentException("The index value (" + index + + ") should be in the range 0 to 3."); } return this.quadrantPaint[index]; } @@ -2038,8 +2039,8 @@ */ public void setQuadrantPaint(int index, Paint paint) { if (index < 0 || index > 3) { - throw new IllegalArgumentException( - "The index should be in the range 0 to 3."); + throw new IllegalArgumentException("The index value (" + index + + ") should be in the range 0 to 3."); } this.quadrantPaint[index] = paint; notifyListeners(new PlotChangeEvent(this)); @@ -3147,7 +3148,8 @@ public ValueAxis getDomainAxisForDataset(int index) { if (index < 0 || index >= getDatasetCount()) { - throw new IllegalArgumentException("Index 'index' out of bounds."); + throw new IllegalArgumentException("Index " + index + + " out of bounds."); } ValueAxis valueAxis = null; @@ -3173,7 +3175,8 @@ public ValueAxis getRangeAxisForDataset(int index) { if (index < 0 || index >= getDatasetCount()) { - throw new IllegalArgumentException("Index 'index' out of bounds."); + throw new IllegalArgumentException("Index " + index + + " out of bounds."); } ValueAxis valueAxis = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 11:04:08
|
Revision: 183 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=183&view=rev Author: mungady Date: 2007-09-26 04:03:59 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/data/general/Series.java (getItemCount): New abstract method, (isEmpty): New method. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/data/general/Series.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-26 11:01:36 UTC (rev 182) +++ trunk/ChangeLog 2007-09-26 11:03:59 UTC (rev 183) @@ -1,5 +1,11 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/data/general/Series.java + (getItemCount): New abstract method, + (isEmpty): New method. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/XYPlot.java (getQuadrantPaint): Improve exception text, (setQuadrantPaint): Likewise, Modified: trunk/source/org/jfree/data/general/Series.java =================================================================== --- trunk/source/org/jfree/data/general/Series.java 2007-09-26 11:01:36 UTC (rev 182) +++ trunk/source/org/jfree/data/general/Series.java 2007-09-26 11:03:59 UTC (rev 183) @@ -51,6 +51,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 04-May-2006 : Updated API docs (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 26-Sep-2007 : Added isEmpty() and getItemCount() methods (DG); * */ @@ -202,6 +203,25 @@ } /** + * Returns <code>true</code> if the series contains no data items, and + * <code>false</code> otherwise. + * + * @return A boolean. + * + * @since 1.0.7 + */ + public boolean isEmpty() { + return (getItemCount() == 0); + } + + /** + * Returns the number of data items in the series. + * + * @return The number of data items in the series. + */ + public abstract int getItemCount(); + + /** * Returns a clone of the series. * <P> * Notes: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-26 14:01:07
|
Revision: 190 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=190&view=rev Author: mungady Date: 2007-09-26 07:00:52 -0700 (Wed, 26 Sep 2007) Log Message: ----------- 2007-09-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/GrayPaintScale.java (getPaint): Use constrained value to calculate gray scale value, * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java (testConstructor): New test method, (testGetPaint): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/renderer/GrayPaintScale.java trunk/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-26 13:55:12 UTC (rev 189) +++ trunk/ChangeLog 2007-09-26 14:00:52 UTC (rev 190) @@ -1,5 +1,13 @@ 2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/GrayPaintScale.java + (getPaint): Use constrained value to calculate gray scale value, + * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java + (testConstructor): New test method, + (testGetPaint): Likewise. + +2007-09-26 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/XYBarRenderer.java (drawItem): Apply margin in a way that works for inverted axes. Modified: trunk/source/org/jfree/chart/renderer/GrayPaintScale.java =================================================================== --- trunk/source/org/jfree/chart/renderer/GrayPaintScale.java 2007-09-26 13:55:12 UTC (rev 189) +++ trunk/source/org/jfree/chart/renderer/GrayPaintScale.java 2007-09-26 14:00:52 UTC (rev 190) @@ -39,6 +39,7 @@ * 05-Jul-2006 : Version 1 (DG); * 31-Jan-2007 : Renamed min and max to lowerBound and upperBound (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 26-Sep-2007 : Fixed bug 1767315, problem in getPaint() method (DG); * */ @@ -76,6 +77,9 @@ * * @param lowerBound the lower bound. * @param upperBound the upper bound. + * + * @throws IllegalArgumentException if <code>lowerBound</code> is not + * less than <code>upperBound</code>. */ public GrayPaintScale(double lowerBound, double upperBound) { if (lowerBound >= upperBound) { @@ -90,6 +94,8 @@ * Returns the lower bound. * * @return The lower bound. + * + * @see #getUpperBound() */ public double getLowerBound() { return this.lowerBound; @@ -99,6 +105,8 @@ * Returns the upper bound. * * @return The upper bound. + * + * @see #getLowerBound() */ public double getUpperBound() { return this.upperBound; @@ -107,14 +115,15 @@ /** * Returns a paint for the specified value. * - * @param value the value. + * @param value the value (must be within the range specified by the + * lower and upper bounds for the scale). * * @return A paint for the specified value. */ public Paint getPaint(double value) { double v = Math.max(value, this.lowerBound); v = Math.min(v, this.upperBound); - int g = (int) ((value - this.lowerBound) / (this.upperBound + int g = (int) ((v - this.lowerBound) / (this.upperBound - this.lowerBound) * 255.0); return new Color(g, g, g); } Modified: trunk/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java 2007-09-26 13:55:12 UTC (rev 189) +++ trunk/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java 2007-09-26 14:00:52 UTC (rev 190) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------ * GrayPaintScaleTests.java * ------------------------ - * (C) Copyright 2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,11 +37,13 @@ * Changes * ------- * 05-Jul-2006 : Version 1 (DG); + * 26-Sep-2007 : Added testConstructor() and testGetPaint() (DG); * */ package org.jfree.chart.renderer.junit; +import java.awt.Color; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; @@ -49,13 +51,13 @@ import java.io.ObjectOutput; import java.io.ObjectOutputStream; -import org.jfree.chart.renderer.GrayPaintScale; - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jfree.chart.renderer.GrayPaintScale; + /** * Tests for the {@link GrayPaintScale} class. */ @@ -79,7 +81,36 @@ super(name); } + private static final double EPSILON = 0.000000001; + + /** + * Simple check for the default constructor. + */ + public void testConstructor() { + GrayPaintScale gps = new GrayPaintScale(); + assertEquals(0.0, gps.getLowerBound(), EPSILON); + assertEquals(1.0, gps.getUpperBound(), EPSILON); + } + /** + * Some checks for the getPaint() method. + */ + public void testGetPaint() { + GrayPaintScale gps = new GrayPaintScale(); + Color c = (Color) gps.getPaint(0.0); + assertTrue(c.equals(Color.black)); + c = (Color) gps.getPaint(1.0); + assertTrue(c.equals(Color.white)); + + // check lookup values that are outside the bounds - see bug report + // 1767315 + c = (Color) gps.getPaint(-0.5); + assertTrue(c.equals(Color.black)); + c = (Color) gps.getPaint(1.5); + assertTrue(c.equals(Color.white)); + } + + /** * A test for the equals() method. */ public void testEquals() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-09-28 15:28:57
|
Revision: 210 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=210&view=rev Author: mungady Date: 2007-09-28 08:28:53 -0700 (Fri, 28 Sep 2007) Log Message: ----------- 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java (drawItem): Simplified entity generation code. 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java (setGroupStroke): Check for null argument, add event notification, (equals): New method override, * tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java (testEquals): Extended to cover additional fields. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java trunk/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-28 15:11:58 UTC (rev 209) +++ trunk/ChangeLog 2007-09-28 15:28:53 UTC (rev 210) @@ -21,6 +21,19 @@ * tests/org/jfree/data/statistics/junit/DefaultStatisticalCategoryDatasetTests.java (testCloning): Check independence. +2007-09-28 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java + (drawItem): Simplified entity generation code. + +2007-09-28 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java + (setGroupStroke): Check for null argument, add event notification, + (equals): New method override, + * tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java + (testEquals): Extended to cover additional fields. + 2007-09-27 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java Modified: trunk/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java 2007-09-28 15:11:58 UTC (rev 209) +++ trunk/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java 2007-09-28 15:28:53 UTC (rev 210) @@ -56,6 +56,7 @@ * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 09-Mar-2007 : Fixed problem with horizontal rendering (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 28-Sep-2007 : Added equals() method override (DG); * */ @@ -82,12 +83,11 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.entity.CategoryItemEntity; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.event.RendererChangeEvent; -import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.category.CategoryDataset; @@ -216,12 +216,17 @@ /** * Sets the stroke of the line between the minimum value and the maximum - * value. + * value and sends a {@link RendererChangeEvent} to all registered + * listeners. * - * @param groupStroke The new stroke + * @param stroke the new stroke (<code>null</code> not permitted). */ - public void setGroupStroke(Stroke groupStroke) { - this.groupStroke = groupStroke; + public void setGroupStroke(Stroke stroke) { + if (stroke == null) { + throw new IllegalArgumentException("Null 'stroke' argument."); + } + this.groupStroke = stroke; + notifyListeners(new RendererChangeEvent(this)); } /** @@ -409,24 +414,43 @@ } } - // collect entity and tool tip information... - if (state.getInfo() != null) { - EntityCollection entities = state.getEntityCollection(); - if (entities != null && shape != null) { - String tip = null; - CategoryToolTipGenerator tipster = getToolTipGenerator(row, - column); - if (tipster != null) { - tip = tipster.generateToolTip(dataset, row, column); - } - CategoryItemEntity entity = new CategoryItemEntity( - shape, tip, null, dataset, dataset.getRowKey(row), - dataset.getColumnKey(column)); - entities.add(entity); - } + // add an item entity, if this information is being collected + EntityCollection entities = state.getEntityCollection(); + if (entities != null && shape != null) { + addItemEntity(entities, dataset, row, column, shape); } } } + + /** + * Tests this instance for equality with an arbitrary object. The icon fields + * are NOT included in the test, so this implementation is a little weak. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + * + * @since 1.0.7 + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof MinMaxCategoryRenderer)) { + return false; + } + MinMaxCategoryRenderer that = (MinMaxCategoryRenderer) obj; + if (this.plotLines != that.plotLines) { + return false; + } + if (!PaintUtilities.equal(this.groupPaint, that.groupPaint)) { + return false; + } + if (!this.groupStroke.equals(that.groupStroke)) { + return false; + } + return super.equals(obj); + } /** * Returns an icon. @@ -470,7 +494,7 @@ } /** - * Returns an icon. + * Returns an icon from a shape. * * @param shape the shape. * @param fill the fill flag. @@ -479,7 +503,7 @@ * @return The icon. */ private Icon getIcon(Shape shape, final boolean fill, - final boolean outline) { + final boolean outline) { final int width = shape.getBounds().width; final int height = shape.getBounds().height; final GeneralPath path = new GeneralPath(shape); Modified: trunk/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java 2007-09-28 15:11:58 UTC (rev 209) +++ trunk/tests/org/jfree/chart/renderer/category/junit/MinMaxCategoryRendererTests.java 2007-09-28 15:28:53 UTC (rev 210) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------------------- * MinMaxCategoryRendererTests.java * -------------------------------- - * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,11 +37,15 @@ * Changes * ------- * 22-Oct-2003 : Version 1 (DG); + * 28-Sep-2007 : Added testEquals() method (DG); * */ package org.jfree.chart.renderer.category.junit; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInput; @@ -90,6 +94,23 @@ MinMaxCategoryRenderer r1 = new MinMaxCategoryRenderer(); MinMaxCategoryRenderer r2 = new MinMaxCategoryRenderer(); assertEquals(r1, r2); + + r1.setDrawLines(true); + assertFalse(r1.equals(r2)); + r2.setDrawLines(true); + assertTrue(r1.equals(r2)); + + r1.setGroupPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, + Color.yellow)); + assertFalse(r1.equals(r2)); + r2.setGroupPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, + Color.yellow)); + assertTrue(r1.equals(r2)); + + r1.setGroupStroke(new BasicStroke(1.2f)); + assertFalse(r1.equals(r2)); + r2.setGroupStroke(new BasicStroke(1.2f)); + assertTrue(r1.equals(r2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-02 10:02:54
|
Revision: 217 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=217&view=rev Author: mungady Date: 2007-10-02 03:02:52 -0700 (Tue, 02 Oct 2007) Log Message: ----------- 2007-10-02 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/BoxAndWhiskerItem.java (BoxAndWhiskerItem(double, double, double, double, double, double, double, double, List)): New constructor, * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java (minimumRangeValue): Changed from Number to double, (minimumRangeValueRow): New field, (minimumRangeValueColumn): Likewise, (maximumRangeValue): Changed from Number to double, (maximumRangeValueRow): New field, (maximumRangeValueColumn): Likewise, (DefaultBoxAndWhiskerCategoryDataset): Updated for changed field types, (add): Fix updating of cached range values, (getRangeLowerBound): Update for changed field type, (getRangeUpperBound): Likewise, * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDataset.java (testAdd): New test method, (testAddUpdatesCachedRange): Likewise, (testConstructor): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/data/statistics/BoxAndWhiskerItem.java trunk/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-02 09:52:32 UTC (rev 216) +++ trunk/ChangeLog 2007-10-02 10:02:52 UTC (rev 217) @@ -1,3 +1,24 @@ +2007-10-02 David Gilbert <dav...@ob...> + + * source/org/jfree/data/statistics/BoxAndWhiskerItem.java + (BoxAndWhiskerItem(double, double, double, double, double, double, + double, double, List)): New constructor, + * source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java + (minimumRangeValue): Changed from Number to double, + (minimumRangeValueRow): New field, + (minimumRangeValueColumn): Likewise, + (maximumRangeValue): Changed from Number to double, + (maximumRangeValueRow): New field, + (maximumRangeValueColumn): Likewise, + (DefaultBoxAndWhiskerCategoryDataset): Updated for changed field types, + (add): Fix updating of cached range values, + (getRangeLowerBound): Update for changed field type, + (getRangeUpperBound): Likewise, + * tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDataset.java + (testAdd): New test method, + (testAddUpdatesCachedRange): Likewise, + (testConstructor): Likewise. + 2007-09-28 David Gilbert <dav...@ob...> * source/org/jfree/data/KeyedObjects.java Modified: trunk/source/org/jfree/data/statistics/BoxAndWhiskerItem.java =================================================================== --- trunk/source/org/jfree/data/statistics/BoxAndWhiskerItem.java 2007-10-02 09:52:32 UTC (rev 216) +++ trunk/source/org/jfree/data/statistics/BoxAndWhiskerItem.java 2007-10-02 10:02:52 UTC (rev 217) @@ -32,8 +32,6 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: BoxAndWhiskerItem.java,v 1.5.2.4 2007/01/17 15:35:00 mungady Exp $ - * * Changes * ------- * 27-Aug-2003 : Version 1 (DG); @@ -41,6 +39,7 @@ * ------------- JFREECHART 1.0.x --------------------------------------------- * 15-Nov-2006 : Added toString() method override (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 02-Oct-2007 : Added new constructor (for convenience) (DG); * */ @@ -126,6 +125,33 @@ } /** + * Creates a new box-and-whisker item. + * + * @param mean the mean. + * @param median the median + * @param q1 the first quartile. + * @param q3 the third quartile. + * @param minRegularValue the minimum regular value. + * @param maxRegularValue the maximum regular value. + * @param minOutlier the minimum outlier value. + * @param maxOutlier the maximum outlier value. + * @param outliers a list of the outliers. + * + * @since 1.0.7 + */ + public BoxAndWhiskerItem(double mean, double median, double q1, double q3, + double minRegularValue, double maxRegularValue, double minOutlier, + double maxOutlier, List outliers) { + + // pass values to other constructor + this(new Double(mean), new Double(median), new Double(q1), + new Double(q3), new Double(minRegularValue), + new Double(maxRegularValue), new Double(minOutlier), + new Double(maxOutlier), outliers); + + } + + /** * Returns the mean. * * @return The mean (possibly <code>null</code>). Modified: trunk/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java =================================================================== --- trunk/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-02 09:52:32 UTC (rev 216) +++ trunk/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java 2007-10-02 10:02:52 UTC (rev 217) @@ -49,6 +49,7 @@ * 13-Jun-2007 : Fixed error in previous patch (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); * 28-Sep-2007 : Fixed cloning bug (DG); + * 02-Oct-2007 : Fixed bug in updating cached bounds (DG); * */ @@ -74,11 +75,27 @@ protected KeyedObjects2D data; /** The minimum range value. */ - private Number minimumRangeValue; + private double minimumRangeValue; + + /** The row index for the cell that the minimum range value comes from. */ + private int minimumRangeValueRow; + + /** + * The column index for the cell that the minimum range value comes from. + */ + private int minimumRangeValueColumn; /** The maximum range value. */ - private Number maximumRangeValue; + private double maximumRangeValue; + /** The row index for the cell that the maximum range value comes from. */ + private int maximumRangeValueRow; + + /** + * The column index for the cell that the maximum range value comes from. + */ + private int maximumRangeValueColumn; + /** The range of values. */ private Range rangeBounds; @@ -87,8 +104,12 @@ */ public DefaultBoxAndWhiskerCategoryDataset() { this.data = new KeyedObjects2D(); - this.minimumRangeValue = null; - this.maximumRangeValue = null; + this.minimumRangeValue = Double.NaN; + this.minimumRangeValueRow = -1; + this.minimumRangeValueColumn = -1; + this.maximumRangeValue = Double.NaN; + this.maximumRangeValueRow = -1; + this.maximumRangeValueColumn = -1; this.rangeBounds = new Range(0.0, 0.0); } @@ -120,6 +141,20 @@ Comparable columnKey) { this.data.addObject(item, rowKey, columnKey); + + // update cached min and max values + int r = this.data.getRowIndex(rowKey); + int c = this.data.getColumnIndex(columnKey); + if (this.maximumRangeValueRow == r + && this.maximumRangeValueColumn == c) { + this.maximumRangeValue = Double.NaN; + } + if (this.minimumRangeValueRow == r + && this.minimumRangeValueColumn == c) { + this.minimumRangeValue = Double.NaN; + } + + double minval = Double.NaN; if (item.getMinOutlier() != null) { minval = item.getMinOutlier().doubleValue(); @@ -129,22 +164,30 @@ maxval = item.getMaxOutlier().doubleValue(); } - if (this.maximumRangeValue == null) { - this.maximumRangeValue = new Double(maxval); + if (Double.isNaN(this.maximumRangeValue)) { + this.maximumRangeValue = maxval; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; } - else if (maxval > this.maximumRangeValue.doubleValue()) { - this.maximumRangeValue = new Double(maxval); + else if (maxval > this.maximumRangeValue) { + this.maximumRangeValue = maxval; + this.maximumRangeValueRow = r; + this.maximumRangeValueColumn = c; } - if (this.minimumRangeValue == null) { - this.minimumRangeValue = new Double(minval); + if (Double.isNaN(this.minimumRangeValue)) { + this.minimumRangeValue = minval; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; } - else if (minval < this.minimumRangeValue.doubleValue()) { - this.minimumRangeValue = new Double(minval); + else if (minval < this.minimumRangeValue) { + this.minimumRangeValue = minval; + this.minimumRangeValueRow = r; + this.minimumRangeValueColumn = c; } - this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(), - this.maximumRangeValue.doubleValue()); + this.rangeBounds = new Range(this.minimumRangeValue, + this.maximumRangeValue); fireDatasetChanged(); @@ -169,6 +212,9 @@ * @param column the column index. * * @return The value. + * + * @see #getMedianValue(int, int) + * @see #getValue(Comparable, Comparable) */ public Number getValue(int row, int column) { return getMedianValue(row, column); @@ -181,6 +227,9 @@ * @param columnKey the columnKey. * * @return The value. + * + * @see #getMedianValue(Comparable, Comparable) + * @see #getValue(int, int) */ public Number getValue(Comparable rowKey, Comparable columnKey) { return getMedianValue(rowKey, columnKey); @@ -421,11 +470,7 @@ * @return The minimum value. */ public double getRangeLowerBound(boolean includeInterval) { - double result = Double.NaN; - if (this.minimumRangeValue != null) { - result = this.minimumRangeValue.doubleValue(); - } - return result; + return this.minimumRangeValue; } /** @@ -437,11 +482,7 @@ * @return The maximum value. */ public double getRangeUpperBound(boolean includeInterval) { - double result = Double.NaN; - if (this.maximumRangeValue != null) { - result = this.maximumRangeValue.doubleValue(); - } - return result; + return this.maximumRangeValue; } /** Modified: trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java =================================================================== --- trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-02 09:52:32 UTC (rev 216) +++ trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerCategoryDatasetTests.java 2007-10-02 10:02:52 UTC (rev 217) @@ -37,6 +37,7 @@ * 01-Mar-2004 : Version 1 (DG); * 17-Apr-2007 : Added a test for bug 1701822 (DG); * 28-Sep-2007 : Enhanced testClone() (DG); + * 02-Oct-2007 : Added new tests (DG); * */ @@ -54,6 +55,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jfree.data.Range; import org.jfree.data.statistics.BoxAndWhiskerItem; import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset; @@ -181,4 +183,84 @@ } } + + private static final double EPSILON = 0.0000000001; + + /** + * Some checks for the add() method. + */ + public void testAdd() { + DefaultBoxAndWhiskerCategoryDataset dataset + = new DefaultBoxAndWhiskerCategoryDataset(); + BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, new ArrayList()); + dataset.add(item1, "R1", "C1"); + + assertEquals(2.0, dataset.getValue("R1", "C1").doubleValue(), EPSILON); + assertEquals(1.0, dataset.getMeanValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(2.0, dataset.getMedianValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(3.0, dataset.getQ1Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(4.0, dataset.getQ3Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(5.0, dataset.getMinRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(6.0, dataset.getMaxRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(7.0, dataset.getMinOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(8.0, dataset.getMaxOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(new Range(7.0, 8.0), dataset.getRangeBounds(false)); + } + + /** + * Some checks for the add() method. + */ + public void testAddUpdatesCachedRange() { + DefaultBoxAndWhiskerCategoryDataset dataset + = new DefaultBoxAndWhiskerCategoryDataset(); + BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, new ArrayList()); + dataset.add(item1, "R1", "C1"); + + // now overwrite this item with another + BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, + 5.5, 6.5, 7.5, 8.5, new ArrayList()); + dataset.add(item2, "R1", "C1"); + + assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON); + assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(), + EPSILON); + assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(), + EPSILON); + assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(), + EPSILON); + assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false)); + } + + /** + * Some basic checks for the constructor. + */ + public void testConstructor() { + DefaultBoxAndWhiskerCategoryDataset dataset + = new DefaultBoxAndWhiskerCategoryDataset(); + assertEquals(0, dataset.getColumnCount()); + assertEquals(0, dataset.getRowCount()); + assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); + assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-03 11:36:46
|
Revision: 225 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=225&view=rev Author: mungady Date: 2007-10-03 02:24:09 -0700 (Wed, 03 Oct 2007) Log Message: ----------- 2007-10-03 David Gilbert <dav...@ob...> * source/org/jfree/data/DefaultKeyedValues.java (removeValue(Comparable)): Throw UnknownKeyException for unrecognised key, * source/org/jfree/data/KeyedObjects.java (getObject(int)): Allow IndexOutOfBoundsException to be thrown, (getKey(int)): Likewise, (getIndex): Check for null argument, (getObject): Throw UnknownKeyException for unrecognised key, (insertValue): New method, (removeValue): Throw UnknownKeyException for unrecognised key, (clear): New method, (hashCode): Likewise, * source/org/jfree/data/KeyedObjects2D.java (getObject): Check for missing key in underlying data structure, * tests/org/jfree/data/junit/DefaultKeyedValuesTests.java (testRemoveValue): Updated checks for consistency with KeyedObjects, * tests/org/jfree/data/junit/KeyedObjectsTests.java (testInsertAndRetrieve): Updated checks, (testGetObject): New test method, (testGetKey): Likewise, (testGetIndex): Likewise, (testSetObject): Likewise, (testRemoveValue): Likewise, (testRemoveValueInt): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/data/DefaultKeyedValues.java trunk/source/org/jfree/data/KeyedObjects.java trunk/source/org/jfree/data/KeyedObjects2D.java trunk/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java trunk/tests/org/jfree/data/junit/KeyedObjectsTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-03 09:13:34 UTC (rev 224) +++ trunk/ChangeLog 2007-10-03 09:24:09 UTC (rev 225) @@ -1,3 +1,29 @@ +2007-10-03 David Gilbert <dav...@ob...> + + * source/org/jfree/data/DefaultKeyedValues.java + (removeValue(Comparable)): Throw UnknownKeyException for unrecognised key, + * source/org/jfree/data/KeyedObjects.java + (getObject(int)): Allow IndexOutOfBoundsException to be thrown, + (getKey(int)): Likewise, + (getIndex): Check for null argument, + (getObject): Throw UnknownKeyException for unrecognised key, + (insertValue): New method, + (removeValue): Throw UnknownKeyException for unrecognised key, + (clear): New method, + (hashCode): Likewise, + * source/org/jfree/data/KeyedObjects2D.java + (getObject): Check for missing key in underlying data structure, + * tests/org/jfree/data/junit/DefaultKeyedValuesTests.java + (testRemoveValue): Updated checks for consistency with KeyedObjects, + * tests/org/jfree/data/junit/KeyedObjectsTests.java + (testInsertAndRetrieve): Updated checks, + (testGetObject): New test method, + (testGetKey): Likewise, + (testGetIndex): Likewise, + (testSetObject): Likewise, + (testRemoveValue): Likewise, + (testRemoveValueInt): Likewise. + 2007-10-02 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java Modified: trunk/source/org/jfree/data/DefaultKeyedValues.java =================================================================== --- trunk/source/org/jfree/data/DefaultKeyedValues.java 2007-10-03 09:13:34 UTC (rev 224) +++ trunk/source/org/jfree/data/DefaultKeyedValues.java 2007-10-03 09:24:09 UTC (rev 225) @@ -32,8 +32,6 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DefaultKeyedValues.java,v 1.8.2.6 2007/04/30 15:28:04 mungady Exp $ - * * Changes: * -------- * 31-Oct-2002 : Version 1 (DG); @@ -54,6 +52,7 @@ * 01-Aug-2006 : Added argument check to getIndex() method (DG); * 30-Apr-2007 : Added insertValue() methods (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); + * 03-Oct-2007 : Make removeValue() throw UnknownKeyException (DG); * */ @@ -104,7 +103,7 @@ * * @param item the item of interest (zero-based index). * - * @return The value. + * @return The value (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ @@ -283,7 +282,7 @@ if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } - int pos = this.getIndex(key); + int pos = getIndex(key); if (pos >= 0) { this.data.remove(pos); } @@ -317,12 +316,15 @@ * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. + * @throws UnknownKeyException if <code>key</code> is not recognised. */ public void removeValue(Comparable key) { int index = getIndex(key); - if (index >= 0) { - removeValue(index); + if (index < 0) { + throw new UnknownKeyException("The key (" + key + + ") is not recognised."); } + removeValue(index); } /** Modified: trunk/source/org/jfree/data/KeyedObjects.java =================================================================== --- trunk/source/org/jfree/data/KeyedObjects.java 2007-10-03 09:13:34 UTC (rev 224) +++ trunk/source/org/jfree/data/KeyedObjects.java 2007-10-03 09:24:09 UTC (rev 225) @@ -38,8 +38,8 @@ * 11-Jan-2005 : Minor tidy up (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); * 28-Sep-2007 : Clean up equals() method (DG); + * 03-Oct-2007 : Make method behaviour consistent with DefaultKeyedValues (DG); * - * */ package org.jfree.data; @@ -78,19 +78,19 @@ } /** - * Returns an object. + * Returns an object from the list. * * @param item the item index (zero-based). * - * @return The object (<code>null</code> if the index is out of range). + * @return The object (possibly <code>null</code>). + * + * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ public Object getObject(int item) { Object result = null; - if (item >= 0 && item < this.data.size()) { - KeyedObject kobj = (KeyedObject) this.data.get(item); - if (kobj != null) { - result = kobj.getObject(); - } + KeyedObject kobj = (KeyedObject) this.data.get(item); + if (kobj != null) { + result = kobj.getObject(); } return result; } @@ -100,42 +100,44 @@ * * @param index the item index (zero-based). * - * @return The row key (or <code>null</code>). + * @return The row key. + * + * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. * * @see #getIndex(Comparable) */ public Comparable getKey(int index) { Comparable result = null; - if (index >= 0 && index < this.data.size()) { - KeyedObject item = (KeyedObject) this.data.get(index); - if (item != null) { - result = item.getKey(); - } + KeyedObject item = (KeyedObject) this.data.get(index); + if (item != null) { + result = item.getKey(); } return result; } /** - * Returns the index for a given key. + * Returns the index for a given key, or <code>-1</code>. * - * @param key the key. + * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @see #getKey(int) */ public int getIndex(Comparable key) { - int result = -1; + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } int i = 0; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { KeyedObject ko = (KeyedObject) iterator.next(); if (ko.getKey().equals(key)) { - result = i; + return i; } i++; } - return result; + return -1; } /** @@ -164,7 +166,12 @@ * @see #addObject(Comparable, Object) */ public Object getObject(Comparable key) { - return getObject(getIndex(key)); + int index = getIndex(key); + if (index < 0) { + throw new UnknownKeyException("The key (" + key + + ") is not recognised."); + } + return getObject(index); } /** @@ -185,7 +192,7 @@ * This is the same as the {@link #addObject(Comparable, Object)} * method. * - * @param key the key. + * @param key the key (<code>null</code> not permitted). * @param object the object. * * @see #getObject(Comparable) @@ -203,9 +210,43 @@ } /** + * Inserts a new value at the specified position in the dataset or, if + * there is an existing item with the specified key, updates the value + * for that item and moves it to the specified position. + * + * @param position the position (in the range <code>0</code> to + * <code>getItemCount()</code>). + * @param key the key (<code>null</code> not permitted). + * @param value the value (<code>null</code> permitted). + * + * @since 1.0.7 + */ + public void insertValue(int position, Comparable key, Object value) { + if (position < 0 || position > this.data.size()) { + throw new IllegalArgumentException("'position' out of bounds."); + } + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } + int pos = getIndex(key); + if (pos >= 0) { + this.data.remove(pos); + } + KeyedObject item = new KeyedObject(key, value); + if (position <= this.data.size()) { + this.data.add(position, item); + } + else { + this.data.add(item); + } + } + + /** * Removes a value from the collection. * * @param index the index of the item to remove. + * + * @see #removeValue(Comparable) */ public void removeValue(int index) { this.data.remove(index); @@ -214,13 +255,32 @@ /** * Removes a value from the collection. * - * @param key the key of the item to remove. + * @param key the key (<code>null</code> not permitted). + * + * @see #removeValue(int) + * + * @throws UnknownKeyException if the key is not recognised. */ public void removeValue(Comparable key) { - removeValue(getIndex(key)); + // defer argument checking + int index = getIndex(key); + if (index < 0) { + throw new UnknownKeyException("The key (" + key.toString() + + ") is not recognised."); + } + removeValue(index); } /** + * Clears all values from the collection. + * + * @since 1.0.7 + */ + public void clear() { + this.data.clear(); + } + + /** * Returns a clone of this object. Keys in the list should be immutable * and are not cloned. Objects in the list are cloned only if they * implement {@link PublicCloneable}. @@ -284,4 +344,13 @@ } + /** + * Returns a hash code. + * + * @return A hash code. + */ + public int hashCode() { + return (this.data != null ? this.data.hashCode() : 0); + } + } Modified: trunk/source/org/jfree/data/KeyedObjects2D.java =================================================================== --- trunk/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 09:13:34 UTC (rev 224) +++ trunk/source/org/jfree/data/KeyedObjects2D.java 2007-10-03 09:24:09 UTC (rev 225) @@ -37,6 +37,8 @@ * 05-Feb-2003 : Version 1 (DG); * 01-Mar-2004 : Added equals() and clone() methods and implemented * Serializable (DG); + * 03-Oct-2007 : Updated getObject() to handle modified behaviour in + * KeyedObjects class (DG); * */ @@ -106,17 +108,18 @@ * @return The object. */ public Object getObject(int row, int column) { - Object result = null; KeyedObjects rowData = (KeyedObjects) this.rows.get(row); if (rowData != null) { Comparable columnKey = (Comparable) this.columnKeys.get(column); if (columnKey != null) { - result = rowData.getObject(columnKey); + int index = rowData.getIndex(columnKey); + if (index >= 0) { + result = rowData.getObject(columnKey); + } } } return result; - } /** Modified: trunk/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java =================================================================== --- trunk/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java 2007-10-03 09:13:34 UTC (rev 224) +++ trunk/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java 2007-10-03 09:24:09 UTC (rev 225) @@ -32,8 +32,6 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DefaultKeyedValuesTests.java,v 1.1.2.2 2007/04/30 15:28:04 mungady Exp $ - * * Changes * ------- * 05-Mar-2003 : Version 1 (DG); @@ -41,6 +39,7 @@ * 31-Jul-2006 : Added test for new clear() method (DG); * 01-Aug-2006 : Extended testGetIndex() method (DG); * 30-Apr-2007 : Added some new tests (DG); + * 03-Oct-2007 : Updated testRemoveValue() (DG); * */ @@ -350,12 +349,12 @@ data.removeValue("B"); assertEquals(-1, data.getIndex("B")); - boolean pass = true; + boolean pass = false; try { data.removeValue("XXX"); } - catch (Exception e) { - pass = false; + catch (UnknownKeyException e) { + pass = true; } assertTrue(pass); } Modified: trunk/tests/org/jfree/data/junit/KeyedObjectsTests.java =================================================================== --- trunk/tests/org/jfree/data/junit/KeyedObjectsTests.java 2007-10-03 09:13:34 UTC (rev 224) +++ trunk/tests/org/jfree/data/junit/KeyedObjectsTests.java 2007-10-03 09:24:09 UTC (rev 225) @@ -36,6 +36,7 @@ * ------- * 27-Jan-2004 : Version 1 (DG); * 28-Sep-2007 : Added testCloning2() (DG); + * 03-Oct-2007 : New tests (DG); * */ @@ -54,6 +55,7 @@ import junit.framework.TestSuite; import org.jfree.data.KeyedObjects; +import org.jfree.data.UnknownKeyException; import org.jfree.data.general.DefaultPieDataset; /** @@ -169,8 +171,16 @@ assertEquals(data.getObject("B"), new Double(2.0)); assertEquals(data.getObject("C"), new Double(3.0)); assertEquals(data.getObject("D"), null); - assertEquals(data.getObject("Not a key"), null); - + + boolean pass = false; + try { + data.getObject("Not a key"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + // check retrieve value by index assertEquals(data.getObject(0), new Double(1.0)); assertEquals(data.getObject(1), new Double(2.0)); @@ -208,5 +218,199 @@ assertEquals(ko1, ko2); } + + /** + * Simple checks for the getObject(int) method. + */ + public void testGetObject() { + // retrieve an item + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("Key 1", "Object 1"); + ko1.addObject("Key 2", null); + ko1.addObject("Key 3", "Object 2"); + assertEquals("Object 1", ko1.getObject(0)); + assertNull(ko1.getObject(1)); + assertEquals("Object 2", ko1.getObject(2)); + + // request with a negative index + boolean pass = false; + try { + ko1.getObject(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // request width index == itemCount + pass = false; + try { + ko1.getObject(3); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Simple checks for the getKey(int) method. + */ + public void testGetKey() { + // retrieve an item + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("Key 1", "Object 1"); + ko1.addObject("Key 2", null); + ko1.addObject("Key 3", "Object 2"); + assertEquals("Key 1", ko1.getKey(0)); + assertEquals("Key 2", ko1.getKey(1)); + assertEquals("Key 3", ko1.getKey(2)); + + // request with a negative index + boolean pass = false; + try { + ko1.getKey(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // request width index == itemCount + pass = false; + try { + ko1.getKey(3); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Simple checks for the getIndex(Comparable) method. + */ + public void testGetIndex() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.addObject("Key 1", "Object 1"); + ko1.addObject("Key 2", null); + ko1.addObject("Key 3", "Object 2"); + assertEquals(0, ko1.getIndex("Key 1")); + assertEquals(1, ko1.getIndex("Key 2")); + assertEquals(2, ko1.getIndex("Key 3")); + + // check null argument + boolean pass = false; + try { + ko1.getIndex(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the setObject(Comparable, Object) method. + */ + public void testSetObject() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.setObject("Key 1", "Object 1"); + ko1.setObject("Key 2", null); + ko1.setObject("Key 3", "Object 2"); + + assertEquals("Object 1", ko1.getObject("Key 1")); + assertEquals(null, ko1.getObject("Key 2")); + assertEquals("Object 2", ko1.getObject("Key 3")); + + // replace an existing value + ko1.setObject("Key 2", "AAA"); + ko1.setObject("Key 3", "BBB"); + assertEquals("AAA", ko1.getObject("Key 2")); + assertEquals("BBB", ko1.getObject("Key 3")); + + // try a null key - should throw an exception + boolean pass = false; + try { + ko1.setObject(null, "XX"); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeValue() methods. + */ + public void testRemoveValue() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.setObject("Key 1", "Object 1"); + ko1.setObject("Key 2", null); + ko1.setObject("Key 3", "Object 2"); + + ko1.removeValue(1); + assertEquals(2, ko1.getItemCount()); + assertEquals(1, ko1.getIndex("Key 3")); + + ko1.removeValue("Key 1"); + assertEquals(1, ko1.getItemCount()); + assertEquals(0, ko1.getIndex("Key 3")); + + // try unknown key + boolean pass = false; + try { + ko1.removeValue("UNKNOWN"); + } + catch (UnknownKeyException e) { + pass = true; + } + assertTrue(pass); + + // try null argument + pass = false; + try { + ko1.removeValue(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the removeValue(int) method. + */ + public void testRemoveValueInt() { + KeyedObjects ko1 = new KeyedObjects(); + ko1.setObject("Key 1", "Object 1"); + ko1.setObject("Key 2", null); + ko1.setObject("Key 3", "Object 2"); + + ko1.removeValue(1); + assertEquals(2, ko1.getItemCount()); + assertEquals(1, ko1.getIndex("Key 3")); + + + // try negative key index + boolean pass = false; + try { + ko1.removeValue(-1); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + + // try key index == itemCount + pass = false; + try { + ko1.removeValue(2); + } + catch (IndexOutOfBoundsException e) { + pass = true; + } + assertTrue(pass); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-08 16:09:42
|
Revision: 295 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=295&view=rev Author: mungady Date: 2007-10-08 09:09:39 -0700 (Mon, 08 Oct 2007) Log Message: ----------- 2007-10-08 David Gilbert <dav...@ob...> Based on Patch 1769088: * source/org/jfree/chart/plot/ThermometerPlot.java (BULB_RADIUS): Deprecated, (BULB_DIAMETER): Likewise, (COLUMN_RADIUS): Likewise, (COLUMN_DIAMETER): Likewise, (GAP_RADIUS): Likewise, (GAP_DIAMETER): Likewise, (bulbRadius): New field, (columnRadius): Likewise, (gapRadius): Likewise, (getBulbRadius): New method, (setBulbRadius): Likewise, (getBulbDiameter): Likewise, (getColumnRadius): Likewise, (setColumnRadius): Likewise, (getColumnDiameter): Likewise, (getGapRadius): Likewise, (setGapRadius): Likewise, (getGapDiameter): Likewise, (draw): Use attributes rather than constants, (equals): Updated for new fields, * tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java (testEquals): Updated for new fields. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/plot/ThermometerPlot.java trunk/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-08 15:19:42 UTC (rev 294) +++ trunk/ChangeLog 2007-10-08 16:09:39 UTC (rev 295) @@ -1,5 +1,32 @@ 2007-10-08 David Gilbert <dav...@ob...> + Based on Patch 1769088: + * source/org/jfree/chart/plot/ThermometerPlot.java + (BULB_RADIUS): Deprecated, + (BULB_DIAMETER): Likewise, + (COLUMN_RADIUS): Likewise, + (COLUMN_DIAMETER): Likewise, + (GAP_RADIUS): Likewise, + (GAP_DIAMETER): Likewise, + (bulbRadius): New field, + (columnRadius): Likewise, + (gapRadius): Likewise, + (getBulbRadius): New method, + (setBulbRadius): Likewise, + (getBulbDiameter): Likewise, + (getColumnRadius): Likewise, + (setColumnRadius): Likewise, + (getColumnDiameter): Likewise, + (getGapRadius): Likewise, + (setGapRadius): Likewise, + (getGapDiameter): Likewise, + (draw): Use attributes rather than constants, + (equals): Updated for new fields, + * tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java + (testEquals): Updated for new fields. + +2007-10-08 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/MultiShapeRenderer.java: New file, * source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java: Modified: trunk/source/org/jfree/chart/plot/ThermometerPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/ThermometerPlot.java 2007-10-08 15:19:42 UTC (rev 294) +++ trunk/source/org/jfree/chart/plot/ThermometerPlot.java 2007-10-08 16:09:39 UTC (rev 295) @@ -33,6 +33,7 @@ * Original Author: Bryan Scott (based on MeterPlot by Hari). * Contributor(s): David Gilbert (for Object Refinery Limited). * Arnaud Lelievre; + * Julien Henry (see patch 1769088) (DG); * * Changes * ------- @@ -84,6 +85,8 @@ * 19-Jun-2007 : Removed deprecated code (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); * 24-Sep-2007 : Implemented new methods in Zoomable interface (DG); + * 08-Oct-2007 : Added attributes for thermometer dimensions - see patch 1769088 + * by Julien Henry (DG); * */ @@ -183,22 +186,46 @@ /** A constant for the 'critical' range. */ public static final int CRITICAL = 2; - /** The bulb radius. */ + /** + * The bulb radius. + * + * @deprecated As of 1.0.7, use {@link #getBulbRadius()}. + */ protected static final int BULB_RADIUS = 40; - /** The bulb diameter. */ + /** + * The bulb diameter. + * + * @deprecated As of 1.0.7, use {@link #getBulbDiameter()}. + */ protected static final int BULB_DIAMETER = BULB_RADIUS * 2; - /** The column radius. */ + /** + * The column radius. + * + * @deprecated As of 1.0.7, use {@link #getColumnRadius()}. + */ protected static final int COLUMN_RADIUS = 20; - /** The column diameter.*/ + /** + * The column diameter. + * + * @deprecated As of 1.0.7, use {@link #getColumnDiameter()}. + */ protected static final int COLUMN_DIAMETER = COLUMN_RADIUS * 2; - /** The gap radius. */ + /** + * The gap radius. + * + * @deprecated As of 1.0.7, use {@link #getGapRadius()}. + */ protected static final int GAP_RADIUS = 5; - /** The gap diameter. */ + /** + * The gap diameter. + * + * @deprecated As of 1.0.7, use {@link #getGapDiameter()}. + */ protected static final int GAP_DIAMETER = GAP_RADIUS * 2; /** The axis gap. */ @@ -226,6 +253,27 @@ /** The default upper bound. */ protected static final double DEFAULT_UPPER_BOUND = 100.0; + /** + * The default bulb radius. + * + * @since 1.0.7 + */ + protected static final int DEFAULT_BULB_RADIUS = 40; + + /** + * The default column radius. + * + * @since 1.0.7 + */ + protected static final int DEFAULT_COLUMN_RADIUS = 20; + + /** + * The default gap radius. + * + * @since 1.0.7 + */ + protected static final int DEFAULT_GAP_RADIUS = 5; + /** The dataset for the plot. */ private ValueDataset dataset; @@ -239,6 +287,27 @@ private double upperBound = DEFAULT_UPPER_BOUND; /** + * The value label position. + * + * @since 1.0.7 + */ + private int bulbRadius = DEFAULT_BULB_RADIUS; + + /** + * The column radius. + * + * @since 1.0.7 + */ + private int columnRadius = DEFAULT_COLUMN_RADIUS; + + /** + * The gap radius. + * + * @since 1.0.7 + */ + private int gapRadius = DEFAULT_GAP_RADIUS; + + /** * Blank space inside the plot area around the outside of the thermometer. */ private RectangleInsets padding; @@ -911,6 +980,124 @@ } /** + * Returns the bulb radius, in Java2D units. + + * @return The bulb radius. + * + * @since 1.0.7 + */ + public int getBulbRadius() { + return this.bulbRadius; + } + + /** + * Sets the bulb radius (in Java2D units) and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param r the new radius (in Java2D units). + * + * @see #getBulbRadius() + * + * @since 1.0.7 + */ + public void setBulbRadius(int r) { + this.bulbRadius = r; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the bulb diameter, which is always twice the value returned + * by {@link #getBulbRadius()}. + * + * @return The bulb diameter. + * + * @since 1.0.7 + */ + public int getBulbDiameter() { + return getBulbRadius() * 2; + } + + /** + * Returns the column radius, in Java2D units. + * + * @return The column radius. + * + * @see #setColumnRadius(int) + * + * @since 1.0.7 + */ + public int getColumnRadius() { + return this.columnRadius; + } + + /** + * Sets the column radius (in Java2D units) and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param r the new radius. + * + * @see #getColumnRadius() + * + * @since 1.0.7 + */ + public void setColumnRadius(int r) { + this.columnRadius = r; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the column diameter, which is always twice the value returned + * by {@link #getColumnRadius()}. + * + * @return The column diameter. + * + * @since 1.0.7 + */ + public int getColumnDiameter() { + return getColumnRadius() * 2; + } + + /** + * Returns the gap radius in Java2D units. + * + * @return The gap radius. + * + * @see #setGapRadius(int) + * + * @since 1.0.7 + */ + public int getGapRadius() { + return this.gapRadius; + } + + /** + * Sets the gap radius (in Java2D units) and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param r the new radius. + * + * @see #getGapRadius() + * + * @since 1.0.7 + */ + public void setGapRadius(int r) { + this.gapRadius = r; + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Returns the gap diameter, which is always twice the value returned by + * {@link #getGapRadius()}. + * + * @return The gap diameter, in Java2D units. + * + * @since 1.0.7 + */ + public int getGapDiameter() { + return getGapRadius() * 2; + } + + /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * @@ -945,30 +1132,31 @@ this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); - int stemTop = (int) (interior.getMinY() + BULB_RADIUS); - int stemBottom = (int) (interior.getMaxY() - BULB_DIAMETER); - Rectangle2D dataArea = new Rectangle2D.Double(midX - COLUMN_RADIUS, - stemTop, COLUMN_RADIUS, stemBottom - stemTop); + int stemTop = (int) (interior.getMinY() + getBulbRadius()); + int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); + Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), + stemTop, getColumnRadius(), stemBottom - stemTop); - outerBulb.setFrame(midX - BULB_RADIUS, stemBottom, BULB_DIAMETER, - BULB_DIAMETER); + outerBulb.setFrame(midX - getBulbRadius(), stemBottom, + getBulbDiameter(), getBulbDiameter()); - outerStem.setRoundRect(midX - COLUMN_RADIUS, interior.getMinY(), - COLUMN_DIAMETER, stemBottom + BULB_DIAMETER - stemTop, - COLUMN_DIAMETER, COLUMN_DIAMETER); + outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), + getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, + getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); - innerBulb.setFrame(midX - BULB_RADIUS + GAP_RADIUS, - stemBottom + GAP_RADIUS, BULB_DIAMETER - GAP_DIAMETER, - BULB_DIAMETER - GAP_DIAMETER); + innerBulb.setFrame(midX - getBulbRadius() + getGapRadius(), + stemBottom + getGapRadius(), getBulbDiameter() + - getGapDiameter(), getBulbDiameter() - getGapDiameter()); - innerStem.setRoundRect(midX - COLUMN_RADIUS + GAP_RADIUS, - interior.getMinY() + GAP_RADIUS, COLUMN_DIAMETER - GAP_DIAMETER, - stemBottom + BULB_DIAMETER - GAP_DIAMETER - stemTop, - COLUMN_DIAMETER - GAP_DIAMETER, COLUMN_DIAMETER - GAP_DIAMETER); + innerStem.setRoundRect(midX - getColumnRadius() + getGapRadius(), + interior.getMinY() + getGapRadius(), getColumnDiameter() + - getGapDiameter(), stemBottom + getBulbDiameter() + - getGapDiameter() - stemTop, getColumnDiameter() + - getGapDiameter(), getColumnDiameter() - getGapDiameter()); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); @@ -979,20 +1167,20 @@ double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); - int i = COLUMN_DIAMETER - GAP_DIAMETER; // already calculated - int j = COLUMN_RADIUS - GAP_RADIUS; // already calculated + int i = getColumnDiameter() - getGapDiameter(); // already calculated + int j = getColumnRadius() - getGapRadius(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); - if (k < (GAP_RADIUS + interior.getMinY())) { - k = (int) (GAP_RADIUS + interior.getMinY()); - l = BULB_RADIUS; + if (k < (getGapRadius() + interior.getMinY())) { + k = (int) (getGapRadius() + interior.getMinY()); + l = getBulbRadius(); } Area mercury = new Area(innerBulb); - if (k < (stemBottom + BULB_RADIUS)) { + if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, - (stemBottom + BULB_RADIUS) - k, l, l); + (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } @@ -1008,7 +1196,7 @@ // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { - double x = midX + COLUMN_RADIUS + 2; + double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); @@ -1019,7 +1207,7 @@ // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { - double x = midX + COLUMN_RADIUS + 2; + double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); @@ -1030,7 +1218,7 @@ // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { - double x = midX + COLUMN_RADIUS + 2; + double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); @@ -1047,7 +1235,7 @@ switch (this.axisLocation) { case RIGHT: - cursor = midX + COLUMN_RADIUS; + cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, @@ -1057,7 +1245,7 @@ case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; - cursor = midX - COLUMN_RADIUS; + cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, @@ -1074,19 +1262,19 @@ switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), - midX + COLUMN_RADIUS + GAP_RADIUS, midY); + midX + getColumnRadius() + getGapRadius(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); - g2.drawString(valueString, midX - COLUMN_RADIUS - - GAP_RADIUS - stringWidth, midY); + g2.drawString(valueString, midX - getColumnRadius() + - getGapRadius() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, - stemBottom + BULB_RADIUS + GAP_RADIUS); + stemBottom + getBulbRadius() + getGapRadius()); break; default: } @@ -1098,7 +1286,7 @@ // draw units indicator metrics = g2.getFontMetrics(); - int tickX1 = midX - COLUMN_RADIUS - GAP_DIAMETER + int tickX1 = midX - getColumnRadius() - getGapDiameter() - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, @@ -1325,6 +1513,15 @@ if (this.useSubrangePaint != that.useSubrangePaint) { return false; } + if (this.bulbRadius != that.bulbRadius) { + return false; + } + if (this.columnRadius != that.columnRadius) { + return false; + } + if (this.gapRadius != that.gapRadius) { + return false; + } for (int i = 0; i < this.subrangePaint.length; i++) { if (!PaintUtilities.equal(this.subrangePaint[i], that.subrangePaint[i])) { Modified: trunk/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java 2007-10-08 15:19:42 UTC (rev 294) +++ trunk/tests/org/jfree/chart/plot/junit/ThermometerPlotTests.java 2007-10-08 16:09:39 UTC (rev 295) @@ -32,8 +32,6 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: ThermometerPlotTests.java,v 1.1.2.3 2007/05/03 12:58:48 mungady Exp $ - * * Changes * ------- * 26-Mar-2003 : Version 1 (DG); @@ -41,6 +39,7 @@ * 03-May-2007 : Added cloning test (DG); * 19-Jun-2007 : Updated for removal of deprecated methods (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); + * 08-Oct-2007 : Updated testEquals() for new fields (DG); * */ @@ -176,6 +175,20 @@ 3.0f, 4.0f, Color.yellow)); assertTrue(p2.equals(p1)); + p1.setBulbRadius(9); + assertFalse(p1.equals(p2)); + p2.setBulbRadius(9); + assertTrue(p2.equals(p1)); + + p1.setColumnRadius(8); + assertFalse(p1.equals(p2)); + p2.setColumnRadius(8); + assertTrue(p2.equals(p1)); + + p1.setGapRadius(7); + assertFalse(p1.equals(p2)); + p2.setGapRadius(7); + assertTrue(p2.equals(p1)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-17 15:34:03
|
Revision: 355 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=355&view=rev Author: mungady Date: 2007-10-17 08:33:57 -0700 (Wed, 17 Oct 2007) Log Message: ----------- 2007-10-17 David Gilbert <dav...@ob...> * experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java (equals): New method override, (clone): Likewise, * experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java (equals): Added call to super.equals(); * experimental/org/jfree/experimental/chart/plot/dial/DialCap.java (equals): Added call to super.equals(); * experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java (setBackground): Fix listener registration, (setCap): Likewise, (setDialFrame): Likewise, (addLayer): Likewise, (getLayerIndex(DialLayer)): New method, (removeLayer(int)): Likewise, (removeLayer(DialLayer)): Likewise, (addScale): Fix listener registration, * experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java (equals): New method override, (Pin.equals): Likewise, (Pin.readObject): New method, (Pin.writeObject): Likewise, (Pointer.equals): New method override, * experimental/org/jfree/experimental/chart/plot/dial/DialScale.java: Now extends DialLayer, * experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java (equals): Added call to super.equals(); * experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java (equals): Added call to super.equals(); * experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java (equals): Added call to super.equals(); * experimental/org/jfree/experimental/chart/plot/dial/StandardDialFrame.java (equals): Added call to super.equals(); * experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java (increment): Removed field, (setLowerBound): Added argument check, (setUpperBound): Likewise, (setBounds): New method, (equals): Updated, (hashCode): Likewise, * experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java (setTickRadius): Added argument check, (setMajorTickIncrement): Likewise, (setTickLabelPaint): Likewise, (equals): Updated. Modified Paths: -------------- trunk/ChangeLog trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialScale.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java trunk/experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialFrame.java trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialBackgroundTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialCapTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialPackageTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialPlotTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialPointerTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialTextAnnotationTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialValueIndicatorTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/SimpleDialFrameTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/StandardDialFrameTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/StandardDialRangeTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/StandardDialScaleTests.java Added Paths: ----------- trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/AbstractDialLayerTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/MyDialLayerChangeListener.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/ChangeLog 2007-10-17 15:33:57 UTC (rev 355) @@ -1,3 +1,50 @@ +2007-10-17 David Gilbert <dav...@ob...> + + * experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java + (equals): New method override, + (clone): Likewise, + * experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java + (equals): Added call to super.equals(); + * experimental/org/jfree/experimental/chart/plot/dial/DialCap.java + (equals): Added call to super.equals(); + * experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java + (setBackground): Fix listener registration, + (setCap): Likewise, + (setDialFrame): Likewise, + (addLayer): Likewise, + (getLayerIndex(DialLayer)): New method, + (removeLayer(int)): Likewise, + (removeLayer(DialLayer)): Likewise, + (addScale): Fix listener registration, + * experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java + (equals): New method override, + (Pin.equals): Likewise, + (Pin.readObject): New method, + (Pin.writeObject): Likewise, + (Pointer.equals): New method override, + * experimental/org/jfree/experimental/chart/plot/dial/DialScale.java: + Now extends DialLayer, + * experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java + (equals): Added call to super.equals(); + * experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java + (equals): Added call to super.equals(); + * experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java + (equals): Added call to super.equals(); + * experimental/org/jfree/experimental/chart/plot/dial/StandardDialFrame.java + (equals): Added call to super.equals(); + * experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java + (increment): Removed field, + (setLowerBound): Added argument check, + (setUpperBound): Likewise, + (setBounds): New method, + (equals): Updated, + (hashCode): Likewise, + * experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java + (setTickRadius): Added argument check, + (setMajorTickIncrement): Likewise, + (setTickLabelPaint): Likewise, + (equals): Updated. + 2007-10-16 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/category/BarRenderer3D.java Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,18 +27,17 @@ * ---------------------- * AbstractDialLayer.java * ---------------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: AbstractDialLayer.java,v 1.1.2.2 2006/11/17 11:06:44 mungady Exp $ - * * Changes * ------- * 06-Nov-2006 : Version 1 (DG); - * 17-Nov-2007 : Added visible flag (DG); - * + * 17-Nov-2006 : Added visible flag (DG); + * 16-Oct-2007 : Implemented equals() and clone() (DG); + * */ package org.jfree.experimental.chart.plot.dial; @@ -76,6 +75,8 @@ * and <code>false</code> otherwise. * * @return A boolean. + * + * @see #setVisible(boolean) */ public boolean isVisible() { return this.visible; @@ -87,6 +88,8 @@ * listeners. * * @param visible the flag. + * + * @see #isVisible() */ public void setVisible(boolean visible) { this.visible = visible; @@ -94,6 +97,39 @@ } /** + * Tests this instance for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof AbstractDialLayer)) { + return false; + } + AbstractDialLayer that = (AbstractDialLayer) obj; + return this.visible == that.visible; + } + + /** + * Returns a clone of this instance. + * + * @return A clone. + * + * @throws CloneNotSupportedException if there is a problem cloning this + * instance. + */ + public Object clone() throws CloneNotSupportedException { + AbstractDialLayer clone = (AbstractDialLayer) super.clone(); + // we don't clone the listeners + clone.listenerList = new EventListenerList(); + return clone; + } + + /** * Registers an object for notification of changes to the dial layer. * * @param listener the object that is being registered. Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java 2007-10-17 15:33:57 UTC (rev 355) @@ -32,12 +32,11 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialBackground.java,v 1.1.2.3 2007/06/11 11:14:02 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); + * 16-Oct-2007 : The equals() method needs to call super.equals() (DG); * */ @@ -114,7 +113,8 @@ } /** - * Sets the paint for the dial background. + * Sets the paint for the dial background and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -142,7 +142,8 @@ /** * Sets the transformer used to adjust the coordinates of any - * <code>GradientPaint</code> instance used for the background paint. + * <code>GradientPaint</code> instance used for the background paint, and + * sends a {@link DialLayerChangeEvent} to all registered listeners. * * @param t the transformer (<code>null</code> not permitted). * @@ -209,7 +210,7 @@ that.gradientPaintTransformer)) { return false; } - return true; + return super.equals(obj); } /** Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -32,12 +32,11 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialCap.java,v 1.1.2.2 2006/11/06 16:26:06 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 17-Oct-2007 : Updated equals() method (DG); * */ @@ -117,14 +116,17 @@ /** * Sets the radius of the cap, as a percentage of the dial's framing - * rectangle. + * rectangle, and sends a {@link DialLayerChangeEvent} to all registered + * listeners. * - * @param radius the radius. + * @param radius the radius (must be greater than zero). * * @see #getRadius() */ public void setRadius(double radius) { - // TODO: validation + if (radius <= 0.0) { + throw new IllegalArgumentException("Requires radius > 0.0."); + } this.radius = radius; notifyListeners(new DialLayerChangeEvent(this)); } @@ -141,7 +143,8 @@ } /** - * Sets the paint for the cap background. + * Sets the paint for the cap background and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -167,7 +170,8 @@ } /** - * Sets the paint used to draw the outline of the cap. + * Sets the paint used to draw the outline of the cap and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -271,7 +275,7 @@ if (!this.outlineStroke.equals(that.outlineStroke)) { return false; } - return true; + return super.equals(obj); } /** Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,11 @@ * -------------- * DialFrame.java * -------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialFrame.java,v 1.1.2.1 2006/11/03 17:03:40 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,11 @@ * -------------- * DialLayer.java * -------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialLayer.java,v 1.1.2.3 2006/11/17 11:06:44 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,11 @@ * ------------------------- * DialLayerChangeEvent.java * ------------------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialLayerChangeEvent.java,v 1.1.2.1 2006/11/06 16:26:06 mungady Exp $ - * * Changes * ------- * 06-Nov-2006 : Version 1 (DG); Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,11 @@ * ---------------------------- * DialLayerChangeListener.java * ---------------------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialLayerChangeListener.java,v 1.1.2.1 2006/11/06 16:26:06 mungady Exp $ - * * Changes * ------- * 06-Nov-2006 : Version 1 (DG); Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java 2007-10-17 15:33:57 UTC (rev 355) @@ -32,13 +32,12 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialPlot.java,v 1.1.2.5 2007/03/08 16:51:07 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 08-Mar-2007 : Fix in hashCode() (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 17-Oct-2007 : Fixed listener registration/deregistration bugs (DG); * */ @@ -151,14 +150,21 @@ } /** - * Sets the background layer. + * Sets the background layer and sends a {@link PlotChangeEvent} to all + * registered listeners. * * @param background the background layer (<code>null</code> permitted). * * @see #getBackground() */ public void setBackground(DialLayer background) { + if (this.background != null) { + this.background.removeChangeListener(this); + } this.background = background; + if (background != null) { + background.addChangeListener(this); + } notifyListeners(new PlotChangeEvent(this)); } @@ -174,14 +180,21 @@ } /** - * Sets the cap. + * Sets the cap and sends a {@link PlotChangeEvent} to all registered + * listeners. * * @param cap the cap (<code>null</code> permitted). * * @see #getCap() */ public void setCap(DialLayer cap) { + if (this.cap != null) { + this.cap.removeChangeListener(this); + } this.cap = cap; + if (cap != null) { + cap.addChangeListener(this); + } notifyListeners(new PlotChangeEvent(this)); } @@ -197,7 +210,8 @@ } /** - * Sets the dial's frame. + * Sets the dial's frame and sends a {@link PlotChangeEvent} to all + * registered listeners. * * @param frame the frame (<code>null</code> not permitted). * @@ -207,7 +221,9 @@ if (frame == null) { throw new IllegalArgumentException("Null 'frame' argument."); } + this.dialFrame.removeChangeListener(this); this.dialFrame = frame; + frame.addChangeListener(this); notifyListeners(new PlotChangeEvent(this)); } @@ -260,7 +276,8 @@ } /** - * Sets the viewing rectangle, relative to the dial's framing rectangle. + * Sets the viewing rectangle, relative to the dial's framing rectangle, + * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param x the x-coordinate (in the range 0.0 to 1.0). * @param y the y-coordinate (in the range 0.0 to 1.0). @@ -281,7 +298,8 @@ } /** - * Adds a layer to the plot. + * Adds a layer to the plot and sends a {@link PlotChangeEvent} to all + * registered listeners. * * @param layer the layer (<code>null</code> not permitted). */ @@ -289,11 +307,52 @@ if (layer == null) { throw new IllegalArgumentException("Null 'layer' argument."); } - this.layers.add(layer); + this.layers.add(layer); + layer.addChangeListener(this); notifyListeners(new PlotChangeEvent(this)); } /** + * Returns the index for the specified layer. + * + * @param layer the layer (<code>null</code> not permitted). + * + * @return The layer index. + */ + public int getLayerIndex(DialLayer layer) { + if (layer == null) { + throw new IllegalArgumentException("Null 'layer' argument."); + } + return this.layers.indexOf(layer); + } + + /** + * Removes the layer at the specified index and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param index the index. + */ + public void removeLayer(int index) { + DialLayer layer = (DialLayer) this.layers.get(index); + if (layer != null) { + layer.removeChangeListener(this); + } + this.layers.remove(index); + notifyListeners(new PlotChangeEvent(this)); + } + + /** + * Removes the specified layer and sends a {@link PlotChangeEvent} to all + * registered listeners. + * + * @param layer the layer (<code>null</code> not permitted). + */ + public void removeLayer(DialLayer layer) { + // defer argument checking + removeLayer(getLayerIndex(layer)); + } + + /** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). @@ -459,14 +518,24 @@ } /** - * Adds a dial scale to the plot. + * Adds a dial scale to the plot and sends a {@link PlotChangeEvent} to + * all registered listeners. * * @param index the scale index. - * @param scale the scale. + * @param scale the scale (<code>null</code> not permitted). */ public void addScale(int index, DialScale scale) { + if (scale == null) { + throw new IllegalArgumentException("Null 'scale' argument."); + } + DialScale existing = (DialScale) this.scales.get(index); + if (existing != null) { + removeLayer(existing); + } this.layers.add(scale); this.scales.set(index, scale); + scale.addChangeListener(this); + notifyListeners(new PlotChangeEvent(this)); } /** @@ -514,7 +583,7 @@ /** * A utility method that computes a rectangle using relative radius values. * - * @param rect the reference rectangle. + * @param rect the reference rectangle (<code>null</code> not permitted). * @param radiusW the width radius (must be > 0.0) * @param radiusH the height radius. * @@ -522,6 +591,9 @@ */ public static Rectangle2D rectangleByRadius(Rectangle2D rect, double radiusW, double radiusH) { + if (rect == null) { + throw new IllegalArgumentException("Null 'rect' argument."); + } double x = rect.getCenterX(); double y = rect.getCenterY(); double w = rect.getWidth() * radiusW; @@ -530,7 +602,8 @@ } /** - * Receives notification when a layer has changed. + * Receives notification when a layer has changed, and responds by + * forwarding a {@link PlotChangeEvent} to all registered listeners. * * @param event the event. */ Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,16 +27,15 @@ * ---------------- * DialPointer.java * ---------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialPointer.java,v 1.1.2.4 2007/04/30 21:38:31 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); + * 17-Oct-2007 : Added equals() overrides (DG); * */ @@ -52,9 +51,14 @@ import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; +import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; +import org.jfree.chart.util.SerialUtilities; /** * A base class for the pointer in a {@link DialPlot}. @@ -140,6 +144,30 @@ } /** + * Checks this instance for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> not permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof DialPointer)) { + return false; + } + DialPointer that = (DialPointer) obj; + if (this.datasetIndex != that.datasetIndex) { + return false; + } + if (this.radius != that.radius) { + return false; + } + return super.equals(obj); + } + + /** * Returns a clone of the pointer. * * @return a clone. @@ -184,16 +212,21 @@ /** * Returns the paint. * - * @return The paint. + * @return The paint (never <code>null</code>). + * + * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** - * Sets the paint. + * Sets the paint and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param paint the paint (<code>null</code> not permitted). + * + * @see #getPaint() */ public void setPaint(Paint paint) { this.paint = paint; @@ -203,16 +236,21 @@ /** * Returns the stroke. * - * @return The stroke. + * @return The stroke (neverA <code>null</code>). + * + * @see #setStroke(Stroke) */ public Stroke getStroke() { return this.stroke; } /** - * Sets the stroke. + * Sets the stroke and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). + * + * @see #getStroke() */ public void setStroke(Stroke stroke) { this.stroke = stroke; @@ -247,6 +285,58 @@ g2.draw(line); } + /** + * Tests this pointer for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof DialPointer.Pin)) { + return false; + } + DialPointer.Pin that = (DialPointer.Pin) obj; + if (!PaintUtilities.equal(this.paint, that.paint)) { + return false; + } + if (!this.stroke.equals(that.stroke)) { + return false; + } + return super.equals(obj); + } + + /** + * Provides serialization support. + * + * @param stream the output stream. + * + * @throws IOException if there is an I/O error. + */ + private void writeObject(ObjectOutputStream stream) throws IOException { + stream.defaultWriteObject(); + SerialUtilities.writePaint(this.paint, stream); + SerialUtilities.writeStroke(this.stroke, stream); + } + + /** + * Provides serialization support. + * + * @param stream the input stream. + * + * @throws IOException if there is an I/O error. + * @throws ClassNotFoundException if there is a classpath problem. + */ + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException { + stream.defaultReadObject(); + this.paint = SerialUtilities.readPaint(stream); + this.stroke = SerialUtilities.readStroke(stream); + } + } /** @@ -281,15 +371,20 @@ * Returns the width radius. * * @return The width radius. + * + * @see #setWidthRadius(double) */ public double getWidthRadius() { return this.widthRadius; } /** - * Sets the width radius. + * Sets the width radius and sends a {@link DialLayerChangeEvent} to + * all registered listeners. * - * @param radius the radius. + * @param radius the radius + * + * @see #getWidthRadius() */ public void setWidthRadius(double radius) { this.widthRadius = radius; @@ -357,6 +452,29 @@ g2.draw(line); } + /** + * Tests this pointer for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof DialPointer.Pointer)) { + return false; + } + DialPointer.Pointer that = (DialPointer.Pointer) obj; + + if (this.widthRadius != that.widthRadius) { + return false; + } + return super.equals(obj); + } + + } } Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialScale.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialScale.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialScale.java 2007-10-17 15:33:57 UTC (rev 355) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,25 +27,25 @@ * -------------- * DialScale.java * -------------- - * (C) Copyright 2006, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialScale.java,v 1.1.2.1 2006/11/03 17:03:40 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); + * 17-Oct-2007 : Made this an extension of the DialLayer interface (DG); * */ package org.jfree.experimental.chart.plot.dial; /** - * A dial scale converts data values into angles. + * A dial scale is a specialised layer that has the ability to convert data + * values into angles. */ -public interface DialScale { +public interface DialScale extends DialLayer { /** * Converts a data value to an angle (in degrees, using the same @@ -54,6 +54,8 @@ * @param value the data value. * * @return The angle in degrees. + * + * @see #angleToValue(double) */ public double valueToAngle(double value); @@ -63,6 +65,8 @@ * @param angle the angle (in degrees). * * @return The data value. + * + * @see #valueToAngle(double) */ public double angleToValue(double angle); Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java 2007-10-17 15:33:57 UTC (rev 355) @@ -32,13 +32,12 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialTextAnnotation.java,v 1.1.2.3 2007/03/08 16:51:07 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 08-Mar-2007 : Fix in hashCode() (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 17-Oct-2007 : Updated equals() (DG); * */ @@ -304,7 +303,7 @@ if (!this.anchor.equals(that.anchor)) { return false; } - return true; + return super.equals(obj); } /** Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java 2007-10-17 15:33:57 UTC (rev 355) @@ -27,17 +27,16 @@ * ----------------------- * DialValueIndicator.java * ----------------------- - * (C) Copyright 2006, 2007, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialValueIndicator.java,v 1.1.2.3 2006/11/07 16:11:12 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 17-Oct-2007 : Updated equals() (DG); * */ @@ -564,7 +563,7 @@ return false; } - return true; + return super.equals(obj); } /** Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java 2007-10-17 15:33:57 UTC (rev 355) @@ -32,8 +32,6 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: SimpleDialFrame.java,v 1.1.2.3 2007/03/08 16:51:07 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); @@ -104,18 +102,26 @@ * Returns the radius, relative to the framing rectangle. * * @return The radius. + * + * @see #setRadius(double) */ public double getRadius() { return this.radius; } /** - * Sets the radius. + * Sets the radius and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * - * @param radius the radius. + * @param radius the radius (must be positive). + * + * @see #getRadius() */ public void setRadius(double radius) { - // TODO: validation + if (radius <= 0) { + throw new IllegalArgumentException("" + + "The 'radius' must be positive."); + } this.radius = radius; notifyListeners(new DialLayerChangeEvent(this)); } @@ -132,7 +138,8 @@ } /** - * Sets the background paint. + * Sets the background paint and sends a {@link DialLayerChangeEvent} to + * all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -158,7 +165,8 @@ } /** - * Sets the foreground paint. + * Sets the foreground paint and sends a {@link DialLayerChangeEvent} to + * all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -184,7 +192,8 @@ } /** - * Sets the stroke. + * Sets the stroke and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * @@ -281,7 +290,7 @@ if (!this.stroke.equals(that.stroke)) { return false; } - return true; + return super.equals(obj); } /** Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialFrame.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialFrame.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialFrame.java 2007-10-17 15:33:57 UTC (rev 355) @@ -32,13 +32,12 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: StandardDialFrame.java,v 1.1.2.4 2007/03/08 16:51:07 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 08-Mar-2007 : Fix in hashCode() (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 17-Oct-2007 : Updated equals() (DG); * */ @@ -330,6 +329,13 @@ } + /** + * Returns the outer window. + * + * @param frame the frame. + * + * @return The outer window. + */ protected Shape getOuterWindow(Rectangle2D frame) { double radiusMargin = 0.02; double angleMargin = 1.5; @@ -428,7 +434,7 @@ if (!this.stroke.equals(that.stroke)) { return false; } - return true; + return super.equals(obj); } /** Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java 2007-10-17 15:33:57 UTC (rev 355) @@ -32,13 +32,12 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: StandardDialRange.java,v 1.1.2.3 2007/03/08 16:51:07 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 08-Mar-2007 : Fix in hashCode() (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 17-Oct-2007 : Removed increment attribute (DG); * */ @@ -71,11 +70,6 @@ /** The maximum data value for the scale. */ private double upperBound; - - /** - * The increment (in data units) for each section. - */ - private double increment; /** * The paint used to draw the range highlight. This field is transient @@ -130,14 +124,18 @@ } /** - * Sets the lower bound of the dial range. + * Sets the lower bound of the dial range and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param bound the lower bound. * * @see #getLowerBound() */ public void setLowerBound(double bound) { - // FIXME: check + if (bound >= this.upperBound) { + throw new IllegalArgumentException( + "Lower bound must be less than upper bound."); + } this.lowerBound = bound; notifyListeners(new DialLayerChangeEvent(this)); } @@ -154,42 +152,39 @@ } /** - * Sets the upper bound of the dial range. + * Sets the upper bound of the dial range and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param bound the upper bound. * * @see #getUpperBound() */ public void setUpperBound(double bound) { - // FIXME: check + if (bound <= this.lowerBound) { + throw new IllegalArgumentException( + "Lower bound must be less than upper bound."); + } this.upperBound = bound; notifyListeners(new DialLayerChangeEvent(this)); } /** - * Returns the increment between tick marks. + * Sets the bounds for the range and sends a {@link DialLayerChangeEvent} + * to all registered listeners. * - * @return The increment. - * - * @see #setIncrement(double) + * @param lower the lower bound. + * @param upper the upper bound. */ - public double getIncrement() { - return this.increment; - } - - /** - * Sets the increment. - * - * @param increment the increment. - * - * @see #getIncrement() - */ - public void setIncrement(double increment) { - // FIXME: check - this.increment = increment; + public void setBounds(double lower, double upper) { + if (lower >= upper) { + throw new IllegalArgumentException( + "Lower must be less than upper."); + } + this.lowerBound = lower; + this.upperBound = upper; notifyListeners(new DialLayerChangeEvent(this)); } - + /** * Returns the paint used to highlight the range. * @@ -202,7 +197,8 @@ } /** - * Sets the paint used to highlight the range. + * Sets the paint used to highlight the range and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -228,7 +224,8 @@ } /** - * Sets the inner radius. + * Sets the inner radius and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param radius the radius. * @@ -251,7 +248,8 @@ } /** - * Sets the outer radius. + * Sets the outer radius and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param radius the radius. * @@ -287,7 +285,6 @@ this.innerRadius, this.innerRadius); Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius); - //double range = this.upperBound - this.lowerBound; DialScale scale = plot.getScaleForDataset(0); double angleMin = scale.valueToAngle(this.lowerBound); @@ -325,9 +322,6 @@ if (this.upperBound != that.upperBound) { return false; } - if (this.increment != that.increment) { - return false; - } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } @@ -337,7 +331,7 @@ if (this.outerRadius != that.outerRadius) { return false; } - return true; + return super.equals(obj); } /** @@ -346,11 +340,9 @@ * @return The hash code. */ public int hashCode() { - int result = 193; - long temp = Double.doubleToLongBits(this.increment); + int result = 193; + long temp = Double.doubleToLongBits(this.lowerBound); result = 37 * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(this.lowerBound); - result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.upperBound); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.innerRadius); Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java 2007-10-17 15:33:57 UTC (rev 355) @@ -27,13 +27,11 @@ * ---------------------- * StandardDialScale.java * ---------------------- - * (C) Copyright 2006, 2007, by Object Refinery Limited. + * (C) Copyright 2006-2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: StandardDialScale.java,v 1.1.2.3 2006/11/17 11:06:44 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); @@ -69,7 +67,7 @@ * A scale for a {@link DialPlot}. */ public class StandardDialScale extends AbstractDialLayer implements DialScale, - DialLayer, Cloneable, PublicCloneable, Serializable { + Cloneable, PublicCloneable, Serializable { /** The minimum data value for the scale. */ private double lowerBound; @@ -202,9 +200,10 @@ } /** - * Sets the start angle for the scale. + * Sets the start angle for the scale and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * - * @param angle the angle. + * @param angle the angle (in degrees). * * @see #getStartAngle() */ @@ -217,13 +216,16 @@ * Returns the extent. * * @return The extent. + * + * @see #setExtent(double) */ public double getExtent() { return this.extent; } /** - * Sets the extent. + * Sets the extent and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param extent the extent. * @@ -247,14 +249,18 @@ } /** - * Sets the tick radius. + * Sets the tick radius and sends a {@link DialLayerChangeEvent} to all + * registered listeners. * * @param radius the radius. * * @see #getTickRadius() */ public void setTickRadius(double radius) { - // TODO: Validate + if (radius <= 0.0) { + throw new IllegalArgumentException( + "The 'radius' must be positive."); + } this.tickRadius = radius; notifyListeners(new DialLayerChangeEvent(this)); } @@ -271,14 +277,18 @@ } /** - * Sets the increment (in data units) between major tick labels. + * Sets the increment (in data units) between major tick labels and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param increment the increment. * * @see #getMajorTickIncrement() */ public void setMajorTickIncrement(double increment) { - // TODO: validation + if (increment <= 0.0) { + throw new IllegalArgumentException( + "The 'increment' must be positive."); + } this.majorTickIncrement = increment; notifyListeners(new DialLayerChangeEvent(this)); } @@ -297,7 +307,8 @@ } /** - * Sets the length factor for the major tick marks. + * Sets the length factor for the major tick marks and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param length the length. * @@ -321,7 +332,8 @@ } /** - * Sets the major tick paint. + * Sets the major tick paint and sends a {@link DialLayerChangeEvent} to + * all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * @@ -347,7 +359,8 @@ } /** - * Sets the stroke used to draw the major tick marks. + * Sets the stroke used to draw the major tick marks and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * @@ -373,7 +386,8 @@ } /** - * Sets the number of minor tick marks between major tick marks. + * Sets the number of minor tick marks between major tick marks and sends + * a {@link DialLayerChangeEvent} to all registered listeners. * * @param count the count. * @@ -399,7 +413,8 @@ } /** - * Sets the length factor for the minor tick marks. + * Sets the length factor for the minor tick marks and sends + * a {@link DialLayerChangeEvent} to all registered listeners. * * @param length the length. * @@ -423,7 +438,8 @@ } /** - * Sets the tick label offset. + * Sets the tick label offset and sends a {@link DialLayerChangeEvent} to + * all registered listeners. * * @param offset the offset. * @@ -446,7 +462,8 @@ } /** - * Sets the font used to display the tick labels. + * Sets the font used to display the tick labels and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). * @@ -464,18 +481,23 @@ * Returns the paint used to draw the tick labels. * * @return The paint (<code>null</code> not permitted). + * + * @see #setTickLabelPaint(Paint) */ public Paint getTickLabelPaint() { return this.tickLabelPaint; } /** - * Sets the paint used to draw the tick labels. + * Sets the paint used to draw the tick labels and sends a + * {@link DialLayerChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). */ public void setTickLabelPaint(Paint paint) { - // TODO: validation + if (paint == null) { + throw new IllegalArgumentException("Null 'paint' argument."); + } this.tickLabelPaint = paint; notifyListeners(new DialLayerChangeEvent(this)); } @@ -616,6 +638,8 @@ * * @return The angle (in degrees, using the same specification as Java's * Arc2D class). + * + * @see #angleToValue(double) */ public double valueToAngle(double value) { double range = this.upperBound - this.lowerBound; @@ -623,6 +647,15 @@ return this.startAngle + unit * (value - this.lowerBound); } + /** + * Converts the given angle to a data value, based on this scale. + * + * @param angle the angle. + * + * @return The data value. + * + * @see #valueToAngle(double) + */ public double angleToValue(double angle) { return Double.NaN; // FIXME } @@ -685,7 +718,7 @@ if (!PaintUtilities.equal(this.tickLabelPaint, that.tickLabelPaint)) { return false; } - return true; + return super.equals(obj); } /** Added: trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/AbstractDialLayerTests.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/AbstractDialLayerTests.java (rev 0) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/AbstractDialLayerTests.java 2007-10-17 15:33:57 UTC (rev 355) @@ -0,0 +1,150 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * --------------------------- + * AbstractDialLayerTests.java + * --------------------------- + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 16-Oct-2007 : Version 1 (DG); + * + */ + +package org.jfree.experimental.chart.plot.dial.junit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.experimental.chart.plot.dial.AbstractDialLayer; +import org.jfree.experimental.chart.plot.dial.DialCap; + +/** + * Tests for the {@link AbstractDialLayer} class. + */ +public class AbstractDialLayerTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(AbstractDialLayerTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public AbstractDialLayerTests(String name) { + super(name); + } + + /** + * Confirm that the equals method can distinguish all the required fields. + */ + public void testEquals() { + DialCap c1 = new DialCap(); + DialCap c2 = new DialCap(); + assertTrue(c1.equals(c2)); + + // visible + c1.setVisible(false); + assertFalse(c1.equals(c2)); + c2.setVisible(false); + assertTrue(c1.equals(c2)); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + // test a default instance + DialCap c1 = new DialCap(); + DialCap c2 = null; + try { + c2 = (DialCap) c1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(c1 != c2); + assertTrue(c1.getClass() == c2.getClass()); + assertTrue(c1.equals(c2)); + + // check that the listener lists are independent + MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); + c1.addChangeListener(l1); + assertTrue(c1.hasListener(l1)); + assertFalse(c2.hasListener(l1)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + // test a default instance + DialCap c1 = new DialCap(); + DialCap c2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(c1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + c2 = (DialCap) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(c1, c2); + + // check that the listener lists are independent + MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); + c1.addChangeListener(l1); + assertTrue(c1.hasListener(l1)); + assertFalse(c2.hasListener(l1)); + } + +} Modified: trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialBackgroundTests.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialBackgroundTests.java 2007-10-17 14:45:11 UTC (rev 354) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialBackgroundTests.java 2007-10-17 15:33:57 UTC (rev 355) @@ -27,13 +27,11 @@ * ------------------------ * DialBackgroundTests.java * ------------------------ - * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2006-2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * - * $Id: DialBackgroundTests.java,v 1.1.2.2 2006/11/06 16:31:01 mungady Exp $ - * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); @@ -106,6 +104,13 @@ b2.setGradientPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); assertTrue(b1.equals(b2)); + + // check an inherited attribute + b1.setVisible(false); + assertFalse(b1.equals(b2)); + b2.setVisible(false); + assertTrue(b1.equals(b2)); + } /** @@ -153,6 +158,12 @@ ... [truncated message content] |
From: <mu...@us...> - 2007-10-23 16:34:10
|
Revision: 405 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=405&view=rev Author: mungady Date: 2007-10-23 09:34:09 -0700 (Tue, 23 Oct 2007) Log Message: ----------- 2007-10-23 David Gilbert <dav...@ob...> * swt/org/jfree/experimental/swt/SWTGraphics2D.java: Lots of API doc updates plus (hints): New field, (SWTGraphics2D): Initialise new field, (getRenderingHint): Implemented, (setRenderingHint): Likewise, (getRenderingHints): Likewise, (addRenderingHints): Likewise, (setRenderingHints): Likewise, (drawPolygon): Likewise, (drawPolyline): Likewise, (drawOval): Likewise, (drawArc): Likewise, (drawRoundRect): Likewise, (clearRect): Implemented, (fillRoundRect): Likewise, (fillOval): Likewise, (fillArc): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-23 16:16:08 UTC (rev 404) +++ trunk/ChangeLog 2007-10-23 16:34:09 UTC (rev 405) @@ -1,5 +1,26 @@ 2007-10-23 David Gilbert <dav...@ob...> + * swt/org/jfree/experimental/swt/SWTGraphics2D.java: + Lots of API doc updates plus + (hints): New field, + (SWTGraphics2D): Initialise new field, + (getRenderingHint): Implemented, + (setRenderingHint): Likewise, + (getRenderingHints): Likewise, + (addRenderingHints): Likewise, + (setRenderingHints): Likewise, + (drawPolygon): Likewise, + (drawPolyline): Likewise, + (drawOval): Likewise, + (drawArc): Likewise, + (drawRoundRect): Likewise, + (clearRect): Implemented, + (fillRoundRect): Likewise, + (fillOval): Likewise, + (fillArc): Likewise. + +2007-10-23 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/AbstractRenderer.java (lookupSeriesPaint): Call accessor methods for per-series paint, (lookupSeriesFillPaint): Likewise, Modified: trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java =================================================================== --- trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java 2007-10-23 16:16:08 UTC (rev 404) +++ trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java 2007-10-23 16:34:09 UTC (rev 405) @@ -47,6 +47,11 @@ * 16-Jul-2007 : Implemented alpha channel (HP); * 11-Sep-2007 : Fixed alpha channel lying within awt colors, bug 1737869 (HP); * 13-Oct-2007 : Fixed compositing issues (HP); + * 23-Oct-2007 : Added mechanism for storing RenderingHints (which are + * still ignored at this point) (DG); + * 23-Oct-2007 : Implemented drawPolygon(), drawPolyline(), drawOval(), + * fillOval(), drawArc() and fillArc() (DG); + * */ package org.jfree.experimental.swt; @@ -106,6 +111,12 @@ /** The swt graphic composite */ private GC gc; + /** + * The rendering hints. For now, these are not used, but at least the + * basic mechanism is present. + */ + private RenderingHints hints; + /** A reference to the compositing rule to apply. This is necessary * due to the poor compositing interface of the SWT toolkit. */ private java.awt.Composite composite; @@ -127,6 +138,7 @@ public SWTGraphics2D(GC gc) { super(); this.gc = gc; + this.hints = new RenderingHints(null); this.composite = AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f); } @@ -146,57 +158,94 @@ return null; } - /* (non-Javadoc) - * @see java.awt.Graphics2D#setRenderingHint(java.awt.RenderingHints.Key, - * java.lang.Object) + /** + * Returns the current value for the specified hint key, or + * <code>null</code> if no value is set. + * + * @param hintKey the hint key (<code>null</code> permitted). + * + * @return The hint value, or <code>null</code>. + * + * @see #setRenderingHint(Key, Object) */ - public void setRenderingHint(Key hintKey, Object hintValue) { - // TODO Auto-generated method stub - + public Object getRenderingHint(Key hintKey) { + return this.hints.get(hintKey); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#getRenderingHint(java.awt.RenderingHints.Key) + /** + * Sets the value for a rendering hint. For now, this graphics context + * ignores all hints. + * + * @param hintKey the key (<code>null</code> not permitted). + * @param hintValue the value (must be compatible with the specified key). + * + * @throws IllegalArgumentException if <code>hintValue</code> is not + * compatible with the <code>hintKey</code>. + * + * @see #getRenderingHint(Key) */ - public Object getRenderingHint(Key hintKey) { - // TODO Auto-generated method stub - return null; + public void setRenderingHint(Key hintKey, Object hintValue) { + this.hints.put(hintKey, hintValue); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#setRenderingHints(java.util.Map) + /** + * Returns a copy of the hints collection for this graphics context. + * + * @return A copy of the hints collection. */ - public void setRenderingHints(Map hints) { - // TODO Auto-generated method stub - + public RenderingHints getRenderingHints() { + return (RenderingHints) this.hints.clone(); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#addRenderingHints(java.util.Map) + /** + * Adds the hints in the specified map to the graphics context, replacing + * any existing hints. For now, this graphics context ignores all hints. + * + * @param hints the hints (<code>null</code> not permitted). + * + * @see #setRenderingHints(Map) */ public void addRenderingHints(Map hints) { - // TODO Auto-generated method stub - + this.hints.putAll(hints); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#getRenderingHints() + /** + * Replaces the existing hints with those contained in the specified + * map. Note that, for now, this graphics context ignores all hints. + * + * @param hints the hints (<code>null</code> not permitted). + * + * @see #addRenderingHints(Map) */ - public RenderingHints getRenderingHints() { - // TODO Auto-generated method stub - return null; + public void setRenderingHints(Map hints) { + if (hints == null) { + throw new NullPointerException("Null 'hints' argument."); + } + this.hints = new RenderingHints(hints); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#getPaint() + /** + * Returns the current paint for this graphics context. + * + * @return The current paint. + * + * @see #setPaint(Paint) */ public Paint getPaint() { + // TODO: it might be a good idea to keep a reference to the color + // specified in setPaint() or setColor(), rather than creating a + // new object every time getPaint() is called. return SWTUtils.toAwtColor(this.gc.getForeground()); } /** - * Set the paint associated with the swt graphic composite. - * @see java.awt.Graphics2D#setPaint(java.awt.Paint) + * Sets the paint for this graphics context. For now, this graphics + * context only supports instances of {@link Color}. + * + * @param paint the paint (<code>null</code> not permitted). + * + * @see #getPaint() + * @see #setColor(Color) */ public void setPaint(Paint paint) { if (paint instanceof Color) { @@ -207,15 +256,26 @@ } } - /* (non-Javadoc) - * @see java.awt.Graphics#getColor() + /** + * Returns the current color for this graphics context. + * + * @return The current color. + * + * @see #setColor(Color) */ public Color getColor() { + // TODO: it might be a good idea to keep a reference to the color + // specified in setPaint() or setColor(), rather than creating a + // new object every time getPaint() is called. return SWTUtils.toAwtColor(this.gc.getForeground()); } - /* (non-Javadoc) - * @see java.awt.Graphics#setColor(java.awt.Color) + /** + * Sets the current color for this graphics context. + * + * @param color the color. + * + * @see #getColor() */ public void setColor(Color color) { org.eclipse.swt.graphics.Color swtColor = getSwtColorFromPool(color); @@ -235,13 +295,6 @@ } /* (non-Javadoc) - * @see java.awt.Graphics2D#getBackground() - */ - public Color getBackground() { - return SWTUtils.toAwtColor(this.gc.getBackground()); - } - - /* (non-Javadoc) * @see java.awt.Graphics2D#setBackground(java.awt.Color) */ public void setBackground(Color color) { @@ -253,6 +306,13 @@ } /* (non-Javadoc) + * @see java.awt.Graphics2D#getBackground() + */ + public Color getBackground() { + return SWTUtils.toAwtColor(this.gc.getBackground()); + } + + /* (non-Javadoc) * @see java.awt.Graphics#setPaintMode() */ public void setPaintMode() { @@ -264,19 +324,24 @@ */ public void setXORMode(Color color) { // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see java.awt.Graphics2D#getComposite() + /** + * Returns the current composite. + * + * @return The current composite. + * + * @see #setComposite(Composite) */ public Composite getComposite() { - //return AlphaComposite.getInstance(this.compositingRule, this.gc.getAlpha()/0xFF); return this.composite; } - /* (non-Javadoc) - * @see java.awt.Graphics2D#setComposite(java.awt.Composite) + /** + * Sets the current composite. This implementation currently supports + * only the {@link AlphaComposite} class. + * + * @param comp the composite. */ public void setComposite(Composite comp) { this.composite = comp; @@ -290,23 +355,32 @@ } } - /* (non-Javadoc) - * @see java.awt.Graphics2D#getStroke() + /** + * Returns the current stroke for this graphics context. + * + * @return The current stroke. + * + * @see #setStroke(Stroke) */ public Stroke getStroke() { return new BasicStroke(this.gc.getLineWidth(), this.gc.getLineCap(), this.gc.getLineJoin()); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#setStroke(java.awt.Stroke) + /** + * Sets the stroke for this graphics context. For now, this implementation + * only recognises the {@link BasicStroke} class. + * + * @param stroke the stroke (<code>null</code> not permitted). + * + * @see #getStroke() */ public void setStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; // linewidth this.gc.setLineWidth((int) bs.getLineWidth()); - + // line join switch (bs.getLineJoin()) { case BasicStroke.JOIN_BEVEL : @@ -319,7 +393,7 @@ this.gc.setLineJoin(SWT.JOIN_ROUND); break; } - + // line cap switch (bs.getEndCap()) { case BasicStroke.CAP_BUTT : @@ -332,10 +406,10 @@ this.gc.setLineCap(SWT.CAP_SQUARE); break; } - + // set the line style to solid by default this.gc.setLineStyle(SWT.LINE_SOLID); - + // apply dash style if any float[] dashes = bs.getDashArray(); if (dashes != null) { @@ -468,7 +542,6 @@ */ public void rotate(double theta, double x, double y) { // TODO Auto-generated method stub - } /* (non-Javadoc) @@ -495,8 +568,15 @@ swtTransform.dispose(); } - /* (non-Javadoc) - * @see java.awt.Graphics2D#draw(java.awt.Shape) + /** + * Draws the outline of the specified shape using the current stroke and + * paint settings. + * + * @param shape the shape (<code>null</code> not permitted). + * + * @see #getPaint() + * @see #getStroke() + * @see #fill(Shape) */ public void draw(Shape shape) { Path path = toSwtPath(shape); @@ -505,76 +585,135 @@ } /** - * Draws a line on the swt graphic composite. - * @see java.awt.Graphics#drawLine(int, int, int, int) + * Draws a line from (x1, y1) to (x2, y2) using the current stroke + * and paint settings. + * + * @param x1 the x-coordinate for the starting point. + * @param y1 the y-coordinate for the starting point. + * @param x2 the x-coordinate for the ending point. + * @param y2 the y-coordinate for the ending point. + * + * @see #draw(Shape) */ public void drawLine(int x1, int y1, int x2, int y2) { this.gc.drawLine(x1, y1, x2, y2); } - /* (non-Javadoc) - * @see java.awt.Graphics#drawPolygon(int[], int[], int) + /** + * Draws the outline of the polygon specified by the given points, using + * the current paint and stroke settings. + * + * @param xPoints the x-coordinates. + * @param yPoints the y-coordinates. + * @param npoints the number of points in the polygon. + * + * @see #draw(Shape) */ public void drawPolygon(int [] xPoints, int [] yPoints, int npoints) { - // TODO Auto-generated method stub - + drawPolyline(xPoints, yPoints, npoints); + if (npoints > 1) { + this.gc.drawLine(xPoints[npoints-1], yPoints[npoints-1], + xPoints[0], yPoints[0]); + } } - /* (non-Javadoc) - * @see java.awt.Graphics#drawPolyline(int[], int[], int) + /** + * Draws a sequence of connected lines specified by the given points, using + * the current paint and stroke settings. + * + * @param xPoints the x-coordinates. + * @param yPoints the y-coordinates. + * @param npoints the number of points in the polygon. + * + * @see #draw(Shape) */ public void drawPolyline(int [] xPoints, int [] yPoints, int npoints) { - // TODO Auto-generated method stub - + if (npoints > 1) { + int x0 = xPoints[0]; + int y0 = yPoints[0]; + int x1 = 0, y1 = 0; + for (int i = 1; i < npoints; i++) { + x1 = xPoints[i]; + y1 = yPoints[i]; + this.gc.drawLine(x0, y0, x1, y1); + x0 = x1; + y0 = y1; + } + } } - /* (non-Javadoc) - * @see java.awt.Graphics#drawOval(int, int, int, int) + /** + * Draws an oval that fits within the specified rectangular region. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param width the frame width. + * @param height the frame height. + * + * @see #fillOval(int, int, int, int) + * @see #draw(Shape) */ public void drawOval(int x, int y, int width, int height) { - // TODO Auto-generated method stub - + this.gc.drawOval(x, y, width - 1, height - 1); } - /* (non-Javadoc) - * @see java.awt.Graphics#drawArc(int, int, int, int, int, int) + /** + * Draws an arc that is part of an ellipse that fits within the specified + * framing rectangle. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param width the frame width. + * @param height the frame height. + * @param arcStart the arc starting point, in degrees. + * @param arcAngle the extent of the arc. + * + * @see #fillArc(int, int, int, int, int, int) */ public void drawArc(int x, int y, int width, int height, int arcStart, int arcAngle) { - // TODO Auto-generated method stub - + this.gc.drawArc(x, y, width - 1, height - 1, arcStart, arcAngle); } - /* (non-Javadoc) - * @see java.awt.Graphics#drawRoundRect(int, int, int, int, int, int) + /** + * Draws a rectangle with rounded corners that fits within the specified + * framing rectangle. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param width the frame width. + * @param height the frame height. + * @param arcWidth the width of the arc defining the roundedness of the + * rectangle's corners. + * @param arcHeight the height of the arc defining the roundedness of the + * rectangle's corners. + * + * @see #fillRoundRect(int, int, int, int, int, int) */ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { - // TODO Auto-generated method stub - + this.gc.drawRoundRectangle(x, y, width - 1, height - 1, arcWidth, + arcHeight); } - /** fill an arbitrary shape on the swt graphic composite - * with the current stroke and paint. - * note that for consistency with the awt method, it is needed - * to switch temporarily the foreground and background colors. - * @see java.awt.Graphics2D#fill(java.awt.Shape) - */ - public void fill(Shape shape) { - // if (!(shape instanceof java.awt.geom.Rectangle2D)) { - // System.out.println("using fill with shape: "+shape.toString()); - // } - // if (shape instanceof java.awt.geom.GeneralPath) { - // java.awt.geom.GeneralPath gp = (java.awt.geom.GeneralPath) shape; - // PathIteratorgp.getPathIterator(this.getTransform()); - // System.out.println("general path details:"+gp.getWindingRule()); - // } - Path path = toSwtPath(shape); - switchColors(); - this.gc.fillPath(path); - switchColors(); - path.dispose(); - } + /** + * Fills the specified shape using the current paint. + * + * @param shape the shape (<code>null</code> not permitted). + * + * @see #getPaint() + * @see #draw(Shape) + */ + public void fill(Shape shape) { + Path path = toSwtPath(shape); + // Note that for consistency with the AWT implementation, it is + // necessary to switch temporarily the foreground and background + // colours + switchColors(); + this.gc.fillPath(path); + switchColors(); + path.dispose(); + } /** * Fill a rectangle area on the swt graphic composite. @@ -588,12 +727,21 @@ this.switchColors(); } - /* (non-Javadoc) - * @see java.awt.Graphics#clearRect(int, int, int, int) + /** + * Fills the specified rectangle with the current background colour. + * + * @param x the x-coordinate for the rectangle. + * @param y the y-coordinate for the rectangle. + * @param width the width. + * @param height the height. + * + * @see #fillRect(int, int, int, int) */ public void clearRect(int x, int y, int width, int height) { - // TODO Auto-generated method stub - + Paint saved = getPaint(); + setPaint(getBackground()); + fillRect(x, y, width, height); + setPaint(saved); } /* (non-Javadoc) @@ -601,33 +749,66 @@ */ public void fillPolygon(int [] xPoints, int [] yPoints, int npoints) { // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see java.awt.Graphics#fillRoundRect(int, int, int, int, int, int) + /** + * Draws a rectangle with rounded corners that fits within the specified + * framing rectangle. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param width the frame width. + * @param height the frame height. + * @param arcWidth the width of the arc defining the roundedness of the + * rectangle's corners. + * @param arcHeight the height of the arc defining the roundedness of the + * rectangle's corners. + * + * @see #drawRoundRect(int, int, int, int, int, int) */ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { - // TODO Auto-generated method stub - + switchColors(); + this.gc.fillRoundRectangle(x, y, width - 1, height - 1, arcWidth, + arcHeight); + switchColors(); } - /* (non-Javadoc) - * @see java.awt.Graphics#fillOval(int, int, int, int) + /** + * Fills an oval that fits within the specified rectangular region. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param width the frame width. + * @param height the frame height. + * + * @see #drawOval(int, int, int, int) + * @see #fill(Shape) */ public void fillOval(int x, int y, int width, int height) { - // TODO Auto-generated method stub - + switchColors(); + this.gc.fillOval(x, y, width - 1, height - 1); + switchColors(); } - /* (non-Javadoc) - * @see java.awt.Graphics#fillArc(int, int, int, int, int, int) + /** + * Fills an arc that is part of an ellipse that fits within the specified + * framing rectangle. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param width the frame width. + * @param height the frame height. + * @param arcStart the arc starting point, in degrees. + * @param arcAngle the extent of the arc. + * + * @see #drawArc(int, int, int, int, int, int) */ public void fillArc(int x, int y, int width, int height, int arcStart, int arcAngle) { - // TODO Auto-generated method stub - + switchColors(); + this.gc.fillArc(x, y, width - 1, height - 1, arcStart, arcAngle); + switchColors(); } /** @@ -665,8 +846,8 @@ * @see java.awt.Graphics2D#getFontRenderContext() */ public FontRenderContext getFontRenderContext() { - FontRenderContext fontRenderContext - = new FontRenderContext(new AffineTransform(), true, true); + FontRenderContext fontRenderContext = new FontRenderContext( + new AffineTransform(), true, true); return fontRenderContext; } @@ -705,7 +886,6 @@ */ public void drawString(AttributedCharacterIterator iterator, int x, int y) { // TODO Auto-generated method stub - } /* (non-Javadoc) @@ -715,7 +895,6 @@ public void drawString(AttributedCharacterIterator iterator, float x, float y) { // TODO Auto-generated method stub - } /* (non-Javadoc) @@ -750,9 +929,8 @@ */ public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y) { - org.eclipse.swt.graphics.Image im - = new org.eclipse.swt.graphics.Image(this.gc.getDevice(), - convertToSWT(image)); + org.eclipse.swt.graphics.Image im = new org.eclipse.swt.graphics.Image( + this.gc.getDevice(), convertToSWT(image)); this.gc.drawImage(im, x, y); im.dispose(); } @@ -856,11 +1034,23 @@ } /** + * Add given swt resource to the resource pool. All resources added + * to the resource pool will be disposed when {@link #dispose()} is called. + * + * @param resource the resource to add to the pool. + * @return the swt <code>Resource</code> just added. + */ + private Resource addToResourcePool(Resource resource) { + this.resourcePool.add(resource); + return resource; + } + + /** * Dispose the resource pool. */ private void disposeResourcePool() { - for (Iterator it = this.resourcePool.iterator();it.hasNext();) { - Resource resource = (Resource)it.next(); + for (Iterator it = this.resourcePool.iterator(); it.hasNext();) { + Resource resource = (Resource) it.next(); resource.dispose(); } this.resourcePool.clear(); @@ -882,8 +1072,7 @@ org.eclipse.swt.graphics.Font swtFont = (org.eclipse.swt.graphics.Font) this.fontsPool.get(font); if (swtFont == null) { - swtFont = new org.eclipse.swt.graphics.Font( - this.gc.getDevice(), + swtFont = new org.eclipse.swt.graphics.Font(this.gc.getDevice(), SWTUtils.toSwtFontData(this.gc.getDevice(), font, true)); addToResourcePool(swtFont); this.fontsPool.put(font, swtFont); @@ -934,7 +1123,7 @@ /** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * - * @param shape the shape. + * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ @@ -1054,16 +1243,4 @@ } return null; } - - /** - * Add given swt resource to the resource pool. All resources added - * to the resource pool will be dispose when {@link #dispose()} is called - * - * @param resource the resource to add to the pool. - * @return the swt <code>Resource</code> just added. - */ - private Resource addToResourcePool(Resource resource) { - this.resourcePool.add(resource); - return resource; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-24 16:35:42
|
Revision: 422 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=422&view=rev Author: mungady Date: 2007-10-24 09:35:41 -0700 (Wed, 24 Oct 2007) Log Message: ----------- Moved experimental DialPlot to main. Added Paths: ----------- trunk/source/org/jfree/chart/plot/dial/ trunk/source/org/jfree/chart/plot/dial/AbstractDialLayer.java trunk/source/org/jfree/chart/plot/dial/ArcDialFrame.java trunk/source/org/jfree/chart/plot/dial/DialBackground.java trunk/source/org/jfree/chart/plot/dial/DialCap.java trunk/source/org/jfree/chart/plot/dial/DialFrame.java trunk/source/org/jfree/chart/plot/dial/DialLayer.java trunk/source/org/jfree/chart/plot/dial/DialLayerChangeEvent.java trunk/source/org/jfree/chart/plot/dial/DialLayerChangeListener.java trunk/source/org/jfree/chart/plot/dial/DialPlot.java trunk/source/org/jfree/chart/plot/dial/DialPointer.java trunk/source/org/jfree/chart/plot/dial/DialScale.java trunk/source/org/jfree/chart/plot/dial/DialTextAnnotation.java trunk/source/org/jfree/chart/plot/dial/DialValueIndicator.java trunk/source/org/jfree/chart/plot/dial/SimpleDialFrame.java trunk/source/org/jfree/chart/plot/dial/StandardDialRange.java trunk/source/org/jfree/chart/plot/dial/StandardDialScale.java trunk/tests/org/jfree/chart/plot/dial/junit/ trunk/tests/org/jfree/chart/plot/dial/junit/AbstractDialLayerTests.java trunk/tests/org/jfree/chart/plot/dial/junit/ArcDialFrameTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialBackgroundTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialCapTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialPackageTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialPlotTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialPointerTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialTextAnnotationTests.java trunk/tests/org/jfree/chart/plot/dial/junit/DialValueIndicatorTests.java trunk/tests/org/jfree/chart/plot/dial/junit/MyDialLayerChangeListener.java trunk/tests/org/jfree/chart/plot/dial/junit/SimpleDialFrameTests.java trunk/tests/org/jfree/chart/plot/dial/junit/StandardDialRangeTests.java trunk/tests/org/jfree/chart/plot/dial/junit/StandardDialScaleTests.java Removed Paths: ------------- trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java trunk/experimental/org/jfree/experimental/chart/plot/dial/ArcDialFrame.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPlot.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialPointer.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialScale.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialTextAnnotation.java trunk/experimental/org/jfree/experimental/chart/plot/dial/DialValueIndicator.java trunk/experimental/org/jfree/experimental/chart/plot/dial/SimpleDialFrame.java trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialRange.java trunk/experimental/org/jfree/experimental/chart/plot/dial/StandardDialScale.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/AbstractDialLayerTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/ArcDialFrameTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialBackgroundTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialCapTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialPackageTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialPlotTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialPointerTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialTextAnnotationTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/DialValueIndicatorTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/MyDialLayerChangeListener.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/SimpleDialFrameTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/StandardDialRangeTests.java trunk/experimental/org/jfree/experimental/chart/plot/dial/junit/StandardDialScaleTests.java Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/AbstractDialLayer.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,195 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ---------------------- - * AbstractDialLayer.java - * ---------------------- - * (C) Copyright 2006-2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 06-Nov-2006 : Version 1 (DG); - * 17-Nov-2006 : Added visible flag (DG); - * 16-Oct-2007 : Implemented equals() and clone() (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.util.Arrays; -import java.util.EventListener; -import java.util.List; - -import javax.swing.event.EventListenerList; - -/** - * A base class that can be used to implement a {@link DialLayer}. It includes - * an event notification mechanism. - */ -public abstract class AbstractDialLayer implements DialLayer { - - /** A flag that controls whether or not the layer is visible. */ - private boolean visible; - - /** Storage for registered listeners. */ - private transient EventListenerList listenerList; - - /** - * Creates a new instance. - */ - protected AbstractDialLayer() { - this.visible = true; - this.listenerList = new EventListenerList(); - } - - /** - * Returns <code>true</code> if this layer is visible (should be displayed), - * and <code>false</code> otherwise. - * - * @return A boolean. - * - * @see #setVisible(boolean) - */ - public boolean isVisible() { - return this.visible; - } - - /** - * Sets the flag that determines whether or not this layer is drawn by - * the plot, and sends a {@link DialLayerChangeEvent} to all registered - * listeners. - * - * @param visible the flag. - * - * @see #isVisible() - */ - public void setVisible(boolean visible) { - this.visible = visible; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Tests this instance for equality with an arbitrary object. - * - * @param obj the object (<code>null</code> permitted). - * - * @return A boolean. - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof AbstractDialLayer)) { - return false; - } - AbstractDialLayer that = (AbstractDialLayer) obj; - return this.visible == that.visible; - } - - /** - * Returns a clone of this instance. - * - * @return A clone. - * - * @throws CloneNotSupportedException if there is a problem cloning this - * instance. - */ - public Object clone() throws CloneNotSupportedException { - AbstractDialLayer clone = (AbstractDialLayer) super.clone(); - // we don't clone the listeners - clone.listenerList = new EventListenerList(); - return clone; - } - - /** - * Registers an object for notification of changes to the dial layer. - * - * @param listener the object that is being registered. - * - * @see #removeChangeListener(DialLayerChangeListener) - */ - public void addChangeListener(DialLayerChangeListener listener) { - this.listenerList.add(DialLayerChangeListener.class, listener); - } - - /** - * Deregisters an object for notification of changes to the dial layer. - * - * @param listener the object to deregister. - * - * @see #addChangeListener(DialLayerChangeListener) - */ - public void removeChangeListener(DialLayerChangeListener listener) { - this.listenerList.remove(DialLayerChangeListener.class, listener); - } - - /** - * Returns <code>true</code> if the specified object is registered with - * the dataset as a listener. Most applications won't need to call this - * method, it exists mainly for use by unit testing code. - * - * @param listener the listener. - * - * @return A boolean. - */ - public boolean hasListener(EventListener listener) { - List list = Arrays.asList(this.listenerList.getListenerList()); - return list.contains(listener); - } - - /** - * Notifies all registered listeners that the dial layer has changed. - * The {@link DialLayerChangeEvent} provides information about the change. - * - * @param event information about the change to the axis. - */ - protected void notifyListeners(DialLayerChangeEvent event) { - Object[] listeners = this.listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == DialLayerChangeListener.class) { - ((DialLayerChangeListener) listeners[i + 1]).dialLayerChanged( - event); - } - } - } - - /** - * Provides serialization support. - * - * @param stream the input stream. - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - this.listenerList = new EventListenerList(); - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/ArcDialFrame.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/ArcDialFrame.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/ArcDialFrame.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,516 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ---------------------- - * ArcDialFrame.java - * ---------------------- - * (C) Copyright 2006, 2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 03-Nov-2006 : Version 1 (DG); - * 08-Mar-2007 : Fix in hashCode() (DG); - * 21-Jun-2007 : Removed JCommon dependencies (DG); - * 17-Oct-2007 : Updated equals() (DG); - * 24-Oct-2007 : Added argument checks and API docs (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Paint; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.geom.Arc2D; -import java.awt.geom.Area; -import java.awt.geom.GeneralPath; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import org.jfree.chart.HashUtilities; -import org.jfree.chart.util.PaintUtilities; -import org.jfree.chart.util.PublicCloneable; -import org.jfree.chart.util.SerialUtilities; - -/** - * A standard frame for the {@link DialPlot} class. - */ -public class ArcDialFrame extends AbstractDialLayer implements DialFrame, - Cloneable, PublicCloneable, Serializable { - - /** - * The color used for the front of the panel. This field is transient - * because it requires special handling for serialization. - */ - private transient Paint backgroundPaint; - - /** - * The color used for the border around the window. This field is transient - * because it requires special handling for serialization. - */ - private transient Paint foregroundPaint; - - /** - * The stroke for drawing the frame outline. This field is transient - * because it requires special handling for serialization. - */ - private transient Stroke stroke; - - /** - * The start angle. - */ - private double startAngle; - - /** - * The end angle. - */ - private double extent; - - /** The inner radius, relative to the framing rectangle. */ - private double innerRadius; - - /** The outer radius, relative to the framing rectangle. */ - private double outerRadius; - - /** - * Creates a new instance of <code>ArcDialFrame</code> that spans - * 180 degrees. - */ - public ArcDialFrame() { - this(0, 180); - } - - /** - * Creates a new instance of <code>ArcDialFrame</code> that spans - * the arc specified. - * - * @param startAngle the startAngle (in degrees). - * @param extent the extent of the arc (in degrees, counter-clockwise). - */ - public ArcDialFrame(double startAngle, double extent) { - this.backgroundPaint = Color.gray; - this.foregroundPaint = new Color(100, 100, 150); - this.stroke = new BasicStroke(2.0f); - this.innerRadius = 0.25; - this.outerRadius = 0.75; - this.startAngle = startAngle; - this.extent = extent; - } - - /** - * Returns the background paint (never <code>null</code>). - * - * @return The background paint. - * - * @see #setBackgroundPaint(Paint) - */ - public Paint getBackgroundPaint() { - return this.backgroundPaint; - } - - /** - * Sets the background paint and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param paint the paint (<code>null</code> not permitted). - * - * @see #getBackgroundPaint() - */ - public void setBackgroundPaint(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } - this.backgroundPaint = paint; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the foreground paint. - * - * @return The foreground paint (never <code>null</code>). - * - * @see #setForegroundPaint(Paint) - */ - public Paint getForegroundPaint() { - return this.foregroundPaint; - } - - /** - * Sets the foreground paint and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param paint the paint (<code>null</code> not permitted). - * - * @see #getForegroundPaint() - */ - public void setForegroundPaint(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } - this.foregroundPaint = paint; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the stroke. - * - * @return The stroke (never <code>null</code>). - * - * @see #setStroke(Stroke) - */ - public Stroke getStroke() { - return this.stroke; - } - - /** - * Sets the stroke and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param stroke the stroke (<code>null</code> not permitted). - * - * @see #getStroke() - */ - public void setStroke(Stroke stroke) { - if (stroke == null) { - throw new IllegalArgumentException("Null 'stroke' argument."); - } - this.stroke = stroke; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the inner radius, relative to the framing rectangle. - * - * @return The inner radius. - * - * @see #setInnerRadius(double) - */ - public double getInnerRadius() { - return this.innerRadius; - } - - /** - * Sets the inner radius and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param radius the inner radius. - * - * @see #getInnerRadius() - */ - public void setInnerRadius(double radius) { - if (radius < 0.0) { - throw new IllegalArgumentException("Negative 'radius' argument."); - } - this.innerRadius = radius; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the outer radius, relative to the framing rectangle. - * - * @return The outer radius. - * - * @see #setOuterRadius(double) - */ - public double getOuterRadius() { - return this.outerRadius; - } - - /** - * Sets the outer radius and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param radius the outer radius. - * - * @see #getOuterRadius() - */ - public void setOuterRadius(double radius) { - if (radius < 0.0) { - throw new IllegalArgumentException("Negative 'radius' argument."); - } - this.outerRadius = radius; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the start angle. - * - * @return The start angle. - * - * @see #setStartAngle(double) - */ - public double getStartAngle() { - return this.startAngle; - } - - /** - * Sets the start angle and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param angle the angle. - * - * @see #getStartAngle() - */ - public void setStartAngle(double angle) { - this.startAngle = angle; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the extent. - * - * @return The extent. - * - * @see #setExtent(double) - */ - public double getExtent() { - return this.extent; - } - - /** - * Sets the extent and sends a {@link DialLayerChangeEvent} to - * all registered listeners. - * - * @param extent the extent. - * - * @see #getExtent() - */ - public void setExtent(double extent) { - this.extent = extent; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the shape for the window for this dial. Some dial layers will - * request that their drawing be clipped within this window. - * - * @param frame the reference frame (<code>null</code> not permitted). - * - * @return The shape of the dial's window. - */ - public Shape getWindow(Rectangle2D frame) { - - Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, - this.innerRadius, this.innerRadius); - Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, - this.outerRadius, this.outerRadius); - Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, - Arc2D.OPEN); - Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle - + this.extent, - this.extent, Arc2D.OPEN); - GeneralPath p = new GeneralPath(); - Point2D point1 = inner.getStartPoint(); - p.moveTo((float) point1.getX(), (float) point1.getY()); - p.append(inner, true); - p.append(outer, true); - p.closePath(); - return p; - - } - - /** - * Returns the outer window. - * - * @param frame the frame. - * - * @return The outer window. - */ - protected Shape getOuterWindow(Rectangle2D frame) { - double radiusMargin = 0.02; - double angleMargin = 1.5; - Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, - this.innerRadius - radiusMargin, this.innerRadius - - radiusMargin); - Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, - this.outerRadius + radiusMargin, this.outerRadius - + radiusMargin); - Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle - - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN); - Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle - + angleMargin + this.extent, - this.extent - 2 * angleMargin, - Arc2D.OPEN); - GeneralPath p = new GeneralPath(); - Point2D point1 = inner.getStartPoint(); - p.moveTo((float) point1.getX(), (float) point1.getY()); - p.append(inner, true); - p.append(outer, true); - p.closePath(); - return p; - } - - /** - * Draws the frame. - * - * @param g2 the graphics target. - * @param plot the plot. - * @param frame the dial's reference frame. - * @param view the dial's view rectangle. - */ - public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, - Rectangle2D view) { - - Shape window = getWindow(frame); - Shape outerWindow = getOuterWindow(frame); - - Area area1 = new Area(outerWindow); - Area area2 = new Area(window); - area1.subtract(area2); - g2.setPaint(Color.lightGray); - g2.fill(area1); - - g2.setStroke(this.stroke); - g2.setPaint(this.foregroundPaint); - g2.draw(window); - g2.draw(outerWindow); - - - } - - /** - * Returns <code>false</code> to indicate that this dial layer is not - * clipped to the dial window. - * - * @return <code>false</code>. - */ - public boolean isClippedToWindow() { - return false; - } - - /** - * Tests this instance for equality with an arbitrary object. - * - * @param obj the object (<code>null</code> permitted). - * - * @return A boolean. - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ArcDialFrame)) { - return false; - } - ArcDialFrame that = (ArcDialFrame) obj; - if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { - return false; - } - if (!PaintUtilities.equal(this.foregroundPaint, that.foregroundPaint)) { - return false; - } - if (this.startAngle != that.startAngle) { - return false; - } - if (this.extent != that.extent) { - return false; - } - if (this.innerRadius != that.innerRadius) { - return false; - } - if (this.outerRadius != that.outerRadius) { - return false; - } - if (!this.stroke.equals(that.stroke)) { - return false; - } - return super.equals(obj); - } - - /** - * Returns a hash code for this instance. - * - * @return The hash code. - */ - public int hashCode() { - int result = 193; - long temp = Double.doubleToLongBits(this.startAngle); - result = 37 * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(this.extent); - result = 37 * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(this.innerRadius); - result = 37 * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(this.outerRadius); - result = 37 * result + (int) (temp ^ (temp >>> 32)); - result = 37 * result + HashUtilities.hashCodeForPaint( - this.backgroundPaint); - result = 37 * result + HashUtilities.hashCodeForPaint( - this.foregroundPaint); - result = 37 * result + this.stroke.hashCode(); - return result; - } - - /** - * Returns a clone of this instance. - * - * @return A clone. - * - * @throws CloneNotSupportedException if any attribute of this instance - * cannot be cloned. - */ - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - /** - * Provides serialization support. - * - * @param stream the output stream. - * - * @throws IOException if there is an I/O error. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - SerialUtilities.writePaint(this.backgroundPaint, stream); - SerialUtilities.writePaint(this.foregroundPaint, stream); - SerialUtilities.writeStroke(this.stroke, stream); - } - - /** - * Provides serialization support. - * - * @param stream the input stream. - * - * @throws IOException if there is an I/O error. - * @throws ClassNotFoundException if there is a classpath problem. - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - this.backgroundPaint = SerialUtilities.readPaint(stream); - this.foregroundPaint = SerialUtilities.readPaint(stream); - this.stroke = SerialUtilities.readStroke(stream); - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialBackground.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,266 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ------------------- - * DialBackground.java - * ------------------- - * (C) Copyright 2006, 2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 03-Nov-2006 : Version 1 (DG); - * 20-Jun-2007 : Removed JCommon dependencies (DG); - * 16-Oct-2007 : The equals() method needs to call super.equals() (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import java.awt.Color; -import java.awt.GradientPaint; -import java.awt.Graphics2D; -import java.awt.Paint; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import org.jfree.chart.HashUtilities; -import org.jfree.chart.util.GradientPaintTransformer; -import org.jfree.chart.util.PaintUtilities; -import org.jfree.chart.util.PublicCloneable; -import org.jfree.chart.util.SerialUtilities; -import org.jfree.chart.util.StandardGradientPaintTransformer; - -/** - * A regular dial layer that can be used to draw the background for a dial. - */ -public class DialBackground extends AbstractDialLayer implements DialLayer, - Cloneable, PublicCloneable, Serializable { - - /** - * The background paint. This field is transient because serialization - * requires special handling. - */ - private transient Paint paint; - - /** - * The transformer used when the background paint is an instance of - * <code>GradientPaint</code>. - */ - private GradientPaintTransformer gradientPaintTransformer; - - /** - * Creates a new instance of <code>DialBackground</code>. The - * default background paint is <code>Color.white</code>. - */ - public DialBackground() { - this(Color.white); - } - - /** - * Creates a new instance of <code>DialBackground</code>. The - * - * @param paint the paint (<code>null</code> not permitted). - * - * @throws IllegalArgumentException if <code>paint</code> is - * <code>null</code>. - */ - public DialBackground(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } - this.paint = paint; - this.gradientPaintTransformer = new StandardGradientPaintTransformer(); - } - - /** - * Returns the paint used to fill the background. - * - * @return The paint (never <code>null</code>). - * - * @see #setPaint(Paint) - */ - public Paint getPaint() { - return this.paint; - } - - /** - * Sets the paint for the dial background and sends a - * {@link DialLayerChangeEvent} to all registered listeners. - * - * @param paint the paint (<code>null</code> not permitted). - * - * @see #getPaint() - */ - public void setPaint(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } - this.paint = paint; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the transformer used to adjust the coordinates of any - * <code>GradientPaint</code> instance used for the background paint. - * - * @return The transformer (never <code>null</code>). - * - * @see #setGradientPaintTransformer(GradientPaintTransformer) - */ - public GradientPaintTransformer getGradientPaintTransformer() { - return this.gradientPaintTransformer; - } - - /** - * Sets the transformer used to adjust the coordinates of any - * <code>GradientPaint</code> instance used for the background paint, and - * sends a {@link DialLayerChangeEvent} to all registered listeners. - * - * @param t the transformer (<code>null</code> not permitted). - * - * @see #getGradientPaintTransformer() - */ - public void setGradientPaintTransformer(GradientPaintTransformer t) { - if (t == null) { - throw new IllegalArgumentException("Null 't' argument."); - } - this.gradientPaintTransformer = t; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns <code>true</code> to indicate that this layer should be - * clipped within the dial window. - * - * @return <code>true</code>. - */ - public boolean isClippedToWindow() { - return true; - } - - /** - * Draws the background to the specified graphics device. If the dial - * frame specifies a window, the clipping region will already have been - * set to this window before this method is called. - * - * @param g2 the graphics device (<code>null</code> not permitted). - * @param plot the plot (ignored here). - * @param frame the dial frame (ignored here). - * @param view the view rectangle (<code>null</code> not permitted). - */ - public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, - Rectangle2D view) { - - Paint p = this.paint; - if (p instanceof GradientPaint) { - p = this.gradientPaintTransformer.transform((GradientPaint) p, view); - } - g2.setPaint(p); - g2.fill(view); - } - - /** - * Tests this instance for equality with an arbitrary object. - * - * @param obj the object (<code>null</code> permitted). - * - * @return A boolean. - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof DialBackground)) { - return false; - } - DialBackground that = (DialBackground) obj; - if (!PaintUtilities.equal(this.paint, that.paint)) { - return false; - } - if (!this.gradientPaintTransformer.equals( - that.gradientPaintTransformer)) { - return false; - } - return super.equals(obj); - } - - /** - * Returns a hash code for this instance. - * - * @return The hash code. - */ - public int hashCode() { - int result = 193; - result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); - result = 37 * result + this.gradientPaintTransformer.hashCode(); - return result; - } - - /** - * Returns a clone of this instance. - * - * @return The clone. - * - * @throws CloneNotSupportedException if some attribute of this instance - * cannot be cloned. - */ - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - /** - * Provides serialization support. - * - * @param stream the output stream. - * - * @throws IOException if there is an I/O error. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - SerialUtilities.writePaint(this.paint, stream); - } - - /** - * Provides serialization support. - * - * @param stream the input stream. - * - * @throws IOException if there is an I/O error. - * @throws ClassNotFoundException if there is a classpath problem. - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - this.paint = SerialUtilities.readPaint(stream); - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialCap.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,338 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ------------ - * DialCap.java - * ------------ - * (C) Copyright 2006, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 03-Nov-2006 : Version 1 (DG); - * 21-Jun-2007 : Removed JCommon dependencies (DG); - * 17-Oct-2007 : Updated equals() method (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Paint; -import java.awt.Stroke; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import org.jfree.chart.HashUtilities; -import org.jfree.chart.util.PaintUtilities; -import org.jfree.chart.util.PublicCloneable; -import org.jfree.chart.util.SerialUtilities; - -/** - * A regular dial layer that can be used to draw a cap over the center of - * the dial (the base of the dial pointer(s)). - */ -public class DialCap extends AbstractDialLayer implements DialLayer, Cloneable, - PublicCloneable, Serializable { - - /** - * The radius of the cap, as a percentage of the framing rectangle. - */ - private double radius; - - /** - * The fill paint. This field is transient because it requires special - * handling for serialization. - */ - private transient Paint fillPaint; - - /** - * The paint used to draw the cap outline (this should never be - * <code>null</code>). This field is transient because it requires - * special handling for serialization. - */ - private transient Paint outlinePaint; - - /** - * The stroke used to draw the cap outline (this should never be - * <code>null</code>). This field is transient because it requires - * special handling for serialization. - */ - private transient Stroke outlineStroke; - - /** - * Creates a new instance of <code>StandardDialBackground</code>. The - * default background paint is <code>Color.white</code>. - */ - public DialCap() { - this.radius = 0.05; - this.fillPaint = Color.white; - this.outlinePaint = Color.black; - this.outlineStroke = new BasicStroke(2.0f); - } - - /** - * Returns the radius of the cap, as a percentage of the dial's framing - * rectangle. - * - * @return The radius. - * - * @see #setRadius(double) - */ - public double getRadius() { - return this.radius; - } - - /** - * Sets the radius of the cap, as a percentage of the dial's framing - * rectangle, and sends a {@link DialLayerChangeEvent} to all registered - * listeners. - * - * @param radius the radius (must be greater than zero). - * - * @see #getRadius() - */ - public void setRadius(double radius) { - if (radius <= 0.0) { - throw new IllegalArgumentException("Requires radius > 0.0."); - } - this.radius = radius; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the paint used to fill the cap. - * - * @return The paint (never <code>null</code>). - * - * @see #setFillPaint(Paint) - */ - public Paint getFillPaint() { - return this.fillPaint; - } - - /** - * Sets the paint for the cap background and sends a - * {@link DialLayerChangeEvent} to all registered listeners. - * - * @param paint the paint (<code>null</code> not permitted). - * - * @see #getFillPaint() - */ - public void setFillPaint(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } - this.fillPaint = paint; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the paint used to draw the outline of the cap. - * - * @return The paint (never <code>null</code>). - * - * @see #setOutlinePaint(Paint) - */ - public Paint getOutlinePaint() { - return this.outlinePaint; - } - - /** - * Sets the paint used to draw the outline of the cap and sends a - * {@link DialLayerChangeEvent} to all registered listeners. - * - * @param paint the paint (<code>null</code> not permitted). - * - * @see #getOutlinePaint() - */ - public void setOutlinePaint(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } - this.outlinePaint = paint; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns the stroke used to draw the outline of the cap. - * - * @return The stroke (never <code>null</code>). - * - * @see #setOutlineStroke(Stroke) - */ - public Stroke getOutlineStroke() { - return this.outlineStroke; - } - - /** - * Sets the stroke used to draw the outline of the cap and sends a - * {@link DialLayerChangeEvent} to all registered listeners. - * - * @param stroke the stroke (<code>null</code> not permitted). - * - * @see #getOutlineStroke() - */ - public void setOutlineStroke(Stroke stroke) { - if (stroke == null) { - throw new IllegalArgumentException("Null 'stroke' argument."); - } - this.outlineStroke = stroke; - notifyListeners(new DialLayerChangeEvent(this)); - } - - /** - * Returns <code>true</code> to indicate that this layer should be - * clipped within the dial window. - * - * @return <code>true</code>. - */ - public boolean isClippedToWindow() { - return true; - } - - /** - * Draws the background to the specified graphics device. If the dial - * frame specifies a window, the clipping region will already have been - * set to this window before this method is called. - * - * @param g2 the graphics device (<code>null</code> not permitted). - * @param plot the plot (ignored here). - * @param frame the dial frame (ignored here). - * @param view the view rectangle (<code>null</code> not permitted). - */ - public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, - Rectangle2D view) { - - g2.setPaint(this.fillPaint); - - Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, - this.radius); - Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), - f.getHeight()); - g2.fill(e); - g2.setPaint(this.outlinePaint); - g2.setStroke(this.outlineStroke); - g2.draw(e); - - } - - /** - * Tests this instance for equality with an arbitrary object. - * - * @param obj the object (<code>null</code> permitted). - * - * @return A boolean. - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof DialCap)) { - return false; - } - DialCap that = (DialCap) obj; - if (this.radius != that.radius) { - return false; - } - if (!PaintUtilities.equal(this.fillPaint, that.fillPaint)) { - return false; - } - if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { - return false; - } - if (!this.outlineStroke.equals(that.outlineStroke)) { - return false; - } - return super.equals(obj); - } - - /** - * Returns a hash code for this instance. - * - * @return The hash code. - */ - public int hashCode() { - int result = 193; - result = 37 * result + HashUtilities.hashCodeForPaint(this.fillPaint); - result = 37 * result + HashUtilities.hashCodeForPaint( - this.outlinePaint); - result = 37 * result + this.outlineStroke.hashCode(); - return result; - } - - /** - * Returns a clone of this instance. - * - * @return A clone. - * - * @throws CloneNotSupportedException if some attribute of the cap cannot - * be cloned. - */ - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - /** - * Provides serialization support. - * - * @param stream the output stream. - * - * @throws IOException if there is an I/O error. - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - SerialUtilities.writePaint(this.fillPaint, stream); - SerialUtilities.writePaint(this.outlinePaint, stream); - SerialUtilities.writeStroke(this.outlineStroke, stream); - } - - /** - * Provides serialization support. - * - * @param stream the input stream. - * - * @throws IOException if there is an I/O error. - * @throws ClassNotFoundException if there is a classpath problem. - */ - private void readObject(ObjectInputStream stream) - throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - this.fillPaint = SerialUtilities.readPaint(stream); - this.outlinePaint = SerialUtilities.readPaint(stream); - this.outlineStroke = SerialUtilities.readStroke(stream); - } - -} - Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialFrame.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,68 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * -------------- - * DialFrame.java - * -------------- - * (C) Copyright 2006-2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 03-Nov-2006 : Version 1 (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import java.awt.Shape; -import java.awt.geom.Rectangle2D; -import java.io.Serializable; - -/** - * A dial frame is the face plate for a dial plot - it is always drawn last. - * JFreeChart includes a couple of implementations of this interface - * ({@link SimpleDialFrame} and {@link ArcDialFrame}). - * <br><br> - * Classes that implement this interface should be {@link Serializable}, - * otherwise chart serialization may fail. - */ -public interface DialFrame extends DialLayer { - - /** - * Returns the shape of the viewing window for the dial, or - * <code>null</code> if the dial is completely open. Other layers in the - * plot will rely on their drawing to be clipped within this window. - * - * @param frame the reference frame for the dial. - * - * @return The window. - */ - public Shape getWindow(Rectangle2D frame); - -} Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayer.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,116 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * -------------- - * DialLayer.java - * -------------- - * (C) Copyright 2006-2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 03-Nov-2006 : Version 1 (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; -import java.io.Serializable; -import java.util.EventListener; - -/** - * A dial layer draws itself within a reference frame. The view frame is a - * subset of the reference frame, and defines the area that is actually - * visible. - * <br><br> - * Classes that implement this interface should be {@link Serializable}, - * otherwise chart serialization may fail. - */ -public interface DialLayer { - - /** - * Returns a flag that indicates whether or not the layer is visible. - * - * @return A boolean. - */ - public boolean isVisible(); - - /** - * Registers a listener with this layer, so that it receives notification - * of changes to this layer. - * - * @param listener the listener. - */ - public void addChangeListener(DialLayerChangeListener listener); - - /** - * Deregisters a listener, so that it no longer receives notification of - * changes to this layer. - * - * @param listener the listener. - */ - public void removeChangeListener(DialLayerChangeListener listener); - - /** - * Returns <code>true</code> if the specified listener is currently - * registered with the this layer. - * - * @param listener the listener. - * - * @return A boolean. - */ - public boolean hasListener(EventListener listener); - - /** - * Returns <code>true</code> if the drawing should be clipped to the - * dial window (which is defined by the {@link DialFrame}), and - * <code>false</code> otherwise. - * - * @return A boolean. - */ - public boolean isClippedToWindow(); - - /** - * Draws the content of this layer. - * - * @param g2 the graphics target (<code>null</code> not permitted). - * @param plot the plot (typically this should not be <code>null</code>, - * but for a layer that doesn't need to reference the plot, it may - * be permitted). - * @param frame the reference frame for the dial's geometry - * (<code>null</code> not permitted). This is typically larger than - * the visible area of the dial (see the next parameter). - * @param view the visible area for the dial (<code>null</code> not - * permitted). - */ - public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, - Rectangle2D view); - -} Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeEvent.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,73 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ------------------------- - * DialLayerChangeEvent.java - * ------------------------- - * (C) Copyright 2006-2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 06-Nov-2006 : Version 1 (DG); - * - */ - -package org.jfree.experimental.chart.plot.dial; - -import org.jfree.chart.event.ChartChangeEvent; - -/** - * An event that can be forwarded to any {@link DialLayerChangeListener} to - * signal a change to a {@link DialLayer}. - */ -public class DialLayerChangeEvent extends ChartChangeEvent { - - /** The dial layer that generated the event. */ - private DialLayer layer; - - /** - * Creates a new instance. - * - * @param layer the dial layer that generated the event. - */ - public DialLayerChangeEvent(DialLayer layer) { - super(layer); - this.layer = layer; - } - - /** - * Returns the layer that generated the event. - * - * @return The layer that generated the event. - */ - public DialLayer getDialLayer() { - return this.layer; - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java 2007-10-24 16:34:49 UTC (rev 421) +++ trunk/experimental/org/jfree/experimental/chart/plot/dial/DialLayerChangeListener.java 2007-10-24 16:35:41 UTC (rev 422) @@ -1,60 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ---------------------------- - * DialLayerChangeListener.java - * ---------------------------- - * (C) Copyright 2006-2007, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Obj... [truncated message content] |
From: <mu...@us...> - 2007-10-25 11:03:42
|
Revision: 426 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=426&view=rev Author: mungady Date: 2007-10-25 04:03:39 -0700 (Thu, 25 Oct 2007) Log Message: ----------- 2007-10-25 David Gilbert <dav...@ob...> * source/org/jfree/chart/axis/StandardTickUnitSource.java: Implemented Serializable, (StandardTickUnitSource): Added explicit constructor, (equals): New method override, (hashCode): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/axis/StandardTickUnitSource.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-25 10:51:13 UTC (rev 425) +++ trunk/ChangeLog 2007-10-25 11:03:39 UTC (rev 426) @@ -1,5 +1,13 @@ 2007-10-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/StandardTickUnitSource.java: + Implemented Serializable, + (StandardTickUnitSource): Added explicit constructor, + (equals): New method override, + (hashCode): Likewise. + +2007-10-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/ChartPanel.java (defaultDirectoryForSaveAs): New field, (ChartPanel(JFreeChart, int, int, int, int, int, int, boolean, boolean, Modified: trunk/source/org/jfree/chart/axis/StandardTickUnitSource.java =================================================================== --- trunk/source/org/jfree/chart/axis/StandardTickUnitSource.java 2007-10-25 10:51:13 UTC (rev 425) +++ trunk/source/org/jfree/chart/axis/StandardTickUnitSource.java 2007-10-25 11:03:39 UTC (rev 426) @@ -35,23 +35,34 @@ * Changes * ------- * 23-Sep-2003 : Version 1 (DG); + * 25-Oct-2007 : Implemented Serializable and equals() method (DG); * */ package org.jfree.chart.axis; +import java.io.Serializable; import java.text.DecimalFormat; /** * A source that can used by the {@link NumberAxis} class to obtain a - * suitable {@link TickUnit}. + * suitable {@link TickUnit}. Instances of this class are {@link Serializable} + * from version 1.0.7 onwards. Cloning is not supported, because instances + * are immutable. */ -public class StandardTickUnitSource implements TickUnitSource { +public class StandardTickUnitSource implements TickUnitSource, Serializable { /** Constant for log(10.0). */ private static final double LOG_10_VALUE = Math.log(10.0); /** + * Default constructor. + */ + public StandardTickUnitSource() { + super(); + } + + /** * Returns a tick unit that is larger than the supplied unit. * * @param unit the unit (<code>null</code> not permitted). @@ -93,4 +104,27 @@ new DecimalFormat("0.0E0")); } + /** + * Tests this instance for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + return (obj instanceof StandardTickUnitSource); + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + return 0; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-10-25 12:56:30
|
Revision: 434 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=434&view=rev Author: mungady Date: 2007-10-25 05:56:24 -0700 (Thu, 25 Oct 2007) Log Message: ----------- 2007-10-25 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/CategoryPlot.java (getDomainAxisIndex): Added argument check, (getRangeAxisIndex): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/plot/CategoryPlot.java trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-25 12:49:14 UTC (rev 433) +++ trunk/ChangeLog 2007-10-25 12:56:24 UTC (rev 434) @@ -1,5 +1,11 @@ 2007-10-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/CategoryPlot.java + (getDomainAxisIndex): Added argument check, + (getRangeAxisIndex): Likewise. + +2007-10-25 David Gilbert <dav...@ob...> + * source/org/jfree/chart/axis/StandardTickUnitSource.java: Implemented Serializable, (StandardTickUnitSource): Added explicit constructor, Modified: trunk/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/CategoryPlot.java 2007-10-25 12:49:14 UTC (rev 433) +++ trunk/source/org/jfree/chart/plot/CategoryPlot.java 2007-10-25 12:56:24 UTC (rev 434) @@ -150,7 +150,8 @@ * 06-Jul-2007 : Updated annotation handling (DG); * 10-Jul-2007 : Added getRangeAxisIndex(ValueAxis) method (DG); * 24-Sep-2007 : Implemented new zoom methods (DG); - * + * 25-Oct-2007 : Added some argument checks (DG); + * */ package org.jfree.chart.plot; @@ -684,13 +685,19 @@ * Returns the index of the specified axis, or <code>-1</code> if the axis * is not assigned to the plot. * - * @param axis the axis. + * @param axis the axis (<code>null</code> not permitted). * * @return The axis index. * + * @see #getDomainAxis(int) + * @see #getRangeAxisIndex(ValueAxis) + * * @since 1.0.3 */ public int getDomainAxisIndex(CategoryAxis axis) { + if (axis == null) { + throw new IllegalArgumentException("Null 'axis' argument."); + } return this.domainAxes.indexOf(axis); } @@ -951,19 +958,24 @@ notifyListeners(new PlotChangeEvent(this)); } + /** * Returns the index of the specified axis, or <code>-1</code> if the axis * is not assigned to the plot. * - * @param axis the axis. + * @param axis the axis (<code>null</code> not permitted). * * @return The axis index. * + * @see #getRangeAxis(int) * @see #getDomainAxisIndex(CategoryAxis) * * @since 1.0.7 */ public int getRangeAxisIndex(ValueAxis axis) { + if (axis == null) { + throw new IllegalArgumentException("Null 'axis' argument."); + } int result = this.rangeAxes.indexOf(axis); if (result < 0) { // try the parent plot Plot parent = getParent(); Modified: trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java 2007-10-25 12:49:14 UTC (rev 433) +++ trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java 2007-10-25 12:56:24 UTC (rev 434) @@ -113,6 +113,14 @@ public CategoryPlotTests(String name) { super(name); } + + /** + * Some checks for the constructor. + */ + public void testConstructor() { + CategoryPlot plot = new CategoryPlot(); + assertEquals(RectangleInsets.ZERO_INSETS, plot.getAxisOffset()); + } /** * A test for a bug reported in the forum. @@ -702,5 +710,52 @@ } assertTrue(success); } + + /** + * Some checks for the getDomainAxisIndex() method. + */ + public void testGetDomainAxisIndex() { + CategoryAxis domainAxis1 = new CategoryAxis("X1"); + CategoryAxis domainAxis2 = new CategoryAxis("X2"); + NumberAxis rangeAxis1 = new NumberAxis("Y1"); + CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1, + null); + assertEquals(0, plot.getDomainAxisIndex(domainAxis1)); + assertEquals(-1, plot.getDomainAxisIndex(domainAxis2)); + plot.setDomainAxis(1, domainAxis2); + assertEquals(1, plot.getDomainAxisIndex(domainAxis2)); + assertEquals(-1, plot.getDomainAxisIndex(new CategoryAxis("X2"))); + boolean pass = false; + try { + plot.getDomainAxisIndex(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + /** + * Some checks for the getRangeAxisIndex() method. + */ + public void testGetRangeAxisIndex() { + CategoryAxis domainAxis1 = new CategoryAxis("X1"); + NumberAxis rangeAxis1 = new NumberAxis("Y1"); + NumberAxis rangeAxis2 = new NumberAxis("Y2"); + CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1, + null); + assertEquals(0, plot.getRangeAxisIndex(rangeAxis1)); + assertEquals(-1, plot.getRangeAxisIndex(rangeAxis2)); + plot.setRangeAxis(1, rangeAxis2); + assertEquals(1, plot.getRangeAxisIndex(rangeAxis2)); + assertEquals(-1, plot.getRangeAxisIndex(new NumberAxis("Y2"))); + boolean pass = false; + try { + plot.getRangeAxisIndex(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-11-05 14:38:06
|
Revision: 463 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=463&view=rev Author: mungady Date: 2007-11-05 06:21:51 -0800 (Mon, 05 Nov 2007) Log Message: ----------- 2007-11-05 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/XYPlot.java (removeDomainMarker(Marker)): New method, (removeDomainMarker(Marker, Layer)): Likewise, (removeDomainMarker(int, Marker, Layer)): Likewise, (removeRangeMarker(Marker)): New method, (removeRangeMarker(Marker, Layer)): Likewise, (removeRangeMarker(int, Marker, Layer)): Likewise. 2007-11-05 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/CategoryPlot.java (removeDomainMarker(Marker)): New method, (removeDomainMarker(Marker, Layer)): Likewise, (removeDomainMarker(int, Marker, Layer)): Likewise, (removeRangeMarker(Marker)): New method, (removeRangeMarker(Marker, Layer)): Likewise, (removeRangeMarker(int, Marker, Layer)): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/plot/CategoryPlot.java trunk/source/org/jfree/chart/plot/XYPlot.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-05 14:04:14 UTC (rev 462) +++ trunk/ChangeLog 2007-11-05 14:21:51 UTC (rev 463) @@ -1,3 +1,23 @@ +2007-11-05 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/XYPlot.java + (removeDomainMarker(Marker)): New method, + (removeDomainMarker(Marker, Layer)): Likewise, + (removeDomainMarker(int, Marker, Layer)): Likewise, + (removeRangeMarker(Marker)): New method, + (removeRangeMarker(Marker, Layer)): Likewise, + (removeRangeMarker(int, Marker, Layer)): Likewise. + +2007-11-05 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/plot/CategoryPlot.java + (removeDomainMarker(Marker)): New method, + (removeDomainMarker(Marker, Layer)): Likewise, + (removeDomainMarker(int, Marker, Layer)): Likewise, + (removeRangeMarker(Marker)): New method, + (removeRangeMarker(Marker, Layer)): Likewise, + (removeRangeMarker(int, Marker, Layer)): Likewise. + 2007-10-31 David Gilbert <dav...@ob...> * source/org/jfree/data/ComparableObjectSeries.java Modified: trunk/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/CategoryPlot.java 2007-11-05 14:04:14 UTC (rev 462) +++ trunk/source/org/jfree/chart/plot/CategoryPlot.java 2007-11-05 14:21:51 UTC (rev 463) @@ -32,6 +32,7 @@ * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Jeremy Bowman; * Arnaud Lelievre; + * Richard West; * * Changes (from 21-Jun-2001) * -------------------------- @@ -144,13 +145,15 @@ * ignored) (DG); * 13-Mar-2007 : Added null argument checks for setRangeCrosshairPaint() and * setRangeCrosshairStroke(), fixed clipping for - * anntotations (DG); + * annotations (DG); * 07-Jun-2007 : Override drawBackground() for new GradientPaint handling (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); * 06-Jul-2007 : Updated annotation handling (DG); * 10-Jul-2007 : Added getRangeAxisIndex(ValueAxis) method (DG); * 24-Sep-2007 : Implemented new zoom methods (DG); * 25-Oct-2007 : Added some argument checks (DG); + * 05-Nov-2007 : Applied patch 1823697, by Richard West, for removal of domain + * and range markers (DG); * */ @@ -957,7 +960,6 @@ } notifyListeners(new PlotChangeEvent(this)); } - /** * Returns the index of the specified axis, or <code>-1</code> if the axis @@ -986,7 +988,7 @@ } return result; } - + /** * Returns the range axis location. * @@ -2054,6 +2056,67 @@ } /** + * Removes a marker for the domain axis and sends a {@link PlotChangeEvent} + * to all registered listeners. + * + * @param marker the marker. + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeDomainMarker(Marker marker) { + return removeDomainMarker(marker, Layer.FOREGROUND); + } + + /** + * Removes a marker for the domain axis in the specified layer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param marker the marker (<code>null</code> not permitted). + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeDomainMarker(Marker marker, Layer layer) { + return removeDomainMarker(0, marker, layer); + } + + /** + * Removes a marker for a specific dataset/renderer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param index the dataset/renderer index. + * @param marker the marker. + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeDomainMarker(int index, Marker marker, Layer layer) { + ArrayList markers; + if (layer == Layer.FOREGROUND) { + markers = (ArrayList) this.foregroundDomainMarkers.get(new Integer( + index)); + } + else { + markers = (ArrayList)this.backgroundDomainMarkers.get(new Integer( + index)); + } + boolean removed = markers.remove(marker); + if (removed) { + notifyListeners(new PlotChangeEvent(this)); + } + return removed; + } + + /** * Adds a marker for display (in the foreground) against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. Typically a * marker will be drawn by the renderer as a line perpendicular to the @@ -2215,6 +2278,71 @@ } /** + * Removes a marker for the range axis and sends a {@link PlotChangeEvent} + * to all registered listeners. + * + * @param marker the marker. + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeRangeMarker(Marker marker) { + return removeRangeMarker(marker, Layer.FOREGROUND); + } + + /** + * Removes a marker for the range axis in the specified layer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param marker the marker (<code>null</code> not permitted). + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeRangeMarker(Marker marker, Layer layer) { + return removeRangeMarker(0, marker, layer); + } + + /** + * Removes a marker for a specific dataset/renderer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param index the dataset/renderer index. + * @param marker the marker. + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeRangeMarker(int index, Marker marker, Layer layer) { + if (marker == null) { + throw new IllegalArgumentException("Null 'marker' argument."); + } + ArrayList markers; + if (layer == Layer.FOREGROUND) { + markers = (ArrayList)this.foregroundRangeMarkers.get(new Integer( + index)); + } + else { + markers = (ArrayList)this.backgroundRangeMarkers.get(new Integer( + index)); + } + + boolean removed = markers.remove(marker); + if (removed) { + notifyListeners(new PlotChangeEvent(this)); + } + return removed; + } + + /** * Returns a flag indicating whether or not the range crosshair is visible. * * @return The flag. Modified: trunk/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/XYPlot.java 2007-11-05 14:04:14 UTC (rev 462) +++ trunk/source/org/jfree/chart/plot/XYPlot.java 2007-11-05 14:21:51 UTC (rev 463) @@ -41,6 +41,7 @@ * Nicolas Brodu; * Eduardo Ramalho; * Sergei Ivanov; + * Richard West; * * Changes (from 21-Jun-2001) * -------------------------- @@ -190,6 +191,8 @@ * XYItemRenderer interface. * 24-Sep-2007 : Added new zoom methods (DG); * 26-Sep-2007 : Include index value in IllegalArgumentExceptions (DG); + * 05-Nov-2007 : Applied patch 1823697, by Richard West, for removal of domain + * and range markers (DG); * */ @@ -2188,6 +2191,67 @@ } /** + * Removes a marker for the domain axis and sends a {@link PlotChangeEvent} + * to all registered listeners. + * + * @param marker the marker. + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeDomainMarker(Marker marker) { + return removeDomainMarker(marker, Layer.FOREGROUND); + } + + /** + * Removes a marker for the domain axis in the specified layer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param marker the marker (<code>null</code> not permitted). + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeDomainMarker(Marker marker, Layer layer) { + return removeDomainMarker(0, marker, layer); + } + + /** + * Removes a marker for a specific dataset/renderer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param index the dataset/renderer index. + * @param marker the marker. + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeDomainMarker(int index, Marker marker, Layer layer) { + ArrayList markers; + if (layer == Layer.FOREGROUND) { + markers = (ArrayList) this.foregroundDomainMarkers.get(new Integer( + index)); + } + else { + markers = (ArrayList)this.backgroundDomainMarkers.get(new Integer( + index)); + } + boolean removed = markers.remove(marker); + if (removed) { + notifyListeners(new PlotChangeEvent(this)); + } + return removed; + } + + /** * Adds a marker for the range axis and sends a {@link PlotChangeEvent} to * all registered listeners. * <P> @@ -2320,6 +2384,71 @@ } /** + * Removes a marker for the range axis and sends a {@link PlotChangeEvent} + * to all registered listeners. + * + * @param marker the marker. + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeRangeMarker(Marker marker) { + return removeRangeMarker(marker, Layer.FOREGROUND); + } + + /** + * Removes a marker for the range axis in the specified layer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param marker the marker (<code>null</code> not permitted). + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeRangeMarker(Marker marker, Layer layer) { + return removeRangeMarker(0, marker, layer); + } + + /** + * Removes a marker for a specific dataset/renderer and sends a + * {@link PlotChangeEvent} to all registered listeners. + * + * @param index the dataset/renderer index. + * @param marker the marker. + * @param layer the layer (foreground or background). + * + * @return A boolean indicating whether or not the marker was actually + * removed. + * + * @since 1.0.7 + */ + public boolean removeRangeMarker(int index, Marker marker, Layer layer) { + if (marker == null) { + throw new IllegalArgumentException("Null 'marker' argument."); + } + ArrayList markers; + if (layer == Layer.FOREGROUND) { + markers = (ArrayList)this.foregroundRangeMarkers.get(new Integer( + index)); + } + else { + markers = (ArrayList)this.backgroundRangeMarkers.get(new Integer( + index)); + } + + boolean removed = markers.remove(marker); + if (removed) { + notifyListeners(new PlotChangeEvent(this)); + } + return removed; + } + + /** * Adds an annotation to the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-11-12 11:27:02
|
Revision: 494 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=494&view=rev Author: mungady Date: 2007-11-12 03:26:58 -0800 (Mon, 12 Nov 2007) Log Message: ----------- 2007-11-12 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/XYPlot.java (equals): Added check for domain/rangeTickBandPaint, * source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java (fillDomainGridBand): Handle plot orientation properly, (fillRangeGridBand): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/plot/XYPlot.java trunk/source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-12 11:08:56 UTC (rev 493) +++ trunk/ChangeLog 2007-11-12 11:26:58 UTC (rev 494) @@ -1,5 +1,13 @@ 2007-11-12 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/XYPlot.java + (equals): Added check for domain/rangeTickBandPaint, + * source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java + (fillDomainGridBand): Handle plot orientation properly, + (fillRangeGridBand): Likewise. + +2007-11-12 David Gilbert <dav...@ob...> + Patch 1827829 from Richard West: * source/org/jfree/chart/renderer/xy/XYBarRenderer.java (drawItemLabel): Fixed NPE. Modified: trunk/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/XYPlot.java 2007-11-12 11:08:56 UTC (rev 493) +++ trunk/source/org/jfree/chart/plot/XYPlot.java 2007-11-12 11:26:58 UTC (rev 494) @@ -193,6 +193,8 @@ * 26-Sep-2007 : Include index value in IllegalArgumentExceptions (DG); * 05-Nov-2007 : Applied patch 1823697, by Richard West, for removal of domain * and range markers (DG); + * 12-Nov-2007 : Fixed bug in equals() method for domain and range tick + * band paint attributes (DG); * */ @@ -3024,7 +3026,6 @@ */ public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea, List ticks) { - // draw the domain tick bands, if any... Paint bandPaint = getDomainTickBandPaint(); if (bandPaint != null) { boolean fillBand = false; @@ -3060,8 +3061,6 @@ */ public void drawRangeTickBands(Graphics2D g2, Rectangle2D dataArea, List ticks) { - - // draw the range tick bands, if any... Paint bandPaint = getRangeTickBandPaint(); if (bandPaint != null) { boolean fillBand = false; @@ -4713,6 +4712,14 @@ if (!ObjectUtilities.equal(this.annotations, that.annotations)) { return false; } + if (!PaintUtilities.equal(this.domainTickBandPaint, + that.domainTickBandPaint)) { + return false; + } + if (!PaintUtilities.equal(this.rangeTickBandPaint, + that.rangeTickBandPaint)) { + return false; + } if (!this.quadrantOrigin.equals(that.quadrantOrigin)) { return false; } Modified: trunk/source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java 2007-11-12 11:08:56 UTC (rev 493) +++ trunk/source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java 2007-11-12 11:26:58 UTC (rev 494) @@ -102,7 +102,8 @@ * 20-Jun-2007 : Removed deprecated code and removed JCommon dependencies (DG); * 27-Jun-2007 : Removed drawDomainGridline() method - use drawDomainLine() * instead (DG); - * + * 12-Nov-2007 : Fixed domain and range band drawing methods (DG); + * */ package org.jfree.chart.renderer.xy; @@ -906,20 +907,22 @@ * @param start the start value. * @param end the end value. */ - public void fillDomainGridBand(Graphics2D g2, - XYPlot plot, - ValueAxis axis, - Rectangle2D dataArea, - double start, double end) { + public void fillDomainGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis, + Rectangle2D dataArea, double start, double end) { double x1 = axis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge()); double x2 = axis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge()); - // TODO: need to change the next line to take account of plot - // orientation... - Rectangle2D band = new Rectangle2D.Double(x1, dataArea.getMinY(), - x2 - x1, dataArea.getMaxY() - dataArea.getMinY()); + Rectangle2D band; + if (plot.getOrientation() == PlotOrientation.VERTICAL) { + band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(), + Math.abs(x2 - x1), dataArea.getWidth()); + } + else { + band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2), + dataArea.getWidth(), Math.abs(x2 - x1)); + } Paint paint = plot.getDomainTickBandPaint(); if (paint != null) { @@ -940,19 +943,21 @@ * @param start the start value. * @param end the end value. */ - public void fillRangeGridBand(Graphics2D g2, - XYPlot plot, - ValueAxis axis, - Rectangle2D dataArea, - double start, double end) { + public void fillRangeGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis, + Rectangle2D dataArea, double start, double end) { - double y1 = axis.valueToJava2D(start, dataArea, + double y1 = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); - // TODO: need to change the next line to take account of the plot - // orientation - Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, - dataArea.getWidth(), y1 - y2); + Rectangle2D band; + if (plot.getOrientation() == PlotOrientation.VERTICAL) { + band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(y1, y2), + dataArea.getWidth(), Math.abs(y2 - y1)); + } + else { + band = new Rectangle2D.Double(Math.min(y1, y2), dataArea.getMinY(), + Math.abs(y2 - y1), dataArea.getHeight()); + } Paint paint = plot.getRangeTickBandPaint(); if (paint != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-11-21 11:34:50
|
Revision: 595 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=595&view=rev Author: mungady Date: 2007-11-21 03:34:49 -0800 (Wed, 21 Nov 2007) Log Message: ----------- 2007-11-21 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java (setBaseShapesVisible): Call fireChangeEvent() instead of notifyListeners(), (setPlotLines): Likewise, (setGapThresholdType): Likewise, (setGapThreshold): Likewise, (setPlotImages): Likewise, (setLegendLine): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-21 11:22:49 UTC (rev 594) +++ trunk/ChangeLog 2007-11-21 11:34:49 UTC (rev 595) @@ -1,5 +1,15 @@ 2007-11-21 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java + (setBaseShapesVisible): Call fireChangeEvent() instead of notifyListeners(), + (setPlotLines): Likewise, + (setGapThresholdType): Likewise, + (setGapThreshold): Likewise, + (setPlotImages): Likewise, + (setLegendLine): Likewise. + +2007-11-21 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/PiePlot.java (DEFAULT_INTERIOR_GAP): Modified default value, (maximumLabelWidth): Likewise, Modified: trunk/source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java 2007-11-21 11:22:49 UTC (rev 594) +++ trunk/source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java 2007-11-21 11:34:49 UTC (rev 595) @@ -303,7 +303,7 @@ public void setBaseShapesVisible(boolean flag) { if (this.baseShapesVisible != flag) { this.baseShapesVisible = flag; - notifyListeners(new RendererChangeEvent(this)); + fireChangeEvent(); } } @@ -347,7 +347,8 @@ } /** - * Sets the 'shapes filled' flag for a series. + * Sets the 'shapes filled' flag for a series and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param flag the flag. @@ -371,7 +372,8 @@ } /** - * Sets the base 'shapes filled' flag. + * Sets the base 'shapes filled' flag and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param flag the flag. * @@ -394,7 +396,8 @@ /** * Sets the flag that controls whether or not a line is plotted between - * each data point. + * each data point and sends a {@link RendererChangeEvent} to all + * registered listeners. * * @param flag the flag. * @@ -403,7 +406,7 @@ public void setPlotLines(boolean flag) { if (this.plotLines != flag) { this.plotLines = flag; - notifyListeners(new RendererChangeEvent(this)); + fireChangeEvent(); } } @@ -419,7 +422,8 @@ } /** - * Sets the gap threshold type. + * Sets the gap threshold type and sends a {@link RendererChangeEvent} to + * all registered listeners. * * @param thresholdType the type (<code>null</code> not permitted). * @@ -431,7 +435,7 @@ "Null 'thresholdType' argument."); } this.gapThresholdType = thresholdType; - notifyListeners(new RendererChangeEvent(this)); + fireChangeEvent(); } /** @@ -446,7 +450,8 @@ } /** - * Sets the gap threshold for discontinuous lines. + * Sets the gap threshold for discontinuous lines and sends a + * {@link RendererChangeEvent} to all registered listeners. * * @param t the threshold. * @@ -454,7 +459,7 @@ */ public void setGapThreshold(double t) { this.gapThreshold = t; - notifyListeners(new RendererChangeEvent(this)); + fireChangeEvent(); } /** @@ -470,7 +475,8 @@ /** * Sets the flag that controls whether or not an image is drawn at each - * data point. + * data point and sends a {@link RendererChangeEvent} to all registered + * listeners. * * @param flag the flag. * @@ -479,7 +485,7 @@ public void setPlotImages(boolean flag) { if (this.plotImages != flag) { this.plotImages = flag; - notifyListeners(new RendererChangeEvent(this)); + fireChangeEvent(); } } @@ -557,7 +563,7 @@ throw new IllegalArgumentException("Null 'line' argument."); } this.legendLine = line; - notifyListeners(new RendererChangeEvent(this)); + fireChangeEvent(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-11-22 09:37:10
|
Revision: 620 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=620&view=rev Author: mungady Date: 2007-11-22 01:37:04 -0800 (Thu, 22 Nov 2007) Log Message: ----------- 2007-11-22 David Gilbert <dav...@ob...> * source/org/jfree/data/xy/XYSeries.java (clone): Reimplemented, * tests/org/jfree/data/xy/junit/XYSeriesTests.java (testCloning2): New method, (testCloning3): Likewise. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/data/xy/XYSeries.java trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-22 09:18:17 UTC (rev 619) +++ trunk/ChangeLog 2007-11-22 09:37:04 UTC (rev 620) @@ -1,3 +1,11 @@ +2007-11-22 David Gilbert <dav...@ob...> + + * source/org/jfree/data/xy/XYSeries.java + (clone): Reimplemented, + * tests/org/jfree/data/xy/junit/XYSeriesTests.java + (testCloning2): New method, + (testCloning3): Likewise. + 2007-11-21 David Gilbert <dav...@ob...> * source/org/jfree/chart/plot/DatasetRenderingOrder.java Modified: trunk/source/org/jfree/data/xy/XYSeries.java =================================================================== --- trunk/source/org/jfree/data/xy/XYSeries.java 2007-11-22 09:18:17 UTC (rev 619) +++ trunk/source/org/jfree/data/xy/XYSeries.java 2007-11-22 09:37:04 UTC (rev 620) @@ -67,6 +67,7 @@ * 15-Jan-2007 : Added toArray() method (DG); * 20-Jun-2007 : Removed deprecated code and JCommon dependencies (DG); * 31-Oct-2007 : Implemented faster hashCode() (DG); + * 22-Nov-2007 : Reimplemented clone() (DG); * */ @@ -562,7 +563,7 @@ */ public int indexOf(Number x) { if (this.autoSort) { - return Collections.binarySearch(this.data, new XYDataItem(x, null)); + return Collections.binarySearch(this.data, new XYDataItem(x, null)); } else { for (int i = 0; i < this.data.size(); i++) { @@ -601,12 +602,13 @@ /** * Returns a clone of the series. * - * @return A clone of the time series. + * @return A clone of the series. * * @throws CloneNotSupportedException if there is a cloning problem. */ public Object clone() throws CloneNotSupportedException { - Object clone = createCopy(0, getItemCount() - 1); + XYSeries clone = (XYSeries) super.clone(); + clone.data = (List) ObjectUtilities.deepClone(this.data); return clone; } Modified: trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java =================================================================== --- trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java 2007-11-22 09:18:17 UTC (rev 619) +++ trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java 2007-11-22 09:37:04 UTC (rev 620) @@ -151,6 +151,51 @@ } /** + * Another test of the clone() method. + */ + public void testCloning2() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 100.0); + s1.add(2.0, null); + s1.add(3.0, 200.0); + XYSeries s2 = null; + try { + s2 = (XYSeries) s1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(s1.equals(s2)); + + // check independence + s2.add(4.0, 300.0); + assertFalse(s1.equals(s2)); + s1.add(4.0, 300.0); + assertTrue(s1.equals(s2)); + } + + /** + * Another test of the clone() method. + */ + public void testCloning3() { + XYSeries s1 = new XYSeries("S1"); + XYSeries s2 = null; + try { + s2 = (XYSeries) s1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(s1.equals(s2)); + + // check independence + s2.add(4.0, 300.0); + assertFalse(s1.equals(s2)); + s1.add(4.0, 300.0); + assertTrue(s1.equals(s2)); + } + + /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2007-11-22 09:50:21
|
Revision: 622 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=622&view=rev Author: mungady Date: 2007-11-22 01:50:16 -0800 (Thu, 22 Nov 2007) Log Message: ----------- 2007-11-22 David Gilbert <dav...@ob...> Fix for bug 1832432: * source/org/jfree/data/time/TimeSeries.java (clone): Reimplemented. Modified Paths: -------------- trunk/ChangeLog trunk/source/org/jfree/data/time/TimeSeries.java trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-22 09:46:16 UTC (rev 621) +++ trunk/ChangeLog 2007-11-22 09:50:16 UTC (rev 622) @@ -1,5 +1,11 @@ 2007-11-22 David Gilbert <dav...@ob...> + Fix for bug 1832432: + * source/org/jfree/data/time/TimeSeries.java + (clone): Reimplemented. + +2007-11-22 David Gilbert <dav...@ob...> + * source/org/jfree/data/DefaultKeyedValues.java (removeValue): Always rebuild index, * source/org/jfree/data/DefaultKeyedValues2D.java Modified: trunk/source/org/jfree/data/time/TimeSeries.java =================================================================== --- trunk/source/org/jfree/data/time/TimeSeries.java 2007-11-22 09:46:16 UTC (rev 621) +++ trunk/source/org/jfree/data/time/TimeSeries.java 2007-11-22 09:50:16 UTC (rev 622) @@ -74,6 +74,7 @@ * 29-Jun-2007 : Changed first parameter in constructors from String to * Comparable (DG); * 31-Oct-2007 : Implemented faster hashCode() (DG); + * 21-Nov-2007 : Fixed clone() method (bug 1832432) (DG); * */ @@ -853,7 +854,8 @@ * subclasses may differ. */ public Object clone() throws CloneNotSupportedException { - Object clone = createCopy(0, getItemCount() - 1); + TimeSeries clone = (TimeSeries) super.clone(); + clone.data = (List) ObjectUtilities.deepClone(this.data); return clone; } Modified: trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java =================================================================== --- trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java 2007-11-22 09:46:16 UTC (rev 621) +++ trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java 2007-11-22 09:50:16 UTC (rev 622) @@ -44,6 +44,7 @@ * 24-May-2006 : Added new tests (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); * 31-Oct-2007 : New hashCode() test (DG); + * 21-Nov-2007 : Added testBug1832432() and testClone2() (DG); * */ @@ -204,6 +205,30 @@ } } + + /** + * Another test of the clone() method. + */ + public void testClone2() { + TimeSeries s1 = new TimeSeries("S1", Year.class); + s1.add(new Year(2007), 100.0); + s1.add(new Year(2008), null); + s1.add(new Year(2009), 200.0); + TimeSeries s2 = null; + try { + s2 = (TimeSeries) s1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(s1.equals(s2)); + + // check independence + s2.addOrUpdate(new Year(2009), 300.0); + assertFalse(s1.equals(s2)); + s1.addOrUpdate(new Year(2009), 300.0); + assertTrue(s1.equals(s2)); + } /** * Add a value to series A for 1999. It should be added at index 0. @@ -584,6 +609,27 @@ assertEquals(1, ts.getItemCount()); } + /** + * A test for bug 1832432. + */ + public void testBug1832432() { + TimeSeries s1 = new TimeSeries("Series"); + TimeSeries s2 = null; + try { + s2 = (TimeSeries) s1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(s1 != s2); + assertTrue(s1.getClass() == s2.getClass()); + assertTrue(s1.equals(s2)); + + // test independence + s1.add(new Day(1, 1, 2007), 100.0); + assertFalse(s1.equals(s2)); + } + /** * Some checks for the getIndex() method. */ @@ -625,7 +671,7 @@ assertEquals(new Year(2006), item.getPeriod()); pass = false; try { - item = series.getDataItem(-1); + /*item = */series.getDataItem(-1); } catch (IndexOutOfBoundsException e) { pass = true; @@ -634,7 +680,7 @@ pass = false; try { - item = series.getDataItem(1); + /*item = */series.getDataItem(1); } catch (IndexOutOfBoundsException e) { pass = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |