svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / LayoutKeyEvent.java @ 6880
History | View | Annotate | Download (3.59 KB)
1 |
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 |
import javax.swing.JPanel; |
8 |
import javax.swing.JTextField; |
9 |
|
10 |
import com.iver.andami.PluginServices; |
11 |
import com.iver.andami.ui.mdiManager.IWindow; |
12 |
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 |
IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
21 |
|
22 |
if (e.getID() == KeyEvent.KEY_PRESSED || !(view instanceof Layout) || e.getSource().getClass()!=JPanel.class) |
23 |
return false; |
24 |
Layout layout=(Layout)view; |
25 |
if (!layout.isEditable())
|
26 |
return false; |
27 |
IFFrame[] fframes = layout.getFFrameSelected();
|
28 |
int dif = 10; |
29 |
if (e.getModifiers() == KeyEvent.CTRL_MASK) { |
30 |
switch (e.getKeyCode()) {
|
31 |
case KeyEvent.VK_C: |
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 |
break;
|
39 |
case KeyEvent.VK_X: |
40 |
if (fframes.length==0) |
41 |
return false; |
42 |
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 |
case KeyEvent.VK_DELETE: |
92 |
case KeyEvent.VK_BACK_SPACE: |
93 |
layout.delFFrameSelected(); |
94 |
layout.refresh(); |
95 |
break;
|
96 |
} |
97 |
if (e.getKeyCode()==KeyEvent.VK_LEFT || e.getKeyCode()==KeyEvent.VK_RIGHT || e.getKeyCode()==KeyEvent.VK_UP || e.getKeyCode()==KeyEvent.VK_DOWN) { |
98 |
if (fframes.length==0) |
99 |
return false; |
100 |
layout.getEFS().startComplexCommand(); |
101 |
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 |
|
126 |
} |