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