From: <mu...@us...> - 2009-04-03 07:08:25
|
Revision: 1930 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1930&view=rev Author: mungady Date: 2009-04-03 07:08:16 +0000 (Fri, 03 Apr 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/data/general/DatasetUtilities.java trunk/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java Modified: trunk/source/org/jfree/data/general/DatasetUtilities.java =================================================================== --- trunk/source/org/jfree/data/general/DatasetUtilities.java 2009-04-03 07:05:37 UTC (rev 1929) +++ trunk/source/org/jfree/data/general/DatasetUtilities.java 2009-04-03 07:08:16 UTC (rev 1930) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------------- * DatasetUtilities.java * --------------------- - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrzej Porebski (bug fix); @@ -112,6 +112,11 @@ * 08-Apr-2008 : Fixed typo in iterateRangeBounds() (DG); * 08-Oct-2008 : Applied patch 2131001 by Jerome David, with some modifications * and additions and some new unit tests (DG); + * 12-Feb-2009 : Added sampleFunction2DToSeries() method (DG); + * 27-Mar-2009 : Added new methods to find domain and range bounds taking into + * account hidden series (DG); + * 01-Apr-2009 : Handle a StatisticalCategoryDataset in + * iterateToFindRangeBounds() (DG); * */ @@ -128,13 +133,18 @@ import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.category.CategoryDataset; +import org.jfree.data.category.CategoryRangeInfo; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.category.IntervalCategoryDataset; import org.jfree.data.function.Function2D; +import org.jfree.data.statistics.BoxAndWhiskerXYDataset; +import org.jfree.data.statistics.StatisticalCategoryDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.OHLCDataset; import org.jfree.data.xy.TableXYDataset; import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYDomainInfo; +import org.jfree.data.xy.XYRangeInfo; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; @@ -266,12 +276,9 @@ * @return The pie dataset with (possibly) aggregated items. */ public static PieDataset createConsolidatedPieDataset(PieDataset source, - Comparable key, - double minimumPercent) - { - return DatasetUtilities.createConsolidatedPieDataset( - source, key, minimumPercent, 2 - ); + Comparable key, double minimumPercent) { + return DatasetUtilities.createConsolidatedPieDataset(source, key, + minimumPercent, 2); } /** @@ -290,9 +297,7 @@ * @return The pie dataset with (possibly) aggregated items. */ public static PieDataset createConsolidatedPieDataset(PieDataset source, - Comparable key, - double minimumPercent, - int minItems) { + Comparable key, double minimumPercent, int minItems) { DefaultPieDataset result = new DefaultPieDataset(); double total = DatasetUtilities.calculatePieDatasetTotal(source); @@ -352,8 +357,7 @@ * @return The dataset. */ public static CategoryDataset createCategoryDataset(String rowKeyPrefix, - String columnKeyPrefix, - double[][] data) { + String columnKeyPrefix, double[][] data) { DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int r = 0; r < data.length; r++) { @@ -381,8 +385,7 @@ * @return The dataset. */ public static CategoryDataset createCategoryDataset(String rowKeyPrefix, - String columnKeyPrefix, - Number[][] data) { + String columnKeyPrefix, Number[][] data) { DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int r = 0; r < data.length; r++) { @@ -410,8 +413,7 @@ * @return The dataset. */ public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, - Comparable[] columnKeys, - double[][] data) { + Comparable[] columnKeys, double[][] data) { // check arguments... if (rowKeys == null) { @@ -425,14 +427,12 @@ } if (ArrayUtilities.hasDuplicateItems(columnKeys)) { throw new IllegalArgumentException( - "Duplicate items in 'columnKeys'." - ); + "Duplicate items in 'columnKeys'."); } if (rowKeys.length != data.length) { throw new IllegalArgumentException( "The number of row keys does not match the number of rows in " - + "the data array." - ); + + "the data array."); } int columnCount = 0; for (int r = 0; r < data.length; r++) { @@ -441,8 +441,7 @@ if (columnKeys.length != columnCount) { throw new IllegalArgumentException( "The number of column keys does not match the number of " - + "columns in the data array." - ); + + "columns in the data array."); } // now do the work... @@ -500,6 +499,31 @@ public static XYDataset sampleFunction2D(Function2D f, double start, double end, int samples, Comparable seriesKey) { + // defer argument checking + XYSeries series = sampleFunction2DToSeries(f, start, end, samples, + seriesKey); + XYSeriesCollection collection = new XYSeriesCollection(series); + return collection; + } + + /** + * Creates an {@link XYSeries} by sampling the specified function over a + * fixed range. + * + * @param f the function (<code>null</code> not permitted). + * @param start the start value for the range. + * @param end the end value for the range. + * @param samples the number of sample points (must be > 1). + * @param seriesKey the key to give the resulting series + * (<code>null</code> not permitted). + * + * @return A series. + * + * @since 1.0.13 + */ + public static XYSeries sampleFunction2DToSeries(Function2D f, + double start, double end, int samples, Comparable seriesKey) { + if (f == null) { throw new IllegalArgumentException("Null 'f' argument."); } @@ -519,8 +543,7 @@ double x = start + (step * i); series.add(x, f.getValue(x)); } - XYSeriesCollection collection = new XYSeriesCollection(series); - return collection; + return series; } /** @@ -650,6 +673,32 @@ } /** + * + * @param dataset + * @param visibleSeriesKeys + * @param includeInterval + * @return + * + * @since 1.0.13 + */ + public static Range findDomainBounds(XYDataset dataset, + List visibleSeriesKeys, boolean includeInterval) { + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + Range result = null; + if (dataset instanceof XYDomainInfo) { + XYDomainInfo info = (XYDomainInfo) dataset; + result = info.getDomainBounds(visibleSeriesKeys, includeInterval); + } + else { + result = iterateToFindDomainBounds(dataset, visibleSeriesKeys, + includeInterval); + } + return result; + } + + /** * Iterates over the items in an {@link XYDataset} to find * the range of x-values. If the dataset is an instance of * {@link IntervalXYDataset}, the starting and ending x-values @@ -758,6 +807,37 @@ } /** + * Finds the bounds of the y-values in the specified dataset, including + * only those series that are listed in visibleSeriesKeys. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param visibleSeriesKeys the keys for the visible series + * (<code>null</code> not permitted). + * @param includeInterval include the y-interval (if the dataset has a + * y-interval). + * + * @return The data bounds. + * + * @since 1.0.13 + */ + public static Range findRangeBounds(CategoryDataset dataset, + List visibleSeriesKeys, boolean includeInterval) { + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + Range result = null; + if (dataset instanceof CategoryRangeInfo) { + CategoryRangeInfo info = (CategoryRangeInfo) dataset; + result = info.getRangeBounds(visibleSeriesKeys, includeInterval); + } + else { + result = iterateToFindRangeBounds(dataset, visibleSeriesKeys, + includeInterval); + } + return result; + } + + /** * Returns the range of values in the range for the dataset. This method * is the partner for the {@link #findDomainBounds(XYDataset)} method. * @@ -797,13 +877,65 @@ } /** + * Finds the bounds of the y-values in the specified dataset, including + * only those series that are listed in visibleSeriesKeys, and those items + * whose x-values fall within the specified range. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param visibleSeriesKeys the keys for the visible series + * (<code>null</code> not permitted). + * @param xRange the x-range (<code>null</code> not permitted). + * @param includeInterval include the y-interval (if the dataset has a + * y-interval). + * + * @return The data bounds. + * + * @since 1.0.13 + */ + public static Range findRangeBounds(XYDataset dataset, + List visibleSeriesKeys, Range xRange, boolean includeInterval) { + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + Range result = null; + if (dataset instanceof XYRangeInfo) { + XYRangeInfo info = (XYRangeInfo) dataset; + result = info.getRangeBounds(visibleSeriesKeys, xRange, + includeInterval); + } + else { + result = iterateToFindRangeBounds(dataset, visibleSeriesKeys, + xRange, includeInterval); + } + return result; + } + + /** * Iterates over the data item of the category dataset to find * the range bounds. * * @param dataset the dataset (<code>null</code> not permitted). + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. * * @return The range (possibly <code>null</code>). * + * @deprecated As of 1.0.10, use + * {@link #iterateRangeBounds(CategoryDataset, boolean)}. + */ + public static Range iterateCategoryRangeBounds(CategoryDataset dataset, + boolean includeInterval) { + return iterateRangeBounds(dataset, includeInterval); + } + + /** + * Iterates over the data item of the category dataset to find + * the range bounds. + * + * @param dataset the dataset (<code>null</code> not permitted). + * + * @return The range (possibly <code>null</code>). + * * @since 1.0.10 */ public static Range iterateRangeBounds(CategoryDataset dataset) { @@ -870,6 +1002,110 @@ } /** + * Iterates over the data item of the category dataset to find + * the range bounds. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. + * @param visibleSeriesKeys the visible series keys. + * + * @return The range (possibly <code>null</code>). + * + * @since 1.0.13 + */ + public static Range iterateToFindRangeBounds(CategoryDataset dataset, + List visibleSeriesKeys, boolean includeInterval) { + + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + if (visibleSeriesKeys == null) { + throw new IllegalArgumentException( + "Null 'visibleSeriesKeys' argument."); + } + + double minimum = Double.POSITIVE_INFINITY; + double maximum = Double.NEGATIVE_INFINITY; + int columnCount = dataset.getColumnCount(); + if (includeInterval && dataset instanceof IntervalCategoryDataset) { + // handle the special case where the dataset has y-intervals that + // we want to measure + IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; + Number lvalue, uvalue; + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.getRowIndex(seriesKey); + for (int column = 0; column < columnCount; column++) { + lvalue = icd.getStartValue(series, column); + uvalue = icd.getEndValue(series, column); + if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) { + minimum = Math.min(minimum, lvalue.doubleValue()); + } + if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) { + maximum = Math.max(maximum, uvalue.doubleValue()); + } + } + } + } + else if (includeInterval + && dataset instanceof StatisticalCategoryDataset) { + // handle the special case where the dataset has y-intervals that + // we want to measure + StatisticalCategoryDataset scd + = (StatisticalCategoryDataset) dataset; + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.getRowIndex(seriesKey); + for (int column = 0; column < columnCount; column++) { + Number meanN = scd.getMeanValue(series, column); + if (meanN != null) { + double std = 0.0; + Number stdN = scd.getStdDevValue(series, column); + if (stdN != null) { + std = stdN.doubleValue(); + if (Double.isNaN(std)) { + std = 0.0; + } + } + double mean = meanN.doubleValue(); + if (!Double.isNaN(mean)) { + minimum = Math.min(minimum, mean - std); + maximum = Math.max(maximum, mean + std); + } + } + } + } + } + else { + // handle the standard case (plain CategoryDataset) + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.getRowIndex(seriesKey); + for (int column = 0; column < columnCount; column++) { + Number value = dataset.getValue(series, column); + if (value != null) { + double v = value.doubleValue(); + if (!Double.isNaN(v)) { + minimum = Math.min(minimum, v); + maximum = Math.max(maximum, v); + } + } + } + } + } + if (minimum == Double.POSITIVE_INFINITY) { + return null; + } + else { + return new Range(minimum, maximum); + } + } + + /** * Iterates over the data item of the xy dataset to find * the range bounds. * @@ -877,6 +1113,20 @@ * * @return The range (possibly <code>null</code>). * + * @deprecated As of 1.0.10, use {@link #iterateRangeBounds(XYDataset)}. + */ + public static Range iterateXYRangeBounds(XYDataset dataset) { + return iterateRangeBounds(dataset); + } + + /** + * Iterates over the data item of the xy dataset to find + * the range bounds. + * + * @param dataset the dataset (<code>null</code> not permitted). + * + * @return The range (possibly <code>null</code>). + * * @since 1.0.10 */ public static Range iterateRangeBounds(XYDataset dataset) { @@ -959,6 +1209,211 @@ } /** + * Returns the range of x-values in the specified dataset for the + * data items belonging to the visible series. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param visibleSeriesKeys the visible series keys (<code>null</code> not + * permitted). + * @param includeInterval a flag that determines whether or not the + * y-interval for the dataset is included (this only applies if the + * dataset is an instance of IntervalXYDataset). + * + * @return The x-range (possibly <code>null</code>). + * + * @since 1.0.13 + */ + public static Range iterateToFindDomainBounds(XYDataset dataset, + List visibleSeriesKeys, boolean includeInterval) { + + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + if (visibleSeriesKeys == null) { + throw new IllegalArgumentException( + "Null 'visibleSeriesKeys' argument."); + } + + double minimum = Double.POSITIVE_INFINITY; + double maximum = Double.NEGATIVE_INFINITY; + + if (includeInterval && dataset instanceof IntervalXYDataset) { + // handle special case of IntervalXYDataset + IntervalXYDataset ixyd = (IntervalXYDataset) dataset; + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.indexOf(seriesKey); + int itemCount = dataset.getItemCount(series); + for (int item = 0; item < itemCount; item++) { + double lvalue = ixyd.getStartXValue(series, item); + double uvalue = ixyd.getEndXValue(series, item); + if (!Double.isNaN(lvalue)) { + minimum = Math.min(minimum, lvalue); + } + if (!Double.isNaN(uvalue)) { + maximum = Math.max(maximum, uvalue); + } + } + } + } + else { + // standard case - plain XYDataset + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.indexOf(seriesKey); + int itemCount = dataset.getItemCount(series); + for (int item = 0; item < itemCount; item++) { + double x = dataset.getXValue(series, item); + if (!Double.isNaN(x)) { + minimum = Math.min(minimum, x); + maximum = Math.max(maximum, x); + } + } + } + } + + if (minimum == Double.POSITIVE_INFINITY) { + return null; + } + else { + return new Range(minimum, maximum); + } + } + + /** + * Returns the range of y-values in the specified dataset for the + * data items belonging to the visible series and with x-values in the + * given range. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param visibleSeriesKeys the visible series keys (<code>null</code> not + * permitted). + * @param xRange the x-range (<code>null</code> not permitted). + * @param includeInterval a flag that determines whether or not the + * y-interval for the dataset is included (this only applies if the + * dataset is an instance of IntervalXYDataset). + * + * @return The y-range (possibly <code>null</code>). + * + * @since 1.0.13 + */ + public static Range iterateToFindRangeBounds(XYDataset dataset, + List visibleSeriesKeys, Range xRange, boolean includeInterval) { + + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + if (visibleSeriesKeys == null) { + throw new IllegalArgumentException( + "Null 'visibleSeriesKeys' argument."); + } + if (xRange == null) { + throw new IllegalArgumentException("Null 'xRange' argument"); + } + + double minimum = Double.POSITIVE_INFINITY; + double maximum = Double.NEGATIVE_INFINITY; + + // handle three cases by dataset type + if (includeInterval && dataset instanceof OHLCDataset) { + // handle special case of OHLCDataset + OHLCDataset ohlc = (OHLCDataset) dataset; + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.indexOf(seriesKey); + int itemCount = dataset.getItemCount(series); + for (int item = 0; item < itemCount; item++) { + double x = ohlc.getXValue(series, item); + if (xRange.contains(x)) { + double lvalue = ohlc.getLowValue(series, item); + double uvalue = ohlc.getHighValue(series, item); + if (!Double.isNaN(lvalue)) { + minimum = Math.min(minimum, lvalue); + } + if (!Double.isNaN(uvalue)) { + maximum = Math.max(maximum, uvalue); + } + } + } + } + } + else if (includeInterval && dataset instanceof BoxAndWhiskerXYDataset) { + // handle special case of BoxAndWhiskerXYDataset + BoxAndWhiskerXYDataset bx = (BoxAndWhiskerXYDataset) dataset; + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.indexOf(seriesKey); + int itemCount = dataset.getItemCount(series); + for (int item = 0; item < itemCount; item++) { + double x = bx.getXValue(series, item); + if (xRange.contains(x)) { + Number lvalue = bx.getMinRegularValue(series, item); + Number uvalue = bx.getMaxRegularValue(series, item); + if (lvalue != null) { + minimum = Math.min(minimum, lvalue.doubleValue()); + } + if (uvalue != null) { + maximum = Math.max(maximum, uvalue.doubleValue()); + } + } + } + } + } + else if (includeInterval && dataset instanceof IntervalXYDataset) { + // handle special case of IntervalXYDataset + IntervalXYDataset ixyd = (IntervalXYDataset) dataset; + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.indexOf(seriesKey); + int itemCount = dataset.getItemCount(series); + for (int item = 0; item < itemCount; item++) { + double x = ixyd.getXValue(series, item); + if (xRange.contains(x)) { + double lvalue = ixyd.getStartYValue(series, item); + double uvalue = ixyd.getEndYValue(series, item); + if (!Double.isNaN(lvalue)) { + minimum = Math.min(minimum, lvalue); + } + if (!Double.isNaN(uvalue)) { + maximum = Math.max(maximum, uvalue); + } + } + } + } + } + else { + // standard case - plain XYDataset + Iterator iterator = visibleSeriesKeys.iterator(); + while (iterator.hasNext()) { + Comparable seriesKey = (Comparable) iterator.next(); + int series = dataset.indexOf(seriesKey); + int itemCount = dataset.getItemCount(series); + for (int item = 0; item < itemCount; item++) { + double x = dataset.getXValue(series, item); + double y = dataset.getYValue(series, item); + if (xRange.contains(x)) { + if (!Double.isNaN(y)) { + minimum = Math.min(minimum, y); + maximum = Math.max(maximum, y); + } + } + } + } + } + if (minimum == Double.POSITIVE_INFINITY) { + return null; + } + else { + return new Range(minimum, maximum); + } + } + + /** * Finds the minimum domain (or X) value for the specified dataset. This * is easy if the dataset implements the {@link DomainInfo} interface (a * good idea if there is an efficient way to determine the minimum value). @@ -1085,12 +1540,10 @@ */ public static Number findMinimumRangeValue(CategoryDataset dataset) { - // check parameters... if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } - // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); Modified: trunk/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java =================================================================== --- trunk/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java 2009-04-03 07:05:37 UTC (rev 1929) +++ trunk/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java 2009-04-03 07:08:16 UTC (rev 1930) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------------- * DatasetUtilitiesTests.java * -------------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -43,11 +43,15 @@ * 28-Mar-2008 : Added and renamed various tests (DG); * 08-Oct-2008 : New tests to support patch 2131001 and related * changes (DG); + * 25-Mar-2009 : Added tests for new iterateToFindRangeBounds() method (DG); * */ package org.jfree.data.general.junit; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -62,6 +66,9 @@ import org.jfree.data.general.DatasetUtilities; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; +import org.jfree.data.statistics.BoxAndWhiskerItem; +import org.jfree.data.statistics.DefaultBoxAndWhiskerXYDataset; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; import org.jfree.data.xy.DefaultIntervalXYDataset; import org.jfree.data.xy.DefaultTableXYDataset; import org.jfree.data.xy.DefaultXYDataset; @@ -998,4 +1005,159 @@ return dataset; } + /** + * Some checks for the iteratorToFindRangeBounds(XYDataset...) method. + */ + public void testIterateToFindRangeBounds1_XYDataset() { + // null dataset throws IllegalArgumentException + boolean pass = false; + try { + DatasetUtilities.iterateToFindRangeBounds(null, new ArrayList(), + new Range(0.0, 1.0), true); } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + // null list throws IllegalArgumentException + pass = false; + try { + DatasetUtilities.iterateToFindRangeBounds(new XYSeriesCollection(), + null, new Range(0.0, 1.0), true); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + // null range throws IllegalArgumentException + pass = false; + try { + DatasetUtilities.iterateToFindRangeBounds(new XYSeriesCollection(), + new ArrayList(), null, true); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some tests for the iterateToFindRangeBounds() method. + */ + public void testIterateToFindRangeBounds2_XYDataset() { + List visibleSeriesKeys = new ArrayList(); + Range xRange = new Range(0.0, 10.0); + + // empty dataset returns null + XYSeriesCollection dataset = new XYSeriesCollection(); + Range r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertNull(r); + + // add an empty series + XYSeries s1 = new XYSeries("A"); + dataset.addSeries(s1); + visibleSeriesKeys.add("A"); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertNull(r); + + // check a null value + s1.add(1.0, null); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertNull(r); + + // check a NaN + s1.add(2.0, Double.NaN); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertNull(r); + + // check a regular value + s1.add(3.0, 5.0); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertEquals(new Range(5.0, 5.0), r); + + // check another regular value + s1.add(4.0, 6.0); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertEquals(new Range(5.0, 6.0), r); + + // add a second series + XYSeries s2 = new XYSeries("B"); + dataset.addSeries(s2); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertEquals(new Range(5.0, 6.0), r); + visibleSeriesKeys.add("B"); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertEquals(new Range(5.0, 6.0), r); + + // add a value to the second series + s2.add(5.0, 15.0); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertEquals(new Range(5.0, 15.0), r); + + // add a value that isn't in the xRange + s2.add(15.0, 150.0); + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false); + assertEquals(new Range(5.0, 15.0), r); + + r = DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, new Range(0.0, 20.0), false); + assertEquals(new Range(5.0, 150.0), r); + } + + /** + * Some checks for the iterateToFindRangeBounds() method when applied to + * a BoxAndWhiskerXYDataset. + */ + public void testIterateToFindRangeBounds_BoxAndWhiskerXYDataset() { + DefaultBoxAndWhiskerXYDataset dataset + = new DefaultBoxAndWhiskerXYDataset("Series 1"); + List visibleSeriesKeys = new ArrayList(); + visibleSeriesKeys.add("Series 1"); + Range xRange = new Range(Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY); + assertNull(DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false)); + + dataset.add(new Date(50L), new BoxAndWhiskerItem(5.0, 4.9, 2.0, 8.0, + 1.0, 9.0, 0.0, 10.0, new ArrayList())); + assertEquals(new Range(5.0, 5.0), + DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, false)); + assertEquals(new Range(1.0, 9.0), + DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, xRange, true)); + } + + /** + * Some checks for the iterateToFindRangeBounds(CategoryDataset...) + * method. + */ + public void testIterateToFindRangeBounds_StatisticalCategoryDataset() { + DefaultStatisticalCategoryDataset dataset + = new DefaultStatisticalCategoryDataset(); + List visibleSeriesKeys = new ArrayList(); + assertNull(DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, false)); + dataset.add(1.0, 0.5, "R1", "C1"); + visibleSeriesKeys.add("R1"); + assertEquals(new Range(1.0, 1.0), + DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, false)); + assertEquals(new Range(0.5, 1.5), + DatasetUtilities.iterateToFindRangeBounds(dataset, + visibleSeriesKeys, true)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 07:04:28
|
Revision: 1935 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1935&view=rev Author: mungady Date: 2009-04-07 07:04:15 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x. Modified Paths: -------------- trunk/source/org/jfree/chart/annotations/XYTextAnnotation.java trunk/tests/org/jfree/chart/annotations/junit/XYTextAnnotationTests.java Modified: trunk/source/org/jfree/chart/annotations/XYTextAnnotation.java =================================================================== --- trunk/source/org/jfree/chart/annotations/XYTextAnnotation.java 2009-04-03 11:29:49 UTC (rev 1934) +++ trunk/source/org/jfree/chart/annotations/XYTextAnnotation.java 2009-04-07 07:04:15 UTC (rev 1935) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------------- * XYTextAnnotation.java * --------------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -48,16 +48,20 @@ * 26-Jan-2006 : Fixed equals() method (bug 1415480) (DG); * 06-Mar-2007 : Added argument checks, re-implemented hashCode() method (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); + * 12-Feb-2009 : Added background paint and outline paint/stroke (DG); + * 01-Apr-2009 : Fixed bug in hotspot calculation (DG); * */ package org.jfree.chart.annotations; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; +import java.awt.Stroke; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; @@ -127,6 +131,34 @@ private double rotationAngle; /** + * The background paint (possibly null). + * + * @since 1.0.13 + */ + private transient Paint backgroundPaint; + + /** + * The flag that controls the visibility of the outline. + * + * @since 1.0.13 + */ + private boolean outlineVisible; + + /** + * The outline paint (never null). + * + * @since 1.0.13 + */ + private transient Paint outlinePaint; + + /** + * The outline stroke (never null). + * + * @since 1.0.13 + */ + private transient Stroke outlineStroke; + + /** * Creates a new annotation to be displayed at the given coordinates. The * coordinates are specified in data space (they will be converted to * Java2D space for display). @@ -147,6 +179,12 @@ this.textAnchor = DEFAULT_TEXT_ANCHOR; this.rotationAnchor = DEFAULT_ROTATION_ANCHOR; this.rotationAngle = DEFAULT_ROTATION_ANGLE; + + // by default the outline and background won't be visible + this.backgroundPaint = null; + this.outlineVisible = false; + this.outlinePaint = Color.black; + this.outlineStroke = new BasicStroke(0.5f); } /** @@ -346,6 +384,112 @@ } /** + * Returns the background paint for the annotation. + * + * @return The background paint (possibly <code>null</code>). + * + * @see #setBackgroundPaint(Paint) + * + * @since 1.0.13 + */ + public Paint getBackgroundPaint() { + return this.backgroundPaint; + } + + /** + * Sets the background paint for the annotation. + * + * @param paint the paint (<code>null</code> permitted). + * + * @see #getBackgroundPaint() + * + * @since 1.0.13 + */ + public void setBackgroundPaint(Paint paint) { + this.backgroundPaint = paint; + } + + /** + * Returns the outline paint for the annotation. + * + * @return The outline paint (never <code>null</code>). + * + * @see #setOutlinePaint(Paint) + * + * @since 1.0.13 + */ + public Paint getOutlinePaint() { + return this.outlinePaint; + } + + /** + * Sets the outline paint for the annotation. + * + * @param paint the paint (<code>null</code> not permitted). + * + * @see #getOutlinePaint() + * + * @since 1.0.13 + */ + public void setOutlinePaint(Paint paint) { + if (paint == null) { + throw new IllegalArgumentException("Null 'paint' argument."); + } + this.outlinePaint = paint; + } + + /** + * Returns the outline stroke for the annotation. + * + * @return The outline stroke (never <code>null</code>). + * + * @see #setOutlineStroke(Stroke) + * + * @since 1.0.13 + */ + public Stroke getOutlineStroke() { + return this.outlineStroke; + } + + /** + * Sets the outline stroke for the annotation. + * + * @param stroke the stroke (<code>null</code> not permitted). + * + * @see #getOutlineStroke() + * + * @since 1.0.13 + */ + public void setOutlineStroke(Stroke stroke) { + if (stroke == null) { + throw new IllegalArgumentException("Null 'stroke' argument."); + } + this.outlineStroke = stroke; + } + + /** + * Returns the flag that controls whether or not the outline is drawn. + * + * @return A boolean. + * + * @since 1.0.13 + */ + public boolean isOutlineVisible() { + return this.outlineVisible; + } + + /** + * Sets the flag that controls whether or not the outline is drawn. + * + * @param visible the new flag value. + * + * @since 1.0.13 + */ + public void setOutlineVisible(boolean visible) { + this.outlineVisible = visible; + } + + /** * Draws the annotation. * * @param g2 the graphics device. @@ -380,12 +524,21 @@ } g2.setFont(getFont()); + Shape hotspot = TextUtilities.calculateRotatedStringBounds( + getText(), g2, anchorX, anchorY, getTextAnchor(), + getRotationAngle(), getRotationAnchor()); + if (this.backgroundPaint != null) { + g2.setPaint(this.backgroundPaint); + g2.fill(hotspot); + } g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); - Shape hotspot = TextUtilities.calculateRotatedStringBounds( - getText(), g2, anchorX, anchorY, getTextAnchor(), - getRotationAngle(), getRotationAnchor()); + if (this.outlineVisible) { + g2.setStroke(this.outlineStroke); + g2.setPaint(this.outlinePaint); + g2.draw(hotspot); + } String toolTip = getToolTipText(); String url = getURL(); @@ -409,9 +562,6 @@ if (!(obj instanceof XYTextAnnotation)) { return false; } - if (!super.equals(obj)) { - return false; - } XYTextAnnotation that = (XYTextAnnotation) obj; if (!this.text.equals(that.text)) { return false; @@ -437,8 +587,20 @@ if (!this.textAnchor.equals(that.textAnchor)) { return false; } - return true; + if (this.outlineVisible != that.outlineVisible) { + return false; } + if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { + 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 the object. @@ -482,6 +644,9 @@ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); + SerialUtilities.writePaint(this.backgroundPaint, stream); + SerialUtilities.writePaint(this.outlinePaint, stream); + SerialUtilities.writeStroke(this.outlineStroke, stream); } /** @@ -496,6 +661,9 @@ throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); + this.backgroundPaint = SerialUtilities.readPaint(stream); + this.outlinePaint = SerialUtilities.readPaint(stream); + this.outlineStroke = SerialUtilities.readStroke(stream); } } Modified: trunk/tests/org/jfree/chart/annotations/junit/XYTextAnnotationTests.java =================================================================== --- trunk/tests/org/jfree/chart/annotations/junit/XYTextAnnotationTests.java 2009-04-03 11:29:49 UTC (rev 1934) +++ trunk/tests/org/jfree/chart/annotations/junit/XYTextAnnotationTests.java 2009-04-07 07:04:15 UTC (rev 1935) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------------- * XYTextAnnotationTests.java * -------------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -39,11 +39,13 @@ * 26-Jan-2006 : Extended equals() test (DG); * 20-Jun-2007 : Removed JCommon tests (DG); * 23-Apr-2008 : Added testPublicCloneable() (DG); + * 12-Feb-2009 : Updated testEquals() (DG); * */ package org.jfree.chart.annotations.junit; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; @@ -144,6 +146,27 @@ assertFalse(a1.equals(a2)); a2.setTextAnchor(TextAnchor.BASELINE_RIGHT); assertTrue(a1.equals(a2)); + + a1.setBackgroundPaint(gp1); + assertFalse(a1.equals(a2)); + a2.setBackgroundPaint(gp1); + assertTrue(a1.equals(a2)); + + a1.setOutlinePaint(gp1); + assertFalse(a1.equals(a2)); + a2.setOutlinePaint(gp1); + assertTrue(a1.equals(a2)); + + a1.setOutlineStroke(new BasicStroke(1.2f)); + assertFalse(a1.equals(a2)); + a2.setOutlineStroke(new BasicStroke(1.2f)); + assertTrue(a1.equals(a2)); + + a1.setOutlineVisible(!a1.isOutlineVisible()); + assertFalse(a1.equals(a2)); + a2.setOutlineVisible(a1.isOutlineVisible()); + assertTrue(a1.equals(a2)); + } /** @@ -168,7 +191,7 @@ a2 = (XYTextAnnotation) a1.clone(); } catch (CloneNotSupportedException e) { - System.err.println("Failed to clone."); + e.printStackTrace(); } assertTrue(a1 != a2); assertTrue(a1.getClass() == a2.getClass()); @@ -187,8 +210,9 @@ * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { - XYTextAnnotation a1 = new XYTextAnnotation("Text", 10.0, 20.0); + a1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, + Color.blue)); XYTextAnnotation a2 = null; try { @@ -206,7 +230,6 @@ e.printStackTrace(); } assertEquals(a1, a2); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 08:47:06
|
Revision: 1943 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1943&view=rev Author: mungady Date: 2009-04-07 08:47:01 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/renderer/RendererUtilities.java trunk/tests/org/jfree/chart/renderer/junit/RendererUtilitiesTests.java Modified: trunk/source/org/jfree/chart/renderer/RendererUtilities.java =================================================================== --- trunk/source/org/jfree/chart/renderer/RendererUtilities.java 2009-04-07 08:37:21 UTC (rev 1942) +++ trunk/source/org/jfree/chart/renderer/RendererUtilities.java 2009-04-07 08:47:01 UTC (rev 1943) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------------- * RendererUtilities.java * ---------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited. + * (C) Copyright 2007-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,6 +35,7 @@ * Changes * ------- * 19-Apr-2007 : Version 1 (DG); + * 27-Mar-2009 : Fixed results for unsorted datasets (DG); * */ @@ -67,16 +68,21 @@ */ public static int findLiveItemsLowerBound(XYDataset dataset, int series, double xLow, double xHigh) { + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + if (xLow >= xHigh) { + throw new IllegalArgumentException("Requires xLow < xHigh."); + } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { // for data in ascending order by x-value, we are (broadly) looking - // for the index of the highest x-value that is less that xLow + // for the index of the highest x-value that is less than xLow int low = 0; int high = itemCount - 1; - int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue >= xLow) { // special case where the lowest x-value is >= xLow @@ -88,6 +94,7 @@ return high; } while (high - low > 1) { + int mid = (low + high) / 2; double midV = dataset.getXValue(series, mid); if (midV >= xLow) { high = mid; @@ -95,16 +102,14 @@ else { low = mid; } - mid = (low + high) / 2; } - return mid; + return high; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { // when the x-values are sorted in descending order, the lower // bound is found by calculating relative to the xHigh value int low = 0; int high = itemCount - 1; - int mid = (low + high) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue <= xHigh) { return low; @@ -114,6 +119,7 @@ return high; } while (high - low > 1) { + int mid = (low + high) / 2; double midV = dataset.getXValue(series, mid); if (midV > xHigh) { low = mid; @@ -123,7 +129,7 @@ } mid = (low + high) / 2; } - return mid; + return high; } else { // we don't know anything about the ordering of the x-values, @@ -131,16 +137,20 @@ // range... int index = 0; // skip any items that don't need including... - while (index < itemCount && dataset.getXValue(series, index) - < xLow) { + double x = dataset.getXValue(series, index); + while (index < itemCount && (x < xLow || x > xHigh)) { index++; + if (index < itemCount) { + x = dataset.getXValue(series, index); + } } - return Math.max(0, index - 1); + return Math.min(Math.max(0, index), itemCount - 1); } } /** - * Finds the index of the item in the specified series that... + * Finds the upper index of the range of live items in the specified data + * series. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index. @@ -155,6 +165,12 @@ */ public static int findLiveItemsUpperBound(XYDataset dataset, int series, double xLow, double xHigh) { + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + if (xLow >= xHigh) { + throw new IllegalArgumentException("Requires xLow < xHigh."); + } int itemCount = dataset.getItemCount(series); if (itemCount <= 1) { return 0; @@ -162,7 +178,6 @@ if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; - int mid = (low + high + 1) / 2; double lowValue = dataset.getXValue(series, low); if (lowValue > xHigh) { return low; @@ -171,6 +186,7 @@ if (highValue <= xHigh) { return high; } + int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (midV <= xHigh) { @@ -179,7 +195,7 @@ else { high = mid; } - mid = (low + high + 1) / 2; + mid = (low + high) / 2; } return mid; } @@ -215,11 +231,14 @@ // range... int index = itemCount - 1; // skip any items that don't need including... - while (index >= 0 && dataset.getXValue(series, index) - > xHigh) { + double x = dataset.getXValue(series, index); + while (index >= 0 && (x < xLow || x > xHigh)) { index--; + if (index >= 0) { + x = dataset.getXValue(series, index); + } } - return Math.min(itemCount - 1, index + 1); + return Math.max(index, 0); } } @@ -241,6 +260,9 @@ // like it matters... int i0 = findLiveItemsLowerBound(dataset, series, xLow, xHigh); int i1 = findLiveItemsUpperBound(dataset, series, xLow, xHigh); + if (i0 > i1) { + i0 = i1; + } return new int[] {i0, i1}; } Modified: trunk/tests/org/jfree/chart/renderer/junit/RendererUtilitiesTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/junit/RendererUtilitiesTests.java 2009-04-07 08:37:21 UTC (rev 1942) +++ trunk/tests/org/jfree/chart/renderer/junit/RendererUtilitiesTests.java 2009-04-07 08:47:01 UTC (rev 1943) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------------------- * RendererUtilitiesTests.java * --------------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2007-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -75,7 +75,7 @@ * Some checks for the findLiveItemsLowerBound() method when the dataset is * unordered. */ - public void testFindLiveItemsLowerBoundUnordered() { + public void testFindLiveItemsLowerBound_Unordered() { DefaultXYDataset d = new DefaultXYDataset(); // check a series with no items @@ -84,42 +84,42 @@ 11.0)); // check a series with one item - d.addSeries("S2", new double[][] {{1.0}, {2.0}}); + d.addSeries("S2", new double[][] {{0.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 1, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 1, 2.0, 3.3)); // check a series with two items - d.addSeries("S3", new double[][] {{1.0, 2.0}, {2.0, 2.0}}); + d.addSeries("S3", new double[][] {{0.0, 1.0}, {9.9, 9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 0.0, 1.1)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 1.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 1.0, 2.2)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 2.0, 3.3)); assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 3.0, 4.4)); // check a series with three items - d.addSeries("S4", new double[][] {{1.0, 2.0, 1.5}, {2.0, 2.0, 2.0}}); + d.addSeries("S4", new double[][] {{1.0, 2.0, 1.5}, {9.9, 9.9, 9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 1.0, 2.2)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 3, 2.0, 3.3)); assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 3, 3.0, 4.4)); // check a series with four items - d.addSeries("S5", new double[][] {{1.0, 2.0, 1.5, 1.8}, {2.0, 2.0, - 2.0, 2.0}}); + d.addSeries("S5", new double[][] {{1.0, 2.0, 1.5, 1.8}, {9.9, 9.9, + 9.9, 9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 1.0, 2.2)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.0, 3.3)); assertEquals(3, RendererUtilities.findLiveItemsLowerBound(d, 4, 3.0, 4.4)); @@ -131,7 +131,7 @@ * Some checks for the findLiveItemsLowerBound() method when the dataset is * ASCENDING. */ - public void testFindLiveItemsLowerBoundAscending() { + public void testFindLiveItemsLowerBound_Ascending() { DefaultXYDataset d = new DefaultXYDataset() { public DomainOrder getDomainOrder() { // we're doing this for testing only, and make sure that we @@ -145,59 +145,71 @@ 11.1)); // check a series with one item - d.addSeries("S2", new double[][] {{1.0}, {2.0}}); + d.addSeries("S2", new double[][] {{1.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 1, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 1, 2.0, 2.2)); // check a series with two items - d.addSeries("S3", new double[][] {{1.0, 2.0}, {2.0, 2.0}}); + d.addSeries("S3", new double[][] {{1.0, 2.0}, {9.9, 9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 1.0, 2.2)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 2.0, 3.3)); assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 3.0, 4.4)); // check a series with three items - d.addSeries("S4", new double[][] {{1.0, 2.0, 3.0}, {2.0, 2.0, 2.0}}); + d.addSeries("S4", new double[][] {{1.0, 2.0, 3.0}, {9.9, 9.9, 9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 1.0, 2.2)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 3, 2.0, 3.3)); - assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 3, 3.0, + assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 3, 3.0, 4.4)); // check a series with four items - d.addSeries("S5", new double[][] {{1.0, 2.0, 3.0, 4.0}, {2.0, 2.0, - 2.0, 2.0}}); + d.addSeries("S5", new double[][] {{1.0, 2.0, 3.0, 4.0}, {9.9, 9.9, + 9.9, 9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 1.0, 2.2)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.0, 3.3)); - assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 4, 3.0, + assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 4, 3.0, 4.4)); - assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 4, 4.0, + assertEquals(3, RendererUtilities.findLiveItemsLowerBound(d, 4, 4.0, 5.5)); + // check a series with repeating items + d.addSeries("S5", new double[][] {{1.0, 2.0, 2.0, 2.0, 3.0}, {9.9, 9.9, + 9.9, 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 0.0, + 4.0)); + assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 1.0, + 4.0)); + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.0, + 4.0)); + assertEquals(4, RendererUtilities.findLiveItemsLowerBound(d, 4, 3.0, + 4.0)); + } /** * Some checks for the findLiveItemsLowerBound() method when the dataset is * DESCENDING. */ - public void testFindLiveItemsLowerBoundDescending() { + public void testFindLiveItemsLowerBound_Descending() { DefaultXYDataset d = new DefaultXYDataset() { public DomainOrder getDomainOrder() { // we're doing this for testing only, and make sure that we - // only add data in ascending order by x-value + // only add data in descending order by x-value return DomainOrder.DESCENDING; } }; @@ -207,17 +219,17 @@ 11.0)); // check a series with one item - d.addSeries("S2", new double[][] {{1.0}, {2.0}}); + d.addSeries("S2", new double[][] {{1.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 1, 0.0, 1.0)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 1, 1.1, 2.0)); // check a series with two items - d.addSeries("S3", new double[][] {{2.0, 1.0}, {2.0, 2.0}}); + d.addSeries("S3", new double[][] {{2.0, 1.0}, {9.9, 9.9}}); assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 0.1, 0.5)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 0.1, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 2, 0.1, 1.0)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 2, 1.1, 2.0)); @@ -227,10 +239,10 @@ 4.0)); // check a series with three items - d.addSeries("S4", new double[][] {{3.0, 2.0, 1.0}, {2.0, 2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 3, 0.0, + d.addSeries("S4", new double[][] {{3.0, 2.0, 1.0}, {9.9, 9.9, 9.9}}); + assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 3, 0.0, 1.0)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 1.0, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 3, 1.0, 2.0)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 3, 2.0, 3.0)); @@ -238,27 +250,39 @@ 4.0)); // check a series with four items - d.addSeries("S5", new double[][] {{4.0, 3.0, 2.0, 1.0}, {2.0, 2.0, - 2.0, 2.0}}); + d.addSeries("S5", new double[][] {{4.0, 3.0, 2.0, 1.0}, {9.9, 9.9, + 9.9, 9.9}}); assertEquals(3, RendererUtilities.findLiveItemsLowerBound(d, 4, 0.1, 0.5)); - assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 4, 0.1, + assertEquals(3, RendererUtilities.findLiveItemsLowerBound(d, 4, 0.1, 1.0)); - assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 4, 1.1, + assertEquals(2, RendererUtilities.findLiveItemsLowerBound(d, 4, 1.1, 2.0)); - assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.2, + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 4, 2.2, 3.0)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 3.3, 4.0)); assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 4, 4.4, 5.0)); + + // check a series with repeating items + d.addSeries("S6", new double[][] {{3.0, 2.0, 2.0, 2.0, 1.0}, {9.9, 9.9, + 9.9, 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsLowerBound(d, 5, 0.0, + 3.0)); + assertEquals(1, RendererUtilities.findLiveItemsLowerBound(d, 5, 0.0, + 2.0)); + assertEquals(4, RendererUtilities.findLiveItemsLowerBound(d, 5, 0.0, + 1.0)); + assertEquals(4, RendererUtilities.findLiveItemsLowerBound(d, 5, 0.0, + 0.5)); } /** * Some checks for the findLiveItemsUpperBound() method when the dataset is * unordered. */ - public void testFindLiveItemsUpperBoundUnordered() { + public void testFindLiveItemsUpperBound_Unordered() { DefaultXYDataset d = new DefaultXYDataset(); // check a series with no items @@ -267,46 +291,46 @@ 11.0)); // check a series with one item - d.addSeries("S2", new double[][] {{1.0}, {2.0}}); + d.addSeries("S2", new double[][] {{1.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 2.0, 3.3)); // check a series with two items - d.addSeries("S3", new double[][] {{1.0, 2.0}, {2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.0, + d.addSeries("S3", new double[][] {{1.0, 2.0}, {9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.0, 1.1)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 1.0, 2.2)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 2.0, 3.3)); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 3.0, + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 3.0, 4.4)); // check a series with three items - d.addSeries("S4", new double[][] {{1.0, 2.0, 1.5}, {2.0, 2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0, + d.addSeries("S4", new double[][] {{1.0, 2.0, 1.5}, {9.9, 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0, 1.1)); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 1.0, 2.2)); - assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 3, 2.0, 3.3)); - assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 3.0, + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 3, 3.0, 4.4)); // check a series with four items - d.addSeries("S5", new double[][] {{1.0, 2.0, 1.5, 1.8}, {2.0, 2.0, - 2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, + d.addSeries("S5", new double[][] {{1.0, 2.0, 1.5, 1.8}, {9.9, 9.9, + 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, 1.1)); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 1.0, 2.2)); - assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 2.0, + assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 4, 2.0, 3.3)); - assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 3.0, + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 3.0, 4.4)); - assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 4.0, + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 4.0, 5.5)); } @@ -314,7 +338,7 @@ * Some checks for the findLiveItemsUpperBound() method when the dataset is * ASCENDING. */ - public void testFindLiveItemsUpperBoundAscending() { + public void testFindLiveItemsUpperBound_Ascending() { DefaultXYDataset d = new DefaultXYDataset() { public DomainOrder getDomainOrder() { // we're doing this for testing only, and make sure that we @@ -328,15 +352,15 @@ 11.1)); // check a series with one item - d.addSeries("S2", new double[][] {{1.0}, {2.0}}); + d.addSeries("S2", new double[][] {{1.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 0.0, 1.1)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 2.0, 2.2)); // check a series with two items - d.addSeries("S3", new double[][] {{1.0, 2.0}, {2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.0, + d.addSeries("S3", new double[][] {{1.0, 2.0}, {9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.0, 1.0)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 1.0, 2.2)); @@ -346,10 +370,10 @@ 4.4)); // check a series with three items - d.addSeries("S4", new double[][] {{1.0, 2.0, 3.0}, {2.0, 2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0, + d.addSeries("S4", new double[][] {{1.0, 2.0, 3.0}, {9.9, 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0, 1.1)); - assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 1.0, + assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 3, 1.0, 2.2)); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 2.0, 3.3)); @@ -357,30 +381,42 @@ 4.4)); // check a series with four items - d.addSeries("S5", new double[][] {{1.0, 2.0, 3.0, 4.0}, {2.0, 2.0, - 2.0, 2.0}}); - assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, + d.addSeries("S5", new double[][] {{1.0, 2.0, 3.0, 4.0}, {9.9, 9.9, + 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, 1.1)); - assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 4, 1.0, + assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 4, 1.0, 2.2)); - assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 2.0, + assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 4, 2.0, 3.3)); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 3.0, 4.4)); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 4.0, 5.5)); + // check a series with repeating items + d.addSeries("S5", new double[][] {{1.0, 2.0, 2.0, 2.0, 3.0}, {9.9, 9.9, + 9.9, 9.9, 9.9}}); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, + 1.0)); + assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, + 2.0)); + assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, + 3.0)); + assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.0, + 4.0)); + } /** * Some checks for the findLiveItemsUpperBound() method when the dataset is * DESCENDING. */ - public void testFindLiveItemsUpperBoundDescending() { + public void testFindLiveItemsUpperBound_Descending() { DefaultXYDataset d = new DefaultXYDataset() { public DomainOrder getDomainOrder() { // we're doing this for testing only, and make sure that we - // only add data in ascending order by x-value + // only add data in descending order by x-value return DomainOrder.DESCENDING; } }; @@ -390,14 +426,14 @@ 11.0)); // check a series with one item - d.addSeries("S2", new double[][] {{1.0}, {2.0}}); + d.addSeries("S2", new double[][] {{1.0}, {9.9}}); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 0.0, 1.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 1, 1.1, 2.0)); // check a series with two items - d.addSeries("S3", new double[][] {{2.0, 1.0}, {2.0, 2.0}}); + d.addSeries("S3", new double[][] {{2.0, 1.0}, {9.9, 9.9}}); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.1, 0.5)); assertEquals(1, RendererUtilities.findLiveItemsUpperBound(d, 2, 0.1, @@ -410,7 +446,7 @@ 4.0)); // check a series with three items - d.addSeries("S4", new double[][] {{3.0, 2.0, 1.0}, {2.0, 2.0, 2.0}}); + d.addSeries("S4", new double[][] {{3.0, 2.0, 1.0}, {9.9, 9.9, 9.9}}); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 0.0, 1.0)); assertEquals(2, RendererUtilities.findLiveItemsUpperBound(d, 3, 1.0, @@ -421,8 +457,8 @@ 4.0)); // check a series with four items - d.addSeries("S5", new double[][] {{4.0, 3.0, 2.0, 1.0}, {2.0, 2.0, - 2.0, 2.0}}); + d.addSeries("S5", new double[][] {{4.0, 3.0, 2.0, 1.0}, {9.9, 9.9, + 9.9, 9.9}}); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.1, 0.5)); assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 4, 0.1, @@ -435,7 +471,18 @@ 4.0)); assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 4, 4.4, 5.0)); + + // check a series with repeating items + d.addSeries("S6", new double[][] {{3.0, 2.0, 2.0, 2.0, 1.0}, {9.9, 9.9, + 9.9, 9.9, 9.9}}); + assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 5, 0.0, + 5.0)); + assertEquals(4, RendererUtilities.findLiveItemsUpperBound(d, 5, 1.0, + 5.0)); + assertEquals(3, RendererUtilities.findLiveItemsUpperBound(d, 5, 2.0, + 5.0)); + assertEquals(0, RendererUtilities.findLiveItemsUpperBound(d, 5, 3.0, + 5.0)); } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 09:29:00
|
Revision: 1947 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1947&view=rev Author: mungady Date: 2009-04-07 09:28:54 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/imagemap/ImageMapUtilities.java trunk/tests/org/jfree/chart/imagemap/junit/ImageMapPackageTests.java Added Paths: ----------- trunk/tests/org/jfree/chart/imagemap/junit/DynamicDriveToolTipTagFragmentGeneratorTests.java trunk/tests/org/jfree/chart/imagemap/junit/ImageMapUtilitiesTests.java trunk/tests/org/jfree/chart/imagemap/junit/OverLIBToolTipTagFragmentGeneratorTests.java Modified: trunk/source/org/jfree/chart/imagemap/ImageMapUtilities.java =================================================================== --- trunk/source/org/jfree/chart/imagemap/ImageMapUtilities.java 2009-04-07 09:20:59 UTC (rev 1946) +++ trunk/source/org/jfree/chart/imagemap/ImageMapUtilities.java 2009-04-07 09:28:54 UTC (rev 1947) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,11 @@ * ---------------------- * ImageMapUtilities.java * ---------------------- - * (C) Copyright 2004-2008, by Richard Atkinson and Contributors. + * (C) Copyright 2004-2009, by Richard Atkinson and Contributors. * * Original Author: Richard Atkinson; * Contributor(s): David Gilbert (for Object Refinery Limited); + * Fawad Halim - bug 2690293; * * Changes * ------- @@ -43,6 +44,8 @@ * 21-Jun-2007 : Removed JCommon dependencies (DG); * 04-Dec-2007 : Added htmlEscape() method, and escape 'name' in * getImageMap() (DG); + * 19-Mar-2009 : Added javascriptEscape() method - see bug 2690293 by FH (DG); + * 25-Mar-2009 : Reimplemented javascriptEscape() (DG); * */ @@ -72,8 +75,7 @@ * @throws java.io.IOException if there are any I/O errors. */ public static void writeImageMap(PrintWriter writer, String name, - ChartRenderingInfo info) - throws IOException { + ChartRenderingInfo info) throws IOException { // defer argument checking... ImageMapUtilities.writeImageMap(writer, name, info, @@ -94,10 +96,8 @@ * @throws java.io.IOException if there are any I/O errors. */ public static void writeImageMap(PrintWriter writer, - String name, - ChartRenderingInfo info, - boolean useOverLibForToolTips) - throws IOException { + String name, ChartRenderingInfo info, + boolean useOverLibForToolTips) throws IOException { ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null; if (useOverLibForToolTips) { @@ -241,4 +241,38 @@ } return result.toString(); } + + /** + * Returns a string that is equivalent to the input string, but with + * special characters converted to JavaScript escape sequences. + * + * @param input the string to escape (<code>null</code> not permitted). + * + * @return A string with characters escaped. + * + * @since 1.0.13 + */ + public static String javascriptEscape(String input) { + if (input == null) { + throw new IllegalArgumentException("Null 'input' argument."); + } + StringBuffer result = new StringBuffer(); + int length = input.length(); + for (int i = 0; i < length; i++) { + char c = input.charAt(i); + if (c == '\"') { + result.append("\\\""); + } + else if (c == '\'') { + result.append("\\'"); + } + else if (c == '\\') { + result.append("\\\\"); + } + else { + result.append(c); + } + } + return result.toString(); + } } Added: trunk/tests/org/jfree/chart/imagemap/junit/DynamicDriveToolTipTagFragmentGeneratorTests.java =================================================================== --- trunk/tests/org/jfree/chart/imagemap/junit/DynamicDriveToolTipTagFragmentGeneratorTests.java (rev 0) +++ trunk/tests/org/jfree/chart/imagemap/junit/DynamicDriveToolTipTagFragmentGeneratorTests.java 2009-04-07 09:28:54 UTC (rev 1947) @@ -0,0 +1,87 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------------------------------------- + * DynamicDriveToolTipTagFragmentGeneratorTests.java + * ------------------------------------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 25-Mar-2009 : Version 1 (DG); + * + */ + +package org.jfree.chart.imagemap.junit; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator; + +/** + * Tests for the {@link DynamicDriveToolTipTagFragmentGenerator} class. + */ +public class DynamicDriveToolTipTagFragmentGeneratorTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(DynamicDriveToolTipTagFragmentGeneratorTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public DynamicDriveToolTipTagFragmentGeneratorTests(String name) { + super(name); + } + + /** + * Some checks for the generateURLFragment() method. + */ + public void testGenerateURLFragment() { + OverLIBToolTipTagFragmentGenerator g + = new OverLIBToolTipTagFragmentGenerator(); + assertEquals(" onMouseOver=\"return overlib('abc');\"" + + " onMouseOut=\"return nd();\"", + g.generateToolTipFragment("abc")); + assertEquals(" onMouseOver=\"return overlib(" + + "'It\\'s \\\"A\\\", 100.0');\" onMouseOut=\"return nd();\"", + g.generateToolTipFragment("It\'s \"A\", 100.0")); + } + +} + Modified: trunk/tests/org/jfree/chart/imagemap/junit/ImageMapPackageTests.java =================================================================== --- trunk/tests/org/jfree/chart/imagemap/junit/ImageMapPackageTests.java 2009-04-07 09:20:59 UTC (rev 1946) +++ trunk/tests/org/jfree/chart/imagemap/junit/ImageMapPackageTests.java 2009-04-07 09:28:54 UTC (rev 1947) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------- * ImageMapPackageTests.java * ------------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited. + * (C) Copyright 2007-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,6 +35,9 @@ * Changes: * -------- * 05-Dec-2007 : Version 1 (DG); + * 25-Mar-2009 : Added DynamicDriveToolTipTagFragmentGeneratorTests, + * ImageMapUtilitiesTests and + * OverLIBToolTipTagFragmentGeneratorTests (DG); * */ @@ -58,6 +61,9 @@ */ public static Test suite() { TestSuite suite = new TestSuite("org.jfree.chart.imagemap"); + suite.addTestSuite(DynamicDriveToolTipTagFragmentGeneratorTests.class); + suite.addTestSuite(ImageMapUtilitiesTests.class); + suite.addTestSuite(OverLIBToolTipTagFragmentGeneratorTests.class); suite.addTestSuite(StandardToolTipTagFragmentGeneratorTests.class); suite.addTestSuite(StandardURLTagFragmentGeneratorTests.class); return suite; Added: trunk/tests/org/jfree/chart/imagemap/junit/ImageMapUtilitiesTests.java =================================================================== --- trunk/tests/org/jfree/chart/imagemap/junit/ImageMapUtilitiesTests.java (rev 0) +++ trunk/tests/org/jfree/chart/imagemap/junit/ImageMapUtilitiesTests.java 2009-04-07 09:28:54 UTC (rev 1947) @@ -0,0 +1,98 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * --------------------------- + * ImageMapUtilitiesTests.java + * --------------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 25-Mar-2009 : Version 1 (DG); + * + */ + +package org.jfree.chart.imagemap.junit; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.imagemap.ImageMapUtilities; + +/** + * Tests for the {@link ImageMapUtilities} class. + */ +public class ImageMapUtilitiesTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(ImageMapUtilitiesTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public ImageMapUtilitiesTests(String name) { + super(name); + } + + /** + * Some checks for the htmlEscape() method. + */ + public void testHTMLEscape() { + assertEquals("", ImageMapUtilities.htmlEscape("")); + assertEquals("abc", ImageMapUtilities.htmlEscape("abc")); + assertEquals("&", ImageMapUtilities.htmlEscape("&")); + assertEquals(""", ImageMapUtilities.htmlEscape("\"")); + assertEquals("<", ImageMapUtilities.htmlEscape("<")); + assertEquals(">", ImageMapUtilities.htmlEscape(">")); + assertEquals("'", ImageMapUtilities.htmlEscape("\'")); + assertEquals("\abc", ImageMapUtilities.htmlEscape("\\abc")); + assertEquals("abc\n", ImageMapUtilities.htmlEscape("abc\n")); + } + + /** + * Some checks for the javascriptEscape() method. + */ + public void testJavascriptEscape() { + assertEquals("", ImageMapUtilities.javascriptEscape("")); + assertEquals("abc", ImageMapUtilities.javascriptEscape("abc")); + assertEquals("\\\'", ImageMapUtilities.javascriptEscape("\'")); + assertEquals("\\\"", ImageMapUtilities.javascriptEscape("\"")); + assertEquals("\\\\", ImageMapUtilities.javascriptEscape("\\")); + } + +} Added: trunk/tests/org/jfree/chart/imagemap/junit/OverLIBToolTipTagFragmentGeneratorTests.java =================================================================== --- trunk/tests/org/jfree/chart/imagemap/junit/OverLIBToolTipTagFragmentGeneratorTests.java (rev 0) +++ trunk/tests/org/jfree/chart/imagemap/junit/OverLIBToolTipTagFragmentGeneratorTests.java 2009-04-07 09:28:54 UTC (rev 1947) @@ -0,0 +1,86 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * -------------------------------------------- + * OverLIBToolTipTagFragmentGeneratorTests.java + * -------------------------------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 25-Mar-2009 : Version 1 (DG); + * + */ + +package org.jfree.chart.imagemap.junit; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator; + +/** + * Tests for the {@link OverLIBToolTipTagFragmentGenerator} class. + */ +public class OverLIBToolTipTagFragmentGeneratorTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(OverLIBToolTipTagFragmentGeneratorTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public OverLIBToolTipTagFragmentGeneratorTests(String name) { + super(name); + } + + /** + * Some checks for the generateURLFragment() method. + */ + public void testGenerateURLFragment() { + OverLIBToolTipTagFragmentGenerator g + = new OverLIBToolTipTagFragmentGenerator(); + assertEquals(" onMouseOver=\"return overlib('abc');\"" + + " onMouseOut=\"return nd();\"", + g.generateToolTipFragment("abc")); + assertEquals(" onMouseOver=\"return overlib(" + + "'It\\'s \\\"A\\\", 100.0');\" onMouseOut=\"return nd();\"", + g.generateToolTipFragment("It\'s \"A\", 100.0")); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 12:34:22
|
Revision: 1954 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1954&view=rev Author: mungady Date: 2009-04-07 12:34:18 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java trunk/source/org/jfree/data/DataUtilities.java trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java trunk/tests/org/jfree/data/junit/DataUtilitiesTests.java Modified: trunk/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java 2009-04-07 11:55:48 UTC (rev 1953) +++ trunk/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java 2009-04-07 12:34:18 UTC (rev 1954) @@ -39,6 +39,7 @@ * 01-Dec-2006 : Updated API docs (DG); * 26-Jun-2008 : Added CrosshairState (DG); * 14-Jan-2009 : Added visibleSeries[] array (PK); + * 04-Feb-2009 : Added getVisibleSeriesArray() method (DG); * */ @@ -197,6 +198,23 @@ } /** + * Returns a copy of the visible series array. + * + * @return The visible series array (possibly <code>null</code>). + * + * @since 1.0.13 + */ + public int[] getVisibleSeriesArray() { + if (this.visibleSeries == null) { + return null; + } + int[] result = new int[this.visibleSeries.length]; + System.arraycopy(this.visibleSeries, 0, result, 0, + this.visibleSeries.length); + return result; + } + + /** * Sets an array with the indices of the visible rows. * * @param visibleSeries the array (<code>null</code> permitted). Modified: trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java 2009-04-07 11:55:48 UTC (rev 1953) +++ trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java 2009-04-07 12:34:18 UTC (rev 1954) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------- * StackedBarRenderer3D.java * ------------------------- - * (C) Copyright 2000-2008, by Serge V. Grachov and Contributors. + * (C) Copyright 2000-2009, by Serge V. Grachov and Contributors. * * Original Author: Serge V. Grachov; * Contributor(s): David Gilbert (for Object Refinery Limited); @@ -83,6 +83,9 @@ * 21-Jun-2007 : Removed JCommon dependencies (DG); * 31-Jul-2007 : Added flag for handling zero values (DG); * 15-Aug-2008 : Fixed bug 2031407 - no negative zero for stack encoding (DG); + * 03-Feb-2009 : Fixed regression in findRangeBounds() method for null + * dataset (DG); + * 04-Feb-2009 : Handle seriesVisible flag (DG); * */ @@ -251,6 +254,9 @@ * @return The range (or <code>null</code> if the dataset is empty). */ public Range findRangeBounds(CategoryDataset dataset) { + if (dataset == null) { + return null; + } if (this.renderAsPercentages) { return new Range(0.0, 1.0); } @@ -310,16 +316,18 @@ * * @param dataset the dataset (<code>null</code> not permitted). * @param category the category key (<code>null</code> not permitted). + * @param includedRows the included rows. * @param base the base value. * @param asPercentages a flag that controls whether the values in the * list are converted to percentages of the total. * * @return The value list. * - * @since 1.2.0 + * @since 1.0.13 */ protected List createStackedValueList(CategoryDataset dataset, - Comparable category, double base, boolean asPercentages) { + Comparable category, int[] includedRows, double base, + boolean asPercentages) { List result = new ArrayList(); double posBase = base; @@ -327,13 +335,14 @@ double total = 0.0; if (asPercentages) { total = DataUtilities.calculateColumnTotal(dataset, - dataset.getColumnIndex(category)); + dataset.getColumnIndex(category), includedRows); } int baseIndex = -1; - int seriesCount = dataset.getRowCount(); - for (int s = 0; s < seriesCount; s++) { - Number n = dataset.getValue(dataset.getRowKey(s), category); + int rowCount = includedRows.length; + for (int i = 0; i < rowCount; i++) { + int r = includedRows[i]; + Number n = dataset.getValue(dataset.getRowKey(r), category); if (n == null) { continue; } @@ -347,7 +356,7 @@ baseIndex = 0; } posBase = posBase + v; - result.add(new Object[] {new Integer(s), new Double(posBase)}); + result.add(new Object[] {new Integer(r), new Double(posBase)}); } else if (v < 0.0) { if (baseIndex < 0) { @@ -355,7 +364,7 @@ baseIndex = 0; } negBase = negBase + v; // '+' because v is negative - result.add(0, new Object[] {new Integer(-s - 1), + result.add(0, new Object[] {new Integer(-r - 1), new Double(negBase)}); baseIndex++; } @@ -399,8 +408,8 @@ Comparable category = dataset.getColumnKey(column); List values = createStackedValueList(dataset, - dataset.getColumnKey(column), getBase(), - this.renderAsPercentages); + dataset.getColumnKey(column), state.getVisibleSeriesArray(), + getBase(), this.renderAsPercentages); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), Modified: trunk/source/org/jfree/data/DataUtilities.java =================================================================== --- trunk/source/org/jfree/data/DataUtilities.java 2009-04-07 11:55:48 UTC (rev 1953) +++ trunk/source/org/jfree/data/DataUtilities.java 2009-04-07 12:34:18 UTC (rev 1954) @@ -30,7 +30,7 @@ * (C) Copyright 2003-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; + * Contributor(s): Peter Kolb (patch 2511330); * * Changes * ------- @@ -41,6 +41,7 @@ * methods (DG); * 28-Jan-2009 : Added equal(double[][], double[][]) method (DG); * 28-Jan-2009 : Added clone(double[][]) method (DG); + * 04-Feb-2009 : Added calculateColumnTotal/RowTotal variants (PK); * */ @@ -120,6 +121,9 @@ * @return The total of the values in the specified column. */ public static double calculateColumnTotal(Values2D data, int column) { + if (data == null) { + throw new IllegalArgumentException("Null 'data' argument."); + } double total = 0.0; int rowCount = data.getRowCount(); for (int r = 0; r < rowCount; r++) { @@ -132,6 +136,37 @@ } /** + * Returns the total of the values in one column of the supplied data + * table by taking only the row numbers in the array into account. + * + * @param data the table of values (<code>null</code> not permitted). + * @param column the column index (zero-based). + * @param validRows the array with valid rows (zero-based). + * + * @return The total of the valid values in the specified column. + * + * @since 1.0.13 + */ + public static double calculateColumnTotal(Values2D data, int column, + int[] validRows) { + if (data == null) { + throw new IllegalArgumentException("Null 'data' argument."); + } + double total = 0.0; + int rowCount = data.getRowCount(); + for (int v = 0; v < validRows.length; v++) { + int row = validRows[v]; + if (row < rowCount) { + Number n = data.getValue(row, column); + if (n != null) { + total += n.doubleValue(); + } + } + } + return total; + } + + /** * Returns the total of the values in one row of the supplied data * table. * @@ -141,6 +176,9 @@ * @return The total of the values in the specified row. */ public static double calculateRowTotal(Values2D data, int row) { + if (data == null) { + throw new IllegalArgumentException("Null 'data' argument."); + } double total = 0.0; int columnCount = data.getColumnCount(); for (int c = 0; c < columnCount; c++) { @@ -153,6 +191,37 @@ } /** + * Returns the total of the values in one row of the supplied data + * table by taking only the column numbers in the array into account. + * + * @param data the table of values (<code>null</code> not permitted). + * @param row the row index (zero-based). + * @param validCols the array with valid cols (zero-based). + * + * @return The total of the valid values in the specified row. + * + * @since 1.0.13 + */ + public static double calculateRowTotal(Values2D data, int row, + int[] validCols) { + if (data == null) { + throw new IllegalArgumentException("Null 'data' argument."); + } + double total = 0.0; + int colCount = data.getColumnCount(); + for (int v = 0; v < validCols.length; v++) { + int col = validCols[v]; + if (col < colCount) { + Number n = data.getValue(row, col); + if (n != null) { + total += n.doubleValue(); + } + } + } + return total; + } + + /** * Constructs an array of <code>Number</code> objects from an array of * <code>double</code> primitives. * Modified: trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java 2009-04-07 11:55:48 UTC (rev 1953) +++ trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java 2009-04-07 12:34:18 UTC (rev 1954) @@ -69,9 +69,10 @@ */ static class MyRenderer extends StackedBarRenderer3D { public List createStackedValueList(CategoryDataset dataset, - Comparable category, double base, boolean asPercentages) { - return super.createStackedValueList(dataset, category, base, - asPercentages); + Comparable category, int[] includedRows, double base, + boolean asPercentages) { + return super.createStackedValueList(dataset, category, + includedRows, base, asPercentages); } } @@ -172,7 +173,7 @@ DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "s0", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0 }, 0.0, false); assertEquals(2, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(1.0), ((Object[]) l.get(1))[1]); @@ -185,7 +186,7 @@ DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(-1.0, "s0", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0 }, 0.0, false); assertEquals(2, l.size()); assertEquals(new Double(-1.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -198,7 +199,7 @@ DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(0.0, "s0", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0 }, 0.0, false); assertEquals(2, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -211,7 +212,7 @@ DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(null, "s0", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0 }, 0.0, false); assertEquals(0, l.size()); } @@ -223,7 +224,8 @@ d.addValue(1.0, "s0", "c0"); d.addValue(1.1, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(1.0), ((Object[]) l.get(1))[1]); @@ -238,7 +240,8 @@ d.addValue(1.0, "s0", "c0"); d.addValue(-1.1, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(-1.1), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -253,7 +256,8 @@ d.addValue(1.0, "s0", "c0"); d.addValue(0.0, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(1.0), ((Object[]) l.get(1))[1]); @@ -268,7 +272,8 @@ d.addValue(1.0, "s0", "c0"); d.addValue(null, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(2, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(1.0), ((Object[]) l.get(1))[1]); @@ -282,7 +287,8 @@ d.addValue(-1.0, "s0", "c0"); d.addValue(1.1, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(-1.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -297,7 +303,8 @@ d.addValue(-1.0, "s0", "c0"); d.addValue(-1.1, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(-2.1), ((Object[]) l.get(0))[1]); assertEquals(new Double(-1.0), ((Object[]) l.get(1))[1]); @@ -312,7 +319,8 @@ d.addValue(-1.0, "s0", "c0"); d.addValue(0.0, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(-1.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -327,7 +335,8 @@ d.addValue(-1.0, "s0", "c0"); d.addValue(null, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(2, l.size()); assertEquals(new Double(-1.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -341,7 +350,8 @@ d.addValue(0.0, "s0", "c0"); d.addValue(1.1, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -356,7 +366,8 @@ d.addValue(0.0, "s0", "c0"); d.addValue(-1.1, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(-1.1), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -371,7 +382,8 @@ d.addValue(0.0, "s0", "c0"); d.addValue(0.0, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -386,7 +398,8 @@ d.addValue(0.0, "s0", "c0"); d.addValue(null, "s1", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1 }, 0.0, + false); assertEquals(2, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(0.0), ((Object[]) l.get(1))[1]); @@ -401,7 +414,8 @@ d.addValue(null, "s1", "c0"); d.addValue(2.0, "s2", "c0"); MyRenderer r = new MyRenderer(); - List l = r.createStackedValueList(d, "c0", 0.0, false); + List l = r.createStackedValueList(d, "c0", new int[] { 0, 1, 2 }, 0.0, + false); assertEquals(3, l.size()); assertEquals(new Double(0.0), ((Object[]) l.get(0))[1]); assertEquals(new Double(1.0), ((Object[]) l.get(1))[1]); Modified: trunk/tests/org/jfree/data/junit/DataUtilitiesTests.java =================================================================== --- trunk/tests/org/jfree/data/junit/DataUtilitiesTests.java 2009-04-07 11:55:48 UTC (rev 1953) +++ trunk/tests/org/jfree/data/junit/DataUtilitiesTests.java 2009-04-07 12:34:18 UTC (rev 1954) @@ -37,6 +37,7 @@ * 03-Mar-2005 : Version 1 (DG); * 28-Jan-2009 : Added tests for equal(double[][], double[][]) method (DG); * 28-Jan-2009 : Added tests for clone(double[][]) (DG); + * 04-Feb-2009 : Added tests for new calculateColumnTotal/RowTotal methods (DG); * */ @@ -94,6 +95,38 @@ } /** + * Some checks for the calculateColumnTotal() method. + */ + public void testCalculateColumnTotal2() { + DefaultKeyedValues2D table = new DefaultKeyedValues2D(); + table.addValue(new Double(1.0), "R0", "C0"); + table.addValue(new Double(2.0), "R0", "C1"); + table.addValue(new Double(3.0), "R1", "C0"); + table.addValue(new Double(4.0), "R1", "C1"); + assertEquals(4.0, DataUtilities.calculateColumnTotal(table, 0, + new int[] {0, 1}), EPSILON); + assertEquals(1.0, DataUtilities.calculateColumnTotal(table, 0, + new int[] {0}), EPSILON); + assertEquals(3.0, DataUtilities.calculateColumnTotal(table, 0, + new int[] {1}), EPSILON); + assertEquals(0.0, DataUtilities.calculateColumnTotal(table, 0, + new int[] {}), EPSILON); + + assertEquals(6.0, DataUtilities.calculateColumnTotal(table, 1, + new int[] {0, 1}), EPSILON); + assertEquals(2.0, DataUtilities.calculateColumnTotal(table, 1, + new int[] {0}), EPSILON); + assertEquals(4.0, DataUtilities.calculateColumnTotal(table, 1, + new int[] {1}), EPSILON); + + table.setValue(null, "R1", "C1"); + assertEquals(2.0, DataUtilities.calculateColumnTotal(table, 1, + new int[] {0, 1}), EPSILON); + assertEquals(0.0, DataUtilities.calculateColumnTotal(table, 1, + new int[] {1}), EPSILON); + } + + /** * Some checks for the calculateRowTotal() method. */ public void testCalculateRowTotal() { @@ -109,6 +142,39 @@ } /** + * Some checks for the calculateRowTotal() method. + */ + public void testCalculateRowTotal2() { + DefaultKeyedValues2D table = new DefaultKeyedValues2D(); + table.addValue(new Double(1.0), "R0", "C0"); + table.addValue(new Double(2.0), "R0", "C1"); + table.addValue(new Double(3.0), "R1", "C0"); + table.addValue(new Double(4.0), "R1", "C1"); + assertEquals(3.0, DataUtilities.calculateRowTotal(table, 0, + new int[] {0, 1}), EPSILON); + assertEquals(1.0, DataUtilities.calculateRowTotal(table, 0, + new int[] {0}), EPSILON); + assertEquals(2.0, DataUtilities.calculateRowTotal(table, 0, + new int[] {1}), EPSILON); + assertEquals(0.0, DataUtilities.calculateRowTotal(table, 0, + new int[] {}), EPSILON); + + assertEquals(7.0, DataUtilities.calculateRowTotal(table, 1, + new int[] {0, 1}), EPSILON); + assertEquals(3.0, DataUtilities.calculateRowTotal(table, 1, + new int[] {0}), EPSILON); + assertEquals(4.0, DataUtilities.calculateRowTotal(table, 1, + new int[] {1}), EPSILON); + assertEquals(0.0, DataUtilities.calculateRowTotal(table, 1, + new int[] {}), EPSILON); + table.setValue(null, "R1", "C1"); + assertEquals(3.0, DataUtilities.calculateRowTotal(table, 1, + new int[] {0, 1}), EPSILON); + assertEquals(0.0, DataUtilities.calculateRowTotal(table, 1, + new int[] {1}), EPSILON); + } + + /** * Some tests for the equal(double[][], double[][]) method. */ public void testEqual() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 11:34:21
|
Revision: 1951 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1951&view=rev Author: mungady Date: 2009-04-07 11:34:18 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/JFreeChart.java trunk/source/org/jfree/chart/axis/CategoryAxis.java trunk/source/org/jfree/chart/axis/DateAxis.java trunk/source/org/jfree/chart/axis/DateTickUnit.java trunk/source/org/jfree/chart/axis/LogAxis.java trunk/source/org/jfree/chart/title/LegendTitle.java trunk/source/org/jfree/chart/title/TextTitle.java trunk/tests/org/jfree/chart/axis/junit/DateAxisTests.java trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java Added Paths: ----------- trunk/source/org/jfree/chart/entity/JFreeChartEntity.java trunk/source/org/jfree/chart/entity/TitleEntity.java Modified: trunk/source/org/jfree/chart/JFreeChart.java =================================================================== --- trunk/source/org/jfree/chart/JFreeChart.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/JFreeChart.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------- * JFreeChart.java * --------------- - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrzej Porebski; @@ -36,6 +36,7 @@ * Christian W. Zuckschwerdt; * Klaus Rheinwald; * Nicolas Brodu; + * Peter Kolb (patch 2603321); * * NOTE: The above list of contributors lists only the people that have * contributed to this source file (JFreeChart.java) - for a list of ALL @@ -145,6 +146,9 @@ * 23-Apr-2008 : Added new contributor (Diego Pierangeli) (DG); * 16-May-2008 : Added new contributor (Michael Siemer) (DG); * 19-Sep-2008 : Check for title visibility (DG); + * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by + * Jess Thrysoee (DG); + * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * */ @@ -185,6 +189,7 @@ import org.jfree.chart.block.LineBorder; import org.jfree.chart.block.RectangleConstraint; import org.jfree.chart.entity.EntityCollection; +import org.jfree.chart.entity.JFreeChartEntity; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.event.ChartProgressEvent; @@ -1142,11 +1147,17 @@ notifyListeners(new ChartProgressEvent(this, this, ChartProgressEvent.DRAWING_STARTED, 0)); + EntityCollection entities = null; // record the chart area, if info is requested... if (info != null) { info.clear(); info.setChartArea(chartArea); + entities = info.getEntityCollection(); } + if (entities != null) { + entities.add(new JFreeChartEntity((Rectangle2D) chartArea.clone(), + this)); + } // ensure no drawing occurs outside chart area... Shape savedClip = g2.getClip(); @@ -1193,10 +1204,6 @@ nonTitleArea.setRect(chartArea); this.padding.trim(nonTitleArea); - EntityCollection entities = null; - if (info != null) { - entities = info.getEntityCollection(); - } if (this.title != null) { EntityCollection e = drawTitle(this.title, g2, nonTitleArea, (entities != null)); @@ -1774,6 +1781,7 @@ new Contributor("Pascal Collet", "-"), new Contributor("Martin Cordova", "-"), new Contributor("Paolo Cova", "-"), + new Contributor("Greg Darke", "-"), new Contributor("Mike Duffy", "-"), new Contributor("Don Elliott", "-"), new Contributor("David Forslund", "-"), @@ -1829,6 +1837,7 @@ new Contributor("Jean-Luc SCHWAB", "-"), new Contributor("Bryan Scott", "-"), new Contributor("Tobias Selb", "-"), + new Contributor("Darshan Shah", "-"), new Contributor("Mofeed Shahin", "-"), new Contributor("Michael Siemer", "-"), new Contributor("Pady Srinivasan", "-"), Modified: trunk/source/org/jfree/chart/axis/CategoryAxis.java =================================================================== --- trunk/source/org/jfree/chart/axis/CategoryAxis.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/axis/CategoryAxis.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -31,7 +31,7 @@ * * Original Author: David Gilbert; * Contributor(s): Pady Srinivasan (patch 1217634); - * Peter Kolb (patch 2497611); + * Peter Kolb (patches 2497611 and 2603321); * * Changes * ------- @@ -94,6 +94,7 @@ * 27-Oct-2008 : Set font on Graphics2D when creating category labels (DG); * 14-Jan-2009 : Added new variant of getCategorySeriesMiddle() to make it * simpler for renderers with hidden series (PK); + * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * */ @@ -916,12 +917,9 @@ * * @return The axis state (never <code>null</code>). */ - public AxisState draw(Graphics2D g2, - double cursor, - Rectangle2D plotArea, - Rectangle2D dataArea, - RectangleEdge edge, - PlotRenderingInfo plotState) { + public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, + Rectangle2D dataArea, RectangleEdge edge, + PlotRenderingInfo plotState) { // if the axis is not visible, don't draw it... if (!isVisible()) { @@ -938,7 +936,7 @@ plotState); state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state, plotState); - + createAndAddEntity(cursor, state, dataArea, edge, plotState); return state; } Modified: trunk/source/org/jfree/chart/axis/DateAxis.java =================================================================== --- trunk/source/org/jfree/chart/axis/DateAxis.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/axis/DateAxis.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -36,7 +36,7 @@ * Bill Kelemen; * Pawel Pabis; * Chris Boek; - * Peter Kolb (patch 1934255); + * Peter Kolb (patches 1934255 and 2603321); * Andrew Mickish (patch 1870189); * Fawad Halim (bug 2201869); * @@ -127,6 +127,7 @@ * 25-Sep-2008 : Added minor tick support, see patch 1934255 by Peter Kolb (DG); * 25-Nov-2008 : Added bug fix 2201869 by Fawad Halim (DG); * 21-Jan-2009 : Check tickUnit for minor tick count (DG); + * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * */ @@ -881,7 +882,7 @@ Calendar calendar = Calendar.getInstance(this.timeZone, this.locale); calendar.setTime(date); - int count = unit.getCount(); + int count = unit.getMultiple(); int current = calendar.get(unit.getCalendarField()); int value = count * (current / count); @@ -1092,7 +1093,7 @@ Date previous = previousStandardDate(date, unit); Calendar calendar = Calendar.getInstance(this.timeZone, this.locale); calendar.setTime(previous); - calendar.add(unit.getCalendarField(), unit.getCount()); + calendar.add(unit.getCalendarField(), unit.getMultiple()); return calendar.getTime(); } @@ -1676,11 +1677,11 @@ long currentTickTime = tickDate.getTime(); tickDate = unit.addToDate(tickDate, this.timeZone); long nextTickTime = tickDate.getTime(); - for (int minorTick = 1; minorTick < getMinorTickCount(); + for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++){ long minorTickTime = currentTickTime + (nextTickTime - currentTickTime) - * minorTick / getMinorTickCount(); + * minorTick / minorTickSpaces; if (getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) { result.add(new DateTick(TickType.MINOR, @@ -1788,11 +1789,11 @@ long currentTickTime = tickDate.getTime(); tickDate = unit.addToDate(tickDate, this.timeZone); long nextTickTime = tickDate.getTime(); - for(int minorTick = 1; minorTick < getMinorTickCount(); + for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++){ long minorTickTime = currentTickTime + (nextTickTime - currentTickTime) - * minorTick / getMinorTickCount(); + * minorTick / minorTickSpaces; if (getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) { result.add(new DateTick(TickType.MINOR, @@ -1825,12 +1826,9 @@ * * @return The axis state (never <code>null</code>). */ - public AxisState draw(Graphics2D g2, - double cursor, - Rectangle2D plotArea, - Rectangle2D dataArea, - RectangleEdge edge, - PlotRenderingInfo plotState) { + public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, + Rectangle2D dataArea, RectangleEdge edge, + PlotRenderingInfo plotState) { // if the axis is not visible, don't draw it... if (!isVisible()) { @@ -1850,7 +1848,7 @@ // returned)... state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state, plotState); - + createAndAddEntity(cursor, state, dataArea, edge, plotState); return state; } Modified: trunk/source/org/jfree/chart/axis/DateTickUnit.java =================================================================== --- trunk/source/org/jfree/chart/axis/DateTickUnit.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/axis/DateTickUnit.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,13 +27,13 @@ * ----------------- * DateTickUnit.java * ----------------- - * (C) Copyright 2000-2008, by Object Refinery Limited. + * (C) Copyright 2000-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Chris Boek; * - * Changes (from 8-Nov-2002) - * -------------------------- + * Changes + * ------- * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG); * 27-Nov-2002 : Added IllegalArgumentException to getMillisecondCount() * method (DG); @@ -49,6 +49,8 @@ * TimeZone) (CB); * 21-Jun-2007 : Removed JCommon dependencies (DG); * 09-Jun-2008 : Deprecated addToDate(Date) (DG); + * 09-Jan-2009 : Replaced the unit and rollUnit fields with an enumerated + * type (DG); * */ @@ -63,7 +65,7 @@ import org.jfree.chart.util.ObjectUtilities; /** - * A tick unit for use by subclasses of {@link DateAxis}. Instances of this + * A tick unit for use by subclasses of {@link DateAxis}. Instances of this * class are immutable. */ public class DateTickUnit extends TickUnit implements Serializable { @@ -163,11 +165,11 @@ } /** - * Returns the unit count. + * Returns the unit multiple. * - * @return The unit count. + * @return The unit multiple (always > 0). */ - public int getCount() { + public int getMultiple() { return this.count; } @@ -216,23 +218,6 @@ } /** - * Calculates a new date by adding this unit to the base date, with - * calculations performed in the default timezone and locale. - * - * @param base the base date. - * - * @return A new date one unit after the base date. - * - * @see #addToDate(Date, TimeZone) - * - * @deprecated As of JFreeChart 1.0.10, this method is deprecated - you - * should use {@link #addToDate(Date, TimeZone)} instead. - */ - public Date addToDate(Date base) { - return addToDate(base, TimeZone.getDefault()); - } - - /** * Calculates a new date by adding this unit to the base date. * * @param base the base date. @@ -299,7 +284,6 @@ return this.unitType.getCalendarField(); } - /** * Returns the (approximate) number of milliseconds for the given unit and * unit count. @@ -345,6 +329,23 @@ } /** + * A utility method to put a default in place if a null formatter is + * supplied. + * + * @param formatter the formatter (<code>null</code> permitted). + * + * @return The formatter if it is not null, otherwise a default. + */ + private static DateFormat notNull(DateFormat formatter) { + if (formatter == null) { + return DateFormat.getDateInstance(DateFormat.SHORT); + } + else { + return formatter; + } + } + + /** * Tests this unit for equality with another object. * * @param obj the object (<code>null</code> permitted). Modified: trunk/source/org/jfree/chart/axis/LogAxis.java =================================================================== --- trunk/source/org/jfree/chart/axis/LogAxis.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/axis/LogAxis.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -460,6 +460,7 @@ plotState); state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state, plotState); + createAndAddEntity(cursor, state, dataArea, edge, plotState); return state; } Added: trunk/source/org/jfree/chart/entity/JFreeChartEntity.java =================================================================== --- trunk/source/org/jfree/chart/entity/JFreeChartEntity.java (rev 0) +++ trunk/source/org/jfree/chart/entity/JFreeChartEntity.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -0,0 +1,210 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * --------------------- + * JFreeChartEntity.java + * -------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: Peter Kolb; + * Contributor(s): ; + * + * Changes: + * -------- + * 15-Feb-2009 : Version 1 (PK); + * + */ + +package org.jfree.chart.entity; + +import java.awt.Shape; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.util.HashUtilities; +import org.jfree.chart.util.ObjectUtilities; +import org.jfree.chart.util.SerialUtilities; + +/** + * A class that captures information about an entire chart. + * + * @since 1.0.13 + */ +public class JFreeChartEntity extends ChartEntity { + + /** For serialization. */ + private static final long serialVersionUID = -4445994133561919083L; + //same as for ChartEntity! + + /** The chart. */ + private JFreeChart chart; + + /** + * Creates a new chart entity. + * + * @param area the area (<code>null</code> not permitted). + * @param chart the chart (<code>null</code> not permitted). + */ + public JFreeChartEntity(Shape area, JFreeChart chart) { + // defer argument checks... + this(area, chart, null); + } + + /** + * Creates a new chart entity. + * + * @param area the area (<code>null</code> not permitted). + * @param chart the chart (<code>null</code> not permitted). + * @param toolTipText the tool tip text (<code>null</code> permitted). + */ + public JFreeChartEntity(Shape area, JFreeChart chart, String toolTipText) { + // defer argument checks... + this(area, chart, toolTipText, null); + } + + /** + * Creates a new chart entity. + * + * @param area the area (<code>null</code> not permitted). + * @param chart the chart (<code>null</code> not permitted). + * @param toolTipText the tool tip text (<code>null</code> permitted). + * @param urlText the URL text for HTML image maps (<code>null</code> + * permitted). + */ + public JFreeChartEntity(Shape area, JFreeChart chart, String toolTipText, + String urlText) { + super(area, toolTipText, urlText); + if (chart == null) { + throw new IllegalArgumentException("Null 'chart' argument."); + } + + this.chart = chart; + } + + /** + * Returns the chart that occupies the entity area. + * + * @return The chart (never <code>null</code>). + */ + public JFreeChart getChart() { + return this.chart; + } + + /** + * Returns a string representation of the chart entity, useful for + * debugging. + * + * @return A string. + */ + public String toString() { + StringBuffer buf = new StringBuffer("JFreeChartEntity: "); + buf.append("tooltip = "); + buf.append(getToolTipText()); + return buf.toString(); + } + + /** + * Tests the entity for equality with an arbitrary object. + * + * @param obj the object to test against (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof JFreeChartEntity)) { + return false; + } + JFreeChartEntity that = (JFreeChartEntity) obj; + if (!getArea().equals(that.getArea())) { + return false; + } + if (!ObjectUtilities.equal(getToolTipText(), that.getToolTipText())) { + return false; + } + if (!ObjectUtilities.equal(getURLText(), that.getURLText())) { + return false; + } + if (!(this.chart.equals(that.chart))) { + return false; + } + return true; + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int result = 39; + result = HashUtilities.hashCode(result, getToolTipText()); + result = HashUtilities.hashCode(result, getURLText()); + return result; + } + + /** + * Returns a clone of the entity. + * + * @return A clone. + * + * @throws CloneNotSupportedException if there is a problem cloning the + * entity. + */ + 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.writeShape(getArea(), 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(); + setArea(SerialUtilities.readShape(stream)); + } + +} Added: trunk/source/org/jfree/chart/entity/TitleEntity.java =================================================================== --- trunk/source/org/jfree/chart/entity/TitleEntity.java (rev 0) +++ trunk/source/org/jfree/chart/entity/TitleEntity.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -0,0 +1,210 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ---------------- + * TitleEntity.java + * ---------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: Peter Kolb; + * Contributor(s): ; + * + * Changes: + * -------- + * 15-Feb-2009 : Version 1 (PK); + * + */ + +package org.jfree.chart.entity; + +import java.awt.Shape; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import org.jfree.chart.title.Title; +import org.jfree.chart.util.HashUtilities; +import org.jfree.chart.util.ObjectUtilities; +import org.jfree.chart.util.SerialUtilities; + +/** + * A class that captures information about a Title of a chart. + * + * @since 1.0.13 + */ +public class TitleEntity extends ChartEntity { + + /** For serialization. */ + private static final long serialVersionUID = -4445994133561919083L; + //same as for ChartEntity! + + /** The Title for the entity. */ + private Title title; + + /** + * Creates a new chart entity. + * + * @param area the area (<code>null</code> not permitted). + * @param title the title (<code>null</code> not permitted). + */ + public TitleEntity(Shape area, Title title) { + // defer argument checks... + this(area, title, null); + } + + /** + * Creates a new chart entity. + * + * @param area the area (<code>null</code> not permitted). + * @param title the title (<code>null</code> not permitted). + * @param toolTipText the tool tip text (<code>null</code> permitted). + */ + public TitleEntity(Shape area, Title title, String toolTipText) { + // defer argument checks... + this(area, title, toolTipText, null); + } + + /** + * Creates a new entity. + * + * @param area the area (<code>null</code> not permitted). + * @param title the title (<code>null</code> not permitted). + * @param toolTipText the tool tip text (<code>null</code> permitted). + * @param urlText the URL text for HTML image maps (<code>null</code> + * permitted). + */ + public TitleEntity(Shape area, Title title, String toolTipText, + String urlText) { + super(area, toolTipText, urlText); + if (title == null) { + throw new IllegalArgumentException("Null 'title' argument."); + } + + this.title = title; + } + + /** + * Returns the title that occupies the entity area. + * + * @return The title (never <code>null</code>). + */ + public Title getTitle() { + return this.title; + } + + /** + * Returns a string representation of the chart entity, useful for + * debugging. + * + * @return A string. + */ + public String toString() { + StringBuffer buf = new StringBuffer("TitleEntity: "); + buf.append("tooltip = "); + buf.append(getToolTipText()); + return buf.toString(); + } + + /** + * Tests the entity for equality with an arbitrary object. + * + * @param obj the object to test against (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof TitleEntity)) { + return false; + } + TitleEntity that = (TitleEntity) obj; + if (!getArea().equals(that.getArea())) { + return false; + } + if (!ObjectUtilities.equal(getToolTipText(), that.getToolTipText())) { + return false; + } + if (!ObjectUtilities.equal(getURLText(), that.getURLText())) { + return false; + } + if (!(this.title.equals(that.title))) { + return false; + } + return true; + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int result = 41; + result = HashUtilities.hashCode(result, getToolTipText()); + result = HashUtilities.hashCode(result, getURLText()); + return result; + } + + /** + * Returns a clone of the entity. + * + * @return A clone. + * + * @throws CloneNotSupportedException if there is a problem cloning the + * entity. + */ + 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.writeShape(getArea(), 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(); + setArea(SerialUtilities.readShape(stream)); + } + +} \ No newline at end of file Modified: trunk/source/org/jfree/chart/title/LegendTitle.java =================================================================== --- trunk/source/org/jfree/chart/title/LegendTitle.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/title/LegendTitle.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------- * LegendTitle.java * ---------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Pierre-Marie Le Biot; @@ -55,6 +55,7 @@ * 18-May-2007 : Pass seriesKey and dataset to legend item block (DG); * 20-Jun-2007 : Removed JCommon dependencies (DG); * 15-Aug-2008 : Added getWrapper() method (DG); + * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * */ @@ -77,12 +78,17 @@ import org.jfree.chart.block.Block; import org.jfree.chart.block.BlockContainer; import org.jfree.chart.block.BlockFrame; +import org.jfree.chart.block.BlockResult; import org.jfree.chart.block.BorderArrangement; import org.jfree.chart.block.CenterArrangement; import org.jfree.chart.block.ColumnArrangement; +import org.jfree.chart.block.EntityBlockParams; import org.jfree.chart.block.FlowArrangement; import org.jfree.chart.block.LabelBlock; import org.jfree.chart.block.RectangleConstraint; +import org.jfree.chart.entity.EntityCollection; +import org.jfree.chart.entity.StandardEntityCollection; +import org.jfree.chart.entity.TitleEntity; import org.jfree.chart.event.TitleChangeEvent; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; @@ -522,6 +528,13 @@ */ public Object draw(Graphics2D g2, Rectangle2D area, Object params) { Rectangle2D target = (Rectangle2D) area.clone(); + Rectangle2D hotspot = (Rectangle2D) area.clone(); + StandardEntityCollection sec = null; + if (params instanceof EntityBlockParams + && ((EntityBlockParams) params).getGenerateEntities()) { + sec = new StandardEntityCollection(); + sec.add(new TitleEntity(hotspot,this)); + } target = trimMargin(target); if (this.backgroundPaint != null) { g2.setPaint(this.backgroundPaint); @@ -535,8 +548,16 @@ container = this.items; } target = trimPadding(target); - return container.draw(g2, target, params); + Object val = container.draw(g2, target, params); + if (val instanceof BlockResult){ + EntityCollection ec = ((BlockResult) val).getEntityCollection(); + if (ec != null && sec != null){ + sec.addAll(ec); + ((BlockResult) val).setEntityCollection(sec); } + } + return val; + } /** * Returns the wrapper container, if any. Modified: trunk/source/org/jfree/chart/title/TextTitle.java =================================================================== --- trunk/source/org/jfree/chart/title/TextTitle.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/source/org/jfree/chart/title/TextTitle.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,11 +27,12 @@ * -------------- * TextTitle.java * -------------- - * (C) Copyright 2000-2008, by David Berry and Contributors. + * (C) Copyright 2000-2009, by David Berry and Contributors. * * Original Author: David Berry; * Contributor(s): David Gilbert (for Object Refinery Limited); * Nicolas Brodu; + * Peter Kolb - patch 2603321; * * Changes (from 18-Sep-2001) * -------------------------- @@ -77,6 +78,8 @@ * 19-Dec-2007 : Implemented some of the missing arrangement options (DG); * 28-Apr-2008 : Added option for maximum lines, and fixed minor bugs in * equals() method (DG); + * 19-Mar-2009 : Changed ChartEntity to TitleEntity - see patch 2603321 by + * Peter Kolb (DG); * */ @@ -99,6 +102,7 @@ import org.jfree.chart.entity.ChartEntity; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.StandardEntityCollection; +import org.jfree.chart.entity.TitleEntity; import org.jfree.chart.event.TitleChangeEvent; import org.jfree.chart.text.G2TextMeasurer; import org.jfree.chart.text.TextBlock; @@ -697,7 +701,8 @@ if (params instanceof EntityBlockParams) { EntityBlockParams p = (EntityBlockParams) params; if (p.getGenerateEntities()) { - entity = new ChartEntity(area, this.toolTipText, this.urlText); + entity = new TitleEntity(area, this, this.toolTipText, + this.urlText); } } area = trimBorder(area); Modified: trunk/tests/org/jfree/chart/axis/junit/DateAxisTests.java =================================================================== --- trunk/tests/org/jfree/chart/axis/junit/DateAxisTests.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/tests/org/jfree/chart/axis/junit/DateAxisTests.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -355,13 +355,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -370,19 +370,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -391,13 +391,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -428,13 +428,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -443,19 +443,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -464,13 +464,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -501,13 +501,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -516,19 +516,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -537,13 +537,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -574,13 +574,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -589,19 +589,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -610,13 +610,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -647,13 +647,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -662,19 +662,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -683,13 +683,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -720,13 +720,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -735,19 +735,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -756,13 +756,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -793,13 +793,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -808,19 +808,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -829,13 +829,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -866,13 +866,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -881,19 +881,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -902,13 +902,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -939,13 +939,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -954,19 +954,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -975,13 +975,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -1012,13 +1012,13 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); @@ -1027,19 +1027,19 @@ axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); @@ -1048,13 +1048,13 @@ axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); } @@ -1079,7 +1079,7 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); @@ -1088,7 +1088,7 @@ axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); @@ -1097,7 +1097,7 @@ axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); } @@ -1122,7 +1122,7 @@ axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); - Date nsd = unit.addToDate(psd); + Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); @@ -1131,7 +1131,7 @@ axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); @@ -1140,7 +1140,7 @@ axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); - nsd = unit.addToDate(psd); + nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); } Modified: trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java =================================================================== --- trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java 2009-04-07 11:04:48 UTC (rev 1950) +++ trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java 2009-04-07 11:34:18 UTC (rev 1951) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------ * JFreeChartTestSuite.java * ------------------------ - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -45,6 +45,8 @@ * 18-Jan-2005 : Added main() method (DG); * 08-Jun-2005 : Added tests for org.jfree.chart.needle package (DG); * 26-Jan-2007 : Added tests for org.jfree.data.time.ohlc package (DG); + * 24-Oct-2007 : Added tests for org.jfree.chart.plot.dial package (DG); + * 25-Mar-2009 : Added missing test suite (org.jfree.data.general) (DG); * */ @@ -70,6 +72,7 @@ import org.jfree.chart.util.junit.UtilPackageTests; import org.jfree.data.category.junit.DataCategoryPackageTests; import org.jfree.data.gantt.junit.DataGanttPackageTests; +import org.jfree.data.general.junit.DataGeneralPackageTests; import org.jfree.data.junit.DataPackageTests; import org.jfree.data.statistics.junit.DataStatisticsPackageTests; import org.jfree.data.time.junit.DataTimePackageTests; @@ -106,11 +109,12 @@ suite.addTest(UtilPackageTests.suite()); suite.addTest(DataPackageTests.suite()); suite.addTest(DataCategoryPackageTests.suite()); + suite.addTest(DataGanttPackageTests.suite()); + suite.addTest(DataGeneralPackageTests.suite()); suite.addTest(DataStatisticsPackageTests.suite()); suite.addTest(DataTimePackageTests.suite()); suite.addTest(OHLCPackageTests.suite()); suite.addTest(DataXYPackageTests.suite()); - suite.addTest(DataGanttPackageTests.suite()); return suite; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 13:50:57
|
Revision: 1956 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1956&view=rev Author: mungady Date: 2009-04-07 13:50:50 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/data/xy/XYSeries.java trunk/source/org/jfree/data/xy/XYSeriesCollection.java trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java trunk/tests/org/jfree/data/xy/junit/XYSeriesCollectionTests.java trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java Modified: trunk/source/org/jfree/data/xy/XYSeries.java =================================================================== --- trunk/source/org/jfree/data/xy/XYSeries.java 2009-04-07 12:46:47 UTC (rev 1955) +++ trunk/source/org/jfree/data/xy/XYSeries.java 2009-04-07 13:50:50 UTC (rev 1956) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------- * XYSeries.java * ------------- - * (C) Copyright 2001-2008, Object Refinery Limited and Contributors. + * (C) Copyright 2001-2009, Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Aaron Metzger; @@ -72,6 +72,7 @@ * 01-May-2008 : Fixed bug 1955483 in addOrUpdate() method, thanks to * Ted Schwartz (DG); * 24-Nov-2008 : Further fix for 1955483 (DG); + * 06-Mar-2009 : Added minX, maxX, minY and maxY fields (DG); * */ @@ -79,8 +80,8 @@ import java.io.Serializable; import java.util.Collections; +import java.util.Iterator; import java.util.List; - import org.jfree.chart.util.ObjectUtilities; import org.jfree.data.general.Series; import org.jfree.data.general.SeriesChangeEvent; @@ -108,12 +109,27 @@ /** The maximum number of items for the series. */ private int maximumItemCount = Integer.MAX_VALUE; - /** A flag that controls whether the items are automatically sorted. */ + /** + * A flag that controls whether the items are automatically sorted + * (by x-value ascending). + */ private boolean autoSort; /** A flag that controls whether or not duplicate x-values are allowed. */ private boolean allowDuplicateXValues; + /** The lowest x-value in the series, excluding Double.NaN values. */ + private double minX; + + /** The highest x-value in the series, excluding Double.NaN values. */ + private double maxX; + + /** The lowest y-value in the series, excluding Double.NaN values. */ + private double minY; + + /** The highest y-value in the series, excluding Double.NaN values. */ + private double maxY; + /** * Creates a new empty series. By default, items added to the series will * be sorted into ascending order by x-value, and duplicate x-values will @@ -147,16 +163,154 @@ * @param allowDuplicateXValues a flag that controls whether duplicate * x-values are allowed. */ - public XYSeries(Comparable key, - boolean autoSort, + public XYSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) { super(key); this.data = new java.util.ArrayList(); this.autoSort = autoSort; this.allowDuplicateXValues = allowDuplicateXValues; + this.minX = Double.NaN; + this.maxX = Double.NaN; + this.minY = Double.NaN; + this.maxY = Double.NaN; } /** + * Returns the smallest x-value in the series, ignoring any Double.NaN + * values. This method returns Double.NaN if there is no smallest x-value + * (for example, when the series is empty). + * + * @return The smallest x-value. + * + * @see #getMaxX() + * + * @since 1.0.13 + */ + public double getMinX() { + return this.minX; + } + + /** + * Returns the largest x-value in the series, ignoring any Double.NaN + * values. This method returns Double.NaN if there is no largest x-value + * (for example, when the series is empty). + * + * @return The largest x-value. + * + * @see #getMinX() + * + * @since 1.0.13 + */ + public double getMaxX() { + return this.maxX; + } + + /** + * Returns the smallest y-value in the series, ignoring any null and + * Double.NaN values. This method returns Double.NaN if there is no + * smallest y-value (for example, when the series is empty). + * + * @return The smallest y-value. + * + * @see #getMaxY() + * + * @since 1.0.13 + */ + public double getMinY() { + return this.minY; + } + + /** + * Returns the largest y-value in the series, ignoring any Double.NaN + * values. This method returns Double.NaN if there is no largest y-value + * (for example, when the series is empty). + * + * @return The largest y-value. + * + * @see #getMinY() + * + * @since 1.0.13 + */ + public double getMaxY() { + return this.maxY; + } + + /** + * Updates the cached values for the minimum and maximum data values. + * + * @param item the item added (<code>null</code> not permitted). + * + * @since 1.0.13 + */ + private void updateBoundsForAddedItem(XYDataItem item) { + double x = item.getXValue(); + this.minX = minIgnoreNaN(this.minX, x); + this.maxX = maxIgnoreNaN(this.maxX, x); + if (item.getY() != null) { + double y = item.getYValue(); + this.minY = minIgnoreNaN(this.minY, y); + this.maxY = maxIgnoreNaN(this.maxY, y); + } + } + + /** + * Updates the cached values for the minimum and maximum data values on + * the basis that the specified item has just been removed. + * + * @param item the item added (<code>null</code> not permitted). + * + * @since 1.0.13 + */ + private void updateBoundsForRemovedItem(XYDataItem item) { + boolean itemContributesToXBounds = false; + boolean itemContributesToYBounds = false; + double x = item.getXValue(); + if (!Double.isNaN(x)) { + if (x <= this.minX || x >= this.maxX) { + itemContributesToXBounds = true; + } + } + if (item.getY() != null) { + double y = item.getYValue(); + if (!Double.isNaN(y)) { + if (y <= this.minY || y >= this.maxY) { + itemContributesToYBounds = true; + } + } + } + if (itemContributesToYBounds) { + findBoundsByIteration(); + } + else if (itemContributesToXBounds) { + if (getAutoSort()) { + this.minX = getX(0).doubleValue(); + this.maxX = getX(getItemCount() - 1).doubleValue(); + } + else { + findBoundsByIteration(); + } + } + } + + /** + * Finds the bounds of the x and y values for the series, by iterating + * through all the data items. + * + * @since 1.0.13 + */ + private void findBoundsByIteration() { + this.minX = Double.NaN; + this.maxX = Double.NaN; + this.minY = Double.NaN; + this.maxY = Double.NaN; + Iterator iterator = this.data.iterator(); + while (iterator.hasNext()) { + XYDataItem item = (XYDataItem) iterator.next(); + updateBoundsForAddedItem(item); + } + } + + /** * Returns the flag that controls whether the items in the series are * automatically sorted. There is no setter for this flag, it must be * defined in the series constructor. @@ -181,6 +335,8 @@ * Returns the number of items in the series. * * @return The item count. + * + * @see #getItems() */ public int getItemCount() { return this.data.size(); @@ -201,6 +357,7 @@ * The default value is <code>Integer.MAX_VALUE</code>. * * @return The maximum item count. + * * @see #setMaximumItemCount(int) */ public int getMaximumItemCount() { @@ -217,18 +374,16 @@ * Typically this value is set before the series is populated with data, * but if it is applied later, it may cause some items to be removed from * the series (in which case a {@link SeriesChangeEvent} will be sent to - * all registered listeners. + * all registered listeners). * * @param maximum the maximum number of items for the series. */ public void setMaximumItemCount(int maximum) { this.maximumItemCount = maximum; - boolean dataRemoved = false; - while (this.data.size() > maximum) { - this.data.remove(0); - dataRemoved = true; - } - if (dataRemoved) { + int remove = this.data.size() - maximum; + if (remove > 0) { + this.data.subList(0, remove).clear(); + findBoundsByIteration(); fireSeriesChanged(); } } @@ -344,11 +499,9 @@ * listeners. */ public void add(XYDataItem item, boolean notify) { - if (item == null) { throw new IllegalArgumentException("Null 'item' argument."); } - if (this.autoSort) { int index = Collections.binarySearch(this.data, item); if (index < 0) { @@ -358,8 +511,8 @@ if (this.allowDuplicateXValues) { // need to make sure we are adding *after* any duplicates int size = this.data.size(); - while (index < size - && item.compareTo(this.data.get(index)) == 0) { + while (index < size && item.compareTo( + this.data.get(index)) == 0) { index++; } if (index < this.data.size()) { @@ -385,8 +538,10 @@ } this.data.add(item); } + updateBoundsForAddedItem(item); if (getItemCount() > this.maximumItemCount) { - this.data.remove(0); + XYDataItem removed = (XYDataItem) this.data.remove(0); + updateBoundsForRemovedItem(removed); } if (notify) { fireSeriesChanged(); @@ -401,9 +556,8 @@ * @param end the end index (zero-based). */ public void delete(int start, int end) { - for (int i = start; i <= end; i++) { - this.data.remove(start); - } + this.data.subList(start, end + 1).clear(); + findBoundsByIteration(); fireSeriesChanged(); } @@ -416,14 +570,17 @@ * @return The item removed. */ public XYDataItem remove(int index) { - XYDataItem result = (XYDataItem) this.data.remove(index); + XYDataItem removed = (XYDataItem) this.data.remove(index); + updateBoundsForRemovedItem(removed); fireSeriesChanged(); - return result; + return removed; } /** - * Removes the item with the specified x-value and sends a - * {@link SeriesChangeEvent} to all registered listeners. + * Removes an item with the specified x-value and sends a + * {@link SeriesChangeEvent} to all registered listeners. Note that when + * a series permits multiple items with the same x-value, this method + * could remove any one of the items with that x-value. * * @param x the x-value. @@ -434,11 +591,16 @@ } /** - * Removes all data items from the series. + * Removes all data items from the series and sends a + * {@link SeriesChangeEvent} to all registered listeners. */ public void clear() { if (this.data.size() > 0) { this.data.clear(); + this.minX = Double.NaN; + this.maxX = Double.NaN; + this.minY = Double.NaN; + this.maxY = Double.NaN; fireSeriesChanged(); } } @@ -487,11 +649,73 @@ */ public void updateByIndex(int index, Number y) { XYDataItem item = getDataItem(index); + + // figure out if we need to iterate through all the y-values + boolean iterate = false; + double oldY = item.getYValue(); + if (!Double.isNaN(oldY)) { + iterate = oldY <= this.minY || oldY >= this.maxY; + } item.setY(y); + + if (iterate) { + findBoundsByIteration(); + } + else if (y != null) { + double yy = y.doubleValue(); + this.minY = minIgnoreNaN(this.minY, yy); + this.maxY = maxIgnoreNaN(this.maxY, yy); + } fireSeriesChanged(); } /** + * A function to find the minimum of two values, but ignoring any + * Double.NaN values. + * + * @param a the first value. + * @param b the second value. + * + * @return The minimum of the two values. + */ + private double minIgnoreNaN(double a, double b) { + if (Double.isNaN(a)) { + return b; + } + else { + if (Double.isNaN(b)) { + return a; + } + else { + return Math.min(a, b); + } + } + } + + /** + * A function to find the maximum of two values, but ignoring any + * Double.NaN values. + * + * @param a the first value. + * @param b the second value. + * + * @return The maximum of the two values. + */ + private double maxIgnoreNaN(double a, double b) { + if (Double.isNaN(a)) { + return b; + } + else { + if (Double.isNaN(b)) { + return a; + } + else { + return Math.max(a, b); + } + } + } + + /** * Updates an item in the series. * * @param x the x-value (<code>null</code> not permitted). @@ -506,9 +730,7 @@ throw new SeriesException("No observation for x = " + x); } else { - XYDataItem item = getDataItem(index); - item.setY(y); - fireSeriesChanged(); + updateByIndex(index, y); } } @@ -557,22 +779,41 @@ catch (CloneNotSupportedException e) { throw new SeriesException("Couldn't clone XYDataItem!"); } + // figure out if we need to iterate through all the y-values + boolean iterate = false; + double oldY = existing.getYValue(); + if (!Double.isNaN(oldY)) { + iterate = oldY <= this.minY || oldY >= this.maxY; + } existing.setY(y); + + if (iterate) { + findBoundsByIteration(); + } + else if (y != null) { + double yy = y.doubleValue(); + this.minY = minIgnoreNaN(this.minY, yy); + this.maxY = minIgnoreNaN(this.maxY, yy); + } } else { // if the series is sorted, the negative index is a result from // Collections.binarySearch() and tells us where to insert the // new item...otherwise it will be just -1 and we should just // append the value to the list... + XYDataItem item = new XYDataItem(x, y); if (this.autoSort) { - this.data.add(-index - 1, new XYDataItem(x, y)); + this.data.add(-index - 1, item); } else { - this.data.add(new XYDataItem(x, y)); + this.data.add(item); } + updateBoundsForAddedItem(item); + // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { - this.data.remove(0); + XYDataItem removed = (XYDataItem) this.data.remove(0); + updateBoundsForRemovedItem(removed); } } fireSeriesChanged(); Modified: trunk/source/org/jfree/data/xy/XYSeriesCollection.java =================================================================== --- trunk/source/org/jfree/data/xy/XYSeriesCollection.java 2009-04-07 12:46:47 UTC (rev 1955) +++ trunk/source/org/jfree/data/xy/XYSeriesCollection.java 2009-04-07 13:50:50 UTC (rev 1956) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ----------------------- * XYSeriesCollection.java * ----------------------- - * (C) Copyright 2001-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2001-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Aaron Metzger; @@ -53,6 +53,10 @@ * 21-Jun-2007 : Removed JCommon dependencies (DG); * 03-Dec-2007 : Added getSeries(Comparable) method (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); + * 27-Feb-2009 : Overridden getDomainOrder() to detect when all series are + * sorted in ascending order (DG); + * 06-Mar-2009 : Implemented RangeInfo (DG); + * 06-Mar-2009 : Fixed equals() implementation (DG); * */ @@ -63,20 +67,22 @@ import java.util.Iterator; import java.util.List; +import org.jfree.chart.util.HashUtilities; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DomainInfo; +import org.jfree.data.DomainOrder; import org.jfree.data.Range; +import org.jfree.data.RangeInfo; import org.jfree.data.UnknownKeyException; import org.jfree.data.general.DatasetChangeEvent; -import org.jfree.data.general.DatasetUtilities; /** * Represents a collection of {@link XYSeries} objects that can be used as a * dataset. */ public class XYSeriesCollection extends AbstractIntervalXYDataset - implements IntervalXYDataset, DomainInfo, PublicCloneable, + implements IntervalXYDataset, DomainInfo, RangeInfo, PublicCloneable, Serializable { /** For serialization. */ @@ -111,20 +117,34 @@ } /** + * Returns the order of the domain (X) values, if this is known. + * + * @return The domain order. + */ + public DomainOrder getDomainOrder() { + int seriesCount = getSeriesCount(); + for (int i = 0; i < seriesCount; i++) { + XYSeries s = getSeries(i); + if (!s.getAutoSort()) { + return DomainOrder.NONE; // we can't be sure of the order + } + } + return DomainOrder.ASCENDING; + } + + /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(XYSeries series) { - if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); - } /** @@ -134,7 +154,6 @@ * @param series the series index (zero-based). */ public void removeSeries(int series) { - if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds."); } @@ -144,7 +163,6 @@ ts.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); - } /** @@ -154,7 +172,6 @@ * @param series the series (<code>null</code> not permitted). */ public void removeSeries(XYSeries series) { - if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } @@ -163,7 +180,6 @@ this.data.remove(series); fireDatasetChanged(); } - } /** @@ -339,11 +355,9 @@ * @return The value (possibly <code>null</code>). */ public Number getY(int series, int index) { - XYSeries ts = (XYSeries) this.data.get(series); XYDataItem xyItem = ts.getDataItem(index); return xyItem.getY(); - } /** @@ -378,15 +392,6 @@ * @return A boolean. */ public boolean equals(Object obj) { - /* - * XXX - * - * what about the interval delegate...? - * The interval width etc wasn't considered - * before, hence i did not add it here (AS) - * - */ - if (obj == this) { return true; } @@ -394,6 +399,9 @@ return false; } XYSeriesCollection that = (XYSeriesCollection) obj; + if (!this.intervalDelegate.equals(that.intervalDelegate)) { + return false; + } return ObjectUtilities.equal(this.data, that.data); } @@ -418,8 +426,10 @@ * @return A hash code. */ public int hashCode() { - // Same question as for equals (AS) - return (this.data != null ? this.data.hashCode() : 0); + int hash = 5; + hash = HashUtilities.hashCode(hash, this.intervalDelegate); + hash = HashUtilities.hashCode(hash, this.data); + return hash; } /** @@ -431,7 +441,26 @@ * @return The minimum value. */ public double getDomainLowerBound(boolean includeInterval) { - return this.intervalDelegate.getDomainLowerBound(includeInterval); + if (includeInterval) { + return this.intervalDelegate.getDomainLowerBound(includeInterval); + } + else { + double result = Double.NaN; + int seriesCount = getSeriesCount(); + for (int s = 0; s < seriesCount; s++) { + XYSeries series = getSeries(s); + double lowX = series.getMinX(); + if (Double.isNaN(result)) { + result = lowX; + } + else { + if (!Double.isNaN(lowX)) { + result = Math.min(result, lowX); + } + } + } + return result; + } } /** @@ -443,7 +472,26 @@ * @return The maximum value. */ public double getDomainUpperBound(boolean includeInterval) { - return this.intervalDelegate.getDomainUpperBound(includeInterval); + if (includeInterval) { + return this.intervalDelegate.getDomainUpperBound(includeInterval); + } + else { + double result = Double.NaN; + int seriesCount = getSeriesCount(); + for (int s = 0; s < seriesCount; s++) { + XYSeries series = getSeries(s); + double hiX = series.getMaxX(); + if (Double.isNaN(result)) { + result = hiX; + } + else { + if (!Double.isNaN(hiX)) { + result = Math.max(result, hiX); + } + } + } + return result; + } } /** @@ -452,16 +500,35 @@ * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * - * @return The range. + * @return The range (or <code>null</code> if the dataset contains no + * values). */ public Range getDomainBounds(boolean includeInterval) { if (includeInterval) { return this.intervalDelegate.getDomainBounds(includeInterval); } else { - return DatasetUtilities.iterateDomainBounds(this, includeInterval); + double lower = Double.POSITIVE_INFINITY; + double upper = Double.NEGATIVE_INFINITY; + int seriesCount = getSeriesCount(); + for (int s = 0; s < seriesCount; s++) { + XYSeries series = getSeries(s); + double minX = series.getMinX(); + if (!Double.isNaN(minX)) { + lower = Math.min(lower, minX); + } + double maxX = series.getMaxX(); + if (!Double.isNaN(maxX)) { + upper = Math.max(upper, maxX); + } + } + if (lower > upper) { + return null; + } + else { + return new Range(lower, upper); + } } - } /** @@ -529,4 +596,87 @@ fireDatasetChanged(); } + /** + * Returns the range of the values in this dataset's range. + * + * @param includeInterval ignored. + * + * @return The range (or <code>null</code> if the dataset contains no + * values). + */ + public Range getRangeBounds(boolean includeInterval) { + double lower = Double.POSITIVE_INFINITY; + double upper = Double.NEGATIVE_INFINITY; + int seriesCount = getSeriesCount(); + for (int s = 0; s < seriesCount; s++) { + XYSeries series = getSeries(s); + double minY = series.getMinY(); + if (!Double.isNaN(minY)) { + lower = Math.min(lower, minY); } + double maxY = series.getMaxY(); + if (!Double.isNaN(maxY)) { + upper = Math.max(upper, maxY); + } + } + if (lower > upper) { + return null; + } + else { + return new Range(lower, upper); + } + } + + /** + * Returns the minimum y-value in the dataset. + * + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. + * + * @return The minimum value. + */ + public double getRangeLowerBound(boolean includeInterval) { + double result = Double.NaN; + int seriesCount = getSeriesCount(); + for (int s = 0; s < seriesCount; s++) { + XYSeries series = getSeries(s); + double lowY = series.getMinY(); + if (Double.isNaN(result)) { + result = lowY; + } + else { + if (!Double.isNaN(lowY)) { + result = Math.min(result, lowY); + } + } + } + return result; + } + + /** + * Returns the maximum y-value in the dataset. + * + * @param includeInterval a flag that determines whether or not the + * y-interval is taken into account. + * + * @return The maximum value. + */ + public double getRangeUpperBound(boolean includeInterval) { + double result = Double.NaN; + int seriesCount = getSeriesCount(); + for (int s = 0; s < seriesCount; s++) { + XYSeries series = getSeries(s); + double hiY = series.getMaxY(); + if (Double.isNaN(result)) { + result = hiY; + } + else { + if (!Double.isNaN(hiY)) { + result = Math.max(result, hiY); + } + } + } + return result; + } + +} Modified: trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java =================================================================== --- trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java 2009-04-07 12:46:47 UTC (rev 1955) +++ trunk/swt/org/jfree/experimental/swt/SWTGraphics2D.java 2009-04-07 13:50:50 UTC (rev 1956) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -32,6 +32,7 @@ * Original Author: Henry Proudhon (henry.proudhon AT ensmp.fr); * Contributor(s): Cedric Chabanois (cchabanois AT no-log.org); * David Gilbert (for Object Refinery Limited); + * Ronnie Duan (see bug report 2583891); * * Changes * ------- @@ -55,6 +56,7 @@ * 24-May-2008 : Use color from pool for setBackground method (HP); * 24-May-2008 : New resource pool for tansform objects; * 18-Nov-2008 : Check for GradientPaint in setPaint() method (DG); + * 27-Feb-2009 : Implemented fillPolygon() - see bug 2583891 (DG); * */ @@ -804,14 +806,21 @@ } /** - * Not implemented - see {@link Graphics#fillPolygon(int[], int[], int)}. + * Fills the specified polygon. * * @param xPoints the x-coordinates. * @param yPoints the y-coordinates. * @param npoints the number of points. */ - public void fillPolygon(int [] xPoints, int [] yPoints, int npoints) { - // TODO Auto-generated method stub + public void fillPolygon(int[] xPoints, int[] yPoints, int npoints) { + int[] pointArray = new int[npoints * 2]; + for (int i = 0; i < npoints; i++) { + pointArray[2 * i] = xPoints[i]; + pointArray[2 * i + 1] = yPoints[i]; + } + switchColors(); + this.gc.fillPolygon(pointArray); + switchColors(); } /** Modified: trunk/tests/org/jfree/data/xy/junit/XYSeriesCollectionTests.java =================================================================== --- trunk/tests/org/jfree/data/xy/junit/XYSeriesCollectionTests.java 2009-04-07 12:46:47 UTC (rev 1955) +++ trunk/tests/org/jfree/data/xy/junit/XYSeriesCollectionTests.java 2009-04-07 13:50:50 UTC (rev 1956) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------------------- * XYSeriesCollectionTests.java * ---------------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -40,6 +40,7 @@ * 08-May-2007 : Added testIndexOf() (DG); * 03-Dec-2007 : Added testGetSeriesByKey() (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); + * 06-Mar-2009 : Added testGetDomainBounds (DG); * */ @@ -51,12 +52,11 @@ 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.chart.util.PublicCloneable; +import org.jfree.data.Range; import org.jfree.data.UnknownKeyException; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; @@ -84,7 +84,19 @@ super(name); } + private static final double EPSILON = 0.0000000001; + /** + * Some checks for the constructor. + */ + public void testConstructor() { + XYSeriesCollection xysc = new XYSeriesCollection(); + assertEquals(0, xysc.getSeriesCount()); + assertEquals(1.0, xysc.getIntervalWidth(), EPSILON); + assertEquals(0.5, xysc.getIntervalPositionFactor(), EPSILON); + } + + /** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { @@ -101,9 +113,24 @@ c1.addSeries(new XYSeries("Empty Series")); assertFalse(c1.equals(c2)); - c2.addSeries(new XYSeries("Empty Series")); assertTrue(c1.equals(c2)); + + c1.setIntervalWidth(5.0); + assertFalse(c1.equals(c2)); + c2.setIntervalWidth(5.0); + assertTrue(c1.equals(c2)); + + c1.setIntervalPositionFactor(0.75); + assertFalse(c1.equals(c2)); + c2.setIntervalPositionFactor(0.75); + assertTrue(c1.equals(c2)); + + c1.setAutoWidth(true); + assertFalse(c1.equals(c2)); + c2.setAutoWidth(true); + assertTrue(c1.equals(c2)); + } /** @@ -295,4 +322,64 @@ assertEquals(0, dataset.indexOf(s2b)); } + /** + * Some checks for the getDomainBounds() method. + */ + public void testGetDomainBounds() { + XYSeriesCollection dataset = new XYSeriesCollection(); + Range r = dataset.getDomainBounds(false); + assertNull(r); + r = dataset.getDomainBounds(true); + assertNull(r); + + XYSeries series = new XYSeries("S1"); + dataset.addSeries(series); + r = dataset.getDomainBounds(false); + assertNull(r); + r = dataset.getDomainBounds(true); + assertNull(r); + + series.add(1.0, 1.1); + r = dataset.getDomainBounds(false); + assertEquals(new Range(1.0, 1.0), r); + r = dataset.getDomainBounds(true); + assertEquals(new Range(0.5, 1.5), r); + + series.add(-1.0, -1.1); + r = dataset.getDomainBounds(false); + assertEquals(new Range(-1.0, 1.0), r); + r = dataset.getDomainBounds(true); + assertEquals(new Range(-1.5, 1.5), r); } + + /** + * Some checks for the getRangeBounds() method. + */ + public void testGetRangeBounds() { + XYSeriesCollection dataset = new XYSeriesCollection(); + Range r = dataset.getRangeBounds(false); + assertNull(r); + r = dataset.getRangeBounds(true); + assertNull(r); + + XYSeries series = new XYSeries("S1"); + dataset.addSeries(series); + r = dataset.getRangeBounds(false); + assertNull(r); + r = dataset.getRangeBounds(true); + assertNull(r); + + series.add(1.0, 1.1); + r = dataset.getRangeBounds(false); + assertEquals(new Range(1.1, 1.1), r); + r = dataset.getRangeBounds(true); + assertEquals(new Range(1.1, 1.1), r); + + series.add(-1.0, -1.1); + r = dataset.getRangeBounds(false); + assertEquals(new Range(-1.1, 1.1), r); + r = dataset.getRangeBounds(true); + assertEquals(new Range(-1.1, 1.1), r); + } + +} Modified: trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java =================================================================== --- trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java 2009-04-07 12:46:47 UTC (rev 1955) +++ trunk/tests/org/jfree/data/xy/junit/XYSeriesTests.java 2009-04-07 13:50:50 UTC (rev 1956) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------ * XYSeriesTests.java * ------------------ - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -40,6 +40,7 @@ * 31-Oct-2007 : New hashCode() test (DG); * 01-May-2008 : Added testAddOrUpdate3() (DG); * 24-Nov-2008 : Added testBug1955483() (DG); + * 06-Mar-2009 : Added tests for cached bounds values (DG); * */ @@ -88,7 +89,6 @@ * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { - XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeries s2 = new XYSeries("Series"); @@ -98,10 +98,13 @@ s1.setKey("Series X"); assertFalse(s1.equals(s2)); - s2.setKey("Series X"); assertTrue(s1.equals(s2)); + s1.add(2.0, 2.2); + assertFalse(s1.equals(s2)); + s2.add(2.0, 2.2); + assertTrue(s1.equals(s2)); } /** @@ -201,11 +204,9 @@ * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { - XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeries s2 = null; - try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); @@ -221,7 +222,6 @@ e.printStackTrace(); } assertEquals(s1, s2); - } /** @@ -233,6 +233,9 @@ s1.add(2.0, 2.0); s1.add(3.0, 3.0); assertEquals(0, s1.indexOf(new Double(1.0))); + assertEquals(1, s1.indexOf(new Double(2.0))); + assertEquals(2, s1.indexOf(new Double(3.0))); + assertEquals(-4, s1.indexOf(new Double(99.9))); } /** @@ -249,22 +252,58 @@ } /** + * A check for the indexOf(Number) method when the series has duplicate + * x-values. + */ + public void testIndexOf3() { + XYSeries s1 = new XYSeries("Series 1"); + s1.add(1.0, 1.0); + s1.add(2.0, 2.0); + s1.add(2.0, 3.0); + assertEquals(0, s1.indexOf(new Double(1.0))); + assertEquals(1, s1.indexOf(new Double(2.0))); + } + + /** * Simple test for the remove() method. */ public void testRemove() { - XYSeries s1 = new XYSeries("Series 1"); s1.add(1.0, 1.0); s1.add(2.0, 2.0); s1.add(3.0, 3.0); + assertEquals(3, s1.getItemCount()); - assertEquals(3, s1.getItemCount()); s1.remove(new Double(2.0)); assertEquals(new Double(3.0), s1.getX(1)); s1.remove(0); assertEquals(new Double(3.0), s1.getX(0)); + } + /** + * Some checks for the remove(int) method. + */ + public void testRemove2() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + s1.add(4.0, 4.4); + s1.add(5.0, 5.5); + s1.add(6.0, 6.6); + assertEquals(6, s1.getItemCount()); + assertEquals(1.0, s1.getMinX(), EPSILON); + assertEquals(6.0, s1.getMaxX(), EPSILON); + assertEquals(1.1, s1.getMinY(), EPSILON); + assertEquals(6.6, s1.getMaxY(), EPSILON); + + s1.remove(5); + assertEquals(5, s1.getItemCount()); + assertEquals(1.0, s1.getMinX(), EPSILON); + assertEquals(5.0, s1.getMaxX(), EPSILON); + assertEquals(1.1, s1.getMinY(), EPSILON); + assertEquals(5.5, s1.getMaxY(), EPSILON); } private static final double EPSILON = 0.0000000001; @@ -420,6 +459,45 @@ } /** + * Check that the item bounds are determined correctly when there is a + * maximum item count. + */ + public void testSetMaximumItemCount3() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + s1.add(4.0, 4.4); + s1.add(5.0, 5.5); + s1.add(6.0, 6.6); + s1.setMaximumItemCount(2); + assertEquals(5.0, s1.getX(0).doubleValue(), EPSILON); + assertEquals(6.0, s1.getX(1).doubleValue(), EPSILON); + assertEquals(5.0, s1.getMinX(), EPSILON); + assertEquals(6.0, s1.getMaxX(), EPSILON); + assertEquals(5.5, s1.getMinY(), EPSILON); + assertEquals(6.6, s1.getMaxY(), EPSILON); + } + + /** + * Check that the item bounds are determined correctly when there is a + * maximum item count. + */ + public void testSetMaximumItemCount4() { + XYSeries s1 = new XYSeries("S1"); + s1.setMaximumItemCount(2); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); + assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); + assertEquals(2.0, s1.getMinX(), EPSILON); + assertEquals(3.0, s1.getMaxX(), EPSILON); + assertEquals(2.2, s1.getMinY(), EPSILON); + assertEquals(3.3, s1.getMaxY(), EPSILON); + } + + /** * Some checks for the toArray() method. */ public void testToArray() { @@ -482,4 +560,222 @@ assertEquals(2, series.getItemCount()); } + /** + * Some checks for the delete(int, int) method. + */ + public void testDelete() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + s1.add(4.0, 4.4); + s1.add(5.0, 5.5); + s1.add(6.0, 6.6); + s1.delete(2, 5); + assertEquals(2, s1.getItemCount()); + assertEquals(1.0, s1.getX(0).doubleValue(), EPSILON); + assertEquals(2.0, s1.getX(1).doubleValue(), EPSILON); + assertEquals(1.0, s1.getMinX(), EPSILON); + assertEquals(2.0, s1.getMaxX(), EPSILON); + assertEquals(1.1, s1.getMinY(), EPSILON); + assertEquals(2.2, s1.getMaxY(), EPSILON); } + + /** + * Some checks for the getMinX() method. + */ + public void testGetMinX() { + XYSeries s1 = new XYSeries("S1"); + assertTrue(Double.isNaN(s1.getMinX())); + + s1.add(1.0, 1.1); + assertEquals(1.0, s1.getMinX(), EPSILON); + + s1.add(2.0, 2.2); + assertEquals(1.0, s1.getMinX(), EPSILON); + + s1.add(Double.NaN, 99.9); + assertEquals(1.0, s1.getMinX(), EPSILON); + + s1.add(-1.0, -1.1); + assertEquals(-1.0, s1.getMinX(), EPSILON); + + s1.add(0.0, null); + assertEquals(-1.0, s1.getMinX(), EPSILON); + } + + /** + * Some checks for the getMaxX() method. + */ + public void testGetMaxX() { + XYSeries s1 = new XYSeries("S1"); + assertTrue(Double.isNaN(s1.getMaxX())); + + s1.add(1.0, 1.1); + assertEquals(1.0, s1.getMaxX(), EPSILON); + + s1.add(2.0, 2.2); + assertEquals(2.0, s1.getMaxX(), EPSILON); + + s1.add(Double.NaN, 99.9); + assertEquals(2.0, s1.getMaxX(), EPSILON); + + s1.add(-1.0, -1.1); + assertEquals(2.0, s1.getMaxX(), EPSILON); + + s1.add(0.0, null); + assertEquals(2.0, s1.getMaxX(), EPSILON); + } + + /** + * Some checks for the getMinY() method. + */ + public void testGetMinY() { + XYSeries s1 = new XYSeries("S1"); + assertTrue(Double.isNaN(s1.getMinY())); + + s1.add(1.0, 1.1); + assertEquals(1.1, s1.getMinY(), EPSILON); + + s1.add(2.0, 2.2); + assertEquals(1.1, s1.getMinY(), EPSILON); + + s1.add(Double.NaN, 99.9); + assertEquals(1.1, s1.getMinY(), EPSILON); + + s1.add(-1.0, -1.1); + assertEquals(-1.1, s1.getMinY(), EPSILON); + + s1.add(0.0, null); + assertEquals(-1.1, s1.getMinY(), EPSILON); + } + + /** + * Some checks for the getMaxY() method. + */ + public void testGetMaxY() { + XYSeries s1 = new XYSeries("S1"); + assertTrue(Double.isNaN(s1.getMaxY())); + + s1.add(1.0, 1.1); + assertEquals(1.1, s1.getMaxY(), EPSILON); + + s1.add(2.0, 2.2); + assertEquals(2.2, s1.getMaxY(), EPSILON); + + s1.add(Double.NaN, 99.9); + assertEquals(99.9, s1.getMaxY(), EPSILON); + + s1.add(-1.0, -1.1); + assertEquals(99.9, s1.getMaxY(), EPSILON); + + s1.add(0.0, null); + assertEquals(99.9, s1.getMaxY(), EPSILON); + } + + /** + * A test for the clear method. + */ + public void testClear() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + + assertEquals(3, s1.getItemCount()); + + s1.clear(); + assertEquals(0, s1.getItemCount()); + assertTrue(Double.isNaN(s1.getMinX())); + assertTrue(Double.isNaN(s1.getMaxX())); + assertTrue(Double.isNaN(s1.getMinY())); + assertTrue(Double.isNaN(s1.getMaxY())); + } + + /** + * Some checks for the updateByIndex() method. + */ + public void testUpdateByIndex() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + + assertEquals(1.1, s1.getMinY(), EPSILON); + assertEquals(3.3, s1.getMaxY(), EPSILON); + + s1.updateByIndex(0, new Double(-5.0)); + assertEquals(-5.0, s1.getMinY(), EPSILON); + assertEquals(3.3, s1.getMaxY(), EPSILON); + + s1.updateByIndex(0, null); + assertEquals(2.2, s1.getMinY(), EPSILON); + assertEquals(3.3, s1.getMaxY(), EPSILON); + + s1.updateByIndex(2, null); + assertEquals(2.2, s1.getMinY(), EPSILON); + assertEquals(2.2, s1.getMaxY(), EPSILON); + + s1.updateByIndex(1, null); + assertTrue(Double.isNaN(s1.getMinY())); + assertTrue(Double.isNaN(s1.getMaxY())); + } + + /** + * Some checks for the updateByIndex() method. + */ + public void testUpdateByIndex2() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, Double.NaN); + + assertTrue(Double.isNaN(s1.getMinY())); + assertTrue(Double.isNaN(s1.getMaxY())); + + s1.updateByIndex(0, new Double(1.0)); + assertEquals(1.0, s1.getMinY(), EPSILON); + assertEquals(1.0, s1.getMaxY(), EPSILON); + + s1.updateByIndex(0, new Double(2.0)); + assertEquals(2.0, s1.getMinY(), EPSILON); + assertEquals(2.0, s1.getMaxY(), EPSILON); + + s1.add(-1.0, -1.0); + s1.updateByIndex(0, new Double(0.0)); + assertEquals(0.0, s1.getMinY(), EPSILON); + assertEquals(2.0, s1.getMaxY(), EPSILON); + } + + /** + * Some checks for the updateByIndex() method. + */ + public void testUpdateByIndex3() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, 1.1); + s1.add(2.0, 2.2); + s1.add(3.0, 3.3); + + s1.updateByIndex(1, new Double(2.05)); + assertEquals(1.1, s1.getMinY(), EPSILON); + assertEquals(3.3, s1.getMaxY(), EPSILON); + } + + /** + * Some checks for the update(Number, Number) method. + */ + public void testUpdateXY() { + XYSeries s1 = new XYSeries("S1"); + s1.add(1.0, Double.NaN); + + assertTrue(Double.isNaN(s1.getMinY())); + assertTrue(Double.isNaN(s1.getMaxY())); + + s1.update(new Double(1.0), new Double(1.0)); + assertEquals(1.0, s1.getMinY(), EPSILON); + assertEquals(1.0, s1.getMaxY(), EPSILON); + + s1.update(new Double(1.0), new Double(2.0)); + assertEquals(2.0, s1.getMinY(), EPSILON); + assertEquals(2.0, s1.getMaxY(), EPSILON); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 19:16:53
|
Revision: 1963 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1963&view=rev Author: mungady Date: 2009-04-07 19:16:38 +0000 (Tue, 07 Apr 2009) Log Message: ----------- New files. Added Paths: ----------- trunk/source/org/jfree/data/general/DefaultHeatMapDataset.java trunk/source/org/jfree/data/general/HeatMapDataset.java trunk/source/org/jfree/data/general/HeatMapUtilities.java trunk/tests/org/jfree/data/general/junit/DefaultHeatMapDatasetTests.java Added: trunk/source/org/jfree/data/general/DefaultHeatMapDataset.java =================================================================== --- trunk/source/org/jfree/data/general/DefaultHeatMapDataset.java (rev 0) +++ trunk/source/org/jfree/data/general/DefaultHeatMapDataset.java 2009-04-07 19:16:38 UTC (rev 1963) @@ -0,0 +1,322 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * -------------------------- + * DefaultHeatMapDataset.java + * -------------------------- + * (C) Copyright 2009, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 28-Jan-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.general; + +import java.io.Serializable; +import org.jfree.data.DataUtilities; +import org.jfree.util.PublicCloneable; + +/** + * A default implementation of the {@link HeatMapDataset} interface. + * + * @since 1.0.13 + */ +public class DefaultHeatMapDataset extends AbstractDataset + implements HeatMapDataset, Cloneable, PublicCloneable, Serializable { + + /** The number of samples in this dataset for the x-dimension. */ + private int xSamples; + + /** The number of samples in this dataset for the y-dimension. */ + private int ySamples; + + /** The minimum x-value in the dataset. */ + private double minX; + + /** The maximum x-value in the dataset. */ + private double maxX; + + /** The minimum y-value in the dataset. */ + private double minY; + + /** The maximum y-value in the dataset. */ + private double maxY; + + /** Storage for the z-values. */ + private double[][] zValues; + + /** + * Creates a new dataset where all the z-values are initially 0. This is + * a fixed size array of z-values. + * + * @param xSamples the number of x-values. + * @param ySamples the number of y-values + * @param minX the minimum x-value in the dataset. + * @param maxX the maximum x-value in the dataset. + * @param minY the minimum y-value in the dataset. + * @param maxY the maximum y-value in the dataset. + */ + public DefaultHeatMapDataset(int xSamples, int ySamples, double minX, + double maxX, double minY, double maxY) { + + if (xSamples < 1) { + throw new IllegalArgumentException("Requires 'xSamples' > 0"); + } + if (ySamples < 1) { + throw new IllegalArgumentException("Requires 'ySamples' > 0"); + } + if (Double.isInfinite(minX) || Double.isNaN(minX)) { + throw new IllegalArgumentException("'minX' cannot be INF or NaN."); + } + if (Double.isInfinite(maxX) || Double.isNaN(maxX)) { + throw new IllegalArgumentException("'maxX' cannot be INF or NaN."); + } + if (Double.isInfinite(minY) || Double.isNaN(minY)) { + throw new IllegalArgumentException("'minY' cannot be INF or NaN."); + } + if (Double.isInfinite(maxY) || Double.isNaN(maxY)) { + throw new IllegalArgumentException("'maxY' cannot be INF or NaN."); + } + + this.xSamples = xSamples; + this.ySamples = ySamples; + this.minX = minX; + this.maxX = maxX; + this.minY = minY; + this.maxY = maxY; + this.zValues = new double[xSamples][]; + for (int x = 0; x < xSamples; x++) { + this.zValues[x] = new double[ySamples]; + } + } + + /** + * Returns the number of x values across the width of the dataset. The + * values are evenly spaced between {@link #getMinimumXValue()} and + * {@link #getMaximumXValue()}. + * + * @return The number of x-values (always > 0). + */ + public int getXSampleCount() { + return this.xSamples; + } + + /** + * Returns the number of y values (or samples) for the dataset. The + * values are evenly spaced between {@link #getMinimumYValue()} and + * {@link #getMaximumYValue()}. + * + * @return The number of y-values (always > 0). + */ + public int getYSampleCount() { + return this.ySamples; + } + + /** + * Returns the lowest x-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The lowest x-value represented in this dataset. + */ + public double getMinimumXValue() { + return this.minX; + } + + /** + * Returns the highest x-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The highest x-value represented in this dataset. + */ + public double getMaximumXValue() { + return this.maxX; + } + + /** + * Returns the lowest y-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The lowest y-value represented in this dataset. + */ + public double getMinimumYValue() { + return this.minY; + } + + /** + * Returns the highest y-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The highest y-value represented in this dataset. + */ + public double getMaximumYValue() { + return this.maxY; + } + + /** + * A convenience method that returns the x-value for the given index. + * + * @param xIndex the xIndex. + * + * @return The x-value. + */ + public double getXValue(int xIndex) { + double x = this.minX + + (this.maxX - this.minX) * (xIndex / (double) this.xSamples); + return x; + } + + /** + * A convenience method that returns the y-value for the given index. + * + * @param yIndex the yIndex. + * + * @return The y-value. + */ + public double getYValue(int yIndex) { + double y = this.minY + + (this.maxY - this.minY) * (yIndex / (double) this.ySamples); + return y; + } + + /** + * Returns the z-value at the specified sample position in the dataset. + * For a missing or unknown value, this method should return Double.NAN. + * + * @param xIndex the position of the x sample in the dataset. + * @param yIndex the position of the y sample in the dataset. + * + * @return The z-value. + */ + public double getZValue(int xIndex, int yIndex) { + return this.zValues[xIndex][yIndex]; + } + + /** + * Returns the z-value at the specified sample position in the dataset. + * In this implementation, where the underlying values are stored in an + * array of double primitives, you should avoid using this method and + * use {@link #getZValue(int, int)} instead. + * + * @param xIndex the position of the x sample in the dataset. + * @param yIndex the position of the y sample in the dataset. + * + * @return The z-value. + */ + public Number getZ(int xIndex, int yIndex) { + return new Double(getZValue(xIndex, yIndex)); + } + + /** + * Updates a z-value in the dataset and sends a {@link DatasetChangeEvent} + * to all registered listeners. + * + * @param xIndex the x-index. + * @param yIndex the y-index. + * @param z the new z-value. + */ + public void setZValue(int xIndex, int yIndex, double z) { + setZValue(xIndex, yIndex, z, true); + } + + /** + * Updates a z-value in the dataset and, if requested, sends a + * {@link DatasetChangeEvent} to all registered listeners. + * + * @param xIndex the x-index. + * @param yIndex the y-index. + * @param z the new z-value. + * @param notify notify listeners? + */ + public void setZValue(int xIndex, int yIndex, double z, boolean notify) { + this.zValues[xIndex][yIndex] = z; + if (notify) { + fireDatasetChanged(); + } + } + + /** + * Tests this dataset 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 DefaultHeatMapDataset)) { + return false; + } + DefaultHeatMapDataset that = (DefaultHeatMapDataset) obj; + if (this.xSamples != that.xSamples) { + return false; + } + if (this.ySamples != that.ySamples) { + return false; + } + if (this.minX != that.minX) { + return false; + } + if (this.maxX != that.maxX) { + return false; + } + if (this.minY != that.minY) { + return false; + } + if (this.maxY != that.maxY) { + return false; + } + if (!DataUtilities.equal(this.zValues, that.zValues)) { + return false; + } + // can't find any differences + return true; + } + + /** + * Returns an independent copy of this dataset. + * + * @return A clone. + * + * @throws java.lang.CloneNotSupportedException + */ + public Object clone() throws CloneNotSupportedException { + DefaultHeatMapDataset clone = (DefaultHeatMapDataset) super.clone(); + clone.zValues = DataUtilities.clone(this.zValues); + return clone; + } + +} Added: trunk/source/org/jfree/data/general/HeatMapDataset.java =================================================================== --- trunk/source/org/jfree/data/general/HeatMapDataset.java (rev 0) +++ trunk/source/org/jfree/data/general/HeatMapDataset.java 2009-04-07 19:16:38 UTC (rev 1963) @@ -0,0 +1,154 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------- + * HeatMapDataset.java + * ------------------- + * (C) Copyright 2009, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 28-Jan-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.general; + +/** + * A dataset that represents a rectangular grid of (x, y, z) values. The x + * and y values appear at regular intervals in the dataset, while the z-values + * can take any value (including <code>null</code> for unknown values). + * + * @since 1.0.13 + */ +public interface HeatMapDataset { + + /** + * Returns the number of x values across the width of the dataset. The + * values are evenly spaced between {@link #getMinimumXValue()} and + * {@link #getMaximumXValue()}. + * + * @return The number of x-values (always > 0). + */ + public int getXSampleCount(); + + /** + * Returns the number of y values (or samples) for the dataset. The + * values are evenly spaced between {@link #getMinimumYValue()} and + * {@link #getMaximumYValue()}. + * + * @return The number of y-values (always > 0). + */ + public int getYSampleCount(); + + /** + * Returns the lowest x-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The lowest x-value represented in this dataset. + */ + public double getMinimumXValue(); + + /** + * Returns the highest x-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The highest x-value represented in this dataset. + */ + public double getMaximumXValue(); + + /** + * Returns the lowest y-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The lowest y-value represented in this dataset. + */ + public double getMinimumYValue(); + + /** + * Returns the highest y-value represented in this dataset. A requirement + * of this interface is that this method must never return infinite or + * Double.NAN values. + * + * @return The highest y-value represented in this dataset. + */ + public double getMaximumYValue(); + + /** + * A convenience method that returns the x-value for the given index. + * + * @param xIndex the xIndex. + * + * @return The x-value. + */ + public double getXValue(int xIndex); + + /** + * A convenience method that returns the y-value for the given index. + * + * @param yIndex the yIndex. + * + * @return The y-value. + */ + public double getYValue(int yIndex); + + /** + * Returns the z-value at the specified sample position in the dataset. + * For a missing or unknown value, this method should return Double.NAN. + * + * @param xIndex the position of the x sample in the dataset. + * @param yIndex the position of the y sample in the dataset. + * + * @return The z-value. + */ + public double getZValue(int xIndex, int yIndex); + + /** + * Returns the z-value at the specified sample position in the dataset. + * This method can return <code>null</code> to indicate a missing/unknown + * value. + * <br><br> + * Bear in mind that the class implementing this interface may + * store its data using primitives rather than objects, so calling this + * method may require a new <code>Number</code> object to be allocated... + * for this reason, it is generally preferable to use the + * {@link #getZValue(int, int)} method unless you *know* that the dataset + * implementation stores the z-values using objects. + * + * @param xIndex the position of the x sample in the dataset. + * @param yIndex the position of the y sample in the dataset. + * + * @return The z-value (possibly <code>null</code>). + */ + public Number getZ(int xIndex, int yIndex); + +} Added: trunk/source/org/jfree/data/general/HeatMapUtilities.java =================================================================== --- trunk/source/org/jfree/data/general/HeatMapUtilities.java (rev 0) +++ trunk/source/org/jfree/data/general/HeatMapUtilities.java 2009-04-07 19:16:38 UTC (rev 1963) @@ -0,0 +1,134 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * --------------------- + * HeatMapUtilities.java + * --------------------- + * (C) Copyright 2009, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 28-Jan-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.general; + +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.image.BufferedImage; +import org.jfree.chart.renderer.PaintScale; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +/** + * A utility class for the {@link HeatMapDataset}. + * + * @since 1.0.13 + */ +public abstract class HeatMapUtilities { + + /** + * Returns a dataset containing one series that holds a copy of the (x, z) + * data from one row (y-index) of the specified dataset. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param row the row (y) index. + * @param seriesName the series name/key (<code>null</code> not permitted). + * + * @return The dataset. + */ + public static XYDataset extractRowFromHeatMapDataset(HeatMapDataset dataset, + int row, Comparable seriesName) { + XYSeries series = new XYSeries(seriesName); + int cols = dataset.getXSampleCount(); + for (int c = 0; c < cols; c++) { + series.add(dataset.getXValue(c), dataset.getZValue(c, row)); + } + XYSeriesCollection result = new XYSeriesCollection(series); + return result; + } + + /** + * Returns a dataset containing one series that holds a copy of the (y, z) + * data from one column (x-index) of the specified dataset. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param column the column (x) index. + * @param seriesName the series name (<code>null</code> not permitted). + * + * @return The dataset. + */ + public static XYDataset extractColumnFromHeatMapDataset( + HeatMapDataset dataset, int column, Comparable seriesName) { + XYSeries series = new XYSeries(seriesName); + int rows = dataset.getYSampleCount(); + for (int r = 0; r < rows; r++) { + series.add(dataset.getYValue(r), dataset.getZValue(column, r)); + } + XYSeriesCollection result = new XYSeriesCollection(series); + return result; + } + + /** + * Creates an image that displays the values from the specified dataset. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param paintScale the paint scale for the z-values (<code>null</code> + * not permitted). + * + * @return A buffered image. + */ + public static BufferedImage createHeatMapImage(HeatMapDataset dataset, + PaintScale paintScale) { + + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + if (paintScale == null) { + throw new IllegalArgumentException("Null 'paintScale' argument."); + } + int xCount = dataset.getXSampleCount(); + int yCount = dataset.getYSampleCount(); + BufferedImage image = new BufferedImage(xCount, yCount, + BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = image.createGraphics(); + for (int xIndex = 0; xIndex < xCount; xIndex++) { + for (int yIndex = 0; yIndex < yCount; yIndex++) { + double z = dataset.getZValue(xIndex, yIndex); + Paint p = paintScale.getPaint(z); + g2.setPaint(p); + g2.fillRect(xIndex, yCount - yIndex - 1, 1, 1); + } + } + return image; + } + +} Added: trunk/tests/org/jfree/data/general/junit/DefaultHeatMapDatasetTests.java =================================================================== --- trunk/tests/org/jfree/data/general/junit/DefaultHeatMapDatasetTests.java (rev 0) +++ trunk/tests/org/jfree/data/general/junit/DefaultHeatMapDatasetTests.java 2009-04-07 19:16:38 UTC (rev 1963) @@ -0,0 +1,246 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------------------- + * DefaultHeatMapDatasetTests.java + * ------------------------------- + * (C) Copyright 2009, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 28-Jan-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.general.junit; + +import org.jfree.data.general.DefaultHeatMapDataset; +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.data.general.DatasetChangeEvent; +import org.jfree.data.general.DatasetChangeListener; + +/** + * Somes tests for the {@link DefaultHeatMapDataset} class. + * + * @since 1.0.13 + */ +public class DefaultHeatMapDatasetTests extends TestCase + implements DatasetChangeListener { + + /** The last event received. */ + private DatasetChangeEvent lastEvent; + + /** + * Records the last event. + * + * @param event the last event. + */ + public void datasetChanged(DatasetChangeEvent event) { + this.lastEvent = event; + } + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(DefaultHeatMapDatasetTests.class); + } + + private static final double EPSILON = 0.0000000001; + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public DefaultHeatMapDatasetTests(String name) { + super(name); + } + + /** + * Some general tests. + */ + public void testGeneral() { + DefaultHeatMapDataset d = new DefaultHeatMapDataset(10, 5, 0.0, 9.0, + 0.0, 5.0); + assertEquals(10, d.getXSampleCount()); + assertEquals(5, d.getYSampleCount()); + assertEquals(0.0, d.getMinimumXValue(), EPSILON); + assertEquals(9.0, d.getMaximumXValue(), EPSILON); + assertEquals(0.0, d.getMinimumYValue(), EPSILON); + assertEquals(5.0, d.getMaximumYValue(), EPSILON); + assertEquals(0.0, d.getZValue(0, 0), EPSILON); + d.addChangeListener(this); + d.setZValue(0, 0, 1.0, false); + assertEquals(1.0, d.getZValue(0, 0), EPSILON); + assertNull(this.lastEvent); + d.setZValue(1, 2, 2.0); + assertEquals(2.0, d.getZValue(1, 2), EPSILON); + assertNotNull(this.lastEvent); + } + + /** + * Some tests for the equals() method. + */ + public void testEquals() { + DefaultHeatMapDataset d1 = new DefaultHeatMapDataset(5, 10, 1.0, 2.0, + 3.0, 4.0); + DefaultHeatMapDataset d2 = new DefaultHeatMapDataset(5, 10, 1.0, 2.0, + 3.0, 4.0); + assertEquals(d1, d2); + + d1 = new DefaultHeatMapDataset(6, 10, 1.0, 2.0, 3.0, 4.0); + assertFalse(d1.equals(d2)); + d2 = new DefaultHeatMapDataset(6, 10, 1.0, 2.0, 3.0, 4.0); + assertTrue(d1.equals(d2)); + + d1 = new DefaultHeatMapDataset(6, 11, 1.0, 2.0, 3.0, 4.0); + assertFalse(d1.equals(d2)); + d2 = new DefaultHeatMapDataset(6, 11, 1.0, 2.0, 3.0, 4.0); + assertTrue(d1.equals(d2)); + + d1 = new DefaultHeatMapDataset(6, 11, 2.0, 2.0, 3.0, 4.0); + assertFalse(d1.equals(d2)); + d2 = new DefaultHeatMapDataset(6, 11, 2.0, 2.0, 3.0, 4.0); + assertTrue(d1.equals(d2)); + + d1 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 3.0, 4.0); + assertFalse(d1.equals(d2)); + d2 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 3.0, 4.0); + assertTrue(d1.equals(d2)); + + d1 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 4.0); + assertFalse(d1.equals(d2)); + d2 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 4.0); + assertTrue(d1.equals(d2)); + + d1 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 5.0); + assertFalse(d1.equals(d2)); + d2 = new DefaultHeatMapDataset(6, 11, 2.0, 3.0, 4.0, 5.0); + assertTrue(d1.equals(d2)); + + d1.setZValue(1, 2, 3.0); + assertFalse(d1.equals(d2)); + d2.setZValue(1, 2, 3.0); + assertTrue(d1.equals(d2)); + + d1.setZValue(0, 0, Double.NEGATIVE_INFINITY); + assertFalse(d1.equals(d2)); + d2.setZValue(0, 0, Double.NEGATIVE_INFINITY); + assertTrue(d1.equals(d2)); + + d1.setZValue(0, 1, Double.POSITIVE_INFINITY); + assertFalse(d1.equals(d2)); + d2.setZValue(0, 1, Double.POSITIVE_INFINITY); + assertTrue(d1.equals(d2)); + + d1.setZValue(0, 2, Double.NaN); + assertFalse(d1.equals(d2)); + d2.setZValue(0, 2, Double.NaN); + assertTrue(d1.equals(d2)); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + DefaultHeatMapDataset d1 = new DefaultHeatMapDataset(2, 3, -1.0, 4.0, + -2.0, 5.0); + d1.setZValue(0, 0, 10.0); + d1.setZValue(0, 1, Double.NEGATIVE_INFINITY); + d1.setZValue(0, 2, Double.POSITIVE_INFINITY); + d1.setZValue(1, 0, Double.NaN); + DefaultHeatMapDataset d2 = null; + try { + d2 = (DefaultHeatMapDataset) d1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(d1 != d2); + assertTrue(d1.getClass() == d2.getClass()); + assertTrue(d1.equals(d2)); + + // simple check for independence + d1.setZValue(0, 0, 11.0); + assertFalse(d1.equals(d2)); + d2.setZValue(0, 0, 11.0); + assertTrue(d1.equals(d2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + DefaultHeatMapDataset d1 = new DefaultHeatMapDataset(2, 3, -1.0, 4.0, + -2.0, 5.0); + d1.setZValue(0, 0, 10.0); + d1.setZValue(0, 1, Double.NEGATIVE_INFINITY); + d1.setZValue(0, 2, Double.POSITIVE_INFINITY); + d1.setZValue(1, 0, Double.NaN); + + DefaultHeatMapDataset d2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(d1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + d2 = (DefaultHeatMapDataset) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(d1, d2); + } + + /** + * Runs the test suite using JUnit's text-based runner. + * + * @param args ignored. + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 19:26:05
|
Revision: 1965 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1965&view=rev Author: mungady Date: 2009-04-07 19:25:07 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Added XYTitleAnnotation plus tests. Modified Paths: -------------- trunk/tests/org/jfree/chart/annotations/junit/AnnotationsPackageTests.java Added Paths: ----------- trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java trunk/tests/org/jfree/chart/annotations/junit/XYTitleAnnotationTests.java Added: trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java =================================================================== --- trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java (rev 0) +++ trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java 2009-04-07 19:25:07 UTC (rev 1965) @@ -0,0 +1,393 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * ---------------------- + * XYTitleAnnotation.java + * ---------------------- + * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): Andrew Mickish; + * + * Changes: + * -------- + * 02-Feb-2007 : Version 1 (DG); + * 30-Apr-2007 : Fixed equals() method (DG); + * 26-Feb-2008 : Fixed NullPointerException when drawing chart with a null + * ChartRenderingInfo - see patch 1901599 by Andrew Mickish (DG); + * 03-Sep-2008 : Moved from experimental to main (DG); + * + */ + +package org.jfree.chart.annotations; + +import java.awt.Graphics2D; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.io.Serializable; +import org.jfree.chart.axis.AxisLocation; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.block.BlockParams; +import org.jfree.chart.block.EntityBlockResult; +import org.jfree.chart.block.RectangleConstraint; +import org.jfree.chart.plot.Plot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.PlotRenderingInfo; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.title.Title; +import org.jfree.chart.util.HashUtilities; +import org.jfree.chart.util.ObjectUtilities; +import org.jfree.chart.util.PublicCloneable; +import org.jfree.chart.util.RectangleAnchor; +import org.jfree.chart.util.RectangleEdge; +import org.jfree.chart.util.Size2D; +import org.jfree.data.Range; +import org.jfree.experimental.chart.util.XYCoordinateType; + +/** + * An annotation that allows any {@link Title} to be placed at a location on + * an {@link XYPlot}. + * + * @since 1.0.11 + */ +public class XYTitleAnnotation extends AbstractXYAnnotation + implements Cloneable, PublicCloneable, Serializable { + + /** For serialization. */ + private static final long serialVersionUID = -4364694501921559958L; + + /** The coordinate type. */ + private XYCoordinateType coordinateType; + + /** The x-coordinate (in data space). */ + private double x; + + /** The y-coordinate (in data space). */ + private double y; + + /** The maximum width. */ + private double maxWidth; + + /** The maximum height. */ + private double maxHeight; + + /** The title. */ + private Title title; + + /** + * The title anchor point. + */ + private RectangleAnchor anchor; + + /** + * Creates a new annotation to be displayed at the specified (x, y) + * location. + * + * @param x the x-coordinate (in data space). + * @param y the y-coordinate (in data space). + * @param title the title (<code>null</code> not permitted). + */ + public XYTitleAnnotation(double x, double y, Title title) { + this(x, y, title, RectangleAnchor.CENTER); + } + + /** + * Creates a new annotation to be displayed at the specified (x, y) + * location. + * + * @param x the x-coordinate (in data space). + * @param y the y-coordinate (in data space). + * @param title the title (<code>null</code> not permitted). + * @param anchor the title anchor (<code>null</code> not permitted). + */ + public XYTitleAnnotation(double x, double y, Title title, + RectangleAnchor anchor) { + if (title == null) { + throw new IllegalArgumentException("Null 'title' argument."); + } + if (anchor == null) { + throw new IllegalArgumentException("Null 'anchor' argument."); + } + this.coordinateType = XYCoordinateType.RELATIVE; + this.x = x; + this.y = y; + this.maxWidth = 0.0; + this.maxHeight = 0.0; + this.title = title; + this.anchor = anchor; + } + + /** + * Returns the coordinate type (set in the constructor). + * + * @return The coordinate type (never <code>null</code>). + */ + public XYCoordinateType getCoordinateType() { + return this.coordinateType; + } + + /** + * Returns the x-coordinate for the annotation. + * + * @return The x-coordinate. + */ + public double getX() { + return this.x; + } + + /** + * Returns the y-coordinate for the annotation. + * + * @return The y-coordinate. + */ + public double getY() { + return this.y; + } + + /** + * Returns the title for the annotation. + * + * @return The title. + */ + public Title getTitle() { + return this.title; + } + + /** + * Returns the title anchor for the annotation. + * + * @return The title anchor. + */ + public RectangleAnchor getTitleAnchor() { + return this.anchor; + } + + /** + * Returns the maximum width. + * + * @return The maximum width. + */ + public double getMaxWidth() { + return this.maxWidth; + } + + /** + * Sets the maximum width. + * + * @param max the maximum width (0.0 or less means no maximum). + */ + public void setMaxWidth(double max) { + this.maxWidth = max; + } + + /** + * Returns the maximum height. + * + * @return The maximum height. + */ + public double getMaxHeight() { + return this.maxHeight; + } + + /** + * Sets the maximum height. + * + * @param max the maximum height. + */ + public void setMaxHeight(double max) { + this.maxHeight = max; + } + + /** + * Draws the annotation. This method is called by the drawing code in the + * {@link XYPlot} class, you don't normally need to call this method + * directly. + * + * @param g2 the graphics device. + * @param plot the plot. + * @param dataArea the data area. + * @param domainAxis the domain axis. + * @param rangeAxis the range axis. + * @param rendererIndex the renderer index. + * @param info if supplied, this info object will be populated with + * entity information. + */ + public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, + ValueAxis domainAxis, ValueAxis rangeAxis, + int rendererIndex, + PlotRenderingInfo info) { + + PlotOrientation orientation = plot.getOrientation(); + AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); + AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); + RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( + domainAxisLocation, orientation); + RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( + rangeAxisLocation, orientation); + Range xRange = domainAxis.getRange(); + Range yRange = rangeAxis.getRange(); + double anchorX = 0.0; + double anchorY = 0.0; + if (this.coordinateType == XYCoordinateType.RELATIVE) { + anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); + anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); + } + else { + anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); + anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); + } + + float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, + domainEdge); + float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, + rangeEdge); + float xx = 0.0f; + float yy = 0.0f; + if (orientation == PlotOrientation.HORIZONTAL) { + xx = j2DY; + yy = j2DX; + } + else if (orientation == PlotOrientation.VERTICAL) { + xx = j2DX; + yy = j2DY; + } + + double maxW = dataArea.getWidth(); + double maxH = dataArea.getHeight(); + if (this.coordinateType == XYCoordinateType.RELATIVE) { + if (this.maxWidth > 0.0) { + maxW = maxW * this.maxWidth; + } + if (this.maxHeight > 0.0) { + maxH = maxH * this.maxHeight; + } + } + if (this.coordinateType == XYCoordinateType.DATA) { + maxW = this.maxWidth; + maxH = this.maxHeight; + } + RectangleConstraint rc = new RectangleConstraint( + new Range(0, maxW), new Range(0, maxH)); + + Size2D size = this.title.arrange(g2, rc); + Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, + size.height); + Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, + this.anchor); + xx = xx - (float) anchorPoint.getX(); + yy = yy - (float) anchorPoint.getY(); + titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); + BlockParams p = new BlockParams(); + if (info != null) { + if (info.getOwner().getEntityCollection() != null) { + p.setGenerateEntities(true); + } + } + Object result = this.title.draw(g2, titleRect, p); + if (info != null) { + if (result instanceof EntityBlockResult) { + EntityBlockResult ebr = (EntityBlockResult) result; + info.getOwner().getEntityCollection().addAll( + ebr.getEntityCollection()); + } + String toolTip = getToolTipText(); + String url = getURL(); + if (toolTip != null || url != null) { + addEntity(info, new Rectangle2D.Float(xx, yy, + (float) size.width, (float) size.height), + rendererIndex, toolTip, url); + } + } + } + + /** + * Tests this object 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 XYTitleAnnotation)) { + return false; + } + XYTitleAnnotation that = (XYTitleAnnotation) obj; + if (this.coordinateType != that.coordinateType) { + return false; + } + if (this.x != that.x) { + return false; + } + if (this.y != that.y) { + return false; + } + if (this.maxWidth != that.maxWidth) { + return false; + } + if (this.maxHeight != that.maxHeight) { + return false; + } + if (!ObjectUtilities.equal(this.title, that.title)) { + return false; + } + if (!this.anchor.equals(that.anchor)) { + return false; + } + return super.equals(obj); + } + + /** + * Returns a hash code for this object. + * + * @return A hash code. + */ + public int hashCode() { + int result = 193; + result = HashUtilities.hashCode(result, this.anchor); + result = HashUtilities.hashCode(result, this.coordinateType); + result = HashUtilities.hashCode(result, this.x); + result = HashUtilities.hashCode(result, this.y); + result = HashUtilities.hashCode(result, this.maxWidth); + result = HashUtilities.hashCode(result, this.maxHeight); + result = HashUtilities.hashCode(result, this.title); + return result; + } + + /** + * Returns a clone of the annotation. + * + * @return A clone. + * + * @throws CloneNotSupportedException if the annotation can't be cloned. + */ + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} Modified: trunk/tests/org/jfree/chart/annotations/junit/AnnotationsPackageTests.java =================================================================== --- trunk/tests/org/jfree/chart/annotations/junit/AnnotationsPackageTests.java 2009-04-07 19:19:19 UTC (rev 1964) +++ trunk/tests/org/jfree/chart/annotations/junit/AnnotationsPackageTests.java 2009-04-07 19:25:07 UTC (rev 1965) @@ -74,6 +74,7 @@ suite.addTestSuite(XYPolygonAnnotationTests.class); suite.addTestSuite(XYShapeAnnotationTests.class); suite.addTestSuite(XYTextAnnotationTests.class); + suite.addTestSuite(XYTitleAnnotationTests.class); return suite; } Added: trunk/tests/org/jfree/chart/annotations/junit/XYTitleAnnotationTests.java =================================================================== --- trunk/tests/org/jfree/chart/annotations/junit/XYTitleAnnotationTests.java (rev 0) +++ trunk/tests/org/jfree/chart/annotations/junit/XYTitleAnnotationTests.java 2009-04-07 19:25:07 UTC (rev 1965) @@ -0,0 +1,207 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * --------------------------- + * XYTitleAnnotationTests.java + * --------------------------- + * (C) Copyright 2007, 2008, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 30-Apr-2007 : Version 1 (DG); + * 26-Feb-2008 : Added testDrawWithNullInfo() (DG); + * + */ + +package org.jfree.chart.annotations.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.chart.JFreeChart; +import org.jfree.chart.annotations.XYTitleAnnotation; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.chart.title.TextTitle; +import org.jfree.data.xy.DefaultTableXYDataset; +import org.jfree.data.xy.XYSeries; + +/** + * Tests for the {@link XYTitleAnnotation} class. + */ +public class XYTitleAnnotationTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(XYTitleAnnotationTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public XYTitleAnnotationTests(String name) { + super(name); + } + + /** + * Confirm that the equals method can distinguish all the required fields. + */ + public void testEquals() { + TextTitle t = new TextTitle("Title"); + XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); + XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t); + assertTrue(a1.equals(a2)); + + a1 = new XYTitleAnnotation(1.1, 2.0, t); + assertFalse(a1.equals(a2)); + a2 = new XYTitleAnnotation(1.1, 2.0, t); + assertTrue(a1.equals(a2)); + + a1 = new XYTitleAnnotation(1.1, 2.2, t); + assertFalse(a1.equals(a2)); + a2 = new XYTitleAnnotation(1.1, 2.2, t); + assertTrue(a1.equals(a2)); + + TextTitle t2 = new TextTitle("Title 2"); + a1 = new XYTitleAnnotation(1.1, 2.2, t2); + assertFalse(a1.equals(a2)); + a2 = new XYTitleAnnotation(1.1, 2.2, t2); + assertTrue(a1.equals(a2)); + } + + /** + * Two objects that are equal are required to return the same hashCode. + */ + public void testHashCode() { + TextTitle t = new TextTitle("Title"); + XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); + XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t); + assertTrue(a1.equals(a2)); + int h1 = a1.hashCode(); + int h2 = a2.hashCode(); + assertEquals(h1, h2); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + TextTitle t = new TextTitle("Title"); + XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); + XYTitleAnnotation a2 = null; + try { + a2 = (XYTitleAnnotation) a1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(a1 != a2); + assertTrue(a1.getClass() == a2.getClass()); + assertTrue(a1.equals(a2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + TextTitle t = new TextTitle("Title"); + XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); + XYTitleAnnotation a2 = null; + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(a1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + a2 = (XYTitleAnnotation) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(a1, a2); + } + + /** + * Draws the chart with a <code>null</code> info object to make sure that + * no exceptions are thrown. + */ + public void testDrawWithNullInfo() { + boolean success = false; + try { + DefaultTableXYDataset dataset = new DefaultTableXYDataset(); + + XYSeries s1 = new XYSeries("Series 1", true, false); + s1.add(5.0, 5.0); + s1.add(10.0, 15.5); + s1.add(15.0, 9.5); + s1.add(20.0, 7.5); + dataset.addSeries(s1); + + XYSeries s2 = new XYSeries("Series 2", true, false); + s2.add(5.0, 5.0); + s2.add(10.0, 15.5); + s2.add(15.0, 9.5); + s2.add(20.0, 3.5); + dataset.addSeries(s2); + XYPlot plot = new XYPlot(dataset, + new NumberAxis("X"), new NumberAxis("Y"), + new XYLineAndShapeRenderer()); + plot.addAnnotation(new XYTitleAnnotation(5.0, 6.0, + new TextTitle("Hello World!"))); + JFreeChart chart = new JFreeChart(plot); + /* BufferedImage image = */ chart.createBufferedImage(300, 200, + null); + success = true; + } + catch (NullPointerException e) { + e.printStackTrace(); + success = false; + } + assertTrue(success); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 19:51:46
|
Revision: 1966 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1966&view=rev Author: mungady Date: 2009-04-07 19:51:44 +0000 (Tue, 07 Apr 2009) Log Message: ----------- New files. Added Paths: ----------- trunk/source/org/jfree/chart/util/LineUtilities.java trunk/tests/org/jfree/chart/urls/junit/CustomCategoryURLGeneratorTests.java trunk/tests/org/jfree/chart/util/junit/LineUtilitiesTests.java trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java Added: trunk/source/org/jfree/chart/util/LineUtilities.java =================================================================== --- trunk/source/org/jfree/chart/util/LineUtilities.java (rev 0) +++ trunk/source/org/jfree/chart/util/LineUtilities.java 2009-04-07 19:51:44 UTC (rev 1966) @@ -0,0 +1,142 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * ------------------ + * LineUtilities.java + * ------------------ + * (C) Copyright 2008, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 05-Nov-2008 : Version 1 (DG); + * + */ + +package org.jfree.chart.util; + +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; + +/** + * Some utility methods for {@link Line2D} objects. + * + * @since 1.0.12 + */ +public class LineUtilities { + + /** + * Clips the specified line to the given rectangle. + * + * @param line the line (<code>null</code> not permitted). + * @param rect the clipping rectangle (<code>null</code> not permitted). + * + * @return <code>true</code> if the clipped line is visible, and + * <code>false</code> otherwise. + */ + public static boolean clipLine(Line2D line, Rectangle2D rect) { + + double x1 = line.getX1(); + double y1 = line.getY1(); + double x2 = line.getX2(); + double y2 = line.getY2(); + + double minX = rect.getMinX(); + double maxX = rect.getMaxX(); + double minY = rect.getMinY(); + double maxY = rect.getMaxY(); + + int f1 = rect.outcode(x1, y1); + int f2 = rect.outcode(x2, y2); + + while ((f1 | f2) != 0) { + if ((f1 & f2) != 0) { + return false; + } + double dx = (x2 - x1); + double dy = (y2 - y1); + // update (x1, y1), (x2, y2) and f1 and f2 using intersections + // then recheck + if (f1 != 0) { + // first point is outside, so we update it against one of the + // four sides then continue + if ((f1 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT + && dx != 0.0) { + y1 = y1 + (minX - x1) * dy / dx; + x1 = minX; + } + else if ((f1 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT + && dx != 0.0) { + y1 = y1 + (maxX - x1) * dy / dx; + x1 = maxX; + } + else if ((f1 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM + && dy != 0.0) { + x1 = x1 + (maxY - y1) * dx / dy; + y1 = maxY; + } + else if ((f1 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP + && dy != 0.0) { + x1 = x1 + (minY - y1) * dx / dy; + y1 = minY; + } + f1 = rect.outcode(x1, y1); + } + else if (f2 != 0) { + // second point is outside, so we update it against one of the + // four sides then continue + if ((f2 & Rectangle2D.OUT_LEFT) == Rectangle2D.OUT_LEFT + && dx != 0.0) { + y2 = y2 + (minX - x2) * dy / dx; + x2 = minX; + } + else if ((f2 & Rectangle2D.OUT_RIGHT) == Rectangle2D.OUT_RIGHT + && dx != 0.0) { + y2 = y2 + (maxX - x2) * dy / dx; + x2 = maxX; + } + else if ((f2 & Rectangle2D.OUT_BOTTOM) == Rectangle2D.OUT_BOTTOM + && dy != 0.0) { + x2 = x2 + (maxY - y2) * dx / dy; + y2 = maxY; + } + else if ((f2 & Rectangle2D.OUT_TOP) == Rectangle2D.OUT_TOP + && dy != 0.0) { + x2 = x2 + (minY - y2) * dx / dy; + y2 = minY; + } + f2 = rect.outcode(x2, y2); + } + } + + line.setLine(x1, y1, x2, y2); + return true; // the line is visible - if it wasn't, we'd have + // returned false from within the while loop above + + } +} Added: trunk/tests/org/jfree/chart/urls/junit/CustomCategoryURLGeneratorTests.java =================================================================== --- trunk/tests/org/jfree/chart/urls/junit/CustomCategoryURLGeneratorTests.java (rev 0) +++ trunk/tests/org/jfree/chart/urls/junit/CustomCategoryURLGeneratorTests.java 2009-04-07 19:51:44 UTC (rev 1966) @@ -0,0 +1,204 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * ------------------------------------ + * CustomCategoryURLGeneratorTests.java + * ------------------------------------ + * (C) Copyright 2008, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 23-Apr-2008 : Version 1, based on CustomXYURLGeneratorTests.java (DG); + * + */ + +package org.jfree.chart.urls.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 java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.urls.CustomCategoryURLGenerator; +import org.jfree.chart.util.PublicCloneable; + +/** + * Tests for the {@link CustomCategoryURLGenerator} class. + */ +public class CustomCategoryURLGeneratorTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(CustomCategoryURLGeneratorTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public CustomCategoryURLGeneratorTests(String name) { + super(name); + } + + /** + * Some checks for the equals() method. + */ + public void testEquals() { + CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator(); + CustomCategoryURLGenerator g2 = new CustomCategoryURLGenerator(); + assertTrue(g1.equals(g2)); + List u1 = new java.util.ArrayList(); + u1.add("URL A1"); + u1.add("URL A2"); + u1.add("URL A3"); + g1.addURLSeries(u1); + assertFalse(g1.equals(g2)); + List u2 = new java.util.ArrayList(); + u2.add("URL A1"); + u2.add("URL A2"); + u2.add("URL A3"); + g2.addURLSeries(u2); + assertTrue(g1.equals(g2)); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator(); + List u1 = new java.util.ArrayList(); + u1.add("URL A1"); + u1.add("URL A2"); + u1.add("URL A3"); + g1.addURLSeries(u1); + CustomCategoryURLGenerator g2 = null; + try { + g2 = (CustomCategoryURLGenerator) g1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(g1 != g2); + assertTrue(g1.getClass() == g2.getClass()); + assertTrue(g1.equals(g2)); + + // check independence + List u2 = new java.util.ArrayList(); + u2.add("URL XXX"); + g1.addURLSeries(u2); + assertFalse(g1.equals(g2)); + g2.addURLSeries(new java.util.ArrayList(u2)); + assertTrue(g1.equals(g2)); + } + + /** + * Checks that the class implements PublicCloneable. + */ + public void testPublicCloneable() { + CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator(); + assertTrue(g1 instanceof PublicCloneable); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + List u1 = new java.util.ArrayList(); + u1.add("URL A1"); + u1.add("URL A2"); + u1.add("URL A3"); + + List u2 = new java.util.ArrayList(); + u2.add("URL B1"); + u2.add("URL B2"); + u2.add("URL B3"); + + CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator(); + CustomCategoryURLGenerator g2 = null; + + g1.addURLSeries(u1); + g1.addURLSeries(u2); + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(g1); + out.close(); + + ObjectInput in = new ObjectInputStream( + new ByteArrayInputStream(buffer.toByteArray())); + g2 = (CustomCategoryURLGenerator) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(g1, g2); + + } + + /** + * Some checks for the addURLSeries() method. + */ + public void testAddURLSeries() { + CustomCategoryURLGenerator g1 = new CustomCategoryURLGenerator(); + // you can add a null list - it would have been better if this + // required EMPTY_LIST + g1.addURLSeries(null); + assertEquals(1, g1.getListCount()); + assertEquals(0, g1.getURLCount(0)); + + List list1 = new java.util.ArrayList(); + list1.add("URL1"); + g1.addURLSeries(list1); + assertEquals(2, g1.getListCount()); + assertEquals(0, g1.getURLCount(0)); + assertEquals(1, g1.getURLCount(1)); + assertEquals("URL1", g1.getURL(1, 0)); + + // if we modify the original list, it's best if the URL generator is + // not affected + list1.clear(); + assertEquals("URL1", g1.getURL(1, 0)); + } + +} Added: trunk/tests/org/jfree/chart/util/junit/LineUtilitiesTests.java =================================================================== --- trunk/tests/org/jfree/chart/util/junit/LineUtilitiesTests.java (rev 0) +++ trunk/tests/org/jfree/chart/util/junit/LineUtilitiesTests.java 2009-04-07 19:51:44 UTC (rev 1966) @@ -0,0 +1,148 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * ----------------------- + * LineUtilitiesTests.java + * ----------------------- + * (C) Copyright 2008, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 05-Nov-2008 : Version 1 (DG); + * + */ + +package org.jfree.chart.util.junit; + +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.chart.util.LineUtilities; + +/** + * Tests for the {@link LineUtilities} class. + */ +public class LineUtilitiesTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(LineUtilitiesTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public LineUtilitiesTests(String name) { + super(name); + } + + private boolean lineEquals(Line2D line, double x1, double y1, double x2, + double y2) { + boolean result = true; + double epsilon = 0.0000000001; + if (Math.abs(line.getX1() - x1) > epsilon) result = false; + if (Math.abs(line.getY1() - y1) > epsilon) result = false; + if (Math.abs(line.getX2() - x2) > epsilon) result = false; + if (Math.abs(line.getY2() - y2) > epsilon) result = false; + if (result == false) { + System.out.println(line.getX1() + ", " + line.getY1() + ", " + + line.getX2() + ", " + line.getY2()); + } + return result; + } + + public void testClipLine() { + Rectangle2D rect = new Rectangle2D.Double(1.0, 1.0, 1.0, 1.0); + Line2D line = new Line2D.Double(); + + assertFalse(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 0.0, 0.0, 0.0, 0.0)); + + line.setLine(0.5, 0.5, 0.6, 0.6); + assertFalse(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 0.5, 0.5, 0.6, 0.6)); + + line.setLine(0.5, 0.5, 1.6, 0.6); + assertFalse(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 0.5, 0.5, 1.6, 0.6)); + + line.setLine(0.5, 0.5, 2.6, 0.6); + assertFalse(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 0.5, 0.5, 2.6, 0.6)); + + line.setLine(0.5, 0.5, 0.6, 1.6); + assertFalse(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 0.5, 0.5, 0.6, 1.6)); + + line.setLine(0.5, 0.5, 1.6, 1.6); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 1.0, 1.0, 1.6, 1.6)); + + line.setLine(0.5, 0.5, 2.6, 1.6); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 1.4545454545454546, 1.0, 2.0, + 1.2857142857142858)); + + line.setLine(0.5, 0.5, 0.5, 2.6); + assertFalse(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 0.5, 0.5, 0.5, 2.6)); + + line.setLine(0.5, 0.5, 1.5, 2.6); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 1.0, 1.55, 1.2142857142857142, 2.0)); + + line.setLine(0.5, 0.5, 2.5, 2.6); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 1.0, 1.025, 1.9285714285714284, 2.0)); + + line.setLine(0.5, 0.5, 1.5, 1.5); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 1.0, 1.0, 1.5, 1.5)); + + line.setLine(2.5, 1.0, 1.5, 1.5); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 2.0, 1.25, 1.5, 1.5)); + + line.setLine(1.5, 1.5, 2.5, 1.0); + assertTrue(LineUtilities.clipLine(line, rect)); + assertTrue(lineEquals(line, 1.5, 1.5, 2.0, 1.25)); + } + +} + Added: trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java =================================================================== --- trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java (rev 0) +++ trunk/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java 2009-04-07 19:51:44 UTC (rev 1966) @@ -0,0 +1,221 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * --------------------------------------- + * DefaultBoxAndWhiskerXYDatasetTests.java + * --------------------------------------- + * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 12-Nov-2007 : Version 1 (DG); + * + */ + +package org.jfree.data.statistics.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 java.util.ArrayList; +import java.util.Date; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.data.Range; +import org.jfree.data.statistics.BoxAndWhiskerItem; +import org.jfree.data.statistics.DefaultBoxAndWhiskerXYDataset; + +/** + * Tests for the {@link DefaultBoxAndWhiskerXYDataset} class. + */ +public class DefaultBoxAndWhiskerXYDatasetTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(DefaultBoxAndWhiskerXYDatasetTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public DefaultBoxAndWhiskerXYDatasetTests(String name) { + super(name); + } + + /** + * Confirm that the equals method can distinguish all the required fields. + */ + public void testEquals() { + DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + DefaultBoxAndWhiskerXYDataset d2 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + assertTrue(d1.equals(d2)); + + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertFalse(d1.equals(d2)); + d2.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertTrue(d1.equals(d2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + DefaultBoxAndWhiskerXYDataset d2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(d1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + d2 = (DefaultBoxAndWhiskerXYDataset) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(d1, d2); + + // test independence + d1.add(new Date(2L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertFalse(d1.equals(d2)); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + DefaultBoxAndWhiskerXYDataset d2 = null; + try { + d2 = (DefaultBoxAndWhiskerXYDataset) d1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(d1 != d2); + assertTrue(d1.getClass() == d2.getClass()); + assertTrue(d1.equals(d2)); + + // test independence + d1.add(new Date(2L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertFalse(d1.equals(d2)); + } + + private static final double EPSILON = 0.0000000001; + + /** + * Some checks for the add() method. + */ + public void testAdd() { + DefaultBoxAndWhiskerXYDataset dataset + = new DefaultBoxAndWhiskerXYDataset("S1"); + BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, new ArrayList()); + dataset.add(new Date(33L), item1); + + assertEquals(1.0, dataset.getY(0, 0).doubleValue(), EPSILON); + assertEquals(1.0, dataset.getMeanValue(0, 0).doubleValue(), EPSILON); + assertEquals(2.0, dataset.getMedianValue(0, 0).doubleValue(), EPSILON); + assertEquals(3.0, dataset.getQ1Value(0, 0).doubleValue(), EPSILON); + assertEquals(4.0, dataset.getQ3Value(0, 0).doubleValue(), EPSILON); + assertEquals(5.0, dataset.getMinRegularValue(0, 0).doubleValue(), + EPSILON); + assertEquals(6.0, dataset.getMaxRegularValue(0, 0).doubleValue(), + EPSILON); + assertEquals(7.0, dataset.getMinOutlier(0, 0).doubleValue(), EPSILON); + assertEquals(8.0, dataset.getMaxOutlier(0, 0).doubleValue(), EPSILON); + assertEquals(new Range(5.0, 6.0), dataset.getRangeBounds(false)); + } + + /** + * Some basic checks for the constructor. + */ + public void testConstructor() { + DefaultBoxAndWhiskerXYDataset dataset + = new DefaultBoxAndWhiskerXYDataset("S1"); + assertEquals(1, dataset.getSeriesCount()); + assertEquals(0, dataset.getItemCount(0)); + assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); + assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); + } + + /** + * Some checks for the getRangeBounds() method. + */ + public void testGetRangeBounds() { + DefaultBoxAndWhiskerXYDataset d1 + = new DefaultBoxAndWhiskerXYDataset("S"); + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(false)); + assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(true)); + + d1.add(new Date(1L), new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, + 6.5, 7.5, 8.5, new ArrayList())); + assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(false)); + assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(true)); + + d1.add(new Date(2L), new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, + 7.5, 8.5, 9.5, new ArrayList())); + assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(false)); + assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(true)); + } + + +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-04-07 20:08:44
|
Revision: 1969 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1969&view=rev Author: mungady Date: 2009-04-07 20:08:37 +0000 (Tue, 07 Apr 2009) Log Message: ----------- Synchronised with 1.0.x. Modified Paths: -------------- trunk/source/org/jfree/chart/renderer/category/WaterfallBarRenderer.java trunk/tests/org/jfree/chart/plot/junit/FastScatterPlotTests.java trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java trunk/tests/org/jfree/chart/renderer/category/junit/WaterfallBarRendererTests.java trunk/tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java Modified: trunk/source/org/jfree/chart/renderer/category/WaterfallBarRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/WaterfallBarRenderer.java 2009-04-07 19:52:20 UTC (rev 1968) +++ trunk/source/org/jfree/chart/renderer/category/WaterfallBarRenderer.java 2009-04-07 20:08:37 UTC (rev 1969) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------- * WaterfallBarRenderer.java * ------------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: Darshan Shah; * Contributor(s): David Gilbert (for Object Refinery Limited); @@ -52,6 +52,8 @@ * 27-Mar-2008 : Fixed error in findRangeBounds() method (DG); * 26-Sep-2008 : Fixed bug with bar alignment when maximumBarWidth is * applied (DG); + * 04-Feb-2009 : Updated findRangeBounds to handle null dataset consistently + * with other renderers (DG); * */ @@ -272,11 +274,9 @@ * @return The range (or <code>null</code> if the dataset is empty). */ public Range findRangeBounds(CategoryDataset dataset) { - if (dataset == null) { - throw new IllegalArgumentException("Null 'dataset' argument."); + return null; } - boolean allItemsNull = true; // we'll set this to false if there is at // least one non-null data item... double minimum = 0.0; Modified: trunk/tests/org/jfree/chart/plot/junit/FastScatterPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/FastScatterPlotTests.java 2009-04-07 19:52:20 UTC (rev 1968) +++ trunk/tests/org/jfree/chart/plot/junit/FastScatterPlotTests.java 2009-04-07 20:08:37 UTC (rev 1969) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------- * FastScatterPlotTests.java * ------------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,6 +35,8 @@ * Changes * ------- * 18-Mar-2003 : Version 1 (DG); + * 29-Jan-2009 : Updated testEquals() (DG); + * 26-Mar-2009 : Updated testEquals() for new panning fields (DG); * */ @@ -136,9 +138,61 @@ plot2.setRangeGridlineStroke(s2); assertTrue(plot1.equals(plot2)); + plot1.setDomainPannable(true); + assertFalse(plot1.equals(plot2)); + plot2.setDomainPannable(true); + assertTrue(plot1.equals(plot2)); + + plot1.setRangePannable(true); + assertFalse(plot1.equals(plot2)); + plot2.setRangePannable(true); + assertTrue(plot1.equals(plot2)); + } /** + * Some tests for the data array equality in the equals() method. + */ + public void testEquals2() { + FastScatterPlot plot1 = new FastScatterPlot(); + FastScatterPlot plot2 = new FastScatterPlot(); + assertTrue(plot1.equals(plot2)); + assertTrue(plot2.equals(plot1)); + + float[][] a = new float[2][]; + float[][] b = new float[2][]; + plot1.setData(a); + assertFalse(plot1.equals(plot2)); + plot2.setData(b); + assertTrue(plot1.equals(plot2)); + + a[0] = new float[6]; + assertFalse(plot1.equals(plot2)); + b[0] = new float[6]; + assertTrue(plot1.equals(plot2)); + + a[0][0] = 1.0f; + assertFalse(plot1.equals(plot2)); + b[0][0] = 1.0f; + assertTrue(plot1.equals(plot2)); + + a[0][1] = Float.NaN; + assertFalse(plot1.equals(plot2)); + b[0][1] = Float.NaN; + assertTrue(plot1.equals(plot2)); + + a[0][2] = Float.POSITIVE_INFINITY; + assertFalse(plot1.equals(plot2)); + b[0][2] = Float.POSITIVE_INFINITY; + assertTrue(plot1.equals(plot2)); + + a[0][3] = Float.NEGATIVE_INFINITY; + assertFalse(plot1.equals(plot2)); + b[0][3] = Float.NEGATIVE_INFINITY; + assertTrue(plot1.equals(plot2)); + } + + /** * Confirm that cloning works. */ public void testCloning() { @@ -149,7 +203,6 @@ } catch (CloneNotSupportedException e) { e.printStackTrace(); - System.err.println("Failed to clone."); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); @@ -160,9 +213,7 @@ * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { - float[][] data = createData(); - ValueAxis domainAxis = new NumberAxis("X"); ValueAxis rangeAxis = new NumberAxis("Y"); FastScatterPlot p1 = new FastScatterPlot(data, domainAxis, rangeAxis); @@ -174,17 +225,15 @@ out.writeObject(p1); out.close(); - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); p2 = (FastScatterPlot) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(p1, p2); - } /** @@ -218,16 +267,13 @@ * @return Random data. */ private float[][] createData() { - float[][] result = new float[2][1000]; for (int i = 0; i < result[0].length; i++) { - float x = (float) i + 100; result[0][i] = x; result[1][i] = 100 + (float) Math.random() * 1000; } return result; - } } Modified: trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-04-07 19:52:20 UTC (rev 1968) +++ trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-04-07 20:08:37 UTC (rev 1969) @@ -417,6 +417,17 @@ plot2.setRangeMinorGridlineStroke(new BasicStroke(1.23f)); assertTrue(plot1.equals(plot2)); + List axisIndices = Arrays.asList(new Integer[] {new Integer(0), + new Integer(1)}); + plot1.mapDatasetToDomainAxes(0, axisIndices); + assertFalse(plot1.equals(plot2)); + plot2.mapDatasetToDomainAxes(0, axisIndices); + assertTrue(plot1.equals(plot2)); + + plot1.mapDatasetToRangeAxes(0, axisIndices); + assertFalse(plot1.equals(plot2)); + plot2.mapDatasetToRangeAxes(0, axisIndices); + assertTrue(plot1.equals(plot2)); } /** @@ -443,6 +454,10 @@ XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); p1.setRangeAxis(1, new NumberAxis("Range Axis 2")); + List axisIndices = Arrays.asList(new Integer[] {new Integer(0), + new Integer(1)}); + p1.mapDatasetToDomainAxes(0, axisIndices); + p1.mapDatasetToRangeAxes(0, axisIndices); p1.setRenderer(1, new XYBarRenderer()); XYPlot p2 = null; try { @@ -609,9 +624,8 @@ out.writeObject(p1); out.close(); - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); p2 = (XYPlot) in.readObject(); in.close(); } @@ -1067,4 +1081,105 @@ assertFalse(plot.removeRangeMarker(new ValueMarker(0.5))); } + /** + * Some tests for the getDomainAxisForDataset() method. + */ + public void testGetDomainAxisForDataset() { + XYDataset dataset = new XYSeriesCollection(); + NumberAxis xAxis = new NumberAxis("X"); + NumberAxis yAxis = new NumberAxis("Y"); + XYItemRenderer renderer = new DefaultXYItemRenderer(); + XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); + assertEquals(xAxis, plot.getDomainAxisForDataset(0)); + + // should get IllegalArgumentException for negative index + boolean pass = false; + try { + plot.getDomainAxisForDataset(-1); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + // should get IllegalArgumentException for index too high + pass = false; + try { + plot.getDomainAxisForDataset(1); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + // if multiple axes are mapped, the first in the list should be + // returned... + NumberAxis xAxis2 = new NumberAxis("X2"); + plot.setDomainAxis(1, xAxis2); + assertEquals(xAxis, plot.getDomainAxisForDataset(0)); + + plot.mapDatasetToDomainAxis(0, 1); + assertEquals(xAxis2, plot.getDomainAxisForDataset(0)); + + List axisIndices = Arrays.asList(new Integer[] {new Integer(0), + new Integer(1)}); + plot.mapDatasetToDomainAxes(0, axisIndices); + assertEquals(xAxis, plot.getDomainAxisForDataset(0)); + + axisIndices = Arrays.asList(new Integer[] {new Integer(1), + new Integer(2)}); + plot.mapDatasetToDomainAxes(0, axisIndices); + assertEquals(xAxis2, plot.getDomainAxisForDataset(0)); + } + + /** + * Some tests for the getRangeAxisForDataset() method. + */ + public void testGetRangeAxisForDataset() { + XYDataset dataset = new XYSeriesCollection(); + NumberAxis xAxis = new NumberAxis("X"); + NumberAxis yAxis = new NumberAxis("Y"); + XYItemRenderer renderer = new DefaultXYItemRenderer(); + XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); + assertEquals(yAxis, plot.getRangeAxisForDataset(0)); + + // should get IllegalArgumentException for negative index + boolean pass = false; + try { + plot.getRangeAxisForDataset(-1); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + // should get IllegalArgumentException for index too high + pass = false; + try { + plot.getRangeAxisForDataset(1); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + + // if multiple axes are mapped, the first in the list should be + // returned... + NumberAxis yAxis2 = new NumberAxis("Y2"); + plot.setRangeAxis(1, yAxis2); + assertEquals(yAxis, plot.getRangeAxisForDataset(0)); + + plot.mapDatasetToRangeAxis(0, 1); + assertEquals(yAxis2, plot.getRangeAxisForDataset(0)); + + List axisIndices = Arrays.asList(new Integer[] {new Integer(0), + new Integer(1)}); + plot.mapDatasetToRangeAxes(0, axisIndices); + assertEquals(yAxis, plot.getRangeAxisForDataset(0)); + + axisIndices = Arrays.asList(new Integer[] {new Integer(1), + new Integer(2)}); + plot.mapDatasetToRangeAxes(0, axisIndices); + assertEquals(yAxis2, plot.getRangeAxisForDataset(0)); + } } Modified: trunk/tests/org/jfree/chart/renderer/category/junit/WaterfallBarRendererTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/category/junit/WaterfallBarRendererTests.java 2009-04-07 19:52:20 UTC (rev 1968) +++ trunk/tests/org/jfree/chart/renderer/category/junit/WaterfallBarRendererTests.java 2009-04-07 20:08:37 UTC (rev 1969) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------------ * WaterfallBarRendererTests.java * ------------------------------ - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -36,6 +36,7 @@ * ------- * 21-Oct-2003 : Version 1 (DG); * 23-Apr-2008 : Added testPublicCloneable() (DG); + * 04-Feb-2009 : Added testFindRangeBounds() (DG); * */ @@ -80,6 +81,14 @@ } /** + * Some tests for the findRangeBounds() method. + */ + public void testFindRangeBounds() { + WaterfallBarRenderer r = new WaterfallBarRenderer(); + assertNull(r.findRangeBounds(null)); + } + + /** * Check that the equals() method distinguishes all fields. */ public void testEquals() { Modified: trunk/tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java =================================================================== --- trunk/tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java 2009-04-07 19:52:20 UTC (rev 1968) +++ trunk/tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java 2009-04-07 20:08:37 UTC (rev 1969) @@ -38,6 +38,7 @@ * 06-Jan-2003 : Added a test for URL generation (DG); * 24-Nov-2006 : New equals() test (DG); * 17-Apr-2007 : Added additional check to testURL() (DG); + * 23-Apr-2008 : Added testPublicCloneable (DG); * */ @@ -55,6 +56,7 @@ import junit.framework.TestSuite; import org.jfree.chart.urls.StandardPieURLGenerator; +import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DefaultPieDataset; /** @@ -115,6 +117,16 @@ } /** + * Checks that the class does not implement PublicCloneable (the generator + * is immutable). + */ + public void testPublicCloneable() { + StandardPieURLGenerator g1 = new StandardPieURLGenerator( + "index.html?", "cat"); + assertFalse(g1 instanceof PublicCloneable); + } + + /** * 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...> - 2009-06-23 07:48:06
|
Revision: 2129 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2129&view=rev Author: mungady Date: 2009-06-23 07:46:44 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/plot/XYPlot.java trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java Modified: trunk/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/XYPlot.java 2009-06-23 07:43:13 UTC (rev 2128) +++ trunk/source/org/jfree/chart/plot/XYPlot.java 2009-06-23 07:46:44 UTC (rev 2129) @@ -223,6 +223,8 @@ * Voigt (DG); * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * 30-Mar-2009 : Delegate panning to axes (DG); + * 10-May-2009 : Added check for fixedLegendItems in equals(), and code to + * handle cloning (DG); * */ @@ -2119,8 +2121,8 @@ } /** - * Returns the paint for the minor grid lines (if any) plotted against the range - * axis. + * Returns the paint for the minor grid lines (if any) plotted against the + * range axis. * * @return The paint (never <code>null</code>). * @@ -3857,12 +3859,14 @@ while (iterator.hasNext()) { paintLine = false; ValueTick tick = (ValueTick) iterator.next(); - if ((tick.getTickType() == TickType.MINOR) && isDomainMinorGridlinesVisible()){ + if ((tick.getTickType() == TickType.MINOR) + && isDomainMinorGridlinesVisible()) { gridStroke = getDomainMinorGridlineStroke(); gridPaint = getDomainMinorGridlinePaint(); paintLine = true; } - else if ((tick.getTickType() == TickType.MAJOR) && isDomainGridlinesVisible()){ + else if ((tick.getTickType() == TickType.MAJOR) + && isDomainGridlinesVisible()) { gridStroke = getDomainGridlineStroke(); gridPaint = getDomainGridlinePaint(); paintLine = true; @@ -5466,6 +5470,10 @@ if (!ObjectUtilities.equal(this.annotations, that.annotations)) { return false; } + if (!ObjectUtilities.equal(this.fixedLegendItems, + that.fixedLegendItems)) { + return false; + } if (!PaintUtilities.equal(this.domainTickBandPaint, that.domainTickBandPaint)) { return false; @@ -5562,7 +5570,10 @@ clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtilities.clone( this.fixedRangeAxisSpace); } - + if (this.fixedLegendItems != null) { + clone.fixedLegendItems + = (LegendItemCollection) this.fixedLegendItems.clone(); + } clone.quadrantOrigin = (Point2D) ObjectUtilities.clone( this.quadrantOrigin); clone.quadrantPaint = (Paint[]) this.quadrantPaint.clone(); Modified: trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-06-23 07:43:13 UTC (rev 2128) +++ trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-06-23 07:46:44 UTC (rev 2129) @@ -45,6 +45,7 @@ * 20-Jun-2007 : Removed JCommon dependencies (DG); * 07-Apr-2008 : Added testRemoveDomainMarker() and * testRemoveRangeMarker() (DG); + * 10-May-2009 : Extended testEquals(), added testCloning3() (DG); * */ @@ -73,6 +74,7 @@ import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; +import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.AxisLocation; @@ -339,6 +341,12 @@ plot2.addRangeMarker(1, new ValueMarker(99.0), Layer.BACKGROUND); assertTrue(plot1.equals(plot2)); + // fixed legend items + plot1.setFixedLegendItems(new LegendItemCollection()); + assertFalse(plot1.equals(plot2)); + plot2.setFixedLegendItems(new LegendItemCollection()); + assertTrue(plot1.equals(plot2)); + // weight plot1.setWeight(3); assertFalse(plot1.equals(plot2)); @@ -472,6 +480,31 @@ } /** + * Tests cloning for a plot where the fixed legend items have been + * specified. + */ + public void testCloning3() { + XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), + new NumberAxis("Range Axis"), new StandardXYItemRenderer()); + LegendItemCollection c1 = new LegendItemCollection(); + p1.setFixedLegendItems(c1); + XYPlot p2 = null; + try { + p2 = (XYPlot) p1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(p1 != p2); + assertTrue(p1.getClass() == p2.getClass()); + assertTrue(p1.equals(p2)); + + // verify independence of fixed legend item collection + c1.add(new LegendItem("X")); + assertFalse(p1.equals(p2)); + } + + /** * Confirm that cloning captures the quadrantOrigin field. */ public void testCloning_QuadrantOrigin() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-06-23 08:47:03
|
Revision: 2140 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2140&view=rev Author: mungady Date: 2009-06-23 08:43:16 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/plot/dial/DialValueIndicator.java Added Paths: ----------- trunk/tests/org/jfree/data/function/junit/DataFunctionPackageTests.java Modified: trunk/source/org/jfree/chart/plot/dial/DialValueIndicator.java =================================================================== --- trunk/source/org/jfree/chart/plot/dial/DialValueIndicator.java 2009-06-23 08:40:57 UTC (rev 2139) +++ trunk/source/org/jfree/chart/plot/dial/DialValueIndicator.java 2009-06-23 08:43:16 UTC (rev 2140) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ----------------------- * DialValueIndicator.java * ----------------------- - * (C) Copyright 2006-2008, by Object Refinery Limited. + * (C) Copyright 2006-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -38,6 +38,7 @@ * 21-Jun-2007 : Removed JCommon dependencies (DG); * 17-Oct-2007 : Updated equals() (DG); * 24-Oct-2007 : Added default constructor and missing event notification (DG); + * 09-Jun-2009 : Improved indicator resizing, fixes bug 2802014 (DG); * */ @@ -49,6 +50,7 @@ import java.awt.FontMetrics; 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.Point2D; @@ -63,6 +65,7 @@ import org.jfree.chart.text.TextAnchor; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.HashUtilities; +import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.RectangleAnchor; @@ -96,6 +99,15 @@ /** The template value. */ private Number templateValue; + /** + * A data value that will be formatted to determine the maximum size of + * the indicator bounds. If this is null, the indicator bounds can grow + * as large as necessary to contain the actual data value. + * + * @since 1.0.14 + */ + private Number maxTemplateValue; + /** The formatter. */ private NumberFormat formatter; @@ -141,6 +153,7 @@ this.radius = 0.3; this.frameAnchor = RectangleAnchor.CENTER; this.templateValue = new Double(100.0); + this.maxTemplateValue = null; this.formatter = new DecimalFormat("0.0"); this.font = new Font("Tahoma", Font.BOLD, 14); this.paint = Color.black; @@ -281,6 +294,35 @@ } /** + * Returns the template value for the maximum size of the indicator + * bounds. + * + * @return The template value (possibly <code>null</code>). + * + * @since 1.0.14 + * + * @see #setMaxTemplateValue(java.lang.Number) + */ + public Number getMaxTemplateValue() { + return this.maxTemplateValue; + } + + /** + * Sets the template value for the maximum size of the indicator bounds + * and sends a {@link DialLayerChangeEvent} to all registered listeners. + * + * @param value the value (<code>null</code> permitted). + * + * @since 1.0.14 + * + * @see #getMaxTemplateValue() + */ + public void setMaxTemplateValue(Number value) { + this.maxTemplateValue = value; + notifyListeners(new DialLayerChangeEvent(this)); + } + + /** * Returns the formatter used to format the value. * * @return The formatter (never <code>null</code>). @@ -550,15 +592,34 @@ Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); + // the indicator bounds is calculated from the templateValue (which + // determines the minimum size), the maxTemplateValue (which, if + // specified, provides a maximum size) and the actual value + FontMetrics fm = g2.getFontMetrics(this.font); + double value = plot.getValue(this.datasetIndex); + String valueStr = this.formatter.format(value); + Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm); + // calculate the bounds of the template value - FontMetrics fm = g2.getFontMetrics(this.font); String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); + double minW = tb.getWidth(); + double minH = tb.getHeight(); + double maxW = Double.MAX_VALUE; + double maxH = Double.MAX_VALUE; + if (this.maxTemplateValue != null) { + s = this.formatter.format(this.maxTemplateValue); + tb = TextUtilities.getTextBounds(s, g2, fm); + maxW = Math.max(tb.getWidth(), minW); + maxH = Math.max(tb.getHeight(), minH); + } + double w = fixToRange(valueBounds.getWidth(), minW, maxW); + double h = fixToRange(valueBounds.getHeight(), minH, maxH); + // align this rectangle to the frameAnchor - Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D( - tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), - this.frameAnchor); + Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), + pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); @@ -572,19 +633,45 @@ g2.setPaint(this.outlinePaint); g2.draw(fb); + // now find the text anchor point + Shape savedClip = g2.getClip(); + g2.clip(fb); - // now find the text anchor point - double value = plot.getValue(this.datasetIndex); - String valueStr = this.formatter.format(value); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); + g2.setClip(savedClip); } /** + * A utility method that adjusts a value, if necessary, to be within a + * specified range. + * + * @param x the value. + * @param minX the minimum value in the range. + * @param maxX the maximum value in the range. + * + * @return The adjusted value. + */ + private double fixToRange(double x, double minX, double maxX) { + if (minX > maxX) { + throw new IllegalArgumentException("Requires 'minX' <= 'maxX'."); + } + if (x < minX) { + return minX; + } + else if (x > maxX) { + return maxX; + } + else { + return x; + } + } + + /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). @@ -614,6 +701,10 @@ if (!this.templateValue.equals(that.templateValue)) { return false; } + if (!ObjectUtilities.equal(this.maxTemplateValue, + that.maxTemplateValue)) { + return false; + } if (!this.font.equals(that.font)) { return false; } @@ -638,7 +729,6 @@ if (!this.textAnchor.equals(that.textAnchor)) { return false; } - return super.equals(obj); } Added: trunk/tests/org/jfree/data/function/junit/DataFunctionPackageTests.java =================================================================== --- trunk/tests/org/jfree/data/function/junit/DataFunctionPackageTests.java (rev 0) +++ trunk/tests/org/jfree/data/function/junit/DataFunctionPackageTests.java 2009-06-23 08:43:16 UTC (rev 2140) @@ -0,0 +1,87 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ----------------------------- + * DataFunctionPackageTests.java + * ----------------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 28-May-2008 : Version 1 (DG); + * + */ + +package org.jfree.data.function.junit; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Some tests for the <code>org.jfree.data.function</code> package that can + * be run using JUnit. You can find more information about JUnit at + * <a href="http://www.junit.org">http://www.junit.org</a>. + */ +public class DataFunctionPackageTests extends TestCase { + + /** + * Returns a test suite to the JUnit test runner. + * + * @return The test suite. + */ + public static Test suite() { + TestSuite suite = new TestSuite("org.jfree.data.function"); + suite.addTestSuite(LineFunction2DTests.class); + suite.addTestSuite(NormalDistributionFunction2DTests.class); + suite.addTestSuite(PolynomialFunction2DTests.class); + suite.addTestSuite(PowerFunction2DTests.class); + return suite; + } + + /** + * Constructs the test suite. + * + * @param name the test suite name. + */ + public DataFunctionPackageTests(String name) { + super(name); + } + + /** + * Runs the test suite using JUnit's text-based runner. + * + * @param args ignored. + */ + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-06-23 08:34:10
|
Revision: 2138 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2138&view=rev Author: mungady Date: 2009-06-23 08:33:02 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/data/function/LineFunction2D.java trunk/source/org/jfree/data/function/NormalDistributionFunction2D.java trunk/source/org/jfree/data/function/PowerFunction2D.java trunk/source/org/jfree/data/statistics/Regression.java trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java Added Paths: ----------- trunk/source/org/jfree/data/function/PolynomialFunction2D.java trunk/tests/org/jfree/data/function/ trunk/tests/org/jfree/data/function/junit/ trunk/tests/org/jfree/data/function/junit/LineFunction2DTests.java trunk/tests/org/jfree/data/function/junit/NormalDistributionFunction2DTests.java trunk/tests/org/jfree/data/function/junit/PolynomialFunction2DTests.java trunk/tests/org/jfree/data/function/junit/PowerFunction2DTests.java Modified: trunk/source/org/jfree/data/function/LineFunction2D.java =================================================================== --- trunk/source/org/jfree/data/function/LineFunction2D.java 2009-06-23 08:30:31 UTC (rev 2137) +++ trunk/source/org/jfree/data/function/LineFunction2D.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------- * LineFunction2D.java * ------------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,15 +35,20 @@ * Changes: * -------- * 01-Oct-2002 : Version 1 (DG); + * 28-May-2009 : Added accessor methods for co-efficients, implemented + * equals() and hashCode(), and added Serialization support (DG); * */ package org.jfree.data.function; +import java.io.Serializable; +import org.jfree.chart.util.HashUtilities; + /** * A function in the form y = a + bx. */ -public class LineFunction2D implements Function2D { +public class LineFunction2D implements Function2D, Serializable { /** The intercept. */ private double a; @@ -63,6 +68,28 @@ } /** + * Returns the 'a' coefficient that was specified in the constructor. + * + * @return The 'a' coefficient. + * + * @since 1.0.14 + */ + public double getIntercept() { + return this.a; + } + + /** + * Returns the 'b' coefficient that was specified in the constructor. + * + * @return The 'b' coefficient. + * + * @since 1.0.14 + */ + public double getSlope() { + return this.b; + } + + /** * Returns the function value. * * @param x the x-value. @@ -73,4 +100,36 @@ return this.a + this.b * x; } + /** + * Tests this function for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (!(obj instanceof LineFunction2D)) { + return false; + } + LineFunction2D that = (LineFunction2D) obj; + if (this.a != that.a) { + return false; + } + if (this.b != that.b) { + return false; + } + return true; + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int result = 29; + result = HashUtilities.hashCode(result, this.a); + result = HashUtilities.hashCode(result, this.b); + return result; + } } Modified: trunk/source/org/jfree/data/function/NormalDistributionFunction2D.java =================================================================== --- trunk/source/org/jfree/data/function/NormalDistributionFunction2D.java 2009-06-23 08:30:31 UTC (rev 2137) +++ trunk/source/org/jfree/data/function/NormalDistributionFunction2D.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -38,16 +38,21 @@ * 21-Nov-2005 : Added getters for the mean and standard deviation (DG); * 12-Feb-2009 : Precompute some constants from the function - see bug * 2572016 (DG); + * 28-May-2009 : Implemented equals() and hashCode(), and added serialization + * support (DG); * */ package org.jfree.data.function; +import java.io.Serializable; +import org.jfree.chart.util.HashUtilities; + /** * A normal distribution function. See * http://en.wikipedia.org/wiki/Normal_distribution. */ -public class NormalDistributionFunction2D implements Function2D { +public class NormalDistributionFunction2D implements Function2D, Serializable { /** The mean. */ private double mean; @@ -108,4 +113,37 @@ return this.factor * Math.exp(-z * z / this.denominator); } + /** + * Tests this function for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (!(obj instanceof NormalDistributionFunction2D)) { + return false; + } + NormalDistributionFunction2D that = (NormalDistributionFunction2D) obj; + if (this.mean != that.mean) { + return false; + } + if (this.std != that.std) { + return false; + } + return true; + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int result = 29; + result = HashUtilities.hashCode(result, this.mean); + result = HashUtilities.hashCode(result, this.std); + return result; + } + } Added: trunk/source/org/jfree/data/function/PolynomialFunction2D.java =================================================================== --- trunk/source/org/jfree/data/function/PolynomialFunction2D.java (rev 0) +++ trunk/source/org/jfree/data/function/PolynomialFunction2D.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -0,0 +1,131 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------------- + * PolynomialFunction2D.java + * ------------------------- + * (C) Copyright 2009, by Object Refinery Limited. + * + * Original Author: Peter Kolb; + * Contributor(s): David Gilbert (for Object Refinery Limited); + * + * Changes: + * -------- + * 23-Mar-2009 : Version 1, patch 2795746 (PK); + * 28-May-2009 : Integrated in JFreeChart with modifications (DG); + * + */ + +package org.jfree.data.function; + +import java.io.Serializable; +import java.util.Arrays; +import org.jfree.chart.util.HashUtilities; + +/** + * A function in the form <code>y = a0 + a1 * x + a2 * x^2 + ... + an * + * x^n</code>. Instances of this class are immutable. + * + * @since 1.0.14 + */ +public class PolynomialFunction2D implements Function2D, Serializable { + + /** The coefficients. */ + private double[] coefficients; + + /** + * Constructs a new polynomial function <code>y = a0 + a1 * x + a2 * x^2 + + * ... + an * x^n</code> + * + * @param coefficients an array with the coefficients [a0, a1, ..., an] + * (<code>null</code> not permitted). + */ + public PolynomialFunction2D(double[] coefficients) { + if (coefficients == null) { + throw new IllegalArgumentException("Null 'coefficients' argument"); + } + this.coefficients = (double[]) coefficients.clone(); + } + + /** + * Returns a copy of the coefficients array that was specified in the + * constructor. + * + * @return The coefficients array. + */ + public double[] getCoefficients() { + return (double[]) this.coefficients.clone(); + } + + /** + * Returns the order of the polynomial. + * + * @return The order. + */ + public int getOrder() { + return this.coefficients.length - 1; + } + + /** + * Returns the function value. + * + * @param x the x-value. + * + * @return The value. + */ + public double getValue(double x) { + double y = 0; + for(int i = 0; i < coefficients.length; i++){ + y += coefficients[i] * Math.pow(x, i); + } + return y; + } + + /** + * Tests this function for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (!(obj instanceof PolynomialFunction2D)) { + return false; + } + PolynomialFunction2D that = (PolynomialFunction2D) obj; + return Arrays.equals(this.coefficients, that.coefficients); + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + return HashUtilities.hashCodeForDoubleArray(this.coefficients); + } + +} Modified: trunk/source/org/jfree/data/function/PowerFunction2D.java =================================================================== --- trunk/source/org/jfree/data/function/PowerFunction2D.java 2009-06-23 08:30:31 UTC (rev 2137) +++ trunk/source/org/jfree/data/function/PowerFunction2D.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------- * PowerFunction2D.java * -------------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,15 +35,20 @@ * Changes: * -------- * 01-Oct-2002 : Version 1 (DG); + * 28-May-2009 : Added accessor methods for co-efficients, implemented + * equals() and hashCode(), and added Serialization support (DG); * */ package org.jfree.data.function; +import java.io.Serializable; +import org.jfree.chart.util.HashUtilities; + /** * A function of the form y = a * x ^ b. */ -public class PowerFunction2D implements Function2D { +public class PowerFunction2D implements Function2D, Serializable { /** The 'a' coefficient. */ private double a; @@ -63,6 +68,28 @@ } /** + * Returns the 'a' coefficient that was specified in the constructor. + * + * @return The 'a' coefficient. + * + * @since 1.0.14 + */ + public double getA() { + return this.a; + } + + /** + * Returns the 'b' coefficient that was specified in the constructor. + * + * @return The 'b' coefficient. + * + * @since 1.0.14 + */ + public double getB() { + return this.b; + } + + /** * Returns the value of the function for a given input ('x'). * * @param x the x-value. @@ -73,4 +100,37 @@ return this.a * Math.pow(x, this.b); } + /** + * Tests this function for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (!(obj instanceof PowerFunction2D)) { + return false; + } + PowerFunction2D that = (PowerFunction2D) obj; + if (this.a != that.a) { + return false; + } + if (this.b != that.b) { + return false; + } + return true; + } + + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int result = 29; + result = HashUtilities.hashCode(result, this.a); + result = HashUtilities.hashCode(result, this.b); + return result; + } + } Modified: trunk/source/org/jfree/data/statistics/Regression.java =================================================================== --- trunk/source/org/jfree/data/statistics/Regression.java 2009-06-23 08:30:31 UTC (rev 2137) +++ trunk/source/org/jfree/data/statistics/Regression.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,10 +27,10 @@ * --------------- * Regression.java * --------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; + * Contributor(s): Peter Kolb (patch 2795746); * * Changes * ------- @@ -38,6 +38,8 @@ * 18-Aug-2003 : Added 'abstract' (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); + * 29-May-2009 : Added support for polynomial regression, see patch 2795746 + * by Peter Kolb (DG); * */ @@ -224,4 +226,148 @@ } + /** + * Returns the parameters 'a0', 'a1', 'a2', ..., 'an' for a polynomial + * function of order n, y = a0 + a1 * x + a2 * x^2 + ... + an * x^n, + * fitted to the data using a polynomial regression equation. + * The result is returned as an array with a length of n + 2, + * where double[0] --> a0, double[1] --> a1, .., double[n] --> an. + * and double[n + 1] is the correlation coefficient R2 + * Reference: J. D. Faires, R. L. Burden, Numerische Methoden (german + * edition), pp. 243ff and 327ff. + * + * @param dataset the dataset (<code>null</code> not permitted). + * @param series the series to fit the regression line against (the series + * must have at least order + 1 non-NaN items). + * @param order the order of the function (> 0). + * + * @return The parameters. + * + * @since 1.0.14 + */ + public static double[] getPolynomialRegression(XYDataset dataset, int series, int order) { + if (dataset == null) { + throw new IllegalArgumentException("Null 'dataset' argument."); + } + int itemCount = dataset.getItemCount(series); + if (itemCount < order + 1) { + throw new IllegalArgumentException("Not enough data."); + } + int validItems = 0; + double[][] data = new double[2][itemCount]; + for(int item = 0; item < itemCount; item++){ + double x = dataset.getXValue(series, item); + double y = dataset.getYValue(series, item); + if (!Double.isNaN(x) && !Double.isNaN(y)){ + data[0][validItems] = x; + data[1][validItems] = y; + validItems++; + } + } + if (validItems < order + 1) { + throw new IllegalArgumentException("Not enough data."); + } + int equations = order + 1; + int coefficients = order + 2; + double[] result = new double[equations + 1]; + double[][] matrix = new double[equations][coefficients]; + double sumX = 0.0; + double sumY = 0.0; + + for(int item = 0; item < validItems; item++){ + sumX += data[0][item]; + sumY += data[1][item]; + for(int eq = 0; eq < equations; eq++){ + for(int coe = 0; coe < coefficients - 1; coe++){ + matrix[eq][coe] += Math.pow(data[0][item],eq + coe); + } + matrix[eq][coefficients - 1] += data[1][item] + * Math.pow(data[0][item],eq); + } + } + double[][] subMatrix = calculateSubMatrix(matrix); + for (int eq = 1; eq < equations; eq++) { + matrix[eq][0] = 0; + for (int coe = 1; coe < coefficients; coe++) { + matrix[eq][coe] = subMatrix[eq - 1][coe - 1]; + } + } + for (int eq = equations - 1; eq > -1; eq--) { + double value = matrix[eq][coefficients - 1]; + for (int coe = eq; coe < coefficients -1; coe++) { + value -= matrix[eq][coe] * result[coe]; + } + result[eq] = value / matrix[eq][eq]; + } + double meanY = sumY / validItems; + double yObsSquare = 0.0; + double yRegSquare = 0.0; + for (int item = 0; item < validItems; item++) { + double yCalc = 0; + for (int eq = 0; eq < equations; eq++) { + yCalc += result[eq] * Math.pow(data[0][item],eq); + } + yRegSquare += Math.pow(yCalc - meanY, 2); + yObsSquare += Math.pow(data[1][item] - meanY, 2); + } + double rSquare = yRegSquare / yObsSquare; + result[equations] = rSquare; + return result; + } + + /** + * Returns a matrix with the following features: (1) the number of rows + * and columns is 1 less than that of the original matrix; (2)the matrix + * is triangular, i.e. all elements a (row, column) with column > row are + * zero. This method is used for calculating a polynomial regression. + * + * @param matrix the start matrix. + * + * @return The new matrix. + */ + private static double[][] calculateSubMatrix(double[][] matrix){ + int equations = matrix.length; + int coefficients = matrix[0].length; + double[][] result = new double[equations - 1][coefficients - 1]; + for (int eq = 1; eq < equations; eq++) { + double factor = matrix[0][0] / matrix[eq][0]; + for (int coe = 1; coe < coefficients; coe++) { + result[eq - 1][coe -1] = matrix[0][coe] - matrix[eq][coe] + * factor; + } + } + if (equations == 1) { + return result; + } + // check for zero pivot element + if (result[0][0] == 0) { + boolean found = false; + for (int i = 0; i < result.length; i ++) { + if (result[i][0] != 0) { + found = true; + double[] temp = result[0]; + for (int j = 0; j < result[i].length; j++) { + result[0][j] = result[i][j]; + } + for (int j = 0; j < temp.length; j++) { + result[i][j] = temp[j]; + } + break; + } + } + if (!found) { + System.out.println("Equation has no solution!"); + return new double[equations - 1][coefficients - 1]; + } + } + double[][] subMatrix = calculateSubMatrix(result); + for (int eq = 1; eq < equations - 1; eq++) { + result[eq][0] = 0; + for (int coe = 1; coe < coefficients - 1; coe++) { + result[eq][coe] = subMatrix[eq - 1][coe - 1]; + } + } + return result; + } + } Modified: trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java =================================================================== --- trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java 2009-06-23 08:30:31 UTC (rev 2137) +++ trunk/tests/org/jfree/chart/junit/JFreeChartTestSuite.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -47,6 +47,7 @@ * 26-Jan-2007 : Added tests for org.jfree.data.time.ohlc package (DG); * 24-Oct-2007 : Added tests for org.jfree.chart.plot.dial package (DG); * 25-Mar-2009 : Added missing test suite (org.jfree.data.general) (DG); + * 28-May-2009 : Added tests for org.jfree.data.function package (DG); * */ @@ -71,6 +72,7 @@ import org.jfree.chart.urls.junit.UrlsPackageTests; import org.jfree.chart.util.junit.UtilPackageTests; import org.jfree.data.category.junit.DataCategoryPackageTests; +import org.jfree.data.function.junit.DataFunctionPackageTests; import org.jfree.data.gantt.junit.DataGanttPackageTests; import org.jfree.data.general.junit.DataGeneralPackageTests; import org.jfree.data.junit.DataPackageTests; @@ -109,6 +111,7 @@ suite.addTest(UtilPackageTests.suite()); suite.addTest(DataPackageTests.suite()); suite.addTest(DataCategoryPackageTests.suite()); + suite.addTest(DataFunctionPackageTests.suite()); suite.addTest(DataGanttPackageTests.suite()); suite.addTest(DataGeneralPackageTests.suite()); suite.addTest(DataStatisticsPackageTests.suite()); Added: trunk/tests/org/jfree/data/function/junit/LineFunction2DTests.java =================================================================== --- trunk/tests/org/jfree/data/function/junit/LineFunction2DTests.java (rev 0) +++ trunk/tests/org/jfree/data/function/junit/LineFunction2DTests.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -0,0 +1,140 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------------ + * LineFunction2DTests.java + * ------------------------ + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 28-May-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.function.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.data.function.LineFunction2D; + +/** + * Tests for the {@link LineFunction2D} class. + */ +public class LineFunction2DTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(LineFunction2DTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public LineFunction2DTests(String name) { + super(name); + } + + private static final double EPSILON = 0.000000001; + + /** + * Some tests for the constructor. + */ + public void testConstructor() { + LineFunction2D f = new LineFunction2D(1.0, 2.0); + assertEquals(1.0, f.getIntercept(), EPSILON); + assertEquals(2.0, f.getSlope(), EPSILON); + } + + + + /** + * For datasets, the equals() method just checks keys and values. + */ + public void testEquals() { + LineFunction2D f1 = new LineFunction2D(1.0, 2.0); + LineFunction2D f2 = new LineFunction2D(1.0, 2.0); + assertTrue(f1.equals(f2)); + f1 = new LineFunction2D(2.0, 3.0); + assertFalse(f1.equals(f2)); + f2 = new LineFunction2D(2.0, 3.0); + assertTrue(f1.equals(f2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + LineFunction2D f1 = new LineFunction2D(1.0, 2.0); + LineFunction2D f2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(f1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + f2 = (LineFunction2D) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(f1, f2); + } + + /** + * Objects that are equal should have the same hash code otherwise FindBugs + * will tell on us... + */ + public void testHashCode() { + LineFunction2D f1 = new LineFunction2D(1.0, 2.0); + LineFunction2D f2 = new LineFunction2D(1.0, 2.0); + assertEquals(f1.hashCode(), f2.hashCode()); + } + +} + Added: trunk/tests/org/jfree/data/function/junit/NormalDistributionFunction2DTests.java =================================================================== --- trunk/tests/org/jfree/data/function/junit/NormalDistributionFunction2DTests.java (rev 0) +++ trunk/tests/org/jfree/data/function/junit/NormalDistributionFunction2DTests.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -0,0 +1,146 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * -------------------------------------- + * NormalDistributionFunction2DTests.java + * -------------------------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 28-May-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.function.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.data.function.LineFunction2D; +import org.jfree.data.function.NormalDistributionFunction2D; + +/** + * Tests for the {@link NormalDistributionFunction2D} class. + */ +public class NormalDistributionFunction2DTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(NormalDistributionFunction2DTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public NormalDistributionFunction2DTests(String name) { + super(name); + } + + private static final double EPSILON = 0.000000001; + + /** + * Some tests for the constructor. + */ + public void testConstructor() { + NormalDistributionFunction2D f = new NormalDistributionFunction2D(1.0, + 2.0); + assertEquals(1.0, f.getMean(), EPSILON); + assertEquals(2.0, f.getStandardDeviation(), EPSILON); + } + + /** + * For datasets, the equals() method just checks keys and values. + */ + public void testEquals() { + NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0, + 2.0); + NormalDistributionFunction2D f2 = new NormalDistributionFunction2D(1.0, + 2.0); + assertTrue(f1.equals(f2)); + f1 = new NormalDistributionFunction2D(2.0, 3.0); + assertFalse(f1.equals(f2)); + f2 = new NormalDistributionFunction2D(2.0, 3.0); + assertTrue(f1.equals(f2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0, + 2.0); + NormalDistributionFunction2D f2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(f1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + f2 = (NormalDistributionFunction2D) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(f1, f2); + } + + /** + * Objects that are equal should have the same hash code otherwise FindBugs + * will tell on us... + */ + public void testHashCode() { + NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0, + 2.0); + NormalDistributionFunction2D f2 = new NormalDistributionFunction2D(1.0, + 2.0); + assertEquals(f1.hashCode(), f2.hashCode()); + } + +} + + Added: trunk/tests/org/jfree/data/function/junit/PolynomialFunction2DTests.java =================================================================== --- trunk/tests/org/jfree/data/function/junit/PolynomialFunction2DTests.java (rev 0) +++ trunk/tests/org/jfree/data/function/junit/PolynomialFunction2DTests.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -0,0 +1,177 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------------------ + * PolynomialFunction2DTests.java + * ------------------------------ + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 28-May-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.function.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 java.util.Arrays; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.data.function.PolynomialFunction2D; + +/** + * Tests for the {@link PolynomialFunction2D} class. + */ +public class PolynomialFunction2DTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(PolynomialFunction2DTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public PolynomialFunction2DTests(String name) { + super(name); + } + + /** + * Some tests for the constructor. + */ + public void testConstructor() { + PolynomialFunction2D f = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + assertTrue(Arrays.equals(new double[] {1.0, 2.0}, f.getCoefficients())); + + boolean pass = false; + try { + f = new PolynomialFunction2D(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the getCoefficients() method. + */ + public void testGetCoefficients() { + PolynomialFunction2D f = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + double[] c = f.getCoefficients(); + assertTrue(Arrays.equals(new double[] {1.0, 2.0}, c)); + + // make sure that modifying the returned array doesn't change the + // function + c[0] = 99.9; + assertTrue(Arrays.equals(new double[] {1.0, 2.0}, f.getCoefficients())); + } + + /** + * Some checks for the getOrder() method. + */ + public void testGetOrder() { + PolynomialFunction2D f = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + assertEquals(1, f.getOrder()); + } + + /** + * For datasets, the equals() method just checks keys and values. + */ + public void testEquals() { + PolynomialFunction2D f1 = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + PolynomialFunction2D f2 = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + assertTrue(f1.equals(f2)); + f1 = new PolynomialFunction2D(new double[] {2.0, 3.0}); + assertFalse(f1.equals(f2)); + f2 = new PolynomialFunction2D(new double[] {2.0, 3.0}); + assertTrue(f1.equals(f2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + PolynomialFunction2D f1 = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + PolynomialFunction2D f2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(f1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + f2 = (PolynomialFunction2D) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(f1, f2); + } + + /** + * Objects that are equal should have the same hash code otherwise FindBugs + * will tell on us... + */ + public void testHashCode() { + PolynomialFunction2D f1 = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + PolynomialFunction2D f2 = new PolynomialFunction2D(new double[] {1.0, + 2.0}); + assertEquals(f1.hashCode(), f2.hashCode()); + + } + +} + + Added: trunk/tests/org/jfree/data/function/junit/PowerFunction2DTests.java =================================================================== --- trunk/tests/org/jfree/data/function/junit/PowerFunction2DTests.java (rev 0) +++ trunk/tests/org/jfree/data/function/junit/PowerFunction2DTests.java 2009-06-23 08:33:02 UTC (rev 2138) @@ -0,0 +1,140 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------------------- + * PowerFunction2DTests.java + * ------------------------- + * (C) Copyright 2009, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 28-May-2009 : Version 1 (DG); + * + */ + +package org.jfree.data.function.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.data.function.PowerFunction2D; + +/** + * Tests for the {@link PowerFunction2D} class. + */ +public class PowerFunction2DTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(PowerFunction2DTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public PowerFunction2DTests(String name) { + super(name); + } + + private static final double EPSILON = 0.000000001; + + /** + * Some tests for the constructor. + */ + public void testConstructor() { + PowerFunction2D f = new PowerFunction2D(1.0, 2.0); + assertEquals(1.0, f.getA(), EPSILON); + assertEquals(2.0, f.getB(), EPSILON); + } + + /** + * For datasets, the equals() method just checks keys and values. + */ + public void testEquals() { + PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0); + PowerFunction2D f2 = new PowerFunction2D(1.0, 2.0); + assertTrue(f1.equals(f2)); + f1 = new PowerFunction2D(2.0, 3.0); + assertFalse(f1.equals(f2)); + f2 = new PowerFunction2D(2.0, 3.0); + assertTrue(f1.equals(f2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0); + PowerFunction2D f2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(f1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + f2 = (PowerFunction2D) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(f1, f2); + } + + /** + * Objects that are equal should have the same hash code otherwise FindBugs + * will tell on us... + */ + public void testHashCode() { + PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0); + PowerFunction2D f2 = new PowerFunction2D(1.0, 2.0); + assertEquals(f1.hashCode(), f2.hashCode()); + } + +} + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-06-25 09:07:50
|
Revision: 2158 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2158&view=rev Author: mungady Date: 2009-06-25 09:07:46 +0000 (Thu, 25 Jun 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java Added Paths: ----------- trunk/source/org/jfree/chart/util/XYCoordinateType.java Removed Paths: ------------- trunk/experimental/org/jfree/experimental/chart/annotations/XYTitleAnnotation.java trunk/experimental/org/jfree/experimental/chart/annotations/junit/XYTitleAnnotationTests.java trunk/experimental/org/jfree/experimental/chart/demo/XYTitleAnnotationDemo1.java trunk/experimental/org/jfree/experimental/chart/util/XYCoordinateType.java Deleted: trunk/experimental/org/jfree/experimental/chart/annotations/XYTitleAnnotation.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/annotations/XYTitleAnnotation.java 2009-06-24 15:44:47 UTC (rev 2157) +++ trunk/experimental/org/jfree/experimental/chart/annotations/XYTitleAnnotation.java 2009-06-25 09:07:46 UTC (rev 2158) @@ -1,395 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * ---------------------- - * XYTitleAnnotation.java - * ---------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): Andrew Mickish; - * - * $Id: XYTitleAnnotation.java,v 1.1.2.2 2007/04/30 20:54:34 mungady Exp $ - * - * Changes: - * -------- - * 02-Feb-2007 : Version 1 (DG); - * 30-Apr-2007 : Fixed equals() method (DG); - * 20-Jun-2007 : Removed JCommon dependencies (DG); - * 26-Feb-2008 : Fixed NullPointerException when drawing chart with a null - * ChartRenderingInfo - see patch 1901599 by Andrew Mickish (DG); - * - */ - -package org.jfree.experimental.chart.annotations; - -import java.awt.Graphics2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.Serializable; - -import org.jfree.chart.util.HashUtilities; -import org.jfree.chart.annotations.AbstractXYAnnotation; -import org.jfree.chart.axis.AxisLocation; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.block.BlockParams; -import org.jfree.chart.block.EntityBlockResult; -import org.jfree.chart.block.RectangleConstraint; -import org.jfree.chart.plot.Plot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.PlotRenderingInfo; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.title.Title; -import org.jfree.chart.util.ObjectUtilities; -import org.jfree.chart.util.PublicCloneable; -import org.jfree.chart.util.RectangleAnchor; -import org.jfree.chart.util.RectangleEdge; -import org.jfree.chart.util.Size2D; -import org.jfree.data.Range; -import org.jfree.experimental.chart.util.XYCoordinateType; - -/** - * An annotation that allows any {@link Title} to be placed at a location on - * an {@link XYPlot}. - */ -public class XYTitleAnnotation extends AbstractXYAnnotation - implements Cloneable, PublicCloneable, Serializable { - - /** For serialization. */ - private static final long serialVersionUID = -4364694501921559958L; - - /** The coordinate type. */ - private XYCoordinateType coordinateType; - - /** The x-coordinate (in data space). */ - private double x; - - /** The y-coordinate (in data space). */ - private double y; - - /** The maximum width. */ - private double maxWidth; - - /** The maximum height. */ - private double maxHeight; - - /** The title. */ - private Title title; - - /** - * The title anchor point. - */ - private RectangleAnchor anchor; - - /** - * Creates a new annotation to be displayed at the specified (x, y) - * location. - * - * @param x the x-coordinate (in data space). - * @param y the y-coordinate (in data space). - * @param title the title (<code>null</code> not permitted). - */ - public XYTitleAnnotation(double x, double y, Title title) { - this(x, y, title, RectangleAnchor.CENTER); - } - - /** - * Creates a new annotation to be displayed at the specified (x, y) - * location. - * - * @param x the x-coordinate (in data space). - * @param y the y-coordinate (in data space). - * @param title the title (<code>null</code> not permitted). - * @param anchor the title anchor (<code>null</code> not permitted). - */ - public XYTitleAnnotation(double x, double y, Title title, - RectangleAnchor anchor) { - if (title == null) { - throw new IllegalArgumentException("Null 'title' argument."); - } - if (anchor == null) { - throw new IllegalArgumentException("Null 'anchor' argument."); - } - this.coordinateType = XYCoordinateType.RELATIVE; - this.x = x; - this.y = y; - this.maxWidth = 0.0; - this.maxHeight = 0.0; - this.title = title; - this.anchor = anchor; - } - - /** - * Returns the coordinate type (set in the constructor). - * - * @return The coordinate type (never <code>null</code>). - */ - public XYCoordinateType getCoordinateType() { - return this.coordinateType; - } - - /** - * Returns the x-coordinate for the annotation. - * - * @return The x-coordinate. - */ - public double getX() { - return this.x; - } - - /** - * Returns the y-coordinate for the annotation. - * - * @return The y-coordinate. - */ - public double getY() { - return this.y; - } - - /** - * Returns the title for the annotation. - * - * @return The title. - */ - public Title getTitle() { - return this.title; - } - - /** - * Returns the title anchor for the annotation. - * - * @return The title anchor. - */ - public RectangleAnchor getTitleAnchor() { - return this.anchor; - } - - /** - * Returns the maximum width. - * - * @return The maximum width. - */ - public double getMaxWidth() { - return this.maxWidth; - } - - /** - * Sets the maximum width. - * - * @param max the maximum width (0.0 or less means no maximum). - */ - public void setMaxWidth(double max) { - this.maxWidth = max; - } - - /** - * Returns the maximum height. - * - * @return The maximum height. - */ - public double getMaxHeight() { - return this.maxHeight; - } - - /** - * Sets the maximum height. - * - * @param max the maximum height. - */ - public void setMaxHeight(double max) { - this.maxHeight = max; - } - - /** - * Draws the annotation. This method is called by the drawing code in the - * {@link XYPlot} class, you don't normally need to call this method - * directly. - * - * @param g2 the graphics device. - * @param plot the plot. - * @param dataArea the data area. - * @param domainAxis the domain axis. - * @param rangeAxis the range axis. - * @param rendererIndex the renderer index. - * @param info if supplied, this info object will be populated with - * entity information. - */ - public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, - ValueAxis domainAxis, ValueAxis rangeAxis, - int rendererIndex, - PlotRenderingInfo info) { - - PlotOrientation orientation = plot.getOrientation(); - AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); - AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); - RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( - domainAxisLocation, orientation); - RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( - rangeAxisLocation, orientation); - Range xRange = domainAxis.getRange(); - Range yRange = rangeAxis.getRange(); - double anchorX = 0.0; - double anchorY = 0.0; - if (this.coordinateType == XYCoordinateType.RELATIVE) { - anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); - anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); - } - else { - anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); - anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); - } - - float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, - domainEdge); - float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, - rangeEdge); - float xx = 0.0f; - float yy = 0.0f; - if (orientation == PlotOrientation.HORIZONTAL) { - xx = j2DY; - yy = j2DX; - } - else if (orientation == PlotOrientation.VERTICAL) { - xx = j2DX; - yy = j2DY; - } - - double maxW = dataArea.getWidth(); - double maxH = dataArea.getHeight(); - if (this.coordinateType == XYCoordinateType.RELATIVE) { - if (this.maxWidth > 0.0) { - maxW = maxW * this.maxWidth; - } - if (this.maxHeight > 0.0) { - maxH = maxH * this.maxHeight; - } - } - if (this.coordinateType == XYCoordinateType.DATA) { - maxW = this.maxWidth; - maxH = this.maxHeight; - } - RectangleConstraint rc = new RectangleConstraint( - new Range(0, maxW), new Range(0, maxH)); - - Size2D size = this.title.arrange(g2, rc); - Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, - size.height); - Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, - this.anchor); - xx = xx - (float) anchorPoint.getX(); - yy = yy - (float) anchorPoint.getY(); - titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); - BlockParams p = new BlockParams(); - if (info != null) { - if (info.getOwner().getEntityCollection() != null) { - p.setGenerateEntities(true); - } - } - Object result = this.title.draw(g2, titleRect, p); - if (info != null) { - if (result instanceof EntityBlockResult) { - EntityBlockResult ebr = (EntityBlockResult) result; - info.getOwner().getEntityCollection().addAll( - ebr.getEntityCollection()); - } - String toolTip = getToolTipText(); - String url = getURL(); - if (toolTip != null || url != null) { - addEntity(info, new Rectangle2D.Float(xx, yy, - (float) size.width, (float) size.height), - rendererIndex, toolTip, url); - } - } - } - - /** - * Tests this object 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 XYTitleAnnotation)) { - return false; - } - XYTitleAnnotation that = (XYTitleAnnotation) obj; - if (this.coordinateType != that.coordinateType) { - return false; - } - if (this.x != that.x) { - return false; - } - if (this.y != that.y) { - return false; - } - if (this.maxWidth != that.maxWidth) { - return false; - } - if (this.maxHeight != that.maxHeight) { - return false; - } - if (!ObjectUtilities.equal(this.title, that.title)) { - return false; - } - if (!this.anchor.equals(that.anchor)) { - return false; - } - return super.equals(obj); - } - - /** - * Returns a hash code for this object. - * - * @return A hash code. - */ - public int hashCode() { - int result = 193; - result = HashUtilities.hashCode(result, this.anchor); - result = HashUtilities.hashCode(result, this.coordinateType); - result = HashUtilities.hashCode(result, this.x); - result = HashUtilities.hashCode(result, this.y); - result = HashUtilities.hashCode(result, this.maxWidth); - result = HashUtilities.hashCode(result, this.maxHeight); - result = HashUtilities.hashCode(result, this.title); - return result; - } - - /** - * Returns a clone of the annotation. - * - * @return A clone. - * - * @throws CloneNotSupportedException if the annotation can't be cloned. - */ - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/annotations/junit/XYTitleAnnotationTests.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/annotations/junit/XYTitleAnnotationTests.java 2009-06-24 15:44:47 UTC (rev 2157) +++ trunk/experimental/org/jfree/experimental/chart/annotations/junit/XYTitleAnnotationTests.java 2009-06-25 09:07:46 UTC (rev 2158) @@ -1,207 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * --------------------------- - * XYTitleAnnotationTests.java - * --------------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 30-Apr-2007 : Version 1 (DG); - * 26-Feb-2008 : Added testDrawWithNullInfo() (DG); - * - */ - -package org.jfree.experimental.chart.annotations.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.chart.JFreeChart; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.chart.title.TextTitle; -import org.jfree.data.xy.DefaultTableXYDataset; -import org.jfree.data.xy.XYSeries; -import org.jfree.experimental.chart.annotations.XYTitleAnnotation; - -/** - * Tests for the {@link XYTitleAnnotation} class. - */ -public class XYTitleAnnotationTests extends TestCase { - - /** - * Returns the tests as a test suite. - * - * @return The test suite. - */ - public static Test suite() { - return new TestSuite(XYTitleAnnotationTests.class); - } - - /** - * Constructs a new set of tests. - * - * @param name the name of the tests. - */ - public XYTitleAnnotationTests(String name) { - super(name); - } - - /** - * Confirm that the equals method can distinguish all the required fields. - */ - public void testEquals() { - TextTitle t = new TextTitle("Title"); - XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); - XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t); - assertTrue(a1.equals(a2)); - - a1 = new XYTitleAnnotation(1.1, 2.0, t); - assertFalse(a1.equals(a2)); - a2 = new XYTitleAnnotation(1.1, 2.0, t); - assertTrue(a1.equals(a2)); - - a1 = new XYTitleAnnotation(1.1, 2.2, t); - assertFalse(a1.equals(a2)); - a2 = new XYTitleAnnotation(1.1, 2.2, t); - assertTrue(a1.equals(a2)); - - TextTitle t2 = new TextTitle("Title 2"); - a1 = new XYTitleAnnotation(1.1, 2.2, t2); - assertFalse(a1.equals(a2)); - a2 = new XYTitleAnnotation(1.1, 2.2, t2); - assertTrue(a1.equals(a2)); - } - - /** - * Two objects that are equal are required to return the same hashCode. - */ - public void testHashCode() { - TextTitle t = new TextTitle("Title"); - XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); - XYTitleAnnotation a2 = new XYTitleAnnotation(1.0, 2.0, t); - assertTrue(a1.equals(a2)); - int h1 = a1.hashCode(); - int h2 = a2.hashCode(); - assertEquals(h1, h2); - } - - /** - * Confirm that cloning works. - */ - public void testCloning() { - TextTitle t = new TextTitle("Title"); - XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); - XYTitleAnnotation a2 = null; - try { - a2 = (XYTitleAnnotation) a1.clone(); - } - catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - assertTrue(a1 != a2); - assertTrue(a1.getClass() == a2.getClass()); - assertTrue(a1.equals(a2)); - } - - /** - * Serialize an instance, restore it, and check for equality. - */ - public void testSerialization() { - TextTitle t = new TextTitle("Title"); - XYTitleAnnotation a1 = new XYTitleAnnotation(1.0, 2.0, t); - XYTitleAnnotation a2 = null; - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutput out = new ObjectOutputStream(buffer); - out.writeObject(a1); - out.close(); - - ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( - buffer.toByteArray())); - a2 = (XYTitleAnnotation) in.readObject(); - in.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - assertEquals(a1, a2); - } - - /** - * Draws the chart with a <code>null</code> info object to make sure that - * no exceptions are thrown. - */ - public void testDrawWithNullInfo() { - boolean success = false; - try { - DefaultTableXYDataset dataset = new DefaultTableXYDataset(); - - XYSeries s1 = new XYSeries("Series 1", true, false); - s1.add(5.0, 5.0); - s1.add(10.0, 15.5); - s1.add(15.0, 9.5); - s1.add(20.0, 7.5); - dataset.addSeries(s1); - - XYSeries s2 = new XYSeries("Series 2", true, false); - s2.add(5.0, 5.0); - s2.add(10.0, 15.5); - s2.add(15.0, 9.5); - s2.add(20.0, 3.5); - dataset.addSeries(s2); - XYPlot plot = new XYPlot(dataset, - new NumberAxis("X"), new NumberAxis("Y"), - new XYLineAndShapeRenderer()); - plot.addAnnotation(new XYTitleAnnotation(5.0, 6.0, - new TextTitle("Hello World!"))); - JFreeChart chart = new JFreeChart(plot); - /* BufferedImage image = */ chart.createBufferedImage(300, 200, - null); - success = true; - } - catch (NullPointerException e) { - e.printStackTrace(); - success = false; - } - assertTrue(success); - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/demo/XYTitleAnnotationDemo1.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/demo/XYTitleAnnotationDemo1.java 2009-06-24 15:44:47 UTC (rev 2157) +++ trunk/experimental/org/jfree/experimental/chart/demo/XYTitleAnnotationDemo1.java 2009-06-25 09:07:46 UTC (rev 2158) @@ -1,230 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2009, 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.] - * - * --------------------------- - * XYTitleAnnotationDemo1.java - * --------------------------- - * (C) Copyright 2007, 2009, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): ; - * - * $Id: XYTitleAnnotationDemo1.java,v 1.1.2.2 2007/05/25 10:37:10 mungady Exp $ - * - * Changes - * ------- - * 02-Feb-2007 : Version 1 (DG); - * 20-Jun-2007 : Removed JCommon dependencies (DG); - * - */ - -package org.jfree.experimental.chart.demo; - -import java.awt.Color; -import java.awt.Font; -import java.text.SimpleDateFormat; - -import javax.swing.JPanel; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.DateAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.block.BlockBorder; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYItemRenderer; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.chart.title.LegendTitle; -import org.jfree.chart.util.ApplicationFrame; -import org.jfree.chart.util.RectangleAnchor; -import org.jfree.chart.util.RectangleEdge; -import org.jfree.chart.util.RectangleInsets; -import org.jfree.chart.util.RefineryUtilities; -import org.jfree.data.time.Month; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; -import org.jfree.data.xy.XYDataset; -import org.jfree.experimental.chart.annotations.XYTitleAnnotation; - -/** - * An example of a time series chart. For the most part, default settings are - * used, except that the renderer is modified to show filled shapes (as well as - * lines) at each data point. - */ -public class XYTitleAnnotationDemo1 extends ApplicationFrame { - - /** - * A demonstration application showing how to create a simple time series - * chart. This example uses monthly data. - * - * @param title the frame title. - */ - public XYTitleAnnotationDemo1(String title) { - super(title); - ChartPanel chartPanel = (ChartPanel) createDemoPanel(); - chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); - chartPanel.setMouseZoomable(true, false); - setContentPane(chartPanel); - } - - /** - * Creates a chart. - * - * @param dataset a dataset. - * - * @return A chart. - */ - private static JFreeChart createChart(XYDataset dataset) { - - JFreeChart chart = ChartFactory.createTimeSeriesChart( - "Legal & General Unit Trust Prices", // title - "Date", // x-axis label - "Price Per Unit", // y-axis label - dataset, // data - false, // create legend? - true, // generate tooltips? - false // generate URLs? - ); - - chart.setBackgroundPaint(Color.white); - - XYPlot plot = (XYPlot) chart.getPlot(); - plot.setBackgroundPaint(Color.lightGray); - plot.setDomainGridlinePaint(Color.white); - plot.setRangeGridlinePaint(Color.white); - plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); - plot.setDomainCrosshairVisible(true); - plot.setRangeCrosshairVisible(true); - - LegendTitle lt = new LegendTitle(plot); - lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); - lt.setBackgroundPaint(new Color(200, 200, 255, 100)); - lt.setFrame(new BlockBorder(Color.white)); - lt.setPosition(RectangleEdge.BOTTOM); - XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, - RectangleAnchor.BOTTOM_RIGHT); - - ta.setMaxWidth(0.48); - plot.addAnnotation(ta); - - XYItemRenderer r = plot.getRenderer(); - if (r instanceof XYLineAndShapeRenderer) { - XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; - renderer.setBaseShapesVisible(true); - renderer.setBaseShapesFilled(true); - } - - DateAxis axis = (DateAxis) plot.getDomainAxis(); - axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); - - ValueAxis yAxis = plot.getRangeAxis(); - yAxis.setLowerMargin(0.35); - return chart; - - } - - /** - * Creates a dataset, consisting of two series of monthly data. - * - * @return The dataset. - */ - private static XYDataset createDataset() { - - TimeSeries s1 = new TimeSeries("L&G European Index Trust"); - s1.add(new Month(2, 2001), 181.8); - s1.add(new Month(3, 2001), 167.3); - s1.add(new Month(4, 2001), 153.8); - s1.add(new Month(5, 2001), 167.6); - s1.add(new Month(6, 2001), 158.8); - s1.add(new Month(7, 2001), 148.3); - s1.add(new Month(8, 2001), 153.9); - s1.add(new Month(9, 2001), 142.7); - s1.add(new Month(10, 2001), 123.2); - s1.add(new Month(11, 2001), 131.8); - s1.add(new Month(12, 2001), 139.6); - s1.add(new Month(1, 2002), 142.9); - s1.add(new Month(2, 2002), 138.7); - s1.add(new Month(3, 2002), 137.3); - s1.add(new Month(4, 2002), 143.9); - s1.add(new Month(5, 2002), 139.8); - s1.add(new Month(6, 2002), 137.0); - s1.add(new Month(7, 2002), 132.8); - - TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); - s2.add(new Month(2, 2001), 129.6); - s2.add(new Month(3, 2001), 123.2); - s2.add(new Month(4, 2001), 117.2); - s2.add(new Month(5, 2001), 124.1); - s2.add(new Month(6, 2001), 122.6); - s2.add(new Month(7, 2001), 119.2); - s2.add(new Month(8, 2001), 116.5); - s2.add(new Month(9, 2001), 112.7); - s2.add(new Month(10, 2001), 101.5); - s2.add(new Month(11, 2001), 106.1); - s2.add(new Month(12, 2001), 110.3); - s2.add(new Month(1, 2002), 111.7); - s2.add(new Month(2, 2002), 111.0); - s2.add(new Month(3, 2002), 109.6); - s2.add(new Month(4, 2002), 113.2); - s2.add(new Month(5, 2002), 111.6); - s2.add(new Month(6, 2002), 108.8); - s2.add(new Month(7, 2002), 101.6); - - TimeSeriesCollection dataset = new TimeSeriesCollection(); - dataset.addSeries(s1); - dataset.addSeries(s2); - - return dataset; - - } - - /** - * Creates a panel for the demo (used by SuperDemo.java). - * - * @return A panel. - */ - public static JPanel createDemoPanel() { - JFreeChart chart = createChart(createDataset()); - return new ChartPanel(chart); - } - - /** - * Starting point for the demonstration application. - * - * @param args ignored. - */ - public static void main(String[] args) { - - XYTitleAnnotationDemo1 demo = new XYTitleAnnotationDemo1( - "XYTitleAnnotationDemo1"); - demo.pack(); - RefineryUtilities.centerFrameOnScreen(demo); - demo.setVisible(true); - - } - -} Deleted: trunk/experimental/org/jfree/experimental/chart/util/XYCoordinateType.java =================================================================== --- trunk/experimental/org/jfree/experimental/chart/util/XYCoordinateType.java 2009-06-24 15:44:47 UTC (rev 2157) +++ trunk/experimental/org/jfree/experimental/chart/util/XYCoordinateType.java 2009-06-25 09:07:46 UTC (rev 2158) @@ -1,132 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * --------------------- - * XYCoordinateType.java - * --------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes - * ------- - * 02-Feb-2007 : Version 1 (DG); - * - */ - -package org.jfree.experimental.chart.util; - -import java.io.ObjectStreamException; -import java.io.Serializable; - -/** - * Represents several possible interpretations for an (x, y) coordinate. - */ -public final class XYCoordinateType implements Serializable { - - /** The (x, y) coordinates represent a point in the data space. */ - public static final XYCoordinateType DATA - = new XYCoordinateType("XYCoordinateType.DATA"); - - /** - * The (x, y) coordinates represent a relative position in the data space. - * In this case, the values should be in the range (0.0 to 1.0). - */ - public static final XYCoordinateType RELATIVE - = new XYCoordinateType("XYCoordinateType.RELATIVE"); - - /** - * The (x, y) coordinates represent indices in a dataset. - * In this case, the values should be in the range (0.0 to 1.0). - */ - public static final XYCoordinateType INDEX - = new XYCoordinateType("XYCoordinateType.INDEX"); - - /** The name. */ - private String name; - - /** - * Private constructor. - * - * @param name the name. - */ - private XYCoordinateType(String name) { - this.name = name; - } - - /** - * Returns a string representing the object. - * - * @return The string. - */ - public String toString() { - return this.name; - } - - /** - * Returns <code>true</code> if this object is equal to the specified - * object, and <code>false</code> otherwise. - * - * @param obj the other object. - * - * @return A boolean. - */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof XYCoordinateType)) { - return false; - } - XYCoordinateType order = (XYCoordinateType) obj; - if (!this.name.equals(order.toString())) { - return false; - } - return true; - } - - /** - * Ensures that serialization returns the unique instances. - * - * @return The object. - * - * @throws ObjectStreamException if there is a problem. - */ - private Object readResolve() throws ObjectStreamException { - if (this.equals(XYCoordinateType.DATA)) { - return XYCoordinateType.DATA; - } - else if (this.equals(XYCoordinateType.RELATIVE)) { - return XYCoordinateType.RELATIVE; - } - else if (this.equals(XYCoordinateType.INDEX)) { - return XYCoordinateType.INDEX; - } - return null; - } - -} Modified: trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java =================================================================== --- trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java 2009-06-24 15:44:47 UTC (rev 2157) +++ trunk/source/org/jfree/chart/annotations/XYTitleAnnotation.java 2009-06-25 09:07:46 UTC (rev 2158) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------------- * XYTitleAnnotation.java * ---------------------- - * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2007-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrew Mickish; @@ -65,7 +65,7 @@ import org.jfree.chart.util.RectangleEdge; import org.jfree.chart.util.Size2D; import org.jfree.data.Range; -import org.jfree.experimental.chart.util.XYCoordinateType; +import org.jfree.chart.util.XYCoordinateType; /** * An annotation that allows any {@link Title} to be placed at a location on Added: trunk/source/org/jfree/chart/util/XYCoordinateType.java =================================================================== --- trunk/source/org/jfree/chart/util/XYCoordinateType.java (rev 0) +++ trunk/source/org/jfree/chart/util/XYCoordinateType.java 2009-06-25 09:07:46 UTC (rev 2158) @@ -0,0 +1,133 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * --------------------- + * XYCoordinateType.java + * --------------------- + * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 02-Feb-2007 : Version 1 (DG); + * + */ + +package org.jfree.chart.util; + +import java.io.ObjectStreamException; +import java.io.Serializable; + +/** + * Represents several possible interpretations for an (x, y) coordinate. + */ +public final class XYCoordinateType implements Serializable { + + /** The (x, y) coordinates represent a point in the data space. */ + public static final XYCoordinateType DATA + = new XYCoordinateType("XYCoordinateType.DATA"); + + /** + * The (x, y) coordinates represent a relative position in the data space. + * In this case, the values should be in the range (0.0 to 1.0). + */ + public static final XYCoordinateType RELATIVE + = new XYCoordinateType("XYCoordinateType.RELATIVE"); + + /** + * The (x, y) coordinates represent indices in a dataset. + * In this case, the values should be in the range (0.0 to 1.0). + */ + public static final XYCoordinateType INDEX + = new XYCoordinateType("XYCoordinateType.INDEX"); + + /** The name. */ + private String name; + + /** + * Private constructor. + * + * @param name the name. + */ + private XYCoordinateType(String name) { + this.name = name; + } + + /** + * Returns a string representing the object. + * + * @return The string. + */ + public String toString() { + return this.name; + } + + /** + * Returns <code>true</code> if this object is equal to the specified + * object, and <code>false</code> otherwise. + * + * @param obj the other object. + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof XYCoordinateType)) { + return false; + } + XYCoordinateType order = (XYCoordinateType) obj; + if (!this.name.equals(order.toString())) { + return false; + } + return true; + } + + /** + * Ensures that serialization returns the unique instances. + * + * @return The object. + * + * @throws ObjectStreamException if there is a problem. + */ + private Object readResolve() throws ObjectStreamException { + if (this.equals(XYCoordinateType.DATA)) { + return XYCoordinateType.DATA; + } + else if (this.equals(XYCoordinateType.RELATIVE)) { + return XYCoordinateType.RELATIVE; + } + else if (this.equals(XYCoordinateType.INDEX)) { + return XYCoordinateType.INDEX; + } + return null; + } + +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-06-26 07:32:28
|
Revision: 2165 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2165&view=rev Author: mungady Date: 2009-06-26 07:32:18 +0000 (Fri, 26 Jun 2009) Log Message: ----------- Added selection parameter to rendering. Modified Paths: -------------- trunk/source/org/jfree/chart/plot/CategoryPlot.java trunk/source/org/jfree/chart/plot/XYPlot.java trunk/source/org/jfree/chart/renderer/AbstractRenderer.java trunk/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java trunk/source/org/jfree/chart/renderer/category/AreaRenderer.java trunk/source/org/jfree/chart/renderer/category/BarPainter.java trunk/source/org/jfree/chart/renderer/category/BarRenderer.java trunk/source/org/jfree/chart/renderer/category/BarRenderer3D.java trunk/source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java trunk/source/org/jfree/chart/renderer/category/CategoryItemRenderer.java trunk/source/org/jfree/chart/renderer/category/CategoryStepRenderer.java trunk/source/org/jfree/chart/renderer/category/GanttRenderer.java trunk/source/org/jfree/chart/renderer/category/GradientBarPainter.java trunk/source/org/jfree/chart/renderer/category/GroupedStackedBarRenderer.java trunk/source/org/jfree/chart/renderer/category/IntervalBarRenderer.java trunk/source/org/jfree/chart/renderer/category/LayeredBarRenderer.java trunk/source/org/jfree/chart/renderer/category/LevelRenderer.java trunk/source/org/jfree/chart/renderer/category/LineAndShapeRenderer.java trunk/source/org/jfree/chart/renderer/category/LineRenderer3D.java trunk/source/org/jfree/chart/renderer/category/MinMaxCategoryRenderer.java trunk/source/org/jfree/chart/renderer/category/ScatterRenderer.java trunk/source/org/jfree/chart/renderer/category/StackedAreaRenderer.java trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer.java trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java trunk/source/org/jfree/chart/renderer/category/StandardBarPainter.java trunk/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java trunk/source/org/jfree/chart/renderer/category/StatisticalLineAndShapeRenderer.java trunk/source/org/jfree/chart/renderer/category/WaterfallBarRenderer.java trunk/source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/CandlestickRenderer.java trunk/source/org/jfree/chart/renderer/xy/ClusteredXYBarRenderer.java trunk/source/org/jfree/chart/renderer/xy/CyclicXYItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/DeviationRenderer.java trunk/source/org/jfree/chart/renderer/xy/GradientXYBarPainter.java trunk/source/org/jfree/chart/renderer/xy/HighLowRenderer.java trunk/source/org/jfree/chart/renderer/xy/SamplingXYLineRenderer.java trunk/source/org/jfree/chart/renderer/xy/StackedXYAreaRenderer.java trunk/source/org/jfree/chart/renderer/xy/StackedXYAreaRenderer2.java trunk/source/org/jfree/chart/renderer/xy/StackedXYBarRenderer.java trunk/source/org/jfree/chart/renderer/xy/StandardXYBarPainter.java trunk/source/org/jfree/chart/renderer/xy/StandardXYItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/VectorRenderer.java trunk/source/org/jfree/chart/renderer/xy/WindItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYAreaRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYAreaRenderer2.java trunk/source/org/jfree/chart/renderer/xy/XYBarPainter.java trunk/source/org/jfree/chart/renderer/xy/XYBarRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYBoxAndWhiskerRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYBubbleRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYDifferenceRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYDotRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYErrorRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYItemRendererState.java trunk/source/org/jfree/chart/renderer/xy/XYLine3DRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYShapeRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYSplineRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYStepAreaRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYStepRenderer.java trunk/source/org/jfree/chart/renderer/xy/YIntervalRenderer.java trunk/source/org/jfree/chart/util/ShapeUtilities.java trunk/tests/org/jfree/chart/junit/AreaChartTests.java trunk/tests/org/jfree/chart/junit/BarChart3DTests.java trunk/tests/org/jfree/chart/junit/BarChartTests.java trunk/tests/org/jfree/chart/junit/GanttChartTests.java trunk/tests/org/jfree/chart/junit/LineChart3DTests.java trunk/tests/org/jfree/chart/junit/LineChartTests.java trunk/tests/org/jfree/chart/junit/ScatterPlotTests.java trunk/tests/org/jfree/chart/junit/StackedAreaChartTests.java trunk/tests/org/jfree/chart/junit/StackedBarChart3DTests.java trunk/tests/org/jfree/chart/junit/StackedBarChartTests.java trunk/tests/org/jfree/chart/junit/TimeSeriesChartTests.java trunk/tests/org/jfree/chart/junit/WaterfallChartTests.java trunk/tests/org/jfree/chart/junit/XYAreaChartTests.java trunk/tests/org/jfree/chart/junit/XYBarChartTests.java trunk/tests/org/jfree/chart/junit/XYLineChartTests.java trunk/tests/org/jfree/chart/junit/XYStepAreaChartTests.java trunk/tests/org/jfree/chart/junit/XYStepChartTests.java Modified: trunk/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/CategoryPlot.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/plot/CategoryPlot.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -3876,14 +3876,14 @@ for (int row = 0; row < rowCount; row++) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, pass); + row, column, false, pass); } } else { for (int row = rowCount - 1; row >= 0; row--) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, pass); + row, column, false, pass); } } } @@ -3894,14 +3894,14 @@ for (int row = 0; row < rowCount; row++) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, pass); + row, column, false, pass); } } else { for (int row = rowCount - 1; row >= 0; row--) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, pass); + row, column, false, pass); } } } Modified: trunk/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/XYPlot.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/plot/XYPlot.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -3740,9 +3740,9 @@ state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); for (int item = firstItem; item <= lastItem; item++) { - renderer.drawItem(g2, state, dataArea, info, + renderer.drawItem(g2, state, dataArea, this, xAxis, yAxis, dataset, series, item, - crosshairState, pass); + false, pass); } state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); @@ -3766,9 +3766,9 @@ state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); for (int item = firstItem; item <= lastItem; item++) { - renderer.drawItem(g2, state, dataArea, info, + renderer.drawItem(g2, state, dataArea, this, xAxis, yAxis, dataset, series, item, - crosshairState, pass); + false, pass); } state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); Modified: trunk/source/org/jfree/chart/renderer/AbstractRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/AbstractRenderer.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/AbstractRenderer.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -700,18 +700,20 @@ // PAINT /** - * Returns the paint used to fill data items as they are drawn. - * <p> - * The default implementation passes control to the - * <code>lookupSeriesPaint()</code> method. You can override this method + * Returns the paint used to fill data items as they are drawn. The + * default implementation passes control to the + * {@link #lookupSeriesPaint(int)} method. You can override this method * if you require different behaviour. * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemPaint(int row, int column) { + public Paint getItemPaint(int row, int column, boolean selected) { return lookupSeriesPaint(row); } @@ -878,10 +880,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemFillPaint(int row, int column) { + public Paint getItemFillPaint(int row, int column, boolean selected) { return lookupSeriesFillPaint(row); } @@ -1031,18 +1036,20 @@ // OUTLINE PAINT ////////////////////////////////////////////////////////// /** - * Returns the paint used to outline data items as they are drawn. - * <p> - * The default implementation passes control to the - * {@link #lookupSeriesOutlinePaint} method. You can override this method - * if you require different behaviour. + * Returns the paint used to outline data items as they are drawn. The + * default implementation passes control to the + * {@link #lookupSeriesOutlinePaint(int)} method. You can override this + * method if you require different behaviour. * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemOutlinePaint(int row, int column) { + public Paint getItemOutlinePaint(int row, int column, boolean selected) { return lookupSeriesOutlinePaint(row); } @@ -1192,17 +1199,19 @@ // STROKE /** - * Returns the stroke used to draw data items. - * <p> - * The default implementation passes control to the getSeriesStroke method. + * Returns the stroke used to draw data items. The default implementation + * passes control to the {@link #lookupSeriesStroke(int)} method. * You can override this method if you require different behaviour. * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The stroke (never <code>null</code>). + * + * @since 1.2.0 */ - public Stroke getItemStroke(int row, int column) { + public Stroke getItemStroke(int row, int column, boolean selected) { return lookupSeriesStroke(row); } @@ -1372,10 +1381,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The stroke (never <code>null</code>). + * + * @since 1.2.0 */ - public Stroke getItemOutlineStroke(int row, int column) { + public Stroke getItemOutlineStroke(int row, int column, boolean selected) { return lookupSeriesOutlineStroke(row); } @@ -1526,17 +1538,20 @@ // SHAPE /** - * Returns a shape used to represent a data item. - * <p> - * The default implementation passes control to the getSeriesShape method. - * You can override this method if you require different behaviour. + * Returns a shape used to represent a data item. The default + * implementation passes control to the {@link #lookupSeriesShape(int)} + * method. You can override this method if you require different + * behaviour. * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The shape (never <code>null</code>). + * + * @since 1.2.0 */ - public Shape getItemShape(int row, int column) { + public Shape getItemShape(int row, int column, boolean selected) { return lookupSeriesShape(row); } @@ -1689,10 +1704,13 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return A boolean. + * + * @since 1.2.0 */ - public boolean isItemLabelVisible(int row, int column) { + public boolean isItemLabelVisible(int row, int column, boolean selected) { return isSeriesItemLabelsVisible(row); } @@ -1814,10 +1832,13 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return The font (never <code>null</code>). + * + * @since 1.2.0 */ - public Font getItemLabelFont(int row, int column) { + public Font getItemLabelFont(int row, int column, boolean selected) { Font result = getSeriesItemLabelFont(row); if (result == null) { result = this.baseItemLabelFont; @@ -1920,10 +1941,13 @@ * * @param row the row index (zero based). * @param column the column index (zero based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemLabelPaint(int row, int column) { + public Paint getItemLabelPaint(int row, int column, boolean selected) { Paint result = getSeriesItemLabelPaint(row); if (result == null) { result = this.baseItemLabelPaint; @@ -2027,12 +2051,14 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return The item label position (never <code>null</code>). * * @see #getNegativeItemLabelPosition(int, int) */ - public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) { + public ItemLabelPosition getPositiveItemLabelPosition(int row, int column, + boolean selected) { return getSeriesPositiveItemLabelPosition(row); } @@ -2047,6 +2073,8 @@ */ public ItemLabelPosition getSeriesPositiveItemLabelPosition(int series) { + // FIXME: Shouldn't this be lookupPositiveItemLabelPosition(int) + // look up the position table ItemLabelPosition position = (ItemLabelPosition) this.positiveItemLabelPositionList.get(series); @@ -2143,12 +2171,16 @@ * * @param row the row index (zero-based). * @param column the column (zero-based). + * @param selected is the item selected? * * @return The item label position (never <code>null</code>). * - * @see #getPositiveItemLabelPosition(int, int) + * @see #getPositiveItemLabelPosition(int, int, selected) + * + * @since 1.2.0 */ - public ItemLabelPosition getNegativeItemLabelPosition(int row, int column) { + public ItemLabelPosition getNegativeItemLabelPosition(int row, int column, + boolean selected) { return getSeriesNegativeItemLabelPosition(row); } @@ -2279,10 +2311,13 @@ * * @param series the series index. * @param item the item index. + * @param selected is the item selected? * * @return A boolean. + * + * @since 1.2.0 */ - public boolean getItemCreateEntity(int series, int item) { + public boolean getItemCreateEntity(int series, int item, boolean selected) { Boolean b = getSeriesCreateEntities(series); if (b != null) { return b.booleanValue(); Modified: trunk/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -107,6 +107,7 @@ * 27-Mar-2009 : Added new findRangeBounds() method to account for hidden * series (DG); * 01-Apr-2009 : Added new addEntity() method (DG); + * 26-Jun-2009 : Updated to support selections (DG); * */ @@ -299,13 +300,16 @@ * * @param row the row index (zero based). * @param column the column index (zero based). + * @param selected is the item selected? * * @return The generator (possibly <code>null</code>). + * + * @since 1.2.0 */ public CategoryItemLabelGenerator getItemLabelGenerator(int row, - int column) { + int column, boolean selected) { CategoryItemLabelGenerator generator = (CategoryItemLabelGenerator) - this.itemLabelGeneratorList.get(row); + this.itemLabelGeneratorList.get(row); if (generator == null) { generator = this.baseItemLabelGenerator; } @@ -407,17 +411,19 @@ /** * Returns the tool tip generator that should be used for the specified - * item. This method looks up the generator using the "three-layer" - * approach outlined in the general description of this interface. You - * can override this method if you want to return a different generator per - * item. + * item. You can override this method if you want to return a different + * generator per item. * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return The generator (possibly <code>null</code>). + * + * @since 1.2.0 */ - public CategoryToolTipGenerator getToolTipGenerator(int row, int column) { + public CategoryToolTipGenerator getToolTipGenerator(int row, int column, + boolean selected) { CategoryToolTipGenerator result = null; result = getSeriesToolTipGenerator(row); @@ -525,10 +531,14 @@ * * @param row the row index (zero based). * @param column the column index (zero based). + * @param selected is the item selected? * * @return The URL generator. + * + * @since 1.2.0 */ - public CategoryURLGenerator getURLGenerator(int row, int column) { + public CategoryURLGenerator getURLGenerator(int row, int column, boolean + selected) { CategoryURLGenerator generator = (CategoryURLGenerator) this.urlGeneratorList.get(row); if (generator == null) { @@ -697,6 +707,84 @@ } /** + * Returns the legend item label generator. + * + * @return The label generator (never <code>null</code>). + * + * @see #setLegendItemLabelGenerator(CategorySeriesLabelGenerator) + */ + public CategorySeriesLabelGenerator getLegendItemLabelGenerator() { + return this.legendItemLabelGenerator; + } + + /** + * Sets the legend item label generator and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param generator the generator (<code>null</code> not permitted). + * + * @see #getLegendItemLabelGenerator() + */ + public void setLegendItemLabelGenerator( + CategorySeriesLabelGenerator generator) { + if (generator == null) { + throw new IllegalArgumentException("Null 'generator' argument."); + } + this.legendItemLabelGenerator = generator; + fireChangeEvent(); + } + + /** + * Returns the legend item tool tip generator. + * + * @return The tool tip generator (possibly <code>null</code>). + * + * @see #setLegendItemToolTipGenerator(CategorySeriesLabelGenerator) + */ + public CategorySeriesLabelGenerator getLegendItemToolTipGenerator() { + return this.legendItemToolTipGenerator; + } + + /** + * Sets the legend item tool tip generator and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param generator the generator (<code>null</code> permitted). + * + * @see #setLegendItemToolTipGenerator(CategorySeriesLabelGenerator) + */ + public void setLegendItemToolTipGenerator( + CategorySeriesLabelGenerator generator) { + this.legendItemToolTipGenerator = generator; + fireChangeEvent(); + } + + /** + * Returns the legend item URL generator. + * + * @return The URL generator (possibly <code>null</code>). + * + * @see #setLegendItemURLGenerator(CategorySeriesLabelGenerator) + */ + public CategorySeriesLabelGenerator getLegendItemURLGenerator() { + return this.legendItemURLGenerator; + } + + /** + * Sets the legend item URL generator and sends a + * {@link RendererChangeEvent} to all registered listeners. + * + * @param generator the generator (<code>null</code> permitted). + * + * @see #getLegendItemURLGenerator() + */ + public void setLegendItemURLGenerator( + CategorySeriesLabelGenerator generator) { + this.legendItemURLGenerator = generator; + fireChangeEvent(); + } + + /** * Returns the number of rows in the dataset. This value is updated in the * {@link AbstractCategoryItemRenderer#initialise} method. * @@ -1485,29 +1573,32 @@ * @param dataset the dataset. * @param row the row. * @param column the column. + * @param selected is the item selected? * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). + * + * @since 1.2.0 */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, - CategoryDataset dataset, int row, int column, + CategoryDataset dataset, int row, int column, boolean selected, double x, double y, boolean negative) { CategoryItemLabelGenerator generator = getItemLabelGenerator(row, - column); + column, selected); if (generator != null) { - Font labelFont = getItemLabelFont(row, column); - Paint paint = getItemLabelPaint(row, column); + Font labelFont = getItemLabelFont(row, column, selected); + Paint paint = getItemLabelPaint(row, column, selected); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, row, column); ItemLabelPosition position = null; if (!negative) { - position = getPositiveItemLabelPosition(row, column); + position = getPositiveItemLabelPosition(row, column, selected); } else { - position = getNegativeItemLabelPosition(row, column); + position = getNegativeItemLabelPosition(row, column, selected); } Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); @@ -1699,114 +1790,24 @@ } /** - * Returns the legend item label generator. - * - * @return The label generator (never <code>null</code>). - * - * @see #setLegendItemLabelGenerator(CategorySeriesLabelGenerator) - */ - public CategorySeriesLabelGenerator getLegendItemLabelGenerator() { - return this.legendItemLabelGenerator; - } - - /** - * Sets the legend item label generator and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param generator the generator (<code>null</code> not permitted). - * - * @see #getLegendItemLabelGenerator() - */ - public void setLegendItemLabelGenerator( - CategorySeriesLabelGenerator generator) { - if (generator == null) { - throw new IllegalArgumentException("Null 'generator' argument."); - } - this.legendItemLabelGenerator = generator; - fireChangeEvent(); - } - - /** - * Returns the legend item tool tip generator. - * - * @return The tool tip generator (possibly <code>null</code>). - * - * @see #setLegendItemToolTipGenerator(CategorySeriesLabelGenerator) - */ - public CategorySeriesLabelGenerator getLegendItemToolTipGenerator() { - return this.legendItemToolTipGenerator; - } - - /** - * Sets the legend item tool tip generator and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param generator the generator (<code>null</code> permitted). - * - * @see #setLegendItemToolTipGenerator(CategorySeriesLabelGenerator) - */ - public void setLegendItemToolTipGenerator( - CategorySeriesLabelGenerator generator) { - this.legendItemToolTipGenerator = generator; - fireChangeEvent(); - } - - /** - * Returns the legend item URL generator. - * - * @return The URL generator (possibly <code>null</code>). - * - * @see #setLegendItemURLGenerator(CategorySeriesLabelGenerator) - */ - public CategorySeriesLabelGenerator getLegendItemURLGenerator() { - return this.legendItemURLGenerator; - } - - /** - * Sets the legend item URL generator and sends a - * {@link RendererChangeEvent} to all registered listeners. - * - * @param generator the generator (<code>null</code> permitted). - * - * @see #getLegendItemURLGenerator() - */ - public void setLegendItemURLGenerator( - CategorySeriesLabelGenerator generator) { - this.legendItemURLGenerator = generator; - fireChangeEvent(); - } - - /** * Adds an entity with the specified hotspot. * * @param entities the entity collection. + * @param hotspot the hotspot (<code>null</code> not permitted). * @param dataset the dataset. * @param row the row index. * @param column the column index. - * @param hotspot the hotspot (<code>null</code> not permitted). + * @param selected is the item selected? + * + * @since 1.2.0 */ - protected void addItemEntity(EntityCollection entities, - CategoryDataset dataset, int row, int column, - Shape hotspot) { + protected void addEntity(EntityCollection entities, Shape hotspot, + CategoryDataset dataset, int row, int column, boolean selected) { + if (hotspot == null) { throw new IllegalArgumentException("Null 'hotspot' argument."); } - if (!getItemCreateEntity(row, column)) { - return; - } - String tip = null; - CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); - if (tipster != null) { - tip = tipster.generateToolTip(dataset, row, column); - } - String url = null; - CategoryURLGenerator urlster = getURLGenerator(row, column); - if (urlster != null) { - url = urlster.generateURL(dataset, row, column); - } - CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, - dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); - entities.add(entity); + addEntity(entities, hotspot, dataset, row, column, selected, 0.0, 0.0); } /** @@ -1818,17 +1819,18 @@ * @param dataset the dataset. * @param row the series. * @param column the item. + * @param selected is the item selected? * @param entityX the entity's center x-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * @param entityY the entity's center y-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * - * @since 1.0.13 + * @since 1.2.0 */ protected void addEntity(EntityCollection entities, Shape hotspot, - CategoryDataset dataset, int row, int column, - double entityX, double entityY) { - if (!getItemCreateEntity(row, column)) { + CategoryDataset dataset, int row, int column, boolean selected, + double entityX, double entityY) { + if (!getItemCreateEntity(row, column, selected)) { return; } Shape s = hotspot; @@ -1843,12 +1845,13 @@ } } String tip = null; - CategoryToolTipGenerator generator = getToolTipGenerator(row, column); + CategoryToolTipGenerator generator = getToolTipGenerator(row, column, + selected); if (generator != null) { tip = generator.generateToolTip(dataset, row, column); } String url = null; - CategoryURLGenerator urlster = getURLGenerator(row, column); + CategoryURLGenerator urlster = getURLGenerator(row, column, selected); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } Modified: trunk/source/org/jfree/chart/renderer/category/AreaRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/AreaRenderer.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/AreaRenderer.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -214,12 +214,15 @@ * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * @param pass the pass index. + * + * @since 1.2.0 */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, - int pass) { + boolean selected, int pass) { // do nothing if item is not visible or null if (!getItemVisible(row, column)) { @@ -283,8 +286,8 @@ float yz = (float) rangeAxis.valueToJava2D(0.0, dataArea, edge); double labelXX = x1; double labelYY = y1; - g2.setPaint(getItemPaint(row, column)); - g2.setStroke(getItemStroke(row, column)); + g2.setPaint(getItemPaint(row, column, selected)); + g2.setStroke(getItemStroke(row, column, selected)); GeneralPath area = new GeneralPath(); @@ -307,13 +310,13 @@ } area.closePath(); - g2.setPaint(getItemPaint(row, column)); + g2.setPaint(getItemPaint(row, column, selected)); g2.fill(area); // draw the item labels if there are any... - if (isItemLabelVisible(row, column)) { - drawItemLabel(g2, orientation, dataset, row, column, labelXX, - labelYY, (value.doubleValue() < 0.0)); + if (isItemLabelVisible(row, column, selected)) { + drawItemLabel(g2, orientation, dataset, row, column, selected, + labelXX, labelYY, (value.doubleValue() < 0.0)); } // submit the current data point as a crosshair candidate @@ -325,7 +328,7 @@ // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { - addItemEntity(entities, dataset, row, column, area); + addEntity(entities, area, dataset, row, column, selected); } } Modified: trunk/source/org/jfree/chart/renderer/category/BarPainter.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/BarPainter.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/BarPainter.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * --------------- * BarPainter.java * --------------- - * (C) Copyright 2008, by Object Refinery Limited. + * (C) Copyright 2008, 2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,6 +35,7 @@ * Changes: * -------- * 19-Jun-2008 : Version 1 (DG); + * 25-Jun-2009 : Interface changed for 1.2.0 (DG); * */ @@ -58,7 +59,7 @@ * serialization will not be supported.</li> * </ul> * - * @since 1.0.11 + * @since 1.2.0 */ public interface BarPainter { @@ -69,11 +70,13 @@ * @param renderer the renderer. * @param row the row index for the item. * @param column the column index for the item. + * @param selected is the item selected? * @param bar the bounds for the bar. * @param base the base of the bar. */ public void paintBar(Graphics2D g2, BarRenderer renderer, - int row, int column, RectangularShape bar, RectangleEdge base); + int row, int column, boolean selected, + RectangularShape bar, RectangleEdge base); /** * Paints the shadow for a single bar on behalf of a renderer. @@ -82,12 +85,13 @@ * @param renderer the renderer. * @param row the row index for the item. * @param column the column index for the item. + * @param selected is the item selected? * @param bar the bounds for the bar. * @param base the base of the bar. * @param pegShadow peg the shadow to the base of the bar? */ public void paintBarShadow(Graphics2D g2, BarRenderer renderer, - int row, int column, RectangularShape bar, RectangleEdge base, - boolean pegShadow); + int row, int column, boolean selected, + RectangularShape bar, RectangleEdge base, boolean pegShadow); } Modified: trunk/source/org/jfree/chart/renderer/category/BarRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/BarRenderer.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/BarRenderer.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -132,7 +132,6 @@ import org.jfree.chart.util.StandardGradientPaintTransformer; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; -import org.jfree.data.general.DatasetUtilities; /** * A {@link CategoryItemRenderer} that draws individual data items as bars. @@ -986,18 +985,13 @@ * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * @param pass the pass index. */ - public void drawItem(Graphics2D g2, - CategoryItemRendererState state, - Rectangle2D dataArea, - CategoryPlot plot, - CategoryAxis domainAxis, - ValueAxis rangeAxis, - CategoryDataset dataset, - int row, - int column, - int pass) { + public void drawItem(Graphics2D g2, CategoryItemRendererState state, + Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, + ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, + boolean selected, int pass) { // nothing is drawn if the row index is not included in the list with // the indices of the visible rows... @@ -1071,16 +1065,17 @@ state.getBarWidth(), barLength + barLengthAdj); } if (getShadowsVisible()) { - this.barPainter.paintBarShadow(g2, this, row, column, bar, barBase, - true); + this.barPainter.paintBarShadow(g2, this, row, column, selected, + bar, barBase, true); } - this.barPainter.paintBar(g2, this, row, column, bar, barBase); + this.barPainter.paintBar(g2, this, row, column, selected, bar, + barBase); CategoryItemLabelGenerator generator = getItemLabelGenerator(row, - column); - if (generator != null && isItemLabelVisible(row, column)) { - drawItemLabel(g2, dataset, row, column, plot, generator, bar, - (value < 0.0)); + column, selected); + if (generator != null && isItemLabelVisible(row, column, selected)) { + drawItemLabelForBar(g2, plot, dataset, row, column, selected, + generator, bar, (value < 0.0)); } // submit the current data point as a crosshair candidate @@ -1092,7 +1087,7 @@ // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { - addItemEntity(entities, dataset, row, column, bar); + addEntity(entities, bar, dataset, row, column, selected); } } @@ -1118,44 +1113,44 @@ } /** - * Draws an item label. This method is overridden so that the bar can be - * used to calculate the label anchor point. + * Draws an item label. This method is used for bars instead of + * {@link #drawItemLabel()} so that the bar can be used to calculate the + * label anchor point. * * @param g2 the graphics device. - * @param data the dataset. + * @param dataset the dataset. * @param row the row. * @param column the column. + * @param selected is the item selected? * @param plot the plot. * @param generator the label generator. * @param bar the bar. * @param negative a flag indicating a negative value. + * + * @since 1.2.0 */ - protected void drawItemLabel(Graphics2D g2, - CategoryDataset data, - int row, - int column, - CategoryPlot plot, - CategoryItemLabelGenerator generator, - Rectangle2D bar, - boolean negative) { + protected void drawItemLabelForBar(Graphics2D g2, CategoryPlot plot, + CategoryDataset dataset, int row, int column, boolean selected, + CategoryItemLabelGenerator generator, Rectangle2D bar, + boolean negative) { - String label = generator.generateLabel(data, row, column); + String label = generator.generateLabel(dataset, row, column); if (label == null) { return; // nothing to do } - Font labelFont = getItemLabelFont(row, column); + Font labelFont = getItemLabelFont(row, column, selected); g2.setFont(labelFont); - Paint paint = getItemLabelPaint(row, column); + Paint paint = getItemLabelPaint(row, column, selected); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { - position = getPositiveItemLabelPosition(row, column); + position = getPositiveItemLabelPosition(row, column, selected); } else { - position = getNegativeItemLabelPosition(row, column); + position = getNegativeItemLabelPosition(row, column, selected); } // work out the label anchor point... Modified: trunk/source/org/jfree/chart/renderer/category/BarRenderer3D.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/BarRenderer3D.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/BarRenderer3D.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -652,18 +652,15 @@ * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * @param pass the pass index. + * + * @since 1.2.0 */ - public void drawItem(Graphics2D g2, - CategoryItemRendererState state, - Rectangle2D dataArea, - CategoryPlot plot, - CategoryAxis domainAxis, - ValueAxis rangeAxis, - CategoryDataset dataset, - int row, - int column, - int pass) { + public void drawItem(Graphics2D g2, CategoryItemRendererState state, + Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, + ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, + boolean selected, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); @@ -703,7 +700,7 @@ bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } - Paint itemPaint = getItemPaint(row, column); + Paint itemPaint = getItemPaint(row, column, selected); g2.setPaint(itemPaint); g2.fill(bar); @@ -743,8 +740,8 @@ if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { - g2.setStroke(getItemOutlineStroke(row, column)); - g2.setPaint(getItemOutlinePaint(row, column)); + g2.setStroke(getItemOutlineStroke(row, column, selected)); + g2.setPaint(getItemOutlinePaint(row, column, selected)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); @@ -754,11 +751,11 @@ } } - CategoryItemLabelGenerator generator - = getItemLabelGenerator(row, column); - if (generator != null && isItemLabelVisible(row, column)) { - drawItemLabel(g2, dataset, row, column, plot, generator, bar, - (value < 0.0)); + CategoryItemLabelGenerator generator = getItemLabelGenerator(row, + column, selected); + if (generator != null && isItemLabelVisible(row, column, selected)) { + drawItemLabelForBar(g2, plot, dataset, row, column, selected, + generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected @@ -772,7 +769,7 @@ barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); - addItemEntity(entities, dataset, row, column, barOutline); + addEntity(entities, barOutline, dataset, row, column, selected); } } Modified: trunk/source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -470,16 +470,10 @@ * @param column the column index (zero-based). * @param pass the pass index. */ - public void drawItem(Graphics2D g2, - CategoryItemRendererState state, - Rectangle2D dataArea, - CategoryPlot plot, - CategoryAxis domainAxis, - ValueAxis rangeAxis, - CategoryDataset dataset, - int row, - int column, - int pass) { + public void drawItem(Graphics2D g2, CategoryItemRendererState state, + Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, + ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, + boolean selected, int pass) { // do nothing if item is not visible if (!getItemVisible(row, column)) { @@ -496,11 +490,11 @@ if (orientation == PlotOrientation.HORIZONTAL) { drawHorizontalItem(g2, state, dataArea, plot, domainAxis, - rangeAxis, dataset, row, column); + rangeAxis, dataset, row, column, selected, pass); } else if (orientation == PlotOrientation.VERTICAL) { drawVerticalItem(g2, state, dataArea, plot, domainAxis, - rangeAxis, dataset, row, column); + rangeAxis, dataset, row, column, selected, pass); } } @@ -520,16 +514,16 @@ * {@link BoxAndWhiskerCategoryDataset}). * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? + * @param pass the number of the current pass. + * + * @since 1.2.0 */ - public void drawHorizontalItem(Graphics2D g2, - CategoryItemRendererState state, - Rectangle2D dataArea, - CategoryPlot plot, - CategoryAxis domainAxis, - ValueAxis rangeAxis, - CategoryDataset dataset, - int row, - int column) { + protected void drawHorizontalItem(Graphics2D g2, + CategoryItemRendererState state, Rectangle2D dataArea, + CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, + CategoryDataset dataset, int row, int column, boolean selected, + int pass) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; @@ -561,8 +555,8 @@ yy = yy + offset; } - g2.setPaint(getItemPaint(row, column)); - Stroke s = getItemStroke(row, column); + g2.setPaint(getItemPaint(row, column, selected)); + Stroke s = getItemStroke(row, column, selected); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); @@ -601,8 +595,8 @@ if (this.fillBox) { g2.fill(box); } - g2.setStroke(getItemOutlineStroke(row, column)); - g2.setPaint(getItemOutlinePaint(row, column)); + g2.setStroke(getItemOutlineStroke(row, column, selected)); + g2.setPaint(getItemOutlinePaint(row, column, selected)); g2.draw(box); } @@ -642,7 +636,7 @@ if (state.getInfo() != null && box != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { - addItemEntity(entities, dataset, row, column, box); + addEntity(entities, box, dataset, row, column, selected); } } @@ -663,16 +657,16 @@ * {@link BoxAndWhiskerCategoryDataset}). * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? + * @param pass the number of the current pass. + * + * @since 1.2.0 */ - public void drawVerticalItem(Graphics2D g2, - CategoryItemRendererState state, - Rectangle2D dataArea, - CategoryPlot plot, - CategoryAxis domainAxis, - ValueAxis rangeAxis, - CategoryDataset dataset, - int row, - int column) { + protected void drawVerticalItem(Graphics2D g2, + CategoryItemRendererState state, Rectangle2D dataArea, + CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, + CategoryDataset dataset, int row, int column, boolean selected, + int pass) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; @@ -707,9 +701,9 @@ double yyAverage = 0.0; double yyOutlier; - Paint itemPaint = getItemPaint(row, column); + Paint itemPaint = getItemPaint(row, column, selected); g2.setPaint(itemPaint); - Stroke s = getItemStroke(row, column); + Stroke s = getItemStroke(row, column, selected); g2.setStroke(s); double aRadius = 0; // average radius @@ -749,8 +743,8 @@ if (this.fillBox) { g2.fill(box); } - g2.setStroke(getItemOutlineStroke(row, column)); - g2.setPaint(getItemOutlinePaint(row, column)); + g2.setStroke(getItemOutlineStroke(row, column, selected)); + g2.setPaint(getItemOutlinePaint(row, column, selected)); g2.draw(box); } @@ -870,7 +864,7 @@ if (state.getInfo() != null && box != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { - addItemEntity(entities, dataset, row, column, box); + addEntity(entities, box, dataset, row, column, selected); } } Modified: trunk/source/org/jfree/chart/renderer/category/CategoryItemRenderer.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/CategoryItemRenderer.java 2009-06-25 11:06:56 UTC (rev 2164) +++ trunk/source/org/jfree/chart/renderer/category/CategoryItemRenderer.java 2009-06-26 07:32:18 UTC (rev 2165) @@ -387,10 +387,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemPaint(int row, int column); + public Paint getItemPaint(int row, int column, boolean selected); /** * Returns the paint used to fill an item drawn by the renderer. @@ -464,12 +467,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). * * @since 1.2.0 */ - public Paint getItemFillPaint(int row, int column); + public Paint getItemFillPaint(int row, int column, boolean selected); /** * Returns the paint used to fill an item drawn by the renderer. @@ -555,10 +559,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemOutlinePaint(int row, int column); + public Paint getItemOutlinePaint(int row, int column, boolean selected); /** * Returns the paint used to outline an item drawn by the renderer. @@ -636,10 +643,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The stroke (never <code>null</code>). + * + * @since 1.2.0 */ - public Stroke getItemStroke(int row, int column); + public Stroke getItemStroke(int row, int column, boolean selected); /** * Returns the stroke used to draw the items in a series. @@ -721,10 +731,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The stroke (never <code>null</code>). + * + * @since 1.2.0 */ - public Stroke getItemOutlineStroke(int row, int column); + public Stroke getItemOutlineStroke(int row, int column, boolean selected); /** * Returns the stroke used to outline the items in a series. @@ -803,10 +816,13 @@ * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). + * @param selected is the item selected? * * @return The shape (never <code>null</code>). + * + * @since 1.2.0 */ - public Shape getItemShape(int row, int column); + public Shape getItemShape(int row, int column, boolean selected); /** * Returns a shape used to represent the items in a series. @@ -973,10 +989,14 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return The generator (possibly <code>null</code>). + * + * @since 1.2.0 */ - public CategoryToolTipGenerator getToolTipGenerator(int row, int column); + public CategoryToolTipGenerator getToolTipGenerator(int row, int column, + boolean selected); /** * Returns the tool tip generator for the specified series (a "layer 1" @@ -1060,10 +1080,14 @@ * * @param series the series index (zero-based). * @param item the item index (zero-based). + * @param selected is the item selected? * * @return The item URL generator. + * + * @since 1.2.0 */ - public CategoryURLGenerator getURLGenerator(int series, int item); + public CategoryURLGenerator getURLGenerator(int series, int item, boolean + selected); /** * Returns the URL generator for a series. @@ -1141,10 +1165,13 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return A boolean. + * + * @since 1.2.0 */ - public boolean isItemLabelVisible(int row, int column); + public boolean isItemLabelVisible(int row, int column, boolean selected); /** * Returns <code>true</code> if the item labels for a series are visible, @@ -1244,11 +1271,14 @@ * * @param series the series index (zero-based). * @param item the item index (zero-based). + * @param selected is the item selected? * * @return The generator (possibly <code>null</code>). + * + * @since 1.2.0 */ public CategoryItemLabelGenerator getItemLabelGenerator(int series, - int item); + int item, boolean selected); /** * Returns the item label generator for a series. @@ -1327,10 +1357,13 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return The font (never <code>null</code>). + * + * @since 1.2.0 */ - public Font getItemLabelFont(int row, int column); + public Font getItemLabelFont(int row, int column, boolean selected); /** * Returns the font for all the item labels in a series. @@ -1409,10 +1442,13 @@ * * @param row the row index (zero based). * @param column the column index (zero based). + * @param selected is the item selected? * * @return The paint (never <code>null</code>). + * + * @since 1.2.0 */ - public Paint getItemLabelPaint(int row, int column); + public Paint getItemLabelPaint(int row, int column, boolean selected); /** * Returns the paint used to draw the item labels for a series. @@ -1491,10 +1527,14 @@ * * @param row the row index (zero-based). * @param column the column index (zero-based). + * @param selected is the item selected? * * @return The item label position (never <code>null</code>). + * + * @since 1.2.0 */ - public ItemLabelPosition getPositiveItemLabelPosition(int row, int column); + public ItemLabelPosition getPositiveItemLabelPosition(int row, int column, + boolean selected); /** * Returns the item label position for all positive values in a series. @@ -1573,10 +1613,14 @@ * * @param row the row index (zero-based). * @param column the column (zero-based). + * @param selected is the item selected? * * @return The item label position. + * + * @since 1.2.0 */ - public ItemLabelPosition getNegativeItemLabelPosition(int row, int column); + public ItemLabelPosition getNegativeItemLabelPosition(int row, int column, + boolean selected); /** * Returns the item label position for all negative values in a series. @@ -1656,12 +1700,13 @@ * * @param series ... [truncated message content] |
From: <mu...@us...> - 2009-06-26 14:13:06
|
Revision: 2167 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2167&view=rev Author: mungady Date: 2009-06-26 13:56:23 +0000 (Fri, 26 Jun 2009) Log Message: ----------- Added removeSeries() methods. Modified Paths: -------------- trunk/source/org/jfree/data/time/ohlc/OHLCSeriesCollection.java trunk/tests/org/jfree/data/time/ohlc/junit/OHLCSeriesCollectionTests.java Modified: trunk/source/org/jfree/data/time/ohlc/OHLCSeriesCollection.java =================================================================== --- trunk/source/org/jfree/data/time/ohlc/OHLCSeriesCollection.java 2009-06-26 07:40:49 UTC (rev 2166) +++ trunk/source/org/jfree/data/time/ohlc/OHLCSeriesCollection.java 2009-06-26 13:56:23 UTC (rev 2167) @@ -38,7 +38,8 @@ * 21-Jun-2007 : Removed JCommon dependencies (DG); * 10-Jul-2008 : Added accessor methods for xPosition attribute (DG); * 23-May-2009 : Added hashCode() implementation (DG); - * + * 26-Jun-2009 : Added removeSeries() methods (DG); + * */ package org.jfree.data.time.ohlc; @@ -371,6 +372,69 @@ } /** + * Removes the series with the specified index and sends a + * {@link DatasetChangeEvent} to all registered listeners. + * + * @param index the series index. + * + * @since 1.0.14 + */ + public void removeSeries(int index) { + OHLCSeries series = getSeries(index); + if (series != null) { + removeSeries(series); + } + } + + /** + * Removes the specified series from the dataset and sends a + * {@link DatasetChangeEvent} to all registered listeners. + * + * @param series the series (<code>null</code> not permitted). + * + * @return <code>true</code> if the series was removed, and + * <code>false</code> otherwise. + * + * @since 1.0.14 + */ + public boolean removeSeries(OHLCSeries series) { + if (series == null) { + throw new IllegalArgumentException("Null 'series' argument."); + } + boolean removed = this.data.remove(series); + if (removed) { + series.removeChangeListener(this); + fireDatasetChanged(); + } + return removed; + } + + /** + * Removes all the series from the collection and sends a + * {@link DatasetChangeEvent} to all registered listeners. + * + * @since 1.0.14 + */ + public void removeAllSeries() { + + if (this.data.size() == 0) { + return; // nothing to do + } + + // deregister the collection as a change listener to each series in the + // collection + for (int i = 0; i < this.data.size(); i++) { + OHLCSeries series = (OHLCSeries) this.data.get(i); + series.removeChangeListener(this); + } + + // remove all the series from the collection and notify listeners. + this.data.clear(); + fireDatasetChanged(); + + } + + /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). Modified: trunk/tests/org/jfree/data/time/ohlc/junit/OHLCSeriesCollectionTests.java =================================================================== --- trunk/tests/org/jfree/data/time/ohlc/junit/OHLCSeriesCollectionTests.java 2009-06-26 07:40:49 UTC (rev 2166) +++ trunk/tests/org/jfree/data/time/ohlc/junit/OHLCSeriesCollectionTests.java 2009-06-26 13:56:23 UTC (rev 2167) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------------ * OHLCSeriesCollectionTests.java * ------------------------------ - * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2006-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -36,6 +36,7 @@ * ------- * 04-Dec-2006 : Version 1 (DG); * 10-Jul-2008 : Updated testEquals() method (DG); + * 26-Jun-2009 : Added tests for removeSeries() methods (DG); * */ @@ -52,6 +53,8 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.time.TimePeriodAnchor; import org.jfree.data.time.Year; import org.jfree.data.time.ohlc.OHLCSeries; @@ -60,7 +63,8 @@ /** * Tests for the {@link OHLCSeriesCollectionTests} class. */ -public class OHLCSeriesCollectionTests extends TestCase { +public class OHLCSeriesCollectionTests extends TestCase + implements DatasetChangeListener { /** * Returns the tests as a test suite. @@ -181,4 +185,80 @@ } } + /** + * Some checks for the {@link OHLCSeriesCollection#removeSeries(int)} + * method. + */ + public void testRemoveSeries_int() { + OHLCSeriesCollection c1 = new OHLCSeriesCollection(); + OHLCSeries s1 = new OHLCSeries("Series 1"); + OHLCSeries s2 = new OHLCSeries("Series 2"); + OHLCSeries s3 = new OHLCSeries("Series 3"); + OHLCSeries s4 = new OHLCSeries("Series 4"); + c1.addSeries(s1); + c1.addSeries(s2); + c1.addSeries(s3); + c1.addSeries(s4); + c1.removeSeries(2); + assertTrue(c1.getSeries(2).equals(s4)); + c1.removeSeries(0); + assertTrue(c1.getSeries(0).equals(s2)); + assertEquals(2, c1.getSeriesCount()); + } + + /** + * Some checks for the + * {@link OHLCSeriesCollection#removeSeries(OHLCSeries)} method. + */ + public void testRemoveSeries() { + OHLCSeriesCollection c1 = new OHLCSeriesCollection(); + OHLCSeries s1 = new OHLCSeries("Series 1"); + OHLCSeries s2 = new OHLCSeries("Series 2"); + OHLCSeries s3 = new OHLCSeries("Series 3"); + OHLCSeries s4 = new OHLCSeries("Series 4"); + c1.addSeries(s1); + c1.addSeries(s2); + c1.addSeries(s3); + c1.addSeries(s4); + c1.removeSeries(s3); + assertTrue(c1.getSeries(2).equals(s4)); + c1.removeSeries(s1); + assertTrue(c1.getSeries(0).equals(s2)); + assertEquals(2, c1.getSeriesCount()); + } + + /** + * A simple check for the removeAllSeries() method. + */ + public void testRemoveAllSeries() { + OHLCSeriesCollection c1 = new OHLCSeriesCollection(); + c1.addChangeListener(this); + + // there should be no change event when clearing an empty series + this.lastEvent = null; + c1.removeAllSeries(); + assertNull(this.lastEvent); + + OHLCSeries s1 = new OHLCSeries("Series 1"); + OHLCSeries s2 = new OHLCSeries("Series 2"); + c1.addSeries(s1); + c1.addSeries(s2); + c1.removeAllSeries(); + assertEquals(0, c1.getSeriesCount()); + assertNotNull(this.lastEvent); + this.lastEvent = null; // clean up + } + + /** The last received event. */ + private DatasetChangeEvent lastEvent; + + /** + * Receives dataset change events. + * + * @param event the event. + */ + public void datasetChanged(DatasetChangeEvent event) { + this.lastEvent = event; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-06-26 15:08:22
|
Revision: 2170 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2170&view=rev Author: mungady Date: 2009-06-26 15:08:20 +0000 (Fri, 26 Jun 2009) Log Message: ----------- Updated cloning. Modified Paths: -------------- trunk/source/org/jfree/data/time/TimeSeriesCollection.java trunk/tests/org/jfree/data/time/junit/TimeSeriesCollectionTests.java Modified: trunk/source/org/jfree/data/time/TimeSeriesCollection.java =================================================================== --- trunk/source/org/jfree/data/time/TimeSeriesCollection.java 2009-06-26 14:10:00 UTC (rev 2169) +++ trunk/source/org/jfree/data/time/TimeSeriesCollection.java 2009-06-26 15:08:20 UTC (rev 2170) @@ -82,7 +82,8 @@ * 19-May-2009 : Implemented XYDomainInfo (DG); * 26-May-2009 : Implemented XYRangeInfo (DG); * 09-Jun-2009 : Apply some short-cuts to series value lookups (DG); - * + * 26-Jun-2009 : Fixed clone() (DG); + * */ package org.jfree.data.time; @@ -108,7 +109,7 @@ /** * A collection of time series objects. This class implements the - * {@link org.jfree.data.xy.XYDataset} interface, as well as the extended + * {@link XYDataset} interface, as well as the extended * {@link IntervalXYDataset} interface. This makes it a convenient dataset for * use with the {@link org.jfree.chart.plot.XYPlot} class. */ @@ -685,4 +686,18 @@ return result; } + /** + * Returns a clone of this time series collection. + * + * @return A clone. + * + * @throws java.lang.CloneNotSupportedException + */ + public Object clone() throws CloneNotSupportedException { + TimeSeriesCollection clone = (TimeSeriesCollection) super.clone(); + clone.data = (List) ObjectUtilities.deepClone(this.data); + clone.workingCalendar = (Calendar) this.workingCalendar.clone(); + return clone; + } + } Modified: trunk/tests/org/jfree/data/time/junit/TimeSeriesCollectionTests.java =================================================================== --- trunk/tests/org/jfree/data/time/junit/TimeSeriesCollectionTests.java 2009-06-26 14:10:00 UTC (rev 2169) +++ trunk/tests/org/jfree/data/time/junit/TimeSeriesCollectionTests.java 2009-06-26 15:08:20 UTC (rev 2170) @@ -152,6 +152,27 @@ } /** + * Some checks for the {@link TimeSeriesCollection#removeSeries(int)} + * method. + */ + public void testRemoveSeries_int() { + TimeSeriesCollection c1 = new TimeSeriesCollection(); + TimeSeries s1 = new TimeSeries("Series 1"); + TimeSeries s2 = new TimeSeries("Series 2"); + TimeSeries s3 = new TimeSeries("Series 3"); + TimeSeries s4 = new TimeSeries("Series 4"); + c1.addSeries(s1); + c1.addSeries(s2); + c1.addSeries(s3); + c1.addSeries(s4); + c1.removeSeries(2); + assertTrue(c1.getSeries(2).equals(s4)); + c1.removeSeries(0); + assertTrue(c1.getSeries(0).equals(s2)); + assertEquals(2, c1.getSeriesCount()); + } + + /** * Test the getSurroundingItems() method to ensure it is returning the * values we expect. */ @@ -229,10 +250,8 @@ * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { - TimeSeriesCollection c1 = new TimeSeriesCollection(createSeries()); TimeSeriesCollection c2 = null; - try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); @@ -240,16 +259,14 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); c2 = (TimeSeriesCollection) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(c1, c2); - } /** @@ -360,4 +377,30 @@ TimeZone.setDefault(saved); } + /** + * Basic checks for cloning. + */ + public void testCloning() { + TimeSeries s1 = new TimeSeries("Series"); + s1.add(new Year(2009), 1.1); + TimeSeriesCollection c1 = new TimeSeriesCollection(); + c1.addSeries(s1); + TimeSeriesCollection c2 = null; + try { + c2 = (TimeSeriesCollection) c1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(c1 != c2); + assertTrue(c1.getClass() == c2.getClass()); + assertTrue(c1.equals(c2)); + + // check independence + s1.setDescription("XYZ"); + assertFalse(c1.equals(c2)); + c2.getSeries(0).setDescription("XYZ"); + assertTrue(c1.equals(c2)); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-06-29 14:17:39
|
Revision: 2181 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2181&view=rev Author: mungady Date: 2009-06-29 14:03:20 +0000 (Mon, 29 Jun 2009) Log Message: ----------- Moved PaintMap and StrokeMap from org.jfree.chart.* to org.jfree.chart.util.*. Modified Paths: -------------- trunk/source/org/jfree/chart/plot/PiePlot.java trunk/tests/org/jfree/chart/junit/ChartPackageTests.java trunk/tests/org/jfree/chart/util/junit/UtilPackageTests.java Added Paths: ----------- trunk/source/org/jfree/chart/util/PaintMap.java trunk/source/org/jfree/chart/util/StrokeMap.java trunk/tests/org/jfree/chart/util/junit/PaintMapTests.java trunk/tests/org/jfree/chart/util/junit/StrokeMapTests.java Removed Paths: ------------- trunk/source/org/jfree/chart/PaintMap.java trunk/source/org/jfree/chart/StrokeMap.java trunk/tests/org/jfree/chart/junit/PaintMapTests.java trunk/tests/org/jfree/chart/junit/StrokeMapTests.java Deleted: trunk/source/org/jfree/chart/PaintMap.java =================================================================== --- trunk/source/org/jfree/chart/PaintMap.java 2009-06-29 13:53:27 UTC (rev 2180) +++ trunk/source/org/jfree/chart/PaintMap.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -1,223 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * ------------- - * PaintMap.java - * ------------- - * (C) Copyright 2006-2008, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes: - * -------- - * 27-Sep-2006 : Version 1 (DG); - * 17-Jan-2007 : Changed TreeMap to HashMap, so that different classes that - * implement Comparable can be used as keys (DG); - * 21-Jun-2007 : Removed JCommon dependencies (DG); - * - */ - -package org.jfree.chart; - -import java.awt.Paint; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.jfree.chart.util.PaintUtilities; -import org.jfree.chart.util.SerialUtilities; - -/** - * A storage structure that maps <code>Comparable</code> instances with - * <code>Paint</code> instances. - * <br><br> - * To support cloning and serialization, you should only use keys that are - * cloneable and serializable. Special handling for the <code>Paint</code> - * instances is included in this class. - * - * @since 1.0.3 - */ -public class PaintMap implements Cloneable, Serializable { - - /** For serialization. */ - static final long serialVersionUID = -4639833772123069274L; - - /** Storage for the keys and values. */ - private transient Map store; - - /** - * Creates a new (empty) map. - */ - public PaintMap() { - this.store = new HashMap(); - } - - /** - * Returns the paint associated with the specified key, or - * <code>null</code>. - * - * @param key the key (<code>null</code> not permitted). - * - * @return The paint, or <code>null</code>. - * - * @throws IllegalArgumentException if <code>key</code> is - * <code>null</code>. - */ - public Paint getPaint(Comparable key) { - if (key == null) { - throw new IllegalArgumentException("Null 'key' argument."); - } - return (Paint) this.store.get(key); - } - - /** - * Returns <code>true</code> if the map contains the specified key, and - * <code>false</code> otherwise. - * - * @param key the key. - * - * @return <code>true</code> if the map contains the specified key, and - * <code>false</code> otherwise. - */ - public boolean containsKey(Comparable key) { - return this.store.containsKey(key); - } - - /** - * Adds a mapping between the specified <code>key</code> and - * <code>paint</code> values. - * - * @param key the key (<code>null</code> not permitted). - * @param paint the paint. - * - * @throws IllegalArgumentException if <code>key</code> is - * <code>null</code>. - */ - public void put(Comparable key, Paint paint) { - if (key == null) { - throw new IllegalArgumentException("Null 'key' argument."); - } - this.store.put(key, paint); - } - - /** - * Resets the map to empty. - */ - public void clear() { - this.store.clear(); - } - - /** - * Tests this map 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 PaintMap)) { - return false; - } - PaintMap that = (PaintMap) obj; - if (this.store.size() != that.store.size()) { - return false; - } - Set keys = this.store.keySet(); - Iterator iterator = keys.iterator(); - while (iterator.hasNext()) { - Comparable key = (Comparable) iterator.next(); - Paint p1 = getPaint(key); - Paint p2 = that.getPaint(key); - if (!PaintUtilities.equal(p1, p2)) { - return false; - } - } - return true; - } - - /** - * Returns a clone of this <code>PaintMap</code>. - * - * @return A clone of this instance. - * - * @throws CloneNotSupportedException if any key is not cloneable. - */ - public Object clone() throws CloneNotSupportedException { - // TODO: I think we need to make sure the keys are actually cloned, - // whereas the paint instances are always immutable so they're OK - 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(); - stream.writeInt(this.store.size()); - Set keys = this.store.keySet(); - Iterator iterator = keys.iterator(); - while (iterator.hasNext()) { - Comparable key = (Comparable) iterator.next(); - stream.writeObject(key); - Paint paint = getPaint(key); - SerialUtilities.writePaint(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.store = new HashMap(); - int keyCount = stream.readInt(); - for (int i = 0; i < keyCount; i++) { - Comparable key = (Comparable) stream.readObject(); - Paint paint = SerialUtilities.readPaint(stream); - this.store.put(key, paint); - } - } - -} Deleted: trunk/source/org/jfree/chart/StrokeMap.java =================================================================== --- trunk/source/org/jfree/chart/StrokeMap.java 2009-06-29 13:53:27 UTC (rev 2180) +++ trunk/source/org/jfree/chart/StrokeMap.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -1,218 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * -------------- - * StrokeMap.java - * -------------- - * (C) Copyright 2006-2008, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes: - * -------- - * 27-Sep-2006 : Version 1 (DG); - * 21-Jun-2007 : Removed JCommon dependencies (DG); - * - */ - -package org.jfree.chart; - -import java.awt.Stroke; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -import org.jfree.chart.util.ObjectUtilities; -import org.jfree.chart.util.SerialUtilities; - -/** - * A storage structure that maps <code>Comparable</code> instances with - * <code>Stroke</code> instances. - * <br><br> - * To support cloning and serialization, you should only use keys that are - * cloneable and serializable. Special handling for the <code>Stroke</code> - * instances is included in this class. - * - * @since 1.0.3 - */ -public class StrokeMap implements Cloneable, Serializable { - - /** For serialization. */ - static final long serialVersionUID = -8148916785963525169L; - - /** Storage for the keys and values. */ - private transient Map store; - - /** - * Creates a new (empty) map. - */ - public StrokeMap() { - this.store = new TreeMap(); - } - - /** - * Returns the stroke associated with the specified key, or - * <code>null</code>. - * - * @param key the key (<code>null</code> not permitted). - * - * @return The stroke, or <code>null</code>. - * - * @throws IllegalArgumentException if <code>key</code> is - * <code>null</code>. - */ - public Stroke getStroke(Comparable key) { - if (key == null) { - throw new IllegalArgumentException("Null 'key' argument."); - } - return (Stroke) this.store.get(key); - } - - /** - * Returns <code>true</code> if the map contains the specified key, and - * <code>false</code> otherwise. - * - * @param key the key. - * - * @return <code>true</code> if the map contains the specified key, and - * <code>false</code> otherwise. - */ - public boolean containsKey(Comparable key) { - return this.store.containsKey(key); - } - - /** - * Adds a mapping between the specified <code>key</code> and - * <code>stroke</code> values. - * - * @param key the key (<code>null</code> not permitted). - * @param stroke the stroke. - */ - public void put(Comparable key, Stroke stroke) { - if (key == null) { - throw new IllegalArgumentException("Null 'key' argument."); - } - this.store.put(key, stroke); - } - - /** - * Resets the map to empty. - */ - public void clear() { - this.store.clear(); - } - - /** - * Tests this map 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 StrokeMap)) { - return false; - } - StrokeMap that = (StrokeMap) obj; - if (this.store.size() != that.store.size()) { - return false; - } - Set keys = this.store.keySet(); - Iterator iterator = keys.iterator(); - while (iterator.hasNext()) { - Comparable key = (Comparable) iterator.next(); - Stroke s1 = getStroke(key); - Stroke s2 = that.getStroke(key); - if (!ObjectUtilities.equal(s1, s2)) { - return false; - } - } - return true; - } - - /** - * Returns a clone of this <code>StrokeMap</code>. - * - * @return A clone of this instance. - * - * @throws CloneNotSupportedException if any key is not cloneable. - */ - public Object clone() throws CloneNotSupportedException { - // TODO: I think we need to make sure the keys are actually cloned, - // whereas the stroke instances are always immutable so they're OK - 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(); - stream.writeInt(this.store.size()); - Set keys = this.store.keySet(); - Iterator iterator = keys.iterator(); - while (iterator.hasNext()) { - Comparable key = (Comparable) iterator.next(); - stream.writeObject(key); - Stroke stroke = getStroke(key); - SerialUtilities.writeStroke(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.store = new TreeMap(); - int keyCount = stream.readInt(); - for (int i = 0; i < keyCount; i++) { - Comparable key = (Comparable) stream.readObject(); - Stroke stroke = SerialUtilities.readStroke(stream); - this.store.put(key, stroke); - } - } - -} Modified: trunk/source/org/jfree/chart/plot/PiePlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/PiePlot.java 2009-06-29 13:53:27 UTC (rev 2180) +++ trunk/source/org/jfree/chart/plot/PiePlot.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------ * PiePlot.java * ------------ - * (C) Copyright 2000-2008, by Andrzej Porebski and Contributors. + * (C) Copyright 2000-2009, by Andrzej Porebski and Contributors. * * Original Author: Andrzej Porebski; * Contributor(s): David Gilbert (for Object Refinery Limited); @@ -162,6 +162,7 @@ * generation (DG); * 23-Sep-2008 : Added getLabelLinkDepth() method - see bug 2121818 reported * by Christoph Beck (DG); + * 29-Jun-2009 : Moved PaintMap and StrokeMap to org.jfree.chart.util.* (DG); * */ @@ -196,8 +197,8 @@ import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; -import org.jfree.chart.PaintMap; -import org.jfree.chart.StrokeMap; +import org.jfree.chart.util.PaintMap; +import org.jfree.chart.util.StrokeMap; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.PieSectionEntity; import org.jfree.chart.event.PlotChangeEvent; Copied: trunk/source/org/jfree/chart/util/PaintMap.java (from rev 2164, trunk/source/org/jfree/chart/PaintMap.java) =================================================================== --- trunk/source/org/jfree/chart/util/PaintMap.java (rev 0) +++ trunk/source/org/jfree/chart/util/PaintMap.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -0,0 +1,221 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * ------------- + * PaintMap.java + * ------------- + * (C) Copyright 2006-2009, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 27-Sep-2006 : Version 1 (DG); + * 17-Jan-2007 : Changed TreeMap to HashMap, so that different classes that + * implement Comparable can be used as keys (DG); + * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 29-Jun-2009 : Moved from org.jfree.chart.* to org.jfree.chart.util.* (DG); + * + */ + +package org.jfree.chart.util; + +import java.awt.Paint; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * A storage structure that maps <code>Comparable</code> instances with + * <code>Paint</code> instances. + * <br><br> + * To support cloning and serialization, you should only use keys that are + * cloneable and serializable. Special handling for the <code>Paint</code> + * instances is included in this class. + * + * @since 1.2.0 + */ +public class PaintMap implements Cloneable, Serializable { + + /** For serialization. */ + static final long serialVersionUID = -4639833772123069274L; + + /** Storage for the keys and values. */ + private transient Map store; + + /** + * Creates a new (empty) map. + */ + public PaintMap() { + this.store = new HashMap(); + } + + /** + * Returns the paint associated with the specified key, or + * <code>null</code>. + * + * @param key the key (<code>null</code> not permitted). + * + * @return The paint, or <code>null</code>. + * + * @throws IllegalArgumentException if <code>key</code> is + * <code>null</code>. + */ + public Paint getPaint(Comparable key) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } + return (Paint) this.store.get(key); + } + + /** + * Returns <code>true</code> if the map contains the specified key, and + * <code>false</code> otherwise. + * + * @param key the key. + * + * @return <code>true</code> if the map contains the specified key, and + * <code>false</code> otherwise. + */ + public boolean containsKey(Comparable key) { + return this.store.containsKey(key); + } + + /** + * Adds a mapping between the specified <code>key</code> and + * <code>paint</code> values. + * + * @param key the key (<code>null</code> not permitted). + * @param paint the paint. + * + * @throws IllegalArgumentException if <code>key</code> is + * <code>null</code>. + */ + public void put(Comparable key, Paint paint) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } + this.store.put(key, paint); + } + + /** + * Resets the map to empty. + */ + public void clear() { + this.store.clear(); + } + + /** + * Tests this map 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 PaintMap)) { + return false; + } + PaintMap that = (PaintMap) obj; + if (this.store.size() != that.store.size()) { + return false; + } + Set keys = this.store.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + Comparable key = (Comparable) iterator.next(); + Paint p1 = getPaint(key); + Paint p2 = that.getPaint(key); + if (!PaintUtilities.equal(p1, p2)) { + return false; + } + } + return true; + } + + /** + * Returns a clone of this <code>PaintMap</code>. + * + * @return A clone of this instance. + * + * @throws CloneNotSupportedException if any key is not cloneable. + */ + public Object clone() throws CloneNotSupportedException { + // TODO: I think we need to make sure the keys are actually cloned, + // whereas the paint instances are always immutable so they're OK + 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(); + stream.writeInt(this.store.size()); + Set keys = this.store.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + Comparable key = (Comparable) iterator.next(); + stream.writeObject(key); + Paint paint = getPaint(key); + SerialUtilities.writePaint(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.store = new HashMap(); + int keyCount = stream.readInt(); + for (int i = 0; i < keyCount; i++) { + Comparable key = (Comparable) stream.readObject(); + Paint paint = SerialUtilities.readPaint(stream); + this.store.put(key, paint); + } + } + +} Property changes on: trunk/source/org/jfree/chart/util/PaintMap.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/source/org/jfree/chart/util/StrokeMap.java (from rev 2164, trunk/source/org/jfree/chart/StrokeMap.java) =================================================================== --- trunk/source/org/jfree/chart/util/StrokeMap.java (rev 0) +++ trunk/source/org/jfree/chart/util/StrokeMap.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -0,0 +1,216 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2009, 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.] + * + * -------------- + * StrokeMap.java + * -------------- + * (C) Copyright 2006-2009, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 27-Sep-2006 : Version 1 (DG); + * 21-Jun-2007 : Removed JCommon dependencies (DG); + * 29-Jun-2009 : Moved from org.jfree.chart.* to org.jfree.chart.util.* (DG); + * + */ + +package org.jfree.chart.util; + +import java.awt.Stroke; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * A storage structure that maps <code>Comparable</code> instances with + * <code>Stroke</code> instances. + * <br><br> + * To support cloning and serialization, you should only use keys that are + * cloneable and serializable. Special handling for the <code>Stroke</code> + * instances is included in this class. + * + * @since 1.0.3 + */ +public class StrokeMap implements Cloneable, Serializable { + + /** For serialization. */ + static final long serialVersionUID = -8148916785963525169L; + + /** Storage for the keys and values. */ + private transient Map store; + + /** + * Creates a new (empty) map. + */ + public StrokeMap() { + this.store = new TreeMap(); + } + + /** + * Returns the stroke associated with the specified key, or + * <code>null</code>. + * + * @param key the key (<code>null</code> not permitted). + * + * @return The stroke, or <code>null</code>. + * + * @throws IllegalArgumentException if <code>key</code> is + * <code>null</code>. + */ + public Stroke getStroke(Comparable key) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } + return (Stroke) this.store.get(key); + } + + /** + * Returns <code>true</code> if the map contains the specified key, and + * <code>false</code> otherwise. + * + * @param key the key. + * + * @return <code>true</code> if the map contains the specified key, and + * <code>false</code> otherwise. + */ + public boolean containsKey(Comparable key) { + return this.store.containsKey(key); + } + + /** + * Adds a mapping between the specified <code>key</code> and + * <code>stroke</code> values. + * + * @param key the key (<code>null</code> not permitted). + * @param stroke the stroke. + */ + public void put(Comparable key, Stroke stroke) { + if (key == null) { + throw new IllegalArgumentException("Null 'key' argument."); + } + this.store.put(key, stroke); + } + + /** + * Resets the map to empty. + */ + public void clear() { + this.store.clear(); + } + + /** + * Tests this map 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 StrokeMap)) { + return false; + } + StrokeMap that = (StrokeMap) obj; + if (this.store.size() != that.store.size()) { + return false; + } + Set keys = this.store.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + Comparable key = (Comparable) iterator.next(); + Stroke s1 = getStroke(key); + Stroke s2 = that.getStroke(key); + if (!ObjectUtilities.equal(s1, s2)) { + return false; + } + } + return true; + } + + /** + * Returns a clone of this <code>StrokeMap</code>. + * + * @return A clone of this instance. + * + * @throws CloneNotSupportedException if any key is not cloneable. + */ + public Object clone() throws CloneNotSupportedException { + // TODO: I think we need to make sure the keys are actually cloned, + // whereas the stroke instances are always immutable so they're OK + 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(); + stream.writeInt(this.store.size()); + Set keys = this.store.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + Comparable key = (Comparable) iterator.next(); + stream.writeObject(key); + Stroke stroke = getStroke(key); + SerialUtilities.writeStroke(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.store = new TreeMap(); + int keyCount = stream.readInt(); + for (int i = 0; i < keyCount; i++) { + Comparable key = (Comparable) stream.readObject(); + Stroke stroke = SerialUtilities.readStroke(stream); + this.store.put(key, stroke); + } + } + +} Property changes on: trunk/source/org/jfree/chart/util/StrokeMap.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/tests/org/jfree/chart/junit/ChartPackageTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/ChartPackageTests.java 2009-06-29 13:53:27 UTC (rev 2180) +++ trunk/tests/org/jfree/chart/junit/ChartPackageTests.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ---------------------- * ChartPackageTests.java * ---------------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -40,6 +40,7 @@ * 02-Mar-2007 : Added missing tests (DG); * 06-Mar-2007 : Added HashUtilitiesTests (DG); * 14-Aug-2008 : Added StandardChartThemeTests (DG); + * 29-Jun-2009 : Moved StrokeMap and PaintMap to org.jfree.chart.util.* (DG); * */ @@ -75,7 +76,6 @@ suite.addTestSuite(LineChartTests.class); suite.addTestSuite(LineChart3DTests.class); suite.addTestSuite(MeterChartTests.class); - suite.addTestSuite(PaintMapTests.class); suite.addTestSuite(PieChartTests.class); suite.addTestSuite(PieChart3DTests.class); suite.addTestSuite(ScatterPlotTests.class); @@ -83,7 +83,6 @@ suite.addTestSuite(StackedBarChartTests.class); suite.addTestSuite(StackedBarChart3DTests.class); suite.addTestSuite(StandardChartThemeTests.class); - suite.addTestSuite(StrokeMapTests.class); suite.addTestSuite(TimeSeriesChartTests.class); suite.addTestSuite(WaterfallChartTests.class); suite.addTestSuite(XYAreaChartTests.class); Deleted: trunk/tests/org/jfree/chart/junit/PaintMapTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/PaintMapTests.java 2009-06-29 13:53:27 UTC (rev 2180) +++ trunk/tests/org/jfree/chart/junit/PaintMapTests.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -1,240 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * ------------------ - * PaintMapTests.java - * ------------------ - * (C) Copyright 2006-2008, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes: - * -------- - * 27-Sep-2006 : Version 1 (DG); - * 17-Jan-2007 : Added testKeysOfDifferentClasses() (DG); - * - */ - -package org.jfree.chart.junit; - -import java.awt.Color; -import java.awt.GradientPaint; -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.chart.PaintMap; - -/** - * Some tests for the {@link PaintMap} class. - */ -public class PaintMapTests extends TestCase { - - /** - * Returns the tests as a test suite. - * - * @return The test suite. - */ - public static Test suite() { - return new TestSuite(PaintMapTests.class); - } - - /** - * Constructs a new set of tests. - * - * @param name the name of the tests. - */ - public PaintMapTests(String name) { - super(name); - } - - /** - * Some checks for the getPaint() method. - */ - public void testGetPaint() { - PaintMap m1 = new PaintMap(); - assertEquals(null, m1.getPaint("A")); - m1.put("A", Color.red); - assertEquals(Color.red, m1.getPaint("A")); - m1.put("A", null); - assertEquals(null, m1.getPaint("A")); - - // a null key should throw an IllegalArgumentException - boolean pass = false; - try { - m1.getPaint(null); - } - catch (IllegalArgumentException e) { - pass = true; - } - assertTrue(pass); - } - - /** - * Some checks for the put() method. - */ - public void testPut() { - PaintMap m1 = new PaintMap(); - m1.put("A", Color.red); - assertEquals(Color.red, m1.getPaint("A")); - - // a null key should throw an IllegalArgumentException - boolean pass = false; - try { - m1.put(null, Color.blue); - } - catch (IllegalArgumentException e) { - pass = true; - } - assertTrue(pass); - } - - /** - * Some checks for the equals() method. - */ - public void testEquals() { - PaintMap m1 = new PaintMap(); - PaintMap m2 = new PaintMap(); - assertTrue(m1.equals(m1)); - assertTrue(m1.equals(m2)); - assertFalse(m1.equals(null)); - assertFalse(m1.equals("ABC")); - - m1.put("K1", Color.red); - assertFalse(m1.equals(m2)); - m2.put("K1", Color.red); - assertTrue(m1.equals(m2)); - - m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, - Color.yellow)); - assertFalse(m1.equals(m2)); - m2.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, - Color.yellow)); - assertTrue(m1.equals(m2)); - - m1.put("K2", null); - assertFalse(m1.equals(m2)); - m2.put("K2", null); - assertTrue(m1.equals(m2)); - } - - /** - * Some checks for cloning. - */ - public void testCloning() { - PaintMap m1 = new PaintMap(); - PaintMap m2 = null; - try { - m2 = (PaintMap) m1.clone(); - } - catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - assertTrue(m1.equals(m2)); - - m1.put("K1", Color.red); - m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, - Color.yellow)); - try { - m2 = (PaintMap) m1.clone(); - } - catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - assertTrue(m1.equals(m2)); - } - - /** - * A check for serialization. - */ - public void testSerialization1() { - PaintMap m1 = new PaintMap(); - PaintMap m2 = null; - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutput out = new ObjectOutputStream(buffer); - out.writeObject(m1); - out.close(); - - ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( - buffer.toByteArray())); - m2 = (PaintMap) in.readObject(); - in.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - assertEquals(m1, m2); - } - - /** - * A check for serialization. - */ - public void testSerialization2() { - PaintMap m1 = new PaintMap(); - m1.put("K1", Color.red); - m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, - Color.yellow)); - PaintMap m2 = null; - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutput out = new ObjectOutputStream(buffer); - out.writeObject(m1); - out.close(); - - ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( - buffer.toByteArray())); - m2 = (PaintMap) in.readObject(); - in.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - assertEquals(m1, m2); - } - - /** - * This test covers a bug reported in the forum: - * - * http://www.jfree.org/phpBB2/viewtopic.php?t=19980 - */ - public void testKeysOfDifferentClasses() { - PaintMap m = new PaintMap(); - m.put("ABC", Color.red); - m.put(new Integer(99), Color.blue); - assertEquals(Color.blue, m.getPaint(new Integer(99))); - } - -} - Deleted: trunk/tests/org/jfree/chart/junit/StrokeMapTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/StrokeMapTests.java 2009-06-29 13:53:27 UTC (rev 2180) +++ trunk/tests/org/jfree/chart/junit/StrokeMapTests.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -1,222 +0,0 @@ -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2008, 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.] - * - * ------------------- - * StrokeMapTests.java - * ------------------- - * (C) Copyright 2006-2008, by Object Refinery Limited. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * Changes: - * -------- - * 27-Sep-2006 : Version 1 (DG); - * - */ - -package org.jfree.chart.junit; - -import java.awt.BasicStroke; -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.chart.StrokeMap; - -/** - * Some tests for the {@link StrokeMap} class. - */ -public class StrokeMapTests extends TestCase { - - /** - * Returns the tests as a test suite. - * - * @return The test suite. - */ - public static Test suite() { - return new TestSuite(StrokeMapTests.class); - } - - /** - * Constructs a new set of tests. - * - * @param name the name of the tests. - */ - public StrokeMapTests(String name) { - super(name); - } - - /** - * Some checks for the getStroke() method. - */ - public void testGetStroke() { - StrokeMap m1 = new StrokeMap(); - assertEquals(null, m1.getStroke("A")); - m1.put("A", new BasicStroke(1.1f)); - assertEquals(new BasicStroke(1.1f), m1.getStroke("A")); - m1.put("A", null); - assertEquals(null, m1.getStroke("A")); - - // a null key should throw an IllegalArgumentException - boolean pass = false; - try { - m1.getStroke(null); - } - catch (IllegalArgumentException e) { - pass = true; - } - assertTrue(pass); - } - - /** - * Some checks for the put() method. - */ - public void testPut() { - StrokeMap m1 = new StrokeMap(); - m1.put("A", new BasicStroke(1.1f)); - assertEquals(new BasicStroke(1.1f), m1.getStroke("A")); - - // a null key should throw an IllegalArgumentException - boolean pass = false; - try { - m1.put(null, new BasicStroke(1.1f)); - } - catch (IllegalArgumentException e) { - pass = true; - } - assertTrue(pass); - } - - /** - * Some checks for the equals() method. - */ - public void testEquals() { - StrokeMap m1 = new StrokeMap(); - StrokeMap m2 = new StrokeMap(); - assertTrue(m1.equals(m1)); - assertTrue(m1.equals(m2)); - assertFalse(m1.equals(null)); - assertFalse(m1.equals("ABC")); - - m1.put("K1", new BasicStroke(1.1f)); - assertFalse(m1.equals(m2)); - m2.put("K1", new BasicStroke(1.1f)); - assertTrue(m1.equals(m2)); - - m1.put("K2", new BasicStroke(2.2f)); - assertFalse(m1.equals(m2)); - m2.put("K2", new BasicStroke(2.2f)); - assertTrue(m1.equals(m2)); - - m1.put("K2", null); - assertFalse(m1.equals(m2)); - m2.put("K2", null); - assertTrue(m1.equals(m2)); - } - - /** - * Some checks for cloning. - */ - public void testCloning() { - StrokeMap m1 = new StrokeMap(); - StrokeMap m2 = null; - try { - m2 = (StrokeMap) m1.clone(); - } - catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - assertTrue(m1.equals(m2)); - - m1.put("K1", new BasicStroke(1.1f)); - m1.put("K2", new BasicStroke(2.2f)); - try { - m2 = (StrokeMap) m1.clone(); - } - catch (CloneNotSupportedException e) { - e.printStackTrace(); - } - assertTrue(m1.equals(m2)); - } - - /** - * A check for serialization. - */ - public void testSerialization1() { - StrokeMap m1 = new StrokeMap(); - StrokeMap m2 = null; - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutput out = new ObjectOutputStream(buffer); - out.writeObject(m1); - out.close(); - - ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( - buffer.toByteArray())); - m2 = (StrokeMap) in.readObject(); - in.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - assertEquals(m1, m2); - } - - /** - * A check for serialization. - */ - public void testSerialization2() { - StrokeMap m1 = new StrokeMap(); - m1.put("K1", new BasicStroke(1.1f)); - m1.put("K2", new BasicStroke(2.2f)); - StrokeMap m2 = null; - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - ObjectOutput out = new ObjectOutputStream(buffer); - out.writeObject(m1); - out.close(); - - ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( - buffer.toByteArray())); - m2 = (StrokeMap) in.readObject(); - in.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - assertEquals(m1, m2); - } - -} - Copied: trunk/tests/org/jfree/chart/util/junit/PaintMapTests.java (from rev 2164, trunk/tests/org/jfree/chart/junit/PaintMapTests.java) =================================================================== --- trunk/tests/org/jfree/chart/util/junit/PaintMapTests.java (rev 0) +++ trunk/tests/org/jfree/chart/util/junit/PaintMapTests.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -0,0 +1,240 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * ------------------ + * PaintMapTests.java + * ------------------ + * (C) Copyright 2006-2008, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 27-Sep-2006 : Version 1 (DG); + * 17-Jan-2007 : Added testKeysOfDifferentClasses() (DG); + * + */ + +package org.jfree.chart.util.junit; + +import java.awt.Color; +import java.awt.GradientPaint; +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.chart.util.PaintMap; + +/** + * Some tests for the {@link PaintMap} class. + */ +public class PaintMapTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(PaintMapTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public PaintMapTests(String name) { + super(name); + } + + /** + * Some checks for the getPaint() method. + */ + public void testGetPaint() { + PaintMap m1 = new PaintMap(); + assertEquals(null, m1.getPaint("A")); + m1.put("A", Color.red); + assertEquals(Color.red, m1.getPaint("A")); + m1.put("A", null); + assertEquals(null, m1.getPaint("A")); + + // a null key should throw an IllegalArgumentException + boolean pass = false; + try { + m1.getPaint(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the put() method. + */ + public void testPut() { + PaintMap m1 = new PaintMap(); + m1.put("A", Color.red); + assertEquals(Color.red, m1.getPaint("A")); + + // a null key should throw an IllegalArgumentException + boolean pass = false; + try { + m1.put(null, Color.blue); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the equals() method. + */ + public void testEquals() { + PaintMap m1 = new PaintMap(); + PaintMap m2 = new PaintMap(); + assertTrue(m1.equals(m1)); + assertTrue(m1.equals(m2)); + assertFalse(m1.equals(null)); + assertFalse(m1.equals("ABC")); + + m1.put("K1", Color.red); + assertFalse(m1.equals(m2)); + m2.put("K1", Color.red); + assertTrue(m1.equals(m2)); + + m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, + Color.yellow)); + assertFalse(m1.equals(m2)); + m2.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, + Color.yellow)); + assertTrue(m1.equals(m2)); + + m1.put("K2", null); + assertFalse(m1.equals(m2)); + m2.put("K2", null); + assertTrue(m1.equals(m2)); + } + + /** + * Some checks for cloning. + */ + public void testCloning() { + PaintMap m1 = new PaintMap(); + PaintMap m2 = null; + try { + m2 = (PaintMap) m1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(m1.equals(m2)); + + m1.put("K1", Color.red); + m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, + Color.yellow)); + try { + m2 = (PaintMap) m1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(m1.equals(m2)); + } + + /** + * A check for serialization. + */ + public void testSerialization1() { + PaintMap m1 = new PaintMap(); + PaintMap m2 = null; + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(m1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + m2 = (PaintMap) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(m1, m2); + } + + /** + * A check for serialization. + */ + public void testSerialization2() { + PaintMap m1 = new PaintMap(); + m1.put("K1", Color.red); + m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, + Color.yellow)); + PaintMap m2 = null; + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(m1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + m2 = (PaintMap) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(m1, m2); + } + + /** + * This test covers a bug reported in the forum: + * + * http://www.jfree.org/phpBB2/viewtopic.php?t=19980 + */ + public void testKeysOfDifferentClasses() { + PaintMap m = new PaintMap(); + m.put("ABC", Color.red); + m.put(new Integer(99), Color.blue); + assertEquals(Color.blue, m.getPaint(new Integer(99))); + } + +} + Property changes on: trunk/tests/org/jfree/chart/util/junit/PaintMapTests.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/tests/org/jfree/chart/util/junit/StrokeMapTests.java (from rev 2164, trunk/tests/org/jfree/chart/junit/StrokeMapTests.java) =================================================================== --- trunk/tests/org/jfree/chart/util/junit/StrokeMapTests.java (rev 0) +++ trunk/tests/org/jfree/chart/util/junit/StrokeMapTests.java 2009-06-29 14:03:20 UTC (rev 2181) @@ -0,0 +1,222 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2008, 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.] + * + * ------------------- + * StrokeMapTests.java + * ------------------- + * (C) Copyright 2006-2008, by Object Refinery Limited. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes: + * -------- + * 27-Sep-2006 : Version 1 (DG); + * + */ + +package org.jfree.chart.util.junit; + +import java.awt.BasicStroke; +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.chart.util.StrokeMap; + +/** + * Some tests for the {@link StrokeMap} class. + */ +public class StrokeMapTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(StrokeMapTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public StrokeMapTests(String name) { + super(name); + } + + /** + * Some checks for the getStroke() method. + */ + public void testGetStroke() { + StrokeMap m1 = new StrokeMap(); + assertEquals(null, m1.getStroke("A")); + m1.put("A", new BasicStroke(1.1f)); + assertEquals(new BasicStroke(1.1f), m1.getStroke("A")); + m1.put("A", null); + assertEquals(null, m1.getStroke("A")); + + // a null key should throw an IllegalArgumentException + boolean pass = false; + try { + m1.getStroke(null); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the put() method. + */ + public void testPut() { + StrokeMap m1 = new StrokeMap(); + m1.put("A", new BasicStroke(1.1f)); + assertEquals(new BasicStroke(1.1f), m1.getStroke("A")); + + // a null key should throw an IllegalArgumentException + boolean pass = false; + try { + m1.put(null, new BasicStroke(1.1f)); + } + catch (IllegalArgumentException e) { + pass = true; + } + assertTrue(pass); + } + + /** + * Some checks for the equals() method. + */ + public vo... [truncated message content] |
From: <mu...@us...> - 2009-07-06 07:28:44
|
Revision: 2194 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2194&view=rev Author: mungady Date: 2009-07-06 07:28:35 +0000 (Mon, 06 Jul 2009) Log Message: ----------- Selection state updates. Modified Paths: -------------- trunk/source/org/jfree/chart/JFreeChart.java trunk/source/org/jfree/chart/RenderingSource.java trunk/source/org/jfree/chart/entity/PieSectionEntity.java trunk/source/org/jfree/chart/labels/AbstractPieItemLabelGenerator.java trunk/source/org/jfree/chart/labels/PieSectionLabelGenerator.java trunk/source/org/jfree/chart/labels/PieToolTipGenerator.java trunk/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java trunk/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java trunk/source/org/jfree/chart/panel/RegionSelectionHandler.java trunk/source/org/jfree/chart/plot/CategoryPlot.java trunk/source/org/jfree/chart/plot/MeterPlot.java trunk/source/org/jfree/chart/plot/MultiplePiePlot.java trunk/source/org/jfree/chart/plot/PiePlot.java trunk/source/org/jfree/chart/plot/PiePlot3D.java trunk/source/org/jfree/chart/plot/PolarPlot.java trunk/source/org/jfree/chart/plot/RingPlot.java trunk/source/org/jfree/chart/plot/SpiderWebPlot.java trunk/source/org/jfree/chart/plot/ThermometerPlot.java trunk/source/org/jfree/chart/plot/WaferMapPlot.java trunk/source/org/jfree/chart/plot/XYPlot.java trunk/source/org/jfree/chart/plot/dial/DialPlot.java trunk/source/org/jfree/chart/renderer/AbstractRenderer.java trunk/source/org/jfree/chart/renderer/RenderAttributes.java trunk/source/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.java trunk/source/org/jfree/chart/renderer/category/BarRenderer.java trunk/source/org/jfree/chart/renderer/category/BarRenderer3D.java trunk/source/org/jfree/chart/renderer/category/BoxAndWhiskerRenderer.java trunk/source/org/jfree/chart/renderer/category/CategoryItemRenderer.java trunk/source/org/jfree/chart/renderer/category/CategoryItemRendererState.java trunk/source/org/jfree/chart/renderer/category/LayeredBarRenderer.java trunk/source/org/jfree/chart/renderer/category/LevelRenderer.java trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java trunk/source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java trunk/source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/CandlestickRenderer.java trunk/source/org/jfree/chart/renderer/xy/DeviationRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYBlockRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYItemRenderer.java trunk/source/org/jfree/chart/renderer/xy/XYItemRendererState.java trunk/source/org/jfree/chart/urls/CustomPieURLGenerator.java trunk/source/org/jfree/chart/urls/PieURLGenerator.java trunk/source/org/jfree/chart/urls/StandardPieURLGenerator.java trunk/source/org/jfree/data/KeyedObjects.java trunk/source/org/jfree/data/category/CategoryDataset.java trunk/source/org/jfree/data/category/CategoryToPieDataset.java trunk/source/org/jfree/data/category/DefaultCategoryDataset.java trunk/source/org/jfree/data/category/DefaultIntervalCategoryDataset.java trunk/source/org/jfree/data/category/SlidingCategoryDataset.java trunk/source/org/jfree/data/gantt/SlidingGanttCategoryDataset.java trunk/source/org/jfree/data/gantt/TaskSeriesCollection.java trunk/source/org/jfree/data/gantt/XYTaskDataset.java trunk/source/org/jfree/data/general/AbstractDataset.java trunk/source/org/jfree/data/general/AbstractSeriesDataset.java trunk/source/org/jfree/data/general/DatasetChangeEvent.java trunk/source/org/jfree/data/general/DatasetUtilities.java trunk/source/org/jfree/data/general/DefaultHeatMapDataset.java trunk/source/org/jfree/data/general/DefaultKeyedValueDataset.java trunk/source/org/jfree/data/general/DefaultKeyedValuesDataset.java trunk/source/org/jfree/data/general/DefaultValueDataset.java trunk/source/org/jfree/data/general/KeyedValuesDataset.java trunk/source/org/jfree/data/jdbc/JDBCCategoryDataset.java trunk/source/org/jfree/data/jdbc/JDBCPieDataset.java trunk/source/org/jfree/data/jdbc/JDBCXYDataset.java trunk/source/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDataset.java trunk/source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java trunk/source/org/jfree/data/statistics/DefaultMultiValueCategoryDataset.java trunk/source/org/jfree/data/statistics/DefaultStatisticalCategoryDataset.java trunk/source/org/jfree/data/statistics/HistogramDataset.java trunk/source/org/jfree/data/statistics/SimpleHistogramDataset.java trunk/source/org/jfree/data/time/TimePeriodValuesCollection.java trunk/source/org/jfree/data/time/TimeSeriesCollection.java trunk/source/org/jfree/data/time/TimeTableXYDataset.java trunk/source/org/jfree/data/time/ohlc/OHLCSeriesCollection.java trunk/source/org/jfree/data/xml/DatasetReader.java trunk/source/org/jfree/data/xml/PieDatasetHandler.java trunk/source/org/jfree/data/xy/AbstractXYDataset.java trunk/source/org/jfree/data/xy/CategoryTableXYDataset.java trunk/source/org/jfree/data/xy/DefaultHighLowDataset.java trunk/source/org/jfree/data/xy/DefaultIntervalXYDataset.java trunk/source/org/jfree/data/xy/DefaultTableXYDataset.java trunk/source/org/jfree/data/xy/DefaultXYDataset.java trunk/source/org/jfree/data/xy/DefaultXYZDataset.java trunk/source/org/jfree/data/xy/MatrixSeriesCollection.java trunk/source/org/jfree/data/xy/VectorSeriesCollection.java trunk/source/org/jfree/data/xy/XIntervalSeriesCollection.java trunk/source/org/jfree/data/xy/XYBarDataset.java trunk/source/org/jfree/data/xy/XYIntervalSeriesCollection.java trunk/source/org/jfree/data/xy/XYSeriesCollection.java trunk/source/org/jfree/data/xy/YIntervalSeriesCollection.java trunk/tests/org/jfree/chart/entity/junit/PieSectionEntityTests.java trunk/tests/org/jfree/chart/entity/junit/StandardEntityCollectionTests.java trunk/tests/org/jfree/chart/junit/JFreeChartTests.java trunk/tests/org/jfree/chart/junit/PieChart3DTests.java trunk/tests/org/jfree/chart/junit/PieChartTests.java trunk/tests/org/jfree/chart/plot/junit/MultiplePiePlotTests.java trunk/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java trunk/tests/org/jfree/chart/plot/junit/RingPlotTests.java trunk/tests/org/jfree/chart/renderer/category/junit/BoxAndWhiskerRendererTests.java trunk/tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java trunk/tests/org/jfree/data/category/junit/CategoryToPieDatasetTests.java trunk/tests/org/jfree/data/category/junit/DefaultCategoryDatasetTests.java trunk/tests/org/jfree/data/general/junit/DatasetUtilitiesTests.java trunk/tests/org/jfree/data/general/junit/DefaultPieDatasetTests.java trunk/tests/org/jfree/data/junit/KeyedObjectTests.java trunk/tests/org/jfree/data/junit/KeyedObjectsTests.java Modified: trunk/source/org/jfree/chart/JFreeChart.java =================================================================== --- trunk/source/org/jfree/chart/JFreeChart.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/JFreeChart.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -1406,6 +1406,9 @@ int imageType, ChartRenderingInfo info) { BufferedImage image = new BufferedImage(width, height, imageType); + if (info != null) { + info.setRenderingSource(new BufferedImageRenderingSource(image)); + } Graphics2D g2 = image.createGraphics(); draw(g2, new Rectangle2D.Double(0, 0, width, height), null, info); g2.dispose(); Modified: trunk/source/org/jfree/chart/RenderingSource.java =================================================================== --- trunk/source/org/jfree/chart/RenderingSource.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/RenderingSource.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -40,6 +40,7 @@ package org.jfree.chart; +import java.awt.Graphics2D; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetSelectionState; @@ -50,6 +51,8 @@ */ public interface RenderingSource { + public Graphics2D createGraphics2D(); + /** * Returns the selection state, if any, that this source is maintaining * for the specified dataset. Modified: trunk/source/org/jfree/chart/entity/PieSectionEntity.java =================================================================== --- trunk/source/org/jfree/chart/entity/PieSectionEntity.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/entity/PieSectionEntity.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -58,7 +58,7 @@ import org.jfree.chart.util.HashUtilities; import org.jfree.chart.util.ObjectUtilities; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A chart entity that represents one section within a pie plot. Modified: trunk/source/org/jfree/chart/labels/AbstractPieItemLabelGenerator.java =================================================================== --- trunk/source/org/jfree/chart/labels/AbstractPieItemLabelGenerator.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/labels/AbstractPieItemLabelGenerator.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -50,7 +50,7 @@ import org.jfree.chart.util.HashUtilities; import org.jfree.data.general.DatasetUtilities; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A base class used for generating pie chart item labels. Modified: trunk/source/org/jfree/chart/labels/PieSectionLabelGenerator.java =================================================================== --- trunk/source/org/jfree/chart/labels/PieSectionLabelGenerator.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/labels/PieSectionLabelGenerator.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -58,7 +58,7 @@ import java.awt.font.TextAttribute; import java.text.AttributedString; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * Interface for a label generator for plots that use data from Modified: trunk/source/org/jfree/chart/labels/PieToolTipGenerator.java =================================================================== --- trunk/source/org/jfree/chart/labels/PieToolTipGenerator.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/labels/PieToolTipGenerator.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -40,7 +40,7 @@ package org.jfree.chart.labels; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A tool tip generator that is used by the Modified: trunk/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java =================================================================== --- trunk/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/labels/StandardPieSectionLabelGenerator.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -57,7 +57,7 @@ import org.jfree.chart.util.ObjectList; import org.jfree.chart.util.PublicCloneable; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A standard item label generator for plots that use data from a Modified: trunk/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java =================================================================== --- trunk/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/labels/StandardPieToolTipGenerator.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -63,7 +63,7 @@ import java.util.Locale; import org.jfree.chart.util.PublicCloneable; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A standard item label generator for plots that use data from a Modified: trunk/source/org/jfree/chart/panel/RegionSelectionHandler.java =================================================================== --- trunk/source/org/jfree/chart/panel/RegionSelectionHandler.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/panel/RegionSelectionHandler.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -176,19 +176,26 @@ */ public void mousePressed(MouseEvent e) { ChartPanel panel = (ChartPanel) e.getSource(); + JFreeChart chart = panel.getChart(); + if (chart == null) { + return; + } + if (!(chart.getPlot() instanceof Selectable)) { + return; + } + Selectable s = (Selectable) chart.getPlot(); + if (!s.canSelectByRegion()) { + return; + } Rectangle2D dataArea = panel.getScreenDataArea(); if (dataArea.contains(e.getPoint())) { - JFreeChart chart = panel.getChart(); - if (chart.getPlot() instanceof Selectable) { - Selectable s = (Selectable) chart.getPlot(); - if (!e.isShiftDown()) { - s.clearSelection(); - chart.setNotify(true); - } - Point pt = e.getPoint(); - this.selection.moveTo((float) pt.getX(), (float) pt.getY()); - this.lastPoint = new Point(pt); + if (!e.isShiftDown()) { + s.clearSelection(); + chart.setNotify(true); } + Point pt = e.getPoint(); + this.selection.moveTo((float) pt.getX(), (float) pt.getY()); + this.lastPoint = new Point(pt); } } @@ -251,6 +258,7 @@ * @param e the event. */ public void mouseClicked(MouseEvent e) { + System.out.println("mouseClicked(): " + e); ChartPanel panel = (ChartPanel) e.getSource(); Rectangle2D dataArea = panel.getScreenDataArea(); if (dataArea.contains(e.getPoint())) { Modified: trunk/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/CategoryPlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/CategoryPlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -188,6 +188,7 @@ import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; +import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -209,6 +210,7 @@ import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; +import org.jfree.chart.RenderingSource; import org.jfree.chart.annotations.CategoryAnnotation; import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.AxisCollection; @@ -221,10 +223,10 @@ import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.axis.ValueTick; import org.jfree.chart.event.ChartChangeEventType; +import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; import org.jfree.chart.event.RendererChangeListener; -import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.CategoryItemRendererState; import org.jfree.chart.util.Layer; @@ -240,6 +242,8 @@ import org.jfree.chart.util.SortOrder; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; +import org.jfree.data.category.CategoryDatasetSelectionState; +import org.jfree.data.category.SelectableCategoryDataset; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; @@ -249,8 +253,8 @@ * renders each data item using a {@link CategoryItemRenderer}. */ public class CategoryPlot extends Plot implements ValueAxisPlot, Pannable, - Zoomable, RendererChangeListener, Cloneable, PublicCloneable, - Serializable { + Selectable, Zoomable, RendererChangeListener, Cloneable, + PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -3537691700434728188L; @@ -1336,7 +1340,9 @@ } // send a dataset change event to self... - DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); + DatasetChangeEvent event = new DatasetChangeEvent(this, dataset, + new DatasetChangeInfo()); + // TODO: fill in real dataset change info datasetChanged(event); } @@ -1405,7 +1411,9 @@ Integer key = new Integer(index); this.datasetToDomainAxesMap.put(key, new ArrayList(axisIndices)); // fake a dataset change event to update axes... - datasetChanged(new DatasetChangeEvent(this, getDataset(index))); + datasetChanged(new DatasetChangeEvent(this, getDataset(index), + new DatasetChangeInfo())); + // TODO: fill in real dataset change info } /** @@ -1500,7 +1508,10 @@ Integer key = new Integer(index); this.datasetToRangeAxesMap.put(key, new ArrayList(axisIndices)); // fake a dataset change event to update axes... - datasetChanged(new DatasetChangeEvent(this, getDataset(index))); + datasetChanged(new DatasetChangeEvent(this, getDataset(index), + new DatasetChangeInfo())); + + // TODO: fill in real dataset change info } /** @@ -3864,7 +3875,8 @@ foundData = true; CategoryItemRendererState state = renderer.initialise(g2, dataArea, - this, index, info); + this, currentDataset, info); + CategoryDatasetSelectionState selectionState = state.getSelectionState(); state.setCrosshairState(crosshairState); int columnCount = currentDataset.getColumnCount(); int rowCount = currentDataset.getRowCount(); @@ -3874,16 +3886,26 @@ for (int column = 0; column < columnCount; column++) { if (this.rowRenderingOrder == SortOrder.ASCENDING) { for (int row = 0; row < rowCount; row++) { + boolean selected = false; + if (selectionState != null) { + selected = selectionState.isSelected(row, + column); + } renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, false, pass); + row, column, selected, pass); } } else { for (int row = rowCount - 1; row >= 0; row--) { + boolean selected = false; + if (selectionState != null) { + selected = selectionState.isSelected(row, + column); + } renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, false, pass); + row, column, selected, pass); } } } @@ -3892,16 +3914,26 @@ for (int column = columnCount - 1; column >= 0; column--) { if (this.rowRenderingOrder == SortOrder.ASCENDING) { for (int row = 0; row < rowCount; row++) { + boolean selected = false; + if (selectionState != null) { + selected = selectionState.isSelected(row, + column); + } renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, false, pass); + row, column, selected, pass); } } else { for (int row = rowCount - 1; row >= 0; row--) { + boolean selected = false; + if (selectionState != null) { + selected = selectionState.isSelected(row, + column); + } renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, - row, column, false, pass); + row, column, selected, pass); } } } @@ -5107,4 +5139,133 @@ } + /** + * Returns <code>true</code> if the plot supports selection by point, + * and <code>false</code> otherwise. + * + * @return A boolean. + * + * @since 1.2.0 + */ + public boolean canSelectByPoint() { + return true; + } + + /** + * Returns <code>true</code> if the plot supports selection by region, + * and <code>false</code> otherwise. + * + * @return A boolean. + * + * @since 1.2.0 + */ + public boolean canSelectByRegion() { + return true; + } + + /** + * Perform a select for the item(s) at the specified (x, y) coordinates + * in Java2D space. + * + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param dataArea the data area. + * @param source the rendering source. + * + * @since 1.2.0 + */ + public void select(double x, double y, Rectangle2D dataArea, + RenderingSource source) { + + int datasetCount = this.datasets.size(); + for (int d = 0; d < datasetCount; d++) { + CategoryDataset dataset = (CategoryDataset) this.datasets.get(d); + if (dataset == null) { + continue; + } + CategoryDatasetSelectionState state = findSelectionStateForDataset( + dataset, source); + if (state == null) { + continue; + } + Graphics2D g2 = source.createGraphics2D(); + CategoryItemRenderer renderer = getRendererForDataset(dataset); + CategoryItemRendererState rs = renderer.initialise(g2, dataArea, + this, dataset, null); + int rowCount = dataset.getRowCount(); + int columnCount = dataset.getColumnCount(); + for (int r = 0; r < rowCount; r++) { + for (int c = 0; c < columnCount; c++) { + if (renderer.hitTest(x, y, null, dataArea, this, + getDomainAxisForDataset(d), + getRangeAxisForDataset(d), dataset, r, c, false, + rs)) { + state.setSelected(r, c, !state.isSelected(r, c)); + } + } + } + } + } + + /** + * Perform a select for the item(s) within the specified region + * in Java2D space. + * + * @param region the region. + * @param dataArea the data area. + * @param source the rendering source. + * + * @since 1.2.0 + */ + public void select(GeneralPath region, Rectangle2D dataArea, + RenderingSource source) { + System.out.println(region); + System.out.println("Select a region..."); + } + + /** + * Clears the selection. + * + * @since 1.2.0 + */ + public void clearSelection() { + // cycle through the datasets and clear the selection state + int datasetCount = this.datasets.size(); + for (int d = 0; d < datasetCount; d++) { + CategoryDataset dataset = (CategoryDataset) this.datasets.get(d); + if (dataset instanceof SelectableCategoryDataset) { + // FIXME: actually, we need to get the selection state + // taking into account the rendering source + SelectableCategoryDataset scd + = (SelectableCategoryDataset) dataset; + if (scd.getSelectionState() != null) { + CategoryDatasetSelectionState selState + = scd.getSelectionState(); + selState.clearSelection(); + } + } + } + } + + + /** + * Returns the selection state for the specified dataset. This could be + * <code>null</code> if the dataset hasn't been set up to support + * selections. + * + * @param dataset the dataset. + * @param source the selection source. + * + * @return The selection state (possibly <code>null</code>). + */ + private CategoryDatasetSelectionState findSelectionStateForDataset( + CategoryDataset dataset, Object source) { + if (dataset instanceof SelectableCategoryDataset) { + SelectableCategoryDataset sd = (SelectableCategoryDataset) dataset; + CategoryDatasetSelectionState s = sd.getSelectionState(); + return s; + } + throw new RuntimeException(); + //return null; // TODO: implement + } } Modified: trunk/source/org/jfree/chart/plot/MeterPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/MeterPlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/MeterPlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -113,6 +113,7 @@ import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; +import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.text.TextAnchor; import org.jfree.chart.text.TextUtilities; @@ -725,7 +726,9 @@ } // send a dataset change event to self... - DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); + DatasetChangeEvent event = new DatasetChangeEvent(this, dataset, + new DatasetChangeInfo()); + // TODO: fill in change type datasetChanged(event); } Modified: trunk/source/org/jfree/chart/plot/MultiplePiePlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/MultiplePiePlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/MultiplePiePlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -80,6 +80,7 @@ import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; +import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.title.TextTitle; import org.jfree.chart.util.ObjectUtilities; @@ -93,7 +94,7 @@ import org.jfree.data.category.CategoryToPieDataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A plot that displays multiple pie plots using data from a @@ -205,7 +206,9 @@ } // send a dataset change event to self to trigger plot change event - datasetChanged(new DatasetChangeEvent(this, dataset)); + datasetChanged(new DatasetChangeEvent(this, dataset, + new DatasetChangeInfo())); + // TODO: fill in real dataset change type } /** @@ -525,7 +528,7 @@ // column keys provide potential keys for individual pies for (int c = 0; c < this.dataset.getColumnCount(); c++) { Comparable key = this.dataset.getColumnKey(c); - Paint p = piePlot.getSectionPaint(key); + Paint p = piePlot.getSectionPaint(key, false); if (p == null) { p = (Paint) this.sectionPaints.get(key); if (p == null) { @@ -539,7 +542,7 @@ // row keys provide potential keys for individual pies for (int r = 0; r < this.dataset.getRowCount(); r++) { Comparable key = this.dataset.getRowKey(r); - Paint p = piePlot.getSectionPaint(key); + Paint p = piePlot.getSectionPaint(key, false); if (p == null) { p = (Paint) this.sectionPaints.get(key); if (p == null) { Modified: trunk/source/org/jfree/chart/plot/PiePlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/PiePlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/PiePlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -181,6 +181,7 @@ import java.awt.geom.Arc2D; import java.awt.geom.CubicCurve2D; import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.QuadCurve2D; @@ -197,6 +198,7 @@ import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; +import org.jfree.chart.RenderingSource; import org.jfree.chart.util.PaintMap; import org.jfree.chart.util.StrokeMap; import org.jfree.chart.entity.EntityCollection; @@ -225,7 +227,11 @@ import org.jfree.data.KeyedValues; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; +import org.jfree.data.pie.PieDatasetChangeInfo; +import org.jfree.data.pie.PieDatasetChangeType; +import org.jfree.data.pie.PieDatasetSelectionState; +import org.jfree.data.pie.SelectablePieDataset; /** * A plot that displays data in the form of a pie chart, using data from any @@ -243,7 +249,8 @@ * @see Plot * @see PieDataset */ -public class PiePlot extends Plot implements Cloneable, Serializable { +public class PiePlot extends Plot implements Selectable, Cloneable, + Serializable { /** For serialization. */ private static final long serialVersionUID = -795612466005590431L; @@ -504,6 +511,13 @@ "org.jfree.chart.plot.LocalizationBundle"); /** + * Override attributes for selected items. + * + * @since 1.2.0 + */ + private PieSelectionAttributes selectedItemAttributes; + + /** * This debug flag controls whether or not an outline is drawn showing the * interior of the plot region. This is drawn as a lightGray rectangle * showing the padding provided by the 'interiorGap' setting. @@ -588,6 +602,7 @@ this.ignoreNullValues = false; this.ignoreZeroValues = false; + this.selectedItemAttributes = new PieSelectionAttributes(); } /** @@ -624,7 +639,8 @@ } // send a dataset change event to self... - DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); + DatasetChangeEvent event = new DatasetChangeEvent(this, dataset, + new PieDatasetChangeInfo(PieDatasetChangeType.UPDATE, -1, -1)); datasetChanged(event); } @@ -847,15 +863,24 @@ * <code>lookupSectionPaint(section, getAutoPopulateSectionPaint())</code>. * * @param key the section key. + * @param selected is the section selected? * * @return The paint for the specified section. * - * @since 1.0.3 + * @since 1.2.0 * * @see #lookupSectionPaint(Comparable, boolean) */ - protected Paint lookupSectionPaint(Comparable key) { - return lookupSectionPaint(key, getAutoPopulateSectionPaint()); + protected Paint lookupSectionPaint(Comparable key, boolean selected) { + Paint result = null; + if (selected) { + result = this.selectedItemAttributes.lookupSectionPaint(key); + } + if (result == null) { + result = lookupSectionPaint(key, selected, + getAutoPopulateSectionPaint()); + } + return result; } /** @@ -877,9 +902,14 @@ * * @return The paint. * - * @since 1.0.3 + * @since 1.2.0 */ - protected Paint lookupSectionPaint(Comparable key, boolean autoPopulate) { + protected Paint lookupSectionPaint(Comparable key, boolean selected, + boolean autoPopulate) { + + if (selected) { + // return Color.WHITE; + } Paint result = null; // is a paint defined for the specified key @@ -946,10 +976,13 @@ * * @see #setSectionPaint(Comparable, Paint) * - * @since 1.0.3 + * @since 1.2.0 */ - public Paint getSectionPaint(Comparable key) { + public Paint getSectionPaint(Comparable key, boolean selected) { // null argument check delegated... + if (selected) { + return Color.white; + } return this.sectionPaintMap.getPaint(key); } @@ -1081,16 +1114,25 @@ * getAutoPopulateSectionOutlinePaint())</code>. * * @param key the section key. + * @param selected is the section selected? * * @return The paint for the specified section. * - * @since 1.0.3 + * @since 1.2.0 * * @see #lookupSectionOutlinePaint(Comparable, boolean) */ - protected Paint lookupSectionOutlinePaint(Comparable key) { - return lookupSectionOutlinePaint(key, + protected Paint lookupSectionOutlinePaint(Comparable key, + boolean selected) { + Paint result = null; + if (selected) { + result = this.selectedItemAttributes.lookupSectionOutlinePaint(key); + } + if (result == null) { + result = lookupSectionOutlinePaint(key, selected, getAutoPopulateSectionOutlinePaint()); + } + return result; } /** @@ -1107,18 +1149,22 @@ * </ul> * * @param key the section key. + * @param selected is the section selected? * @param autoPopulate a flag that controls whether the drawing supplier * is used to auto-populate the section outline paint settings. * * @return The paint. * - * @since 1.0.3 + * @since 1.2.0 */ - protected Paint lookupSectionOutlinePaint(Comparable key, + protected Paint lookupSectionOutlinePaint(Comparable key, boolean selected, boolean autoPopulate) { Paint result = null; + if (selected) { + return Color.WHITE; + } // is a paint defined for the specified key result = this.sectionOutlinePaintMap.getPaint(key); if (result != null) { @@ -1264,16 +1310,25 @@ * getAutoPopulateSectionOutlineStroke())</code>. * * @param key the section key. + * @param selected is the section selected? * * @return The stroke for the specified section. * - * @since 1.0.3 + * @since 1.2.0 * * @see #lookupSectionOutlineStroke(Comparable, boolean) */ - protected Stroke lookupSectionOutlineStroke(Comparable key) { - return lookupSectionOutlineStroke(key, + protected Stroke lookupSectionOutlineStroke(Comparable key, + boolean selected) { + Stroke s = null; + if (selected) { + s = this.selectedItemAttributes.lookupSectionOutlineStroke(key); + } + if (s == null) { + s = lookupSectionOutlineStroke(key, selected, getAutoPopulateSectionOutlineStroke()); + } + return s; } /** @@ -1290,15 +1345,16 @@ * </ul> * * @param key the section key. + * @param selected is the section selected? * @param autoPopulate a flag that controls whether the drawing supplier * is used to auto-populate the section outline stroke settings. * * @return The stroke. * - * @since 1.0.3 + * @since 1.2.0 */ protected Stroke lookupSectionOutlineStroke(Comparable key, - boolean autoPopulate) { + boolean selected, boolean autoPopulate) { Stroke result = null; @@ -2344,17 +2400,10 @@ } - /** - * Draws the pie. - * - * @param g2 the graphics device. - * @param plotArea the plot area. - * @param info chart rendering info. - */ - protected void drawPie(Graphics2D g2, Rectangle2D plotArea, - PlotRenderingInfo info) { + private Rectangle2D[] calculateLinkAndExplodeAreas(Graphics2D g2, + Rectangle2D plotArea) { - PiePlotState state = initialise(g2, plotArea, this, null, info); + Rectangle2D[] result = new Rectangle2D[2]; // adjust the plot area for interior spacing and labels... double labelReserve = 0.0; @@ -2365,7 +2414,6 @@ + labelReserve) * 2.0; double gapVertical = plotArea.getHeight() * this.interiorGap * 2.0; - if (DEBUG_DRAW_INTERIOR) { double hGap = plotArea.getWidth() * this.interiorGap; double vGap = plotArea.getHeight() * this.interiorGap; @@ -2397,7 +2445,7 @@ // the labels Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW, linkH); - state.setLinkArea(linkArea); + result[0] = linkArea; if (DEBUG_DRAW_LINK_AREA) { g2.setPaint(Color.blue); @@ -2418,7 +2466,26 @@ double vv = linkArea.getHeight() * lm * 2.0; Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0, linkY + vv / 2.0, linkW - hh, linkH - vv); + result[1] = explodeArea; + return result; + } + /** + * Draws the pie. + * + * @param g2 the graphics device. + * @param plotArea the plot area. + * @param info chart rendering info. + */ + protected void drawPie(Graphics2D g2, Rectangle2D plotArea, + PlotRenderingInfo info) { + + PiePlotState state = initialise(g2, plotArea, this, null, info); + + Rectangle2D[] areas = calculateLinkAndExplodeAreas(g2, plotArea); + Rectangle2D linkArea = areas[0]; + Rectangle2D explodeArea = areas[1]; + state.setLinkArea(linkArea); state.setExplodedPieArea(explodeArea); // the pie area defines the circle/ellipse for regular pie sections. @@ -2446,6 +2513,8 @@ // plot the data (unless the dataset is null)... if ((this.dataset != null) && (this.dataset.getKeys().size() > 0)) { + PieDatasetSelectionState ss = findSelectionStateForDataset( + this.dataset, state); List keys = this.dataset.getKeys(); double totalValue = DatasetUtilities.calculatePieDatasetTotal( this.dataset); @@ -2459,7 +2528,12 @@ double value = n.doubleValue(); if (value > 0.0) { runningTotal += value; - drawItem(g2, section, explodeArea, state, pass); + boolean selected = false; + if (ss != null) { + selected = ss.isSelected(this.dataset.getKey(section)); + } + drawItem(g2, section, selected, explodeArea, state, + pass); } } } @@ -2483,12 +2557,13 @@ * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. + * @param selected is the item selected? * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ - protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, - PiePlotState state, int currentPass) { + protected void drawItem(Graphics2D g2, int section, boolean selected, + Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { @@ -2533,17 +2608,21 @@ } else if (currentPass == 1) { Comparable key = getSectionKey(section); - Paint paint = lookupSectionPaint(key); + Paint paint = lookupSectionPaint(key, selected); + Shape savedClip = g2.getClip(); + g2.clip(arc); g2.setPaint(paint); g2.fill(arc); - Paint outlinePaint = lookupSectionOutlinePaint(key); - Stroke outlineStroke = lookupSectionOutlineStroke(key); + Paint outlinePaint = lookupSectionOutlinePaint(key, selected); + Stroke outlineStroke = lookupSectionOutlineStroke(key, + selected); if (this.sectionOutlinesVisible) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); } + g2.setClip(savedClip); // update the linking line target for later // add an entity for the pie section @@ -2896,9 +2975,10 @@ urlText = this.legendLabelURLGenerator.generateURL( this.dataset, key, this.pieIndex); } - Paint paint = lookupSectionPaint(key); - Paint outlinePaint = lookupSectionOutlinePaint(key); - Stroke outlineStroke = lookupSectionOutlineStroke(key); + Paint paint = lookupSectionPaint(key, false); + Paint outlinePaint = lookupSectionOutlinePaint(key, false); + Stroke outlineStroke = lookupSectionOutlineStroke(key, + false); LegendItem item = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, true, outlinePaint, outlineStroke, @@ -3068,6 +3148,226 @@ } /** + * Returns the selection state for the specified dataset. This could be + * <code>null</code> if the dataset hasn't been set up to support + * selections. + * + * @param dataset the dataset. + * @param source the selection source. + * + * @return The selection state (possibly <code>null</code>). + */ + private PieDatasetSelectionState findSelectionStateForDataset( + PieDataset dataset, Object source) { + if (dataset instanceof SelectablePieDataset) { + SelectablePieDataset sd = (SelectablePieDataset) dataset; + PieDatasetSelectionState s = sd.getSelectionState(); + return s; + } + throw new RuntimeException(); + //return null; // TODO: implement + } + + /** + * Returns <code>true</code> to indicate that the plot supports selection + * by clicking on a point. + * + * @return <code>true</code>. + * + * @since 1.2.0 + */ + public boolean canSelectByPoint() { + return true; + } + + /** + * Returns <code>false</code> to indicate that the plot does not support + * selection by region. + * + * @return <code>false</code>. + * + * @since 1.2.0 + */ + public boolean canSelectByRegion() { + return false; + } + + /** + * Selects a data item. + * + * @param x + * @param y + * @param dataArea + * @param source + */ + public void select(double x, double y, Rectangle2D dataArea, + RenderingSource source) { + + System.out.println("select " + x + ", " + y); + + PieDatasetSelectionState state = findSelectionStateForDataset( + dataset, source); + if (state == null) { + return; + } + + Rectangle2D[] areas = calculateLinkAndExplodeAreas(null, dataArea); + Rectangle2D linkArea = areas[0]; + Rectangle2D explodeArea = areas[1]; + + // the pie area defines the circle/ellipse for regular pie sections. + // it is defined by shrinking the explodeArea by the explodeMargin + // factor. + double maximumExplodePercent = getMaximumExplodePercent(); + double percent = maximumExplodePercent / (1.0 + maximumExplodePercent); + + double h1 = explodeArea.getWidth() * percent; + double v1 = explodeArea.getHeight() * percent; + Rectangle2D pieArea = new Rectangle2D.Double(explodeArea.getX() + + h1 / 2.0, explodeArea.getY() + v1 / 2.0, + explodeArea.getWidth() - h1, explodeArea.getHeight() - v1); + + // plot the data (unless the dataset is null)... + if ((this.dataset != null) && (this.dataset.getKeys().size() > 0)) { + + + List keys = this.dataset.getKeys(); + double total = DatasetUtilities.calculatePieDatasetTotal( + this.dataset); + double runningTotal = 0.0; + for (int section = 0; section < keys.size(); section++) { + Number n = this.dataset.getValue(section); + if (n == null) { + continue; + } + double value = n.doubleValue(); + if (value > 0.0) { + double angle0 = calculateAngleForValue(runningTotal, + total); + double angle1 = calculateAngleForValue(runningTotal + + value, total); + runningTotal += value; + System.out.println(this.dataset.getValue(section)); + System.out.println(angle0); + System.out.println(angle1); + double angle = (angle1 - angle0); + if (Math.abs(angle) > getMinimumArcAngleToDraw()) { + double ep = 0.0; + double mep = getMaximumExplodePercent(); + if (mep > 0.0) { + ep = getExplodePercent(getSectionKey(section)) / mep; + } + Rectangle2D arcBounds = getArcBounds(pieArea, + explodeArea, angle0, angle, ep); + Arc2D.Double arc = new Arc2D.Double(arcBounds, + angle0, angle, Arc2D.PIE); + if (arc.contains(x, y)) { + Comparable key = this.dataset.getKey(section); + state.setSelected(key, !state.isSelected(key)); + System.out.println(key + " is " + state.isSelected(key)); + } + } + } + } + } + } + + private double calculateAngleForValue(double value, double total) { + if (this.direction == Rotation.CLOCKWISE) { + return this.startAngle - (value / total * 360.0); + } + else if (this.direction == Rotation.ANTICLOCKWISE) { + return this.startAngle + (value / total * 360.0); + } + throw new RuntimeException("Unrecognised Rotation type."); + } + + /** + * This method does nothing, because this plot does not support + * selection by region. + * + * @param region ignored. + * @param dataArea ignored. + * @param source ignored. + * + * @see #canSelectByRegion() + * + * @since 1.2.0 + */ + public void select(GeneralPath region, Rectangle2D dataArea, + RenderingSource source) { + // operation not supported + } + + /** + * Clears the selection. + * + * @since 1.2.0 + */ + public void clearSelection() { + System.out.println("Clear selection."); + } + + /** + * Returns a shape representing the hotspot for a pie section. + * + * @param g2 the graphics device. + * @param dataArea the area within which the data is being rendered. + * @param selected is the item selected? + * + * @return A shape equal to the hot spot for a data item. + */ + public Shape createHotSpotShape(Graphics2D g2, Rectangle2D dataArea, + int section, boolean selected) { + + Number n = this.dataset.getValue(section); + if (n == null) { + return null; + } + double value = n.doubleValue(); + double angle1 = 0.0; + double angle2 = 0.0; + + double total = DatasetUtilities.calculatePieDatasetTotal(this.dataset); + double lead = 0.0; + if (this.direction == Rotation.CLOCKWISE) { + for (int i = 0; i < section; i++) { + n = this.dataset.getValue(i); + if (n != null) { + value = n.doubleValue(); + if (value >= 0.0) { + lead = lead + value; + } + } + } + angle1 = getStartAngle() - lead / total * 360.0; + angle2 = angle1 - value / total * 360.0; + } + else if (this.direction == Rotation.ANTICLOCKWISE) { + angle1 = getStartAngle() + lead / total * 360.0; + angle2 = angle1 + value / total * 360.0; + } + else { + throw new IllegalStateException("Rotation type not recognised."); + } + + double angle = (angle2 - angle1); + if (Math.abs(angle) > getMinimumArcAngleToDraw()) { + double ep = 0.0; + double mep = getMaximumExplodePercent(); + if (mep > 0.0) { + ep = getExplodePercent(getSectionKey(section)) / mep; + } + Rectangle2D arcBounds = getArcBounds(dataArea, + dataArea, angle1, angle, ep); + Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, + Arc2D.PIE); + return arc; + } + return null; + } + + /** * Tests this plot for equality with an arbitrary object. Note that the * plot's dataset is NOT included in the test for equality. * @@ -3122,9 +3422,8 @@ that.sectionOutlinePaintMap)) { return false; } - if (!PaintUtilities.equal( - this.baseSectionOutlinePaint, that.baseSectionOutlinePaint - )) { + if (!PaintUtilities.equal(this.baseSectionOutlinePaint, + that.baseSectionOutlinePaint)) { return false; } if (!ObjectUtilities.equal(this.sectionOutlineStrokeMap, @@ -3327,4 +3626,7 @@ this.legendItemShape = SerialUtilities.readShape(stream); } + public PieSelectionAttributes getSelectedItemAttributes() { + return this.selectedItemAttributes; + } } Modified: trunk/source/org/jfree/chart/plot/PiePlot3D.java =================================================================== --- trunk/source/org/jfree/chart/plot/PiePlot3D.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/PiePlot3D.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -110,7 +110,7 @@ import org.jfree.chart.labels.PieToolTipGenerator; import org.jfree.chart.util.RectangleInsets; import org.jfree.data.general.DatasetUtilities; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A plot that displays data in the form of a 3D pie chart, using data from @@ -462,9 +462,9 @@ continue; } Comparable key = getSectionKey(categoryIndex); - paint = lookupSectionPaint(key); - outlinePaint = lookupSectionOutlinePaint(key); - outlineStroke = lookupSectionOutlineStroke(key); + paint = lookupSectionPaint(key, false); + outlinePaint = lookupSectionOutlinePaint(key, false); + outlineStroke = lookupSectionOutlineStroke(key, false); g2.setPaint(paint); g2.fill(arc); g2.setPaint(outlinePaint); @@ -500,9 +500,9 @@ Arc2D segment = (Arc2D) iterator.next(); if (segment != null) { Comparable key = getSectionKey(cat); - paint = lookupSectionPaint(key); - outlinePaint = lookupSectionOutlinePaint(key); - outlineStroke = lookupSectionOutlineStroke(key); + paint = lookupSectionPaint(key, false); + outlinePaint = lookupSectionOutlinePaint(key, false); + outlineStroke = lookupSectionOutlineStroke(key, false); drawSide(g2, pieArea, segment, front, back, paint, outlinePaint, outlineStroke, false, true); } @@ -516,9 +516,9 @@ Arc2D segment = (Arc2D) iterator.next(); if (segment != null) { Comparable key = getSectionKey(cat); - paint = lookupSectionPaint(key); - outlinePaint = lookupSectionOutlinePaint(key); - outlineStroke = lookupSectionOutlineStroke(key); + paint = lookupSectionPaint(key, false); + outlinePaint = lookupSectionOutlinePaint(key, false); + outlineStroke = lookupSectionOutlineStroke(key, false); drawSide(g2, pieArea, segment, front, back, paint, outlinePaint, outlineStroke, true, false); } @@ -541,8 +541,8 @@ Comparable currentKey = (Comparable) sectionKeys.get(sectionIndex); paint = lookupSectionPaint(currentKey, true); - outlinePaint = lookupSectionOutlinePaint(currentKey); - outlineStroke = lookupSectionOutlineStroke(currentKey); + outlinePaint = lookupSectionOutlinePaint(currentKey, false); + outlineStroke = lookupSectionOutlineStroke(currentKey, false); g2.setPaint(paint); g2.fill(upperArc); g2.setStroke(outlineStroke); Modified: trunk/source/org/jfree/chart/plot/PolarPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/PolarPlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/PolarPlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -81,6 +81,7 @@ import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.axis.TickUnit; import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; import org.jfree.chart.event.RendererChangeListener; @@ -349,15 +350,17 @@ existing.removeChangeListener(this); } - // set the new m_Dataset, and register the chart as a change listener... + // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (this.dataset != null) { setDatasetGroup(this.dataset.getGroup()); this.dataset.addChangeListener(this); } - // send a m_Dataset change event to self... - DatasetChangeEvent event = new DatasetChangeEvent(this, this.dataset); + // send a dataset change event to self... + DatasetChangeEvent event = new DatasetChangeEvent(this, this.dataset, + new DatasetChangeInfo()); + // TODO: fill in real dataset change type datasetChanged(event); } Modified: trunk/source/org/jfree/chart/plot/RingPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/RingPlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/RingPlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------- * RingPlot.java * ------------- - * (C) Copyright 2004-2008, by Object Refinery Limited. + * (C) Copyright 2004-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limtied); * Contributor(s): Christoph Beck (bug 2121818); @@ -77,7 +77,7 @@ import org.jfree.chart.util.SerialUtilities; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.UnitType; -import org.jfree.data.general.PieDataset; +import org.jfree.data.pie.PieDataset; /** * A customised pie plot that leaves a hole in the middle. @@ -409,11 +409,11 @@ } } else if (currentPass == 1) { - Paint paint = lookupSectionPaint(key); + Paint paint = lookupSectionPaint(key, false); g2.setPaint(paint); g2.fill(path); - Paint outlinePaint = lookupSectionOutlinePaint(key); - Stroke outlineStroke = lookupSectionOutlineStroke(key); + Paint outlinePaint = lookupSectionOutlinePaint(key, false); + Stroke outlineStroke = lookupSectionOutlineStroke(key, false); if (outlinePaint != null && outlineStroke != null) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); Modified: trunk/source/org/jfree/chart/plot/SpiderWebPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/SpiderWebPlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/SpiderWebPlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -100,6 +100,7 @@ import org.jfree.chart.LegendItemCollection; import org.jfree.chart.entity.CategoryItemEntity; import org.jfree.chart.entity.EntityCollection; +import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.labels.CategoryItemLabelGenerator; import org.jfree.chart.labels.CategoryToolTipGenerator; @@ -369,7 +370,9 @@ } // send a dataset change event to self to trigger plot change event - datasetChanged(new DatasetChangeEvent(this, dataset)); + datasetChanged(new DatasetChangeEvent(this, dataset, + new DatasetChangeInfo())); + // TODO: fill in real dataset change type } /** Modified: trunk/source/org/jfree/chart/plot/ThermometerPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/ThermometerPlot.java 2009-07-06 07:25:07 UTC (rev 2193) +++ trunk/source/org/jfree/chart/plot/ThermometerPlot.java 2009-07-06 07:28:35 UTC (rev 2194) @@ -117,6 +117,7 @@ import org.jfree.chart.LegendItemCollection; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; @@ -447,7 +448,9 @@ } // send a dataset change event to self... - DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); + DatasetChangeEvent event = new DatasetChangeEvent(this, datase... [truncated message content] |
From: <mu...@us...> - 2009-07-07 20:13:49
|
Revision: 2203 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2203&view=rev Author: mungady Date: 2009-07-07 20:13:36 +0000 (Tue, 07 Jul 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java Modified: trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java =================================================================== --- trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java 2009-07-07 20:04:48 UTC (rev 2202) +++ trunk/source/org/jfree/chart/renderer/category/StackedBarRenderer3D.java 2009-07-07 20:13:36 UTC (rev 2203) @@ -109,6 +109,7 @@ import org.jfree.chart.labels.CategoryItemLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.util.HashUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DataUtilities; import org.jfree.data.Range; @@ -137,7 +138,7 @@ * A flag that controls whether or not zero values are drawn by the * renderer. * - * @since 1.2.0 + * @since 1.0.14 */ private boolean ignoreZeroValues; @@ -225,7 +226,7 @@ * * @return A boolean. * - * @since 1.2.0 + * @since 1.0.14 */ public boolean getIgnoreZeroValues() { return this.ignoreZeroValues; @@ -238,7 +239,7 @@ * * @param ignore the new flag value. * - * @since 1.2.0 + * @since 1.0.14 */ public void setIgnoreZeroValues(boolean ignore) { this.ignoreZeroValues = ignore; @@ -844,4 +845,16 @@ return super.equals(obj); } + /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int hash = super.hashCode(); + hash = HashUtilities.hashCode(hash, this.renderAsPercentages); + hash = HashUtilities.hashCode(hash, this.ignoreZeroValues); + return hash; + } + } Modified: trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java 2009-07-07 20:04:48 UTC (rev 2202) +++ trunk/tests/org/jfree/chart/renderer/category/junit/StackedBarRenderer3DTests.java 2009-07-07 20:13:36 UTC (rev 2203) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------------ * StackedBarRenderer3DTests.java * ------------------------------ - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,7 +37,8 @@ * 25-Mar-2003 : Version 1 (DG); * 18-Jan-2007 : Added many new tests (DG); * 23-Apr-2008 : Added testPublicCloneable() (DG); - * + * 03-Feb-2009 : Added testFindRangeBounds() (DG); + * */ package org.jfree.chart.renderer.category.junit; @@ -56,6 +57,7 @@ import org.jfree.chart.renderer.category.StackedBarRenderer3D; import org.jfree.chart.util.PublicCloneable; +import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; @@ -95,6 +97,33 @@ } /** + * Some checks for the findRangeBounds() method. + */ + public void testFindRangeBounds() { + StackedBarRenderer3D r = new StackedBarRenderer3D(); + assertNull(r.findRangeBounds(null)); + + // an empty dataset should return a null range + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + assertNull(r.findRangeBounds(dataset)); + + dataset.addValue(1.0, "R1", "C1"); + assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset)); + + dataset.addValue(-2.0, "R1", "C2"); + assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); + + dataset.addValue(null, "R1", "C3"); + assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); + + dataset.addValue(2.0, "R2", "C1"); + assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset)); + + dataset.addValue(null, "R2", "C2"); + assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset)); + } + + /** * Check that the equals() method distinguishes all fields. */ public void testEquals() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-07-07 19:26:54
|
Revision: 2201 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2201&view=rev Author: mungady Date: 2009-07-07 19:26:50 +0000 (Tue, 07 Jul 2009) Log Message: ----------- Various updates. Modified Paths: -------------- trunk/source/org/jfree/data/gantt/XYTaskDataset.java trunk/source/org/jfree/data/xy/XYSeriesCollection.java trunk/source/org/jfree/data/xy/YIntervalSeriesCollection.java trunk/tests/org/jfree/chart/axis/junit/LogAxisTests.java trunk/tests/org/jfree/chart/axis/junit/NumberAxisTests.java trunk/tests/org/jfree/chart/axis/junit/SubCategoryAxisTests.java trunk/tests/org/jfree/chart/axis/junit/ValueAxisTests.java trunk/tests/org/jfree/chart/junit/AreaChartTests.java trunk/tests/org/jfree/chart/junit/BarChart3DTests.java trunk/tests/org/jfree/chart/junit/BarChartTests.java trunk/tests/org/jfree/chart/junit/ChartPanelTests.java trunk/tests/org/jfree/chart/junit/GanttChartTests.java trunk/tests/org/jfree/chart/junit/JFreeChartTests.java trunk/tests/org/jfree/chart/junit/LineChart3DTests.java trunk/tests/org/jfree/chart/junit/LineChartTests.java trunk/tests/org/jfree/chart/junit/PieChart3DTests.java trunk/tests/org/jfree/chart/junit/PieChartTests.java trunk/tests/org/jfree/chart/junit/ScatterPlotTests.java trunk/tests/org/jfree/chart/junit/StackedAreaChartTests.java trunk/tests/org/jfree/chart/junit/StackedBarChart3DTests.java trunk/tests/org/jfree/chart/junit/StackedBarChartTests.java trunk/tests/org/jfree/chart/junit/TimeSeriesChartTests.java trunk/tests/org/jfree/chart/junit/WaterfallChartTests.java trunk/tests/org/jfree/chart/junit/XYAreaChartTests.java trunk/tests/org/jfree/chart/junit/XYBarChartTests.java trunk/tests/org/jfree/chart/junit/XYLineChartTests.java trunk/tests/org/jfree/chart/junit/XYStepAreaChartTests.java trunk/tests/org/jfree/chart/junit/XYStepChartTests.java trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java trunk/tests/org/jfree/chart/plot/junit/MultiplePiePlotTests.java trunk/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRenderer2Tests.java trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRendererTests.java trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYBarRendererTests.java trunk/tests/org/jfree/chart/renderer/xy/junit/StandardXYItemRendererTests.java trunk/tests/org/jfree/chart/renderer/xy/junit/XYBarRendererTests.java trunk/tests/org/jfree/chart/renderer/xy/junit/XYLineAndShapeRendererTests.java trunk/tests/org/jfree/data/general/junit/DefaultHeatMapDatasetTests.java trunk/tests/org/jfree/data/general/junit/DefaultPieDatasetTests.java trunk/tests/org/jfree/data/time/junit/TimePeriodValuesTests.java trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java trunk/tests/org/jfree/data/time/ohlc/junit/OHLCSeriesCollectionTests.java trunk/tests/org/jfree/data/time/ohlc/junit/OHLCSeriesTests.java trunk/tests/org/jfree/data/xy/junit/VectorSeriesTests.java trunk/tests/org/jfree/data/xy/junit/XIntervalSeriesTests.java trunk/tests/org/jfree/data/xy/junit/XYIntervalSeriesTests.java trunk/tests/org/jfree/data/xy/junit/YIntervalSeriesTests.java Modified: trunk/source/org/jfree/data/gantt/XYTaskDataset.java =================================================================== --- trunk/source/org/jfree/data/gantt/XYTaskDataset.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/source/org/jfree/data/gantt/XYTaskDataset.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -45,8 +45,8 @@ import org.jfree.chart.axis.SymbolAxis; import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.renderer.xy.XYBarRenderer; -import org.jfree.data.general.DatasetChangeEvent; -import org.jfree.data.general.DatasetChangeListener; +import org.jfree.data.event.DatasetChangeEvent; +import org.jfree.data.event.DatasetChangeListener; import org.jfree.data.time.TimePeriod; import org.jfree.data.xy.AbstractXYDataset; import org.jfree.data.xy.IntervalXYDataset; Modified: trunk/source/org/jfree/data/xy/XYSeriesCollection.java =================================================================== --- trunk/source/org/jfree/data/xy/XYSeriesCollection.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/source/org/jfree/data/xy/XYSeriesCollection.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -79,7 +79,7 @@ import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.UnknownKeyException; -import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.data.event.DatasetChangeEvent; /** * Represents a collection of {@link XYSeries} objects that can be used as a Modified: trunk/source/org/jfree/data/xy/YIntervalSeriesCollection.java =================================================================== --- trunk/source/org/jfree/data/xy/YIntervalSeriesCollection.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/source/org/jfree/data/xy/YIntervalSeriesCollection.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -52,7 +52,7 @@ import org.jfree.chart.event.DatasetChangeInfo; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; -import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.data.event.DatasetChangeEvent; /** * A collection of {@link YIntervalSeries} objects. Modified: trunk/tests/org/jfree/chart/axis/junit/LogAxisTests.java =================================================================== --- trunk/tests/org/jfree/chart/axis/junit/LogAxisTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/axis/junit/LogAxisTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -202,16 +202,8 @@ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); - JFreeChart chart = ChartFactory.createBarChart( - "Test", - "Categories", - "Value", - dataset, - PlotOrientation.VERTICAL, - false, - false, - false - ); + JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", + "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); @@ -229,8 +221,7 @@ dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createLineChart("Test", "Categories", - "Value", dataset, PlotOrientation.VERTICAL, false, false, - false); + "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); @@ -257,16 +248,8 @@ series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); - JFreeChart chart = ChartFactory.createScatterPlot( - "Test", - "X", - "Y", - dataset, - PlotOrientation.VERTICAL, - false, - false, - false - ); + JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", + dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); @@ -285,16 +268,8 @@ series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); - JFreeChart chart = ChartFactory.createScatterPlot( - "Test", - "X", - "Y", - dataset, - PlotOrientation.VERTICAL, - false, - false, - false - ); + JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", + dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); Modified: trunk/tests/org/jfree/chart/axis/junit/NumberAxisTests.java =================================================================== --- trunk/tests/org/jfree/chart/axis/junit/NumberAxisTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/axis/junit/NumberAxisTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -229,16 +229,8 @@ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); - JFreeChart chart = ChartFactory.createBarChart( - "Test", - "Categories", - "Value", - dataset, - PlotOrientation.VERTICAL, - false, - false, - false - ); + JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", + "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); assertEquals(axis.getLowerBound(), 0.0, EPSILON); @@ -255,8 +247,7 @@ dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createLineChart("Test", "Categories", - "Value", dataset, PlotOrientation.VERTICAL, false, false, - false); + "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); @@ -275,8 +266,7 @@ dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createLineChart("Test", "Categories", - "Value", dataset, PlotOrientation.VERTICAL, false, false, - false); + "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); @@ -301,8 +291,7 @@ dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createBarChart("Test", "Categories", - "Value", dataset, PlotOrientation.VERTICAL, false, false, - false); + "Value", dataset, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); @@ -351,16 +340,8 @@ series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); - JFreeChart chart = ChartFactory.createScatterPlot( - "Test", - "X", - "Y", - dataset, - PlotOrientation.VERTICAL, - false, - false, - false - ); + JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", + dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getDomainAxis(); axis.setAutoRangeIncludesZero(false); @@ -379,16 +360,8 @@ series.add(3.0, 3.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); - JFreeChart chart = ChartFactory.createScatterPlot( - "Test", - "X", - "Y", - dataset, - PlotOrientation.VERTICAL, - false, - false, - false - ); + JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y", + dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); Modified: trunk/tests/org/jfree/chart/axis/junit/SubCategoryAxisTests.java =================================================================== --- trunk/tests/org/jfree/chart/axis/junit/SubCategoryAxisTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/axis/junit/SubCategoryAxisTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------- * SubCategoryAxisTests.java * ------------------------- - * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2004-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -176,8 +176,7 @@ */ public void test2275695() { JFreeChart chart = ChartFactory.createStackedBarChart("Test", - "Category", "Value", null, PlotOrientation.VERTICAL, - true, false, false); + "Category", "Value", null, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(new SubCategoryAxis("SubCategoryAxis")); boolean success = false; Modified: trunk/tests/org/jfree/chart/axis/junit/ValueAxisTests.java =================================================================== --- trunk/tests/org/jfree/chart/axis/junit/ValueAxisTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/axis/junit/ValueAxisTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------- * ValueAxisTests.java * ------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -232,9 +232,7 @@ XYSeriesCollection dataset = new XYSeriesCollection(series); dataset.setIntervalWidth(0.0); JFreeChart chart = ChartFactory.createScatterPlot( - "Title", "X", "Y", dataset, PlotOrientation.VERTICAL, - false, false, false - ); + "Title", "X", "Y", dataset, false); ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis(); Range r = domainAxis.getRange(); assertEquals(110.0, r.getLength(), EPSILON); Modified: trunk/tests/org/jfree/chart/junit/AreaChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/AreaChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/AreaChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -186,7 +186,7 @@ CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createAreaChart("Area Chart", "Domain", "Range", - dataset, PlotOrientation.HORIZONTAL, true, true, true); + dataset, true); } Modified: trunk/tests/org/jfree/chart/junit/BarChart3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/BarChart3DTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/BarChart3DTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -198,7 +198,7 @@ // create the chart... return ChartFactory.createBarChart3D("Bar Chart 3D", "Domain", "Range", - dataset, PlotOrientation.HORIZONTAL, true, true, true); + dataset, true); } Modified: trunk/tests/org/jfree/chart/junit/BarChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/BarChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/BarChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -201,15 +201,8 @@ "C", data); // create the chart... - return ChartFactory.createBarChart( - "Bar Chart", - "Domain", "Range", - dataset, - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); + return ChartFactory.createBarChart("Bar Chart", "Domain", "Range", + dataset, true); } Modified: trunk/tests/org/jfree/chart/junit/ChartPanelTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/ChartPanelTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/ChartPanelTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -179,7 +179,7 @@ public void test2502355_zoom() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); @@ -194,7 +194,7 @@ public void test2502355_zoomInBoth() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); @@ -209,7 +209,7 @@ public void test2502355_zoomOutBoth() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); @@ -224,7 +224,7 @@ public void test2502355_restoreAutoBounds() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); @@ -239,7 +239,7 @@ public void test2502355_zoomInDomain() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); @@ -256,7 +256,7 @@ public void test2502355_zoomInRange() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); @@ -273,7 +273,7 @@ public void test2502355_zoomOutDomain() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); @@ -290,7 +290,7 @@ public void test2502355_zoomOutRange() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); @@ -307,7 +307,7 @@ public void test2502355_restoreAutoDomainBounds() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); @@ -324,7 +324,7 @@ public void test2502355_restoreAutoRangeBounds() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); @@ -341,7 +341,7 @@ public void testSetMouseWheelEnabled() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", - "Y", dataset, PlotOrientation.VERTICAL, false, false, false); + "Y", dataset, false); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); assertTrue(panel.isMouseWheelEnabled()); Modified: trunk/tests/org/jfree/chart/junit/GanttChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/GanttChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/GanttChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -188,17 +188,8 @@ * @return The chart. */ private static JFreeChart createGanttChart() { - - // create the chart... - return ChartFactory.createGanttChart( - "Gantt Chart", - "Domain", "Range", - null, - true, // include legend - true, - true - ); - + return ChartFactory.createGanttChart("Gantt Chart", "Domain", "Range", + null, true); } /** Modified: trunk/tests/org/jfree/chart/junit/JFreeChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/JFreeChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/JFreeChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------- * JFreeChartTests.java * -------------------- - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -113,22 +113,12 @@ * Common test setup. */ protected void setUp() { - - // create a dataset... - DefaultPieDataset data = new DefaultPieDataset(); - data.setValue("Java", new Double(43.2)); - data.setValue("Visual Basic", new Double(0.0)); - data.setValue("C/C++", new Double(17.5)); - - // create the chart... - this.pieChart = ChartFactory.createPieChart( - "Pie Chart", // chart title - data, // data - true, // include legend - true, - false - ); - + DefaultPieDataset dataset = new DefaultPieDataset(); + dataset.setValue("Java", new Double(43.2)); + dataset.setValue("Visual Basic", new Double(0.0)); + dataset.setValue("C/C++", new Double(17.5)); + this.pieChart = ChartFactory.createPieChart("Pie Chart", dataset, + true); } /** @@ -252,8 +242,7 @@ */ public void testGetSubtitle() { DefaultPieDataset dataset = new DefaultPieDataset(); - JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart("title", dataset, true); Title t = chart.getSubtitle(0); assertTrue(t instanceof LegendTitle); @@ -295,8 +284,7 @@ data.setValue("Type 2", 23.9); data.setValue("Type 3", 45.8); - JFreeChart c1 = ChartFactory.createPieChart("Test", data, true, true, - true); + JFreeChart c1 = ChartFactory.createPieChart("Test", data, true); JFreeChart c2 = null; try { @@ -328,8 +316,7 @@ data.setValue("Type 2", 23.9); data.setValue("Type 3", 45.8); - JFreeChart c1 = ChartFactory.createPieChart3D("Test", data, true, true, - true); + JFreeChart c1 = ChartFactory.createPieChart3D("Test", data, true); JFreeChart c2 = null; try { @@ -401,19 +388,10 @@ dataset.addValue(3.0, series3, category8); // create the chart... - JFreeChart c1 = ChartFactory.createBarChart( - "Vertical Bar Chart", // chart title - "Category", // domain axis label - "Value", // range axis label - dataset, // data - PlotOrientation.VERTICAL, // orientation - true, // include legend - true, - false - ); + JFreeChart c1 = ChartFactory.createBarChart("Vertical Bar Chart", + "Category", "Value", dataset, true); JFreeChart c2 = null; - try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); @@ -446,7 +424,7 @@ dataset.addSeries(series); JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date", - "Value", dataset, true, true, true); + "Value", dataset, true); JFreeChart c2 = null; try { @@ -472,8 +450,7 @@ */ public void testAddSubtitle() { DefaultPieDataset dataset = new DefaultPieDataset(); - JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart("title", dataset, true); TextTitle t0 = new TextTitle("T0"); chart.addSubtitle(0, t0); @@ -516,8 +493,7 @@ */ public void testGetSubtitles() { DefaultPieDataset dataset = new DefaultPieDataset(); - JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart("title", dataset, true); List subtitles = chart.getSubtitles(); assertEquals(1, chart.getSubtitleCount()); @@ -532,8 +508,7 @@ */ public void testLegendEvents() { DefaultPieDataset dataset = new DefaultPieDataset(); - JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart("title", dataset, true); chart.addChangeListener(this); this.lastChartChangeEvent = null; LegendTitle legend = chart.getLegend(); @@ -546,8 +521,7 @@ */ public void testTitleChangeEvent() { DefaultPieDataset dataset = new DefaultPieDataset(); - JFreeChart chart = ChartFactory.createPieChart("title", dataset, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart("title", dataset, true); chart.addChangeListener(this); this.lastChartChangeEvent = null; TextTitle t = chart.getTitle(); Modified: trunk/tests/org/jfree/chart/junit/LineChart3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/LineChart3DTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/LineChart3DTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -196,15 +196,8 @@ "C", data); // create the chart... - return ChartFactory.createLineChart3D( - "Line Chart", - "Domain", "Range", - dataset, - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); + return ChartFactory.createLineChart3D("Line Chart", "Domain", "Range", + dataset, true); } Modified: trunk/tests/org/jfree/chart/junit/LineChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/LineChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/LineChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -186,7 +186,6 @@ */ private static JFreeChart createLineChart() { - // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, @@ -194,18 +193,9 @@ CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); + return ChartFactory.createLineChart("Line Chart", "Domain", "Range", + dataset, true); - // create the chart... - return ChartFactory.createLineChart( - "Line Chart", - "Domain", "Range", - dataset, - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); - } /** Modified: trunk/tests/org/jfree/chart/junit/PieChart3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/PieChart3DTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/PieChart3DTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------- * PieChart3DTests.java * -------------------- - * (C) Copyright 2004-2008, by Object Refinery Limited. + * (C) Copyright 2004-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -141,14 +141,7 @@ * @return The pie chart. */ private static JFreeChart createPieChart3D(PieDataset dataset) { - - return ChartFactory.createPieChart3D( - "Pie Chart", // chart title - dataset, // data - true, // include legend - true, - false - ); + return ChartFactory.createPieChart3D("Pie Chart", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/PieChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/PieChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/PieChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------ * PieChartTests.java * ------------------ - * (C) Copyright 2002-2008, by Object Refinery Limited. + * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -108,19 +108,11 @@ * @return The pie chart. */ private static JFreeChart createPieChart() { - // create a dataset... - DefaultPieDataset data = new DefaultPieDataset(); - data.setValue("Java", new Double(43.2)); - data.setValue("Visual Basic", new Double(0.0)); - data.setValue("C/C++", new Double(17.5)); - - // create the chart... - return ChartFactory.createPieChart("Pie Chart", // chart title - data, // data - true, // include legend - true, - false - ); + DefaultPieDataset dataset = new DefaultPieDataset(); + dataset.setValue("Java", new Double(43.2)); + dataset.setValue("Visual Basic", new Double(0.0)); + dataset.setValue("C/C++", new Double(17.5)); + return ChartFactory.createPieChart("Pie Chart", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/ScatterPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/ScatterPlotTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/ScatterPlotTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -169,26 +169,13 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); - - // create the chart... - return ChartFactory.createScatterPlot( - "Scatter Plot", // chart title - "Domain", - "Range", - dataset, // data - PlotOrientation.VERTICAL, - true, // include legend - true, // tooltips - false // urls - ); - + return ChartFactory.createScatterPlot("Scatter Plot", "Domain", + "Range", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/StackedAreaChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/StackedAreaChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/StackedAreaChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -185,27 +185,14 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; - CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); - - // create the chart... - return ChartFactory.createStackedAreaChart( - "Stacked Area Chart", // chart title - "Domain", "Range", - dataset, // data - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); - + return ChartFactory.createStackedAreaChart("Stacked Area Chart", + "Domain", "Range", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/StackedBarChart3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/StackedBarChart3DTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/StackedBarChart3DTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -196,15 +196,8 @@ "C", data); // create the chart... - return ChartFactory.createStackedBarChart3D( - "Stacked Bar Chart 3D", // chart title - "Domain", "Range", - dataset, // data - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); + return ChartFactory.createStackedBarChart3D("Stacked Bar Chart 3D", + "Domain", "Range", dataset, true); } Modified: trunk/tests/org/jfree/chart/junit/StackedBarChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/StackedBarChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/StackedBarChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -191,27 +191,14 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; - CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); - - // create the chart... - return ChartFactory.createStackedBarChart( - "Stacked Bar Chart", // chart title - "Domain", "Range", - dataset, // data - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); - + return ChartFactory.createStackedBarChart("Stacked Bar Chart", + "Domain", "Range", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/TimeSeriesChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/TimeSeriesChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/TimeSeriesChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -164,25 +164,13 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); - - // create the chart... - return ChartFactory.createTimeSeriesChart( - "XY Line Chart", // chart title - "Domain", - "Range", - dataset, // data - true, // include legend - true, // tooltips - true // urls - ); - + return ChartFactory.createTimeSeriesChart("XY Line Chart", "Domain", + "Range", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/WaterfallChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/WaterfallChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/WaterfallChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -164,18 +164,9 @@ CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); + return ChartFactory.createWaterfallChart("Waterfall Chart", "Domain", + "Range", dataset, true); - // create the chart... - return ChartFactory.createWaterfallChart( - "Waterfall Chart", - "Domain", "Range", - dataset, - PlotOrientation.HORIZONTAL, - true, // include legend - true, - true - ); - } } Modified: trunk/tests/org/jfree/chart/junit/XYAreaChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/XYAreaChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/XYAreaChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -166,26 +166,13 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); - - // create the chart... - return ChartFactory.createXYAreaChart( - "Area Chart", // chart title - "Domain", - "Range", - dataset, // data - PlotOrientation.VERTICAL, - true, // include legend - true, // tooltips - true // urls - ); - + return ChartFactory.createXYAreaChart("Area Chart", "Domain", "Range", + dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/XYBarChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/XYBarChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/XYBarChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -178,16 +178,8 @@ series1), 1.0); // create the chart... - return ChartFactory.createXYBarChart( - "XY Bar Chart", // chart title - "Domain", false, - "Range", - dataset, // data - PlotOrientation.VERTICAL, - true, // include legend - true, // tooltips - true // urls - ); + return ChartFactory.createXYBarChart("XY Bar Chart", "Domain", false, + "Range", dataset, true); } Modified: trunk/tests/org/jfree/chart/junit/XYLineChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/XYLineChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/XYLineChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -165,26 +165,13 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); - - // create the chart... - return ChartFactory.createXYLineChart( - "XY Line Chart", // chart title - "Domain", - "Range", - dataset, // data - PlotOrientation.VERTICAL, - true, // include legend - true, // tooltips - true // urls - ); - + return ChartFactory.createXYLineChart("XY Line Chart", "Domain", + "Range", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/XYStepAreaChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/XYStepAreaChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/XYStepAreaChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -165,26 +165,13 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); - - // create the chart... - return ChartFactory.createXYStepAreaChart( - "Step Chart", // chart title - "Domain", - "Range", - dataset, // data - PlotOrientation.VERTICAL, - true, // include legend - true, // tooltips - true // urls - ); - + return ChartFactory.createXYStepAreaChart("Step Chart", "Domain", + "Range", dataset, true); } /** Modified: trunk/tests/org/jfree/chart/junit/XYStepChartTests.java =================================================================== --- trunk/tests/org/jfree/chart/junit/XYStepChartTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/junit/XYStepChartTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -165,26 +165,13 @@ * @return The chart. */ private static JFreeChart createChart() { - - // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); - - // create the chart... - return ChartFactory.createXYStepChart( - "Step Chart", // chart title - "Domain", - "Range", - dataset, // data - PlotOrientation.VERTICAL, - true, // include legend - true, // tooltips - true // urls - ); - + return ChartFactory.createXYStepChart("Step Chart", "Domain", "Range", + dataset, true); } /** Modified: trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -671,16 +671,8 @@ */ public void testSerialization3() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - JFreeChart chart = ChartFactory.createBarChart( - "Test Chart", - "Category Axis", - "Value Axis", - dataset, - PlotOrientation.VERTICAL, - true, - true, - false - ); + JFreeChart chart = ChartFactory.createBarChart("Test Chart", + "Category Axis", "Value Axis", dataset, true); JFreeChart chart2 = null; // serialize and deserialize the chart.... @@ -716,16 +708,8 @@ */ public void testSerialization4() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); - JFreeChart chart = ChartFactory.createBarChart( - "Test Chart", - "Category Axis", - "Value Axis", - dataset, - PlotOrientation.VERTICAL, - true, - true, - false - ); + JFreeChart chart = ChartFactory.createBarChart("Test Chart", + "Category Axis", "Value Axis", dataset, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.addRangeMarker(new ValueMarker(1.1), Layer.FOREGROUND); plot.addRangeMarker(new IntervalMarker(2.2, 3.3), Layer.BACKGROUND); @@ -883,7 +867,7 @@ public void test1654215() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", - dataset, PlotOrientation.VERTICAL, true, false, false); + dataset, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(1, new LineAndShapeRenderer()); boolean success = false; Modified: trunk/tests/org/jfree/chart/plot/junit/MultiplePiePlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/MultiplePiePlotTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/plot/junit/MultiplePiePlotTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -153,11 +153,9 @@ 3.0f, 4.0f, Color.yellow)); assertTrue(p1.equals(p2)); - p1.setPieChart(ChartFactory.createPieChart("Title", null, true, true, - true)); + p1.setPieChart(ChartFactory.createPieChart("Title", null, true)); assertFalse(p1.equals(p2)); - p2.setPieChart(ChartFactory.createPieChart("Title", null, true, true, - true)); + p2.setPieChart(ChartFactory.createPieChart("Title", null, true)); assertTrue(p1.equals(p2)); p1.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); Modified: trunk/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/plot/junit/PiePlot3DTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -134,8 +134,7 @@ * Draws a pie chart where the label generator returns null. */ public void testDrawWithNullDataset() { - JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true); boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, Modified: trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -639,8 +639,7 @@ DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("L1", 12.0); dataset.setValue("L2", 11.0); - JFreeChart chart = ChartFactory.createPieChart("Test", dataset, true, - false, false); + JFreeChart chart = ChartFactory.createPieChart("Test", dataset, true); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLegendLabelGenerator(new NullLegendLabelGenerator()); boolean success = false; Modified: trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -713,16 +713,8 @@ public void testSerialization3() { XYSeriesCollection dataset = new XYSeriesCollection(); - JFreeChart chart = ChartFactory.createXYLineChart( - "Test Chart", - "Domain Axis", - "Range Axis", - dataset, - PlotOrientation.VERTICAL, - true, - true, - false - ); + JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", + "Domain Axis", "Range Axis", dataset, true); JFreeChart chart2 = null; // serialize and deserialize the chart.... @@ -761,16 +753,8 @@ public void testSerialization4() { XYSeriesCollection dataset = new XYSeriesCollection(); - JFreeChart chart = ChartFactory.createXYLineChart( - "Test Chart", - "Domain Axis", - "Range Axis", - dataset, - PlotOrientation.VERTICAL, - true, - true, - false - ); + JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", + "Domain Axis", "Range Axis", dataset, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.addDomainMarker(new ValueMarker(1.0), Layer.FOREGROUND); plot.addDomainMarker(new IntervalMarker(2.0, 3.0), Layer.BACKGROUND); @@ -1025,7 +1009,7 @@ public void test1654215() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", - dataset, PlotOrientation.VERTICAL, true, false, false); + dataset, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(1, new XYLineAndShapeRenderer()); boolean success = false; @@ -1051,7 +1035,7 @@ public void testDrawRangeGridlines() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", - dataset, PlotOrientation.VERTICAL, true, false, false); + dataset, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(null); boolean success = false; @@ -1079,7 +1063,7 @@ dataset.addSeries("Series 1", new double[][] {{1.0, 2.0}, {3.0, 4.0}}); dataset.addSeries("Series 2", new double[][] {{}, {}}); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", - dataset, PlotOrientation.VERTICAL, true, false, false); + dataset, true); boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, Modified: trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRenderer2Tests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRenderer2Tests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRenderer2Tests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------------- * StackedXYAreaRenderer2Tests.java * ------------------------------- - * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2005-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -98,8 +98,7 @@ public void testDrawWithEmptyDataset() { boolean success = false; JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x", - "y", new DefaultTableXYDataset(), PlotOrientation.VERTICAL, - true, false, false); + "y", new DefaultTableXYDataset(), true); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYAreaRenderer2()); try { @@ -198,8 +197,7 @@ TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createStackedXYAreaChart( - "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, - false, false, false); + "Test Chart", "X", "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); plot.setRenderer(renderer); Modified: trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRendererTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRendererTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYAreaRendererTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------------- * StackedXYAreaRendererTests.java * ------------------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -188,8 +188,7 @@ TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createStackedXYAreaChart( - "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, - false, false, false); + "Test Chart", "X", "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); Range bounds = rangeAxis.getRange(); Modified: trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYBarRendererTests.java =================================================================== --- trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYBarRendererTests.java 2009-07-07 19:17:05 UTC (rev 2200) +++ trunk/tests/org/jfree/chart/renderer/xy/junit/StackedXYBarRendererTests.java 2009-07-07 19:26:50 UTC (rev 2201) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -177,9 +177,8 @@ public void testFindDomainBounds() { TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); - JFreeChart chart = ChartFactory.createStackedXYAreaChart( - "Test Chart", "X", "Y", dataset, - PlotOrientation.VERTICAL, false, false, false); + JFreeChart chart = ChartFactory.createStackedXYAreaChart("Test Chart", + "X", "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYBarRenderer()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); @@ -197,9 +196,8 @@ public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); - JFreeChart chart = ChartFactory.createStackedXYAreaChart( - "Test Chart", "X", "Y", dataset, - PlotOrientation.VERTICAL, false, fals... [truncated message content] |
From: <mu...@us...> - 2009-07-08 09:33:35
|
Revision: 2205 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2205&view=rev Author: mungady Date: 2009-07-08 09:33:31 +0000 (Wed, 08 Jul 2009) Log Message: ----------- Synchronised with 1.0.x branch. Modified Paths: -------------- trunk/source/org/jfree/chart/plot/CategoryPlot.java trunk/source/org/jfree/chart/plot/XYPlot.java trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java Modified: trunk/source/org/jfree/chart/plot/CategoryPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/CategoryPlot.java 2009-07-08 08:58:47 UTC (rev 2204) +++ trunk/source/org/jfree/chart/plot/CategoryPlot.java 2009-07-08 09:33:31 UTC (rev 2205) @@ -4529,6 +4529,8 @@ * * @return A boolean. * + * @see #isRangePannable() + * * @since 1.0.13 */ public boolean isDomainPannable() { @@ -4541,6 +4543,9 @@ * * @return A boolean. * + * @see #setRangePannable(boolean) + * @see #isDomainPannable() + * * @since 1.0.13 */ public boolean isRangePannable() { @@ -4553,6 +4558,8 @@ * * @param pannable the new flag value. * + * @see #isRangePannable() + * * @since 1.0.13 */ public void setRangePannable(boolean pannable) { @@ -5010,6 +5017,17 @@ clone.datasetToRangeAxesMap.putAll(this.datasetToRangeAxesMap); clone.renderers = (ObjectList) this.renderers.clone(); + for (int i = 0; i < this.renderers.size(); i++) { + CategoryItemRenderer renderer2 = (CategoryItemRenderer) + this.renderers.get(i); + if (renderer2 instanceof PublicCloneable) { + PublicCloneable pc = (PublicCloneable) renderer2; + CategoryItemRenderer rc = (CategoryItemRenderer) pc.clone(); + clone.renderers.set(i, rc); + rc.setPlot(clone); + rc.addChangeListener(clone); + } + } if (this.fixedDomainAxisSpace != null) { clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtilities.clone( this.fixedDomainAxisSpace); Modified: trunk/source/org/jfree/chart/plot/XYPlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/XYPlot.java 2009-07-08 08:58:47 UTC (rev 2204) +++ trunk/source/org/jfree/chart/plot/XYPlot.java 2009-07-08 09:33:31 UTC (rev 2205) @@ -5574,7 +5574,10 @@ XYItemRenderer renderer2 = (XYItemRenderer) this.renderers.get(i); if (renderer2 instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) renderer2; - clone.renderers.set(i, pc.clone()); + XYItemRenderer rc = (XYItemRenderer) pc.clone(); + clone.renderers.set(i, rc); + rc.setPlot(clone); + rc.addChangeListener(clone); } } clone.foregroundDomainMarkers = (Map) ObjectUtilities.clone( Modified: trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java 2009-07-08 08:58:47 UTC (rev 2204) +++ trunk/tests/org/jfree/chart/plot/junit/CategoryPlotTests.java 2009-07-08 09:33:31 UTC (rev 2205) @@ -27,7 +27,7 @@ * ---------------------- * CategoryPlotTests.java * ---------------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -502,6 +502,10 @@ CategoryPlot p1 = new CategoryPlot(); p1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow)); + p1.setRangeMinorGridlinePaint(new GradientPaint(2.0f, 3.0f, Color.white, + 4.0f, 5.0f, Color.red)); + p1.setRangeZeroBaselinePaint(new GradientPaint(3.0f, 4.0f, Color.red, + 5.0f, 6.0f, Color.white)); CategoryPlot p2 = null; try { p2 = (CategoryPlot) p1.clone(); @@ -607,10 +611,33 @@ } /** + * Renderers that belong to the plot are being cloned but they are + * retaining a reference to the original plot. + */ + public void testBug2817504() { + CategoryPlot p1 = new CategoryPlot(); + LineAndShapeRenderer r1 = new LineAndShapeRenderer(); + p1.setRenderer(r1); + CategoryPlot p2 = null; + try { + p2 = (CategoryPlot) p1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(p1 != p2); + assertTrue(p1.getClass() == p2.getClass()); + assertTrue(p1.equals(p2)); + + // check for independence + LineAndShapeRenderer r2 = (LineAndShapeRenderer) p2.getRenderer(); + assertTrue(r2.getPlot() == p2); + } + + /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { - DefaultCategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis domainAxis = new CategoryAxis("Domain"); NumberAxis rangeAxis = new NumberAxis("Range"); @@ -967,7 +994,7 @@ boolean pass = false; try { plot.getDomainAxisForDataset(-1); -} + } catch (IllegalArgumentException e) { pass = true; } Modified: trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-07-08 08:58:47 UTC (rev 2204) +++ trunk/tests/org/jfree/chart/plot/junit/XYPlotTests.java 2009-07-08 09:33:31 UTC (rev 2205) @@ -46,6 +46,7 @@ * 07-Apr-2008 : Added testRemoveDomainMarker() and * testRemoveRangeMarker() (DG); * 10-May-2009 : Extended testEquals(), added testCloning3() (DG); + * 06-Jul-2009 : Added testBug2817504() (DG); * */ @@ -550,6 +551,30 @@ } /** + * Renderers that belong to the plot are being cloned but they are + * retaining a reference to the original plot. + */ + public void testBug2817504() { + XYPlot p1 = new XYPlot(); + XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer(); + p1.setRenderer(r1); + XYPlot p2 = null; + try { + p2 = (XYPlot) p1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(p1 != p2); + assertTrue(p1.getClass() == p2.getClass()); + assertTrue(p1.equals(p2)); + + // check for independence + XYLineAndShapeRenderer r2 = (XYLineAndShapeRenderer) p2.getRenderer(); + assertTrue(r2.getPlot() == p2); + } + + /** * Tests the independence of the clones. */ public void testCloneIndependence() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-07-15 12:36:24
|
Revision: 2214 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2214&view=rev Author: mungady Date: 2009-07-15 12:36:21 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Synchronised with 1.0.X branch. Modified Paths: -------------- trunk/source/org/jfree/chart/plot/PiePlot.java trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java Modified: trunk/source/org/jfree/chart/plot/PiePlot.java =================================================================== --- trunk/source/org/jfree/chart/plot/PiePlot.java 2009-07-15 12:25:10 UTC (rev 2213) +++ trunk/source/org/jfree/chart/plot/PiePlot.java 2009-07-15 12:36:21 UTC (rev 2214) @@ -162,7 +162,10 @@ * generation (DG); * 23-Sep-2008 : Added getLabelLinkDepth() method - see bug 2121818 reported * by Christoph Beck (DG); + * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by + * Jess Thrysoee (DG); * 29-Jun-2009 : Moved PaintMap and StrokeMap to org.jfree.chart.util.* (DG); + * 10-Jul-2009 : Added optional drop shadow generator (DG); * */ @@ -176,6 +179,7 @@ import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; +import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; @@ -186,6 +190,7 @@ import java.awt.geom.Point2D; import java.awt.geom.QuadCurve2D; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -213,6 +218,7 @@ import org.jfree.chart.text.TextBox; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.urls.PieURLGenerator; +import org.jfree.chart.util.DefaultShadowGenerator; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; @@ -221,10 +227,12 @@ import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.Rotation; import org.jfree.chart.util.SerialUtilities; +import org.jfree.chart.util.ShadowGenerator; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.UnitType; import org.jfree.data.DefaultKeyedValues; import org.jfree.data.KeyedValues; +import org.jfree.data.category.CategoryDataset; import org.jfree.data.event.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.pie.PieDataset; @@ -236,6 +244,11 @@ /** * A plot that displays data in the form of a pie chart, using data from any * class that implements the {@link PieDataset} interface. + * The example shown here is generated by the <code>PieChartDemo2.java</code> + * program included in the JFreeChart Demo Collection: + * <br><br> + * <img src="../../../../images/PiePlotSample.png" + * alt="PiePlotSample.png" /> * <P> * Special notes: * <ol> @@ -243,7 +256,7 @@ * in a clockwise direction, but these settings can be changed;</li> * <li>negative values in the dataset are ignored;</li> * <li>there are utility methods for creating a {@link PieDataset} from a - * {@link org.jfree.data.category.CategoryDataset};</li> + * {@link CategoryDataset};</li> * </ol> * * @see Plot @@ -505,9 +518,16 @@ */ private double minimumArcAngleToDraw; + /** + * The shadow generator for the plot (<code>null</code> permitted). + * + * @since 1.0.14 + */ + private ShadowGenerator shadowGenerator; + /** The resourceBundle for the localization. */ - protected static ResourceBundle localizationResources = - ResourceBundleWrapper.getBundle( + protected static ResourceBundle localizationResources + = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** @@ -602,7 +622,9 @@ this.ignoreNullValues = false; this.ignoreZeroValues = false; + this.selectedItemAttributes = new PieSelectionAttributes(); + this.shadowGenerator = new DefaultShadowGenerator(); } /** @@ -2325,6 +2347,33 @@ } /** + * Returns the shadow generator for the plot, if any. + * + * @return The shadow generator (possibly <code>null</code>). + * + * @since 1.0.14 + */ + public ShadowGenerator getShadowGenerator() { + return this.shadowGenerator; + } + + /** + * Sets the shadow generator for the plot and sends a + * {@link PlotChangeEvent} to all registered listeners. Note that this is + * a btmap drop-shadow generation facility and is separate from the + * vector based show option that is controlled via the + * {@link setShadowPaint()} method. + * + * @param generator the generator (<code>null</code> permitted). + * + * @since 1.0.14 + */ + public void setShadowGenerator(ShadowGenerator generator) { + this.shadowGenerator = generator; + fireChangeEvent(); + } + + /** * Initialises the drawing procedure. This method will be called before * the first item is rendered, giving the plot an opportunity to initialise * any state information it wants to maintain. @@ -2387,7 +2436,28 @@ getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { + Graphics2D savedG2 = g2; + Rectangle2D savedDataArea = area; + BufferedImage dataImage = null; + if (this.shadowGenerator != null) { + dataImage = new BufferedImage((int) area.getWidth(), + (int) area.getHeight(), BufferedImage.TYPE_INT_ARGB); + g2 = dataImage.createGraphics(); + g2.setRenderingHints(savedG2.getRenderingHints()); + area = new Rectangle(0, 0, dataImage.getWidth(), dataImage.getHeight()); + } drawPie(g2, area, info); + if (this.shadowGenerator != null) { + BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage); + g2 = savedG2; + area = savedDataArea; + g2.drawImage(shadowImage, (int) savedDataArea.getX() + + this.shadowGenerator.calculateOffsetX(), + (int) savedDataArea.getY() + + this.shadowGenerator.calculateOffsetY(), null); + g2.drawImage(dataImage, (int) savedDataArea.getX(), + (int) savedDataArea.getY(), null); + } } else { drawNoDataMessage(g2, area); @@ -2716,7 +2786,8 @@ bounds); Shape bg = ShapeUtilities.createTranslatedShape(out, x - bounds.getCenterX(), y - bounds.getCenterY()); - if (this.labelShadowPaint != null) { + if (this.labelShadowPaint != null + && this.shadowGenerator == null) { Shape shadow = ShapeUtilities.createTranslatedShape(bg, this.shadowXOffset, this.shadowYOffset); g2.setPaint(this.labelShadowPaint); @@ -2849,7 +2920,12 @@ labelBox.setBackgroundPaint(this.labelBackgroundPaint); labelBox.setOutlinePaint(this.labelOutlinePaint); labelBox.setOutlineStroke(this.labelOutlineStroke); - labelBox.setShadowPaint(this.labelShadowPaint); + if (this.shadowGenerator == null) { + labelBox.setShadowPaint(this.labelShadowPaint); + } + else { + labelBox.setShadowPaint(null); + } labelBox.setInteriorGap(this.labelPadding); double theta = Math.toRadians( leftKeys.getValue(i).doubleValue()); @@ -3430,9 +3506,8 @@ that.sectionOutlineStrokeMap)) { return false; } - if (!ObjectUtilities.equal( - this.baseSectionOutlineStroke, that.baseSectionOutlineStroke - )) { + if (!ObjectUtilities.equal(this.baseSectionOutlineStroke, + that.baseSectionOutlineStroke)) { return false; } if (!PaintUtilities.equal(this.shadowPaint, that.shadowPaint)) { @@ -3541,6 +3616,10 @@ != that.autoPopulateSectionOutlineStroke) { return false; } + if (!ObjectUtilities.equal(this.shadowGenerator, + that.shadowGenerator)) { + return false; + } // can't find any difference... return true; } Modified: trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java =================================================================== --- trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java 2009-07-15 12:25:10 UTC (rev 2213) +++ trunk/tests/org/jfree/chart/plot/junit/PiePlotTests.java 2009-07-15 12:36:21 UTC (rev 2214) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ----------------- * PiePlotTests.java * ----------------- - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -40,7 +40,8 @@ * 23-Nov-2006 : Additional equals() and clone() tests (DG); * 17-Apr-2007 : Added check for label generator that returns a null label (DG); * 21-Jun-2007 : Removed JCommon dependencies (DG); - * 31-Mar-2008 : Updated testEquals(); + * 31-Mar-2008 : Updated testEquals() (DG); + * 10-Jul-2009 : Updated testEquals() (DG); * */ @@ -62,11 +63,9 @@ import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.text.AttributedString; - import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; - import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItemCollection; @@ -77,6 +76,7 @@ import org.jfree.chart.plot.PiePlot; import org.jfree.chart.urls.CustomPieURLGenerator; import org.jfree.chart.urls.StandardPieURLGenerator; +import org.jfree.chart.util.DefaultShadowGenerator; import org.jfree.chart.util.Rotation; import org.jfree.data.pie.DefaultPieDataset; import org.jfree.data.pie.PieDataset; @@ -414,6 +414,19 @@ assertFalse(plot1.equals(plot2)); plot2.setAutoPopulateSectionOutlineStroke(true); assertTrue(plot1.equals(plot2)); + + // shadowGenerator + plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, + 0.6f, 4, -Math.PI / 4)); + assertFalse(plot1.equals(plot2)); + plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, + 0.6f, 4, -Math.PI / 4)); + assertTrue(plot1.equals(plot2)); + + plot1.setShadowGenerator(null); + assertFalse(plot1.equals(plot2)); + plot2.setShadowGenerator(null); + assertTrue(plot1.equals(plot2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mu...@us...> - 2009-08-31 20:54:24
|
Revision: 2227 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=2227&view=rev Author: mungady Date: 2009-08-31 20:54:18 +0000 (Mon, 31 Aug 2009) Log Message: ----------- 2009-08-31 David Gilbert <dav...@ob...> * source/org/jfree/data/time/TimeSeries.java (createCopy): Clear cached minY and maxY values. Modified Paths: -------------- trunk/source/org/jfree/data/time/TimeSeries.java trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java Modified: trunk/source/org/jfree/data/time/TimeSeries.java =================================================================== --- trunk/source/org/jfree/data/time/TimeSeries.java 2009-08-31 20:51:37 UTC (rev 2226) +++ trunk/source/org/jfree/data/time/TimeSeries.java 2009-08-31 20:54:18 UTC (rev 2227) @@ -84,6 +84,7 @@ * storage are cloned to keep series isolated from external * changes (DG); * 10-Jun-2009 : Added addOrUpdate(TimeSeriesDataItem) method (DG); + * 31-Aug-2009 : Clear minY and maxY cache values in createCopy (DG); * */ @@ -1046,7 +1047,6 @@ */ public TimeSeries createCopy(int start, int end) throws CloneNotSupportedException { - if (start < 0) { throw new IllegalArgumentException("Requires start >= 0."); } @@ -1054,7 +1054,8 @@ throw new IllegalArgumentException("Requires start <= end."); } TimeSeries copy = (TimeSeries) super.clone(); - + copy.minY = Double.NaN; + copy.maxY = Double.NaN; copy.data = new java.util.ArrayList(); if (this.data.size() > 0) { for (int index = start; index <= end; index++) { Modified: trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java =================================================================== --- trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java 2009-08-31 20:51:37 UTC (rev 2226) +++ trunk/tests/org/jfree/data/time/junit/TimeSeriesTests.java 2009-08-31 20:54:18 UTC (rev 2227) @@ -49,6 +49,7 @@ * 13-Jan-2009 : Added testEquals3() and testRemoveAgedItems3() (DG); * 26-May-2009 : Added various tests for min/maxY values (DG); * 09-Jun-2009 : Added testAdd_TimeSeriesDataItem (DG); + * 31-Aug-2009 : Added new test for createCopy() method (DG); * */ @@ -342,7 +343,6 @@ * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { - TimeSeries s1 = new TimeSeries("A test"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); @@ -350,24 +350,20 @@ s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); TimeSeries s2 = null; - try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); - - ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); s2 = (TimeSeries) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertTrue(s1.equals(s2)); - } /** @@ -592,13 +588,34 @@ } } + /** + * Checks that the min and max y values are updated correctly when copying + * a subset. + * + * @throws java.lang.CloneNotSupportedException + */ + public void testCreateCopy3() throws CloneNotSupportedException { + TimeSeries s1 = new TimeSeries("S1"); + s1.add(new Year(2009), 100.0); + s1.add(new Year(2010), 101.0); + s1.add(new Year(2011), 102.0); + assertEquals(100.0, s1.getMinY(), EPSILON); + assertEquals(102.0, s1.getMaxY(), EPSILON); + TimeSeries s2 = s1.createCopy(0, 1); + assertEquals(100.0, s2.getMinY(), EPSILON); + assertEquals(101.0, s2.getMaxY(), EPSILON); + + TimeSeries s3 = s1.createCopy(1, 2); + assertEquals(101.0, s3.getMinY(), EPSILON); + assertEquals(102.0, s3.getMaxY(), EPSILON); + } + /** * Test the setMaximumItemCount() method to ensure that it removes items * from the series if necessary. */ public void testSetMaximumItemCount() { - TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |