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