86 |
86 |
* @author Vicente Caballero Navarro
|
87 |
87 |
*/
|
88 |
88 |
public class CADExtension extends Extension {
|
89 |
|
private static CADToolAdapter adapter = new CADToolAdapter();
|
|
89 |
private static HashMap adapters=new HashMap();
|
90 |
90 |
|
91 |
|
private static EditionManager editionManager = new EditionManager();
|
92 |
|
|
93 |
|
private static HashMap namesCadTools = new HashMap();
|
94 |
|
|
95 |
|
// /private MapControl mapControl;
|
96 |
91 |
private static View view;
|
97 |
92 |
|
98 |
93 |
private MapControl mapControl;
|
99 |
94 |
|
100 |
95 |
public static CADToolAdapter getCADToolAdapter() {
|
101 |
|
return adapter;
|
|
96 |
com.iver.andami.ui.mdiManager.View view=(com.iver.andami.ui.mdiManager.View)PluginServices.getMDIManager().getActiveView();
|
|
97 |
if (view instanceof View) {
|
|
98 |
View v=(View)view;
|
|
99 |
if (!adapters.containsKey(v)) {
|
|
100 |
adapters.put(v,new CADToolAdapter());
|
|
101 |
}
|
|
102 |
return (CADToolAdapter)adapters.get(v);
|
|
103 |
}
|
|
104 |
return null;
|
|
105 |
|
102 |
106 |
}
|
103 |
107 |
|
104 |
108 |
/**
|
... | ... | |
170 |
174 |
|| s.equals("_chaflan") || s.equals("_join")) {
|
171 |
175 |
setCADTool(s, true);
|
172 |
176 |
}
|
173 |
|
adapter.configureMenu();
|
|
177 |
CADToolAdapter cta=getCADToolAdapter();
|
|
178 |
cta.configureMenu();
|
174 |
179 |
}
|
175 |
180 |
|
176 |
181 |
public static void addCADTool(String name, CADTool c) {
|
177 |
|
namesCadTools.put(name, c);
|
|
182 |
CADToolAdapter.addCADTool(name, c);
|
178 |
183 |
}
|
179 |
184 |
|
180 |
185 |
public static void setCADTool(String text, boolean showCommand) {
|
181 |
|
CADTool ct = (CADTool) namesCadTools.get(text);
|
|
186 |
CADToolAdapter cta=getCADToolAdapter();
|
|
187 |
CADTool ct=cta.getCADTool(text);
|
|
188 |
|
182 |
189 |
if (ct == null)
|
183 |
190 |
throw new RuntimeException("No such cad tool");
|
184 |
|
adapter.setCadTool(ct);
|
|
191 |
cta.setCadTool(ct);
|
185 |
192 |
ct.init();
|
186 |
193 |
if (showCommand) {
|
187 |
194 |
if (PluginServices.getMDIManager().getActiveView() instanceof View) {
|
188 |
195 |
View vista = (View) PluginServices.getMDIManager().getActiveView();
|
189 |
196 |
vista.getConsolePanel().addText("\n" + ct.getName(),
|
190 |
197 |
JConsole.COMMAND);
|
191 |
|
adapter.askQuestion();
|
|
198 |
cta.askQuestion();
|
192 |
199 |
}
|
193 |
200 |
}
|
194 |
201 |
// PluginServices.getMainFrame().setSelectedTool("SELECT");
|
... | ... | |
196 |
203 |
}
|
197 |
204 |
|
198 |
205 |
public static CADTool getCADTool() {
|
199 |
|
return adapter.getCadTool();
|
|
206 |
CADToolAdapter cta=getCADToolAdapter();
|
|
207 |
return cta.getCadTool();
|
200 |
208 |
}
|
201 |
209 |
|
202 |
210 |
/**
|
... | ... | |
224 |
232 |
}
|
225 |
233 |
|
226 |
234 |
public MapControl getMapControl() {
|
227 |
|
return editionManager.getMapControl();
|
|
235 |
return getEditionManager().getMapControl();
|
228 |
236 |
}
|
229 |
237 |
|
230 |
238 |
class KeyAction extends AbstractAction {
|
... | ... | |
257 |
265 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
258 |
266 |
*/
|
259 |
267 |
public void actionPerformed(ActionEvent e) {
|
260 |
|
adapter.keyPressed(actionCommand);
|
|
268 |
CADToolAdapter cta=getCADToolAdapter();
|
|
269 |
cta.keyPressed(actionCommand);
|
261 |
270 |
}
|
262 |
271 |
|
263 |
272 |
}
|
... | ... | |
272 |
281 |
|
273 |
282 |
public boolean postProcessKeyEvent(KeyEvent e) {
|
274 |
283 |
// System.out.println("KeyEvent e = " + e);
|
275 |
|
if ((adapter == null) || (view == null))
|
|
284 |
CADToolAdapter cta=getCADToolAdapter();
|
|
285 |
if ((cta == null) || (view == null))
|
276 |
286 |
return false;
|
277 |
287 |
|
278 |
288 |
if (e.getID() != KeyEvent.KEY_RELEASED)
|
279 |
289 |
return false;
|
280 |
290 |
if (!(e.getComponent() instanceof JTextComponent)) {
|
281 |
291 |
if (e.getKeyCode() == KeyEvent.VK_DELETE)
|
282 |
|
adapter.keyPressed("eliminar");
|
|
292 |
cta.keyPressed("eliminar");
|
283 |
293 |
else if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
|
284 |
|
adapter.keyPressed("escape");
|
|
294 |
cta.keyPressed("escape");
|
285 |
295 |
else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
286 |
296 |
// TODO: REVISAR ESTO CUANDO VIENE UN INTRO DESDE UN
|
287 |
297 |
// JTEXTAREA
|
... | ... | |
353 |
363 |
menu.setVisible(true);
|
354 |
364 |
menu.addActionListener(new ActionListener() {
|
355 |
365 |
public void actionPerformed(ActionEvent e) {
|
356 |
|
adapter.transition(e.getActionCommand());
|
|
366 |
CADToolAdapter cta=getCADToolAdapter();
|
|
367 |
cta.transition(e.getActionCommand());
|
357 |
368 |
}
|
358 |
369 |
});
|
359 |
370 |
|
... | ... | |
372 |
383 |
* @return Returns the editionManager.
|
373 |
384 |
*/
|
374 |
385 |
public static EditionManager getEditionManager() {
|
375 |
|
return editionManager;
|
|
386 |
CADToolAdapter cta=getCADToolAdapter();
|
|
387 |
return cta.getEditionManager();
|
376 |
388 |
}
|
377 |
389 |
|
378 |
390 |
public static CADTool[] getCADTools() {
|
379 |
|
return (CADTool[]) namesCadTools.values().toArray(new CADTool[0]);
|
|
391 |
return CADToolAdapter.getCADTools();
|
380 |
392 |
}
|
381 |
393 |
|
382 |
394 |
public static void initFocus() {
|
383 |
395 |
view = (View) PluginServices.getMDIManager().getActiveView();
|
384 |
396 |
MapControl mapControl = (MapControl) view.getMapControl();
|
|
397 |
CADToolAdapter cta=getCADToolAdapter();
|
385 |
398 |
if (!mapControl.getNamesMapTools().containsKey("cadtooladapter")){
|
386 |
399 |
// StatusBarListener sbl=new StatusBarListener(view.getMapControl());
|
387 |
400 |
// mapControl.addMapTool("cadtooladapter", new Behavior[]{adapter,new MouseMovementBehavior(sbl)});
|
388 |
|
mapControl.addMapTool("cadtooladapter", adapter);
|
|
401 |
mapControl.addMapTool("cadtooladapter", cta);
|
389 |
402 |
}
|
390 |
403 |
// view.getMapControl().setTool("cadtooladapter");
|
391 |
404 |
JEditTextArea jeta=view.getConsolePanel().getTxt();
|
... | ... | |
394 |
407 |
|
395 |
408 |
view.addConsoleListener("cad", new ResponseListener() {
|
396 |
409 |
public void acceptResponse(String response) {
|
397 |
|
adapter.textEntered(response);
|
|
410 |
CADToolAdapter cta=getCADToolAdapter();
|
|
411 |
cta.textEntered(response);
|
398 |
412 |
// TODO:
|
399 |
413 |
// FocusManager fm=FocusManager.getCurrentManager();
|
400 |
414 |
// fm.focusPreviousComponent(mapControl);
|
... | ... | |
404 |
418 |
|
405 |
419 |
}
|
406 |
420 |
});
|
407 |
|
editionManager.setMapControl(mapControl);
|
|
421 |
cta.getEditionManager().setMapControl(mapControl);
|
408 |
422 |
view.getMapControl().setTool("cadtooladapter");
|
409 |
423 |
}
|
410 |
424 |
}
|