13 |
|
|
14 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
15 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
16 |
|
import java.util.Vector; |
17 |
|
|
18 |
import javax.swing.JTable; |
import javax.swing.JTable; |
19 |
import javax.swing.ListSelectionModel; |
import javax.swing.ListSelectionModel; |
20 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
21 |
|
import javax.swing.plaf.basic.BasicTreeUI.SelectionModelPropertyChangeHandler; |
22 |
|
|
23 |
import org.jfree.chart.JFreeChart; |
import org.jfree.chart.JFreeChart; |
24 |
import org.jfree.data.general.Dataset; |
import org.jfree.data.general.Dataset; |
25 |
|
import org.jfree.data.general.SeriesDataset; |
26 |
|
import org.jfree.data.xy.XYSeriesCollection; |
27 |
|
|
28 |
|
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
29 |
import schmitzm.jfree.chart.renderer.SelectionRenderer; |
import schmitzm.jfree.chart.renderer.SelectionRenderer; |
30 |
import schmitzm.jfree.chart.selection.DatasetSelectionListener; |
import schmitzm.jfree.chart.selection.DatasetSelectionListener; |
31 |
import schmitzm.jfree.chart.selection.DatasetSelectionModel; |
import schmitzm.jfree.chart.selection.DatasetSelectionModel; |
32 |
import schmitzm.jfree.chart.selection.SelectionChangeEvent; |
import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider; |
33 |
|
import schmitzm.jfree.chart.selection.DatasetSelectionChangeEvent; |
34 |
|
import schmitzm.jfree.feature.Feature2DatasetItemDatasetGroup; |
35 |
|
|
36 |
/** |
/** |
37 |
* This class keeps the selection of a {@link Dataset} (based on feature |
* This class keeps the selection of a {@link Dataset} (based on feature |
46 |
* </ul> |
* </ul> |
47 |
* After creating, the instance of this synchronizer must be added as listener |
* After creating, the instance of this synchronizer must be added as listener |
48 |
* to both, the {@link StyledLayerSelectionModel} and the chart's |
* to both, the {@link StyledLayerSelectionModel} and the chart's |
49 |
* {@link SelectionRenderer}. |
* {@link DatasetSelectionModel} (e.g. the renderer). |
50 |
* |
* @see DatasetSelectionModelProvider |
51 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
52 |
*/ |
*/ |
53 |
public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
54 |
implements DatasetSelectionListener |
implements DatasetSelectionListener { |
|
{ |
|
55 |
|
|
56 |
|
/** Holds the chart datset to keep synchronized with the layer selection model. */ |
57 |
|
protected DatasetSelectionModel<?> datasetSelModel = null; |
58 |
|
/** Hold the mapping between feature IDs and dataset items. */ |
59 |
|
protected Feature2DatasetItemDatasetGroup<?> mapping = null; |
60 |
|
|
61 |
/** |
/** |
62 |
* Creates a new synchronizer. |
* Creates a new synchronizer. |
63 |
* @param layerSelModel |
* @param layerSelModel |
64 |
|
* layer selection model to keep synchronized with the dataset |
65 |
|
* selection model |
66 |
|
* @param datasetSelModel |
67 |
|
* dataset selection model to keep synchronized with the layer |
68 |
|
* selection model |
69 |
*/ |
*/ |
70 |
public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel) { |
public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) { |
71 |
super(layerSelModel); |
super(layerSelModel); |
72 |
|
// the dataset selection model must provide a mapping |
73 |
|
// to the feature IDs |
74 |
|
if ( datasetSelModel.getDataset() == null || |
75 |
|
!(datasetSelModel.getDataset().getGroup() instanceof Feature2DatasetItemDatasetGroup) ) |
76 |
|
throw new UnsupportedOperationException("Dataset must provide a Feature2DatasetItemDatasetGroup as DatasetGroup."); |
77 |
|
this.datasetSelModel = datasetSelModel; |
78 |
|
this.mapping = (Feature2DatasetItemDatasetGroup<?>)datasetSelModel.getDataset().getGroup(); |
79 |
} |
} |
80 |
|
|
81 |
|
/** |
82 |
|
* Called by {@link StyledLayerSelectionModel} when a the selection on other |
83 |
|
* selection components (map, table, ...) has changed. When calling this |
84 |
|
* method changes the dataset selection according to the |
85 |
|
* {@link StyledLayerSelectionModel} selection. |
86 |
|
* @param evt an event |
87 |
|
*/ |
88 |
@Override |
@Override |
89 |
public void propertyChange(PropertyChangeEvent evt) { |
public void propertyChange(PropertyChangeEvent evt) { |
90 |
// TODO apply selection changes to the ChartSelectionModel |
if (!(evt instanceof StyledLayerSelectionEvent)) |
91 |
|
return; |
92 |
|
StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt; |
93 |
|
// Only react on own layer and ignore events invoked by |
94 |
|
// this component itself |
95 |
|
if (selEvt.getEmitter() != layerSelModel || selectionChangeCausedByMe) |
96 |
|
return; |
97 |
|
// Apply new selection on chart (except this event is one of |
98 |
|
// some more events) |
99 |
|
Vector<String> newSelection = layerSelModel.getSelection(); |
100 |
|
if (newSelection == null) |
101 |
|
return; |
102 |
|
|
103 |
|
// Avoid event circles in valueChanged(..) |
104 |
|
selectionChangeCausedByMe = true; |
105 |
|
|
106 |
|
datasetSelModel.setValueIsAdjusting(true); |
107 |
|
datasetSelModel.clearSelection(); |
108 |
|
|
109 |
|
for (String fID : newSelection) { |
110 |
|
Comparable dataID = mapping.getDataID(fID); |
111 |
|
if (dataID != null ) { |
112 |
|
//TODO: Fallunterscheidung zwischen den unterschiedlichen DatasetSelectionModel-Typen!! |
113 |
|
} else { |
114 |
|
LOGGER.warn("Something that is not visible in the chart should be selected"); |
115 |
|
} |
116 |
|
} |
117 |
|
datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically! |
118 |
|
|
119 |
|
// Danger of event circles in valueChanged(..) banned |
120 |
|
selectionChangeCausedByMe = false; |
121 |
} |
} |
122 |
|
|
123 |
@Override |
@Override |
124 |
public void selectionChanged(SelectionChangeEvent e) { |
public void selectionChanged(DatasetSelectionChangeEvent e) { |
125 |
// TODO Auto-generated method stub |
// TODO Auto-generated method stub |
126 |
|
|
127 |
} |
} |