/[schmitzm]/branches/2.1/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
ViewVC logotype

Diff of /branches/2.1/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 134 by mojays, Sat May 30 20:22:00 2009 UTC revision 136 by mojays, Wed Jun 3 19:53:33 2009 UTC
# Line 15  import java.beans.PropertyChangeEvent; Line 15  import java.beans.PropertyChangeEvent;
15  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
16  import java.util.Vector;  import java.util.Vector;
17    
 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;  
18  import org.jfree.data.general.Dataset;  import org.jfree.data.general.Dataset;
 import org.jfree.data.general.SeriesDataset;  
 import org.jfree.data.xy.XYSeriesCollection;  
19    
 import schmitzm.geotools.gui.FeatureCollectionTableModel;  
20  import schmitzm.jfree.chart.renderer.SelectionRenderer;  import schmitzm.jfree.chart.renderer.SelectionRenderer;
21    import schmitzm.jfree.chart.selection.DatasetSelectionChangeEvent;
22  import schmitzm.jfree.chart.selection.DatasetSelectionListener;  import schmitzm.jfree.chart.selection.DatasetSelectionListener;
23  import schmitzm.jfree.chart.selection.DatasetSelectionModel;  import schmitzm.jfree.chart.selection.DatasetSelectionModel;
24  import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;  import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider;
25  import schmitzm.jfree.chart.selection.DatasetSelectionChangeEvent;  import schmitzm.jfree.feature.FeatureDatasetSelectionModel;
 import schmitzm.jfree.feature.Feature2DatasetItemDatasetGroup;  
26    
27  /**  /**
28   * This class keeps the selection of a {@link Dataset} (based on feature   * This class keeps the selection of a {@link Dataset} (based on feature
# Line 54  public class ChartSelectionSynchronizer Line 45  public class ChartSelectionSynchronizer
45                                          implements DatasetSelectionListener {                                          implements DatasetSelectionListener {
46    
47    /** Holds the chart datset to keep synchronized with the layer selection model. */    /** Holds the chart datset to keep synchronized with the layer selection model. */
48    protected DatasetSelectionModel<?> datasetSelModel = null;    protected FeatureDatasetSelectionModel<?> datasetSelModel = null;
49    /** Hold the mapping between feature IDs and dataset items. */  
   protected Feature2DatasetItemDatasetGroup<?> mapping = null;  
     
50    /**    /**
51     * Creates a new synchronizer.     * Creates a new synchronizer.
52     * @param layerSelModel     * @param layerSelModel
# Line 67  public class ChartSelectionSynchronizer Line 56  public class ChartSelectionSynchronizer
56     *            dataset selection model to keep synchronized with the layer     *            dataset selection model to keep synchronized with the layer
57     *            selection model     *            selection model
58     */     */
59    public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) {    public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, FeatureDatasetSelectionModel<?> datasetSelModel) {
60      super(layerSelModel);      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.");  
61      this.datasetSelModel = datasetSelModel;      this.datasetSelModel = datasetSelModel;
     this.mapping         = (Feature2DatasetItemDatasetGroup<?>)datasetSelModel.getDataset().getGroup();  
62    }    }
63    
64    /**    /**
65     * Called by {@link StyledLayerSelectionModel} when a the selection on other     * Called by {@link StyledLayerSelectionModel} when the selection on other
66     * selection components (map, table, ...) has changed. When calling this     * selection components (map, table, ...) has changed. When calling this
67     * method changes the dataset selection according to the     * method changes the dataset selection according to the
68     * {@link StyledLayerSelectionModel} selection.     * {@link StyledLayerSelectionModel} selection.
# Line 105  public class ChartSelectionSynchronizer Line 88  public class ChartSelectionSynchronizer
88    
89      datasetSelModel.setValueIsAdjusting(true);      datasetSelModel.setValueIsAdjusting(true);
90      datasetSelModel.clearSelection();      datasetSelModel.clearSelection();
91            for (String fID : newSelection)
92      for (String fID : newSelection) {        datasetSelModel.setItemSelected(fID, true);
       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");  
       }  
     }  
93      datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically!      datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically!
94    
95      // Danger of event circles in valueChanged(..) banned      // Danger of event circles in valueChanged(..) banned
96      selectionChangeCausedByMe = false;      selectionChangeCausedByMe = false;
97    }    }
98    
99      /**
100       * Called when the chart selection is changed by the user. When calling this
101       * method changes the selection of the {@link StyledLayerSelectionModel}.
102       * @param evt an event
103       */
104    @Override    @Override
105    public void selectionChanged(DatasetSelectionChangeEvent e) {    public void selectionChanged(DatasetSelectionChangeEvent evt) {
106      // TODO Auto-generated method stub      // ignore event if it is part of multiple events
107            if (evt != null && evt.getSource().getValueIsAdjusting())
108            return;
109        // ignore event if it is caused by the ChartSelectionSynchronizer
110        if (selectionChangeCausedByMe)
111            return;
112    
113        // Avoid event circles in propertyChange(..)
114        selectionChangeCausedByMe = true;
115    
116        // reset the selection of the DpLayerSelectionModel
117        layerSelModel.setValueIsAdjusting(true);
118        layerSelModel.clearSelection();
119        for (String featureID : datasetSelModel.getSelectedFeatures())
120          layerSelModel.addSelection(featureID);
121        layerSelModel.setValueIsAdjusting(false);
122    
123        // Danger of event circles in propertyChange(..) banned
124        selectionChangeCausedByMe = false;
125    }    }
126        
127    

Legend:
Removed from v.134  
changed lines
  Added in v.136

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26