/[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 131 by mojays, Sat May 30 19:58:13 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;
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 52  import schmitzm.jfree.chart.selection.Da Line 44  import schmitzm.jfree.chart.selection.Da
44  public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>  public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
45                                          implements DatasetSelectionListener {                                          implements DatasetSelectionListener {
46    
47    /**    /** Holds the chart datset to keep synchronized with the layer selection model. */
48     * Holds the chart datset to keep synchronized with the layer selection model.    protected FeatureDatasetSelectionModel<?> datasetSelModel = null;
    */  
   protected DatasetSelectionModel<?> datasetSelModel = null;  
49    
50    /**    /**
51     * Creates a new synchronizer.     * Creates a new synchronizer.
# Line 66  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);
61      this.datasetSelModel = datasetSelModel;      this.datasetSelModel = datasetSelModel;
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 98  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      XYSeriesCollection dataset = (XYSeriesCollection)datasetSelModel.getDataset();        datasetSelModel.setItemSelected(fID, true);
 //    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");  
 //      }  
 //    }  
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.131  
changed lines
  Added in v.136

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26