[Schmitzm-commits] r246 - in trunk/src/schmitzm: geotools/gui jfree/chart
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jul 30 18:32:23 CEST 2009
Author: alfonx
Date: 2009-07-30 18:32:22 +0200 (Thu, 30 Jul 2009)
New Revision: 246
Modified:
trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java
trunk/src/schmitzm/jfree/chart/SelectableChartPanel.java
Log:
* GP-ChartStuff: Added buttons for different selection types on charts: SET, ADD, REMOVE, CLEAR and ZOOM in chart and ZOOM TO SELECTION
Modified: trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java 2009-07-30 11:56:55 UTC (rev 245)
+++ trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java 2009-07-30 16:32:22 UTC (rev 246)
@@ -126,9 +126,7 @@
newPanelArroundTable.add(splitPane.getRightComponent(),
BorderLayout.CENTER);
splitPane.setRightComponent(newPanelArroundTable);
- splitPane.setDividerLocation(0.33); // SK: Does have no effect
- // because JMapPane overrules
- // this
+ splitPane.setDividerLocation(0.33); // SK: Does have no effect because the JSplitPane is not yet rendered.
} else {
newPanelArroundTable.add(getComponent(0), BorderLayout.CENTER);
removeAll();
Modified: trunk/src/schmitzm/jfree/chart/SelectableChartPanel.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/SelectableChartPanel.java 2009-07-30 11:56:55 UTC (rev 245)
+++ trunk/src/schmitzm/jfree/chart/SelectableChartPanel.java 2009-07-30 16:32:22 UTC (rev 246)
@@ -41,7 +41,6 @@
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
-import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
@@ -51,242 +50,328 @@
import schmitzm.lang.LangUtil;
/**
- * This class extends the {@link org.jfree.chart.ChartPanel} with some
- * new functionalities.
+ * This class extends the {@link org.jfree.chart.ChartPanel} with some new
+ * functionalities.
* <ul>
-* <li>select chart points and highlight them</li>
- * <li>setting window selection mode to ZOOM or SELECT</li>
+ * <li>select chart points and highlight them</li>
+ * <li>setting window selection mode to ZOOM or SELECT</li>
* </ul>
+ *
* @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
* @version 1.0
*/
public class SelectableChartPanel extends org.jfree.chart.ChartPanel {
- /** Used for log and debug messages. */
- protected Logger LOGGER = LangUtil.createLogger(this);
+ /** Used for log and debug messages. */
+ protected Logger LOGGER = LangUtil.createLogger(this);
- /**
- * Types of window selection on chart panel.
- */
- public static enum WindowSelectionMode {
- /** Zoom on window selection (normal behavior of {@link org.jfree.chart.ChartPanel}) */
- ZOOM_IN,
- /** Select some data points in chart to highlight on window selection. */
- SELECT,
- }
-
- /** Holds the behavior on window selection (Default: {@link WindowSelectionMode#ZOOM_IN}). */
- protected WindowSelectionMode windowSelectionMode = WindowSelectionMode.ZOOM_IN;
-
- /** Listens to mouse window selection on the chart. */
- protected ChartMouseSelectionTracker selectionTracker = null;
-
- /**
- * Creates a new chart panel.
- */
- public SelectableChartPanel(JFreeChart chart) {
- super(chart);
- init();
- }
+ /**
+ * Types of window selection on chart panel.
+ */
+ public static enum WindowSelectionMode {
+ /**
+ * Zoom on window selection (normal behavior of
+ * {@link org.jfree.chart.ChartPanel})
+ */
+ ZOOM_IN,
+ /**
+ * Swap the "selection-state" of data objects in the chart on window
+ * selection.
+ */
+ SELECT_SWAP,
+ /**
+ * Set the set of selected objects to the inclusions of the window
+ * selection.
+ */
+ SELECT_SET,
+ /** Add objects to the selection on window selection. */
+ SELECT_ADD,
+ /** Remove objects from the selection on window selection. */
+ SELECT_REMOVE
+ }
- /**
- * Creates a new chart panel.
- */
- public SelectableChartPanel(JFreeChart chart, boolean useBuffer) {
- super(chart, useBuffer);
- init();
- }
+ /**
+ * Holds the behavior on window selection (Default:
+ * {@link WindowSelectionMode#ZOOM_IN}).
+ */
+ protected WindowSelectionMode windowSelectionMode = WindowSelectionMode.ZOOM_IN;
- /**
- * Creates a new chart panel.
- */
- public SelectableChartPanel(JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) {
- super(chart, properties, save, print, zoom, tooltips);
- init();
- }
+ /** Listens to mouse window selection on the chart. */
+ protected ChartMouseSelectionTracker selectionTracker = null;
- /**
- * Creates a new chart panel.
- */
- public SelectableChartPanel(JFreeChart chart, int width, int height, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth,
- int maximumDrawHeight, boolean useBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) {
- super(chart, width, height, minimumDrawWidth, minimumDrawHeight,
- maximumDrawWidth, maximumDrawHeight, useBuffer, properties, save,
- print, zoom, tooltips);
- init();
- }
+ /**
+ * Creates a new chart panel.
+ */
+ public SelectableChartPanel(JFreeChart chart) {
+ super(chart);
+ init();
+ }
- /**
- * Called by every constructor to initialize the extensions
- * of this panel.
- */
- protected void init() {
- selectionTracker = new ChartMouseSelectionTracker(this) {
- public void selectionPerformed(Rectangle2D selectedArea, Set<XYItemEntity> selectedEntities) {
- LOGGER.debug( selectedEntities.size() + " objects selected" );
-
- // remember all changed selection models to reset "valueAdjusting"
- // property at the end
- Set<DatasetSelectionModel<?>> changedModels = new HashSet<DatasetSelectionModel<?>>();
- Plot plot = getChart().getPlot();
- for (Iterator<XYItemEntity> i = selectedEntities.iterator(); i.hasNext(); ) {
- XYItemEntity e = i.next();
- Dataset dataset = e.getDataset();
- DatasetSelectionModel<?> selModel = null;
- if ( plot instanceof XYPlot ) {
- XYItemRenderer renderer = ((XYPlot)plot).getRendererForDataset((XYDataset)dataset);
- if ( renderer instanceof DatasetSelectionModelProvider )
- selModel = ((DatasetSelectionModelProvider<?>)renderer).getSelectionModel();
- }
+ /**
+ * Creates a new chart panel.
+ */
+ public SelectableChartPanel(JFreeChart chart, boolean useBuffer) {
+ super(chart, useBuffer);
+ init();
+ }
- // set "valueAdjusting" property for selection model and remember the
- // model to reset the property at the end
- if ( selModel != null ) {
- selModel.setValueIsAdjusting(true);
- changedModels.add(selModel);
- }
- // perform the selection change
- if ( selModel instanceof SeriesDatasetSelectionModel ) {
- int series = e.getSeriesIndex();
- Comparable seriesKey = e.getDataset().getSeriesKey(series);
- int item = e.getItem();
- ((SeriesDatasetSelectionModel)selModel).changeItemSelection(seriesKey, item);
- } else {
- if ( selModel == null )
- LOGGER.warn("Selection not supported for dataset: "+LangUtil.getSimpleClassName(dataset));
- else
- LOGGER.error("Selection not yet implemented for selection model: "+LangUtil.getSimpleClassName(selModel));
- }
- }
- // refresh the visualization
- refresh();
- // reset the "valueAdjusting" property to inform listeners
- // about the selection change
- for (DatasetSelectionModel<?> selModel : changedModels)
- selModel.setValueIsAdjusting(false);
- }
-
- };
- addMouseListener(selectionTracker);
- setWindowSelectionMode( WindowSelectionMode.ZOOM_IN );
-
-// XYPlot p = (XYPlot)getChart().getPlot();
-// XYLineAndShapeRenderer r = (XYLineAndShapeRenderer)p.getRenderer();
+ /**
+ * Creates a new chart panel.
+ */
+ public SelectableChartPanel(JFreeChart chart, boolean properties,
+ boolean save, boolean print, boolean zoom, boolean tooltips) {
+ super(chart, properties, save, print, zoom, tooltips);
+ init();
+ }
-//
-// XYItemRenderer r2 = new XYLineAndShapeRenderer(r.getBaseLinesVisible(), r.getBaseShapesVisible()) {
-// 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) {
-// if ( !selectedIdx.contains(item) )
-// return;
-//
-// super.drawItem(g, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass);
-// }
-// };
-// r.setBasePaint(Color.gray);
-// r2.setBasePaint(Color.YELLOW);
-// int datasetCount = p.getDatasetCount();
-// p.setDataset(datasetCount, p.getDataset());
-// p.setRenderer(datasetCount, r2);
-// p.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);
-
-
-
-// addChartMouseListener( new ChartMouseListener() {
-// @Override
-// public void chartMouseClicked(ChartMouseEvent e) {
-// System.err.println("MouseClicked: "+e.getEntity());
-// }
-// @Override
-// public void chartMouseMoved(ChartMouseEvent e) {
-// System.err.println("MouseMoved: "+e.getEntity());
-// }
-// });
-
- }
-
- /**
- * Repaints the chart.
- */
- public void refresh() {
- setRefreshBuffer(true);
- repaint();
- }
-
- /**
- * After setting a new chart the zoom relevant properties are
- * reset according to the new chart. After calling the super-method,
- * this methods resets the properties according to the current
- * {@link #windowSelectionMode} to keep its functionality remaining.
- * @see #updateStatesForWindowSelectionMode()
- */
- public void setChart(JFreeChart chart) {
- super.setChart(chart);
- // zoom relevant properties were reset according to
- // chart properties!
- // But we do not want them changed, so reset the states.
- updateStatesForWindowSelectionMode();
- }
-
- /**
- * Configures the zoomable properties and {@link #selectionTracker} according
- * to the current {@link #windowSelectionMode}.
- */
- protected void updateStatesForWindowSelectionMode() {
- // enable/disable the zoom functionality
- setMouseZoomable( windowSelectionMode == WindowSelectionMode.ZOOM_IN, getFillZoomRectangle() );
- // enable/disable the selection functionality
- if ( selectionTracker != null )
- selectionTracker.setEnabled( windowSelectionMode == WindowSelectionMode.SELECT );
- }
-
- /**
- * Sets the behavior of the chart panel on window selections via mouse.
- * @param mode new selection mode
- */
- public void setWindowSelectionMode(WindowSelectionMode mode) {
- this.windowSelectionMode = mode;
- updateStatesForWindowSelectionMode();
- }
+ /**
+ * Creates a new chart panel.
+ */
+ public SelectableChartPanel(JFreeChart chart, int width, int height,
+ int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth,
+ int maximumDrawHeight, boolean useBuffer, boolean properties,
+ boolean save, boolean print, boolean zoom, boolean tooltips) {
+ super(chart, width, height, minimumDrawWidth, minimumDrawHeight,
+ maximumDrawWidth, maximumDrawHeight, useBuffer, properties,
+ save, print, zoom, tooltips);
+ init();
+ }
- /**
- * Returns the behavior of the chart panel on window selections via mouse.
- * @param mode new selection mode
- */
- public WindowSelectionMode getWindowSelectionMode() {
- return this.windowSelectionMode;
- }
-
- /**
- * Ignores the event if the window selection mode is not
- * {@link WindowSelectionMode#ZOOM_IN}, to avoid conflicts
- * between the two listeners.
- */
- @Override
- public void mouseDragged(MouseEvent e) {
- if ( getWindowSelectionMode() != WindowSelectionMode.ZOOM_IN )
- return;
- super.mouseDragged(e);
- }
+ /**
+ * Called by every constructor to initialize the extensions of this panel.
+ */
+ protected void init() {
- /**
- * Ignores the event if the window selection mode is not
- * {@link WindowSelectionMode#ZOOM_IN}, to avoid conflicts
- * between the two listeners.
- */
- @Override
- public void mouseMoved(MouseEvent e) {
- if ( getWindowSelectionMode() != WindowSelectionMode.ZOOM_IN )
- return;
- super.mouseMoved(e);
- }
+ selectionTracker = new ChartMouseSelectionTracker(this) {
+ /**
+ * This method is only called, if the #WindowSelectionMode is not in
+ * Zoom-Mode. Otherwise this listener is disabled.
+ */
+ @SuppressWarnings("fallthrough")
+ public void selectionPerformed(Rectangle2D selectedArea,
+ Set<XYItemEntity> selectedEntities) {
+ LOGGER.debug(selectedEntities.size() + " objects selected");
+
+ // remember all changed selection models to reset
+ // "valueAdjusting"
+ // property at the end
+ Set<DatasetSelectionModel<?>> changedModels = new HashSet<DatasetSelectionModel<?>>();
+ Plot plot = getChart().getPlot();
+ for (Iterator<XYItemEntity> i = selectedEntities.iterator(); i
+ .hasNext();) {
+ XYItemEntity e = i.next();
+ Dataset dataset = e.getDataset();
+ DatasetSelectionModel<?> selModel = null;
+ if (plot instanceof XYPlot) {
+ XYItemRenderer renderer = ((XYPlot) plot)
+ .getRendererForDataset((XYDataset) dataset);
+ if (renderer instanceof DatasetSelectionModelProvider)
+ selModel = ((DatasetSelectionModelProvider<?>) renderer)
+ .getSelectionModel();
+ }
+
+ // set "valueAdjusting" property for selection model and
+ // remember the
+ // model to reset the property at the end
+ if (selModel != null) {
+ selModel.setValueIsAdjusting(true);
+
+ /*
+ * If we do a SELCTION_SET and this is the first time we
+ * change this selection model, let's clear it before
+ * adding all the selected object.
+ */
+ if (!changedModels.contains(selModel)
+ && windowSelectionMode == WindowSelectionMode.SELECT_SET){
+ selModel.clearSelection();
+ }
+
+ changedModels.add(selModel);
+ }
+ // perform the selection change
+ if (selModel instanceof SeriesDatasetSelectionModel) {
+ int series = e.getSeriesIndex();
+ Comparable seriesKey = e.getDataset().getSeriesKey(
+ series);
+ int item = e.getItem();
+ final SeriesDatasetSelectionModel seriesDatasetSelectionModel = (SeriesDatasetSelectionModel) selModel;
+
+ /*
+ * We have the SelectionModel, a SeriesKey and it's
+ * Item-ID. Now we deal with it depending on the
+ * WindowSelectionMode
+ */
+ switch (windowSelectionMode) {
+ case SELECT_SET:
+ // Is cleared once earlier
+ case SELECT_ADD:
+ if (!seriesDatasetSelectionModel.isItemSelected(
+ seriesKey, item))
+ seriesDatasetSelectionModel.setItemSelected(
+ seriesKey, item, true);
+ break;
+ case SELECT_SWAP:
+ seriesDatasetSelectionModel.changeItemSelection(
+ seriesKey, item);
+ break;
+ case SELECT_REMOVE:
+ if (seriesDatasetSelectionModel.isItemSelected(
+ seriesKey, item))
+ seriesDatasetSelectionModel.setItemSelected(
+ seriesKey, item, false);
+ break;
+ }
+
+ } else {
+ if (selModel == null)
+ LOGGER.warn("Selection not supported for dataset: "
+ + LangUtil.getSimpleClassName(dataset));
+ else
+ LOGGER
+ .error("Selection not yet implemented for selection model: "
+ + LangUtil
+ .getSimpleClassName(selModel));
+ }
+ }
+ // refresh the visualization
+ refresh();
+ // reset the "valueAdjusting" property to inform listeners
+ // about the selection change
+ for (DatasetSelectionModel<?> selModel : changedModels)
+ selModel.setValueIsAdjusting(false);
+ }
+
+ };
+ addMouseListener(selectionTracker);
+ setWindowSelectionMode(WindowSelectionMode.ZOOM_IN);
+
+ // XYPlot p = (XYPlot)getChart().getPlot();
+ // XYLineAndShapeRenderer r = (XYLineAndShapeRenderer)p.getRenderer();
+
+ //
+ // XYItemRenderer r2 = new
+ // XYLineAndShapeRenderer(r.getBaseLinesVisible(),
+ // r.getBaseShapesVisible()) {
+ // 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) {
+ // if ( !selectedIdx.contains(item) )
+ // return;
+ //
+ // super.drawItem(g, state, dataArea, info, plot, domainAxis, rangeAxis,
+ // dataset, series, item, crosshairState, pass);
+ // }
+ // };
+ // r.setBasePaint(Color.gray);
+ // r2.setBasePaint(Color.YELLOW);
+ // int datasetCount = p.getDatasetCount();
+ // p.setDataset(datasetCount, p.getDataset());
+ // p.setRenderer(datasetCount, r2);
+ // p.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);
+
+ // addChartMouseListener( new ChartMouseListener() {
+ // @Override
+ // public void chartMouseClicked(ChartMouseEvent e) {
+ // System.err.println("MouseClicked: "+e.getEntity());
+ // }
+ // @Override
+ // public void chartMouseMoved(ChartMouseEvent e) {
+ // System.err.println("MouseMoved: "+e.getEntity());
+ // }
+ // });
+
+ }
+
+ /**
+ * Repaints the chart.
+ */
+ public void refresh() {
+ setRefreshBuffer(true);
+ repaint();
+ }
+
+ /**
+ * After setting a new chart the zoom relevant properties are reset
+ * according to the new chart. After calling the super-method, this methods
+ * resets the properties according to the current
+ * {@link #windowSelectionMode} to keep its functionality remaining.
+ *
+ * @see #updateStatesForWindowSelectionMode()
+ */
+ public void setChart(JFreeChart chart) {
+ super.setChart(chart);
+ // zoom relevant properties were reset according to
+ // chart properties!
+ // But we do not want them changed, so reset the states.
+ updateStatesForWindowSelectionMode();
+ }
+
+ /**
+ * Configures the zoomable properties and {@link #selectionTracker}
+ * according to the current {@link #windowSelectionMode}.
+ */
+ protected void updateStatesForWindowSelectionMode() {
+ // enable/disable the zoom functionality
+ setMouseZoomable(windowSelectionMode == WindowSelectionMode.ZOOM_IN,
+ getFillZoomRectangle());
+ // enable/disable the selection functionality
+ if (selectionTracker != null)
+ selectionTracker
+ .setEnabled(windowSelectionMode != WindowSelectionMode.ZOOM_IN);
+ }
+
+ /**
+ * Sets the behavior of the chart panel on window selections via mouse.
+ *
+ * @param mode
+ * new selection mode
+ */
+ public void setWindowSelectionMode(WindowSelectionMode mode) {
+ this.windowSelectionMode = mode;
+ updateStatesForWindowSelectionMode();
+
+ }
+
+ /**
+ * Returns the behavior of the chart panel on window selections via mouse.
+ *
+ * @param mode
+ * new selection mode
+ */
+ public WindowSelectionMode getWindowSelectionMode() {
+ return this.windowSelectionMode;
+ }
+
+ /**
+ * Ignores the event if the window selection mode is not
+ * {@link WindowSelectionMode#ZOOM_IN}, to avoid conflicts between the two
+ * listeners.
+ */
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ if (getWindowSelectionMode() != WindowSelectionMode.ZOOM_IN)
+ return;
+ super.mouseDragged(e);
+ }
+
+ /**
+ * Ignores the event if the window selection mode is not
+ * {@link WindowSelectionMode#ZOOM_IN}, to avoid conflicts between the two
+ * listeners.
+ */
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ if (getWindowSelectionMode() != WindowSelectionMode.ZOOM_IN)
+ return;
+ super.mouseMoved(e);
+ }
+
}
More information about the Schmitzm-commits
mailing list