1 |
mojays |
130 |
/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM) |
2 |
|
|
|
3 |
|
|
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. |
4 |
|
|
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. |
5 |
|
|
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 |
6 |
|
|
|
7 |
|
|
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. |
8 |
|
|
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. |
9 |
|
|
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. |
10 |
|
|
**/ |
11 |
|
|
|
12 |
|
|
package skrueger.geotools.selection; |
13 |
|
|
|
14 |
|
|
import java.beans.PropertyChangeEvent; |
15 |
|
|
import java.beans.PropertyChangeListener; |
16 |
mojays |
131 |
import java.util.Vector; |
17 |
mojays |
130 |
|
18 |
|
|
import javax.swing.JTable; |
19 |
|
|
import javax.swing.ListSelectionModel; |
20 |
|
|
import javax.swing.event.ListSelectionListener; |
21 |
mojays |
131 |
import javax.swing.plaf.basic.BasicTreeUI.SelectionModelPropertyChangeHandler; |
22 |
mojays |
130 |
|
23 |
|
|
import org.jfree.chart.JFreeChart; |
24 |
|
|
import org.jfree.data.general.Dataset; |
25 |
mojays |
131 |
import org.jfree.data.general.SeriesDataset; |
26 |
|
|
import org.jfree.data.xy.XYSeriesCollection; |
27 |
mojays |
130 |
|
28 |
mojays |
131 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
29 |
mojays |
130 |
import schmitzm.jfree.chart.renderer.SelectionRenderer; |
30 |
|
|
import schmitzm.jfree.chart.selection.DatasetSelectionListener; |
31 |
|
|
import schmitzm.jfree.chart.selection.DatasetSelectionModel; |
32 |
mojays |
131 |
import schmitzm.jfree.chart.selection.DatasetSelectionModelProvider; |
33 |
|
|
import schmitzm.jfree.chart.selection.DatasetSelectionChangeEvent; |
34 |
mojays |
130 |
|
35 |
|
|
/** |
36 |
|
|
* This class keeps the selection of a {@link Dataset} (based on feature |
37 |
|
|
* attributes) synchronized with the {@link StyledLayerSelectionModel} of a layer. |
38 |
|
|
* This is done by implementing: |
39 |
|
|
* <ul> |
40 |
|
|
* <li>a {@link PropertyChangeListener} which listens to the |
41 |
|
|
* {@link StyledLayerSelectionModel} and accordingly changes the {@link SelectionRenderer} |
42 |
|
|
* selection</li> |
43 |
|
|
* <li>a {@link DatasetSelectionModel} which listens to the {@link SelectionRenderer} and |
44 |
|
|
* accordingly changes the {@link StyledLayerSelectionModel} selection</li> |
45 |
|
|
* </ul> |
46 |
|
|
* After creating, the instance of this synchronizer must be added as listener |
47 |
|
|
* to both, the {@link StyledLayerSelectionModel} and the chart's |
48 |
mojays |
131 |
* {@link DatasetSelectionModel} (e.g. the renderer). |
49 |
|
|
* @see DatasetSelectionModelProvider |
50 |
mojays |
130 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
51 |
|
|
*/ |
52 |
|
|
public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
53 |
mojays |
131 |
implements DatasetSelectionListener { |
54 |
mojays |
130 |
|
55 |
|
|
/** |
56 |
mojays |
131 |
* Holds the chart datset to keep synchronized with the layer selection model. |
57 |
|
|
*/ |
58 |
|
|
protected DatasetSelectionModel<?> datasetSelModel = null; |
59 |
|
|
|
60 |
|
|
/** |
61 |
mojays |
130 |
* Creates a new synchronizer. |
62 |
|
|
* @param layerSelModel |
63 |
mojays |
131 |
* 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 |
mojays |
130 |
*/ |
69 |
mojays |
131 |
public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) { |
70 |
mojays |
130 |
super(layerSelModel); |
71 |
mojays |
131 |
this.datasetSelModel = datasetSelModel; |
72 |
mojays |
130 |
} |
73 |
|
|
|
74 |
mojays |
131 |
/** |
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 |
mojays |
130 |
@Override |
82 |
|
|
public void propertyChange(PropertyChangeEvent evt) { |
83 |
mojays |
131 |
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 |
mojays |
130 |
} |
120 |
|
|
|
121 |
|
|
@Override |
122 |
mojays |
131 |
public void selectionChanged(DatasetSelectionChangeEvent e) { |
123 |
mojays |
130 |
// TODO Auto-generated method stub |
124 |
|
|
|
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
} |