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

Annotation of /trunk/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 134 - (hide annotations)
Sat May 30 20:22:00 2009 UTC (15 years, 9 months ago) by mojays
File size: 6702 byte(s)
new Feature2DatasetItemDatasetGroup
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 134 import schmitzm.jfree.feature.Feature2DatasetItemDatasetGroup;
35 mojays 130
36     /**
37     * This class keeps the selection of a {@link Dataset} (based on feature
38     * attributes) synchronized with the {@link StyledLayerSelectionModel} of a layer.
39     * This is done by implementing:
40     * <ul>
41     * <li>a {@link PropertyChangeListener} which listens to the
42     * {@link StyledLayerSelectionModel} and accordingly changes the {@link SelectionRenderer}
43     * selection</li>
44     * <li>a {@link DatasetSelectionModel} which listens to the {@link SelectionRenderer} and
45     * accordingly changes the {@link StyledLayerSelectionModel} selection</li>
46     * </ul>
47     * After creating, the instance of this synchronizer must be added as listener
48     * to both, the {@link StyledLayerSelectionModel} and the chart's
49 mojays 131 * {@link DatasetSelectionModel} (e.g. the renderer).
50     * @see DatasetSelectionModelProvider
51 mojays 130 * @author <a href="mailto:[email protected]">Martin Schmitz</a>
52     */
53     public class ChartSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
54 mojays 131 implements DatasetSelectionListener {
55 mojays 130
56 mojays 134 /** Holds the chart datset to keep synchronized with the layer selection model. */
57 mojays 131 protected DatasetSelectionModel<?> datasetSelModel = null;
58 mojays 134 /** Hold the mapping between feature IDs and dataset items. */
59     protected Feature2DatasetItemDatasetGroup<?> mapping = null;
60    
61 mojays 131 /**
62 mojays 130 * Creates a new synchronizer.
63     * @param layerSelModel
64 mojays 131 * 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 mojays 130 */
70 mojays 131 public ChartSelectionSynchronizer(StyledFeatureLayerSelectionModel layerSelModel, DatasetSelectionModel<?> datasetSelModel) {
71 mojays 130 super(layerSelModel);
72 mojays 134 // 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 mojays 131 this.datasetSelModel = datasetSelModel;
78 mojays 134 this.mapping = (Feature2DatasetItemDatasetGroup<?>)datasetSelModel.getDataset().getGroup();
79 mojays 130 }
80    
81 mojays 131 /**
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 mojays 130 @Override
89     public void propertyChange(PropertyChangeEvent evt) {
90 mojays 131 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 mojays 134 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 mojays 131 datasetSelModel.setValueIsAdjusting(false); // event is fired autmatically!
118    
119     // Danger of event circles in valueChanged(..) banned
120     selectionChangeCausedByMe = false;
121 mojays 130 }
122    
123     @Override
124 mojays 131 public void selectionChanged(DatasetSelectionChangeEvent e) {
125 mojays 130 // TODO Auto-generated method stub
126    
127     }
128    
129    
130     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26