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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat May 30 21:58:14 CEST 2009


Author: mojays
Date: 2009-05-30 21:58:13 +0200 (Sat, 30 May 2009)
New Revision: 131

Added:
   trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionChangeEvent.java
Modified:
   trunk/src/schmitzm/jfree/JFreeChartUtil.java
   trunk/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java
   trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java
   trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java
   trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java
   trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
   trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
Log:


Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -74,15 +74,15 @@
     if ( !Number.class.isAssignableFrom(yType.getBinding()) )
       throw new UnsupportedOperationException("Attribute must be numeric: "+yAttr);
     
-    XYSeriesCollection dataset = new XYSeriesCollection();
-    FeatureIterator    fi      = fc.features();
-    XYSeries xySeries          = new XYSeries(key);
+    XYSeriesCollection dataset   = new XYSeriesCollection();
+    FeatureIterator    fi        = fc.features();
+    XYSeries           xySeries  = new XYSeries(key,true,true);
     dataset.addSeries(xySeries);
     for (;fi.hasNext();) {
       Feature f = fi.next();
       Number xValue = (Number)f.getAttribute(xAttr);
       Number yValue = (Number)f.getAttribute(yAttr);
-      xySeries.addOrUpdate(xValue, yValue);
+      xySeries.add(xValue, yValue);
     }
     return dataset;
   }

Modified: trunk/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/schmitzm/jfree/chart/renderer/SelectionRenderer.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -12,6 +12,7 @@
 
 import java.awt.Paint;
 
+import schmitzm.jfree.chart.selection.AbstractDatasetSelectionModel;
 import schmitzm.jfree.chart.selection.DatasetSelectionModel;
 import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;
 

Modified: trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/schmitzm/jfree/chart/selection/AbstractDatasetSelectionModel.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -40,7 +40,13 @@
   
   /** Holds the listeners to the {@link DatasetSelectionModel}. */
   protected Vector<DatasetSelectionListener> listeners = new Vector<DatasetSelectionListener>();
-  
+
+  /** Indicates whether a selection change is a part of multiple
+   *  changes. If {@code true} {@link #refreshSelection()} has NO effect
+   *  until {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
+   *  is called. */
+  private boolean valueIsAdjusting = false;
+
   /**
    * Creates a new selection model.
    * @param dataset {@link Dataset} whose data can be selected
@@ -91,17 +97,44 @@
   }
 
   /**
+   * Returns whether the current selection change is a part of multiple
+   * changes. If {@code true} {@link #refreshSelection()} has no effect
+   * and no {@link DatasetSelectionChangeEvent} is fired until
+   * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
+   * is called.
+   */
+  public boolean getValueIsAdjusting() {
+    return this.valueIsAdjusting;
+  }
+
+  /**
+   * Sets whether the following selection changes are part of multiple
+   * changes. If {@code true} {@link #refreshSelection()} has no effect
+   * and no {@link DatasetSelectionChangeEvent} event is fired.
+   * If the value is set from {@code true} to {@code false} an automatic
+   * refresh is initiated.
+   * @see #refreshSelection()
+   */
+  public void setValueIsAdjusting(boolean valueIsAdjusting) {
+    if ( valueIsAdjusting != this.valueIsAdjusting ) {
+      this.valueIsAdjusting = valueIsAdjusting;
+      if ( !this.valueIsAdjusting )
+        refreshSelection();
+    }
+  }
+  
+  /**
    * Informs all listeners about a general selection change.
    */
-  public void fireSelectionChanged() {
+  public void refreshSelection() {
     for (DatasetSelectionListener l : listeners)
       l.selectionChanged( createSelectionChangeEvent() );
   }
   
   /**
-   * Creates a {@link SelectionChangeEvent}.
+   * Creates a {@link DatasetSelectionChangeEvent}.
    */
-  protected SelectionChangeEvent createSelectionChangeEvent() {
-    return new SelectionChangeEvent(this);
+  protected DatasetSelectionChangeEvent createSelectionChangeEvent() {
+    return new DatasetSelectionChangeEvent(this);
   }
 }

Added: trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionChangeEvent.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionChangeEvent.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionChangeEvent.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -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 DatasetSelectionChangeEvent extends ChangeEvent {
+  /**
+   * Creates a new event.
+   * @param source
+   */
+  public DatasetSelectionChangeEvent(Object source) {
+    super(source);
+  }
+}

Modified: trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionListener.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -19,5 +19,5 @@
    * Called when the selection of a {@link DatasetSelectionModel} has changed.
    * @param e the event
    */
-  public void selectionChanged(SelectionChangeEvent e);
+  public void selectionChanged(DatasetSelectionChangeEvent e);
 }

Modified: trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/schmitzm/jfree/chart/selection/DatasetSelectionModel.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -16,6 +16,7 @@
 import org.jfree.data.general.SeriesDataset;
 
 import schmitzm.jfree.JFreeChartUtil;
+import skrueger.geotools.selection.StyledLayerSelectionEvent;
 
 /**
  * This selection model maintains whether items of a {@link Dataset} are selected
@@ -50,7 +51,26 @@
   public void removeSelectionListener(DatasetSelectionListener listener);
   
   /**
+   * Returns whether the current selection change is a part of multiple
+   * changes. If {@code true} {@link #refreshSelection()} has no effect
+   * and no {@link DatasetSelectionChangeEvent} is fired until
+   * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
+   * is called.
+   */
+  public boolean getValueIsAdjusting();
+
+  /**
+   * Sets whether the following selection changes are part of multiple
+   * changes. If {@code true} {@link #refreshSelection()} has no effect
+   * and no {@link DatasetSelectionChangeEvent} event is fired.
+   * If the value is set from {@code true} to {@code false} an automatic
+   * refresh is initiated.
+   * @see #refreshSelection()
+   */
+  public void setValueIsAdjusting(boolean valueIsAdjusting);
+
+  /**
    * Informs all listeners about a general selection change.
    */
-  public void fireSelectionChanged();
+  public void refreshSelection();
 }

Modified: trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -13,18 +13,24 @@
 
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.Vector;
 
 import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionListener;
+import javax.swing.plaf.basic.BasicTreeUI.SelectionModelPropertyChangeHandler;
 
 import org.jfree.chart.JFreeChart;
 import org.jfree.data.general.Dataset;
+import org.jfree.data.general.SeriesDataset;
+import org.jfree.data.xy.XYSeriesCollection;
 
+import schmitzm.geotools.gui.FeatureCollectionTableModel;
 import schmitzm.jfree.chart.renderer.SelectionRenderer;
 import schmitzm.jfree.chart.selection.DatasetSelectionListener;
 import schmitzm.jfree.chart.selection.DatasetSelectionModel;
-import schmitzm.jfree.chart.selection.SelectionChangeEvent;
+import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;
+import schmitzm.jfree.chart.selection.DatasetSelectionChangeEvent;
 
 /**
  * This class keeps the selection of a {@link Dataset} (based on feature
@@ -39,29 +45,81 @@
  * </ul>
  * After creating, the instance of this synchronizer must be added as listener
  * to both, the {@link StyledLayerSelectionModel} and the chart's
- * {@link SelectionRenderer}.
- * 
+ * {@link DatasetSelectionModel} (e.g. the renderer).
+ * @see DatasetSelectionModelProvider
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
  */
 public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
-                                        implements DatasetSelectionListener
-                                        {
+                                        implements DatasetSelectionListener {
 
   /**
+   * Holds the chart datset to keep synchronized with the layer selection model.
+   */
+  protected DatasetSelectionModel<?> datasetSelModel = null;
+
+  /**
    * Creates a new synchronizer.
    * @param layerSelModel
+   *             layer selection model to keep synchronized with the dataset
+   *             selection model
+   * @param datasetSelModel
+   *            dataset selection model to keep synchronized with the layer
+   *            selection model
    */
-  public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel) {
+  public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) {
     super(layerSelModel);
+    this.datasetSelModel = datasetSelModel;
   }
 
+  /**
+   * Called by {@link StyledLayerSelectionModel} when a the selection on other
+   * selection components (map, table, ...) has changed. When calling this
+   * method changes the dataset selection according to the
+   * {@link StyledLayerSelectionModel} selection.
+   * @param evt an event
+   */
   @Override
   public void propertyChange(PropertyChangeEvent evt) {
-    // TODO apply selection changes to the ChartSelectionModel
+    if (!(evt instanceof StyledLayerSelectionEvent))
+      return;
+    StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt;
+    // Only react on own layer and ignore events invoked by
+    // this component itself
+    if (selEvt.getEmitter() != layerSelModel || selectionChangeCausedByMe)
+        return;
+    // Apply new selection on chart (except this event is one of
+    // some more events)
+    Vector<String> newSelection = layerSelModel.getSelection();
+    if (newSelection == null)
+      return;
+
+    // Avoid event circles in valueChanged(..)
+    selectionChangeCausedByMe = true;
+
+    datasetSelModel.setValueIsAdjusting(true);
+    datasetSelModel.clearSelection();
+    
+    XYSeriesCollection dataset = (XYSeriesCollection)datasetSelModel.getDataset();
+//    dataset.getSeries(0).getDataItem(index);
+//    
+//    
+//    for (String fid : newSelection) {
+//      int modelIdx = featureTableModel.findFeature(fid);
+//      if (modelIdx >= 0) {
+//          int tableIdx = featureTable.convertRowIndexToView(modelIdx);
+//          tableSelModel.addSelectionInterval(tableIdx, tableIdx);
+//      } else {
+//          LOGGER.warn("Something that is not visible in the Table should be selected");
+//      }
+//    }
+    datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically!
+
+    // Danger of event circles in valueChanged(..) banned
+    selectionChangeCausedByMe = false;
   }
 
   @Override
-  public void selectionChanged(SelectionChangeEvent e) {
+  public void selectionChanged(DatasetSelectionChangeEvent e) {
     // TODO Auto-generated method stub
     
   }

Modified: trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
===================================================================
--- trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java	2009-05-30 16:34:00 UTC (rev 130)
+++ trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java	2009-05-30 19:58:13 UTC (rev 131)
@@ -108,7 +108,7 @@
 
 
   /**
-   * Returns whether the current selection changes are a part of multiple
+   * Returns whether the current selection change is a part of multiple
    * changes. If {@code true} {@link #refreshSelection()} has no effect
    * and no {@link StyledLayerSelectionEvent} is fired until
    * {@link #setValueIsAdjusting(boolean) setValueIsAdjusting(false)}
@@ -119,7 +119,7 @@
   }
 
   /**
-   * Sets whether the following selection changes are a part of multiple
+   * Sets whether the following selection changes are part of multiple
    * changes. If {@code true} {@link #refreshSelection()} has no effect
    * and no {@link StyledLayerSelectionEvent} event is fired.
    * If the value is set from {@code true} to {@code false} an automatic



More information about the Schmitzm-commits mailing list