Revision 727 org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.app/org.gvsig.topology.app.mainplugin/src/main/java/org/gvsig/topology/app/mainplugin/AppTopologyServices.java
AppTopologyServices.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.topology.app.mainplugin; |
25 | 25 |
|
26 |
import java.io.File; |
|
26 | 27 |
import java.util.ArrayList; |
27 | 28 |
import java.util.HashMap; |
28 | 29 |
import java.util.List; |
29 | 30 |
import java.util.Map; |
31 |
import javax.swing.ImageIcon; |
|
30 | 32 |
import javax.swing.tree.TreeModel; |
31 | 33 |
import org.apache.commons.lang3.mutable.Mutable; |
32 | 34 |
import org.apache.commons.lang3.mutable.MutableObject; |
35 |
import org.gvsig.andami.IconThemeHelper; |
|
36 |
import org.gvsig.andami.PluginsLocator; |
|
33 | 37 |
import org.gvsig.app.ApplicationLocator; |
34 | 38 |
import org.gvsig.app.ApplicationManager; |
35 | 39 |
import org.gvsig.app.project.Project; |
36 | 40 |
import org.gvsig.app.project.documents.Document; |
37 | 41 |
import org.gvsig.app.project.documents.view.ViewDocument; |
38 | 42 |
import org.gvsig.app.project.documents.view.ViewManager; |
43 |
import org.gvsig.fmap.dal.EditingNotification; |
|
44 |
import org.gvsig.fmap.dal.EditingNotificationManager; |
|
39 | 45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
46 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
|
47 |
import org.gvsig.fmap.geom.Geometry; |
|
48 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
49 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
50 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
51 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
40 | 52 |
import org.gvsig.fmap.geom.primitive.Envelope; |
41 | 53 |
import org.gvsig.fmap.geom.primitive.Point; |
54 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
55 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
56 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
42 | 57 |
import org.gvsig.fmap.mapcontext.ViewPort; |
43 | 58 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
44 | 59 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
45 | 60 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
46 | 61 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
62 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
47 | 63 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
48 | 64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
65 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
|
66 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
67 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2; |
|
68 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
|
69 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
|
70 |
import org.gvsig.tools.dynobject.DynObject; |
|
49 | 71 |
import org.gvsig.tools.exception.BaseException; |
72 |
import org.gvsig.tools.observer.Observable; |
|
73 |
import org.gvsig.tools.observer.Observer; |
|
74 |
import org.gvsig.tools.swing.api.ListElement; |
|
50 | 75 |
import org.gvsig.tools.visitor.VisitCanceledException; |
51 | 76 |
import org.gvsig.tools.visitor.Visitor; |
52 | 77 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
... | ... | |
62 | 87 |
public class AppTopologyServices implements TopologySwingServices { |
63 | 88 |
|
64 | 89 |
private static final Logger LOGGER = LoggerFactory.getLogger(AppTopologyServices.class); |
65 |
|
|
90 |
|
|
66 | 91 |
private class WorkingAreaViewPortListener implements ViewPortListener { |
67 |
|
|
92 |
|
|
68 | 93 |
private WorkingAreaChangedListener workingAreaChangedListener; |
69 | 94 |
private ViewPort viewPort; |
70 |
|
|
95 |
|
|
71 | 96 |
public WorkingAreaViewPortListener(ViewPort viewPort, WorkingAreaChangedListener workingAreaChangedListener) { |
72 | 97 |
this.workingAreaChangedListener = workingAreaChangedListener; |
73 | 98 |
this.viewPort = viewPort; |
... | ... | |
76 | 101 |
public ViewPort getViewPort() { |
77 | 102 |
return this.viewPort; |
78 | 103 |
} |
79 |
|
|
104 |
|
|
80 | 105 |
@Override |
81 | 106 |
public void extentChanged(ExtentEvent e) { |
82 | 107 |
this.workingAreaChangedListener.workingAreaChanged(e.getNewExtent()); |
... | ... | |
91 | 116 |
} |
92 | 117 |
} |
93 | 118 |
|
119 |
private class EditingNotificationObserver implements Observer { |
|
120 |
|
|
121 |
public EditingNotificationObserver() { |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
public void update(Observable o, Object notification) { |
|
127 |
EditingNotification n = (EditingNotification) notification; |
|
128 |
if (n.isCancelable() && n.getFeature() != null) { |
|
129 |
try { |
|
130 |
DynObject data = n.getFeature().getAsDynObject(); |
|
131 |
DynObjectEditor editor = new DynObjectEditor(data); |
|
132 |
editor.setTitle("Topology - " + n.getFeature().getType().getName()); |
|
133 |
editor.editObject(true); |
|
134 |
if (editor.isCanceled()) { |
|
135 |
n.cancel(); |
|
136 |
} else { |
|
137 |
editor.getData(data); |
|
138 |
} |
|
139 |
} catch (Exception ex) { |
|
140 |
LOGGER.warn("Problems showing the feature in a form.", ex); |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
94 | 146 |
private Map<WorkingAreaChangedListener, WorkingAreaViewPortListener> workingAreaListener; |
95 |
|
|
147 |
private ISymbol errorPolygonSymbol = null; |
|
148 |
private ISymbol errorPointSymbol = null; |
|
149 |
private ISymbol errorLineSymbol = null; |
|
150 |
private EditingNotificationObserver editingNotificationObserver = null; |
|
151 |
|
|
96 | 152 |
public AppTopologyServices() { |
97 | 153 |
this.workingAreaListener = new HashMap<>(); |
98 | 154 |
} |
99 |
|
|
155 |
|
|
100 | 156 |
@Override |
101 | 157 |
public TreeModel getDataSetTreeModel() { |
102 | 158 |
ApplicationManager application = ApplicationLocator.getManager(); |
... | ... | |
108 | 164 |
public FeatureStore getFeatureStore(final TopologyDataSet dataSet) { |
109 | 165 |
final Mutable<FeatureStore> store = new MutableObject<>(); |
110 | 166 |
store.setValue(null); |
111 |
|
|
167 |
|
|
112 | 168 |
ApplicationManager application = ApplicationLocator.getManager(); |
113 | 169 |
Project project = application.getCurrentProject(); |
114 |
|
|
170 |
|
|
115 | 171 |
List<Document> views = new ArrayList<>(); |
116 | 172 |
views.add(project.getActiveDocument(ViewManager.TYPENAME)); |
117 | 173 |
// views.addAll(project.getDocuments(ViewManager.TYPENAME)); |
118 | 174 |
|
119 | 175 |
for (Document view : views) { |
120 |
if( view == null ) {
|
|
176 |
if (view == null) {
|
|
121 | 177 |
continue; |
122 | 178 |
} |
123 |
FLayers layers = ((ViewDocument)view).getMapContext().getLayers(); |
|
179 |
FLayers layers = ((ViewDocument) view).getMapContext().getLayers();
|
|
124 | 180 |
try { |
125 | 181 |
layers.accept(new Visitor() { |
126 | 182 |
@Override |
127 | 183 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
128 |
if( o instanceof FLyrVect ) {
|
|
184 |
if (o instanceof FLyrVect) {
|
|
129 | 185 |
FLyrVect layer = (FLyrVect) o; |
130 |
if( dataSet.isThisStore(layer.getFeatureStore()) ) {
|
|
186 |
if (dataSet.isThisStore(layer.getFeatureStore())) {
|
|
131 | 187 |
store.setValue(layer.getFeatureStore()); |
132 | 188 |
throw new VisitCanceledException(); |
133 | 189 |
} |
... | ... | |
147 | 203 |
public void zoomTo(Envelope envelope) { |
148 | 204 |
ApplicationManager application = ApplicationLocator.getManager(); |
149 | 205 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
150 |
if( viewdoc == null ) {
|
|
206 |
if (viewdoc == null) {
|
|
151 | 207 |
return; |
152 | 208 |
} |
153 | 209 |
ViewPort viewPort = viewdoc.getMapContext().getViewPort(); |
... | ... | |
159 | 215 |
try { |
160 | 216 |
ApplicationManager application = ApplicationLocator.getManager(); |
161 | 217 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
162 |
if( viewdoc == null ) {
|
|
218 |
if (viewdoc == null) {
|
|
163 | 219 |
return; |
164 | 220 |
} |
165 | 221 |
viewdoc.getMapContext().invalidate(); |
... | ... | |
167 | 223 |
LOGGER.warn("Cant refresh view", ex); |
168 | 224 |
} |
169 | 225 |
} |
170 |
|
|
226 |
|
|
171 | 227 |
@Override |
172 | 228 |
public void centerTo(Point point) { |
173 | 229 |
try { |
174 | 230 |
ApplicationManager application = ApplicationLocator.getManager(); |
175 | 231 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
176 |
if( viewdoc == null ) {
|
|
232 |
if (viewdoc == null) {
|
|
177 | 233 |
return; |
178 | 234 |
} |
179 | 235 |
ViewPort viewPort = viewdoc.getMapContext().getViewPort(); |
... | ... | |
189 | 245 |
public Envelope getWorkingArea() { |
190 | 246 |
ApplicationManager application = ApplicationLocator.getManager(); |
191 | 247 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
192 |
if( viewdoc == null ) {
|
|
248 |
if (viewdoc == null) {
|
|
193 | 249 |
return null; |
194 | 250 |
} |
195 | 251 |
ViewPort viewPort = viewdoc.getMapContext().getViewPort(); |
... | ... | |
200 | 256 |
public void addWorkingAreaChangedListener(WorkingAreaChangedListener listener) { |
201 | 257 |
ApplicationManager application = ApplicationLocator.getManager(); |
202 | 258 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
203 |
if( viewdoc == null ) {
|
|
259 |
if (viewdoc == null) {
|
|
204 | 260 |
return; |
205 | 261 |
} |
206 | 262 |
ViewPort viewPort = viewdoc.getMapContext().getViewPort(); |
207 | 263 |
WorkingAreaViewPortListener viewPortListener = this.workingAreaListener.get(listener); |
208 |
if( viewPortListener==null ) {
|
|
264 |
if (viewPortListener == null) {
|
|
209 | 265 |
viewPortListener = new WorkingAreaViewPortListener(viewPort, listener); |
210 | 266 |
this.workingAreaListener.put(listener, viewPortListener); |
211 | 267 |
} else { |
212 |
if( viewPort != viewPortListener.getViewPort() ) {
|
|
268 |
if (viewPort != viewPortListener.getViewPort()) {
|
|
213 | 269 |
viewPortListener.getViewPort().removeViewPortListener(viewPortListener); |
214 | 270 |
viewPortListener = new WorkingAreaViewPortListener(viewPort, listener); |
215 | 271 |
this.workingAreaListener.put(listener, viewPortListener); |
... | ... | |
221 | 277 |
@Override |
222 | 278 |
public void removeWorkingAreaChangedListener(WorkingAreaChangedListener listener) { |
223 | 279 |
WorkingAreaViewPortListener viewPortListener = this.workingAreaListener.get(listener); |
224 |
if( viewPortListener==null ) {
|
|
280 |
if (viewPortListener == null) {
|
|
225 | 281 |
return; |
226 | 282 |
} |
227 |
viewPortListener.getViewPort().removeViewPortListener(viewPortListener);
|
|
283 |
viewPortListener.getViewPort().removeViewPortListener(viewPortListener); |
|
228 | 284 |
} |
229 |
|
|
230 |
|
|
285 |
|
|
286 |
@Override |
|
287 |
public void addError(Geometry geom) { |
|
288 |
if (this.errorPointSymbol == null) { |
|
289 |
try { |
|
290 |
File pluginfolder = PluginsLocator.getManager().getPlugin(this).getPluginDirectory(); |
|
291 |
File folder = new File(pluginfolder, "symbols"); |
|
292 |
ISymbol[] symbols = MapContextLocator.getSymbolManager().loadSymbols(folder); |
|
293 |
for (ISymbol symbol : symbols) { |
|
294 |
if (symbol instanceof ISymbol_v2) { |
|
295 |
String symbolid = ((ISymbol_v2) symbol).getID(); |
|
296 |
switch(symbolid) { |
|
297 |
case "topology-error-polygon": |
|
298 |
this.errorPolygonSymbol = symbol; |
|
299 |
break; |
|
300 |
case "topology-error-line": |
|
301 |
this.errorLineSymbol = symbol; |
|
302 |
break; |
|
303 |
case "topology-error-point": |
|
304 |
this.errorPointSymbol = symbol; |
|
305 |
break; |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
} catch (Exception ex) { |
|
310 |
} |
|
311 |
} |
|
312 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
313 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
314 |
MapContext mapContext = viewdoc.getMapContext(); |
|
315 |
GraphicLayer gl = mapContext.getGraphicsLayer(); |
|
316 |
gl.removeGraphics("topology-errors"); |
|
317 |
if ( geom!=null ) { |
|
318 |
ISymbol symbol = null; |
|
319 |
if( geom instanceof Point || geom instanceof MultiPoint) { |
|
320 |
symbol = this.errorPointSymbol; |
|
321 |
} else if( geom instanceof Curve || geom instanceof MultiCurve ) { |
|
322 |
symbol = this.errorLineSymbol; |
|
323 |
} else if( geom instanceof Surface || geom instanceof MultiSurface ) { |
|
324 |
symbol = this.errorPolygonSymbol; |
|
325 |
} |
|
326 |
if (symbol != null) { |
|
327 |
int symbolid = gl.getSymbolId(symbol); |
|
328 |
if (symbolid < 0) { |
|
329 |
gl.addSymbol(symbol); |
|
330 |
symbolid = gl.getSymbolId(symbol); |
|
331 |
} |
|
332 |
gl.addGraphic("topology-errors", geom, symbolid); |
|
333 |
} |
|
334 |
} |
|
335 |
mapContext.invalidate(); |
|
336 |
} |
|
337 |
|
|
338 |
@Override |
|
339 |
public void setShowFormWhenEdit(boolean showFormWhenEdit) { |
|
340 |
if (this.editingNotificationObserver == null) { |
|
341 |
this.editingNotificationObserver = new EditingNotificationObserver(); |
|
342 |
} |
|
343 |
EditingNotificationManager editingNotificationManager = DALSwingLocator.getEditingNotificationManager(); |
|
344 |
if (showFormWhenEdit) { |
|
345 |
editingNotificationManager.addObserver(this.editingNotificationObserver); |
|
346 |
} else { |
|
347 |
editingNotificationManager.deleteObserver(this.editingNotificationObserver); |
|
348 |
} |
|
349 |
} |
|
350 |
|
|
351 |
@Override |
|
352 |
public ImageIcon getTreeIcon(TreeModel model, Object item) { |
|
353 |
return ((DataSetsTreeModel)model).getTreeIcon(item); |
|
354 |
} |
|
355 |
|
|
231 | 356 |
} |
Also available in: Unified diff