svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / CADExtension.java @ 5571
History | View | Annotate | Download (11.5 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 | 5257 | caballero | import javax.swing.FocusManager; |
53 | 3883 | caballero | import javax.swing.JMenuItem; |
54 | import javax.swing.JPopupMenu; |
||
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 | 4950 | caballero | import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 | import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
||
62 | 5164 | caballero | import com.iver.cit.gvsig.fmap.tools.CompoundBehavior; |
63 | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
||
64 | import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
||
65 | 3712 | caballero | import com.iver.cit.gvsig.gui.View; |
66 | import com.iver.cit.gvsig.gui.cad.CADTool; |
||
67 | import com.iver.cit.gvsig.gui.cad.CADToolAdapter; |
||
68 | 3883 | caballero | import com.iver.cit.gvsig.gui.cad.tools.CopyCADTool; |
69 | import com.iver.cit.gvsig.gui.cad.tools.RotateCADTool; |
||
70 | import com.iver.cit.gvsig.gui.cad.tools.ScaleCADTool; |
||
71 | 5164 | caballero | import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
72 | 4892 | caballero | import com.iver.utiles.console.JConsole; |
73 | 3712 | caballero | import com.iver.utiles.console.ResponseListener; |
74 | 5478 | caballero | import com.iver.utiles.console.jedit.JEditTextArea; |
75 | 5115 | caballero | |
76 | 3712 | caballero | /**
|
77 | 5115 | caballero | * Extensi?n dedicada a controlar las diferentes operaciones sobre el editado de
|
78 | * una capa.
|
||
79 | 3712 | caballero | *
|
80 | * @author Vicente Caballero Navarro
|
||
81 | */
|
||
82 | 5005 | jorpiell | public class CADExtension extends Extension { |
83 | 5115 | caballero | private static CADToolAdapter adapter = new CADToolAdapter(); |
84 | 4950 | caballero | |
85 | 5115 | caballero | private static EditionManager editionManager = new EditionManager(); |
86 | 4950 | caballero | |
87 | 5115 | caballero | private static HashMap namesCadTools = new HashMap(); |
88 | 4950 | caballero | |
89 | 5115 | caballero | // /private MapControl mapControl;
|
90 | private static View view; |
||
91 | 4950 | caballero | |
92 | 5115 | caballero | private MapControl mapControl;
|
93 | 4950 | caballero | |
94 | 5115 | caballero | public static CADToolAdapter getCADToolAdapter() { |
95 | return adapter;
|
||
96 | } |
||
97 | 4950 | caballero | |
98 | 5115 | caballero | /**
|
99 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
100 | */
|
||
101 | public void initialize() { |
||
102 | 5478 | caballero | |
103 | 5373 | fjp | // Fijamos que los s?mbolos de dibujo tengan outline
|
104 | // TODO: Esto se debe configurar en el cuadro de di?logo de preferencias
|
||
105 | CADTool.drawingSymbol.setOutlined(true);
|
||
106 | CADTool.drawingSymbol.setOutlineColor(CADTool.drawingSymbol.getColor().darker()); |
||
107 | CADTool.modifySymbol.setOutlined(true);
|
||
108 | CADTool.modifySymbol.setOutlineColor(CADTool.modifySymbol.getColor().darker()); |
||
109 | CADTool.selectSymbol.setOutlined(true);
|
||
110 | CADTool.selectSymbol.setOutlineColor(CADTool.selectSymbol.getColor().darker()); |
||
111 | 3712 | caballero | |
112 | 5478 | caballero | |
113 | 5115 | caballero | CopyCADTool copy = new CopyCADTool();
|
114 | 3712 | caballero | |
115 | 5115 | caballero | RotateCADTool rotate = new RotateCADTool();
|
116 | ScaleCADTool scale = new ScaleCADTool();
|
||
117 | |||
118 | addCADTool("_copy", copy);
|
||
119 | |||
120 | addCADTool("_rotate", rotate);
|
||
121 | addCADTool("_scale", scale);
|
||
122 | |||
123 | KeyboardFocusManager kfm = KeyboardFocusManager |
||
124 | .getCurrentKeyboardFocusManager(); |
||
125 | kfm.addKeyEventPostProcessor(new myKeyEventPostProcessor());
|
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
||
130 | */
|
||
131 | public void execute(String s) { |
||
132 | initFocus(); |
||
133 | |||
134 | if (s.equals("_spline") || s.equals("_copy") |
||
135 | || s.equals("_equidistance") || s.equals("_matriz") |
||
136 | || s.equals("_symmetry") || s.equals("_rotate") |
||
137 | || s.equals("_stretch") || s.equals("_scale") |
||
138 | || s.equals("_extend") || s.equals("_trim") |
||
139 | || s.equals("_unit") || s.equals("_exploit") |
||
140 | || s.equals("_chaflan") || s.equals("_join")) { |
||
141 | setCADTool(s, true);
|
||
142 | } |
||
143 | adapter.configureMenu(); |
||
144 | } |
||
145 | |||
146 | public static void addCADTool(String name, CADTool c) { |
||
147 | 3712 | caballero | namesCadTools.put(name, c); |
148 | } |
||
149 | 5115 | caballero | |
150 | public static void setCADTool(String text, boolean showCommand) { |
||
151 | 3712 | caballero | CADTool ct = (CADTool) namesCadTools.get(text); |
152 | 5115 | caballero | if (ct == null) |
153 | throw new RuntimeException("No such cad tool"); |
||
154 | 3883 | caballero | adapter.setCadTool(ct); |
155 | 3712 | caballero | ct.init(); |
156 | 5115 | caballero | if (showCommand) {
|
157 | 4892 | caballero | View vista = (View) PluginServices.getMDIManager().getActiveView(); |
158 | 5115 | caballero | vista.getConsolePanel().addText("\n" + ct.getName(),
|
159 | JConsole.COMMAND); |
||
160 | 4892 | caballero | adapter.askQuestion(); |
161 | } |
||
162 | 5115 | caballero | // PluginServices.getMainFrame().setSelectedTool("SELECT");
|
163 | // PluginServices.getMainFrame().enableControls();
|
||
164 | 3712 | caballero | } |
165 | |||
166 | 5115 | caballero | public static CADTool getCADTool() { |
167 | return adapter.getCadTool();
|
||
168 | } |
||
169 | |||
170 | /**
|
||
171 | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
||
172 | */
|
||
173 | public boolean isEnabled() { |
||
174 | 5560 | fjp | // initFocus();
|
175 | 5115 | caballero | return true; |
176 | } |
||
177 | |||
178 | /**
|
||
179 | * @see com.iver.andami.plugins.IExtension#isVisible()
|
||
180 | */
|
||
181 | public boolean isVisible() { |
||
182 | if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
|
||
183 | view = (View) PluginServices.getMDIManager().getActiveView();
|
||
184 | mapControl = (MapControl) view.getMapControl(); |
||
185 | FLayer[] layers = mapControl.getMapContext().getLayers()
|
||
186 | .getActives(); |
||
187 | if (!(layers[0] instanceof FLyrAnnotation)) { |
||
188 | return true; |
||
189 | 4950 | caballero | } |
190 | 5115 | caballero | } |
191 | 4950 | caballero | return false; |
192 | 5115 | caballero | } |
193 | |||
194 | 3712 | caballero | public MapControl getMapControl() {
|
195 | 4899 | caballero | return editionManager.getMapControl();
|
196 | 3712 | caballero | } |
197 | |||
198 | 5115 | caballero | class KeyAction extends AbstractAction { |
199 | |||
200 | 3712 | caballero | private String key; |
201 | |||
202 | 5115 | caballero | public KeyAction(String key) { |
203 | 3712 | caballero | this.key = key;
|
204 | } |
||
205 | |||
206 | 5115 | caballero | /*
|
207 | * (non-Javadoc)
|
||
208 | *
|
||
209 | 3712 | caballero | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
210 | */
|
||
211 | public void actionPerformed(ActionEvent e) { |
||
212 | view.focusConsole(key); |
||
213 | } |
||
214 | |||
215 | } |
||
216 | |||
217 | 5115 | caballero | class MyAction extends AbstractAction { |
218 | 3712 | caballero | private String actionCommand; |
219 | |||
220 | 5115 | caballero | public MyAction(String command) { |
221 | 3712 | caballero | actionCommand = command; |
222 | } |
||
223 | |||
224 | /**
|
||
225 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
226 | */
|
||
227 | public void actionPerformed(ActionEvent e) { |
||
228 | adapter.keyPressed(actionCommand); |
||
229 | } |
||
230 | |||
231 | } |
||
232 | 4432 | caballero | |
233 | 4210 | fjp | /**
|
234 | * @author fjp
|
||
235 | *
|
||
236 | 5115 | caballero | * La idea es usar esto para recibir lo que el usuario escribe y enviarlo a
|
237 | * la consola de la vista para que salga por all?.
|
||
238 | 4210 | fjp | */
|
239 | 5115 | caballero | private class myKeyEventPostProcessor implements KeyEventPostProcessor { |
240 | 3712 | caballero | |
241 | 4210 | fjp | public boolean postProcessKeyEvent(KeyEvent e) { |
242 | 4748 | fjp | // System.out.println("KeyEvent e = " + e);
|
243 | 5115 | caballero | if ((adapter == null) || (view == null)) |
244 | return false; |
||
245 | |||
246 | if (e.getID() != KeyEvent.KEY_RELEASED) |
||
247 | return false; |
||
248 | if (!(e.getComponent() instanceof JTextComponent)) { |
||
249 | if (e.getKeyCode() == KeyEvent.VK_DELETE) |
||
250 | adapter.keyPressed("eliminar");
|
||
251 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
||
252 | adapter.keyPressed("escape");
|
||
253 | else if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
||
254 | // TODO: REVISAR ESTO CUANDO VIENE UN INTRO DESDE UN
|
||
255 | // JTEXTAREA
|
||
256 | // QUE NO ES EL DE CONSOLA
|
||
257 | 5257 | caballero | //view.focusConsole("");
|
258 | 5115 | caballero | } |
259 | |||
260 | else {
|
||
261 | 5478 | caballero | /* if ((!e.isActionKey())) {
|
262 | 5227 | caballero | //if (Character.isLetterOrDigit(e.getKeyChar())) {
|
263 | 5115 | caballero | Character keyChar = new Character(e.getKeyChar());
|
264 | if (e.getComponent().getName() != null) {
|
||
265 | System.out
|
||
266 | .println("Evento de teclado desde el componente "
|
||
267 | + e.getComponent().getName());
|
||
268 | if (!e.getComponent().getName().equals(
|
||
269 | "CADConsole")) {
|
||
270 | view.focusConsole(keyChar + "");
|
||
271 | }
|
||
272 | } else {
|
||
273 | if (!(e.getComponent() instanceof JTextComponent)) {
|
||
274 | view.focusConsole(keyChar + "");
|
||
275 | }
|
||
276 | }
|
||
277 | 5227 | caballero | //}
|
278 | 5478 | caballero | }*/
|
279 | 5115 | caballero | } |
280 | } |
||
281 | 4210 | fjp | return false; |
282 | } |
||
283 | 4432 | caballero | |
284 | 4210 | fjp | } |
285 | |||
286 | 5115 | caballero | /*
|
287 | * private void registerKeyStrokes(){ for (char key = '0'; key <= '9';
|
||
288 | * key++){ Character keyChar = new Character(key);
|
||
289 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),
|
||
290 | * keyChar); mapControl.getActionMap().put(keyChar, new
|
||
291 | * KeyAction(keyChar+"")); } for (char key = 'a'; key <= 'z'; key++){
|
||
292 | * Character keyChar = new Character(key);
|
||
293 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),
|
||
294 | * keyChar); mapControl.getActionMap().put(keyChar, new
|
||
295 | * KeyAction(keyChar+"")); } for (char key = 'A'; key <= 'Z'; key++){
|
||
296 | * Character keyChar = new Character(key);
|
||
297 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),
|
||
298 | * keyChar); mapControl.getActionMap().put(keyChar, new
|
||
299 | * KeyAction(keyChar+"")); }
|
||
300 | * //this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
|
||
301 | * 0), "enter"); //this.getActionMap().put("enter", new MyAction("enter"));
|
||
302 | * Character keyChar = new
|
||
303 | * Character(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0).getKeyChar());
|
||
304 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
|
||
305 | * 0),keyChar); mapControl.getActionMap().put(keyChar, new KeyAction(""));
|
||
306 | * // El espacio como si fuera INTRO Character keyCharSpace = new
|
||
307 | * Character(' ');
|
||
308 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('
|
||
309 | * '), keyCharSpace); mapControl.getActionMap().put(keyCharSpace, new
|
||
310 | * KeyAction(""));
|
||
311 | *
|
||
312 | * }
|
||
313 | */
|
||
314 | private static JPopupMenu popup = new JPopupMenu(); |
||
315 | 4432 | caballero | |
316 | 5115 | caballero | public static void clearMenu() { |
317 | 3883 | caballero | popup.removeAll(); |
318 | } |
||
319 | |||
320 | 5115 | caballero | public static void addMenuEntry(String text) { |
321 | 3883 | caballero | JMenuItem menu = new JMenuItem(text); |
322 | menu.setActionCommand(text); |
||
323 | menu.setEnabled(true);
|
||
324 | menu.setVisible(true);
|
||
325 | menu.addActionListener(new ActionListener() { |
||
326 | public void actionPerformed(ActionEvent e) { |
||
327 | adapter.transition(e.getActionCommand()); |
||
328 | } |
||
329 | }); |
||
330 | |||
331 | popup.add(menu); |
||
332 | } |
||
333 | 5115 | caballero | |
334 | 3883 | caballero | public static void showPopup(MouseEvent e) { |
335 | 5115 | caballero | popup.show(e.getComponent(), e.getX(), e.getY()); |
336 | } |
||
337 | |||
338 | 3883 | caballero | public static View getView() { |
339 | return view;
|
||
340 | } |
||
341 | 4147 | fjp | |
342 | /**
|
||
343 | * @return Returns the editionManager.
|
||
344 | */
|
||
345 | public static EditionManager getEditionManager() { |
||
346 | return editionManager;
|
||
347 | } |
||
348 | 5115 | caballero | |
349 | public static CADTool[] getCADTools() { |
||
350 | return (CADTool[]) namesCadTools.values().toArray(new CADTool[0]); |
||
351 | 4892 | caballero | } |
352 | 4899 | caballero | |
353 | 5115 | caballero | public static void initFocus() { |
354 | view = (View) PluginServices.getMDIManager().getActiveView();
|
||
355 | MapControl mapControl = (MapControl) view.getMapControl(); |
||
356 | 5164 | caballero | if (!mapControl.getNamesMapTools().containsKey("cadtooladapter")){ |
357 | StatusBarListener sbl=new StatusBarListener(view.getMapControl());
|
||
358 | mapControl.addMapTool("cadtooladapter", new Behavior[]{adapter,new MouseMovementBehavior(sbl)}); |
||
359 | } |
||
360 | 5560 | fjp | // view.getMapControl().setTool("cadtooladapter");
|
361 | 5478 | caballero | JEditTextArea jeta=view.getConsolePanel().getTxt(); |
362 | jeta.requestFocusInWindow(); |
||
363 | jeta.setCaretPosition(jeta.getText().length()); |
||
364 | 5257 | caballero | |
365 | 5115 | caballero | view.addConsoleListener("cad", new ResponseListener() { |
366 | public void acceptResponse(String response) { |
||
367 | adapter.textEntered(response); |
||
368 | // TODO:
|
||
369 | // FocusManager fm=FocusManager.getCurrentManager();
|
||
370 | // fm.focusPreviousComponent(mapControl);
|
||
371 | /*
|
||
372 | * if (popup.isShowing()){ popup.setVisible(false); }
|
||
373 | */
|
||
374 | |||
375 | } |
||
376 | }); |
||
377 | editionManager.setMapControl(mapControl); |
||
378 | view.getMapControl().setTool("cadtooladapter");
|
||
379 | 4899 | caballero | } |
380 | 3712 | caballero | } |