1 |
1 |
/*
|
2 |
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
|
*
|
4 |
|
* Project : DiSiD org.gvsig.vectorediting.lib.impl
|
|
3 |
*
|
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.impl
|
5 |
5 |
* SVN Id : $Id$
|
6 |
6 |
*/
|
7 |
7 |
package org.gvsig.vectorediting.swing.impl;
|
... | ... | |
22 |
22 |
import org.gvsig.andami.ui.mdiFrame.MainFrame;
|
23 |
23 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
|
24 |
24 |
import org.gvsig.fmap.geom.Geometry;
|
|
25 |
import org.gvsig.fmap.geom.exception.CreateGeometryException;
|
25 |
26 |
import org.gvsig.fmap.geom.primitive.Point;
|
26 |
27 |
import org.gvsig.fmap.mapcontext.MapContext;
|
27 |
28 |
import org.gvsig.fmap.mapcontext.ViewPort;
|
... | ... | |
53 |
54 |
|
54 |
55 |
public class DefaultEditingBehavior extends Behavior implements EditingBehavior {
|
55 |
56 |
|
56 |
|
private Map<FLyrVect, EditingService> serviceRegistration;
|
|
57 |
private Map<FLyrVect, EditingService> serviceRegistration;
|
57 |
58 |
|
58 |
|
private MapControl mapControl;
|
|
59 |
private MapControl mapControl;
|
59 |
60 |
|
60 |
|
private FLyrVect currentLayer;
|
|
61 |
private FLyrVect currentLayer;
|
61 |
62 |
|
62 |
|
private EditingService activeService;
|
|
63 |
private EditingService activeService;
|
63 |
64 |
|
64 |
|
private EditingServiceParameter currentParam;
|
|
65 |
private EditingServiceParameter currentParam;
|
65 |
66 |
|
66 |
|
private Point adjustedPoint;
|
|
67 |
private Point adjustedPoint;
|
67 |
68 |
|
68 |
|
private StatusBarListener sbl = null;
|
|
69 |
private StatusBarListener sbl = null;
|
69 |
70 |
|
70 |
|
private JConsole console;
|
|
71 |
private JConsole console;
|
71 |
72 |
|
72 |
|
private JDockPanel dockConsole = null;
|
|
73 |
private JDockPanel dockConsole = null;
|
73 |
74 |
|
74 |
|
private boolean isShowConsole;
|
|
75 |
private boolean isShowConsole;
|
75 |
76 |
|
76 |
|
protected ResponseAdapter consoleResponseAdapter;
|
|
77 |
protected ResponseAdapter consoleResponseAdapter;
|
77 |
78 |
|
78 |
|
private static final Image imageCursor = new BufferedImage(32, 32,
|
79 |
|
BufferedImage.TYPE_INT_ARGB);
|
80 |
|
static {
|
81 |
|
Graphics g = imageCursor.getGraphics();
|
82 |
|
int size1 = 15;
|
83 |
|
int x = 16;
|
84 |
|
int y = 16;
|
85 |
|
g.setColor(Color.MAGENTA);
|
86 |
|
g.drawLine((x - size1), (y), (x + size1), (y));
|
87 |
|
g.drawLine((x), (y - size1), (x), (y + size1));
|
88 |
|
g.drawRect((x - 6), (y - 6), 12, 12);
|
89 |
|
g.drawRect((x - 3), (y - 3), 6, 6);
|
90 |
|
}
|
|
79 |
private static final Image imageCursor = new BufferedImage(32, 32,
|
|
80 |
BufferedImage.TYPE_INT_ARGB);
|
|
81 |
static {
|
|
82 |
Graphics g = imageCursor.getGraphics();
|
|
83 |
int size1 = 15;
|
|
84 |
int x = 16;
|
|
85 |
int y = 16;
|
|
86 |
g.setColor(Color.MAGENTA);
|
|
87 |
g.drawLine((x - size1), (y), (x + size1), (y));
|
|
88 |
g.drawLine((x), (y - size1), (x), (y + size1));
|
|
89 |
g.drawRect((x - 6), (y - 6), 12, 12);
|
|
90 |
g.drawRect((x - 3), (y - 3), 6, 6);
|
|
91 |
}
|
91 |
92 |
|
92 |
|
private LayerListener layerListener = new LayerListener() {
|
|
93 |
private LayerListener layerListener = new LayerListener() {
|
93 |
94 |
|
94 |
|
public void activationChanged(LayerEvent e) {
|
95 |
|
FLayer layer = e.getSource();
|
96 |
|
if (layer instanceof FLyrVect) {
|
|
95 |
public void activationChanged(LayerEvent e) {
|
|
96 |
FLayer layer = e.getSource();
|
|
97 |
if (layer instanceof FLyrVect) {
|
97 |
98 |
|
98 |
|
if (layer.isActive() && layer.isEditing()) {
|
99 |
|
showConsole();
|
100 |
|
getMapControl().setTool("VectorEditing");
|
101 |
|
}
|
102 |
|
else if (!layer.isEditing() && layer.isActive()) {
|
103 |
|
changeCurrentLayer((FLyrVect) layer);
|
104 |
|
hideConsole();
|
105 |
|
getMapControl().setTool("zoomIn");
|
106 |
|
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
107 |
|
}
|
108 |
|
changeCurrentLayer((FLyrVect) layer);
|
|
99 |
if (layer.isActive() && layer.isEditing()) {
|
|
100 |
showConsole();
|
|
101 |
getMapControl().setTool("VectorEditing");
|
|
102 |
} else if (!layer.isEditing() && layer.isActive()) {
|
|
103 |
changeCurrentLayer((FLyrVect) layer);
|
|
104 |
hideConsole();
|
|
105 |
getMapControl().setTool("zoomIn");
|
|
106 |
PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
|
|
107 |
}
|
|
108 |
changeCurrentLayer((FLyrVect) layer);
|
109 |
109 |
|
110 |
|
}
|
|
110 |
}
|
111 |
111 |
|
112 |
|
}
|
|
112 |
}
|
113 |
113 |
|
114 |
|
public void drawValueChanged(LayerEvent e) {}
|
|
114 |
public void drawValueChanged(LayerEvent e) {
|
|
115 |
}
|
115 |
116 |
|
116 |
|
public void editionChanged(LayerEvent e) {}
|
|
117 |
public void editionChanged(LayerEvent e) {
|
|
118 |
}
|
117 |
119 |
|
118 |
|
public void nameChanged(LayerEvent e) {}
|
|
120 |
public void nameChanged(LayerEvent e) {
|
|
121 |
}
|
119 |
122 |
|
120 |
|
public void visibilityChanged(LayerEvent e) {}
|
121 |
|
};
|
|
123 |
public void visibilityChanged(LayerEvent e) {
|
|
124 |
}
|
|
125 |
};
|
122 |
126 |
|
123 |
|
public void cleanBehavior() {
|
124 |
|
activeService = null;
|
125 |
|
currentParam = null;
|
|
127 |
public void cleanBehavior() {
|
|
128 |
activeService = null;
|
|
129 |
currentParam = null;
|
126 |
130 |
|
127 |
|
getConsolePanel()
|
128 |
|
.addText("\nSeleccione un herramienta\n", JConsole.MESSAGE);
|
129 |
|
// MainFrame main = PluginServices.getMainFrame();
|
130 |
|
// main.setSelectedTool(""); We can define a default tool. I.E Zoom in.
|
131 |
|
}
|
|
131 |
getConsolePanel().addText("\nSeleccione un herramienta\n",
|
|
132 |
JConsole.MESSAGE);
|
|
133 |
// MainFrame main = PluginServices.getMainFrame();
|
|
134 |
// main.setSelectedTool(""); We can define a default tool. I.E Zoom in.
|
|
135 |
}
|
132 |
136 |
|
133 |
|
public DefaultEditingBehavior(MapControl mapControl) {
|
134 |
|
if (mapControl != null) {
|
135 |
|
this.mapControl = mapControl;
|
136 |
|
serviceRegistration = new HashMap<FLyrVect, EditingService>();
|
137 |
|
sbl = new StatusBarListener(mapControl);
|
138 |
|
initMapControlListeners(mapControl);
|
139 |
|
initConsolePanelListeners(getConsolePanel());
|
140 |
|
FLayers layers = mapControl.getMapContext().getLayers();
|
141 |
|
for (int i = 0; i < layers.getLayersCount(); i++) {
|
142 |
|
if (layers.getLayer(i) instanceof FLyrVect
|
143 |
|
&& layers.getLayer(i).isActive())
|
144 |
|
changeCurrentLayer((FLyrVect) layers.getLayer(i));
|
145 |
|
}
|
|
137 |
public DefaultEditingBehavior(MapControl mapControl) {
|
|
138 |
if (mapControl != null) {
|
|
139 |
this.mapControl = mapControl;
|
|
140 |
serviceRegistration = new HashMap<FLyrVect, EditingService>();
|
|
141 |
sbl = new StatusBarListener(mapControl);
|
|
142 |
initMapControlListeners(mapControl);
|
|
143 |
initConsolePanelListeners(getConsolePanel());
|
|
144 |
FLayers layers = mapControl.getMapContext().getLayers();
|
|
145 |
for (int i = 0; i < layers.getLayersCount(); i++) {
|
|
146 |
if (layers.getLayer(i) instanceof FLyrVect
|
|
147 |
&& layers.getLayer(i).isActive())
|
|
148 |
changeCurrentLayer((FLyrVect) layers.getLayer(i));
|
|
149 |
}
|
146 |
150 |
|
147 |
|
}
|
148 |
|
}
|
|
151 |
}
|
|
152 |
}
|
149 |
153 |
|
150 |
|
private void initConsolePanelListeners(JConsole jConsole) {
|
151 |
|
consoleResponseAdapter = new ResponseAdapter();
|
152 |
|
jConsole.addResponseListener(consoleResponseAdapter);
|
153 |
|
addConsoleListener("ViewEditing", new ResponseListener() {
|
|
154 |
private void initConsolePanelListeners(JConsole jConsole) {
|
|
155 |
consoleResponseAdapter = new ResponseAdapter();
|
|
156 |
jConsole.addResponseListener(consoleResponseAdapter);
|
|
157 |
addConsoleListener("ViewEditing", new ResponseListener() {
|
154 |
158 |
|
155 |
|
public void acceptResponse(String response) {
|
156 |
|
try {
|
157 |
|
textEntered(response);
|
158 |
|
}
|
159 |
|
catch (RuntimeException ex) {
|
160 |
|
getConsolePanel().addText(ex.getMessage(), JConsole.ERROR);
|
161 |
|
getNextParameter();
|
162 |
|
}
|
163 |
|
}
|
164 |
|
});
|
165 |
|
|
166 |
|
}
|
|
159 |
public void acceptResponse(String response) {
|
|
160 |
try {
|
|
161 |
textEntered(response);
|
|
162 |
} catch (RuntimeException ex) {
|
|
163 |
getConsolePanel().addText(ex.getMessage(), JConsole.ERROR);
|
|
164 |
getNextParameter();
|
|
165 |
}
|
|
166 |
}
|
|
167 |
});
|
167 |
168 |
|
168 |
|
public void activateTool(String name) {
|
|
169 |
}
|
169 |
170 |
|
170 |
|
EditingManager manager = EditingLocator.getManager();
|
|
171 |
public void activateTool(String name) {
|
171 |
172 |
|
172 |
|
if (currentLayer != null) {
|
173 |
|
EditingService service = serviceRegistration.get(currentLayer);
|
174 |
|
if (service == null) {
|
175 |
|
service = (EditingService) manager.getEditingService(name,
|
176 |
|
currentLayer.getFeatureStore());
|
177 |
|
serviceRegistration.put(currentLayer, service);
|
178 |
|
}
|
179 |
|
if (service != null) {
|
180 |
|
this.activeService = service;
|
181 |
|
service.start();
|
182 |
|
getNextParameter();
|
183 |
|
}
|
184 |
|
}
|
185 |
|
}
|
|
173 |
EditingManager manager = EditingLocator.getManager();
|
186 |
174 |
|
187 |
|
private void askQuestion(EditingServiceParameter param) {
|
188 |
|
if (getConsolePanel() != null) {
|
189 |
|
getConsolePanel().addText("\n" + "#" + param.getDescription() + " > ",
|
190 |
|
JConsole.MESSAGE);
|
191 |
|
}
|
192 |
|
}
|
|
175 |
if (currentLayer != null) {
|
|
176 |
EditingService service = serviceRegistration.get(currentLayer);
|
|
177 |
if (service == null) {
|
|
178 |
service = (EditingService) manager.getEditingService(name,
|
|
179 |
currentLayer.getFeatureStore());
|
|
180 |
serviceRegistration.put(currentLayer, service);
|
|
181 |
}
|
|
182 |
if (service != null) {
|
|
183 |
this.activeService = service;
|
|
184 |
service.start();
|
|
185 |
getNextParameter();
|
|
186 |
}
|
|
187 |
}
|
|
188 |
}
|
193 |
189 |
|
194 |
|
@Override
|
195 |
|
public ToolListener getListener() {
|
196 |
|
return new ToolListener() {
|
|
190 |
private void askQuestion(EditingServiceParameter param) {
|
|
191 |
if (getConsolePanel() != null) {
|
|
192 |
getConsolePanel().addText(
|
|
193 |
"\n" + "#" + param.getDescription() + " > ",
|
|
194 |
JConsole.MESSAGE);
|
|
195 |
}
|
|
196 |
}
|
197 |
197 |
|
198 |
|
/**
|
199 |
|
*
|
|
198 |
@Override
|
|
199 |
public ToolListener getListener() {
|
|
200 |
return new ToolListener() {
|
|
201 |
|
|
202 |
/**
|
|
203 |
*
|
200 |
204 |
*/
|
201 |
|
public boolean cancelDrawing() {
|
202 |
|
return false;
|
203 |
|
}
|
|
205 |
public boolean cancelDrawing() {
|
|
206 |
return false;
|
|
207 |
}
|
204 |
208 |
|
205 |
|
/**
|
206 |
|
*
|
|
209 |
/**
|
|
210 |
*
|
207 |
211 |
*/
|
208 |
|
public Image getImageCursor() {
|
209 |
|
return imageCursor;
|
210 |
|
}
|
211 |
|
};
|
212 |
|
}
|
|
212 |
public Image getImageCursor() {
|
|
213 |
return imageCursor;
|
|
214 |
}
|
|
215 |
};
|
|
216 |
}
|
213 |
217 |
|
214 |
|
private void getNextParameter() {
|
215 |
|
currentParam = activeService.next();
|
216 |
|
if (currentParam == null) {
|
217 |
|
activeService.finish();
|
218 |
|
mapControl.rePaintDirtyLayers();
|
219 |
|
activeService.start();
|
220 |
|
getNextParameter();
|
221 |
|
}
|
222 |
|
else {
|
223 |
|
askQuestion(currentParam);
|
224 |
|
setCaretPosition();
|
225 |
|
}
|
|
218 |
private void getNextParameter() {
|
|
219 |
currentParam = activeService.next();
|
|
220 |
if (currentParam == null) {
|
|
221 |
activeService.finish();
|
|
222 |
mapControl.rePaintDirtyLayers();
|
|
223 |
activeService.start();
|
|
224 |
getNextParameter();
|
|
225 |
} else {
|
|
226 |
askQuestion(currentParam);
|
|
227 |
setCaretPosition();
|
|
228 |
}
|
226 |
229 |
|
227 |
|
}
|
|
230 |
}
|
228 |
231 |
|
229 |
|
private void initMapControlListeners(MapControl mapControl) {
|
|
232 |
private void initMapControlListeners(MapControl mapControl) {
|
230 |
233 |
|
231 |
|
MapContext context = mapControl.getMapContext();
|
232 |
|
FLayers layers = context.getLayers();
|
233 |
|
layers.addLayerListener(layerListener);
|
|
234 |
MapContext context = mapControl.getMapContext();
|
|
235 |
FLayers layers = context.getLayers();
|
|
236 |
layers.addLayerListener(layerListener);
|
234 |
237 |
|
235 |
|
layers.addLayerCollectionListener(new LayerCollectionListener() {
|
|
238 |
layers.addLayerCollectionListener(new LayerCollectionListener() {
|
236 |
239 |
|
237 |
|
public void layerAdded(LayerCollectionEvent e) {
|
238 |
|
FLayers layers2 = e.getLayers();
|
239 |
|
for (int i = 0; i < layers2.getLayersCount(); i++) {
|
240 |
|
FLayer layer = layers2.getLayer(i);
|
241 |
|
if (layer instanceof FLyrVect) {
|
242 |
|
((FLyrVect) layer).addLayerListener(layerListener);
|
243 |
|
}
|
244 |
|
}
|
245 |
|
}
|
|
240 |
public void layerAdded(LayerCollectionEvent e) {
|
|
241 |
FLayers layers2 = e.getLayers();
|
|
242 |
for (int i = 0; i < layers2.getLayersCount(); i++) {
|
|
243 |
FLayer layer = layers2.getLayer(i);
|
|
244 |
if (layer instanceof FLyrVect) {
|
|
245 |
((FLyrVect) layer).addLayerListener(layerListener);
|
|
246 |
}
|
|
247 |
}
|
|
248 |
}
|
246 |
249 |
|
247 |
|
public void layerAdding(LayerCollectionEvent e)
|
248 |
|
throws CancelationException {}
|
|
250 |
public void layerAdding(LayerCollectionEvent e)
|
|
251 |
throws CancelationException {
|
|
252 |
}
|
249 |
253 |
|
250 |
|
public void layerMoved(LayerPositionEvent e) {}
|
|
254 |
public void layerMoved(LayerPositionEvent e) {
|
|
255 |
}
|
251 |
256 |
|
252 |
|
public void layerMoving(LayerPositionEvent e) throws CancelationException {}
|
|
257 |
public void layerMoving(LayerPositionEvent e)
|
|
258 |
throws CancelationException {
|
|
259 |
}
|
253 |
260 |
|
254 |
|
public void layerRemoved(LayerCollectionEvent e) {
|
255 |
|
FLayers layers2 = e.getLayers();
|
256 |
|
for (int i = 0; i < layers2.getLayersCount(); i++) {
|
257 |
|
FLayer layer = layers2.getLayer(i);
|
258 |
|
if (layer instanceof FLyrVect) {
|
259 |
|
((FLyrVect) layer).removeLayerListener(layerListener);
|
260 |
|
}
|
261 |
|
}
|
262 |
|
}
|
|
261 |
public void layerRemoved(LayerCollectionEvent e) {
|
|
262 |
FLayers layers2 = e.getLayers();
|
|
263 |
for (int i = 0; i < layers2.getLayersCount(); i++) {
|
|
264 |
FLayer layer = layers2.getLayer(i);
|
|
265 |
if (layer instanceof FLyrVect) {
|
|
266 |
((FLyrVect) layer).removeLayerListener(layerListener);
|
|
267 |
}
|
|
268 |
}
|
|
269 |
}
|
263 |
270 |
|
264 |
|
public void layerRemoving(LayerCollectionEvent e)
|
265 |
|
throws CancelationException {}
|
|
271 |
public void layerRemoving(LayerCollectionEvent e)
|
|
272 |
throws CancelationException {
|
|
273 |
}
|
266 |
274 |
|
267 |
|
public void visibilityChanged(LayerCollectionEvent e)
|
268 |
|
throws CancelationException {}
|
269 |
|
});
|
270 |
|
}
|
|
275 |
public void visibilityChanged(LayerCollectionEvent e)
|
|
276 |
throws CancelationException {
|
|
277 |
}
|
|
278 |
});
|
|
279 |
}
|
271 |
280 |
|
272 |
|
public void mouseClicked(MouseEvent e) throws BehaviorException {
|
273 |
|
// TODO Auto-generated method stub
|
274 |
|
ViewPort vp = mapControl.getViewPort();
|
275 |
|
if (activeService != null) {
|
276 |
|
if (currentParam != null) {
|
277 |
|
switch (currentParam.getType()) {
|
278 |
|
case POSITION:
|
279 |
|
Point point;
|
280 |
|
point = vp.convertToMapPoint(e.getX(), e.getY());
|
281 |
|
this.activeService.value(point);
|
|
281 |
public void mouseClicked(MouseEvent e) throws BehaviorException {
|
|
282 |
// TODO Auto-generated method stub
|
|
283 |
ViewPort vp = mapControl.getViewPort();
|
|
284 |
if (activeService != null) {
|
|
285 |
if (currentParam != null) {
|
|
286 |
switch (currentParam.getType()) {
|
|
287 |
case POSITION:
|
|
288 |
case VALUE:
|
|
289 |
Point point;
|
|
290 |
point = vp.convertToMapPoint(e.getX(), e.getY());
|
|
291 |
this.activeService.value(point);
|
282 |
292 |
|
283 |
|
case LIST_POSITIONS:
|
284 |
|
case OPTION:
|
285 |
|
case SELECTION:
|
286 |
|
case GEOMETRY:
|
287 |
|
case VALUE:
|
288 |
|
}
|
289 |
|
getNextParameter();
|
290 |
|
}
|
|
293 |
case LIST_POSITIONS:
|
|
294 |
case OPTION:
|
|
295 |
case SELECTION:
|
|
296 |
case GEOMETRY:
|
|
297 |
}
|
|
298 |
getNextParameter();
|
|
299 |
}
|
291 |
300 |
|
292 |
|
}
|
293 |
|
}
|
|
301 |
}
|
|
302 |
}
|
294 |
303 |
|
295 |
|
public void mouseEntered(MouseEvent e) throws BehaviorException {
|
296 |
|
// TODO Auto-generated method stub
|
297 |
|
}
|
|
304 |
public void mouseEntered(MouseEvent e) throws BehaviorException {
|
|
305 |
// TODO Auto-generated method stub
|
|
306 |
}
|
298 |
307 |
|
299 |
|
public void mouseMoved(MouseEvent e) throws BehaviorException {
|
300 |
|
ViewPort vp = mapControl.getViewPort();
|
301 |
|
adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY());
|
302 |
|
showCoords(e.getPoint());
|
|
308 |
public void mouseMoved(MouseEvent e) throws BehaviorException {
|
|
309 |
ViewPort vp = mapControl.getViewPort();
|
|
310 |
adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY());
|
|
311 |
showCoords(e.getPoint());
|
303 |
312 |
|
304 |
|
getMapControl().repaint();
|
305 |
|
}
|
|
313 |
getMapControl().repaint();
|
|
314 |
}
|
306 |
315 |
|
307 |
|
public void mousePressed(MouseEvent e) throws BehaviorException {
|
308 |
|
// TODO Auto-generated method stub
|
309 |
|
}
|
|
316 |
public void mousePressed(MouseEvent e) throws BehaviorException {
|
|
317 |
// TODO Auto-generated method stub
|
|
318 |
}
|
310 |
319 |
|
311 |
|
public void mouseReleased(MouseEvent e) throws BehaviorException {
|
312 |
|
// TODO Auto-generated method stub
|
313 |
|
}
|
|
320 |
public void mouseReleased(MouseEvent e) throws BehaviorException {
|
|
321 |
// TODO Auto-generated method stub
|
|
322 |
}
|
314 |
323 |
|
315 |
|
public void paintComponent(MapControlDrawer mapControlDrawer) {
|
316 |
|
super.paintComponent(mapControlDrawer);
|
317 |
|
if (activeService == null || adjustedPoint == null) {
|
318 |
|
return;
|
319 |
|
}
|
|
324 |
public void paintComponent(MapControlDrawer mapControlDrawer) {
|
|
325 |
super.paintComponent(mapControlDrawer);
|
|
326 |
if (activeService == null || adjustedPoint == null) {
|
|
327 |
return;
|
|
328 |
}
|
320 |
329 |
|
321 |
|
Geometry helperGeo = activeService.draw(adjustedPoint);
|
322 |
|
if (helperGeo != null) {
|
323 |
|
mapControl.getMapControlDrawer().draw(helperGeo,
|
324 |
|
MapControlLocator.getMapControlManager().getAxisReferenceSymbol());
|
325 |
|
}
|
326 |
|
}
|
|
330 |
Geometry helperGeo = activeService.draw(adjustedPoint);
|
|
331 |
if (helperGeo != null) {
|
|
332 |
mapControl.getMapControlDrawer().draw(
|
|
333 |
helperGeo,
|
|
334 |
MapControlLocator.getMapControlManager()
|
|
335 |
.getAxisReferenceSymbol());
|
|
336 |
}
|
|
337 |
}
|
327 |
338 |
|
328 |
|
private void setCaretPosition() {
|
|
339 |
private void setCaretPosition() {
|
329 |
340 |
|
330 |
|
JEditTextArea jeta = getConsolePanel().getTxt();
|
331 |
|
jeta.requestFocusInWindow();
|
332 |
|
jeta.setCaretPosition(jeta.getText().length());
|
|
341 |
JEditTextArea jeta = getConsolePanel().getTxt();
|
|
342 |
jeta.requestFocusInWindow();
|
|
343 |
jeta.setCaretPosition(jeta.getText().length());
|
333 |
344 |
|
334 |
|
}
|
|
345 |
}
|
335 |
346 |
|
336 |
|
private void changeCurrentLayer(FLyrVect layer) {
|
337 |
|
this.currentLayer = layer;
|
338 |
|
this.activeService = serviceRegistration.get(layer);
|
339 |
|
if (activeService != null) {
|
340 |
|
getNextParameter();
|
341 |
|
MainFrame main = PluginServices.getMainFrame();
|
342 |
|
main.setSelectedTool(activeService.getName());
|
343 |
|
}
|
344 |
|
}
|
|
347 |
private void changeCurrentLayer(FLyrVect layer) {
|
|
348 |
this.currentLayer = layer;
|
|
349 |
this.activeService = serviceRegistration.get(layer);
|
|
350 |
if (activeService != null) {
|
|
351 |
getNextParameter();
|
|
352 |
MainFrame main = PluginServices.getMainFrame();
|
|
353 |
main.setSelectedTool(activeService.getName());
|
|
354 |
}
|
|
355 |
}
|
345 |
356 |
|
346 |
|
private void showCoords(Point2D point) {
|
347 |
|
String[] axisText = new String[2];
|
348 |
|
axisText[0] = "X = ";
|
349 |
|
axisText[1] = "Y = ";
|
|
357 |
private void showCoords(Point2D point) {
|
|
358 |
String[] axisText = new String[2];
|
|
359 |
axisText[0] = "X = ";
|
|
360 |
axisText[1] = "Y = ";
|
350 |
361 |
|
351 |
|
ViewPort vp = mapControl.getMapContext().getViewPort();
|
352 |
|
IProjection iProj = vp.getProjection();
|
353 |
|
Point p = vp.convertToMapPoint(point);
|
354 |
|
Point2D p2D = new Point2D.Double(p.getX(), p.getY());
|
|
362 |
ViewPort vp = mapControl.getMapContext().getViewPort();
|
|
363 |
IProjection iProj = vp.getProjection();
|
|
364 |
Point p = vp.convertToMapPoint(point);
|
|
365 |
Point2D p2D = new Point2D.Double(p.getX(), p.getY());
|
355 |
366 |
|
356 |
|
sbl.setFractionDigits(p2D);
|
357 |
|
axisText = sbl.setCoorDisplayText(axisText);
|
358 |
|
MainFrame mF = PluginServices.getMainFrame();
|
|
367 |
sbl.setFractionDigits(p2D);
|
|
368 |
axisText = sbl.setCoorDisplayText(axisText);
|
|
369 |
MainFrame mF = PluginServices.getMainFrame();
|
359 |
370 |
|
360 |
|
if (mF != null) {
|
361 |
|
mF.getStatusBar().setMessage(
|
362 |
|
"units",
|
363 |
|
PluginServices.getText(this,
|
364 |
|
MapContext.getDistanceNames()[vp.getDistanceUnits()]));
|
365 |
|
mF.getStatusBar().setControlValue("scale",
|
366 |
|
String.valueOf(mapControl.getMapContext().getScaleView()));
|
367 |
|
mF.getStatusBar().setMessage("projection", iProj.getAbrev());
|
|
371 |
if (mF != null) {
|
|
372 |
mF.getStatusBar()
|
|
373 |
.setMessage(
|
|
374 |
"units",
|
|
375 |
PluginServices.getText(this, MapContext
|
|
376 |
.getDistanceNames()[vp.getDistanceUnits()]));
|
|
377 |
mF.getStatusBar().setControlValue("scale",
|
|
378 |
String.valueOf(mapControl.getMapContext().getScaleView()));
|
|
379 |
mF.getStatusBar().setMessage("projection", iProj.getAbrev());
|
368 |
380 |
|
369 |
|
String[] coords = sbl.getCoords(p2D);
|
370 |
|
mF.getStatusBar().setMessage("x", axisText[0] + coords[0]);
|
371 |
|
mF.getStatusBar().setMessage("y", axisText[1] + coords[1]);
|
372 |
|
}
|
|
381 |
String[] coords = sbl.getCoords(p2D);
|
|
382 |
mF.getStatusBar().setMessage("x", axisText[0] + coords[0]);
|
|
383 |
mF.getStatusBar().setMessage("y", axisText[1] + coords[1]);
|
|
384 |
}
|
373 |
385 |
|
374 |
|
}
|
|
386 |
}
|
375 |
387 |
|
376 |
|
private void textEntered(String response) {
|
377 |
|
if (response == null) {
|
378 |
|
cleanBehavior();
|
379 |
|
}
|
380 |
|
else {
|
381 |
|
TYPE type = currentParam.getType();
|
382 |
|
try {
|
383 |
|
switch (type) {
|
384 |
|
case POSITION:
|
385 |
|
String[] numbers = new String[1];
|
386 |
|
numbers[0] = response;
|
387 |
|
numbers = response.split(",");
|
388 |
|
if (numbers.length == 2) {
|
389 |
|
if (numbers[0].startsWith("(") && numbers[1].endsWith(")\n")) { // CCS
|
390 |
|
numbers[0] = numbers[0].replace("(", "");
|
391 |
|
numbers[1] = numbers[1].replace(")\n", "");
|
392 |
|
}
|
393 |
|
double[] values = new double[] { Double.parseDouble(numbers[0]),
|
394 |
|
Double.parseDouble(numbers[1]) };
|
|
388 |
private void textEntered(String response) {
|
|
389 |
if (response == null) {
|
|
390 |
cleanBehavior();
|
|
391 |
} else {
|
|
392 |
TYPE type = currentParam.getType();
|
|
393 |
try {
|
|
394 |
Point point = null;
|
|
395 |
Double value = null;
|
|
396 |
switch (type) {
|
|
397 |
case POSITION:
|
|
398 |
point = parsePoint(response);
|
|
399 |
if (point != null){
|
|
400 |
this.activeService.value(point);
|
|
401 |
}
|
|
402 |
break;
|
|
403 |
case VALUE:
|
|
404 |
try {
|
|
405 |
point = parsePoint(response);
|
|
406 |
} catch (Exception e) {
|
|
407 |
// Do nothing
|
|
408 |
}
|
|
409 |
if (point != null){
|
|
410 |
this.activeService.value(point);
|
|
411 |
break;
|
|
412 |
}
|
|
413 |
value = Double.valueOf(response);
|
|
414 |
this.activeService.value(value);
|
|
415 |
break;
|
|
416 |
case LIST_POSITIONS:
|
|
417 |
case OPTION:
|
|
418 |
case SELECTION:
|
|
419 |
case GEOMETRY:
|
|
420 |
}
|
|
421 |
getNextParameter();
|
|
422 |
} catch (Exception e) {
|
|
423 |
throw new RuntimeException("Datos inv?lidos: " + response);
|
|
424 |
}
|
|
425 |
}
|
|
426 |
}
|
395 |
427 |
|
396 |
|
Point point = geomManager.createPoint(values[0], values[1],
|
397 |
|
Geometry.SUBTYPES.GEOM2D); // TODO Maybe do util class to get type
|
398 |
|
// and subtype of a featureStore
|
|
428 |
private Point parsePoint(String response){
|
|
429 |
String[] numbers = new String[1];
|
|
430 |
numbers[0] = response;
|
|
431 |
numbers = response.split(",");
|
|
432 |
if (numbers.length == 2) {
|
|
433 |
if (numbers[0].startsWith("(") && numbers[1].endsWith(")\n")) { // CCS
|
|
434 |
numbers[0] = numbers[0].replace("(", "");
|
|
435 |
numbers[1] = numbers[1].replace(")\n", "");
|
|
436 |
}
|
|
437 |
double[] values = new double[] { Double.parseDouble(numbers[0]),
|
|
438 |
Double.parseDouble(numbers[1]) };
|
399 |
439 |
|
400 |
|
this.activeService.value(point);
|
401 |
|
}
|
402 |
|
else {
|
403 |
|
throw new RuntimeException("Datos inv?lidos: " + response);
|
404 |
|
}
|
405 |
|
case LIST_POSITIONS:
|
406 |
|
case OPTION:
|
407 |
|
case SELECTION:
|
408 |
|
case GEOMETRY:
|
409 |
|
case VALUE:
|
410 |
|
}
|
411 |
|
getNextParameter();
|
412 |
|
}
|
413 |
|
catch (Exception e) {
|
414 |
|
throw new RuntimeException("Datos inv?lidos: " + response);
|
415 |
|
}
|
416 |
|
}
|
417 |
|
}
|
|
440 |
Point point;
|
|
441 |
try {
|
|
442 |
point = geomManager.createPoint(values[0], values[1],
|
|
443 |
Geometry.SUBTYPES.GEOM2D);
|
|
444 |
// TODO: Maybe do util class to get type and subtype of a featureStore
|
|
445 |
return point;
|
|
446 |
} catch (CreateGeometryException e) {
|
|
447 |
new RuntimeException("Can't create a point" + response);
|
|
448 |
}
|
|
449 |
} else {
|
|
450 |
throw new RuntimeException("Can't parse a point" + response);
|
|
451 |
}
|
|
452 |
return null;
|
|
453 |
}
|
418 |
454 |
|
419 |
|
private JDockPanel getDockConsole() {
|
420 |
|
if (dockConsole == null) {
|
421 |
|
dockConsole = new JDockPanel(getConsolePanel());
|
422 |
|
}
|
423 |
|
return dockConsole;
|
424 |
|
}
|
|
455 |
private JDockPanel getDockConsole() {
|
|
456 |
if (dockConsole == null) {
|
|
457 |
dockConsole = new JDockPanel(getConsolePanel());
|
|
458 |
}
|
|
459 |
return dockConsole;
|
|
460 |
}
|
425 |
461 |
|
426 |
|
public void showConsole() {
|
427 |
|
if (isShowConsole) {
|
428 |
|
return;
|
429 |
|
}
|
430 |
|
isShowConsole = true;
|
431 |
|
getMapControl().remove(getDockConsole());
|
432 |
|
getMapControl().setLayout(new BorderLayout());
|
433 |
|
getMapControl().add(getDockConsole(), BorderLayout.SOUTH);
|
434 |
|
getDockConsole().setVisible(true);
|
435 |
|
setCaretPosition();
|
436 |
|
}
|
|
462 |
public void showConsole() {
|
|
463 |
if (isShowConsole) {
|
|
464 |
return;
|
|
465 |
}
|
|
466 |
isShowConsole = true;
|
|
467 |
getMapControl().remove(getDockConsole());
|
|
468 |
getMapControl().setLayout(new BorderLayout());
|
|
469 |
getMapControl().add(getDockConsole(), BorderLayout.SOUTH);
|
|
470 |
getDockConsole().setVisible(true);
|
|
471 |
setCaretPosition();
|
|
472 |
}
|
437 |
473 |
|
438 |
|
public void hideConsole() {
|
439 |
|
isShowConsole = false;
|
440 |
|
getDockConsole().setVisible(false);
|
|
474 |
public void hideConsole() {
|
|
475 |
isShowConsole = false;
|
|
476 |
getDockConsole().setVisible(false);
|
441 |
477 |
|
442 |
|
}
|
|
478 |
}
|
443 |
479 |
|
444 |
|
private JConsole getConsolePanel() {
|
445 |
|
if (console == null) {
|
446 |
|
console = new JConsole(true);
|
447 |
|
// Para distinguir cuando se est? escribiendo sobre la consola y
|
448 |
|
// cuando no.
|
449 |
|
console.setJTextName("VectorEditingConsole");
|
450 |
|
}
|
451 |
|
return console;
|
452 |
|
}
|
|
480 |
private JConsole getConsolePanel() {
|
|
481 |
if (console == null) {
|
|
482 |
console = new JConsole(true);
|
|
483 |
// Para distinguir cuando se est? escribiendo sobre la consola y
|
|
484 |
// cuando no.
|
|
485 |
console.setJTextName("VectorEditingConsole");
|
|
486 |
}
|
|
487 |
return console;
|
|
488 |
}
|
453 |
489 |
|
454 |
|
private void addConsoleListener(String prefix, ResponseListener listener) {
|
455 |
|
consoleResponseAdapter.putSpaceListener(prefix, listener);
|
|
490 |
private void addConsoleListener(String prefix, ResponseListener listener) {
|
|
491 |
consoleResponseAdapter.putSpaceListener(prefix, listener);
|
456 |
492 |
|
457 |
|
}
|
|
493 |
}
|
458 |
494 |
|
459 |
|
static class ResponseAdapter implements ResponseListener {
|
|
495 |
static class ResponseAdapter implements ResponseListener {
|
460 |
496 |
|
461 |
|
private HashMap<String, ResponseListener> spaceListener = new HashMap<String, ResponseListener>();
|
|
497 |
private HashMap<String, ResponseListener> spaceListener = new HashMap<String, ResponseListener>();
|
462 |
498 |
|
463 |
|
public void putSpaceListener(String namespace, ResponseListener listener) {
|
464 |
|
spaceListener.put(namespace, listener);
|
465 |
|
}
|
|
499 |
public void putSpaceListener(String namespace, ResponseListener listener) {
|
|
500 |
spaceListener.put(namespace, listener);
|
|
501 |
}
|
466 |
502 |
|
467 |
|
public void acceptResponse(String response) {
|
468 |
|
boolean nameSpace = false;
|
469 |
|
int n = -1;
|
470 |
|
if (response != null) {
|
471 |
|
if ((n = response.indexOf(':')) != -1) {
|
472 |
|
nameSpace = true;
|
473 |
|
}
|
474 |
|
}
|
|
503 |
public void acceptResponse(String response) {
|
|
504 |
boolean nameSpace = false;
|
|
505 |
int n = -1;
|
|
506 |
if (response != null) {
|
|
507 |
if ((n = response.indexOf(':')) != -1) {
|
|
508 |
nameSpace = true;
|
|
509 |
}
|
|
510 |
}
|
475 |
511 |
|
476 |
|
if (nameSpace) {
|
477 |
|
ResponseListener listener = spaceListener.get(response.substring(0, n));
|
478 |
|
if (listener != null) {
|
479 |
|
listener.acceptResponse(response.substring(n + 1));
|
480 |
|
}
|
481 |
|
}
|
482 |
|
else {
|
483 |
|
Iterator<ResponseListener> i = spaceListener.values().iterator();
|
484 |
|
while (i.hasNext()) {
|
485 |
|
ResponseListener listener = i.next();
|
486 |
|
listener.acceptResponse(response);
|
487 |
|
}
|
488 |
|
}
|
489 |
|
}
|
490 |
|
}
|
|
512 |
if (nameSpace) {
|
|
513 |
ResponseListener listener = spaceListener.get(response
|
|
514 |
.substring(0, n));
|
|
515 |
if (listener != null) {
|
|
516 |
listener.acceptResponse(response.substring(n + 1));
|
|
517 |
}
|
|
518 |
} else {
|
|
519 |
Iterator<ResponseListener> i = spaceListener.values()
|
|
520 |
.iterator();
|
|
521 |
while (i.hasNext()) {
|
|
522 |
ResponseListener listener = i.next();
|
|
523 |
listener.acceptResponse(response);
|
|
524 |
}
|
|
525 |
}
|
|
526 |
}
|
|
527 |
}
|
491 |
528 |
}
|