[Schmitzm-commits] r501 - in branches/1.0-gt2-2.6/src/schmitzm/jfree/chart: . renderer

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 27 11:19:09 CET 2009


Author: mojays
Date: 2009-10-27 11:19:08 +0100 (Tue, 27 Oct 2009)
New Revision: 501

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/SelectableChartPanel.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionCategoryRenderer.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionXYRenderer.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionXYLineAndShapeRenderer.java
Log:
Applied "my code style" and JavaDoc to some changes.

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/SelectableChartPanel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/SelectableChartPanel.java	2009-10-25 16:56:21 UTC (rev 500)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/SelectableChartPanel.java	2009-10-27 10:19:08 UTC (rev 501)
@@ -29,6 +29,8 @@
  ******************************************************************************/
 package schmitzm.jfree.chart;
 
+import java.awt.BasicStroke;
+import java.awt.Color;
 import java.awt.event.MouseEvent;
 import java.awt.geom.Rectangle2D;
 import java.util.HashSet;
@@ -420,7 +422,7 @@
       
       selRenderer.setBaseShape( originRenderer.lookupSeriesShape(0) );
       selRenderer.setBaseStroke( originRenderer.lookupSeriesStroke(0) );
-      
+
       if ( dataset instanceof XYDataset ) {
         ((XYItemRenderer)selRenderer).setBaseToolTipGenerator( ((XYItemRenderer)originRenderer).getBaseToolTipGenerator() );
         for (int i=0; i<((XYDataset)dataset).getSeriesCount(); i++) {

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionCategoryRenderer.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionCategoryRenderer.java	2009-10-25 16:56:21 UTC (rev 500)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionCategoryRenderer.java	2009-10-27 10:19:08 UTC (rev 501)
@@ -32,6 +32,7 @@
 import java.awt.Color;
 import java.awt.Graphics2D;
 import java.awt.Paint;
+import java.awt.Stroke;
 import java.awt.geom.Rectangle2D;
 
 import org.apache.log4j.Logger;
@@ -75,11 +76,15 @@
    *  data item is selected or not. */
   protected CategoryDatasetSelectionModel selectionModel = null;
 
-  /** Holds the selection color for each series. */
+  /** Holds the color for selected items (used for all series). */
   protected Paint selectionPaint = null;
 
-private Paint selectionOutlinePaint;
+  /** Holds the outline paint for selected items (used for all series). */
+  protected Paint selectionOutlinePaint;
   
+//  /** Holds the selection {@link Stroke} (used for all series). */
+//  protected Stroke selectionStroke = null;
+
   /**
    * Creates a new renderer.
    */
@@ -156,8 +161,8 @@
   }
 
   /**
-   * Returns the color, the selected data <b>of the primary series</b>
-   * is rendered with.
+   * Returns the color, the selected data is rendered with. This color
+   * is used for all series.
    * @return {@code null} if no selection color is defined
    *         for the series
    */
@@ -166,7 +171,8 @@
   }
 
   /**
-   * Sets the color, the selected data is rendered with.
+   * Sets the color, the selected data is rendered with. This color
+   * is used for all series.
    * @param paint color for the selected data
    */
   public void setSelectionPaint(Paint paint) {
@@ -174,6 +180,45 @@
   }
   
   /**
+   * Returns the outline color for selected points. This paint is
+   * used for all series.
+   */
+  @Override
+  public Paint getSelectionOutlinePaint() {
+      return selectionOutlinePaint;
+  }
+  
+  /**
+   * Sets the outline paint for selected points. This paint is
+   * used for all series.
+   * @param paint a color
+   */
+  @Override
+  public void setSelectionOutlinePaint(Paint paint) {
+      selectionOutlinePaint = paint;
+  }
+
+//  /**
+//   * Returns the {@link Stroke}, the selected data is rendered with.
+//   * @return {@code null} if no special stroke is set (the base stroke
+//   *         should be used)
+//   */
+//  @Override
+//  public Stroke getSelectionStroke() {
+//    return selectionStroke;
+//  }
+//
+//  /**
+//   * Sets the {@link Stroke}, the selected data is rendered with.
+//   * @param stroke {@link Stroke} for the selected data (set to {@code null}
+//   *               if the base stroke should be used)
+//   */
+//  @Override
+//  public void setSelectionStroke(Stroke stroke) {
+//    this.selectionStroke = stroke;
+//  }
+
+  /**
    * Creates and sets a new {@link SeriesDatasetSelectionModel}, if no selection model
    * is set yet, or the selection model's dataset differs from the dataset of the
    * new plot.
@@ -212,7 +257,6 @@
         Comparable<?> itemKey   = dataset.getColumnKey(column);
         if ( selectionModel.isItemSelected(seriesKey, itemKey) ) {
           setSeriesPaint( row, selPaint, false );
-
           // Apply the selection outline color 
           if (getSelectionOutlinePaint() != null) 
         	  setSeriesOutlinePaint( row, getSelectionOutlinePaint(), false );
@@ -225,13 +269,4 @@
       LOGGER.debug("No selection model set for renderer. All series rendererd normally.");
   }
 
-	@Override
-	public Paint getSelectionOutlinePaint() {
-		return selectionOutlinePaint;
-	}
-	
-	@Override
-	public void setSelectionOutlinePaint(Paint paint) {
-		selectionOutlinePaint = paint;
-	}
 }

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-25 16:56:21 UTC (rev 500)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/PointSelectionXYRenderer.java	2009-10-27 10:19:08 UTC (rev 501)
@@ -29,10 +29,12 @@
  ******************************************************************************/
 package schmitzm.jfree.chart.renderer;
 
+import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Paint;
+import java.awt.Stroke;
 import java.awt.Rectangle;
 import java.awt.TexturePaint;
 import java.awt.geom.Ellipse2D;
@@ -80,11 +82,16 @@
    *  data item is selected or not. */
   protected SeriesDatasetSelectionModel selectionModel = null;
 
-  /** Holds the selection color for each series. */
+  /** Holds the selection color (used for all series). */
   protected Paint selectionPaint = null;
+//  protected Map<Integer,Paint> selectionPaint = new HashMap<Integer, Paint>();
+
+  /** Holds the outline paint for selected items (used for all series). */
   protected Paint selectionOutlinePaint = null;
-//  protected Map<Integer,Paint> selectionPaint = new HashMap<Integer, Paint>();
-  
+
+//  /** Holds the selection {@link Stroke} (used for all series). */
+//  protected Stroke selectionStroke = null;
+
   /**
    * Creates a new renderer.
    */
@@ -162,8 +169,8 @@
   }
 
   /**
-   * Returns the color, the selected data <b>of the primary series</b>
-   * is rendered with.
+   * Returns the color, the selected data is rendered with. This
+   * color is used for all series.
    * @return {@code null} if no selection color is defined
    *         for the series
    */
@@ -174,8 +181,8 @@
   }
 
   /**
-   * Sets the color, the selected data <b>of the primary series</b>
-   * is rendered with.
+   * Sets the color, the selected data is rendered with.  This
+   * color is used for all series.
    * @param paint color for the selected data
    */
   @Override
@@ -183,20 +190,47 @@
     selectionPaint = paint;
   }
 
+
   /**
-   * Sets the color, the selected data <b>of the primary series</b>
-   * is rendered with.
-   * @param paint color for the selected data
+   * Returns the outline color for selected points. This paint is
+   * used for all series.
    */
-  public void setSelectionOutlinePaint(Paint paint) {
-	  selectionOutlinePaint = paint;
+  @Override
+  public Paint getSelectionOutlinePaint() {
+      return selectionOutlinePaint;
   }
   
-  public Paint getSelectionOutlinePaint() {
-	  return selectionOutlinePaint;
+  /**
+   * Sets the outline paint for selected points. This paint is
+   * used for all series.
+   * @param paint a color
+   */
+  @Override
+  public void setSelectionOutlinePaint(Paint paint) {
+      selectionOutlinePaint = paint;
   }
 
 //  /**
+//   * Returns the {@link Stroke}, the selected data is rendered with.
+//   * @return {@code null} if no special stroke is set (the base stroke
+//   *         should be used)
+//   */
+//  @Override
+//  public Stroke getSelectionStroke() {
+//    return selectionStroke;
+//  }
+//
+//  /**
+//   * Sets the {@link Stroke}, the selected data is rendered with.
+//   * @param stroke {@link Stroke} for the selected data (set to {@code null}
+//   *               if the base stroke should be used)
+//   */
+//  @Override
+//  public void setSelectionStroke(Stroke stroke) {
+//    this.selectionStroke = stroke;
+//  }
+
+//  /**
 //   * Returns the color, the selected data is rendered with.
 //   * @param series the data series
 //   * @return {@code null} if no selection color is defined

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java	2009-10-25 16:56:21 UTC (rev 500)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java	2009-10-27 10:19:08 UTC (rev 501)
@@ -30,6 +30,7 @@
 package schmitzm.jfree.chart.renderer;
 
 import java.awt.Paint;
+import java.awt.Stroke;
 
 import schmitzm.jfree.chart.selection.DatasetSelectionModel;
 import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;
@@ -61,4 +62,18 @@
    * @param paint color for the selected data
    */
   public void setSelectionOutlinePaint(Paint paint);
+
+//  /**
+//   * Returns the {@link Stroke}, the selected data is rendered with.
+//   * @return {@code null} if no special stroke is set (the base stroke
+//   *         should be used)
+//   */
+//  public Stroke getSelectionStroke();
+//
+//  /**
+//   * Sets the {@link Stroke}, the selected data is rendered with.
+//   * @param stroke {@link Stroke} for the selected data (set to {@code null}
+//   *               if the base stroke should be used)
+//   */
+//  public void setSelectionStroke(Stroke stroke);
 }

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionXYLineAndShapeRenderer.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionXYLineAndShapeRenderer.java	2009-10-25 16:56:21 UTC (rev 500)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/renderer/SelectionXYLineAndShapeRenderer.java	2009-10-27 10:19:08 UTC (rev 501)
@@ -1,292 +1,293 @@
-///*******************************************************************************
-// * Copyright (c) 2009 Martin O. J. Schmitz.
-// * 
-// * This file is part of the SCHMITZM library - a collection of utility 
-// * classes based on Java 1.6, focusing (not only) on Java Swing 
-// * and the Geotools library.
-// * 
-// * The SCHMITZM project is hosted at:
-// * http://wald.intevation.org/projects/schmitzm/
-// * 
-// * This program 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 3
-// * of the License, or (at your option) any later version.
-// * 
-// * This program 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 General Public License for more details.
-// * 
-// * You should have received a copy of the GNU Lesser General Public License (license.txt)
-// * along with this program; if not, write to the Free Software
-// * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-// * or try this link: http://www.gnu.org/licenses/lgpl.html
-// * 
-// * Contributors:
-// *     Martin O. J. Schmitz - initial API and implementation
-// *     Stefan A. Krüger - additional utility classes
-// ******************************************************************************/
-//package schmitzm.jfree.chart.renderer;
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program 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 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Krüger - additional utility classes
+ ******************************************************************************/
+package schmitzm.jfree.chart.renderer;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Stroke;
+import java.awt.geom.Rectangle2D;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.plot.CrosshairState;
+import org.jfree.chart.plot.Plot;
+import org.jfree.chart.plot.PlotRenderingInfo;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.renderer.xy.XYItemRendererState;
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.xy.XYDataset;
+
+import schmitzm.jfree.chart.SelectableChartPanel;
+import schmitzm.jfree.chart.selection.SeriesDatasetSelectionModel;
+import schmitzm.lang.LangUtil;
+
+/**
+ * Extends the {@link XYLineAndShapeRenderer} with the
+ * {@link SelectionRenderer} functionality. Additionally redefines
+ * the {@link #drawItem(Graphics2D, XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)}
+ * method to realize the highlight rendering of the selected
+ * items.<br>
+ * <b>Note:</b><br>
+ * An adequate {@link SeriesDatasetSelectionModel} is automatically
+ * created when a new {@link Plot} is set. Manually calling {@link #setSelectionModel(SeriesDatasetSelectionModel)}
+ * is usually not necessary. Overwrite {@link #createAndSetSelectionModel()} to
+ * avoid this behavior.<br>
+ * If no selection model is set, the behavior of this renderer is exactly
+ * like the super class.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ * @deprecated This class is not used anymore because the selection rendering
+ *             is no longer realized by the origin dataset renderer (e.g. because
+ *             the selected data items should be rendered in the foregound!).
+ *             Instead the {@link SelectableChartPanel} inserts explicit
+ *             renderers to the plot to draw only the selected data items highlighted. 
+ */
+public class SelectionXYLineAndShapeRenderer extends XYLineAndShapeRenderer implements SelectionRenderer<SeriesDatasetSelectionModel> {
+  /** Used for log and debug messages. */
+  protected Logger LOGGER = LangUtil.createLogger(this);
+
+  /** Holds the selection model, the renderer uses to determine whether a
+   *  data item is selected or not. */
+  protected SeriesDatasetSelectionModel selectionModel = null;
+
+  /** Holds the selection color (used for all series). */
+  protected Map<Integer,Paint> selectionPaint = new HashMap<Integer, Paint>();
+  
+  /** Holds the outline paint for selected items (used for all series). */
+  protected Paint selectionOutlinePaint = null;
+
+//  /** Holds the selection {@link Stroke} (used for all series). */
+//  protected Stroke selectionStroke = null;
+
+  /**
+   * Creates a new renderer.
+   */
+  public SelectionXYLineAndShapeRenderer() {
+    super();
+    init();
+  }
+
+  /**
+   * Creates a new renderer.
+   * @param lines   indicates whether lines are rendered between the data points
+   * @param shapes  indicates whether shapes are rendered under the data line
+   */
+  public SelectionXYLineAndShapeRenderer(boolean lines, boolean shapes) {
+    super(lines, shapes);
+    init();
+  }
+  
+  /**
+   * Called by every constructor to initialize the extensions 
+   * of this renderer.
+   */
+  protected void init() {
+    // set a default highlight color for the primary series
+    setSelectionPaint(Color.YELLOW);
+  }
+ 
+  /**
+   * Sets the selection model the renderer uses to determine whether
+   * a data item is selected or not.
+   * @param model the selection model
+   */
+  public void setSelectionModel(SeriesDatasetSelectionModel model) {
+    this.selectionModel = model;
+  }
+  
+  /**
+   * Returns the selection model the renderer uses to determine whether
+   * a data item is selected or not.
+   */
+  public SeriesDatasetSelectionModel getSelectionModel() {
+    return selectionModel;
+  }
+  
+  /**
+   * Creates and sets an adequate {@link SeriesDatasetSelectionModel}
+   * according to the {@link Dataset} of the current {@link Plot}. Automatically
+   * called by {@link #setPlot(XYPlot)}.<br>
+   * Sets the selection model to {@code null} if the renderer is not
+   * connected to a plot or the plot contains no dataset.
+   * @see #createSelectionModel(XYDataset) 
+   */
+  public void createAndSetSelectionModel() {
+    XYPlot    plot       = getPlot();
+    XYDataset newDataset = (plot == null) ? null : plot.getDataset();
+    if ( getSelectionModel() == null || getSelectionModel().getDataset() != newDataset )
+      setSelectionModel( newDataset != null ? createSelectionModel(newDataset) : null );
+  }
+
+  /**
+   * Creates an adequate {@link SeriesDatasetSelectionModel}
+   * according to the given {@link Dataset}. Subclasses can overwrite this
+   * method to create an alternative {@link SeriesDatasetSelectionModel}.
+   */
+  public SeriesDatasetSelectionModel createSelectionModel(Dataset dataset) {
+    if ( !(dataset instanceof XYDataset) )
+      throw new IllegalArgumentException(LangUtil.getSimpleClassName(this)+".createSelectionModel(.) can only be applied for XYDataset: "+LangUtil.getSimpleClassName(dataset));
+    return new SeriesDatasetSelectionModel((XYDataset)dataset);
+  }
+
+  /**
+   * Returns the color, the selected data <b>of the primary series</b>
+   * is rendered with.
+   * @return {@code null} if no selection color is defined
+   *         for the series
+   */
+  public Paint getSelectionPaint() {
+    return getSelectionPaint(0);
+  }
+
+  /**
+   * Sets the color, the selected data <b>of the primary series</b>
+   * is rendered with.
+   * @param paint color for the selected data
+   */
+  public void setSelectionPaint(Paint paint) {
+    setSelectionPaint(0, paint);
+  }
+
+  /**
+   * Returns the outline color for selected points. This paint is
+   * used for all series.
+   */
+  @Override
+  public Paint getSelectionOutlinePaint() {
+      return selectionOutlinePaint;
+  }
+  
+  /**
+   * Sets the outline paint for selected points. This paint is
+   * used for all series.
+   * @param paint a color
+   */
+  @Override
+  public void setSelectionOutlinePaint(Paint paint) {
+      selectionOutlinePaint = paint;
+  }
+
+//  /**
+//   * Returns the {@link Stroke}, the selected data is rendered with.
+//   * @return {@code null} if no special stroke is set (the base stroke
+//   *         should be used)
+//   */
+//  @Override
+//  public Stroke getSelectionStroke() {
+//    return selectionStroke;
+//  }
 //
-//import java.awt.Color;
-//import java.awt.Graphics2D;
-//import java.awt.Paint;
-//import java.awt.geom.Rectangle2D;
-//import java.util.HashMap;
-//import java.util.Map;
-//
-//import org.apache.log4j.Logger;
-//import org.jfree.chart.axis.ValueAxis;
-//import org.jfree.chart.plot.CrosshairState;
-//import org.jfree.chart.plot.Plot;
-//import org.jfree.chart.plot.PlotRenderingInfo;
-//import org.jfree.chart.plot.XYPlot;
-//import org.jfree.chart.renderer.xy.XYItemRendererState;
-//import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
-//import org.jfree.data.general.Dataset;
-//import org.jfree.data.xy.XYDataset;
-//
-//import schmitzm.jfree.chart.SelectableChartPanel;
-//import schmitzm.jfree.chart.selection.SeriesDatasetSelectionModel;
-//import schmitzm.lang.LangUtil;
-//
-///**
-// * Extends the {@link XYLineAndShapeRenderer} with the {@link SelectionRenderer}
-// * functionality. Additionally redefines the
-// * {@link #drawItem(Graphics2D, XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)}
-// * method to realize the highlight rendering of the selected items.<br>
-// * <b>Note:</b><br>
-// * An adequate {@link SeriesDatasetSelectionModel} is automatically created when
-// * a new {@link Plot} is set. Manually calling
-// * {@link #setSelectionModel(SeriesDatasetSelectionModel)} is usually not
-// * necessary. Overwrite {@link #createAndSetSelectionModel()} to avoid this
-// * behavior.<br>
-// * If no selection model is set, the behavior of this renderer is exactly like
-// * the super class.
-// * 
-// * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
-// * @deprecated This class is not used anymore because the selection rendering is
-// *             no longer realized by the origin dataset renderer (e.g. because
-// *             the selected data items should be rendered in the foregound!).
-// *             Instead the {@link SelectableChartPanel} inserts explicit
-// *             renderers to the plot to draw only the selected data items
-// *             highlighted.
-// */
-//public class SelectionXYLineAndShapeRenderer extends XYLineAndShapeRenderer
-//		implements SelectionRenderer<SeriesDatasetSelectionModel> {
-//	/** Used for log and debug messages. */
-//	protected Logger LOGGER = LangUtil.createLogger(this);
-//
-//	/**
-//	 * Holds the selection model, the renderer uses to determine whether a data
-//	 * item is selected or not.
-//	 */
-//	protected SeriesDatasetSelectionModel selectionModel = null;
-//
-//	/** Holds the selection color for each series. */
-//	protected Map<Integer, Paint> selectionPaint = new HashMap<Integer, Paint>();
-//	/**
-//	 * Returns the color, the selected data is rendered with.
-//	 * 
-//	 * @param series
-//	 *            the data series
-//	 * @return {@code null} if no selection color is defined for the series
-//	 */
-//	public Paint getSelectionOutlinePaint(int series) {
-//		return selectionPaint.get(series);
-//	}
-//
-//	/**
-//	 * Creates a new renderer.
-//	 */
-//	public SelectionXYLineAndShapeRenderer() {
-//		super();
-//		init();
-//	}
-//
-//	/**
-//	 * Creates a new renderer.
-//	 * 
-//	 * @param lines
-//	 *            indicates whether lines are rendered between the data points
-//	 * @param shapes
-//	 *            indicates whether shapes are rendered under the data line
-//	 */
-//	public SelectionXYLineAndShapeRenderer(boolean lines, boolean shapes) {
-//		super(lines, shapes);
-//		init();
-//	}
-//
-//	/**
-//	 * Called by every constructor to initialize the extensions of this
-//	 * renderer.
-//	 */
-//	protected void init() {
-//		// set a default highlight color for the primary series
-//		setUseOutlinePaint(true);
-//		setSelectionPaint(Color.YELLOW);
-//		setSelectionOutlinePaint(Color.RED);
-//	}
-//
-//	/**
-//	 * Sets the selection model the renderer uses to determine whether a data
-//	 * item is selected or not.
-//	 * 
-//	 * @param model
-//	 *            the selection model
-//	 */
-//	public void setSelectionModel(SeriesDatasetSelectionModel model) {
-//		this.selectionModel = model;
-//	}
-//
-//	/**
-//	 * Returns the selection model the renderer uses to determine whether a data
-//	 * item is selected or not.
-//	 */
-//	public SeriesDatasetSelectionModel getSelectionModel() {
-//		return selectionModel;
-//	}
-//
-//	/**
-//	 * Creates and sets an adequate {@link SeriesDatasetSelectionModel}
-//	 * according to the {@link Dataset} of the current {@link Plot}.
-//	 * Automatically called by {@link #setPlot(XYPlot)}.<br>
-//	 * Sets the selection model to {@code null} if the renderer is not connected
-//	 * to a plot or the plot contains no dataset.
-//	 * 
-//	 * @see #createSelectionModel(XYDataset)
-//	 */
-//	public void createAndSetSelectionModel() {
-//		XYPlot plot = getPlot();
-//		XYDataset newDataset = (plot == null) ? null : plot.getDataset();
-//		if (getSelectionModel() == null
-//				|| getSelectionModel().getDataset() != newDataset)
-//			setSelectionModel(newDataset != null ? createSelectionModel(newDataset)
-//					: null);
-//	}
-//
-//	/**
-//	 * Creates an adequate {@link SeriesDatasetSelectionModel} according to the
-//	 * given {@link Dataset}. Subclasses can overwrite this method to create an
-//	 * alternative {@link SeriesDatasetSelectionModel}.
-//	 */
-//	public SeriesDatasetSelectionModel createSelectionModel(Dataset dataset) {
-//		if (!(dataset instanceof XYDataset))
-//			throw new IllegalArgumentException(
-//					LangUtil.getSimpleClassName(this)
-//							+ ".createSelectionModel(.) can only be applied for XYDataset: "
-//							+ LangUtil.getSimpleClassName(dataset));
-//		return new SeriesDatasetSelectionModel((XYDataset) dataset);
-//	}
-//
-//	/**
-//	 * Returns the color, the selected data <b>of the primary series</b> is
-//	 * rendered with.
-//	 * 
-//	 * @return {@code null} if no selection color is defined for the series
-//	 */
-//	public Paint getSelectionPaint() {
-//		return getSelectionPaint(0);
-//	}
-//
-//	/**
-//	 * Sets the color, the selected data <b>of the primary series</b> is
-//	 * rendered with.
-//	 * 
-//	 * @param paint
-//	 *            color for the selected data
-//	 */
-//	public void setSelectionPaint(Paint paint) {
-//		setSelectionPaint(0, paint);
-//	}
-//
-//	/**
-//	 * Returns the color, the selected data is rendered with.
-//	 * 
-//	 * @param series
-//	 *            the data series
-//	 * @return {@code null} if no selection color is defined for the series
-//	 */
-//	public Paint getSelectionPaint(int series) {
-//		return selectionPaint.get(series);
-//	}
-//
-//	/**
-//	 * Sets the color, the selected data is rendered with.
-//	 * 
-//	 * @param series
-//	 *            the data series
-//	 * @param paint
-//	 *            color for the selected data
-//	 */
-//	public void setSelectionPaint(int series, Paint paint) {
-//		selectionPaint.put(series, paint);
-//	}
-//
-//	/**
-//	 * Creates and sets a new {@link SeriesDatasetSelectionModel}, if no
-//	 * selection model is set yet, or the selection model's dataset differs from
-//	 * the dataset of the new plot.
-//	 * 
-//	 * @param plot
-//	 *            the plot rendered by this renderer
-//	 */
-//	public void setPlot(XYPlot plot) {
-//		super.setPlot(plot);
-//		createAndSetSelectionModel();
-//	}
-//
-//	/**
-//	 * Sets the rendering color (temporary for the rendering process) to the
-//	 * {@linkplain #getSelectionPaint(int) highlight color}, if the item is
-//	 * defined as selected (by the {@linkplain #getSelectionModel() selection
-//	 * model}).
-//	 */
-//	public void drawItem(Graphics2D g, XYItemRendererState state,
-//			Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
-//			ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
-//			int series, int item, CrosshairState crosshairState, int pass) {
-//
-//		// Save the normal rendering color
-//		Paint origPaint = getSeriesPaint(series);
-//
-//		// if selection model and color is set and the item is selected
-//		// the highlighting selection color is (temporary) set for the
-//		// rendering process
-//		if (getSelectionModel() != null) {
-//			Paint selPaint = getSelectionPaint(series);
-//			if (selPaint != null) {
-//				Comparable seriesKey = dataset.getSeriesKey(series);
-//				if (selectionModel.isItemSelected(seriesKey, item))
-//					setSeriesPaint(series, selPaint, false);
-//				else
-//					setSeriesPaint(series, origPaint, false);
-//			} else
-//				LOGGER.warn("No selection paint set for series " + series
-//						+ ". Series is rendererd normally.");
-//		} else
-//			LOGGER
-//					.debug("No selection model set for renderer. All series rendererd normally.");
-//
-//		// rendering
-//		super.drawItem(g, state, dataArea, info, plot, domainAxis, rangeAxis,
-//				dataset, series, item, crosshairState, pass);
-//
-//		// reset the original rendering color
-//		setSeriesPaint(series, origPaint, false);
-//	}
-//
-//	@Override
-//	public Paint getSelectionOutlinePaint() {
-//		return getSeriesOutlinePaint(0);
-//	}
-//
-//	@Override
-//	public void setSelectionOutlinePaint(Paint paint) {
-//		setSeriesOutlinePaint(0, paint);
-//	}
-//	
-//
-//
-//}
+//  /**
+//   * Sets the {@link Stroke}, the selected data is rendered with.
+//   * @param stroke {@link Stroke} for the selected data (set to {@code null}
+//   *               if the base stroke should be used)
+//   */
+//  @Override
+//  public void setSelectionStroke(Stroke stroke) {
+//    this.selectionStroke = stroke;
+//  }
+
+  /**
+   * Returns the color, the selected data is rendered with.
+   * @param series the data series
+   * @return {@code null} if no selection color is defined
+   *         for the series
+   */
+  public Paint getSelectionPaint(int series) {
+    return selectionPaint.get(series);
+  }
+
+  /**
+   * Sets the color, the selected data is rendered with.
+   * @param series the data series
+   * @param paint color for the selected data
+   */
+  public void setSelectionPaint(int series, Paint paint) {
+    selectionPaint.put(series, paint);
+  }
+  
+  /**
+   * Creates and sets a new {@link SeriesDatasetSelectionModel}, if no selection model
+   * is set yet, or the selection model's dataset differs from the dataset of the
+   * new plot.
+   * @param plot the plot rendered by this renderer
+   */
+  public void setPlot(XYPlot plot) {
+    super.setPlot(plot);
+    createAndSetSelectionModel();
+  }
+
+  /**
+   * Sets the rendering color (temporary for the rendering process) to the
+   * {@linkplain #getSelectionPaint(int) highlight color}, if the item is
+   * defined as selected (by the {@linkplain #getSelectionModel() selection model}).
+   */
+  public void drawItem(Graphics2D g,
+      XYItemRendererState state,
+      Rectangle2D dataArea,
+      PlotRenderingInfo info,
+      XYPlot plot,
+      ValueAxis domainAxis,
+      ValueAxis rangeAxis,
+      XYDataset dataset,
+      int series,
+      int item,
+      CrosshairState crosshairState,
+      int pass) {
+
+    // Save the normal rendering color
+    Paint origPaint = getSeriesPaint(series);
+
+    // if selection model and color is set and the item is selected
+    // the highlighting selection color is (temporary) set for the
+    // rendering process
+    if ( getSelectionModel() != null ) {
+      Paint selPaint  = getSelectionPaint(series);
+      if ( selPaint != null ) {
+        Comparable seriesKey = dataset.getSeriesKey(series);
+        if ( selectionModel.isItemSelected(seriesKey, item) )
+          setSeriesPaint( series, selPaint, false );
+        else
+          setSeriesPaint( series, origPaint, false );
+      } else
+        LOGGER.warn("No selection paint set for series "+series+". Series is rendererd normally.");
+    } else
+      LOGGER.debug("No selection model set for renderer. All series rendererd normally.");
+    
+    // rendering
+    super.drawItem(g, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass);
+    
+    // reset the original rendering color
+    setSeriesPaint( series, origPaint, false );
+  }
+}



More information about the Schmitzm-commits mailing list