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