/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
ViewVC logotype

Contents of /branches/1.0-gt2-2.6/src/skrueger/geotools/selection/TableSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 111 - (show annotations)
Tue May 12 23:33:14 2009 UTC (15 years, 9 months ago) by alfonx
Original Path: trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
File MIME type: text/plain
File size: 7646 byte(s)
* Fixed some bugs with the SelectionListeners and the JMapPane. To make this work,  StyledFeatureLayerSelectionModel now extends StyledLayerSelectionModel<String>. So the selection is remembered as a Set of Feature-IDs. This change was needed, because Feature.java doesn't overwrite the equals method, and therefore the HashSet didn't function as expected.
* Added new Tools and BUttons to MapPaneToolBar.java to select features
* Changed a lot in MapPaneToolBar.java. It now allows to position Spaces, Actions and Tools via the ID field. (the new feature is to mix them)
* Fixed a bug in AV's ClickInfoPanel that would suddenly pop up an AtlasViewer if started from Geopublisher under special circumstances.
* Moving layers in the legend is using MapContext's move method instead of remove and insert.
* LayerPanel's remember* Maps now all have the MapLayer's ID as a key. 

This commit includes latest schmitzm.jar and av.jar. The av.jar is also commited to the ISDSS, but the ISDSS will still have the old schmitzm.jar. Latest schmitzm.jar in ISDSS should be updated ASAP. I just don't know where to put it.
1 /**
2 Copyright 2008 Stefan Alfons Krüger
3
4 atlas-framework - This file is part of the Atlas Framework
5
6 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.
7 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.
8 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
9
10 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.
11 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.
12 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.
13 **/
14 package skrueger.geotools.selection;
15
16 import java.beans.PropertyChangeEvent;
17 import java.beans.PropertyChangeListener;
18 import java.util.Vector;
19
20 import javax.swing.JTable;
21 import javax.swing.ListSelectionModel;
22 import javax.swing.event.ListSelectionEvent;
23 import javax.swing.event.ListSelectionListener;
24 import javax.swing.table.TableModel;
25
26 import org.geotools.feature.Feature;
27
28 import schmitzm.geotools.gui.FeatureCollectionTableModel;
29 import schmitzm.swing.table.PipedTableModel;
30 import schmitzm.swing.table.SelectionTableModel;
31 import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;
32 import skrueger.geotools.selection.StyledLayerSelectionEvent;
33 import skrueger.geotools.selection.StyledLayerSelectionModel;
34
35 /**
36 * This class keeps the selection of a (feature) {@link JTable} synchronized
37 * with the {@link StyledLayerSelectionModel} of a layer. This is done by
38 * implementing:
39 * <ul>
40 * <li>a {@link PropertyChangeListener} which listens to the
41 * {@link StyledLayerSelectionModel} and accordingly changes the {@link JTable}
42 * selection</li>
43 * <li>a {@link ListSelectionListener} which listens to the {@link JTable} 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 table's
48 * {@link ListSelectionModel}.
49 *
50 * @author <a href="mailto:[email protected]">Martin Schmitz</a>
51 * (University of Bonn/Germany)
52 */
53 public class TableSelectionSynchronizer extends
54 StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
55 implements ListSelectionListener {
56 /**
57 * Holds the table to keep synchronized with the layer selection model.
58 */
59 protected JTable featureTable = null;
60 /** Holds the table's data. */
61 protected FeatureCollectionTableModel featureTableModel = null;
62
63 /**
64 * Creates a new synchronizer
65 *
66 * @param layerSelModel
67 * layer selection model to keep synchronized with the feature
68 * table
69 * @param table
70 * table to keep synchronized with the layer selection model
71 */
72 public TableSelectionSynchronizer(
73 StyledFeatureLayerSelectionModel layerSelModel, JTable table) {
74 super(layerSelModel);
75
76 TableModel model = table.getModel();
77 if (model instanceof PipedTableModel)
78 model = ((PipedTableModel) table.getModel()).getPipedModel();
79
80 if (!(model instanceof FeatureCollectionTableModel))
81 throw new IllegalArgumentException(
82 "Table must have a model instance of FeatureCollectionTableModel");
83
84 this.featureTableModel = (FeatureCollectionTableModel) model;
85 this.featureTable = table;
86 }
87
88 /**
89 * Called by {@link StyledLayerSelectionModel} when a the selection on other
90 * selection components (map, chart, ...) has changed. When calling this
91 * method changes the table selection according to the
92 * {@link StyledLayerSelectionModel} selection.
93 *
94 * @param evt
95 * an event
96 */
97 @Override
98 public void propertyChange(PropertyChangeEvent evt) {
99 if (!(evt instanceof StyledLayerSelectionEvent))
100 return;
101 StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt;
102 // Only react on own layer and ignore events invoked by
103 // this component itself
104 if (selEvt.getEmitter() != layerSelModel || selectionChangeCausedByMe)
105 return;
106 // Apply new selection on table (except this event is one of
107 // some more events)
108 Vector<String> newSelection = layerSelModel.getSelection();
109 if (newSelection == null)
110 return;
111
112 // LOGGER.debug("Table pop changed "+selEvt);
113 // LOGGER.debug("Table pop changed to "+newSelection);
114
115 // Avoid event circles in valueChanged(..)
116 selectionChangeCausedByMe = true;
117
118 ListSelectionModel tableSelModel = featureTable.getSelectionModel();
119 tableSelModel.setValueIsAdjusting(true);
120 tableSelModel.clearSelection();
121 for (String fid : newSelection) {
122 int modelIdx = featureTableModel.findFeature(fid);
123 if (modelIdx >= 0) {
124 int tableIdx = featureTable.convertRowIndexToView(modelIdx);
125 tableSelModel.addSelectionInterval(tableIdx, tableIdx);
126 } else {
127 LOGGER
128 .warn("Something that is not visible in the Table should be selected");
129 }
130 }
131 tableSelModel.setValueIsAdjusting(false); // event is fired
132 // autmatically!
133
134 // Danger of event circles in valueChanged(..) banned
135 selectionChangeCausedByMe = false;
136 }
137
138 /**
139 * Called when the table selection is changed by the user. When calling this
140 * method changes the selection of the {@link StyledLayerSelectionModel}.
141 *
142 * @param evt
143 * an event
144 */
145 @Override
146 public void valueChanged(ListSelectionEvent evt) {
147 // ignore event if it is part of multiple events
148 if (evt != null && evt.getValueIsAdjusting())
149 return;
150 // ignore event if it is caused by the DpLayerVectorSelectionModel
151 if (selectionChangeCausedByMe)
152 return;
153
154 // Avoid event circles in propertyChange(..)
155 selectionChangeCausedByMe = true;
156
157 // reset the selection of the DpLayerSelectionModel
158 layerSelModel.setValueIsAdjusting(true);
159 LOGGER.debug("valueCahnged in TableSyncronizer vom Index "
160 + evt.getFirstIndex() + " to " + evt.getLastIndex());
161
162 if (evt == null || (evt != null && evt.getFirstIndex() == -1)){
163 // If the value is changing because the filter has been changed (e.g.
164 // table structure change) the evt.getFirstIndex() is -1, but evt.getLastIndex is > -1
165 layerSelModel.clearSelection();
166 } else{
167
168 for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) {
169 int featureIndex = featureTable.convertRowIndexToModel(i);
170 Feature changedFeature = featureTableModel.getFeature(featureIndex);
171 if (featureTable.isRowSelected(i))
172 layerSelModel.addSelection(changedFeature.getID());
173 else
174 layerSelModel.removeSelection(changedFeature.getID());
175 }
176 }
177 layerSelModel.setValueIsAdjusting(false);
178
179 // Danger of event circles in propertyChange(..) banned
180 selectionChangeCausedByMe = false;
181 }
182 }

Properties

Name Value
svn:eol-style native
svn:keywords Id
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26