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