gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.swing / org.gvsig.vectorediting.swing.impl / src / main / java / org / gvsig / vectorediting / swing / impl / EditingCompoundBehavior.java @ 79
History | View | Annotate | Download (5.55 KB)
1 |
package org.gvsig.vectorediting.swing.impl; |
---|---|
2 |
|
3 |
import java.awt.Image; |
4 |
import java.awt.event.MouseEvent; |
5 |
import java.awt.event.MouseWheelEvent; |
6 |
|
7 |
import org.gvsig.fmap.mapcontrol.MapControl; |
8 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
9 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
10 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
11 |
import org.gvsig.fmap.mapcontrol.tools.PointSelectionListener; |
12 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
13 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.IBehavior; |
14 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
15 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseWheelBehavior; |
16 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
17 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
18 |
|
19 |
public class EditingCompoundBehavior extends CompoundBehavior { |
20 |
|
21 |
private enum Mode { |
22 |
EDITING, SELECTION |
23 |
}; |
24 |
|
25 |
private Mode mode = Mode.EDITING;
|
26 |
private IBehavior editing;
|
27 |
private IBehavior selection;
|
28 |
private IBehavior zoom;
|
29 |
|
30 |
public final static int EDITING_INDEX = 0; |
31 |
public final static int SELECTION_INDEX = 1; |
32 |
|
33 |
public EditingCompoundBehavior(IBehavior editing) {
|
34 |
super(new Behavior[0]); |
35 |
this.editing = editing;
|
36 |
|
37 |
this.selection = null; |
38 |
this.zoom = new MouseWheelBehavior(); |
39 |
} |
40 |
|
41 |
public void addMapBehavior(Behavior mt, boolean draw) { |
42 |
if (mt instanceof MouseWheelBehavior) { |
43 |
return;
|
44 |
} |
45 |
throw new UnsupportedOperationException(); |
46 |
} |
47 |
|
48 |
public void removeMapBehavior(Behavior mt) { |
49 |
throw new UnsupportedOperationException(); |
50 |
} |
51 |
|
52 |
public boolean containsBehavior(Behavior mt) { |
53 |
return (mt == this.editing || mt == this.selection); |
54 |
} |
55 |
|
56 |
public Behavior getBehavior(int index) { |
57 |
switch (index) {
|
58 |
case EDITING_INDEX:
|
59 |
return (Behavior) this.editing; |
60 |
case SELECTION_INDEX:
|
61 |
return (Behavior) this.selection; |
62 |
default:
|
63 |
throw new IndexOutOfBoundsException(); |
64 |
} |
65 |
} |
66 |
|
67 |
public boolean isDrawnBehavior(int index) { |
68 |
switch (mode) {
|
69 |
case EDITING:
|
70 |
return index == EDITING_INDEX;
|
71 |
case SELECTION:
|
72 |
return index == SELECTION_INDEX;
|
73 |
default:
|
74 |
return false; |
75 |
} |
76 |
} |
77 |
|
78 |
public void setDrawnBehavior(int index, boolean draw) { |
79 |
switch (index) {
|
80 |
case EDITING_INDEX:
|
81 |
if (draw) {
|
82 |
mode = Mode.EDITING; |
83 |
} else {
|
84 |
mode = Mode.SELECTION; |
85 |
} |
86 |
break;
|
87 |
case SELECTION_INDEX:
|
88 |
if (draw) {
|
89 |
mode = Mode.SELECTION; |
90 |
} else {
|
91 |
mode = Mode.EDITING; |
92 |
} |
93 |
break;
|
94 |
default:
|
95 |
throw new IndexOutOfBoundsException(); |
96 |
} |
97 |
} |
98 |
|
99 |
public int size() { |
100 |
return 2; |
101 |
} |
102 |
|
103 |
public Image getImageCursor() { |
104 |
switch (mode) {
|
105 |
default:
|
106 |
case EDITING:
|
107 |
return this.editing.getImageCursor(); |
108 |
case SELECTION:
|
109 |
return this.selection.getImageCursor(); |
110 |
} |
111 |
} |
112 |
|
113 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
114 |
switch (mode) {
|
115 |
default:
|
116 |
case EDITING:
|
117 |
this.editing.mouseClicked(e);
|
118 |
break;
|
119 |
case SELECTION:
|
120 |
this.selection.mouseClicked(e);
|
121 |
} |
122 |
this.zoom.mouseClicked(e);
|
123 |
} |
124 |
|
125 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
126 |
switch (mode) {
|
127 |
default:
|
128 |
case EDITING:
|
129 |
this.editing.mouseDragged(e);
|
130 |
break;
|
131 |
case SELECTION:
|
132 |
this.selection.mouseDragged(e);
|
133 |
} |
134 |
this.zoom.mouseDragged(e);
|
135 |
} |
136 |
|
137 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
138 |
switch (mode) {
|
139 |
default:
|
140 |
case EDITING:
|
141 |
this.editing.mouseEntered(e);
|
142 |
break;
|
143 |
case SELECTION:
|
144 |
this.selection.mouseEntered(e);
|
145 |
} |
146 |
this.zoom.mouseEntered(e);
|
147 |
} |
148 |
|
149 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
150 |
switch (mode) {
|
151 |
default:
|
152 |
case EDITING:
|
153 |
this.editing.mouseExited(e);
|
154 |
break;
|
155 |
case SELECTION:
|
156 |
this.selection.mouseExited(e);
|
157 |
} |
158 |
this.zoom.mouseExited(e);
|
159 |
} |
160 |
|
161 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
162 |
switch (mode) {
|
163 |
default:
|
164 |
case EDITING:
|
165 |
this.editing.mouseMoved(e);
|
166 |
break;
|
167 |
case SELECTION:
|
168 |
this.selection.mouseMoved(e);
|
169 |
} |
170 |
this.zoom.mouseMoved(e);
|
171 |
} |
172 |
|
173 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
174 |
switch (mode) {
|
175 |
default:
|
176 |
case EDITING:
|
177 |
this.editing.mousePressed(e);
|
178 |
break;
|
179 |
case SELECTION:
|
180 |
this.selection.mousePressed(e);
|
181 |
} |
182 |
this.zoom.mousePressed(e);
|
183 |
} |
184 |
|
185 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
186 |
switch (mode) {
|
187 |
default:
|
188 |
case EDITING:
|
189 |
this.editing.mouseReleased(e);
|
190 |
break;
|
191 |
case SELECTION:
|
192 |
this.selection.mouseReleased(e);
|
193 |
} |
194 |
this.zoom.mouseReleased(e);
|
195 |
} |
196 |
|
197 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
198 |
switch (mode) {
|
199 |
default:
|
200 |
case EDITING:
|
201 |
this.editing.mouseWheelMoved(e);
|
202 |
break;
|
203 |
case SELECTION:
|
204 |
this.selection.mouseWheelMoved(e);
|
205 |
} |
206 |
this.zoom.mouseWheelMoved(e);
|
207 |
} |
208 |
|
209 |
public void paintComponent(MapControlDrawer renderer) { |
210 |
switch (mode) {
|
211 |
default:
|
212 |
case EDITING:
|
213 |
this.editing.paintComponent(renderer);
|
214 |
break;
|
215 |
case SELECTION:
|
216 |
this.selection.paintComponent(renderer);
|
217 |
} |
218 |
this.zoom.paintComponent(renderer);
|
219 |
} |
220 |
|
221 |
public void setListener(ToolListener listener) { |
222 |
if (listener != null) { |
223 |
throw new UnsupportedOperationException( |
224 |
"CompoundBehavior does not have listeners");
|
225 |
} |
226 |
} |
227 |
|
228 |
public ToolListener getListener() {
|
229 |
return null; |
230 |
} |
231 |
|
232 |
public void setMapControl(MapControl mc) { |
233 |
this.editing.setMapControl(mc);
|
234 |
this.zoom.setMapControl(mc);
|
235 |
|
236 |
if (this.selection == null){ |
237 |
if (mc !=null) { |
238 |
// StatusBarListener sbl = new StatusBarListener(mc);
|
239 |
PointSelectionListener psl = new PointSelectionListener(mc);
|
240 |
this.selection = new CompoundBehavior(new Behavior[] { |
241 |
new PointBehavior(psl) }); //, new MouseMovementBehavior(sbl) }); |
242 |
this.selection.setMapControl(mc);
|
243 |
} |
244 |
} else {
|
245 |
this.selection.setMapControl(mc);
|
246 |
} |
247 |
} |
248 |
|
249 |
} |