22 |
import javax.swing.ListSelectionModel; |
import javax.swing.ListSelectionModel; |
23 |
import javax.swing.event.ListSelectionEvent; |
import javax.swing.event.ListSelectionEvent; |
24 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
25 |
|
import javax.swing.text.Utilities; |
26 |
|
|
27 |
import org.geotools.feature.Feature; |
import org.geotools.feature.Feature; |
28 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
29 |
|
import org.geotools.styling.PolygonSymbolizer; |
30 |
|
import org.geotools.styling.Rule; |
31 |
|
import org.geotools.styling.RuleImpl; |
32 |
import org.geotools.styling.Style; |
import org.geotools.styling.Style; |
33 |
|
import org.geotools.styling.StyleImpl; |
34 |
|
import org.geotools.styling.Symbolizer; |
35 |
|
import org.opengis.filter.Filter; |
36 |
|
import org.opengis.filter.FilterVisitor; |
37 |
|
import org.opengis.layer.StyleURL; |
38 |
|
|
39 |
|
import schmitzm.geotools.FilterUtil; |
40 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
41 |
import schmitzm.geotools.gui.JMapPane; |
import schmitzm.geotools.gui.JMapPane; |
42 |
import schmitzm.geotools.map.event.FeatureSelectedEvent; |
import schmitzm.geotools.map.event.FeatureSelectedEvent; |
43 |
import schmitzm.geotools.map.event.JMapPaneEvent; |
import schmitzm.geotools.map.event.JMapPaneEvent; |
44 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
45 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
46 |
|
import schmitzm.lang.LangUtil; |
47 |
import skrueger.geotools.StyledFeatureCollectionInterface; |
import skrueger.geotools.StyledFeatureCollectionInterface; |
48 |
import skrueger.geotools.StyledMapInterface; |
import skrueger.geotools.StyledMapInterface; |
49 |
import skrueger.geotools.selection.StyledFeatureLayerSelectionModel; |
import skrueger.geotools.selection.StyledFeatureLayerSelectionModel; |
69 |
* (University of Bonn/Germany) |
* (University of Bonn/Germany) |
70 |
*/ |
*/ |
71 |
public class FeatureMapLayerSelectionSynchronizer extends |
public class FeatureMapLayerSelectionSynchronizer extends |
72 |
StyledLayerSelectionModelSynchronizer<Feature> implements |
StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> |
73 |
JMapPaneListener { |
implements JMapPaneListener { |
74 |
/** |
/** |
75 |
* Holds the {@link MapLayer} to keep synchronized with the layer selection |
* Holds the {@link MapLayer} to keep synchronized with the layer selection |
76 |
* model. |
* model. |
135 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
136 |
} |
} |
137 |
|
|
138 |
private void changeLayerStyle(Vector<Feature> newSelection) { |
private void changeLayerStyle(final Vector<Feature> newSelection) { |
139 |
Style selectionMapStyle = null; |
Style selectionMapStyle = null; |
140 |
try { |
try { |
141 |
if (newSelection.isEmpty()) { |
if (newSelection.isEmpty()) { |
142 |
|
|
|
LOGGER.debug("NO SELECTION"); |
|
143 |
selectionMapStyle = styledMapLayer.getStyle(); |
selectionMapStyle = styledMapLayer.getStyle(); |
144 |
|
LOGGER.debug("NO SELECTION .. reset original style"); |
145 |
|
|
146 |
} else { |
} else { |
147 |
LOGGER.debug("SELECTION EXISTEnT"); |
LOGGER.debug("SELECTION .. change style"); |
148 |
|
|
149 |
|
Style originalStyle = styledMapLayer.getStyle(); |
150 |
|
|
151 |
|
// TODO This clone is a deep clone and it is slow.. |
152 |
selectionMapStyle = StylingUtil |
selectionMapStyle = StylingUtil |
153 |
.createDefaultStyle(styledMapLayer.getGeoObject()); |
.createDefaultStyle(styledMapLayer.getGeoObject()); |
154 |
|
|
155 |
|
// Symbolizer sss = selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0]; |
156 |
|
// if (sss instanceof PolygonSymbolizer) { |
157 |
|
// PolygonSymbolizer ps = (PolygonSymbolizer) sss; |
158 |
|
// ps.getFill().setOpacity( FilterUtil.FILTER_FAC.literal(0.5)); |
159 |
|
// } |
160 |
|
|
161 |
|
// Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule(); |
162 |
|
selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0] |
163 |
|
.setFilter(new Filter() { |
164 |
|
|
165 |
|
@Override |
166 |
|
public Object accept(FilterVisitor visitor, |
167 |
|
Object extraData) { |
168 |
|
return null; |
169 |
|
} |
170 |
|
|
171 |
|
@Override |
172 |
|
public boolean evaluate(Object obj) { |
173 |
|
if (obj instanceof Feature) { |
174 |
|
Feature f = (Feature) obj; |
175 |
|
// TODO BAD CODE |
176 |
|
for (Feature ff : newSelection) { |
177 |
|
if (ff.getID().equals(f.getID())) |
178 |
|
return true; |
179 |
|
} |
180 |
|
return false; |
181 |
|
|
182 |
|
} |
183 |
|
return false; |
184 |
|
} |
185 |
|
|
186 |
|
}); |
187 |
|
|
188 |
|
selectionMapStyle.setFeatureTypeStyles(LangUtil.extendArray( |
189 |
|
originalStyle |
190 |
|
.getFeatureTypeStyles(), selectionMapStyle.getFeatureTypeStyles())); |
191 |
|
|
192 |
|
// selectionMapStyle.setFeatureTypeStyles(originalStyle.getF) |
193 |
|
|
194 |
|
// Flat copy the style |
195 |
|
|
196 |
|
// selectionMapStyle = |
197 |
|
// StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject()); |
198 |
|
|
199 |
} |
} |
200 |
|
|
201 |
mapLayer.setStyle(selectionMapStyle); |
mapLayer.setStyle(selectionMapStyle); |
221 |
|
|
222 |
@Override |
@Override |
223 |
public void performMapPaneEvent(JMapPaneEvent e) { |
public void performMapPaneEvent(JMapPaneEvent e) { |
224 |
if (!(e instanceof FeatureSelectedEvent)) |
|
225 |
|
if (!(e instanceof FeatureSelectedEvent)) { |
226 |
|
// LOGGER.debug("Ignoring event " + e); |
227 |
return; |
return; |
228 |
|
} |
229 |
|
|
230 |
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
FeatureSelectedEvent fse = (FeatureSelectedEvent) e; |
231 |
|
// LOGGER.debug("Do event " + fse); |
232 |
|
// LOGGER.debug("Do event " + fse.getSelectionResult()); |
233 |
|
|
234 |
// ignore event if it is caused by the DpLayerVectorSelectionModel |
// ignore event if it is caused by the DpLayerVectorSelectionModel |
235 |
if (selectionChangeCausedByMe) |
if (selectionChangeCausedByMe) |
257 |
// Show selected feature in the map, which is not automatically done by |
// Show selected feature in the map, which is not automatically done by |
258 |
// the FeatureSelectedEvent |
// the FeatureSelectedEvent |
259 |
changeLayerStyle(layerSelModel.getSelection()); |
changeLayerStyle(layerSelModel.getSelection()); |
260 |
|
|
261 |
// Danger of event circles in propertyChange(..) banned |
// Danger of event circles in propertyChange(..) banned |
262 |
selectionChangeCausedByMe = false; |
selectionChangeCausedByMe = false; |
263 |
} |
} |