[Schmitzm-commits] r134 - in trunk/src: schmitzm/jfree schmitzm/jfree/feature skrueger/geotools/selection

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


Author: mojays
Date: 2009-05-30 22:22:00 +0200 (Sat, 30 May 2009)
New Revision: 134

Added:
   trunk/src/schmitzm/jfree/feature/
   trunk/src/schmitzm/jfree/feature/Feature2DatasetItemDatasetGroup.java
Modified:
   trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
Log:
new Feature2DatasetItemDatasetGroup

Added: trunk/src/schmitzm/jfree/feature/Feature2DatasetItemDatasetGroup.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/Feature2DatasetItemDatasetGroup.java	2009-05-30 20:18:07 UTC (rev 133)
+++ trunk/src/schmitzm/jfree/feature/Feature2DatasetItemDatasetGroup.java	2009-05-30 20:22:00 UTC (rev 134)
@@ -0,0 +1,120 @@
+/** 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.feature;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.geotools.feature.Feature;
+import org.geotools.feature.FeatureCollection;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.general.DatasetGroup;
+
+/**
+ * This {@link DatasetGroup} is raped! It implements the mapping between
+ * an dataset item (point in chart) and the corresponding {@link Feature}.
+ * Because a {@link DatasetGroup} can be set to <b>every</b> {@link Dataset}, the
+ * mapping can be accessed everywhere the {@link Dataset} can be accessed,
+ * independently of the concrete {@link Dataset}. 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class Feature2DatasetItemDatasetGroup<E extends Comparable> extends DatasetGroup {
+  /** Holds the {@link FeatureCollection} for the mapping */
+  protected FeatureCollection featureCollection = null;
+  /** Holds the data item (E) for each feature ID (String). */
+  protected Map<String,E> fid2did = new HashMap<String, E>();
+  /** Holds the feature ID (String) for each data item (E). */
+  protected Map<E,String> did2fid = new HashMap<E, String>();
+  
+  /**
+   * Creates a "mapping" dataset group with a default id. 
+   */
+  public Feature2DatasetItemDatasetGroup() {
+    this(null);
+  }
+
+  /**
+   * Creates a "mapping" dataset group with a default id. 
+   * @param fc a {@link FeatureCollection} (can be {@code null}) 
+   */
+  public Feature2DatasetItemDatasetGroup(FeatureCollection fc) {
+    super();
+    this.featureCollection = fc;
+  }
+
+  /**
+   * Creates a "mapping" dataset group.
+   * @param fc a {@link FeatureCollection}
+   * @param id id for the group (can be {@code null})
+   */
+  public Feature2DatasetItemDatasetGroup(FeatureCollection fc, String id) {
+    super(id);
+    this.featureCollection = fc;
+  }
+  
+  /**
+   * Returns the {@link FeatureCollection} the mapping is provided for.
+   */
+  public FeatureCollection getFeatureCollection() {
+    return featureCollection;
+  }
+  
+  /**
+   * Sets the mapping between a feature ID and a dataset item.
+   * @param fID    feature ID
+   * @param dataID dataset item
+   */
+  public void setMapping(String fID, E dataID) {
+    fid2did.put(fID, dataID);
+    did2fid.put(dataID,fID);
+  }
+  
+  /**
+   * Removes the mapping between a feature ID and a dataset item.
+   * @param fID    feature ID
+   */
+  public void removeMappingForFeatureID(String fID) {
+    E dataID = fid2did.remove(fID);
+    if ( dataID != null )
+      did2fid.remove(dataID);
+  }
+  
+  /**
+   * Removes the mapping between a feature ID and a dataset item.
+   * @param dateID data item
+   */
+  public void removeMappingForDataItem(E dataID) {
+    String fID = did2fid.remove(dataID);
+    if ( fID != null )
+      fid2did.remove(fID);
+  }
+
+  /**
+   * Returns the data item for a given feature ID.
+   * @param fID a feature ID
+   * @return {@code null} if no data item is registered for the feature ID
+   */
+  public E getDataID(String fID) {
+    return fid2did.get(fID);
+  }
+  
+  /**
+   * Returns feature ID for a given data item.
+   * @param dataID a date item
+   * @return {@code null} if feature ID is registered for the data item
+   */
+  public String getFeatureID(E itemID) {
+    return did2fid.get(itemID);
+  }
+ 
+
+}

Modified: trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java	2009-05-30 20:18:07 UTC (rev 133)
+++ trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java	2009-05-30 20:22:00 UTC (rev 134)
@@ -31,6 +31,7 @@
 import schmitzm.jfree.chart.selection.DatasetSelectionModel;
 import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;
 import schmitzm.jfree.chart.selection.DatasetSelectionChangeEvent;
+import schmitzm.jfree.feature.Feature2DatasetItemDatasetGroup;
 
 /**
  * This class keeps the selection of a {@link Dataset} (based on feature
@@ -52,11 +53,11 @@
 public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
                                         implements DatasetSelectionListener {
 
-  /**
-   * Holds the chart datset to keep synchronized with the layer selection model.
-   */
+  /** Holds the chart datset to keep synchronized with the layer selection model. */
   protected DatasetSelectionModel<?> datasetSelModel = null;
-
+  /** Hold the mapping between feature IDs and dataset items. */
+  protected Feature2DatasetItemDatasetGroup<?> mapping = null; 
+  
   /**
    * Creates a new synchronizer.
    * @param layerSelModel
@@ -68,7 +69,13 @@
    */
   public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) {
     super(layerSelModel);
+    // the dataset selection model must provide a mapping
+    // to the feature IDs
+    if ( datasetSelModel.getDataset() == null ||
+         !(datasetSelModel.getDataset().getGroup() instanceof Feature2DatasetItemDatasetGroup) )
+      throw new UnsupportedOperationException("Dataset must provide a Feature2DatasetItemDatasetGroup as DatasetGroup.");
     this.datasetSelModel = datasetSelModel;
+    this.mapping         = (Feature2DatasetItemDatasetGroup<?>)datasetSelModel.getDataset().getGroup();
   }
 
   /**
@@ -99,19 +106,14 @@
     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");
-//      }
-//    }
+    for (String fID : newSelection) {
+      Comparable dataID = mapping.getDataID(fID);
+      if (dataID != null ) {
+//TODO: Fallunterscheidung zwischen den unterschiedlichen DatasetSelectionModel-Typen!!
+      } else {
+          LOGGER.warn("Something that is not visible in the chart should be selected");
+      }
+    }
     datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically!
 
     // Danger of event circles in valueChanged(..) banned



More information about the Schmitzm-commits mailing list