root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / CADExtension.java @ 4901
History | View | Annotate | Download (13.3 KB)
1 | 3712 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig; |
||
42 | |||
43 | 4210 | fjp | import java.awt.KeyEventPostProcessor; |
44 | import java.awt.KeyboardFocusManager; |
||
45 | 3712 | caballero | import java.awt.event.ActionEvent; |
46 | 3883 | caballero | import java.awt.event.ActionListener; |
47 | 3712 | caballero | import java.awt.event.KeyEvent; |
48 | 3883 | caballero | import java.awt.event.MouseEvent; |
49 | 3712 | caballero | import java.util.HashMap; |
50 | |||
51 | import javax.swing.AbstractAction; |
||
52 | 3883 | caballero | import javax.swing.JMenuItem; |
53 | import javax.swing.JPopupMenu; |
||
54 | 4727 | fjp | import javax.swing.JTextArea; |
55 | 4815 | fjp | import javax.swing.text.JTextComponent; |
56 | 3712 | caballero | |
57 | import com.iver.andami.PluginServices; |
||
58 | import com.iver.andami.plugins.Extension; |
||
59 | import com.iver.cit.gvsig.fmap.MapControl; |
||
60 | import com.iver.cit.gvsig.gui.View; |
||
61 | import com.iver.cit.gvsig.gui.cad.CADTool; |
||
62 | import com.iver.cit.gvsig.gui.cad.CADToolAdapter; |
||
63 | 3883 | caballero | import com.iver.cit.gvsig.gui.cad.tools.CopyCADTool; |
64 | 4118 | caballero | import com.iver.cit.gvsig.gui.cad.tools.EditVertexCADTool; |
65 | 4432 | caballero | import com.iver.cit.gvsig.gui.cad.tools.MoveCADTool; |
66 | 3883 | caballero | import com.iver.cit.gvsig.gui.cad.tools.RotateCADTool; |
67 | import com.iver.cit.gvsig.gui.cad.tools.ScaleCADTool; |
||
68 | 3829 | caballero | import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
69 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
70 | 3712 | caballero | import com.iver.utiles.console.ResponseListener; |
71 | /**
|
||
72 | * Extensi?n dedicada a controlar las diferentes operaciones sobre el editado
|
||
73 | * de una capa.
|
||
74 | *
|
||
75 | * @author Vicente Caballero Navarro
|
||
76 | */
|
||
77 | public class CADExtension implements Extension { |
||
78 | 3735 | caballero | private static CADToolAdapter adapter=new CADToolAdapter(); |
79 | 4147 | fjp | private static EditionManager editionManager = new EditionManager(); |
80 | 3748 | caballero | private static HashMap namesCadTools = new HashMap(); |
81 | 4899 | caballero | ///private MapControl mapControl;
|
82 | 3883 | caballero | private static View view; |
83 | 3735 | caballero | public static CADToolAdapter getCADToolAdapter(){ |
84 | 4147 | fjp | return adapter;
|
85 | 3712 | caballero | } |
86 | /**
|
||
87 | * @see com.iver.andami.plugins.Extension#inicializar()
|
||
88 | */
|
||
89 | public void inicializar() { |
||
90 | 3829 | caballero | SelectionCADTool selection=new SelectionCADTool();
|
91 | 3883 | caballero | CopyCADTool copy=new CopyCADTool();
|
92 | 4432 | caballero | MoveCADTool move=new MoveCADTool();
|
93 | 3883 | caballero | RotateCADTool rotate=new RotateCADTool();
|
94 | ScaleCADTool scale=new ScaleCADTool();
|
||
95 | 4118 | caballero | EditVertexCADTool editvertex=new EditVertexCADTool();
|
96 | 3829 | caballero | addCADTool("selection", selection);
|
97 | 3883 | caballero | addCADTool("copy",copy);
|
98 | 4432 | caballero | addCADTool("move",move);
|
99 | 3883 | caballero | addCADTool("rotate",rotate);
|
100 | addCADTool("scale",scale);
|
||
101 | 4118 | caballero | addCADTool("editvertex",editvertex);
|
102 | 4210 | fjp | KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); |
103 | kfm.addKeyEventPostProcessor(new myKeyEventPostProcessor());
|
||
104 | 3712 | caballero | } |
105 | |||
106 | /**
|
||
107 | * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
||
108 | */
|
||
109 | public void execute(String s) { |
||
110 | 4899 | caballero | initFocus(); |
111 | 3712 | caballero | |
112 | 4432 | caballero | if (s.equals("SPLINE")) { |
113 | 4892 | caballero | setCADTool("spline",true); |
114 | 4432 | caballero | } else if (s.equals("COPY")) { |
115 | 4892 | caballero | setCADTool("copy",true); |
116 | 4432 | caballero | } else if (s.equals("MOVE")) { |
117 | 4892 | caballero | setCADTool("move",true); |
118 | 4432 | caballero | } else if (s.equals("EQUIDISTANCE")) { |
119 | 4892 | caballero | setCADTool("equidistance",true); |
120 | 4432 | caballero | } else if (s.equals("MATRIZ")) { |
121 | 4892 | caballero | setCADTool("matriz",true); |
122 | 4432 | caballero | } else if (s.equals("SYMMETRY")) { |
123 | 4892 | caballero | setCADTool("symmetry",true); |
124 | 4432 | caballero | } else if (s.equals("ROTATION")) { |
125 | 4892 | caballero | setCADTool("rotate",true); |
126 | 4432 | caballero | } else if (s.equals("STRETCHING")) { |
127 | 4892 | caballero | setCADTool("stretching",true); |
128 | 4432 | caballero | } else if (s.equals("SCALE")) { |
129 | 4892 | caballero | setCADTool("scale",true); |
130 | 4432 | caballero | } else if (s.equals("EXTEND")) { |
131 | 4892 | caballero | setCADTool("extend",true); |
132 | 4432 | caballero | } else if (s.equals("TRIM")) { |
133 | 4892 | caballero | setCADTool("trim",true); |
134 | 4432 | caballero | } else if (s.equals("UNIT")) { |
135 | 4892 | caballero | setCADTool("unit",true); |
136 | 4432 | caballero | } else if (s.equals("EXPLOIT")) { |
137 | 4892 | caballero | setCADTool("exploit",true); |
138 | 4432 | caballero | } else if (s.equals("CHAFLAN")) { |
139 | 4892 | caballero | setCADTool("chaflan",true); |
140 | 4432 | caballero | } else if (s.equals("JOIN")) { |
141 | 4892 | caballero | setCADTool("join",true); |
142 | 4432 | caballero | } else if (s.equals("SELCAD")) { |
143 | 4892 | caballero | setCADTool("selection",true); |
144 | 4432 | caballero | } else if (s.equals("EDITVERTEX")) { |
145 | 4892 | caballero | setCADTool("editvertex",true); |
146 | 3712 | caballero | } |
147 | 3883 | caballero | adapter.configureMenu(); |
148 | 3712 | caballero | //ViewControls.CANCELED=false;
|
149 | } |
||
150 | 4551 | caballero | public static void addCADTool(String name, CADTool c){ |
151 | 3712 | caballero | namesCadTools.put(name, c); |
152 | } |
||
153 | 4892 | caballero | public static void setCADTool(String text,boolean showCommand){ |
154 | 3712 | caballero | CADTool ct = (CADTool) namesCadTools.get(text); |
155 | if (ct == null) throw new RuntimeException("No such cad tool"); |
||
156 | 3883 | caballero | adapter.setCadTool(ct); |
157 | 3712 | caballero | ct.init(); |
158 | 4892 | caballero | if (showCommand){
|
159 | View vista = (View) PluginServices.getMDIManager().getActiveView(); |
||
160 | vista.getConsolePanel().addText("\n" + ct.getName(),JConsole.COMMAND);
|
||
161 | adapter.askQuestion(); |
||
162 | } |
||
163 | 3883 | caballero | //PluginServices.getMainFrame().setSelectedTool("SELECT");
|
164 | //PluginServices.getMainFrame().enableControls();
|
||
165 | 3712 | caballero | } |
166 | 4583 | caballero | public static CADTool getCADTool(){ |
167 | return adapter.getCadTool();
|
||
168 | } |
||
169 | 3712 | caballero | /**
|
170 | * @see com.iver.andami.plugins.Extension#isEnabled()
|
||
171 | */
|
||
172 | public boolean isEnabled() { |
||
173 | 4147 | fjp | /* com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
|
174 | 3712 | caballero | .getActiveView();
|
175 | |||
176 | if (f == null) {
|
||
177 | return false;
|
||
178 | }
|
||
179 | |||
180 | if (f.getClass() == View.class) {
|
||
181 | FLayer[] l = ((View) f).getModel().getMapContext().getLayers()
|
||
182 | .getActives();
|
||
183 | |||
184 | for (int i = 0; i < l.length; i++) {
|
||
185 | if (l[i] instanceof FLyrVect && ((FLyrVect) l[i]).isEditing()) {
|
||
186 | return true;
|
||
187 | }
|
||
188 | }
|
||
189 | }
|
||
190 | |||
191 | 4147 | fjp | return false; */
|
192 | 4583 | caballero | /*if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
193 | 4147 | fjp | {
|
194 | // Queremos que siempre que haya edici?n esto est? funcionando.
|
||
195 | editionManager.setMapControl(mapControl);
|
||
196 | return true;
|
||
197 | }
|
||
198 | else
|
||
199 | return false;
|
||
200 | 4432 | caballero | |
201 | 4583 | caballero | */
|
202 | return true; |
||
203 | 3712 | caballero | } |
204 | |||
205 | /**
|
||
206 | * @see com.iver.andami.plugins.Extension#isVisible()
|
||
207 | */
|
||
208 | public boolean isVisible() { |
||
209 | 4583 | caballero | if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
210 | { |
||
211 | // Queremos que siempre que haya edici?n esto est? funcionando.
|
||
212 | 4899 | caballero | ///editionManager.setMapControl(mapControl);
|
213 | 4583 | caballero | return true; |
214 | } |
||
215 | else
|
||
216 | return false; |
||
217 | // com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
|
||
218 | // .getActiveView();
|
||
219 | //
|
||
220 | // if (f == null) {
|
||
221 | // return false;
|
||
222 | // }
|
||
223 | //
|
||
224 | // if (f.getClass() == View.class) {
|
||
225 | // FLayer[] layers=getMapControl().getMapContext().getLayers().getActives();
|
||
226 | // if (layers[0] instanceof FLyrVect && ((FLyrVect)layers[0]).isEditing()){
|
||
227 | // return true;
|
||
228 | // }
|
||
229 | // }
|
||
230 | // return false;
|
||
231 | 3712 | caballero | } |
232 | public MapControl getMapControl() {
|
||
233 | 4899 | caballero | return editionManager.getMapControl();
|
234 | 3712 | caballero | } |
235 | class KeyAction extends AbstractAction{ |
||
236 | |||
237 | private String key; |
||
238 | |||
239 | public KeyAction(String key){ |
||
240 | this.key = key;
|
||
241 | } |
||
242 | |||
243 | /* (non-Javadoc)
|
||
244 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
245 | */
|
||
246 | public void actionPerformed(ActionEvent e) { |
||
247 | view.focusConsole(key); |
||
248 | } |
||
249 | |||
250 | } |
||
251 | |||
252 | class MyAction extends AbstractAction{ |
||
253 | private String actionCommand; |
||
254 | |||
255 | public MyAction(String command){ |
||
256 | actionCommand = command; |
||
257 | } |
||
258 | |||
259 | /**
|
||
260 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
261 | */
|
||
262 | public void actionPerformed(ActionEvent e) { |
||
263 | adapter.keyPressed(actionCommand); |
||
264 | } |
||
265 | |||
266 | } |
||
267 | 4432 | caballero | |
268 | 4210 | fjp | /**
|
269 | * @author fjp
|
||
270 | *
|
||
271 | * La idea es usar esto para recibir lo que el usuario escribe y enviarlo
|
||
272 | * a la consola de la vista para que salga por all?.
|
||
273 | */
|
||
274 | private class myKeyEventPostProcessor implements KeyEventPostProcessor |
||
275 | { |
||
276 | 3712 | caballero | |
277 | 4210 | fjp | public boolean postProcessKeyEvent(KeyEvent e) { |
278 | 4748 | fjp | // System.out.println("KeyEvent e = " + e);
|
279 | 4210 | fjp | if ((adapter==null) || (view == null)) return false; |
280 | 4475 | fjp | if (e.getID() != KeyEvent.KEY_RELEASED) return false; |
281 | 4210 | fjp | if (e.getKeyCode() == KeyEvent.VK_DELETE) |
282 | adapter.keyPressed("eliminar");
|
||
283 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
||
284 | adapter.keyPressed("escape");
|
||
285 | else if (e.getKeyCode() == KeyEvent.VK_ENTER) |
||
286 | 4901 | caballero | { |
287 | 4454 | fjp | // TODO: REVISAR ESTO CUANDO VIENE UN INTRO DESDE UN JTEXTAREA
|
288 | // QUE NO ES EL DE CONSOLA
|
||
289 | 4901 | caballero | // view.focusConsole("");
|
290 | } |
||
291 | 4210 | fjp | else
|
292 | { |
||
293 | 4727 | fjp | if ((e.getID() == KeyEvent.KEY_RELEASED) && (!e.isActionKey())) |
294 | 4551 | caballero | { |
295 | 4727 | fjp | if (Character.isLetterOrDigit(e.getKeyChar())) |
296 | { |
||
297 | Character keyChar = new Character(e.getKeyChar()); |
||
298 | if (e.getComponent().getName() != null) |
||
299 | { |
||
300 | System.out.println("Evento de teclado desde el componente " + e.getComponent().getName()); |
||
301 | if (!e.getComponent().getName().equals("CADConsole")) |
||
302 | 4892 | caballero | { |
303 | 4727 | fjp | view.focusConsole(keyChar+"");
|
304 | } |
||
305 | } |
||
306 | else
|
||
307 | { |
||
308 | 4815 | fjp | if (!(e.getComponent() instanceof JTextComponent)) |
309 | 4892 | caballero | { |
310 | 4727 | fjp | view.focusConsole(keyChar+"");
|
311 | 4892 | caballero | } |
312 | 4727 | fjp | } |
313 | 4210 | fjp | } |
314 | } |
||
315 | } |
||
316 | return false; |
||
317 | } |
||
318 | 4432 | caballero | |
319 | 4210 | fjp | } |
320 | |||
321 | 4551 | caballero | /* private void registerKeyStrokes(){
|
322 | 3712 | caballero | for (char key = '0'; key <= '9'; key++){
|
323 | Character keyChar = new Character(key);
|
||
324 | mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), keyChar);
|
||
325 | mapControl.getActionMap().put(keyChar, new KeyAction(keyChar+""));
|
||
326 | }
|
||
327 | for (char key = 'a'; key <= 'z'; key++){
|
||
328 | Character keyChar = new Character(key);
|
||
329 | mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), keyChar);
|
||
330 | mapControl.getActionMap().put(keyChar, new KeyAction(keyChar+""));
|
||
331 | }
|
||
332 | for (char key = 'A'; key <= 'Z'; key++){
|
||
333 | Character keyChar = new Character(key);
|
||
334 | mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), keyChar);
|
||
335 | mapControl.getActionMap().put(keyChar, new KeyAction(keyChar+""));
|
||
336 | }
|
||
337 | //this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
|
||
338 | //this.getActionMap().put("enter", new MyAction("enter"));
|
||
339 | Character keyChar = new Character(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0).getKeyChar());
|
||
340 | mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),keyChar);
|
||
341 | mapControl.getActionMap().put(keyChar, new KeyAction(""));
|
||
342 | 4432 | caballero | |
343 | 4147 | fjp | // El espacio como si fuera INTRO
|
344 | Character keyCharSpace = new Character(' ');
|
||
345 | mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(' '), keyCharSpace);
|
||
346 | mapControl.getActionMap().put(keyCharSpace, new KeyAction(""));
|
||
347 | |||
348 | 4432 | caballero | |
349 | 3712 | caballero | }
|
350 | 4551 | caballero | */
|
351 | 3883 | caballero | private static JPopupMenu popup = new JPopupMenu(); |
352 | public static void clearMenu(){ |
||
353 | popup.removeAll(); |
||
354 | } |
||
355 | |||
356 | public static void addMenuEntry(String text){ |
||
357 | JMenuItem menu = new JMenuItem(text); |
||
358 | menu.setActionCommand(text); |
||
359 | menu.setEnabled(true);
|
||
360 | menu.setVisible(true);
|
||
361 | menu.addActionListener(new ActionListener() { |
||
362 | public void actionPerformed(ActionEvent e) { |
||
363 | adapter.transition(e.getActionCommand()); |
||
364 | } |
||
365 | }); |
||
366 | |||
367 | popup.add(menu); |
||
368 | } |
||
369 | public static void showPopup(MouseEvent e) { |
||
370 | popup.show(e.getComponent(), |
||
371 | e.getX(), e.getY()); |
||
372 | } |
||
373 | public static View getView() { |
||
374 | return view;
|
||
375 | } |
||
376 | 4147 | fjp | |
377 | /**
|
||
378 | * @return Returns the editionManager.
|
||
379 | */
|
||
380 | public static EditionManager getEditionManager() { |
||
381 | return editionManager;
|
||
382 | } |
||
383 | 4892 | caballero | public static CADTool[] getCADTools(){ |
384 | return (CADTool[])namesCadTools.values().toArray(new CADTool[0]); |
||
385 | } |
||
386 | 4899 | caballero | public static void initFocus(){ |
387 | view = (View) PluginServices.getMDIManager().getActiveView();
|
||
388 | MapControl mapControl = (MapControl) view.getMapControl(); |
||
389 | if (!mapControl.getNamesMapTools().containsKey("cadtooladapter")) |
||
390 | mapControl.addMapTool("cadtooladapter",adapter);
|
||
391 | view.getMapControl().setTool("cadtooladapter");
|
||
392 | view.addConsoleListener("cad", new ResponseListener() { |
||
393 | public void acceptResponse(String response) { |
||
394 | adapter.textEntered(response); |
||
395 | // TODO:
|
||
396 | // FocusManager fm=FocusManager.getCurrentManager();
|
||
397 | // fm.focusPreviousComponent(mapControl);
|
||
398 | /*if (popup.isShowing()){
|
||
399 | popup.setVisible(false);
|
||
400 | }*/
|
||
401 | |||
402 | } |
||
403 | }); |
||
404 | editionManager.setMapControl(mapControl); |
||
405 | view.getMapControl().setTool("cadtooladapter");
|
||
406 | } |
||
407 | 3712 | caballero | } |