[Schmitzm-commits] r130 - in trunk/src: schmitzm/jfree/chart/selection skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat May 30 18:34:00 CEST 2009


Author: mojays
Date: 2009-05-30 18:34:00 +0200 (Sat, 30 May 2009)
New Revision: 130

Added:
   trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java
   trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java
   trunk/src/schmitzm/jfree/chart/selection/SelectionChangeEvent.java
   trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
Modified:
   trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java
   trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModelProvider.java
   trunk/src/schmitzm/jfree/chart/selection/SeriesDatasetSelectionModel.java
Log:
new DatasetSelectionListener and ChartSelectionSynchronizer (not finished!)

Added: trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -0,0 +1,107 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+package schmitzm.jfree.chart.selection;
+
+import java.util.Vector;
+
+import javax.swing.event.EventListenerList;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.general.DatasetChangeListener;
+import org.jfree.data.general.SeriesDataset;
+
+import schmitzm.jfree.JFreeChartUtil;
+import schmitzm.lang.LangUtil;
+
+/**
+ * This class is a general implementation of {@link DatasetSelectionModel} and maintains whether
+ * items of a {@link Dataset} are selected in a chart or not. The model connects to
+ * the {@link Dataset} as {@link DatasetChangeListener} to recognize the moment a
+ * series is removed. Subclasses must implement
+ * {@link #datasetChanged(org.jfree.data.general.DatasetChangeEvent)} to react with an
+ * automatic unselect.
+ * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ */
+public abstract class AbstractDatasetSelectionModel<E extends Dataset> implements DatasetSelectionModel<E> {
+  /** {@link Logger} to log waring, debug or error messages. */
+  protected Logger LOGGER = LangUtil.createLogger(this);
+
+  /** Holds the {@link Dataset} whose data can be selected. */
+  protected E dataset = null;
+  
+  /** Holds the listeners to the {@link DatasetSelectionModel}. */
+  protected Vector<DatasetSelectionListener> listeners = new Vector<DatasetSelectionListener>();
+  
+  /**
+   * Creates a new selection model.
+   * @param dataset {@link Dataset} whose data can be selected
+   */
+  public AbstractDatasetSelectionModel(E dataset) {
+    this.dataset = dataset;
+    dataset.addChangeListener(this);
+  }
+  
+  /**
+   * Creates a {@link AbstractDatasetSelectionModel} for a {@link Dataset}.
+   * @param dataset a dataset
+   * @return {@code null} if selection is not supported for dataset
+   */
+  public static AbstractDatasetSelectionModel<?> createInstanceFor(Dataset dataset) {
+    if ( dataset instanceof SeriesDataset )
+      return new SeriesDatasetSelectionModel((SeriesDataset)dataset);
+    return null;
+  }
+
+  /**
+   * Returns the {@link Dataset} whose data can be selected. 
+   */
+  public E getDataset() {
+    return dataset;
+  }
+  
+  /**
+   * Clears the selection.
+   */
+  public abstract void clearSelection();
+  
+  /**
+   * Adds a listener which will be informed about changed on the
+   * selection model.
+   * @param listener the listener to be added
+   */
+  public void addSelectionListener(DatasetSelectionListener listener) {
+    listeners.add(listener);
+  }
+  
+  /**
+   * Removes a listener from the selection model.
+   * @param listener the listener to be remove
+   */
+  public void removeSelectionListener(DatasetSelectionListener listener) {
+    listeners.remove(listener);
+  }
+
+  /**
+   * Informs all listeners about a general selection change.
+   */
+  public void fireSelectionChanged() {
+    for (DatasetSelectionListener l : listeners)
+      l.selectionChanged( createSelectionChangeEvent() );
+  }
+  
+  /**
+   * Creates a {@link SelectionChangeEvent}.
+   */
+  protected SelectionChangeEvent createSelectionChangeEvent() {
+    return new SelectionChangeEvent(this);
+  }
+}

Added: trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -0,0 +1,23 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+
+package schmitzm.jfree.chart.selection;
+
+/**
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public interface DatasetSelectionListener {
+  /**
+   * Called when the selection of a {@link DatasetSelectionModel} has changed.
+   * @param e the event
+   */
+  public void selectionChanged(SelectionChangeEvent e);
+}

Modified: trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -18,49 +18,39 @@
 import schmitzm.jfree.JFreeChartUtil;
 
 /**
- * This selection model maintains whether items of a {@link Dataset} is selected
+ * This selection model maintains whether items of a {@link Dataset} are selected
  * in a chart or not. The model connects to the {@link Dataset} as {@link DatasetChangeListener}
  * to recognize the moment a series is removed. Subclasses must implement
  * {@link #datasetChanged(org.jfree.data.general.DatasetChangeEvent)} to react with an
  * automatic unselect.
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  */
-public abstract class DatasetSelectionModel<E extends Dataset> implements DatasetChangeListener {
-  private static Logger LOGGER = Logger.getLogger(JFreeChartUtil.class.getName());
-
-  /** Holds the {@link Dataset} whose data can be selected. */
-  protected E dataset = null;
-  
+public interface DatasetSelectionModel<E extends Dataset> extends DatasetChangeListener {
   /**
-   * Creates a new selection model.
-   * @param dataset {@link Dataset} whose data can be selected
+   * Returns the {@link Dataset} whose data can be selected. 
    */
-  public DatasetSelectionModel(E dataset) {
-    this.dataset = dataset;
-    dataset.addChangeListener(this);
-  }
+  public E getDataset();
   
   /**
-   * Creates a {@link DatasetSelectionModel} for a {@link Dataset}.
-   * @param dataset a dataset
-   * @return {@code null} if selection is not supported for dataset
+   * Clears the selection.
    */
-  public static DatasetSelectionModel<?> createInstanceFor(Dataset dataset) {
-    if ( dataset instanceof SeriesDataset )
-      return new SeriesDatasetSelectionModel((SeriesDataset)dataset);
-    return null;
-  }
-
+  public void clearSelection();
+  
   /**
-   * Returns the {@link Dataset} whose data can be selected. 
+   * Adds a listener which will be informed about changed on the
+   * selection model.
+   * @param listener the listener to be added
    */
-  public E getDataset() {
-    return dataset;
-  }
+  public void addSelectionListener(DatasetSelectionListener listener);
   
   /**
-   * Clears the selection.
+   * Removes a listener from the selection model.
+   * @param listener the listener to be remove
    */
-  public abstract void clearSelection();
+  public void removeSelectionListener(DatasetSelectionListener listener);
   
+  /**
+   * Informs all listeners about a general selection change.
+   */
+  public void fireSelectionChanged();
 }

Modified: trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModelProvider.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModelProvider.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModelProvider.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -15,7 +15,7 @@
 
 /**
  * Interface for all objects (especially {@link Plot Plots}) which provide
- * a {@link DatasetSelectionModel}.
+ * a {@link AbstractDatasetSelectionModel}.
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  */
 public interface DatasetSelectionModelProvider<E extends DatasetSelectionModel<?>> {

Added: trunk/src/schmitzm/jfree/chart/selection/SelectionChangeEvent.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/SelectionChangeEvent.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/schmitzm/jfree/chart/selection/SelectionChangeEvent.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -0,0 +1,27 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+package schmitzm.jfree.chart.selection;
+
+import javax.swing.event.ChangeEvent;
+
+/**
+ * This event indicates a change on a dataset selection.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class SelectionChangeEvent extends ChangeEvent {
+  /**
+   * Creates a new event.
+   * @param source
+   */
+  public SelectionChangeEvent(Object source) {
+    super(source);
+  }
+}

Modified: trunk/src/schmitzm/jfree/chart/selection/SeriesDatasetSelectionModel.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/SeriesDatasetSelectionModel.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/schmitzm/jfree/chart/selection/SeriesDatasetSelectionModel.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -24,7 +24,7 @@
  * in a chart or not.
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  */
-public class SeriesDatasetSelectionModel extends DatasetSelectionModel<SeriesDataset> {
+public class SeriesDatasetSelectionModel extends AbstractDatasetSelectionModel<SeriesDataset> {
   /** Contains a {@link Set} for each series. In each of these sets the
    *  indices of the selected items are stored. */
   protected Map<Comparable,Set<Integer>> selectedSeriesIdx = new HashMap<Comparable,Set<Integer>>();

Added: trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java	2009-05-30 16:28:52 UTC (rev 129)
+++ trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java	2009-05-30 16:34:00 UTC (rev 130)
@@ -0,0 +1,70 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+
+package skrueger.geotools.selection;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionListener;
+
+import org.jfree.chart.JFreeChart;
+import org.jfree.data.general.Dataset;
+
+import schmitzm.jfree.chart.renderer.SelectionRenderer;
+import schmitzm.jfree.chart.selection.DatasetSelectionListener;
+import schmitzm.jfree.chart.selection.DatasetSelectionModel;
+import schmitzm.jfree.chart.selection.SelectionChangeEvent;
+
+/**
+ * This class keeps the selection of a {@link Dataset} (based on feature
+ * attributes) synchronized with the {@link StyledLayerSelectionModel} of a layer.
+ * This is done by implementing:
+ * <ul>
+ * <li>a {@link PropertyChangeListener} which listens to the
+ * {@link StyledLayerSelectionModel} and accordingly changes the {@link SelectionRenderer}
+ * selection</li>
+ * <li>a {@link DatasetSelectionModel} which listens to the {@link SelectionRenderer} and
+ * accordingly changes the {@link StyledLayerSelectionModel} selection</li>
+ * </ul>
+ * After creating, the instance of this synchronizer must be added as listener
+ * to both, the {@link StyledLayerSelectionModel} and the chart's
+ * {@link SelectionRenderer}.
+ * 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
+                                        implements DatasetSelectionListener
+                                        {
+
+  /**
+   * Creates a new synchronizer.
+   * @param layerSelModel
+   */
+  public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel) {
+    super(layerSelModel);
+  }
+
+  @Override
+  public void propertyChange(PropertyChangeEvent evt) {
+    // TODO apply selection changes to the ChartSelectionModel
+  }
+
+  @Override
+  public void selectionChanged(SelectionChangeEvent e) {
+    // TODO Auto-generated method stub
+    
+  }
+  
+
+}



More information about the Schmitzm-commits mailing list