105 |
*/ |
*/ |
106 |
@Override |
@Override |
107 |
public void propertyChange(PropertyChangeEvent evt) { |
public void propertyChange(PropertyChangeEvent evt) { |
108 |
|
|
109 |
|
if (!isEnabled()) |
110 |
|
return; |
111 |
|
|
112 |
if (!(evt instanceof StyledLayerSelectionEvent)) |
if (!(evt instanceof StyledLayerSelectionEvent)) |
113 |
return; |
return; |
114 |
StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt; |
StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt; |
131 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
132 |
} |
} |
133 |
|
|
134 |
|
/** |
135 |
|
* Changes the Style of the {@link MapLayer} to reflect changes of the |
136 |
|
* selection. |
137 |
|
* |
138 |
|
* @param newSelection |
139 |
|
* A {@link Vector} of Feature-IDs that are selected. |
140 |
|
*/ |
141 |
private void changeLayerStyle(final Vector<String> newSelection) { |
private void changeLayerStyle(final Vector<String> newSelection) { |
142 |
Style selectionMapStyle = null; |
Style selectionMapStyle = null; |
143 |
try { |
try { |
144 |
if (newSelection.isEmpty()) { |
if (newSelection.isEmpty()) { |
145 |
|
|
146 |
selectionMapStyle = styledMapLayer.getStyle(); |
selectionMapStyle = styledMapLayer.getStyle(); |
147 |
// LOGGER.debug("NO SELECTION .. set to original style directly"); |
// LOGGER.debug("NO SELECTION .. set to original style directly"); |
148 |
|
|
149 |
} else { |
} else { |
150 |
LOGGER.debug("SELECTION .. change style"); |
LOGGER.debug("SELECTION .. change style"); |
161 |
// .createSelectionStyle(normalStyle, geoObj); |
// .createSelectionStyle(normalStyle, geoObj); |
162 |
selectionMapStyle = StylingUtil |
selectionMapStyle = StylingUtil |
163 |
.createSelectionStyle(styledMapLayer.getGeoObject()); |
.createSelectionStyle(styledMapLayer.getGeoObject()); |
164 |
// selectionMapStyle = StylingUtil |
// selectionMapStyle = StylingUtil |
165 |
// .createDefaultStyle(styledMapLayer.getGeoObject()); |
// .createDefaultStyle(styledMapLayer.getGeoObject()); |
166 |
|
|
167 |
selectionMapStyle.getFeatureTypeStyles()[0] |
selectionMapStyle.getFeatureTypeStyles()[0] |
168 |
.setName(SELECTION_STYLING); |
.setName(SELECTION_STYLING); |
207 |
} else { |
} else { |
208 |
newFeatureTypes = originalFeatureTypeStyles; |
newFeatureTypes = originalFeatureTypeStyles; |
209 |
} |
} |
210 |
|
|
211 |
// The last FTS is the selection FTS |
// The last FTS is the selection FTS |
212 |
newFeatureTypes = LangUtil.extendArray(newFeatureTypes, |
newFeatureTypes = LangUtil.extendArray(newFeatureTypes, |
213 |
selectionMapStyle.getFeatureTypeStyles()); |
selectionMapStyle.getFeatureTypeStyles()); |
223 |
} |
} |
224 |
} |
} |
225 |
|
|
226 |
|
/** |
227 |
|
* Used to synchronize {@link FeatureSelectedEvent}s with the |
228 |
|
* {@link StyledFeatureLayerSelectionModel} |
229 |
|
*/ |
230 |
@Override |
@Override |
231 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(JMapPaneEvent e) { |
232 |
|
|
233 |
|
// Ignore event if it is caused by us or the synchronizer is disabled. |
234 |
|
if (!isEnabled() || selectionChangeCausedByMe) |
235 |
|
return; |
236 |
|
|
237 |
|
if (!(e instanceof FeatureSelectedEvent)) { |
238 |
|
// LOGGER.debug("Ignoring event " + e); |
239 |
|
return; |
240 |
|
} |
241 |
|
|
242 |
/** |
/** |
243 |
* Only listen to FeatureSelectionEvents if the appropriate tool is |
* Only listen to FeatureSelectedEvents if an appropriate tool is |
244 |
* selected. |
* selected. |
245 |
*/ |
*/ |
246 |
final int selectedTool = toolBar.getSelectedTool(); |
final int selectedTool = toolBar.getSelectedTool(); |
247 |
if (selectedTool != MapPaneToolBar.TOOL_SELECTION_ADD |
if (selectedTool != MapPaneToolBar.TOOL_SELECTION_ADD |
248 |
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_REMOVE |
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_REMOVE |
|
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_CLEAR |
|
249 |
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_SET) { |
&& selectedTool != MapPaneToolBar.TOOL_SELECTION_SET) { |
250 |
return; |
return; |
251 |
} |
} |
252 |
|
|
|
if (!(e instanceof FeatureSelectedEvent)) { |
|
|
// LOGGER.debug("Ignoring event " + e); |
|
|
return; |
|
|
} |
|
253 |
// only listen to events directly coming from JMapPane |
// only listen to events directly coming from JMapPane |
254 |
// selection (ignore selections from FilterDialog) |
// selection (ignore selections from FilterDialog) |
255 |
if (e.getSourceObject() != this.mapPane) |
if (e.getSourceObject() != this.mapPane) |
257 |
|
|
258 |
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
259 |
|
|
260 |
// ignore event if it is caused by the DpLayerVectorSelectionModel |
/** |
261 |
if (selectionChangeCausedByMe) |
* Checking, that the FeatureSelectedEvent actually contains features from this layer |
262 |
|
*/ |
263 |
|
final String sourceID = fse.getSourceLayer().getTitle(); |
264 |
|
final String syncForID = mapLayer.getTitle(); |
265 |
|
if (sourceID != null && syncForID != null |
266 |
|
&& !sourceID.equals(syncForID)){ |
267 |
|
LOGGER.debug("Ignoring a FeatureSelectedEvent from "+sourceID); |
268 |
return; |
return; |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
LOGGER.debug("Do event " + fse); |
LOGGER.debug("do event " + fse); |
273 |
|
|
274 |
// Avoid event circles in propertyChange(..) |
// Avoid event circles in propertyChange(..) |
275 |
selectionChangeCausedByMe = true; |
selectionChangeCausedByMe = true; |
276 |
|
|
277 |
if (selectedTool == MapPaneToolBar.TOOL_SELECTION_CLEAR) { |
Collection<Feature> selectionResult = (Collection<Feature>) fse |
278 |
|
.getSelectionResult(); |
279 |
|
|
280 |
|
// reset the selection of the DpLayerSelectionModel |
281 |
|
// layerSelModel.setValueIsAdjusting(true); |
282 |
|
|
283 |
|
if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) { |
284 |
|
layerSelModel.setValueIsAdjusting(true); |
285 |
|
for (Feature f : selectionResult) { |
286 |
|
layerSelModel.addSelection(f.getID()); |
287 |
|
} |
288 |
|
layerSelModel.setValueIsAdjusting(false); |
289 |
|
} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) { |
290 |
|
layerSelModel.setValueIsAdjusting(true); |
291 |
layerSelModel.clearSelection(); |
layerSelModel.clearSelection(); |
|
} else { |
|
|
Collection<Feature> selectionResult = (Collection<Feature>) fse |
|
|
.getSelectionResult(); |
|
|
|
|
|
// reset the selection of the DpLayerSelectionModel |
|
|
// layerSelModel.setValueIsAdjusting(true); |
|
|
|
|
|
if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) { |
|
|
layerSelModel.setValueIsAdjusting(true); |
|
|
for (Feature f : selectionResult) { |
|
|
layerSelModel.addSelection(f.getID()); |
|
|
} |
|
|
layerSelModel.setValueIsAdjusting(false); |
|
|
} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) { |
|
|
layerSelModel.setValueIsAdjusting(true); |
|
|
layerSelModel.clearSelection(); |
|
292 |
|
|
293 |
for (Feature f : selectionResult) { |
for (Feature f : selectionResult) { |
294 |
layerSelModel.addSelection(f.getID()); |
layerSelModel.addSelection(f.getID()); |
295 |
} |
} |
296 |
|
|
297 |
LOGGER.debug("Setting selection to " + selectionResult.size()); |
LOGGER.debug("Setting selection to " + selectionResult.size()); |
298 |
layerSelModel.setValueIsAdjusting(false); |
layerSelModel.setValueIsAdjusting(false); |
299 |
} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) { |
} else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) { |
300 |
layerSelModel.setValueIsAdjusting(true); |
layerSelModel.setValueIsAdjusting(true); |
301 |
for (Feature f : selectionResult) { |
for (Feature f : selectionResult) { |
302 |
layerSelModel.removeSelection(f.getID()); |
layerSelModel.removeSelection(f.getID()); |
|
} |
|
|
layerSelModel.setValueIsAdjusting(false); |
|
303 |
} |
} |
304 |
} // els it's not a Clear Selection command |
layerSelModel.setValueIsAdjusting(false); |
305 |
|
} |
306 |
|
|
307 |
// Show selected features in the map, which is not automatically done by |
// Show selected features in the map, which is not automatically done by |
308 |
// the origin: FeatureSelectedEvent |
// the origin: FeatureSelectedEvent |
311 |
// Danger of event circles in propertyChange(..) banned |
// Danger of event circles in propertyChange(..) banned |
312 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
313 |
} |
} |
314 |
|
|
315 |
} |
} |