Revision 30335 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/SelectionCADTool.java
SelectionCADTool.java | ||
---|---|---|
41 | 41 |
package org.gvsig.editing.gui.cad.tools; |
42 | 42 |
|
43 | 43 |
import java.awt.Color; |
44 |
import java.awt.Graphics; |
|
45 | 44 |
import java.awt.Graphics2D; |
46 | 45 |
import java.awt.Image; |
47 | 46 |
import java.awt.event.InputEvent; |
... | ... | |
71 | 70 |
import org.gvsig.fmap.geom.operation.DrawOperationContext; |
72 | 71 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
73 | 72 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
73 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
74 | 74 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
75 | 75 |
import org.gvsig.fmap.mapcontext.MapContext; |
76 | 76 |
import org.gvsig.fmap.mapcontext.ViewPort; |
77 | 77 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
78 | 78 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
79 | 79 |
import org.gvsig.fmap.mapcontrol.MapControl; |
80 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
80 | 81 |
|
81 | 82 |
|
82 | 83 |
/** |
... | ... | |
85 | 86 |
* @author Vicente Caballero Navarro |
86 | 87 |
*/ |
87 | 88 |
public class SelectionCADTool extends DefaultCADTool { |
88 |
// public static int tolerance = 4; |
|
89 |
// public static int tolerance = 4;
|
|
89 | 90 |
|
90 | 91 |
protected SelectionCADToolContext _fsm; |
91 | 92 |
|
92 | 93 |
protected Point2D firstPoint; |
93 | 94 |
|
94 | 95 |
protected String nextState; |
95 |
// Registros de los que se ha seleccionado alg?n handler. |
|
96 |
// Registros de los que se ha seleccionado alg?n handler.
|
|
96 | 97 |
protected ArrayList rowselectedHandlers=new ArrayList(); |
97 | 98 |
protected String type=PluginServices.getText(this,"simple"); |
98 |
// protected ArrayList pointsPolygon=new ArrayList(); |
|
99 |
// protected ArrayList pointsPolygon=new ArrayList();
|
|
99 | 100 |
|
100 | 101 |
protected boolean multipleSelection=false; |
101 | 102 |
/** |
... | ... | |
123 | 124 |
System.out.println("TRANSICION DESDE ESTADO " + _fsm.getState() |
124 | 125 |
+ " x= " + x + " y=" + y); |
125 | 126 |
try{ |
126 |
_fsm.addPoint(x, y, event); |
|
127 |
_fsm.addPoint(x, y, event);
|
|
127 | 128 |
}catch (Exception e) { |
128 | 129 |
init(); |
129 | 130 |
PluginServices.getMDIManager().restoreCursor(); |
... | ... | |
166 | 167 |
public void transition(String s) throws CommandException { |
167 | 168 |
if (!super.changeCommand(s)){ |
168 | 169 |
_fsm.addOption(s); |
169 |
}
|
|
170 |
}
|
|
170 | 171 |
} |
171 | 172 |
|
172 | 173 |
public String getNextState() { |
... | ... | |
175 | 176 |
|
176 | 177 |
protected void pointDoubleClick(MapContext map) throws ReadException { |
177 | 178 |
FLayer[] actives = map |
178 |
.getLayers().getActives();
|
|
179 |
// for (int i=0; i < actives.length; i++){ |
|
180 |
// if (actives[i] instanceof FLyrAnnotation && actives[i].isEditing()) { |
|
181 |
// FLyrAnnotation lyrAnnotation = (FLyrAnnotation) actives[i]; |
|
182 |
// lyrAnnotation.setSelectedEditing(); |
|
183 |
// lyrAnnotation.setInEdition(lyrAnnotation.getRecordset().getSelection().nextSetBit(0)); |
|
184 |
// FLabel fl=lyrAnnotation.getLabel(lyrAnnotation.getInEdition()); |
|
185 |
// if (fl!=null){ |
|
186 |
// View vista=(View)PluginServices.getMDIManager().getActiveWindow(); |
|
187 |
// TextFieldEdit tfe=new TextFieldEdit(lyrAnnotation); |
|
188 |
// tfe.show(vista.getMapControl().getViewPort().fromMapPoint(fl.getOrig()),vista.getMapControl()); |
|
189 |
// } |
|
190 |
// } |
|
191 |
// } |
|
192 |
} |
|
179 |
.getLayers().getActives();
|
|
180 |
// for (int i=0; i < actives.length; i++){
|
|
181 |
// if (actives[i] instanceof FLyrAnnotation && actives[i].isEditing()) {
|
|
182 |
// FLyrAnnotation lyrAnnotation = (FLyrAnnotation) actives[i];
|
|
183 |
// lyrAnnotation.setSelectedEditing();
|
|
184 |
// lyrAnnotation.setInEdition(lyrAnnotation.getRecordset().getSelection().nextSetBit(0));
|
|
185 |
// FLabel fl=lyrAnnotation.getLabel(lyrAnnotation.getInEdition());
|
|
186 |
// if (fl!=null){
|
|
187 |
// View vista=(View)PluginServices.getMDIManager().getActiveWindow();
|
|
188 |
// TextFieldEdit tfe=new TextFieldEdit(lyrAnnotation);
|
|
189 |
// tfe.show(vista.getMapControl().getViewPort().fromMapPoint(fl.getOrig()),vista.getMapControl());
|
|
190 |
// }
|
|
191 |
// }
|
|
192 |
// }
|
|
193 |
}
|
|
193 | 194 |
/** |
194 | 195 |
* Equivale al transition del prototipo pero sin pasarle como par? metro el |
195 | 196 |
* editableFeatureSource que ya estar? creado. |
... | ... | |
202 | 203 |
* par?metro y del punto que se pase en esta transici?n. |
203 | 204 |
*/ |
204 | 205 |
public void addPoint(double x, double y, InputEvent event) { |
205 |
// if (event!=null && ((MouseEvent)event).getClickCount()==2){ |
|
206 |
// try { |
|
207 |
// pointDoubleClick((MapControl)event.getComponent()); |
|
208 |
// } catch (ReadException e) { |
|
209 |
// NotificationManager.addError(e.getMessage(),e); |
|
210 |
// } |
|
211 |
// return; |
|
212 |
// } |
|
206 |
// if (event!=null && ((MouseEvent)event).getClickCount()==2){
|
|
207 |
// try {
|
|
208 |
// pointDoubleClick((MapControl)event.getComponent());
|
|
209 |
// } catch (ReadException e) {
|
|
210 |
// NotificationManager.addError(e.getMessage(),e);
|
|
211 |
// }
|
|
212 |
// return;
|
|
213 |
// }
|
|
213 | 214 |
SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
214 | 215 |
.getPreviousState(); |
215 | 216 |
String status = actualState.getName(); |
... | ... | |
243 | 244 |
// IFeature feat = (IFeature) |
244 | 245 |
// row.getLinkedRow().cloneRow(); |
245 | 246 |
Geometry ig = feature.getDefaultGeometry() |
246 |
.cloneGeometry();
|
|
247 |
.cloneGeometry(); |
|
247 | 248 |
// if (vea instanceof AnnotationEditableAdapter) { |
248 | 249 |
// // Movemos la geometr?a |
249 | 250 |
// UtilFunctions.moveGeom(ig, x - |
... | ... | |
252 | 253 |
// Movemos los handlers que hemos seleccionado |
253 | 254 |
// previamente dentro del m?todo select() |
254 | 255 |
Handler[] handlers = ig |
255 |
.getHandlers(Geometry.SELECTHANDLER);
|
|
256 |
.getHandlers(Geometry.SELECTHANDLER); |
|
256 | 257 |
for (int k = 0; k < selectedHandler.size(); k++) { |
257 | 258 |
Handler h = (Handler) selectedHandler.get(k); |
258 | 259 |
for (int j = 0; j < handlers.length; j++) { |
... | ... | |
334 | 335 |
* @param y |
335 | 336 |
* par?metro x del punto que se pase para dibujar. |
336 | 337 |
*/ |
337 |
public void drawOperation(Graphics g, double x, double y) {
|
|
338 |
public void drawOperation(MapControlDrawer renderer, double x, double y) {
|
|
338 | 339 |
SelectionCADToolState actualState = _fsm.getState(); |
339 | 340 |
String status = actualState.getName(); |
340 | 341 |
VectorialLayerEdited vle = getVLE(); |
... | ... | |
352 | 353 |
elShape.lineTo(x, y); |
353 | 354 |
elShape.lineTo(firstPoint.getX(), y); |
354 | 355 |
elShape.lineTo(firstPoint.getX(), firstPoint.getY()); |
355 |
DrawOperationContext doc=new DrawOperationContext(); |
|
356 |
doc.setGraphics((Graphics2D)g); |
|
357 |
doc.setViewPort(vp); |
|
358 |
doc.setSymbol(DefaultCADTool.geometrySelectSymbol); |
|
359 |
try { |
|
360 |
createCurve(elShape).cloneGeometry().invokeOperation(Draw.CODE,doc); |
|
361 |
} catch (GeometryOperationNotSupportedException e) { |
|
362 |
e.printStackTrace(); |
|
363 |
} catch (GeometryOperationException e) { |
|
364 |
e.printStackTrace(); |
|
365 |
} |
|
366 |
// geomFactory.createPolyline2D(elShape).draw((Graphics2D) g, |
|
367 |
// vp, |
|
368 |
// DefaultCADTool.geometrySelectSymbol); |
|
356 |
|
|
357 |
Curve curve = createCurve(elShape); |
|
358 |
renderer.draw(curve, mapControlManager.getGeometrySelectionSymbol()); |
|
359 |
|
|
369 | 360 |
Image img = vle.getSelectionImage(); |
370 |
g.drawImage(img, 0, 0, null);
|
|
371 |
return;
|
|
361 |
renderer.drawImage(img, 0, 0);
|
|
362 |
return;
|
|
372 | 363 |
}else if (status.equals("Selection.WithHandlers")) { |
373 | 364 |
// Movemos los handlers que hemos seleccionado |
374 | 365 |
// previamente dentro del m?todo select() |
... | ... | |
384 | 375 |
// redibujamos la nueva geometr?a. |
385 | 376 |
for (int i = 0; i < rowselectedHandlers.size(); i++) { |
386 | 377 |
Feature feature=(Feature)rowselectedHandlers.get(i); |
387 |
// IRowEdited rowEd = (IRowEdited) rowselectedHandlers.get(i); |
|
388 |
// IGeometry geom = ((IFeature) rowEd.getLinkedRow()) |
|
389 |
// .getGeometry().cloneGeometry(); |
|
378 |
|
|
390 | 379 |
Geometry geom=(feature.getDefaultGeometry()).cloneGeometry(); |
391 |
g.setColor(Color.gray); |
|
392 |
DrawOperationContext doc=new DrawOperationContext(); |
|
393 |
doc.setGraphics((Graphics2D)g); |
|
394 |
doc.setViewPort(vp); |
|
395 |
doc.setSymbol(DefaultCADTool.axisReferencesSymbol); |
|
396 |
try { |
|
397 |
geom.invokeOperation(Draw.CODE,doc); |
|
398 |
} catch (GeometryOperationNotSupportedException e) { |
|
399 |
e.printStackTrace(); |
|
400 |
} catch (GeometryOperationException e) { |
|
401 |
e.printStackTrace(); |
|
402 |
} |
|
380 |
renderer.setColor(Color.gray); |
|
381 |
renderer.draw(geom, mapControlManager.getAxisReferenceSymbol()); |
|
403 | 382 |
} |
404 | 383 |
for (int k = 0; k < selectedHandler.size(); k++) { |
405 | 384 |
Handler h = (Handler)selectedHandler.get(k); |
... | ... | |
411 | 390 |
return; |
412 | 391 |
} |
413 | 392 |
try{ |
414 |
Image imgSel = vle.getSelectionImage(); |
|
415 |
if (imgSel!=null) { |
|
416 |
g.drawImage(imgSel, 0, 0, null); |
|
417 |
} |
|
418 |
Image imgHand = vle.getHandlersImage(); |
|
419 |
if (imgHand!=null) { |
|
420 |
g.drawImage(imgHand, 0, 0, null); |
|
421 |
} |
|
393 |
Image imgSel = vle.getSelectionImage(); |
|
394 |
renderer.drawImage(imgSel, 0, 0); |
|
395 |
|
|
396 |
Image imgHand = vle.getHandlersImage(); |
|
397 |
renderer.drawImage(imgHand, 0, 0); |
|
422 | 398 |
}catch (Exception e) { |
423 | 399 |
} |
424 | 400 |
} |
... | ... | |
434 | 410 |
*/ |
435 | 411 |
public void addOption(String s) { |
436 | 412 |
SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
437 |
.getPreviousState();
|
|
413 |
.getPreviousState(); |
|
438 | 414 |
String status = actualState.getName(); |
439 | 415 |
System.out.println("PREVIOUSSTATE =" + status); // + "ESTADO ACTUAL: " + |
440 | 416 |
// _fsm.getState()); |
... | ... | |
464 | 440 |
public String getStatus() { |
465 | 441 |
try { |
466 | 442 |
SelectionCADToolState actualState = (SelectionCADToolState) _fsm |
467 |
.getPreviousState();
|
|
443 |
.getPreviousState(); |
|
468 | 444 |
String status = actualState.getName(); |
469 | 445 |
|
470 | 446 |
return status; |
... | ... | |
487 | 463 |
|
488 | 464 |
public boolean selectFeatures(double x, double y, InputEvent event) { |
489 | 465 |
SelectionCADToolState actualState = _fsm |
490 |
.getState();
|
|
466 |
.getState(); |
|
491 | 467 |
|
492 | 468 |
String status = actualState.getName(); |
493 | 469 |
VectorialLayerEdited vle = getVLE(); |
... | ... | |
512 | 488 |
try { |
513 | 489 |
selection = (FeatureSet)vle.getFeatureStore().getSelection(); |
514 | 490 |
|
515 |
// ArrayList selectedRow = vle.getSelectedRow(); |
|
516 |
long countSel=selection.getSize(); |
|
517 |
if (countSel > 0) { |
|
518 |
nextState = "Selection.WithSelectedFeatures"; |
|
519 |
return true; |
|
520 |
} else { |
|
521 |
{ |
|
522 |
nextState = "Selection.SecondPoint"; |
|
491 |
// ArrayList selectedRow = vle.getSelectedRow(); |
|
492 |
long countSel=selection.getSize(); |
|
493 |
if (countSel > 0) { |
|
494 |
nextState = "Selection.WithSelectedFeatures"; |
|
523 | 495 |
return true; |
496 |
} else { |
|
497 |
{ |
|
498 |
nextState = "Selection.SecondPoint"; |
|
499 |
return true; |
|
500 |
} |
|
524 | 501 |
} |
525 |
} |
|
526 | 502 |
} catch (ReadException e) { |
527 | 503 |
e.printStackTrace(); |
528 | 504 |
return false; |
... | ... | |
552 | 528 |
PluginServices.getMDIManager().setWaitCursor(); |
553 | 529 |
|
554 | 530 |
double tam = getCadToolAdapter().getMapControl().getViewPort() |
555 |
.toMapDistance(MapControl.tolerance);
|
|
531 |
.toMapDistance(mapControlManager.getTolerance());
|
|
556 | 532 |
|
557 | 533 |
Handler[] handlers = null; |
558 | 534 |
rowselectedHandlers.clear(); |
... | ... | |
566 | 542 |
// |
567 | 543 |
// IFeature fea = (IFeature) rowEd.getLinkedRow(); |
568 | 544 |
handlers = (feature.getDefaultGeometry()) |
569 |
.getHandlers(Geometry.SELECTHANDLER);
|
|
545 |
.getHandlers(Geometry.SELECTHANDLER); |
|
570 | 546 |
// y miramos los handlers de cada entidad seleccionada |
571 | 547 |
double min = tam; |
572 | 548 |
// int hSel = -1; |
... | ... | |
611 | 587 |
}else{ |
612 | 588 |
this.type = type; |
613 | 589 |
} |
614 |
// pointsPolygon.clear(); |
|
590 |
// pointsPolygon.clear();
|
|
615 | 591 |
} |
616 | 592 |
|
617 | 593 |
public String toString() { |
Also available in: Unified diff