1 |
|
/******************************************************************************* |
2 |
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
|
* |
4 |
|
* This file is part of the SCHMITZM library - a collection of utility |
5 |
|
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
|
* and the Geotools library. |
7 |
|
* |
8 |
|
* The SCHMITZM project is hosted at: |
9 |
|
* http://wald.intevation.org/projects/schmitzm/ |
10 |
|
* |
11 |
|
* This program is free software; you can redistribute it and/or |
12 |
|
* modify it under the terms of the GNU Lesser General Public License |
13 |
|
* as published by the Free Software Foundation; either version 3 |
14 |
|
* of the License, or (at your option) any later version. |
15 |
|
* |
16 |
|
* This program is distributed in the hope that it will be useful, |
17 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
|
* GNU General Public License for more details. |
20 |
|
* |
21 |
|
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
|
* along with this program; if not, write to the Free Software |
23 |
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
|
* |
26 |
|
* Contributors: |
27 |
|
* Martin O. J. Schmitz - initial API and implementation |
28 |
|
* Stefan A. Krüger - additional utility classes |
29 |
|
******************************************************************************/ |
30 |
/** |
/** |
31 |
Copyright 2008 Stefan Alfons Krüger |
Copyright 2008 Stefan Alfons Krüger |
32 |
|
|
33 |
atlas-framework - This file is part of the Atlas Framework |
atlas-framework - This file is part of the Atlas Framework |
34 |
|
|
35 |
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. |
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. |
42 |
**/ |
**/ |
43 |
package skrueger.geotools.selection; |
package skrueger.geotools.selection; |
44 |
|
|
45 |
|
import java.awt.RenderingHints; |
46 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
47 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
48 |
import java.util.Collection; |
import java.io.File; |
49 |
|
import java.util.HashMap; |
50 |
|
import java.util.HashSet; |
51 |
|
import java.util.Iterator; |
52 |
|
import java.util.Set; |
53 |
import java.util.Vector; |
import java.util.Vector; |
54 |
|
|
55 |
import javax.swing.JTable; |
import javax.swing.JTable; |
56 |
import javax.swing.ListSelectionModel; |
import javax.swing.ListSelectionModel; |
|
import javax.swing.event.ListSelectionEvent; |
|
57 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
|
import javax.swing.text.Utilities; |
|
58 |
|
|
59 |
import org.geotools.feature.Feature; |
import org.geotools.feature.FeatureCollection; |
60 |
|
import org.geotools.feature.FeatureIterator; |
61 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
62 |
import org.geotools.styling.PolygonSymbolizer; |
import org.geotools.renderer.GTRenderer; |
63 |
import org.geotools.styling.Rule; |
import org.geotools.renderer.label.LabelCacheImpl; |
64 |
import org.geotools.styling.RuleImpl; |
import org.geotools.renderer.lite.StreamingRenderer; |
65 |
|
import org.geotools.styling.FeatureTypeStyle; |
66 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
67 |
import org.geotools.styling.StyleImpl; |
import org.geotools.styling.visitor.DuplicatingStyleVisitor; |
68 |
import org.geotools.styling.Symbolizer; |
import org.opengis.feature.simple.SimpleFeature; |
69 |
import org.opengis.filter.Filter; |
import org.opengis.feature.simple.SimpleFeatureType; |
70 |
import org.opengis.filter.FilterVisitor; |
import org.opengis.filter.identity.FeatureId; |
|
import org.opengis.layer.StyleURL; |
|
71 |
|
|
72 |
import schmitzm.geotools.FilterUtil; |
import schmitzm.geotools.FilterUtil; |
73 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.GTUtil; |
74 |
import schmitzm.geotools.gui.JMapPane; |
import schmitzm.geotools.gui.JMapPane; |
75 |
import schmitzm.geotools.map.event.FeatureSelectedEvent; |
import schmitzm.geotools.map.event.FeatureSelectedEvent; |
76 |
import schmitzm.geotools.map.event.JMapPaneEvent; |
import schmitzm.geotools.map.event.JMapPaneEvent; |
77 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
78 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
79 |
import schmitzm.lang.LangUtil; |
import skrueger.geotools.MapPaneToolBar; |
80 |
import skrueger.geotools.StyledFeatureCollectionInterface; |
import skrueger.geotools.StyledFeaturesInterface; |
81 |
import skrueger.geotools.StyledMapInterface; |
import skrueger.geotools.StyledLayerInterface; |
|
import skrueger.geotools.selection.StyledFeatureLayerSelectionModel; |
|
|
import skrueger.geotools.selection.StyledLayerSelectionEvent; |
|
|
import skrueger.geotools.selection.StyledLayerSelectionModel; |
|
82 |
|
|
83 |
/** |
/** |
84 |
* This class keeps the selection of a (feature) {@link JTable} synchronized |
* This class keeps the selection of a (feature) {@link JTable} synchronized |
101 |
public class FeatureMapLayerSelectionSynchronizer extends |
public class FeatureMapLayerSelectionSynchronizer extends |
102 |
StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
103 |
implements JMapPaneListener { |
implements JMapPaneListener { |
104 |
|
public static final String SELECTION_STYLING = "SELECTION"; |
105 |
/** |
/** |
106 |
* Holds the {@link MapLayer} to keep synchronized with the layer selection |
* Holds the {@link MapLayer} to keep synchronized with the layer selection |
107 |
* model. |
* model. |
108 |
*/ |
*/ |
109 |
protected final MapLayer mapLayer; |
protected final MapLayer mapLayer; |
110 |
protected final StyledMapInterface<?> styledMapLayer; |
protected final StyledFeaturesInterface<?> styledLayer; |
111 |
protected final JMapPane mapPane; |
protected final JMapPane mapPane; |
112 |
|
private final MapPaneToolBar toolBar; |
113 |
|
private final HashMap<Object, Object> defaultGTRenderingHints; |
114 |
|
|
115 |
/** |
/** |
116 |
* Creates a new synchronizer |
* Creates a new synchronizer |
124 |
*/ |
*/ |
125 |
public FeatureMapLayerSelectionSynchronizer( |
public FeatureMapLayerSelectionSynchronizer( |
126 |
StyledFeatureLayerSelectionModel layerSelModel, |
StyledFeatureLayerSelectionModel layerSelModel, |
127 |
StyledMapInterface<?> styledMapLayer, MapLayer mapLayer, |
StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer, |
128 |
JMapPane mapPane) { |
JMapPane mapPane, MapPaneToolBar toolBar, |
129 |
|
HashMap<Object, Object> defaultGTRenderingHints) { |
130 |
|
|
131 |
super(layerSelModel); |
super(layerSelModel); |
132 |
this.styledMapLayer = styledMapLayer; |
this.styledLayer = styledLayer; |
133 |
|
|
134 |
this.mapLayer = mapLayer; |
this.mapLayer = mapLayer; |
135 |
this.mapPane = mapPane; |
this.mapPane = mapPane; |
136 |
|
this.toolBar = toolBar; |
137 |
|
if (defaultGTRenderingHints != null) |
138 |
|
this.defaultGTRenderingHints = defaultGTRenderingHints; |
139 |
|
else |
140 |
|
this.defaultGTRenderingHints = new HashMap<Object, Object>(); |
141 |
} |
} |
142 |
|
|
143 |
/** |
/** |
152 |
*/ |
*/ |
153 |
@Override |
@Override |
154 |
public void propertyChange(PropertyChangeEvent evt) { |
public void propertyChange(PropertyChangeEvent evt) { |
155 |
|
|
156 |
|
if (!isEnabled()) |
157 |
|
return; |
158 |
|
|
159 |
if (!(evt instanceof StyledLayerSelectionEvent)) |
if (!(evt instanceof StyledLayerSelectionEvent)) |
160 |
return; |
return; |
161 |
StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt; |
StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt; |
165 |
return; |
return; |
166 |
// Apply new selection on table (except this event is one of |
// Apply new selection on table (except this event is one of |
167 |
// some more events) |
// some more events) |
168 |
Vector<Feature> newSelection = layerSelModel.getSelection(); |
Vector<String> newSelection = layerSelModel.getSelection(); |
169 |
if (newSelection == null) |
if (newSelection == null) |
170 |
return; |
return; |
171 |
|
|
178 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
179 |
} |
} |
180 |
|
|
181 |
private void changeLayerStyle(final Vector<Feature> newSelection) { |
/** |
182 |
Style selectionMapStyle = null; |
* Changes the Style of the {@link MapLayer} to reflect changes of the |
183 |
|
* selection. |
184 |
|
* |
185 |
|
* @param newSelection |
186 |
|
* A {@link Vector} of SimpleFeature-IDs that are selected. |
187 |
|
*/ |
188 |
|
private void changeLayerStyle(final Vector<String> newSelection) { |
189 |
try { |
try { |
190 |
|
|
191 |
|
Style originalStyle = mapLayer.getStyle(); |
192 |
if (newSelection.isEmpty()) { |
if (newSelection.isEmpty()) { |
193 |
|
|
194 |
selectionMapStyle = styledMapLayer.getStyle(); |
// Check if the Style contains a SELECTION FTS |
195 |
LOGGER.debug("NO SELECTION .. reset original style"); |
|
196 |
|
FeatureTypeStyle[] clone = originalStyle.featureTypeStyles() |
197 |
|
.toArray(new FeatureTypeStyle[] {}).clone(); |
198 |
|
|
199 |
|
for (FeatureTypeStyle fts : clone) { |
200 |
|
if (fts.getName() != null |
201 |
|
&& fts.getName().equals(SELECTION_STYLING)) { |
202 |
|
originalStyle.featureTypeStyles().remove(fts); |
203 |
|
|
204 |
|
replaceRenderer(); |
205 |
|
// mapPane.refresh(); |
206 |
|
|
207 |
|
return; |
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
} else { |
} else { |
212 |
LOGGER.debug("SELECTION .. change style"); |
LOGGER.debug("SELECTION .. change style"); |
213 |
|
|
214 |
Style originalStyle = styledMapLayer.getStyle(); |
// We take Style from the MapLayer that is displayed at the |
215 |
|
// moment. We do not use the styledLayer.getStyle, because in |
216 |
// TODO This clone is a deep clone and it is slow.. |
// the atlas, this always return the default style, but |
217 |
selectionMapStyle = StylingUtil |
// additional styles might be selected. |
218 |
.createDefaultStyle(styledMapLayer.getGeoObject()); |
// Taking the style from the mapLayer indicated, that we have to |
219 |
|
// remove any selection rules first. |
220 |
// Symbolizer sss = selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0]; |
|
221 |
// if (sss instanceof PolygonSymbolizer) { |
FeatureTypeStyle selectionFTStyle = StylingUtil |
222 |
// PolygonSymbolizer ps = (PolygonSymbolizer) sss; |
.createSelectionStyle(styledLayer.getGeoObject()); |
223 |
// ps.getFill().setOpacity( FilterUtil.FILTER_FAC.literal(0.5)); |
|
224 |
|
selectionFTStyle.setName(SELECTION_STYLING); |
225 |
|
|
226 |
|
/** |
227 |
|
* |
228 |
|
* Add a Filter to the selectionMapStyle, so that it is only |
229 |
|
* used on objects that are selected. <br/> |
230 |
|
* To optimize rendering speed, the filter checks whether more |
231 |
|
* than half of the features are selected. If so, the filter is |
232 |
|
* inverted to be shorter. |
233 |
|
* |
234 |
|
*/ |
235 |
|
|
236 |
|
final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollectionFiltered = styledLayer |
237 |
|
.getFeatureCollectionFiltered(); |
238 |
|
if (newSelection.size() > featureCollectionFiltered.size() / 2) { |
239 |
|
FeatureIterator<SimpleFeature> iterator = featureCollectionFiltered |
240 |
|
.features(); |
241 |
|
Set<FeatureId> antiFids = new HashSet<FeatureId>(); |
242 |
|
try { |
243 |
|
while (iterator.hasNext()) { |
244 |
|
SimpleFeature next = iterator.next(); |
245 |
|
if (!newSelection.contains(next.getID())) |
246 |
|
antiFids.add(FilterUtil.FILTER_FAC2 |
247 |
|
.featureId(next.getID())); |
248 |
|
} |
249 |
|
|
250 |
|
selectionFTStyle.rules().get(0).setFilter( |
251 |
|
FilterUtil.FILTER_FAC2 |
252 |
|
.not(FilterUtil.FILTER_FAC2 |
253 |
|
.id(antiFids))); |
254 |
|
|
255 |
|
} finally { |
256 |
|
featureCollectionFiltered.close(iterator); |
257 |
|
} |
258 |
|
} else { |
259 |
|
Set<FeatureId> fids = new HashSet<FeatureId>(); |
260 |
|
for (String fid : newSelection) { |
261 |
|
fids.add(FilterUtil.FILTER_FAC2.featureId(fid)); |
262 |
|
} |
263 |
|
|
264 |
|
selectionFTStyle.rules().get(0).setFilter( |
265 |
|
FilterUtil.FILTER_FAC2.id(fids)); |
266 |
|
} |
267 |
|
|
268 |
|
// Maybe there has already been another selection |
269 |
|
// FeatureTypeStyle... Let's replace it... |
270 |
|
boolean foundAndReplaced = false; |
271 |
|
for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) { |
272 |
|
if (fts.getName() != null |
273 |
|
&& fts.getName().equals(SELECTION_STYLING)) { |
274 |
|
foundAndReplaced = true; |
275 |
|
fts.rules().clear(); |
276 |
|
fts.rules().addAll(selectionFTStyle.rules()); |
277 |
|
break; |
278 |
|
} |
279 |
|
} |
280 |
|
if (!foundAndReplaced) { |
281 |
|
originalStyle.featureTypeStyles().add(selectionFTStyle); |
282 |
|
} |
283 |
|
|
284 |
|
// Refresh the map |
285 |
|
// mapPane.refresh(); |
286 |
|
|
287 |
|
DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor(); |
288 |
|
dsv.visit(originalStyle); |
289 |
|
Style newStyle = (Style) dsv.getCopy(); |
290 |
|
|
291 |
|
//SK-Debug |
292 |
|
// try { |
293 |
|
//// |
294 |
|
//// StylingUtil.saveStyleToSLD(newStyle, new File( |
295 |
|
//// "/home/stefan/Desktop/selection.sld")); |
296 |
|
// } catch (Exception e) { |
297 |
// } |
// } |
298 |
|
|
299 |
// Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule(); |
// DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor(); |
300 |
selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0] |
// dsv.visit(originalStyle); |
301 |
.setFilter(new Filter() { |
// Style newStyle = originalStyle; |
302 |
|
|
303 |
@Override |
// Style newStyle = StylingUtil.STYLE_BUILDER.createStyle(); |
304 |
public Object accept(FilterVisitor visitor, |
// newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles()); |
305 |
Object extraData) { |
mapLayer.setStyle(newStyle); |
|
return null; |
|
|
} |
|
|
|
|
|
@Override |
|
|
public boolean evaluate(Object obj) { |
|
|
if (obj instanceof Feature) { |
|
|
Feature f = (Feature) obj; |
|
|
// TODO BAD CODE |
|
|
for (Feature ff : newSelection) { |
|
|
if (ff.getID().equals(f.getID())) |
|
|
return true; |
|
|
} |
|
|
return false; |
|
|
|
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
selectionMapStyle.setFeatureTypeStyles(LangUtil.extendArray( |
|
|
originalStyle |
|
|
.getFeatureTypeStyles(), selectionMapStyle.getFeatureTypeStyles())); |
|
|
|
|
|
// selectionMapStyle.setFeatureTypeStyles(originalStyle.getF) |
|
|
|
|
|
// Flat copy the style |
|
|
|
|
|
// selectionMapStyle = |
|
|
// StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject()); |
|
306 |
|
|
307 |
|
replaceRenderer(); |
308 |
} |
} |
309 |
|
|
|
mapLayer.setStyle(selectionMapStyle); |
|
|
mapPane.refresh(); |
|
310 |
} catch (Exception e) { |
} catch (Exception e) { |
311 |
LOGGER.error("Error while trying to create a selection style", e); |
LOGGER.error("Error while trying to create a selection style", e); |
312 |
} |
} |
313 |
} |
} |
314 |
|
|
315 |
// |
private void replaceRenderer() { |
316 |
// /** |
// |
317 |
// * Called when the table selection is changed by the user. When calling |
// // Has to be done before we apply the new Renderer |
318 |
// this |
// mapLayer.setStyle(style); |
319 |
// * method changes the selection of the {@link StyledLayerSelectionModel}. |
|
320 |
// * |
GTRenderer oldRenderer = mapPane.getRenderer(); |
321 |
// * @param evt |
|
322 |
// * an event |
/** |
323 |
// */ |
* Explicitly putting a new instance of LabelCacheDefault into the |
324 |
// @Override |
* renderer instance, so JMapPane doesn't reuse the old one. This is |
325 |
// public void valueChanged(ListSelectionEvent evt) { |
* very useful when changing the TextSymbolizer with AtlasStyler<br/> |
326 |
// |
* SK 9.7.09: It's not enought to user LabelCache.clear(). We can not |
327 |
// } |
* reuse the old Renderer - better to create a new one! |
328 |
|
*/ |
329 |
|
final GTRenderer newRenderer = GTUtil.createGTRenderer(); |
330 |
|
|
331 |
|
final HashMap<Object, Object> rendererHints = defaultGTRenderingHints; |
332 |
|
rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, |
333 |
|
new LabelCacheImpl()); |
334 |
|
|
335 |
|
newRenderer.setRendererHints(rendererHints); |
336 |
|
mapPane.setRenderer(newRenderer); |
337 |
|
|
338 |
|
if (oldRenderer != null) { |
339 |
|
|
340 |
|
RenderingHints java2DHints = oldRenderer.getJava2DHints(); |
341 |
|
if (java2DHints != null) { |
342 |
|
newRenderer.setJava2DHints(java2DHints); |
343 |
|
} |
344 |
|
|
345 |
|
oldRenderer.setContext(null); |
346 |
|
oldRenderer = null; |
347 |
|
} |
348 |
|
|
349 |
|
mapPane.refresh(); |
350 |
|
|
351 |
|
} |
352 |
|
|
353 |
|
/** |
354 |
|
* Used to synchronize {@link FeatureSelectedEvent}s with the |
355 |
|
* {@link StyledFeatureLayerSelectionModel} |
356 |
|
*/ |
357 |
@Override |
@Override |
358 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(JMapPaneEvent e) { |
359 |
|
|
360 |
|
// Ignore event if it is caused by us or the synchronizer is disabled. |
361 |
|
if (!isEnabled() || selectionChangeCausedByMe) |
362 |
|
return; |
363 |
|
|
364 |
if (!(e instanceof FeatureSelectedEvent)) { |
if (!(e instanceof FeatureSelectedEvent)) { |
365 |
// LOGGER.debug("Ignoring event " + e); |
// LOGGER.debug("Ignoring event " + e); |
366 |
|
return; |
367 |
|
} |
368 |
|
|
369 |
|
/** |
370 |
|
* Only listen to FeatureSelectedEvents if an appropriate tool is |
371 |
|
* selected. |
372 |
|
*/ |
373 |
|
final int selectedTool = toolBar.getSelectedTool(); |
374 |
|
if (selectedTool != MapPaneToolBar.TOOL_SELECTION_ADD |
375 |
|
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_REMOVE |
376 |
|
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_SET) { |
377 |
return; |
return; |
378 |
} |
} |
379 |
|
|
380 |
// only listen to events directly coming from JMapPane |
// only listen to events directly coming from JMapPane |
381 |
// selection (ignore selections from FilterDialog) |
// selection (ignore selections from FilterDialog) |
382 |
if ( e.getSourceObject() != this.mapPane ) |
if (e.getSourceObject() != this.mapPane) |
383 |
return; |
return; |
384 |
|
|
|
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
|
|
// LOGGER.debug("Do event " + fse); |
|
|
// LOGGER.debug("Do event " + fse.getSelectionResult()); |
|
385 |
|
|
386 |
// ignore event if it is caused by the DpLayerVectorSelectionModel |
/** |
387 |
if (selectionChangeCausedByMe) |
* Checking, that the FeatureSelectedEvent actually contains features |
388 |
|
* from this layer |
389 |
|
*/ |
390 |
|
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
391 |
|
final String sourceID = fse.getSourceLayer().getTitle(); |
392 |
|
final String syncForID = mapLayer.getTitle(); |
393 |
|
if (sourceID != null && syncForID != null |
394 |
|
&& !sourceID.equals(syncForID)) { |
395 |
|
LOGGER.debug("Ignoring a FeatureSelectedEvent from " + sourceID); |
396 |
return; |
return; |
397 |
|
} |
398 |
|
|
399 |
|
// LOGGER.debug("do event " + fse); |
400 |
|
|
401 |
// Avoid event circles in propertyChange(..) |
// Avoid event circles in propertyChange(..) |
402 |
selectionChangeCausedByMe = true; |
selectionChangeCausedByMe = true; |
403 |
|
|
404 |
// reset the selection of the DpLayerSelectionModel |
final FeatureCollection<SimpleFeatureType, SimpleFeature> selectionResult = fse |
405 |
// layerSelModel.setValueIsAdjusting(true); |
.getSelectionResult(); |
406 |
|
Iterator<SimpleFeature> fi = selectionResult.iterator(); |
407 |
|
try { |
408 |
|
|
409 |
layerSelModel.addSelection((Collection<Feature>) fse |
// reset the selection of the DpLayerSelectionModel |
410 |
.getSelectionResult()); |
// layerSelModel.setValueIsAdjusting(true); |
411 |
|
|
412 |
// for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) { |
if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) { |
413 |
// Feature changedFeature = featureTableModel.getFeature(featureTable |
layerSelModel.setValueIsAdjusting(true); |
|
// .convertRowIndexToModel(i)); |
|
|
// if (featureTable.isRowSelected(i)) |
|
|
// layerSelModel.addSelection(changedFeature); |
|
|
// else |
|
|
// layerSelModel.removeSelection(changedFeature); |
|
|
// } |
|
|
// layerSelModel.setValueIsAdjusting(false); |
|
414 |
|
|
415 |
// Show selected feature in the map, which is not automatically done by |
for (int fIdx = 0; fi.hasNext(); fIdx++) { |
416 |
// the FeatureSelectedEvent |
SimpleFeature f = fi.next(); |
417 |
|
layerSelModel.addSelection(f.getID()); |
418 |
|
} |
419 |
|
layerSelModel.setValueIsAdjusting(false); |
420 |
|
} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) { |
421 |
|
layerSelModel.setValueIsAdjusting(true); |
422 |
|
layerSelModel.clearSelection(); |
423 |
|
|
424 |
|
for (int fIdx = 0; fi.hasNext(); fIdx++) { |
425 |
|
SimpleFeature f = fi.next(); |
426 |
|
layerSelModel.addSelection(f.getID()); |
427 |
|
} |
428 |
|
|
429 |
|
// LOGGER.debug("Setting selection to " + fi.()); |
430 |
|
|
431 |
|
layerSelModel.setValueIsAdjusting(false); |
432 |
|
} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) { |
433 |
|
layerSelModel.setValueIsAdjusting(true); |
434 |
|
for (int fIdx = 0; fi.hasNext(); fIdx++) { |
435 |
|
SimpleFeature f = fi.next(); |
436 |
|
layerSelModel.removeSelection(f.getID()); |
437 |
|
} |
438 |
|
layerSelModel.setValueIsAdjusting(false); |
439 |
|
} |
440 |
|
|
441 |
|
} finally { |
442 |
|
selectionResult.close(fi); |
443 |
|
} |
444 |
|
|
445 |
|
// Show selected features in the map, which is not automatically done by |
446 |
|
// the origin: FeatureSelectedEvent |
447 |
changeLayerStyle(layerSelModel.getSelection()); |
changeLayerStyle(layerSelModel.getSelection()); |
448 |
|
|
449 |
// Danger of event circles in propertyChange(..) banned |
// Danger of event circles in propertyChange(..) banned |
450 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
451 |
} |
} |
452 |
|
|
453 |
} |
} |