root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / LayoutKeyEvent.java @ 24962
History | View | Annotate | Download (5.01 KB)
1 | 7304 | caballero | package com.iver.cit.gvsig.project.documents.layout; |
---|---|---|---|
2 | |||
3 | import java.awt.KeyEventDispatcher; |
||
4 | import java.awt.event.KeyEvent; |
||
5 | import java.awt.geom.Rectangle2D; |
||
6 | |||
7 | 24962 | vcaballero | import org.gvsig.tools.undo.RedoException; |
8 | import org.gvsig.tools.undo.UndoException; |
||
9 | |||
10 | 7304 | caballero | import com.iver.andami.PluginServices; |
11 | import com.iver.andami.ui.mdiManager.IWindow; |
||
12 | import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
||
13 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
14 | 7304 | caballero | |
15 | public class LayoutKeyEvent implements KeyEventDispatcher{ |
||
16 | 9807 | caballero | private static IFFrame[] selectFFrames=new IFFrame[0]; |
17 | 7304 | caballero | private int difX; |
18 | private int difY; |
||
19 | |||
20 | 9807 | caballero | public static boolean copy(Layout layout) { |
21 | IFFrame[] fframes = layout.getLayoutContext().getFFrameSelected();
|
||
22 | if (fframes.length==0) |
||
23 | return false; |
||
24 | selectFFrames = new IFFrame[fframes.length];
|
||
25 | for (int i = 0; i < fframes.length; i++) { |
||
26 | selectFFrames[i] = fframes[i].cloneFFrame(layout); |
||
27 | } |
||
28 | return true; |
||
29 | } |
||
30 | public static boolean cut(Layout layout) { |
||
31 | IFFrame[] fframes = layout.getLayoutContext().getFFrameSelected();
|
||
32 | if (fframes.length==0) |
||
33 | return false; |
||
34 | selectFFrames = new IFFrame[fframes.length];
|
||
35 | for (int i = 0; i < fframes.length; i++) { |
||
36 | selectFFrames[i] = fframes[i].cloneFFrame(layout); |
||
37 | } |
||
38 | layout.getLayoutContext().delFFrameSelected(); |
||
39 | layout.getLayoutContext().callLayoutDrawListeners(); |
||
40 | return true; |
||
41 | } |
||
42 | public static boolean paste(Layout layout) { |
||
43 | IFFrame copyFFrame = null;
|
||
44 | 24962 | vcaballero | layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(layout, "paste_elements"));
|
45 | 9807 | caballero | for (int i = 0; i < selectFFrames.length; i++) { |
46 | copyFFrame = selectFFrames[i].cloneFFrame(layout); |
||
47 | if (i == 0) |
||
48 | layout.getLayoutContext().addFFrame(copyFFrame, true, true); |
||
49 | else
|
||
50 | layout.getLayoutContext().addFFrame(copyFFrame, false, true); |
||
51 | } |
||
52 | 24962 | vcaballero | layout.getLayoutContext().getFrameCommandsRecord().endComplex(); |
53 | 9807 | caballero | layout.getLayoutContext().callLayoutDrawListeners(); |
54 | return true; |
||
55 | } |
||
56 | public static boolean undo(Layout layout) { |
||
57 | 24962 | vcaballero | LayoutContext lcontext=layout.getLayoutContext(); |
58 | try {
|
||
59 | lcontext.getFrameCommandsRecord().undo(); |
||
60 | } catch (UndoException e) {
|
||
61 | e.printStackTrace(); |
||
62 | } |
||
63 | 9807 | caballero | layout.getLayoutContext().updateFFrames(); |
64 | layout.getLayoutContext().callLayoutDrawListeners(); |
||
65 | PluginServices.getMainFrame().enableControls(); |
||
66 | return true; |
||
67 | } |
||
68 | public static boolean redo(Layout layout) { |
||
69 | 24962 | vcaballero | LayoutContext lcontext=layout.getLayoutContext(); |
70 | try {
|
||
71 | lcontext.getFrameCommandsRecord().redo(); |
||
72 | } catch (RedoException e) {
|
||
73 | e.printStackTrace(); |
||
74 | } |
||
75 | lcontext.updateFFrames(); |
||
76 | lcontext.callLayoutDrawListeners(); |
||
77 | 9807 | caballero | PluginServices.getMainFrame().enableControls(); |
78 | return true; |
||
79 | } |
||
80 | |||
81 | public boolean dispatchKeyEvent(KeyEvent e) { |
||
82 | 7304 | caballero | IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
83 | |||
84 | 9807 | caballero | if (e.getID() == KeyEvent.KEY_PRESSED || !(view instanceof Layout) || !(e.getSource() instanceof LayoutControl)) |
85 | 7304 | caballero | return false; |
86 | Layout layout=(Layout)view; |
||
87 | 9392 | caballero | if (!layout.getLayoutContext().isEditable())
|
88 | 7304 | caballero | return false; |
89 | 9392 | caballero | IFFrame[] fframes = layout.getLayoutContext().getFFrameSelected();
|
90 | 7304 | caballero | int dif = 10; |
91 | if (e.getModifiers() == KeyEvent.CTRL_MASK) { |
||
92 | switch (e.getKeyCode()) {
|
||
93 | case KeyEvent.VK_C: |
||
94 | 9807 | caballero | copy(layout); |
95 | 7304 | caballero | break;
|
96 | case KeyEvent.VK_X: |
||
97 | 9807 | caballero | cut(layout); |
98 | 7304 | caballero | break;
|
99 | case KeyEvent.VK_V: |
||
100 | 9807 | caballero | paste(layout); |
101 | 7304 | caballero | break;
|
102 | case KeyEvent.VK_Z: |
||
103 | 9807 | caballero | undo(layout); |
104 | 7304 | caballero | break;
|
105 | case KeyEvent.VK_Y: |
||
106 | 9807 | caballero | redo(layout); |
107 | 7304 | caballero | break;
|
108 | } |
||
109 | } else {
|
||
110 | switch (e.getKeyCode()) {
|
||
111 | case KeyEvent.VK_LEFT: |
||
112 | difX = difX - dif; |
||
113 | break;
|
||
114 | |||
115 | case KeyEvent.VK_RIGHT: |
||
116 | difX = difX + dif; |
||
117 | break;
|
||
118 | case KeyEvent.VK_UP: |
||
119 | difY = difY - dif; |
||
120 | break;
|
||
121 | case KeyEvent.VK_DOWN: |
||
122 | difY = difY + dif; |
||
123 | break;
|
||
124 | case KeyEvent.VK_DELETE: |
||
125 | case KeyEvent.VK_BACK_SPACE: |
||
126 | 9392 | caballero | layout.getLayoutContext().delFFrameSelected(); |
127 | layout.getLayoutControl().refresh(); |
||
128 | 7304 | caballero | break;
|
129 | } |
||
130 | if (e.getKeyCode()==KeyEvent.VK_LEFT || e.getKeyCode()==KeyEvent.VK_RIGHT || e.getKeyCode()==KeyEvent.VK_UP || e.getKeyCode()==KeyEvent.VK_DOWN) { |
||
131 | if (fframes.length==0) |
||
132 | return false; |
||
133 | 24962 | vcaballero | layout.getLayoutContext().getFrameCommandsRecord().startComplex(PluginServices.getText(this, "move_elements")); |
134 | 7304 | caballero | for (int i = 0; i < fframes.length; i++) { |
135 | IFFrame fframeAux = fframes[i].cloneFFrame(layout); |
||
136 | Rectangle2D r = getRectMove(fframes[i]
|
||
137 | 9392 | caballero | .getBoundingBox(layout.getLayoutControl().getAT()), difX, difY); |
138 | 7304 | caballero | fframeAux.setBoundBox(FLayoutUtilities.toSheetRect(r, |
139 | 9392 | caballero | layout.getLayoutControl().getAT())); |
140 | 21358 | vcaballero | layout.getLayoutContext().getFrameCommandsRecord().update(fframes[i], fframeAux); |
141 | 7304 | caballero | } |
142 | 24962 | vcaballero | layout.getLayoutContext().getFrameCommandsRecord().endComplex(); |
143 | 9392 | caballero | layout.getLayoutContext().updateFFrames(); |
144 | layout.getLayoutControl().refresh(); |
||
145 | 7304 | caballero | } |
146 | difX = 0;
|
||
147 | difY = 0;
|
||
148 | |||
149 | } |
||
150 | return true; |
||
151 | } |
||
152 | private Rectangle2D getRectMove(Rectangle2D r,int difX,int difY) { |
||
153 | Rectangle2D rectMove=new Rectangle2D.Double(); |
||
154 | rectMove.setRect(r.getX()+difX,r.getY()+difY,r.getWidth(),r.getHeight()); |
||
155 | return rectMove;
|
||
156 | } |
||
157 | 9807 | caballero | public static boolean hasSelection() { |
158 | return selectFFrames.length>0; |
||
159 | } |
||
160 | 7304 | caballero | |
161 | } |