Revision 1763 branches/gvSIG_CAD_Layout_version/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/Layout.java
Layout.java | ||
---|---|---|
55 | 55 |
import com.iver.cit.gvsig.fmap.DriverException; |
56 | 56 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
57 | 57 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
58 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
58 | 59 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
59 | 60 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
60 | 61 |
import com.iver.cit.gvsig.gui.cad.CADToolAdapter; |
... | ... | |
68 | 69 |
import com.iver.cit.gvsig.gui.cad.tools.PolyLineCadTool; |
69 | 70 |
import com.iver.cit.gvsig.gui.cad.tools.PolygonCadTool; |
70 | 71 |
import com.iver.cit.gvsig.gui.cad.tools.RectangleCadTool; |
72 |
import com.iver.cit.gvsig.gui.cad.tools.SelectionCadTool; |
|
71 | 73 |
import com.iver.cit.gvsig.gui.layout.dialogs.FConfigLayoutDialog; |
72 | 74 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrame; |
73 | 75 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics; |
... | ... | |
101 | 103 |
import java.awt.Rectangle; |
102 | 104 |
import java.awt.Toolkit; |
103 | 105 |
import java.awt.event.ActionEvent; |
106 |
import java.awt.event.ActionListener; |
|
104 | 107 |
import java.awt.event.KeyEvent; |
105 | 108 |
import java.awt.geom.AffineTransform; |
106 | 109 |
import java.awt.geom.Point2D; |
... | ... | |
111 | 114 |
import java.awt.print.Printable; |
112 | 115 |
import java.awt.print.PrinterException; |
113 | 116 |
import java.awt.print.PrinterJob; |
117 |
import java.io.IOException; |
|
114 | 118 |
|
115 | 119 |
import java.util.ArrayList; |
116 | 120 |
import java.util.BitSet; |
... | ... | |
134 | 138 |
import javax.swing.AbstractAction; |
135 | 139 |
import javax.swing.Action; |
136 | 140 |
import javax.swing.ImageIcon; |
141 |
import javax.swing.JMenuItem; |
|
137 | 142 |
import javax.swing.JPanel; |
143 |
import javax.swing.JPopupMenu; |
|
138 | 144 |
import javax.swing.KeyStroke; |
139 | 145 |
|
140 | 146 |
|
... | ... | |
238 | 244 |
private boolean isDrawCuadricula = true; |
239 | 245 |
private Doc doc = null; |
240 | 246 |
private PrintRequestAttributeSet att = null; |
241 |
private boolean cadtool = false; |
|
247 |
//private boolean cadtool = false;
|
|
242 | 248 |
private HashMap namesCadTools = new HashMap(); |
243 |
private LayoutCADToolAdapter cadToolAdapter; |
|
244 |
private HashMap namesMapTools = new HashMap(); |
|
245 |
private Stack toolStack = new Stack(); |
|
246 |
|
|
249 |
///private LayoutCADToolAdapter cadToolAdapter; |
|
250 |
//private HashMap namesMapTools = new HashMap(); |
|
251 |
//private Stack toolStack = new Stack(); |
|
252 |
private FFrameGraphics fframegraphics; |
|
253 |
private LayoutAdapter ladapter; |
|
254 |
// Menu contextual |
|
255 |
private JPopupMenu popup = new JPopupMenu(); |
|
247 | 256 |
/** |
248 | 257 |
* Creates a new Layout object. |
249 | 258 |
*/ |
250 | 259 |
public Layout() { |
251 | 260 |
this.setLayout(null); |
252 |
cadToolAdapter=new LayoutCADToolAdapter(this); |
|
253 |
FFrameGraphics fg=new FFrameGraphics(cadToolAdapter); |
|
254 |
addFFrame(fg,true); |
|
261 |
///cadToolAdapter=new LayoutCADToolAdapter(this); |
|
262 |
|
|
263 |
ladapter=new LayoutAdapter(this); |
|
264 |
fframegraphics=new FFrameGraphics(ladapter.getCADToolAdapter()); |
|
265 |
///addFFrame(fg,true); |
|
255 | 266 |
events = new EventsHandler(this); |
256 | 267 |
layoutPaint = new FLayoutDraw(this); |
257 |
getCadToolAdapter().setEditableFeatureSource(new LayoutEditableFeature(this),new FBitSet()); |
|
268 |
FBitSet selection=new FBitSet(); |
|
269 |
getCadToolAdapter().setEditableFeatureSource(new LayoutEditableFeature(this,selection),selection); |
|
258 | 270 |
try { |
259 | 271 |
getCadToolAdapter().getEditableFeatureSource().startEdition(); |
260 | 272 |
} catch (EditionException e) { |
... | ... | |
456 | 468 |
//Herramienta de CAD de a?adir pol?gono. |
457 | 469 |
PolygonCadTool polygonCADTool = new PolygonCadTool(); |
458 | 470 |
addCadTool("polygon", polygonCADTool); |
471 |
|
|
472 |
SelectionCadTool selectionCADTool=new SelectionCadTool(); |
|
473 |
addCadTool("selection",selectionCADTool); |
|
459 | 474 |
} |
460 | 475 |
|
461 | 476 |
/** |
... | ... | |
467 | 482 |
public void actionPerformed(ActionEvent e) { |
468 | 483 |
for (int i = getFFrames().size() - 1; i >= 0; i--) { |
469 | 484 |
IFFrame fframe = (IFFrame) getFFrames().get(i); |
470 |
|
|
485 |
getCadToolAdapter().getEditableFeatureSource().startComplexGeometry(); |
|
471 | 486 |
if (fframe.getSelected() != FFrame.NOSELECT) { |
472 |
getFFrames().remove(i);
|
|
487 |
((LayoutEditableFeature)getCadToolAdapter().getEditableFeatureSource()).removeFFrame(i);
|
|
473 | 488 |
} |
474 | 489 |
} |
475 |
|
|
490 |
try { |
|
491 |
getCadToolAdapter().getEditableFeatureSource().endComplexGeometry(); |
|
492 |
} catch (IOException e1) { |
|
493 |
e1.printStackTrace(); |
|
494 |
} catch (DriverIOException e1) { |
|
495 |
e1.printStackTrace(); |
|
496 |
} |
|
497 |
getCadToolAdapter().keyPressed("eliminar"); |
|
498 |
|
|
476 | 499 |
refresh(); |
477 | 500 |
} |
478 | 501 |
}; |
... | ... | |
508 | 531 |
g.drawImage(img, 0, 0, this); |
509 | 532 |
|
510 | 533 |
g.setClip(rClip); |
511 |
cadToolAdapter.drawGrid(g);
|
|
534 |
ladapter.getCADToolAdapter().drawGrid(g);
|
|
512 | 535 |
layoutPaint.drawRuler((Graphics2D) g, Color.black); |
513 | 536 |
g.setColor(Color.black); |
514 | 537 |
g.setXORMode(Color.white); |
... | ... | |
527 | 550 |
g.drawImage(img, 0, 0, this); |
528 | 551 |
|
529 | 552 |
g.setClip(rClip); |
530 |
cadToolAdapter.drawGrid(g);
|
|
553 |
ladapter.getCADToolAdapter().drawGrid(g);
|
|
531 | 554 |
layoutPaint.drawRuler((Graphics2D) g, Color.black); |
532 | 555 |
g.setColor(Color.black); |
533 | 556 |
g.setXORMode(Color.white); |
... | ... | |
594 | 617 |
} |
595 | 618 |
|
596 | 619 |
g.setClip(rClip); |
597 |
cadToolAdapter.drawGrid(g);
|
|
620 |
ladapter.getCADToolAdapter().drawGrid(g);
|
|
598 | 621 |
layoutPaint.drawRuler((Graphics2D) g, Color.black); |
599 | 622 |
break; |
600 | 623 |
|
... | ... | |
642 | 665 |
} |
643 | 666 |
|
644 | 667 |
g.setClip(rClip); |
645 |
cadToolAdapter.drawGrid(g);
|
|
668 |
ladapter.getCADToolAdapter().drawGrid(g);
|
|
646 | 669 |
layoutPaint.drawRuler((Graphics2D) g, Color.black); |
647 | 670 |
|
648 | 671 |
break; |
649 | 672 |
|
650 | 673 |
case GRAPHICS: |
674 |
Graphics gima = img.getGraphics(); |
|
675 |
try { |
|
676 |
getFFrameGraphics().draw((Graphics2D)gima,getAT(),getRect(),null); |
|
677 |
} catch (DriverException e1) { |
|
678 |
e1.printStackTrace(); |
|
679 |
} |
|
680 |
setStatus(ACTUALIZADO); |
|
681 |
repaint(); |
|
651 | 682 |
break; |
652 | 683 |
|
653 | 684 |
case DESACTUALIZADO: |
... | ... | |
668 | 699 |
} catch (DriverException e) { |
669 | 700 |
e.printStackTrace(); |
670 | 701 |
} |
671 |
|
|
672 |
g.setClip(rClip); |
|
702 |
ladapter.getCADToolAdapter().drawGrid(gimag); |
|
703 |
//g.setClip(rClip);
|
|
673 | 704 |
layoutPaint.drawRectangle((Graphics2D) g); |
674 |
|
|
705 |
//cadToolAdapter.drawGrid(g); |
|
675 | 706 |
g.drawImage(img, 0, 0, this); |
676 | 707 |
g.setClip(rClip); |
677 |
cadToolAdapter.drawGrid(g); |
|
678 | 708 |
|
709 |
|
|
679 | 710 |
layoutPaint.drawHandlers((Graphics2D) g, Color.black); |
680 | 711 |
layoutPaint.drawRuler((Graphics2D) g, Color.black); |
681 | 712 |
if (getTool()==GRAPHICS){ |
682 |
cadToolAdapter.drawCursor(g); |
|
713 |
ladapter.getCADToolAdapter().drawCursor(g); |
|
714 |
ladapter.getCADToolAdapter().paintComponent(g); |
|
683 | 715 |
} |
684 | 716 |
|
685 | 717 |
break; |
... | ... | |
692 | 724 |
g.setClip(rClip); |
693 | 725 |
layoutPaint.drawHandlers((Graphics2D) g, Color.black); |
694 | 726 |
layoutPaint.drawRuler((Graphics2D) g, Color.black); |
695 |
cadToolAdapter.drawGrid(g); |
|
727 |
//cadToolAdapter.drawGrid(g);
|
|
696 | 728 |
if (getTool()==GRAPHICS){ |
697 |
cadToolAdapter.drawCursor(g); |
|
729 |
ladapter.getCADToolAdapter().drawCursor(g); |
|
730 |
ladapter.getCADToolAdapter().paintComponent(g); |
|
698 | 731 |
} |
699 |
cadToolAdapter.paintComponent(g); |
|
732 |
|
|
700 | 733 |
|
701 | 734 |
} |
702 | 735 |
} |
... | ... | |
709 | 742 |
* a?adimos y false si lo que se pretende es que no se |
710 | 743 |
* deseleccionen lo que ya est?n seleccionados. |
711 | 744 |
*/ |
712 |
public void addFFrame(IFFrame frame, boolean clearSelection) { |
|
745 |
public int addFFrame(IFFrame frame, boolean clearSelection) { |
|
746 |
|
|
713 | 747 |
if (clearSelection) { |
714 | 748 |
for (int i = getFFrames().size() - 1; i >= 0; i--) { |
715 | 749 |
IFFrame fframe1 = (IFFrame) getFFrames().get(i); |
... | ... | |
733 | 767 |
frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString())); |
734 | 768 |
getFFrames().add(frame); |
735 | 769 |
frame.setSelected(true); |
770 |
return getFFrames().size()-1; |
|
736 | 771 |
} |
737 | 772 |
|
738 | 773 |
/** |
... | ... | |
982 | 1017 |
break; |
983 | 1018 |
|
984 | 1019 |
case GRAPHICS: |
985 |
fframedialog = new FFrameGraphicsDialog(this, |
|
1020 |
/* fframedialog = new FFrameGraphicsDialog(this,
|
|
986 | 1021 |
(FFrameGraphics) fframe); |
987 | 1022 |
|
1023 |
*/ |
|
988 | 1024 |
break; |
989 | 1025 |
|
990 | 1026 |
default: |
... | ... | |
1246 | 1282 |
} |
1247 | 1283 |
|
1248 | 1284 |
/** |
1249 |
* @see com.iver.cit.gvsig.fmap.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D) |
|
1250 |
*/ |
|
1251 |
public void extentChanged(Rectangle2D newExtent) { |
|
1252 |
} |
|
1253 |
|
|
1254 |
/** |
|
1255 | 1285 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel() |
1256 | 1286 |
*/ |
1257 | 1287 |
public Object getViewModel() { |
... | ... | |
1288 | 1318 |
*/ |
1289 | 1319 |
public void viewClosed() { |
1290 | 1320 |
try { |
1291 |
cadToolAdapter.getEditableFeatureSource().stopEdition();
|
|
1321 |
ladapter.getCADToolAdapter().getEditableFeatureSource().stopEdition();
|
|
1292 | 1322 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1",""); |
1293 | 1323 |
} catch (EditionException e) { |
1294 | 1324 |
e.printStackTrace(); |
... | ... | |
1323 | 1353 |
/** |
1324 | 1354 |
* DOCUMENT ME! |
1325 | 1355 |
* |
1326 |
* @return DOCUMENT ME! |
|
1327 |
*/ |
|
1328 |
public CadTool getCadTool() { |
|
1329 |
return cadToolAdapter.getCadTool(); |
|
1330 |
} |
|
1331 |
|
|
1332 |
/** |
|
1333 |
* DOCUMENT ME! |
|
1334 |
* |
|
1335 | 1356 |
* @param name DOCUMENT ME! |
1336 | 1357 |
* @param c DOCUMENT ME! |
1337 | 1358 |
*/ |
... | ... | |
1346 | 1367 |
*/ |
1347 | 1368 |
public void setCadTool(String text) { |
1348 | 1369 |
CadTool ct = (CadTool) namesCadTools.get(text); |
1349 |
|
|
1350 | 1370 |
if (ct == null) { |
1351 | 1371 |
throw new RuntimeException("No such cad tool"); |
1352 | 1372 |
} |
1353 |
|
|
1354 |
cadToolAdapter.setCadTool(ct); |
|
1355 |
cadtool = true; |
|
1373 |
ladapter.getCADToolAdapter().setCadTool(ct); |
|
1374 |
//cadtool = true; |
|
1356 | 1375 |
setTool(GRAPHICS); |
1357 |
|
|
1358 | 1376 |
//clearMouseImage(); |
1359 | 1377 |
} |
1360 | 1378 |
|
... | ... | |
1364 | 1382 |
* @return DOCUMENT ME! |
1365 | 1383 |
*/ |
1366 | 1384 |
public CADToolAdapter getCadToolAdapter() { |
1367 |
return (CADToolAdapter)cadToolAdapter;
|
|
1385 |
return (CADToolAdapter)ladapter.getCADToolAdapter();
|
|
1368 | 1386 |
} |
1369 | 1387 |
public FFrameGraphics getFFrameGraphics(){ |
1370 |
return (FFrameGraphics)getFFrames().get(0);
|
|
1388 |
return fframegraphics;
|
|
1371 | 1389 |
} |
1390 |
public void undo(){ |
|
1391 |
|
|
1392 |
try { |
|
1393 |
getCadToolAdapter().getEditableFeatureSource().undo(); |
|
1394 |
} catch (DriverIOException e) { |
|
1395 |
e.printStackTrace(); |
|
1396 |
} catch (IOException e) { |
|
1397 |
e.printStackTrace(); |
|
1398 |
} |
|
1399 |
} |
|
1400 |
public void redo(){ |
|
1401 |
try { |
|
1402 |
getCadToolAdapter().getEditableFeatureSource().redo(); |
|
1403 |
} catch (DriverIOException e) { |
|
1404 |
e.printStackTrace(); |
|
1405 |
} catch (IOException e) { |
|
1406 |
e.printStackTrace(); |
|
1407 |
} |
|
1408 |
} |
|
1409 |
public void addMenuEntry(String text, String actionCommand){ |
|
1410 |
JMenuItem menu = new JMenuItem(text); |
|
1411 |
menu.setActionCommand(actionCommand); |
|
1412 |
menu.setEnabled(true); |
|
1413 |
menu.setVisible(true); |
|
1414 |
menu.addActionListener(new ActionListener() { |
|
1415 |
public void actionPerformed(ActionEvent e) { |
|
1416 |
getCadToolAdapter().transition(e.getActionCommand()); |
|
1417 |
refresh(); |
|
1418 |
} |
|
1419 |
}); |
|
1420 |
|
|
1421 |
popup.add(menu); |
|
1422 |
} |
|
1423 |
public void clearMenu(){ |
|
1424 |
popup.removeAll(); |
|
1425 |
} |
|
1426 |
public JPopupMenu getPopup(){ |
|
1427 |
return popup; |
|
1428 |
} |
|
1372 | 1429 |
} |
Also available in: Unified diff