[Schmitzm-commits] r498 - in branches/1.0-gt2-2.6/src: schmitzm/jfree schmitzm/jfree/chart/renderer schmitzm/jfree/chart/style skrueger/geotools/resource/icons
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Oct 25 14:18:02 CET 2009
Author: alfonx
Date: 2009-10-25 14:18:01 +0100 (Sun, 25 Oct 2009)
New Revision: 498
Modified:
branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionXYRenderer.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
branches/1.0-gt2-2.6/src/skrueger/geotools/resource/icons/zoom_full_extend.png
Log:
Selectierte Punkte werden jetzt mit rotem rand gezeichnet
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java 2009-10-23 18:43:58 UTC (rev 497)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java 2009-10-25 13:18:01 UTC (rev 498)
@@ -91,566 +91,704 @@
/**
* In dieser Klasse sind Hilfsmethoden fuer JFreeChart hinterlegt.
- * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ *
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
+ * (University of Bonn/Germany)
* @version 1.0
*/
public class JFreeChartUtil {
- private static Logger LOGGER = Logger.getLogger(JFreeChartUtil.class.getName());
-
- /** Default percentage, an (axis) range is extended with on centering
- * to avoid points directly on the plot border. */
- public static final Double DEFAULT_CENTRATION_BOUNDARY_PCT = 0.1;
-
- /** {@link ResourceProvider}, der die Lokalisation fuer GUI-Komponenten
- * zur Verfuegung stellt. Diese sind in properties-Datein unter
- * {@code schmitzm.jfree.resource.locales.JFreeResourceBundle_XXX.properties}
- * hinterlegt. */
- public static ResourceProvider RESOURCE = new ResourceProvider( LangUtil.extendPackagePath(JFreeChartUtil.class,"resource.locales.JFreeResourceBundle"), Locale.ENGLISH );
+ private static Logger LOGGER = Logger.getLogger(JFreeChartUtil.class
+ .getName());
- /**
- * Convenience method to access the {@link ResourceProvider}.
- */
- public static String R(String key, Object... values) {
- return RESOURCE.getString(key, values);
- }
+ /**
+ * Default percentage, an (axis) range is extended with on centering to
+ * avoid points directly on the plot border.
+ */
+ public static final Double DEFAULT_CENTRATION_BOUNDARY_PCT = 0.1;
- /** Instance of {@link ChartStyleXMLFactory}. */
- public static final ChartStyleXMLFactory<ChartStyle> CHART_STYLE_FACTORY = new ChartStyleXMLFactory<ChartStyle>();
+ /**
+ * {@link ResourceProvider}, der die Lokalisation fuer GUI-Komponenten zur
+ * Verfuegung stellt. Diese sind in properties-Datein unter {@code
+ * schmitzm.jfree.resource.locales.JFreeResourceBundle_XXX.properties}
+ * hinterlegt.
+ */
+ public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
+ .extendPackagePath(JFreeChartUtil.class,
+ "resource.locales.JFreeResourceBundle"), Locale.ENGLISH);
- /**
- * Sets all chart legends (in)visible.
- * @param chart a chart to apply
- * @param visible indicates the visible property
- */
- public static void setLegendVisible(JFreeChart chart, boolean visible) {
- for (Object title : chart.getSubtitles())
- if ( title instanceof LegendTitle )
- ((Title)title).setVisible(visible);
- }
-
- /**
- * Fires a change event to all {@link PlotChangeListener} connected
- * to the plot.
- * @param plot a plot
- */
- public static void fireChangeEvent(Plot plot) {
- plot.notifyListeners( new PlotChangeEvent(plot) );
- }
-
- /**
- * Fires a change event to all {@link RendererChangeListener} connected
- * to the renderer.
- * @param renderer a renderer
- */
- public static void fireChangeEvent(AbstractRenderer renderer) {
- renderer.notifyListeners( new RendererChangeEvent(renderer,true) );
- }
+ /**
+ * Convenience method to access the {@link ResourceProvider}.
+ */
+ public static String R(String key, Object... values) {
+ return RESOURCE.getString(key, values);
+ }
- /**
- * Returns the maximum extend of a {@link Range} including
- * a given boundary.
- * @param range a {@link Range}
- * @param boundaryPct extends the {@link Range} bound by percentage (if {@code null}
- * {@value #DEFAULT_CENTRATION_BOUNDARY_PCT} is used).
- * @return a value >= 0
- */
- public static double getAbsRange(Range range, Double boundaryPct) {
- if ( boundaryPct == null )
- boundaryPct = DEFAULT_CENTRATION_BOUNDARY_PCT;
- return Math.max(
- Math.abs(range.getUpperBound()),
- Math.abs(range.getLowerBound())
- ) * (1+boundaryPct);
- }
-
- /**
- * Returns a new centered {@link Range} defined as [-maxAbs; maxAbs] of a
- * given {@link Range}.
- * @param range the {@link Range} to center
- * @param boundaryPct extends the range's absolute maximum by percentage (if {@code null}
- * {@value #DEFAULT_CENTRATION_BOUNDARY_PCT} is used).
- * @return a new {@link Range} object
- */
- public static Range centerRange(Range range, Double boundaryPct) {
- double absMax = getAbsRange(range,boundaryPct);
- return new Range(-absMax, absMax);
- }
-
- /**
- * Centers a gives {@link Axis} around 0.
- * @param axis the {@link Axis} to center
- * @param boundaryPct extends the axis range's absolute maximum by percentage (if {@code null}
- * {@value #DEFAULT_CENTRATION_BOUNDARY_PCT} is used).
- */
- public static void centerAxis(ValueAxis axis, Double boundaryPct) {
- // first recalculate the full extend (unfortunately the listeners are
- // called; the method to de-activate this behavior is protected!)
- axis.setAutoRange(true);
- // then reset the centering
- double absMax = getAbsRange(axis.getRange(),boundaryPct);
- axis.setRange(-absMax, absMax);
- }
+ /** Instance of {@link ChartStyleXMLFactory}. */
+ public static final ChartStyleXMLFactory<ChartStyle> CHART_STYLE_FACTORY = new ChartStyleXMLFactory<ChartStyle>();
- /**
- * Centers a gives {@link Plot} around 0/0 (of the main axis).
- * For {@link CategoryPlot} only the range axis is centered.
- * @param axis the {@link Plot} to center
- * @param boundaryPct percentage boundary the absolute maximum is extended with
- */
- public static void centerPlot(Plot plot, Double boundaryPct) {
- if ( plot instanceof XYPlot ) {
- centerAxis( ((XYPlot)plot).getDomainAxis(), boundaryPct );
- centerAxis( ((XYPlot)plot).getRangeAxis(), boundaryPct );
- }
- if ( plot instanceof CategoryPlot )
- centerAxis( ((CategoryPlot)plot).getRangeAxis(), boundaryPct );
- }
+ /**
+ * Sets all chart legends (in)visible.
+ *
+ * @param chart
+ * a chart to apply
+ * @param visible
+ * indicates the visible property
+ */
+ public static void setLegendVisible(JFreeChart chart, boolean visible) {
+ for (Object title : chart.getSubtitles())
+ if (title instanceof LegendTitle)
+ ((Title) title).setVisible(visible);
+ }
- /**
- * Creates a {@link XYItemRenderer} for the given stepped and stacked
- * properties.
- * @param type chart type
- * @param stepped stepped property
- * @param stacked stacked property
- */
- public static XYItemRenderer createXYRenderer(BasicChartStyle style) {
- return createXYRenderer(
- style.getType(),
- style.isStepped(),
- style.isStacked()
- );
- }
-
- /**
- * Creates a {@link XYItemRenderer} for the given stepped and stacked
- * properties.
- * @param type chart type
- * @param stepped stepped property
- * @param stacked stacked property
- */
- public static XYItemRenderer createXYRenderer(ChartType type, boolean stepped, boolean stacked) {
- switch ( type ) {
- case LINE: // "stacked" is not available for line charts
- if ( stacked )
- LOGGER.warn("Stacked property can not be applied to line charts. Property ignored!");
- // Create renderer according to "stepped"
- if ( stepped )
- return new XYStepRenderer();
- // normal line renderer
- return new XYLineAndShapeRenderer(true, false);
- case AREA: // Apply stacked
- if ( stacked ) {
- // "stacked" and "stepped" can not be applied the same time
- if ( stepped )
- LOGGER.warn("A stacked area chart can not be stepped the same time (use a stacked bar chart instead). Stepped propery ignored!");
- // Stacked area renderer
- return new StackedXYAreaRenderer2();
- }
- // Stepped area renderer
- if ( stepped )
- return new XYStepAreaRenderer(XYStepAreaRenderer.AREA);
- // Neither stepped nor stepped
- return new XYAreaRenderer(XYAreaRenderer.AREA);
- case BAR: // bar charts are automatically stepped,
- // so only "stacked" is applied
- if ( stacked )
- return new StackedXYBarRenderer();
- // Normal bar renderer
- return new XYBarRenderer();
- }
- throw new UnsupportedOperationException("XYItemRenderer could not be created for chart type: "+type);
- }
+ /**
+ * Fires a change event to all {@link PlotChangeListener} connected to the
+ * plot.
+ *
+ * @param plot
+ * a plot
+ */
+ public static void fireChangeEvent(Plot plot) {
+ plot.notifyListeners(new PlotChangeEvent(plot));
+ }
-
- /**
- * Creates a {@link CategoryItemRenderer} for the given stepped and stacked
- * properties.
- * @param type chart type
- * @param stepped stepped property
- * @param stacked stacked property
- */
- public static CategoryItemRenderer createCategoryRenderer(BasicChartStyle style) {
- return createCategoryRenderer(
- style.getType(),
- style.isStepped(),
- style.isStacked()
- );
- }
-
- /**
- * Creates a {@link CategoryItemRenderer} for the given stepped and stacked
- * properties.
- * @param type chart type
- * @param stepped stepped property
- * @param stacked stacked property
- */
- public static CategoryItemRenderer createCategoryRenderer(ChartType type, boolean stepped, boolean stacked) {
- switch ( type ) {
- case LINE: // "stacked" is not available for line charts
- if ( stacked )
- LOGGER.warn("Stacked property can not be applied to line charts. Property ignored!");
- // Create renderer according to "stepped"
- if ( stepped )
- return new CategoryStepRenderer();
- // normal line renderer
- return new LineAndShapeRenderer(true, false);
- case AREA: // category area chart is automatically stepped,
- // so only "stacked" is applied
- if ( stacked )
- return new StackedAreaRenderer(false);
- // Normal area renderer
- return new AreaRenderer();
- case BAR: // bar charts are automatically stepped,
- // so only "stacked" is applied
- if ( stacked )
- return new StackedBarRenderer(false);
- // Normal bar renderer
- return new BarRenderer();
- }
- throw new UnsupportedOperationException("CategoryItemRenderer could not be created for chart type: "+type);
- }
+ /**
+ * Fires a change event to all {@link RendererChangeListener} connected to
+ * the renderer.
+ *
+ * @param renderer
+ * a renderer
+ */
+ public static void fireChangeEvent(AbstractRenderer renderer) {
+ renderer.notifyListeners(new RendererChangeEvent(renderer, true));
+ }
- /**
- * Returns the renderer for the {@code i}-th dataset of a plot.
- * @param plot a plot
- * @param index the dataset index
- * @return the primary renderer if no specific renderer is
- * set for dataset {@code i}
- */
- public static Object getRendererForDataset(Plot plot, int i) {
- Object renderer = null;
- if ( plot instanceof XYPlot ) {
- renderer = ((XYPlot)plot).getRenderer(i);
- if ( renderer == null )
- renderer = ((XYPlot)plot).getRenderer();
- }
+ /**
+ * Returns the maximum extend of a {@link Range} including a given boundary.
+ *
+ * @param range
+ * a {@link Range}
+ * @param boundaryPct
+ * extends the {@link Range} bound by percentage (if {@code null}
+ * {@value #DEFAULT_CENTRATION_BOUNDARY_PCT} is used).
+ * @return a value >= 0
+ */
+ public static double getAbsRange(Range range, Double boundaryPct) {
+ if (boundaryPct == null)
+ boundaryPct = DEFAULT_CENTRATION_BOUNDARY_PCT;
+ return Math.max(Math.abs(range.getUpperBound()), Math.abs(range
+ .getLowerBound()))
+ * (1 + boundaryPct);
+ }
- if ( plot instanceof CategoryPlot ) {
- renderer = ((CategoryPlot)plot).getRenderer(i);
- if ( renderer == null )
- renderer = ((CategoryPlot)plot).getRenderer();
- }
-
- return renderer;
- }
-
- /**
- * Searchs the renderers of a plot for {@link SelectionRenderer} for
- * a {@link Dataset}.
- * @param plot the plot to check for renderer
- * @param dataset the dataset a {@link SelectionRenderer} is
- * searched for
- * @return {@code null} if there is no {@link SelectionRenderer} defined
- * for the dataset
- */
- public static SelectionRenderer<?> getSelectionRendererForDataset(Plot plot, Dataset dataset) {
- if ( plot instanceof XYPlot ) {
- XYPlot xyPlot = (XYPlot)plot;
- for (int i=0; i<xyPlot.getDatasetCount(); i++) {
- Dataset d = xyPlot.getDataset(i);
- if ( d != dataset )
- continue;
- // determine renderer for dataset (if no renderer is set,
- // take the primary renderer)
- XYItemRenderer r = xyPlot.getRenderer(i);
- if ( r == null )
- r = xyPlot.getRenderer();
- // stop search, if renderer is a SelectionRenderer
- if ( r instanceof SelectionRenderer<?> )
- return (SelectionRenderer<?>)r;
- }
- }
+ /**
+ * Returns a new centered {@link Range} defined as [-maxAbs; maxAbs] of a
+ * given {@link Range}.
+ *
+ * @param range
+ * the {@link Range} to center
+ * @param boundaryPct
+ * extends the range's absolute maximum by percentage (if {@code
+ * null} {@value #DEFAULT_CENTRATION_BOUNDARY_PCT} is used).
+ * @return a new {@link Range} object
+ */
+ public static Range centerRange(Range range, Double boundaryPct) {
+ double absMax = getAbsRange(range, boundaryPct);
+ return new Range(-absMax, absMax);
+ }
- if ( plot instanceof CategoryPlot ) {
- CategoryPlot catPlot = (CategoryPlot)plot;
- for (int i=0; i<catPlot.getDatasetCount(); i++) {
- Dataset d = catPlot.getDataset(i);
- if ( d != dataset )
- continue;
- // determine renderer for dataset (if no renderer is set,
- // take the primary renderer)
- CategoryItemRenderer r = catPlot.getRenderer(i);
- if ( r == null )
- r = catPlot.getRenderer();
- // stop search, if renderer is a SelectionRenderer
- if ( r instanceof SelectionRenderer<?> )
- return (SelectionRenderer<?>)r;
- }
- }
-
- return null;
- }
-
- /**
- * Searchs the renderers of a plot for {@link SelectionRenderer} for
- * a {@link Dataset} and returns its {@link DatasetSelectionModel}.
- * @param plot the plot to check for renderer
- * @param dataset the dataset a {@link SelectionRenderer} is
- * searched for
- * @return {@code null} if there is no {@link SelectionRenderer} defined
- * for the dataset
- */
- public static DatasetSelectionModel<?,?,?> getSelectionModelForDataset(Plot plot, Dataset dataset) {
- SelectionRenderer<?> selRenderer = getSelectionRendererForDataset(plot, dataset);
- if ( selRenderer != null )
- return selRenderer.getSelectionModel();
- return null;
- }
+ /**
+ * Centers a gives {@link Axis} around 0 (if normalized) or around it's
+ * center.
+ *
+ * @param axis
+ * the {@link Axis} to center
+ * @param boundaryPct
+ * extends the axis range's absolute maximum by percentage (if
+ * {@code null} {@value #DEFAULT_CENTRATION_BOUNDARY_PCT} is
+ * used).
+ * @param symmetric
+ * If <code>true</code> the axis is centered symetrically
+ */
+ public static void zoomAxisToFullExtend(ValueAxis axis, Double boundaryPct,
+ boolean symmetric) {
+ // first recalculate the full extend (unfortunately the listeners are
+ // called; the method to de-activate this behavior is protected!)
+ axis.setAutoRange(true);
+ // then reset the centering
+ if (symmetric) {
+ double absMax = getAbsRange(axis.getRange(), boundaryPct);
+ axis.setRange(-absMax, absMax);
+ } else {
+ axis.setRange(axis.getRange().getLowerBound(), axis.getRange()
+ .getUpperBound());
+ }
+ }
- /**
- * Returns all {@link SelectionRenderer} for a {@link Plot}.
- * @param plot the plot to check for renderer
- * @return never {@code null}
- */
- public static Map<Integer,SelectionRenderer<?>> getSelectionRenderer(Plot plot) {
- Map<Integer,SelectionRenderer<?>> selRenderer = new HashMap<Integer,SelectionRenderer<?>>();
-
- if ( plot instanceof XYPlot ) {
- XYPlot xyPlot = (XYPlot)plot;
- for (int i=0; i<xyPlot.getRendererCount(); i++) {
- XYItemRenderer r = xyPlot.getRenderer(i);
- if ( r instanceof SelectionRenderer<?> )
- selRenderer.put(i, (SelectionRenderer<?>)r);
- }
- }
+ /**
+ * Centers a gives {@link Plot}. For
+ * {@link CategoryPlot} only the range axis is centered.
+ *
+ * @param axis
+ * the {@link Plot} to center
+ * @param boundaryPct
+ * percentage boundary the absolute maximum is extended with
+ * @param symetric
+ * If <code>true</code> the axis is centered symmetrically around it medium.
+ */
+ public static void zoomPlotToFullExtend(Plot plot, Double boundaryPct,
+ boolean symetric) {
+ if (plot instanceof XYPlot) {
+ zoomAxisToFullExtend(((XYPlot) plot).getDomainAxis(), boundaryPct, symetric);
+ zoomAxisToFullExtend(((XYPlot) plot).getRangeAxis(), boundaryPct, symetric);
+ }
+ if (plot instanceof CategoryPlot)
+ zoomAxisToFullExtend(((CategoryPlot) plot).getRangeAxis(), boundaryPct, symetric);
+ }
- if ( plot instanceof CategoryPlot ) {
- CategoryPlot catPlot = (CategoryPlot)plot;
- for (int i=0; i<catPlot.getRendererCount(); i++) {
- CategoryItemRenderer r = catPlot.getRenderer(i);
- if ( r instanceof SelectionRenderer<?> )
- selRenderer.put(i, (SelectionRenderer<?>)r);
- }
- }
-
- return selRenderer;
- }
-
- /**
- * Searchs the renderers of a plot for all {@link SelectionRenderer}
- * and returns their {@link DatasetSelectionModel DatasetSelectionModels}.
- * @param plot the plot to check for renderer
- * @return never {@code null}
- */
- public static Map<Integer,DatasetSelectionModel<?,?,?>> getSelectionModels(Plot plot) {
- Map<Integer,SelectionRenderer<?>> selRenderer = getSelectionRenderer(plot);
- Map<Integer,DatasetSelectionModel<?,?,?>> selModels = new HashMap<Integer, DatasetSelectionModel<?,?,?>>();
- for (int dataset : selRenderer.keySet())
- selModels.put(dataset, selRenderer.get(dataset).getSelectionModel());
- return selModels;
- }
-
- /**
- * Returns the (first) dataset of a {@link Plot} which is rendererd
- * by a renderer.
- * @param plot the plot which holds the datasets and renderer
- * @param renderer the renderer a dataset is seached for
- * @return {@code null} if there is no dataset which is rendered
- * by the given renderer
- */
- public static Dataset getDatasetForRenderer(Plot plot, Object renderer) {
- if ( plot instanceof XYPlot ) {
- XYPlot xyPlot = (XYPlot)plot;
- for (int i=0; i<xyPlot.getRendererCount(); i++)
- if ( xyPlot.getRenderer(i) == renderer )
- return xyPlot.getDataset(i);
- }
+ /**
+ * Creates a {@link XYItemRenderer} for the given stepped and stacked
+ * properties.
+ *
+ * @param type
+ * chart type
+ * @param stepped
+ * stepped property
+ * @param stacked
+ * stacked property
+ */
+ public static XYItemRenderer createXYRenderer(BasicChartStyle style) {
+ return createXYRenderer(style.getType(), style.isStepped(), style
+ .isStacked());
+ }
- if ( plot instanceof CategoryPlot ) {
- CategoryPlot catPlot = (CategoryPlot)plot;
- for (int i=0; i<catPlot.getRendererCount(); i++)
- if ( catPlot.getRenderer(i) == renderer )
- return catPlot.getDataset(i);
- }
-
- return null;
- }
+ /**
+ * Creates a {@link XYItemRenderer} for the given stepped and stacked
+ * properties.
+ *
+ * @param type
+ * chart type
+ * @param stepped
+ * stepped property
+ * @param stacked
+ * stacked property
+ */
+ public static XYItemRenderer createXYRenderer(ChartType type,
+ boolean stepped, boolean stacked) {
+ switch (type) {
+ case LINE: // "stacked" is not available for line charts
+ if (stacked)
+ LOGGER
+ .warn("Stacked property can not be applied to line charts. Property ignored!");
+ // Create renderer according to "stepped"
+ if (stepped)
+ return new XYStepRenderer();
+ // normal line renderer
+ return new XYLineAndShapeRenderer(true, false);
+ case AREA: // Apply stacked
+ if (stacked) {
+ // "stacked" and "stepped" can not be applied the same time
+ if (stepped)
+ LOGGER
+ .warn("A stacked area chart can not be stepped the same time (use a stacked bar chart instead). Stepped propery ignored!");
+ // Stacked area renderer
+ return new StackedXYAreaRenderer2();
+ }
+ // Stepped area renderer
+ if (stepped)
+ return new XYStepAreaRenderer(XYStepAreaRenderer.AREA);
+ // Neither stepped nor stepped
+ return new XYAreaRenderer(XYAreaRenderer.AREA);
+ case BAR: // bar charts are automatically stepped,
+ // so only "stacked" is applied
+ if (stacked)
+ return new StackedXYBarRenderer();
+ // Normal bar renderer
+ return new XYBarRenderer();
+ }
+ throw new UnsupportedOperationException(
+ "XYItemRenderer could not be created for chart type: " + type);
+ }
- /**
- * Applies general dataset properties to a {@link Dataset}.
- * @param dataset dataset the properties are applied to
- * @param sample dataset the properties are taken from
- */
- public static void applyDatasetProperties(Dataset dataset, Dataset sample) {
- dataset.setGroup( sample.getGroup() );
- }
-
- /**
- * Creates a {@link JFreeChart} which shows a point for each data item and
- * a the appropriate regression line.
- * @param dataset the data
- * @param title title for the chart
- * @param xAxisTitle title for the X-Axis
- * @param yAxisTitle title for the Y-Axis
- * @param regressionLine indicates whether the regression line is shown
- */
- public static JFreeChart createRegressionChart(XYDataset dataset, String title, String xAxisTitle, String yAxisTitle, boolean regressionLine) {
- if ( regressionLine && !(dataset instanceof XYSeriesCollection) )
- throw new UnsupportedOperationException("Regression line can only be created for XYSeriesCollection!");
-
- NumberAxis xAxis = new NumberAxis(xAxisTitle);
- xAxis.setAutoRangeIncludesZero(false);
- NumberAxis yAxis = new NumberAxis(yAxisTitle);
- yAxis.setAutoRangeIncludesZero(false);
+ /**
+ * Creates a {@link CategoryItemRenderer} for the given stepped and stacked
+ * properties.
+ *
+ * @param type
+ * chart type
+ * @param stepped
+ * stepped property
+ * @param stacked
+ * stacked property
+ */
+ public static CategoryItemRenderer createCategoryRenderer(
+ BasicChartStyle style) {
+ return createCategoryRenderer(style.getType(), style.isStepped(), style
+ .isStacked());
+ }
- XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
- XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
- XYURLGenerator urlGenerator = new StandardXYURLGenerator();
- XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
-
- renderer.setBaseToolTipGenerator(toolTipGenerator);
- renderer.setURLGenerator(urlGenerator);
- plot.setRenderer(renderer);
- plot.setOrientation(PlotOrientation.VERTICAL);
+ /**
+ * Creates a {@link CategoryItemRenderer} for the given stepped and stacked
+ * properties.
+ *
+ * @param type
+ * chart type
+ * @param stepped
+ * stepped property
+ * @param stacked
+ * stacked property
+ */
+ public static CategoryItemRenderer createCategoryRenderer(ChartType type,
+ boolean stepped, boolean stacked) {
+ switch (type) {
+ case LINE: // "stacked" is not available for line charts
+ if (stacked)
+ LOGGER
+ .warn("Stacked property can not be applied to line charts. Property ignored!");
+ // Create renderer according to "stepped"
+ if (stepped)
+ return new CategoryStepRenderer();
+ // normal line renderer
+ return new LineAndShapeRenderer(true, false);
+ case AREA: // category area chart is automatically stepped,
+ // so only "stacked" is applied
+ if (stacked)
+ return new StackedAreaRenderer(false);
+ // Normal area renderer
+ return new AreaRenderer();
+ case BAR: // bar charts are automatically stepped,
+ // so only "stacked" is applied
+ if (stacked)
+ return new StackedBarRenderer(false);
+ // Normal bar renderer
+ return new BarRenderer();
+ }
+ throw new UnsupportedOperationException(
+ "CategoryItemRenderer could not be created for chart type: "
+ + type);
+ }
- // Create Regression line
- if ( regressionLine) {
+ /**
+ * Returns the renderer for the {@code i}-th dataset of a plot.
+ *
+ * @param plot
+ * a plot
+ * @param index
+ * the dataset index
+ * @return the primary renderer if no specific renderer is set for dataset
+ * {@code i}
+ */
+ public static Object getRendererForDataset(Plot plot, int i) {
+ Object renderer = null;
+ if (plot instanceof XYPlot) {
+ renderer = ((XYPlot) plot).getRenderer(i);
+ if (renderer == null)
+ renderer = ((XYPlot) plot).getRenderer();
+ }
- // only if there are at least 2 items, otherwise we would get a IllegalArgumentException
- if ( ((XYSeriesCollection)dataset).getItemCount(0)>=2 ) {
- // create sample data for curve (plot function directly is not yet available)
- XYDataset regressionData = createRegressionLineDataset((XYSeriesCollection)dataset,0,title+" Regression line",2);
- if ( regressionData != null )
- addRegressionLineToPlot(plot, regressionData, Color.blue);
- } else {
- LOGGER.info("Not enought items in the series to create a regression line.");
- }
- }
- JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
+ if (plot instanceof CategoryPlot) {
+ renderer = ((CategoryPlot) plot).getRenderer(i);
+ if (renderer == null)
+ renderer = ((CategoryPlot) plot).getRenderer();
+ }
- return chart; //ChartFactory.createScatterPlot(title, xAttr, yAttr, dataset, PlotOrientation.HORIZONTAL, true, true, true);
- }
+ return renderer;
+ }
- /**
- * Creates sample data for a regression line of an {@link XYDataset}.
- * @param dataset data the regression line is created for
- * @param series series of {@code dataset} the regression line is created for
- * @param seriesKey the key for the created dataset
- * @param sampleCnt count of created samples
- */
- public static XYDataset createRegressionLineDataset(XYSeriesCollection dataset, int series, String seriesKey, int sampleCount) {
- double minX = dataset.getSeries(0).getMinX();
- double maxX = dataset.getSeries(0).getMaxX();
- return createRegressionLineDataset(dataset,series,seriesKey,minX,maxX,sampleCount);
- }
+ /**
+ * Searchs the renderers of a plot for {@link SelectionRenderer} for a
+ * {@link Dataset}.
+ *
+ * @param plot
+ * the plot to check for renderer
+ * @param dataset
+ * the dataset a {@link SelectionRenderer} is searched for
+ * @return {@code null} if there is no {@link SelectionRenderer} defined for
+ * the dataset
+ */
+ public static SelectionRenderer<?> getSelectionRendererForDataset(
+ Plot plot, Dataset dataset) {
+ if (plot instanceof XYPlot) {
+ XYPlot xyPlot = (XYPlot) plot;
+ for (int i = 0; i < xyPlot.getDatasetCount(); i++) {
+ Dataset d = xyPlot.getDataset(i);
+ if (d != dataset)
+ continue;
+ // determine renderer for dataset (if no renderer is set,
+ // take the primary renderer)
+ XYItemRenderer r = xyPlot.getRenderer(i);
+ if (r == null)
+ r = xyPlot.getRenderer();
+ // stop search, if renderer is a SelectionRenderer
+ if (r instanceof SelectionRenderer<?>)
+ return (SelectionRenderer<?>) r;
+ }
+ }
- /**
- * Creates sample data for a regression line of an {@link XYDataset}.
- * @param dataset data the regression line is created for
- * @param series series of {@code dataset} the regression line is created for
- * @param seriesKey the key for the created dataset
- * @param startX the first value the sample data is created for
- * @param endX the last value the sample data is created for
- * @param sampleCnt count of created samples
- * @return {@code null} if the regression data could not be created (because of an
- * error
- */
- public static XYDataset createRegressionLineDataset(XYDataset dataset, int series, String seriesKey, double startX, double endX, int sampleCount) {
- try {
- double[] coefficients = Regression.getOLSRegression(dataset, series);
-
- seriesKey += " r²=" + DecimalFormat.getInstance().format(coefficients[1]*coefficients[1]);
-
- Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
- return DatasetUtilities.sampleFunction2D(curve, startX, endX, 2, seriesKey);
- } catch (Exception err) {
- // according to the data sometimes the regression
- // dataset could not be created
- LOGGER.warn("Regression line could not be created: "+err.getLocalizedMessage());
- return null;
- }
- }
+ if (plot instanceof CategoryPlot) {
+ CategoryPlot catPlot = (CategoryPlot) plot;
+ for (int i = 0; i < catPlot.getDatasetCount(); i++) {
+ Dataset d = catPlot.getDataset(i);
+ if (d != dataset)
+ continue;
+ // determine renderer for dataset (if no renderer is set,
+ // take the primary renderer)
+ CategoryItemRenderer r = catPlot.getRenderer(i);
+ if (r == null)
+ r = catPlot.getRenderer();
+ // stop search, if renderer is a SelectionRenderer
+ if (r instanceof SelectionRenderer<?>)
+ return (SelectionRenderer<?>) r;
+ }
+ }
- /**
- * Adds a line plot for regression data to a plot.
- * @param plot the plot the line is added to (at the end)
- * @param regressionData the regression data
- * @param lineColor the color for the regression line
- */
- public static void addRegressionLineToPlot(XYPlot plot, XYDataset regressionData, Color lineColor) {
- int datasetCount = plot.getDatasetCount();
- // set the regression data
- plot.setDataset(datasetCount, regressionData);
- // create and set the renderer for the regression line
- XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,false);
- renderer.setSeriesPaint(0, Color.blue);
- plot.setRenderer(datasetCount, renderer);
- }
+ return null;
+ }
+ /**
+ * Searchs the renderers of a plot for {@link SelectionRenderer} for a
+ * {@link Dataset} and returns its {@link DatasetSelectionModel}.
+ *
+ * @param plot
+ * the plot to check for renderer
+ * @param dataset
+ * the dataset a {@link SelectionRenderer} is searched for
+ * @return {@code null} if there is no {@link SelectionRenderer} defined for
+ * the dataset
+ */
+ public static DatasetSelectionModel<?, ?, ?> getSelectionModelForDataset(
+ Plot plot, Dataset dataset) {
+ SelectionRenderer<?> selRenderer = getSelectionRendererForDataset(plot,
+ dataset);
+ if (selRenderer != null)
+ return selRenderer.getSelectionModel();
+ return null;
+ }
+ /**
+ * Returns all {@link SelectionRenderer} for a {@link Plot}.
+ *
+ * @param plot
+ * the plot to check for renderer
+ * @return never {@code null}
+ */
+ public static Map<Integer, SelectionRenderer<?>> getSelectionRenderer(
+ Plot plot) {
+ Map<Integer, SelectionRenderer<?>> selRenderer = new HashMap<Integer, SelectionRenderer<?>>();
-//###################
-// BISHER NUR WILDE TESTS
-//###################
-// /**
-// * Converts a Excel file to CVS format.
-// * @param xlsInput stream to Excel source
-// * @param sheetName name of the sheet in the Excel source (if {@code null} the
-// * first sheet is used)
-// * @param headRow indicates whether the first row contains the column names
-// * @param csvHeader indicates whether the column names are also taken to the CVS (note:
-// * if {@code true} and {@code headRow = false} dummy column
-// * names "A", "B", ... are generates in CVS!)
-// * @param delimChr character takes as delimiter in CSV
-// * @param strEncChr character String values are encapsulated with (if {@code null}, Strings
-// * are not encapsulated)
-// */
-// public static InputStream createCSVFromXLS(InputStream xlsInput, String sheetName, boolean headRow, boolean csvHeader, String delimChr, String strEncChar) throws IOException {
-// PipedOutputStream csvOutput = new PipedOutputStream();
-//
-// // read XLS and create a CSV
-// HSSFWorkbook wb = new HSSFWorkbook( new POIFSFileSystem(xlsInput) );
-// HSSFSheet sheet = ( sheetName != null ) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
-//
-// int firstRow = sheet.getFirstRowNum();
-// int lastRow = sheet.getLastRowNum();
-//// int rowCount = sheet.getPhysicalNumberOfRows();
-// for (int y=firstRow; y <= lastRow; y++) {
-// HSSFRow row = sheet.getRow(y);
-// int firstCol = row.getFirstCellNum();
-// int lastCol = row.getLastCellNum();
-// for (int x=firstCol; x <= lastCol; x++) {
-// HSSFCell cell = row.getCell(x);
-//// String csvValue = convertCellValueToString(cell,???);
-// }
-// }
-//
-// return new PipedInputStream(csvOutput);
-// }
-//
-// public static String convertCellValueToString(HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator) {
-// String strValue = "";
-// switch( cell.getCellType() ) {
-// case HSSFCell.CELL_TYPE_BOOLEAN: strValue = ""+cell.getBooleanCellValue();
-// break;
-// case HSSFCell.CELL_TYPE_NUMERIC: strValue = ""+cell.getNumericCellValue();
-// break;
-// case HSSFCell.CELL_TYPE_FORMULA: strValue = ""+cell.getNumericCellValue();
-// }
-// return strValue;
-//
-// }
-//
-// /**
-// * Creates a Dataset from Excel file.
-// * @param xlsInput stream to Excel source
-// * @param sheetName name of the sheet in the Excel source (if {@code null} the
-// * first sheet is used)
-// */
-// public static CategoryDataset createDatasetFromXLS(InputStream xlsInput, String sheetName) throws IOException {
-// PipedOutputStream csvOutput = new PipedOutputStream();
-// InputStreamReader csvInput = new InputStreamReader( new PipedInputStream(csvOutput) );
-//
-//
-//// return new CSV(';','"').readCategoryDataset(csvInput);
-//
-// HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(xlsInput));
-// ExcelExtractor extractor = new ExcelExtractor(wb);
-//
-// extractor.setFormulasNotResults(false);
-// extractor.setIncludeSheetNames(false);
-// String text = extractor.getText();
-// System.out.println(text);
-// return null;
-// }
+ if (plot instanceof XYPlot) {
+ XYPlot xyPlot = (XYPlot) plot;
+ for (int i = 0; i < xyPlot.getRendererCount(); i++) {
+ XYItemRenderer r = xyPlot.getRenderer(i);
+ if (r instanceof SelectionRenderer<?>)
+ selRenderer.put(i, (SelectionRenderer<?>) r);
+ }
+ }
+
+ if (plot instanceof CategoryPlot) {
+ CategoryPlot catPlot = (CategoryPlot) plot;
+ for (int i = 0; i < catPlot.getRendererCount(); i++) {
+ CategoryItemRenderer r = catPlot.getRenderer(i);
+ if (r instanceof SelectionRenderer<?>)
+ selRenderer.put(i, (SelectionRenderer<?>) r);
+ }
+ }
+
+ return selRenderer;
+ }
+
+ /**
+ * Searchs the renderers of a plot for all {@link SelectionRenderer} and
+ * returns their {@link DatasetSelectionModel DatasetSelectionModels}.
+ *
+ * @param plot
+ * the plot to check for renderer
+ * @return never {@code null}
+ */
+ public static Map<Integer, DatasetSelectionModel<?, ?, ?>> getSelectionModels(
+ Plot plot) {
+ Map<Integer, SelectionRenderer<?>> selRenderer = getSelectionRenderer(plot);
+ Map<Integer, DatasetSelectionModel<?, ?, ?>> selModels = new HashMap<Integer, DatasetSelectionModel<?, ?, ?>>();
+ for (int dataset : selRenderer.keySet())
+ selModels
+ .put(dataset, selRenderer.get(dataset).getSelectionModel());
+ return selModels;
+ }
+
+ /**
+ * Returns the (first) dataset of a {@link Plot} which is rendererd by a
+ * renderer.
+ *
+ * @param plot
+ * the plot which holds the datasets and renderer
+ * @param renderer
+ * the renderer a dataset is seached for
+ * @return {@code null} if there is no dataset which is rendered by the
+ * given renderer
+ */
+ public static Dataset getDatasetForRenderer(Plot plot, Object renderer) {
+ if (plot instanceof XYPlot) {
+ XYPlot xyPlot = (XYPlot) plot;
+ for (int i = 0; i < xyPlot.getRendererCount(); i++)
+ if (xyPlot.getRenderer(i) == renderer)
+ return xyPlot.getDataset(i);
+ }
+
+ if (plot instanceof CategoryPlot) {
+ CategoryPlot catPlot = (CategoryPlot) plot;
+ for (int i = 0; i < catPlot.getRendererCount(); i++)
+ if (catPlot.getRenderer(i) == renderer)
+ return catPlot.getDataset(i);
+ }
+
+ return null;
+ }
+
+ /**
+ * Applies general dataset properties to a {@link Dataset}.
+ *
+ * @param dataset
+ * dataset the properties are applied to
+ * @param sample
+ * dataset the properties are taken from
+ */
+ public static void applyDatasetProperties(Dataset dataset, Dataset sample) {
+ dataset.setGroup(sample.getGroup());
+ }
+
+ /**
+ * Creates a {@link JFreeChart} which shows a point for each data item and a
+ * the appropriate regression line.
+ *
+ * @param dataset
+ * the data
+ * @param title
+ * title for the chart
+ * @param xAxisTitle
+ * title for the X-Axis
+ * @param yAxisTitle
+ * title for the Y-Axis
+ * @param regressionLine
+ * indicates whether the regression line is shown
+ */
+ public static JFreeChart createRegressionChart(XYDataset dataset,
+ String title, String xAxisTitle, String yAxisTitle,
+ boolean regressionLine) {
+ if (regressionLine && !(dataset instanceof XYSeriesCollection))
+ throw new UnsupportedOperationException(
+ "Regression line can only be created for XYSeriesCollection!");
+
+ NumberAxis xAxis = new NumberAxis(xAxisTitle);
+ xAxis.setAutoRangeIncludesZero(false);
+ NumberAxis yAxis = new NumberAxis(yAxisTitle);
+ yAxis.setAutoRangeIncludesZero(false);
+
+ XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
+ XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
+ XYURLGenerator urlGenerator = new StandardXYURLGenerator();
+ XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
+
+ renderer.setBaseToolTipGenerator(toolTipGenerator);
+ renderer.setURLGenerator(urlGenerator);
+ plot.setRenderer(renderer);
+ plot.setOrientation(PlotOrientation.VERTICAL);
+
+ // Create Regression line
+ if (regressionLine) {
+
+ // only if there are at least 2 items, otherwise we would get a
+ // IllegalArgumentException
+ if (((XYSeriesCollection) dataset).getItemCount(0) >= 2) {
+ // create sample data for curve (plot function directly is not
+ // yet available)
+ XYDataset regressionData = createRegressionLineDataset(
+ (XYSeriesCollection) dataset, 0, title
+ + " Regression line", 2);
+ if (regressionData != null)
+ addRegressionLineToPlot(plot, regressionData, Color.blue);
+ } else {
+ LOGGER
+ .info("Not enought items in the series to create a regression line.");
+ }
+ }
+ JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
+ plot, true);
+
+ return chart; // ChartFactory.createScatterPlot(title, xAttr, yAttr,
+ // dataset, PlotOrientation.HORIZONTAL, true, true,
+ // true);
+ }
+
+ /**
+ * Creates sample data for a regression line of an {@link XYDataset}.
+ *
+ * @param dataset
+ * data the regression line is created for
+ * @param series
+ * series of {@code dataset} the regression line is created for
+ * @param seriesKey
+ * the key for the created dataset
+ * @param sampleCnt
+ * count of created samples
+ */
+ public static XYDataset createRegressionLineDataset(
+ XYSeriesCollection dataset, int series, String seriesKey,
+ int sampleCount) {
+ double minX = dataset.getSeries(0).getMinX();
+ double maxX = dataset.getSeries(0).getMaxX();
+ return createRegressionLineDataset(dataset, series, seriesKey, minX,
+ maxX, sampleCount);
+ }
+
+ /**
+ * Creates sample data for a regression line of an {@link XYDataset}.
+ *
+ * @param dataset
+ * data the regression line is created for
+ * @param series
+ * series of {@code dataset} the regression line is created for
+ * @param seriesKey
+ * the key for the created dataset
+ * @param startX
+ * the first value the sample data is created for
+ * @param endX
+ * the last value the sample data is created for
+ * @param sampleCnt
+ * count of created samples
+ * @return {@code null} if the regression data could not be created (because
+ * of an error
+ */
+ public static XYDataset createRegressionLineDataset(XYDataset dataset,
+ int series, String seriesKey, double startX, double endX,
+ int sampleCount) {
+ try {
+ double[] coefficients = Regression
+ .getOLSRegression(dataset, series);
+
+ seriesKey += " r²="
+ + DecimalFormat.getInstance().format(
+ coefficients[1] * coefficients[1]);
+
+ Function2D curve = new LineFunction2D(coefficients[0],
+ coefficients[1]);
+ return DatasetUtilities.sampleFunction2D(curve, startX, endX, 2,
+ seriesKey);
+ } catch (Exception err) {
+ // according to the data sometimes the regression
+ // dataset could not be created
+ LOGGER.warn("Regression line could not be created: "
+ + err.getLocalizedMessage());
+ return null;
+ }
+ }
+
+ /**
+ * Adds a line plot for regression data to a plot.
+ *
+ * @param plot
+ * the plot the line is added to (at the end)
+ * @param regressionData
+ * the regression data
+ * @param lineColor
+ * the color for the regression line
+ */
+ public static void addRegressionLineToPlot(XYPlot plot,
+ XYDataset regressionData, Color lineColor) {
+ int datasetCount = plot.getDatasetCount();
+ // set the regression data
+ plot.setDataset(datasetCount, regressionData);
+ // create and set the renderer for the regression line
+ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,
+ false);
+ renderer.setSeriesPaint(0, Color.blue);
+ plot.setRenderer(datasetCount, renderer);
+ }
+
+ // ###################
+ // BISHER NUR WILDE TESTS
+ // ###################
+ // /**
+ // * Converts a Excel file to CVS format.
+ // * @param xlsInput stream to Excel source
+ // * @param sheetName name of the sheet in the Excel source (if {@code null}
+ // the
+ // * first sheet is used)
+ // * @param headRow indicates whether the first row contains the column
+ // names
+ // * @param csvHeader indicates whether the column names are also taken to
+ // the CVS (note:
+ // * if {@code true} and {@code headRow = false} dummy column
+ // * names "A", "B", ... are generates in CVS!)
+ // * @param delimChr character takes as delimiter in CSV
+ // * @param strEncChr character String values are encapsulated with (if
+ // {@code null}, Strings
+ // * are not encapsulated)
+ // */
+ // public static InputStream createCSVFromXLS(InputStream xlsInput, String
+ // sheetName, boolean headRow, boolean csvHeader, String delimChr, String
+ // strEncChar) throws IOException {
+ // PipedOutputStream csvOutput = new PipedOutputStream();
+ //
+ // // read XLS and create a CSV
+ // HSSFWorkbook wb = new HSSFWorkbook( new POIFSFileSystem(xlsInput) );
+ // HSSFSheet sheet = ( sheetName != null ) ? wb.getSheet(sheetName) :
+ // wb.getSheetAt(0);
+ //
+ // int firstRow = sheet.getFirstRowNum();
+ // int lastRow = sheet.getLastRowNum();
+ // // int rowCount = sheet.getPhysicalNumberOfRows();
+ // for (int y=firstRow; y <= lastRow; y++) {
+ // HSSFRow row = sheet.getRow(y);
+ // int firstCol = row.getFirstCellNum();
+ // int lastCol = row.getLastCellNum();
+ // for (int x=firstCol; x <= lastCol; x++) {
+ // HSSFCell cell = row.getCell(x);
+ // // String csvValue = convertCellValueToString(cell,???);
+ // }
+ // }
+ //
+ // return new PipedInputStream(csvOutput);
+ // }
+ //
+ // public static String convertCellValueToString(HSSFCell cell,
+ // HSSFFormulaEvaluator formulaEvaluator) {
+ // String strValue = "";
+ // switch( cell.getCellType() ) {
+ // case HSSFCell.CELL_TYPE_BOOLEAN: strValue =
+ // ""+cell.getBooleanCellValue();
+ // break;
+ // case HSSFCell.CELL_TYPE_NUMERIC: strValue =
+ // ""+cell.getNumericCellValue();
+ // break;
+ // case HSSFCell.CELL_TYPE_FORMULA: strValue =
+ // ""+cell.getNumericCellValue();
+ // }
+ // return strValue;
+ //
+ // }
+ //
+ // /**
+ // * Creates a Dataset from Excel file.
+ // * @param xlsInput stream to Excel source
+ // * @param sheetName name of the sheet in the Excel source (if {@code null}
+ // the
+ // * first sheet is used)
+ // */
+ // public static CategoryDataset createDatasetFromXLS(InputStream xlsInput,
+ // String sheetName) throws IOException {
+ // PipedOutputStream csvOutput = new PipedOutputStream();
+ // InputStreamReader csvInput = new InputStreamReader( new
+ // PipedInputStream(csvOutput) );
+ //
+ //
+ // // return new CSV(';','"').readCategoryDataset(csvInput);
+ //
+ // HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(xlsInput));
+ // ExcelExtractor extractor = new ExcelExtractor(wb);
+ //
+ // extractor.setFormulasNotResults(false);
+ // extractor.setIncludeSheetNames(false);
+ // String text = extractor.getText();
+ // System.out.println(text);
+ // return null;
+ // }
}
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionXYRenderer.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionXYRenderer.java 2009-10-23 18:43:58 UTC (rev 497)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionXYRenderer.java 2009-10-25 13:18:01 UTC (rev 498)
@@ -30,9 +30,15 @@
package schmitzm.jfree.chart.renderer;
import java.awt.Color;
+import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.TexturePaint;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
import org.apache.log4j.Logger;
import org.jfree.chart.axis.ValueAxis;
@@ -44,6 +50,7 @@
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
+import org.jfree.util.BooleanList;
import schmitzm.jfree.JFreeChartUtil;
import schmitzm.jfree.chart.selection.SeriesDatasetSelectionModel;
@@ -75,6 +82,7 @@
/** Holds the selection color for each series. */
protected Paint selectionPaint = null;
+ protected Paint selectionOutlinePaint = null;
// protected Map<Integer,Paint> selectionPaint = new HashMap<Integer, Paint>();
/**
@@ -90,8 +98,11 @@
* of this renderer.
*/
protected void init() {
- // set a default highlight color for the primary series
- setSelectionPaint(Color.YELLOW);
+ setSelectionPaint(Color.YELLOW);
+ setSelectionOutlinePaint(Color.RED);
+
+ // Cost be one hour, because this was disabled by default .. grrrr
+ setUseOutlinePaint(true);
}
/**
@@ -169,10 +180,22 @@
*/
@Override
public void setSelectionPaint(Paint paint) {
-// setSelectionPaint(0, paint);
selectionPaint = paint;
}
+ /**
+ * Sets the color, the selected data <b>of the primary series</b>
+ * is rendered with.
+ * @param paint color for the selected data
+ */
+ public void setSelectionOutlinePaint(Paint paint) {
+ selectionOutlinePaint = paint;
+ }
+
+ public Paint getSelectionOutlinePaint() {
+ return selectionOutlinePaint;
+ }
+
// /**
// * Returns the color, the selected data is rendered with.
// * @param series the data series
@@ -232,6 +255,11 @@
Comparable<?> seriesKey = dataset.getSeriesKey(series);
if ( selectionModel.isItemSelected(seriesKey, item) ) {
setSeriesPaint( series, selPaint, false );
+
+ if (getSelectionOutlinePaint() != null) {
+ setSeriesOutlinePaint(series, selectionOutlinePaint, false );
+ }
+
super.drawItem(g, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass);
}
} else
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java 2009-10-23 18:43:58 UTC (rev 497)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartPlotStyle.java 2009-10-25 13:18:01 UTC (rev 498)
@@ -410,7 +410,7 @@
// Axis origin centration
plot.getRangeAxis().setAutoRange(!isCenterOriginSymetrically());
if (isCenterOriginSymetrically()) {
- JFreeChartUtil.centerAxis( plot.getRangeAxis(), 0.1);
+ JFreeChartUtil.zoomAxisToFullExtend( plot.getRangeAxis(), 0.1, isCenterOriginSymetrically());
}
}
@@ -451,8 +451,8 @@
plot.getRangeAxis().setAutoRange(!isCenterOriginSymetrically());
plot.getDomainAxis().setAutoRange(!isCenterOriginSymetrically());
if (isCenterOriginSymetrically()) {
- JFreeChartUtil.centerAxis( plot.getDomainAxis(), 0.1);
- JFreeChartUtil.centerAxis( plot.getRangeAxis(), 0.1);
+ JFreeChartUtil.zoomAxisToFullExtend( plot.getDomainAxis(), 0.1, isCenterOriginSymetrically());
+ JFreeChartUtil.zoomAxisToFullExtend( plot.getRangeAxis(), 0.1, isCenterOriginSymetrically());
}
// TEST
plot.setDomainPannable(true);
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2009-10-23 18:43:58 UTC (rev 497)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2009-10-25 13:18:01 UTC (rev 498)
@@ -364,7 +364,7 @@
renderer.setSeriesShape(series,
shape,
false);
- LOGGER.debug("Setting shape = "+shape +" for series "+series);
+// LOGGER.debug("Setting shape = "+shape +" for series "+series);
}
} catch (Exception err) {
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/resource/icons/zoom_full_extend.png
===================================================================
(Binary files differ)
More information about the Schmitzm-commits
mailing list