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 |
|
|
35 |
/** |
/** |
36 |
* This class keeps the selection of a {@link Dataset} (based on feature |
* This class keeps the selection of a {@link Dataset} (based on feature |
45 |
* </ul> |
* </ul> |
46 |
* After creating, the instance of this synchronizer must be added as listener |
* After creating, the instance of this synchronizer must be added as listener |
47 |
* to both, the {@link StyledLayerSelectionModel} and the chart's |
* to both, the {@link StyledLayerSelectionModel} and the chart's |
48 |
* {@link SelectionRenderer}. |
* {@link DatasetSelectionModel} (e.g. the renderer). |
49 |
* |
* @see DatasetSelectionModelProvider |
50 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
51 |
*/ |
*/ |
52 |
public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
53 |
implements DatasetSelectionListener |
implements DatasetSelectionListener { |
54 |
{ |
|
55 |
|
/** |
56 |
|
* Holds the chart datset to keep synchronized with the layer selection model. |
57 |
|
*/ |
58 |
|
protected DatasetSelectionModel<?> datasetSelModel = null; |
59 |
|
|
60 |
/** |
/** |
61 |
* Creates a new synchronizer. |
* Creates a new synchronizer. |
62 |
* @param layerSelModel |
* @param layerSelModel |
63 |
|
* layer selection model to keep synchronized with the dataset |
64 |
|
* selection model |
65 |
|
* @param datasetSelModel |
66 |
|
* dataset selection model to keep synchronized with the layer |
67 |
|
* selection model |
68 |
*/ |
*/ |
69 |
public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel) { |
public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) { |
70 |
super(layerSelModel); |
super(layerSelModel); |
71 |
|
this.datasetSelModel = datasetSelModel; |
72 |
} |
} |
73 |
|
|
74 |
|
/** |
75 |
|
* Called by {@link StyledLayerSelectionModel} when a the selection on other |
76 |
|
* selection components (map, table, ...) has changed. When calling this |
77 |
|
* method changes the dataset selection according to the |
78 |
|
* {@link StyledLayerSelectionModel} selection. |
79 |
|
* @param evt an event |
80 |
|
*/ |
81 |
@Override |
@Override |
82 |
public void propertyChange(PropertyChangeEvent evt) { |
public void propertyChange(PropertyChangeEvent evt) { |
83 |
// TODO apply selection changes to the ChartSelectionModel |
if (!(evt instanceof StyledLayerSelectionEvent)) |
84 |
|
return; |
85 |
|
StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt; |
86 |
|
// Only react on own layer and ignore events invoked by |
87 |
|
// this component itself |
88 |
|
if (selEvt.getEmitter() != layerSelModel || selectionChangeCausedByMe) |
89 |
|
return; |
90 |
|
// Apply new selection on chart (except this event is one of |
91 |
|
// some more events) |
92 |
|
Vector<String> newSelection = layerSelModel.getSelection(); |
93 |
|
if (newSelection == null) |
94 |
|
return; |
95 |
|
|
96 |
|
// Avoid event circles in valueChanged(..) |
97 |
|
selectionChangeCausedByMe = true; |
98 |
|
|
99 |
|
datasetSelModel.setValueIsAdjusting(true); |
100 |
|
datasetSelModel.clearSelection(); |
101 |
|
|
102 |
|
XYSeriesCollection dataset = (XYSeriesCollection)datasetSelModel.getDataset(); |
103 |
|
// dataset.getSeries(0).getDataItem(index); |
104 |
|
// |
105 |
|
// |
106 |
|
// for (String fid : newSelection) { |
107 |
|
// int modelIdx = featureTableModel.findFeature(fid); |
108 |
|
// if (modelIdx >= 0) { |
109 |
|
// int tableIdx = featureTable.convertRowIndexToView(modelIdx); |
110 |
|
// tableSelModel.addSelectionInterval(tableIdx, tableIdx); |
111 |
|
// } else { |
112 |
|
// LOGGER.warn("Something that is not visible in the Table should be selected"); |
113 |
|
// } |
114 |
|
// } |
115 |
|
datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically! |
116 |
|
|
117 |
|
// Danger of event circles in valueChanged(..) banned |
118 |
|
selectionChangeCausedByMe = false; |
119 |
} |
} |
120 |
|
|
121 |
@Override |
@Override |
122 |
public void selectionChanged(SelectionChangeEvent e) { |
public void selectionChanged(DatasetSelectionChangeEvent e) { |
123 |
// TODO Auto-generated method stub |
// TODO Auto-generated method stub |
124 |
|
|
125 |
} |
} |