svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / LayoutKeyEvent.java @ 6880
History | View | Annotate | Download (3.59 KB)
1 | 6276 | caballero | package com.iver.cit.gvsig.gui.layout; |
---|---|---|---|
2 | |||
3 | import java.awt.KeyEventDispatcher; |
||
4 | import java.awt.event.KeyEvent; |
||
5 | import java.awt.geom.Rectangle2D; |
||
6 | |||
7 | 6740 | caballero | import javax.swing.JPanel; |
8 | 6393 | caballero | import javax.swing.JTextField; |
9 | 6276 | caballero | |
10 | import com.iver.andami.PluginServices; |
||
11 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
12 | 6276 | caballero | import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
13 | |||
14 | public class LayoutKeyEvent implements KeyEventDispatcher{ |
||
15 | private static IFFrame[] selectFFrames; |
||
16 | private int difX; |
||
17 | private int difY; |
||
18 | |||
19 | public boolean dispatchKeyEvent(KeyEvent e) { |
||
20 | 6880 | cesar | IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
21 | 6375 | caballero | |
22 | 6740 | caballero | if (e.getID() == KeyEvent.KEY_PRESSED || !(view instanceof Layout) || e.getSource().getClass()!=JPanel.class) |
23 | 6276 | caballero | return false; |
24 | 6375 | caballero | Layout layout=(Layout)view; |
25 | 6717 | caballero | if (!layout.isEditable())
|
26 | return false; |
||
27 | 6276 | caballero | IFFrame[] fframes = layout.getFFrameSelected();
|
28 | int dif = 10; |
||
29 | if (e.getModifiers() == KeyEvent.CTRL_MASK) { |
||
30 | switch (e.getKeyCode()) {
|
||
31 | 6740 | caballero | case KeyEvent.VK_C: |
32 | 6717 | caballero | if (fframes.length==0) |
33 | return false; |
||
34 | 6276 | caballero | selectFFrames = new IFFrame[fframes.length];
|
35 | for (int i = 0; i < fframes.length; i++) { |
||
36 | selectFFrames[i] = fframes[i].cloneFFrame(layout); |
||
37 | } |
||
38 | break;
|
||
39 | case KeyEvent.VK_X: |
||
40 | 6717 | caballero | if (fframes.length==0) |
41 | return false; |
||
42 | 6276 | caballero | selectFFrames = new IFFrame[fframes.length];
|
43 | for (int i = 0; i < fframes.length; i++) { |
||
44 | selectFFrames[i] = fframes[i].cloneFFrame(layout); |
||
45 | } |
||
46 | layout.delFFrameSelected(); |
||
47 | layout.refresh(); |
||
48 | break;
|
||
49 | case KeyEvent.VK_V: |
||
50 | IFFrame copyFFrame = null;
|
||
51 | layout.getEFS().startComplexCommand(); |
||
52 | for (int i = 0; i < selectFFrames.length; i++) { |
||
53 | copyFFrame = selectFFrames[i].cloneFFrame(layout); |
||
54 | if (i == 0) |
||
55 | layout.addFFrame(copyFFrame, true, true); |
||
56 | else
|
||
57 | layout.addFFrame(copyFFrame, false, true); |
||
58 | } |
||
59 | layout.getEFS().endComplexCommand( |
||
60 | PluginServices.getText(this, "paste_elements")); |
||
61 | layout.refresh(); |
||
62 | break;
|
||
63 | case KeyEvent.VK_Z: |
||
64 | layout.getEFS().undo(); |
||
65 | layout.updateFFrames(); |
||
66 | layout.refresh(); |
||
67 | PluginServices.getMainFrame().enableControls(); |
||
68 | break;
|
||
69 | case KeyEvent.VK_Y: |
||
70 | layout.getEFS().redo(); |
||
71 | layout.updateFFrames(); |
||
72 | layout.refresh(); |
||
73 | PluginServices.getMainFrame().enableControls(); |
||
74 | break;
|
||
75 | } |
||
76 | } else {
|
||
77 | switch (e.getKeyCode()) {
|
||
78 | case KeyEvent.VK_LEFT: |
||
79 | difX = difX - dif; |
||
80 | break;
|
||
81 | |||
82 | case KeyEvent.VK_RIGHT: |
||
83 | difX = difX + dif; |
||
84 | break;
|
||
85 | case KeyEvent.VK_UP: |
||
86 | difY = difY - dif; |
||
87 | break;
|
||
88 | case KeyEvent.VK_DOWN: |
||
89 | difY = difY + dif; |
||
90 | break;
|
||
91 | 6300 | caballero | case KeyEvent.VK_DELETE: |
92 | case KeyEvent.VK_BACK_SPACE: |
||
93 | layout.delFFrameSelected(); |
||
94 | layout.refresh(); |
||
95 | break;
|
||
96 | 6276 | caballero | } |
97 | if (e.getKeyCode()==KeyEvent.VK_LEFT || e.getKeyCode()==KeyEvent.VK_RIGHT || e.getKeyCode()==KeyEvent.VK_UP || e.getKeyCode()==KeyEvent.VK_DOWN) { |
||
98 | 6717 | caballero | if (fframes.length==0) |
99 | return false; |
||
100 | layout.getEFS().startComplexCommand(); |
||
101 | 6276 | caballero | for (int i = 0; i < fframes.length; i++) { |
102 | IFFrame fframeAux = fframes[i].cloneFFrame(layout); |
||
103 | Rectangle2D r = getRectMove(fframes[i]
|
||
104 | .getBoundingBox(layout.getAT()), difX, difY); |
||
105 | fframeAux.setBoundBox(FLayoutUtilities.toSheetRect(r, |
||
106 | layout.getAT())); |
||
107 | layout.getEFS().modifyFFrame(fframes[i], fframeAux); |
||
108 | } |
||
109 | layout.getEFS().endComplexCommand( |
||
110 | PluginServices.getText(this, "move_elements")); |
||
111 | layout.updateFFrames(); |
||
112 | layout.refresh(); |
||
113 | } |
||
114 | difX = 0;
|
||
115 | difY = 0;
|
||
116 | |||
117 | } |
||
118 | return true; |
||
119 | } |
||
120 | private Rectangle2D getRectMove(Rectangle2D r,int difX,int difY) { |
||
121 | Rectangle2D rectMove=new Rectangle2D.Double(); |
||
122 | rectMove.setRect(r.getX()+difX,r.getY()+difY,r.getWidth(),r.getHeight()); |
||
123 | return rectMove;
|
||
124 | } |
||
125 | 6375 | caballero | |
126 | 6276 | caballero | } |