svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / CADExtension.java @ 36005
History | View | Annotate | Download (16.8 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 | 29616 | jpiera | package org.gvsig.editing; |
42 | 3712 | caballero | |
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 | 6528 | caballero | import javax.swing.JTable; |
55 | 5817 | fjp | import javax.swing.KeyStroke; |
56 | 4815 | fjp | import javax.swing.text.JTextComponent; |
57 | 3712 | caballero | |
58 | 29616 | jpiera | import org.gvsig.andami.PluginServices; |
59 | 36005 | jpiera | import org.gvsig.andami.PluginsLocator; |
60 | import org.gvsig.andami.PluginsManager; |
||
61 | 29616 | jpiera | import org.gvsig.andami.plugins.Extension; |
62 | import org.gvsig.andami.preferences.IPreference; |
||
63 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
64 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
65 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
66 | 29616 | jpiera | import org.gvsig.editing.gui.accelerators.ForceCursorAccelerator; |
67 | import org.gvsig.editing.gui.accelerators.GridAccelerator; |
||
68 | import org.gvsig.editing.gui.accelerators.OrtoAccelerator; |
||
69 | import org.gvsig.editing.gui.accelerators.RefentAccelerator; |
||
70 | import org.gvsig.editing.gui.cad.CADTool; |
||
71 | import org.gvsig.editing.gui.cad.CADToolAdapter; |
||
72 | import org.gvsig.editing.gui.cad.tools.CopyCADTool; |
||
73 | import org.gvsig.editing.gui.cad.tools.RotateCADTool; |
||
74 | import org.gvsig.editing.gui.cad.tools.ScaleCADTool; |
||
75 | import org.gvsig.editing.gui.cad.tools.SymmetryCADTool; |
||
76 | import org.gvsig.editing.gui.preferences.EditingPage; |
||
77 | import org.gvsig.editing.project.documents.view.toc.MenuEntry; |
||
78 | 21666 | vcaballero | import org.gvsig.fmap.mapcontext.layers.FLayer; |
79 | 36005 | jpiera | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
80 | 21666 | vcaballero | import org.gvsig.fmap.mapcontrol.MapControl; |
81 | 36005 | jpiera | import org.gvsig.fmap.mapcontrol.MapControlLocator; |
82 | import org.gvsig.fmap.mapcontrol.MapControlManager; |
||
83 | import org.gvsig.tools.dynobject.DynObject; |
||
84 | 29616 | jpiera | import org.gvsig.utils.console.JConsole; |
85 | import org.gvsig.utils.console.ResponseListener; |
||
86 | import org.gvsig.utils.console.jedit.JEditTextArea; |
||
87 | 21666 | vcaballero | |
88 | 5115 | caballero | |
89 | 3712 | caballero | /**
|
90 | 5115 | caballero | * Extensi?n dedicada a controlar las diferentes operaciones sobre el editado de
|
91 | * una capa.
|
||
92 | 3712 | caballero | *
|
93 | * @author Vicente Caballero Navarro
|
||
94 | */
|
||
95 | 11434 | caballero | public class CADExtension extends Extension implements IPreferenceExtension{ |
96 | 6174 | caballero | private static HashMap adapters=new HashMap(); |
97 | 4950 | caballero | |
98 | 31496 | jjdelcerro | private static DefaultViewPanel view; |
99 | 4950 | caballero | |
100 | 5115 | caballero | private MapControl mapControl;
|
101 | 6192 | caballero | private static CADToolAdapter adapter=null; |
102 | 11434 | caballero | private EditingPage editingPage=new EditingPage(); |
103 | 4950 | caballero | |
104 | 24538 | vcaballero | |
105 | public static CADToolAdapter getCADToolAdapter(FLayer layer) { |
||
106 | IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
||
107 | for (int i = 0; i < windows.length; i++) { |
||
108 | IWindow window=windows[i]; |
||
109 | 31496 | jjdelcerro | if (window instanceof DefaultViewPanel){ |
110 | DefaultViewPanel v=(DefaultViewPanel)window; |
||
111 | 24538 | vcaballero | if (v.getModel().getMapContext().equals(layer.getMapContext())){
|
112 | if (!adapters.containsKey(v.getModel())) {
|
||
113 | adapters.put(v.getModel(),new CADToolAdapter());
|
||
114 | } |
||
115 | return (CADToolAdapter)adapters.get(v.getModel());
|
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | return null; |
||
120 | } |
||
121 | |||
122 | 5115 | caballero | public static CADToolAdapter getCADToolAdapter() { |
123 | 29616 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow view=PluginServices.getMDIManager().getActiveWindow(); |
124 | 31496 | jjdelcerro | if (view instanceof DefaultViewPanel) { |
125 | DefaultViewPanel v=(DefaultViewPanel)view; |
||
126 | 7546 | caballero | if (!adapters.containsKey(v.getModel())) {
|
127 | adapters.put(v.getModel(),new CADToolAdapter());
|
||
128 | 6174 | caballero | } |
129 | 7546 | caballero | adapter=(CADToolAdapter)adapters.get(v.getModel()); |
130 | 6192 | caballero | return adapter;
|
131 | 6174 | caballero | } |
132 | 6192 | caballero | return adapter;
|
133 | 6174 | caballero | |
134 | 5115 | caballero | } |
135 | 4950 | caballero | |
136 | 5115 | caballero | /**
|
137 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
138 | 5115 | caballero | */
|
139 | public void initialize() { |
||
140 | 5478 | caballero | |
141 | 5793 | fjp | // Registramos los Popup menus:
|
142 | 7674 | caballero | MenuEntry.register(); |
143 | 3712 | caballero | |
144 | 5115 | caballero | CopyCADTool copy = new CopyCADTool();
|
145 | RotateCADTool rotate = new RotateCADTool();
|
||
146 | ScaleCADTool scale = new ScaleCADTool();
|
||
147 | 5884 | caballero | SymmetryCADTool symmetry=new SymmetryCADTool();
|
148 | 5115 | caballero | addCADTool("_copy", copy);
|
149 | addCADTool("_rotate", rotate);
|
||
150 | addCADTool("_scale", scale);
|
||
151 | 5884 | caballero | addCADTool("_symmetry", symmetry);
|
152 | // Registramos las teclas de acceso r?pido que vamos a usar.
|
||
153 | 5959 | caballero | |
154 | 5845 | fjp | KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0); |
155 | 5959 | caballero | RefentAccelerator accRef = new RefentAccelerator();
|
156 | 5845 | fjp | PluginServices.registerKeyStroke(key, accRef); |
157 | 5115 | caballero | |
158 | 5845 | fjp | key = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0); |
159 | 5959 | caballero | OrtoAccelerator accOrto = new OrtoAccelerator();
|
160 | 5845 | fjp | PluginServices.registerKeyStroke(key, accOrto); |
161 | |||
162 | key = KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0); |
||
163 | 5959 | caballero | GridAccelerator accGrid = new GridAccelerator();
|
164 | 5845 | fjp | PluginServices.registerKeyStroke(key, accGrid); |
165 | |||
166 | key = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0); |
||
167 | 5959 | caballero | ForceCursorAccelerator accForce = new ForceCursorAccelerator();
|
168 | 5845 | fjp | PluginServices.registerKeyStroke(key, accForce); |
169 | 5959 | caballero | |
170 | |||
171 | 5115 | caballero | KeyboardFocusManager kfm = KeyboardFocusManager |
172 | .getCurrentKeyboardFocusManager(); |
||
173 | kfm.addKeyEventPostProcessor(new myKeyEventPostProcessor());
|
||
174 | 15637 | jmvivo | |
175 | 14810 | jmvivo | registerIcons(); |
176 | 5115 | caballero | } |
177 | |||
178 | 36005 | jpiera | @Override
|
179 | public void postInitialize() { |
||
180 | //Register the edition symbology
|
||
181 | registerEditionSymbology(); |
||
182 | } |
||
183 | |||
184 | /**
|
||
185 | * It registers the default symbology used in edition
|
||
186 | */
|
||
187 | private void registerEditionSymbology() { |
||
188 | PluginsManager pluginsManager = PluginsLocator.getManager(); |
||
189 | DynObject dynObject = pluginsManager.getPlugin(getClass()).getPluginProperties(); |
||
190 | |||
191 | MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
||
192 | |||
193 | if (dynObject.hasDynValue(EditingPage.DEFAULT_AXIS_REFERENCES_SYMBOL)){
|
||
194 | mapControlManager.setAxisReferenceSymbol( |
||
195 | (ISymbol)dynObject.getDynValue(EditingPage.DEFAULT_AXIS_REFERENCES_SYMBOL)); |
||
196 | } |
||
197 | |||
198 | if (dynObject.hasDynValue(EditingPage.DEFAULT_RECTANGLE_SELECTION_SYMBOL)) {
|
||
199 | mapControlManager.setGeometrySelectionSymbol( |
||
200 | (ISymbol)dynObject.getDynValue(EditingPage.DEFAULT_RECTANGLE_SELECTION_SYMBOL)); |
||
201 | } |
||
202 | |||
203 | if (dynObject.hasDynValue(EditingPage.DEFAULT_HANDLER_SYMBOL)) {
|
||
204 | mapControlManager.setHandlerSymbol( |
||
205 | (ISymbol)dynObject.getDynValue(EditingPage.DEFAULT_HANDLER_SYMBOL)); |
||
206 | } |
||
207 | } |
||
208 | |||
209 | private void registerIcons(){ |
||
210 | 15637 | jmvivo | PluginServices.getIconTheme().registerDefault( |
211 | 14810 | jmvivo | "edition-geometry-copy",
|
212 | this.getClass().getClassLoader().getResource("images/Copy.png") |
||
213 | ); |
||
214 | 15637 | jmvivo | |
215 | PluginServices.getIconTheme().registerDefault( |
||
216 | 14810 | jmvivo | "edition-geometry-symmetry",
|
217 | this.getClass().getClassLoader().getResource("images/Symmetry.png") |
||
218 | ); |
||
219 | 15637 | jmvivo | |
220 | PluginServices.getIconTheme().registerDefault( |
||
221 | 14810 | jmvivo | "edition-geometry-rotate",
|
222 | this.getClass().getClassLoader().getResource("images/Rotation.png") |
||
223 | ); |
||
224 | 15637 | jmvivo | |
225 | PluginServices.getIconTheme().registerDefault( |
||
226 | 14810 | jmvivo | "edition-geometry-scale",
|
227 | 15954 | vcaballero | this.getClass().getClassLoader()
|
228 | .getResource("images/Scale.png"));
|
||
229 | 15637 | jmvivo | |
230 | 15954 | vcaballero | PluginServices.getIconTheme().registerDefault( |
231 | "edition-properties",
|
||
232 | CADExtension.class.getClassLoader().getResource( |
||
233 | "images/EditingProperties.png"));
|
||
234 | 15637 | jmvivo | |
235 | 15954 | vcaballero | PluginServices.getIconTheme().registerDefault( |
236 | "field-expresion",
|
||
237 | CADExtension.class.getClassLoader().getResource( |
||
238 | "images/FieldExpresion.png"));
|
||
239 | PluginServices.getIconTheme().registerDefault( |
||
240 | "flatness-icon",
|
||
241 | CADExtension.class.getClassLoader().getResource( |
||
242 | "images/Flatness.png"));
|
||
243 | PluginServices.getIconTheme().registerDefault( |
||
244 | "grid-icon",
|
||
245 | CADExtension.class.getClassLoader().getResource( |
||
246 | "images/Grid.png"));
|
||
247 | PluginServices.getIconTheme().registerDefault( |
||
248 | "snapper-icon",
|
||
249 | CADExtension.class.getClassLoader().getResource( |
||
250 | "images/Snapper.png"));
|
||
251 | 15637 | jmvivo | } |
252 | |||
253 | 5115 | caballero | /**
|
254 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
255 | 5115 | caballero | */
|
256 | public void execute(String s) { |
||
257 | initFocus(); |
||
258 | |||
259 | if (s.equals("_spline") || s.equals("_copy") |
||
260 | || s.equals("_equidistance") || s.equals("_matriz") |
||
261 | || s.equals("_symmetry") || s.equals("_rotate") |
||
262 | || s.equals("_stretch") || s.equals("_scale") |
||
263 | || s.equals("_extend") || s.equals("_trim") |
||
264 | 5884 | caballero | || s.equals("_unit")
|
265 | 5115 | caballero | || s.equals("_chaflan") || s.equals("_join")) { |
266 | setCADTool(s, true);
|
||
267 | } |
||
268 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
269 | cta.configureMenu(); |
||
270 | 5115 | caballero | } |
271 | |||
272 | public static void addCADTool(String name, CADTool c) { |
||
273 | 6174 | caballero | CADToolAdapter.addCADTool(name, c); |
274 | 3712 | caballero | } |
275 | 5115 | caballero | |
276 | public static void setCADTool(String text, boolean showCommand) { |
||
277 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
278 | CADTool ct=cta.getCADTool(text); |
||
279 | |||
280 | 5115 | caballero | if (ct == null) |
281 | throw new RuntimeException("No such cad tool"); |
||
282 | 6713 | caballero | cta.initializeFlatness(); |
283 | 6174 | caballero | cta.setCadTool(ct); |
284 | 3712 | caballero | ct.init(); |
285 | 5115 | caballero | if (showCommand) {
|
286 | 31496 | jjdelcerro | if (PluginServices.getMDIManager().getActiveWindow() instanceof DefaultViewPanel) { |
287 | DefaultViewPanel vista = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
||
288 | 5959 | caballero | vista.getConsolePanel().addText("\n" + ct.getName(),
|
289 | 5115 | caballero | JConsole.COMMAND); |
290 | 6174 | caballero | cta.askQuestion(); |
291 | 5959 | caballero | } |
292 | 4892 | caballero | } |
293 | 5115 | caballero | // PluginServices.getMainFrame().setSelectedTool("SELECT");
|
294 | // PluginServices.getMainFrame().enableControls();
|
||
295 | 3712 | caballero | } |
296 | |||
297 | 5115 | caballero | public static CADTool getCADTool() { |
298 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
299 | return cta.getCadTool();
|
||
300 | 5115 | caballero | } |
301 | |||
302 | /**
|
||
303 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
304 | 5115 | caballero | */
|
305 | public boolean isEnabled() { |
||
306 | 5560 | fjp | // initFocus();
|
307 | 5115 | caballero | return true; |
308 | } |
||
309 | |||
310 | /**
|
||
311 | 29616 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isVisible()
|
312 | 5115 | caballero | */
|
313 | public boolean isVisible() { |
||
314 | if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE) {
|
||
315 | 31496 | jjdelcerro | view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
316 | 6604 | caballero | mapControl = view.getMapControl(); |
317 | 5115 | caballero | FLayer[] layers = mapControl.getMapContext().getLayers()
|
318 | .getActives(); |
||
319 | 21666 | vcaballero | // if (!(layers[0] instanceof FLyrAnnotation)) {
|
320 | // return true;
|
||
321 | // }
|
||
322 | 23086 | vcaballero | return true; |
323 | 5115 | caballero | } |
324 | 23086 | vcaballero | return false; |
325 | 5115 | caballero | } |
326 | |||
327 | 3712 | caballero | public MapControl getMapControl() {
|
328 | 6174 | caballero | return getEditionManager().getMapControl();
|
329 | 3712 | caballero | } |
330 | |||
331 | 5115 | caballero | class KeyAction extends AbstractAction { |
332 | |||
333 | 3712 | caballero | private String key; |
334 | |||
335 | 5115 | caballero | public KeyAction(String key) { |
336 | 3712 | caballero | this.key = key;
|
337 | } |
||
338 | |||
339 | 5115 | caballero | /*
|
340 | * (non-Javadoc)
|
||
341 | *
|
||
342 | 3712 | caballero | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
343 | */
|
||
344 | public void actionPerformed(ActionEvent e) { |
||
345 | view.focusConsole(key); |
||
346 | } |
||
347 | |||
348 | } |
||
349 | |||
350 | 5115 | caballero | class MyAction extends AbstractAction { |
351 | 3712 | caballero | private String actionCommand; |
352 | |||
353 | 5115 | caballero | public MyAction(String command) { |
354 | 3712 | caballero | actionCommand = command; |
355 | } |
||
356 | |||
357 | /**
|
||
358 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
359 | */
|
||
360 | public void actionPerformed(ActionEvent e) { |
||
361 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
362 | cta.keyPressed(actionCommand); |
||
363 | 3712 | caballero | } |
364 | |||
365 | } |
||
366 | 4432 | caballero | |
367 | 4210 | fjp | /**
|
368 | * @author fjp
|
||
369 | *
|
||
370 | 5115 | caballero | * La idea es usar esto para recibir lo que el usuario escribe y enviarlo a
|
371 | * la consola de la vista para que salga por all?.
|
||
372 | 4210 | fjp | */
|
373 | 5115 | caballero | private class myKeyEventPostProcessor implements KeyEventPostProcessor { |
374 | 3712 | caballero | |
375 | 4210 | fjp | public boolean postProcessKeyEvent(KeyEvent e) { |
376 | 4748 | fjp | // System.out.println("KeyEvent e = " + e);
|
377 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
378 | if ((cta == null) || (view == null)) |
||
379 | 5115 | caballero | return false; |
380 | |||
381 | 7832 | jmvivo | if (cta.getMapControl() == null){ |
382 | return false; |
||
383 | } |
||
384 | |||
385 | 5115 | caballero | if (e.getID() != KeyEvent.KEY_RELEASED) |
386 | return false; |
||
387 | if (!(e.getComponent() instanceof JTextComponent)) { |
||
388 | if (e.getKeyCode() == KeyEvent.VK_DELETE) |
||
389 | 6174 | caballero | cta.keyPressed("eliminar");
|
390 | 5115 | caballero | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
391 | 6174 | caballero | cta.keyPressed("escape");
|
392 | 5115 | caballero | else if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
393 | // TODO: REVISAR ESTO CUANDO VIENE UN INTRO DESDE UN
|
||
394 | // JTEXTAREA
|
||
395 | // QUE NO ES EL DE CONSOLA
|
||
396 | 6528 | caballero | if (!(e.getSource() instanceof JTable)) |
397 | view.focusConsole("");
|
||
398 | 5115 | caballero | } |
399 | 12739 | caballero | else if ((!e.isActionKey() && e.getKeyCode()!=KeyEvent.VK_TAB)) { |
400 | 5227 | caballero | //if (Character.isLetterOrDigit(e.getKeyChar())) {
|
401 | 5115 | caballero | Character keyChar = new Character(e.getKeyChar()); |
402 | if (e.getComponent().getName() != null) { |
||
403 | System.out
|
||
404 | .println("Evento de teclado desde el componente "
|
||
405 | + e.getComponent().getName()); |
||
406 | if (!e.getComponent().getName().equals(
|
||
407 | "CADConsole")) {
|
||
408 | view.focusConsole(keyChar + "");
|
||
409 | } |
||
410 | } else {
|
||
411 | if (!(e.getComponent() instanceof JTextComponent)) { |
||
412 | view.focusConsole(keyChar + "");
|
||
413 | } |
||
414 | } |
||
415 | 5227 | caballero | //}
|
416 | 5839 | fjp | } |
417 | 5115 | caballero | } |
418 | 4210 | fjp | return false; |
419 | } |
||
420 | 4432 | caballero | |
421 | 4210 | fjp | } |
422 | |||
423 | 5115 | caballero | /*
|
424 | * private void registerKeyStrokes(){ for (char key = '0'; key <= '9';
|
||
425 | * key++){ Character keyChar = new Character(key);
|
||
426 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),
|
||
427 | * keyChar); mapControl.getActionMap().put(keyChar, new
|
||
428 | * KeyAction(keyChar+"")); } for (char key = 'a'; key <= 'z'; key++){
|
||
429 | * Character keyChar = new Character(key);
|
||
430 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),
|
||
431 | * keyChar); mapControl.getActionMap().put(keyChar, new
|
||
432 | * KeyAction(keyChar+"")); } for (char key = 'A'; key <= 'Z'; key++){
|
||
433 | * Character keyChar = new Character(key);
|
||
434 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),
|
||
435 | * keyChar); mapControl.getActionMap().put(keyChar, new
|
||
436 | * KeyAction(keyChar+"")); }
|
||
437 | * //this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
|
||
438 | * 0), "enter"); //this.getActionMap().put("enter", new MyAction("enter"));
|
||
439 | * Character keyChar = new
|
||
440 | * Character(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0).getKeyChar());
|
||
441 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
|
||
442 | * 0),keyChar); mapControl.getActionMap().put(keyChar, new KeyAction(""));
|
||
443 | * // El espacio como si fuera INTRO Character keyCharSpace = new
|
||
444 | * Character(' ');
|
||
445 | * mapControl.getInputMap(MapControl.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke('
|
||
446 | * '), keyCharSpace); mapControl.getActionMap().put(keyCharSpace, new
|
||
447 | * KeyAction(""));
|
||
448 | *
|
||
449 | * }
|
||
450 | */
|
||
451 | private static JPopupMenu popup = new JPopupMenu(); |
||
452 | 4432 | caballero | |
453 | 5115 | caballero | public static void clearMenu() { |
454 | 3883 | caballero | popup.removeAll(); |
455 | } |
||
456 | |||
457 | 5115 | caballero | public static void addMenuEntry(String text) { |
458 | 3883 | caballero | JMenuItem menu = new JMenuItem(text); |
459 | menu.setActionCommand(text); |
||
460 | menu.setEnabled(true);
|
||
461 | menu.setVisible(true);
|
||
462 | menu.addActionListener(new ActionListener() { |
||
463 | public void actionPerformed(ActionEvent e) { |
||
464 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
465 | cta.transition(e.getActionCommand()); |
||
466 | 3883 | caballero | } |
467 | }); |
||
468 | |||
469 | popup.add(menu); |
||
470 | } |
||
471 | 5115 | caballero | |
472 | 3883 | caballero | public static void showPopup(MouseEvent e) { |
473 | 5115 | caballero | popup.show(e.getComponent(), e.getX(), e.getY()); |
474 | } |
||
475 | |||
476 | 31496 | jjdelcerro | public static DefaultViewPanel getView() { |
477 | 3883 | caballero | return view;
|
478 | } |
||
479 | 4147 | fjp | |
480 | 7832 | jmvivo | public static void clearView() { |
481 | view = null;
|
||
482 | } |
||
483 | |||
484 | 4147 | fjp | /**
|
485 | * @return Returns the editionManager.
|
||
486 | */
|
||
487 | public static EditionManager getEditionManager() { |
||
488 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
489 | return cta.getEditionManager();
|
||
490 | 4147 | fjp | } |
491 | 5115 | caballero | |
492 | public static CADTool[] getCADTools() { |
||
493 | 6174 | caballero | return CADToolAdapter.getCADTools();
|
494 | 4892 | caballero | } |
495 | 4899 | caballero | |
496 | 5115 | caballero | public static void initFocus() { |
497 | 31496 | jjdelcerro | view = (DefaultViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
498 | 6604 | caballero | MapControl mapControl = view.getMapControl(); |
499 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
500 | 5164 | caballero | if (!mapControl.getNamesMapTools().containsKey("cadtooladapter")){ |
501 | 5874 | fjp | // StatusBarListener sbl=new StatusBarListener(view.getMapControl());
|
502 | // mapControl.addMapTool("cadtooladapter", new Behavior[]{adapter,new MouseMovementBehavior(sbl)});
|
||
503 | 30335 | jpiera | mapControl.addBehavior("cadtooladapter", cta);
|
504 | 5164 | caballero | } |
505 | 5560 | fjp | // view.getMapControl().setTool("cadtooladapter");
|
506 | 5478 | caballero | JEditTextArea jeta=view.getConsolePanel().getTxt(); |
507 | jeta.requestFocusInWindow(); |
||
508 | jeta.setCaretPosition(jeta.getText().length()); |
||
509 | 5257 | caballero | |
510 | 5115 | caballero | view.addConsoleListener("cad", new ResponseListener() { |
511 | public void acceptResponse(String response) { |
||
512 | 6174 | caballero | CADToolAdapter cta=getCADToolAdapter(); |
513 | cta.textEntered(response); |
||
514 | 5115 | caballero | // TODO:
|
515 | // FocusManager fm=FocusManager.getCurrentManager();
|
||
516 | // fm.focusPreviousComponent(mapControl);
|
||
517 | /*
|
||
518 | * if (popup.isShowing()){ popup.setVisible(false); }
|
||
519 | */
|
||
520 | |||
521 | } |
||
522 | }); |
||
523 | 6174 | caballero | cta.getEditionManager().setMapControl(mapControl); |
524 | 5115 | caballero | view.getMapControl().setTool("cadtooladapter");
|
525 | 4899 | caballero | } |
526 | 11434 | caballero | |
527 | public IPreference[] getPreferencesPages() { |
||
528 | IPreference[] preferences=new IPreference[1]; |
||
529 | preferences[0]=editingPage;
|
||
530 | return preferences;
|
||
531 | } |
||
532 | 3712 | caballero | } |