svn-gvsig-desktop / branches / Andami_CAD / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / MDIFrame.java @ 3513
History | View | Annotate | Download (34 KB)
1 |
/* 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.andami.ui.mdiFrame; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.Insets; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.awt.event.ComponentEvent; |
51 |
import java.awt.event.ComponentListener; |
52 |
import java.awt.event.ContainerEvent; |
53 |
import java.awt.event.ContainerListener; |
54 |
import java.awt.event.MouseAdapter; |
55 |
import java.awt.event.MouseEvent; |
56 |
import java.awt.event.WindowAdapter; |
57 |
import java.awt.event.WindowEvent; |
58 |
import java.net.URL; |
59 |
import java.util.ArrayList; |
60 |
import java.util.HashMap; |
61 |
import java.util.Iterator; |
62 |
import java.util.NoSuchElementException; |
63 |
import java.util.Vector; |
64 |
|
65 |
import javax.swing.AbstractButton; |
66 |
import javax.swing.ButtonGroup; |
67 |
import javax.swing.FocusManager; |
68 |
import javax.swing.ImageIcon; |
69 |
import javax.swing.JComponent; |
70 |
import javax.swing.JDesktopPane; |
71 |
import javax.swing.JFrame; |
72 |
import javax.swing.JLabel; |
73 |
import javax.swing.JMenu; |
74 |
import javax.swing.JMenuBar; |
75 |
import javax.swing.JOptionPane; |
76 |
import javax.swing.JPanel; |
77 |
import javax.swing.JPopupMenu; |
78 |
import javax.swing.KeyStroke; |
79 |
import javax.swing.MenuElement; |
80 |
import javax.swing.SwingUtilities; |
81 |
import javax.swing.Timer; |
82 |
|
83 |
import org.apache.log4j.Logger; |
84 |
|
85 |
import com.iver.andami.Launcher; |
86 |
import com.iver.andami.PluginServices; |
87 |
import com.iver.andami.messages.Messages; |
88 |
import com.iver.andami.messages.NotificationManager; |
89 |
import com.iver.andami.plugins.ExtensionDecorator; |
90 |
import com.iver.andami.plugins.PluginClassLoader; |
91 |
import com.iver.andami.plugins.config.generate.ActionTool; |
92 |
import com.iver.andami.plugins.config.generate.Label; |
93 |
import com.iver.andami.plugins.config.generate.Menu; |
94 |
import com.iver.andami.plugins.config.generate.PopupMenu; |
95 |
import com.iver.andami.plugins.config.generate.SelectableTool; |
96 |
import com.iver.andami.plugins.config.generate.SkinExtensionType; |
97 |
import com.iver.andami.plugins.config.generate.ToolBar; |
98 |
import com.iver.andami.ui.mdiManager.MDIManager; |
99 |
import com.iver.andami.ui.mdiManager.MDIManagerFactory; |
100 |
import com.iver.utiles.console.ResponseListener; |
101 |
|
102 |
|
103 |
/**
|
104 |
* Frame principal de la aplicaci?n.
|
105 |
*
|
106 |
* @version $Revision: 3513 $
|
107 |
*/
|
108 |
public class MDIFrame extends JFrame implements ComponentListener, |
109 |
ContainerListener, ActionListener, MainFrame { |
110 |
/** DOCUMENT ME! */
|
111 |
private static Logger logger = Logger.getLogger(MDIFrame.class.getName()); |
112 |
private MDIManager mdiManager = MDIManagerFactory.createManager();
|
113 |
|
114 |
/** Elementos de la aplicaci?n */
|
115 |
private JMenuBar menuBar = new JMenuBar(); |
116 |
|
117 |
/** DOCUMENT ME! */
|
118 |
private JPanel toolBars = new JPanel(); |
119 |
|
120 |
/** DOCUMENT ME! */
|
121 |
private NewStatusBar bEstado = null; |
122 |
|
123 |
/** Asocia los nombres con las barras de herramientas */
|
124 |
private HashMap toolBarMap = new HashMap(); |
125 |
|
126 |
/**
|
127 |
* actionCommand del tool seleccionado
|
128 |
*/
|
129 |
private String selectedTool; |
130 |
|
131 |
/** Asocia los nombres con los popupMenus */
|
132 |
private HashMap popupMap = new HashMap(); |
133 |
|
134 |
/** Asocia controles con la clase de la extension asociada */
|
135 |
private HashMap controlClass = new HashMap(); |
136 |
|
137 |
/**
|
138 |
* Asocia la informaci?n sobre las etiquetas que van en la status bar con
|
139 |
* cada extension
|
140 |
*/
|
141 |
private HashMap classLabels = new HashMap(); |
142 |
|
143 |
/** ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener) */
|
144 |
private ArrayList progressListeners = new ArrayList(); |
145 |
|
146 |
/** Timer para invocar los enventos de la interfaz anterior */
|
147 |
private Timer progressTimer = null; |
148 |
|
149 |
/** Tabla hash que asocia las clases con las extensiones */
|
150 |
private HashMap classesExtensions = new HashMap(); |
151 |
|
152 |
/** ?ltima clase que activ? etiquetas */
|
153 |
private Class lastLabelClass; |
154 |
|
155 |
/** Instancia que pone los tooltip en la barra de estado */
|
156 |
private TooltipListener tooltipListener = new TooltipListener(); |
157 |
private HashMap infoCodedMenus = new HashMap(); |
158 |
|
159 |
private String titlePrefix; |
160 |
private ButtonGroup buttonGroup=new ButtonGroup(); |
161 |
private ComplexDesktopPane desktopPane = new ComplexDesktopPane(); |
162 |
/** Adaptador de los listeners de la consola */
|
163 |
private ResponseAdapter consoleResponseAdapter = new ResponseAdapter(); |
164 |
|
165 |
/**
|
166 |
* Realiza tareas para poner en marcha la aplicaci?n
|
167 |
*
|
168 |
* @throws RuntimeException DOCUMENT ME!
|
169 |
*/
|
170 |
public void init() { |
171 |
if (!SwingUtilities.isEventDispatchThread()) { |
172 |
throw new RuntimeException("Not Event Dispatch Thread"); |
173 |
} |
174 |
|
175 |
//Se a?aden los listeners del JFrame
|
176 |
this.addWindowListener(new WindowAdapter() { |
177 |
public void windowClosing(WindowEvent e) { |
178 |
/*JOptionPane dlgSalir = new JOptionPane(Utilities.getMessage(this,"quiere_salir"),
|
179 |
JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
180 |
*/
|
181 |
int option = JOptionPane.showConfirmDialog(MDIFrame.this, |
182 |
Messages.getString("MDIFrame.quiere_salir"),
|
183 |
Messages.getString("MDIFrame.salir"),
|
184 |
JOptionPane.YES_NO_OPTION);
|
185 |
|
186 |
if (option == JOptionPane.YES_OPTION) { |
187 |
Launcher.closeApplication(); |
188 |
} |
189 |
} |
190 |
}); |
191 |
this.addComponentListener(this); |
192 |
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
193 |
|
194 |
//Se configura la barra de menu
|
195 |
setJMenuBar(menuBar); |
196 |
|
197 |
//Se configura el layout del JFrame principal
|
198 |
this.getContentPane().setLayout(new BorderLayout()); |
199 |
|
200 |
/*
|
201 |
* Se configura y se a?ade el JPanel de las barras de
|
202 |
* herramientas
|
203 |
*/
|
204 |
FlowLayout layout = new FlowLayout(FlowLayout.LEFT); |
205 |
layout.setHgap(0);
|
206 |
layout.setVgap(0);
|
207 |
toolBars.setLayout(layout); |
208 |
getContentPane().add(toolBars, BorderLayout.PAGE_START);
|
209 |
|
210 |
// Se a?ade la barra de estado a la aplicaci?n
|
211 |
bEstado = new NewStatusBar();
|
212 |
bEstado.setInfoText(Messages.getString("StatusBar.Aplicacion_iniciada"));
|
213 |
getContentPane().add(bEstado, BorderLayout.SOUTH);
|
214 |
|
215 |
this.toolBars.addContainerListener(this); |
216 |
|
217 |
pack(); |
218 |
|
219 |
this.setSize(500, 500); |
220 |
this.setExtendedState(MAXIMIZED_BOTH);
|
221 |
mdiManager.init(this);
|
222 |
|
223 |
|
224 |
//getContentPane().add(desktopPane, BorderLayout.CENTER);
|
225 |
|
226 |
//desktopPane.getConsole().addResponseListener(consoleResponseAdapter);
|
227 |
} |
228 |
/**
|
229 |
* @return
|
230 |
*/
|
231 |
public JDesktopPane getDesktopPane() { |
232 |
return desktopPane.getDesktopPane();
|
233 |
} |
234 |
public void setTitle(String title) { |
235 |
super.setTitle(titlePrefix + ":" + title); |
236 |
} |
237 |
|
238 |
/**
|
239 |
* A?ade un modo de operaci?n a la caja de herramientas
|
240 |
*
|
241 |
* @param ext Texto del boton, si es null no aparece texto
|
242 |
* @param ext Icono del boton, si es null no aparece icono
|
243 |
* @param ext Extensi?n asociada al control
|
244 |
* @param selectableTool Enable text del control
|
245 |
*
|
246 |
* @throws ClassNotFoundException
|
247 |
* @throws RuntimeException DOCUMENT ME!
|
248 |
*/
|
249 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
250 |
ToolBar toolBar, SelectableTool selectableTool) |
251 |
throws ClassNotFoundException { |
252 |
if (!SwingUtilities.isEventDispatchThread()) { |
253 |
throw new RuntimeException("No Event Dispatch Thread"); |
254 |
} |
255 |
|
256 |
// Para traducir
|
257 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
258 |
|
259 |
JToggleButton btn;
|
260 |
URL image = loader.getResource(selectableTool.getIcon());
|
261 |
|
262 |
if (image != null) { |
263 |
btn = new JToggleButton(selectableTool.getText(), |
264 |
new ImageIcon(image)); |
265 |
} else {
|
266 |
btn = new JToggleButton(selectableTool.getText()); |
267 |
} |
268 |
|
269 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
270 |
btn.addMouseListener(tooltipListener); |
271 |
btn.addActionListener(this);
|
272 |
btn.setFocusable(false);
|
273 |
btn.setActionCommand(selectableTool.getActionCommand()); |
274 |
btn.setToolTipText(selectableTool.getTooltip()); |
275 |
btn.setEnabled(false);
|
276 |
btn.setVisible(false);
|
277 |
|
278 |
if (selectableTool.getIsDefault()) {
|
279 |
btn.setSelected(true);
|
280 |
selectedTool = btn.getActionCommand(); |
281 |
} |
282 |
|
283 |
String name = getName(toolBar.getName(), loader);
|
284 |
|
285 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
286 |
|
287 |
if (jtb == null) { |
288 |
jtb = new SelectableToolBar(toolBar.getName());
|
289 |
jtb.setRollover(true);
|
290 |
toolBarMap.put(name, jtb); |
291 |
toolBars.add(jtb); |
292 |
} |
293 |
|
294 |
jtb.addButton(buttonGroup, btn); |
295 |
|
296 |
controlClass.put(btn, loader.loadClass(ext.getClassName())); |
297 |
|
298 |
if (selectableTool.getTooltip() != null) { |
299 |
btn.setToolTip(ps.getText(selectableTool.getTooltip())); |
300 |
} |
301 |
|
302 |
if (selectableTool.getEnableText() != null) { |
303 |
btn.setEnableText(ps.getText(selectableTool.getEnableText())); |
304 |
} |
305 |
|
306 |
if (selectableTool.getLast() == true) { |
307 |
jtb.addSeparator(); |
308 |
} |
309 |
} |
310 |
|
311 |
/**
|
312 |
* A?ade un bot?n a la barra de herramientas
|
313 |
*
|
314 |
* @param ext Texto del boton, si es null no aparece texto
|
315 |
* @param ext Extensi?n asociada al control
|
316 |
* @param toolBar Icono del boton, si es null no aparece texto
|
317 |
* @param actionTool Tooltip de la barra de herramientas
|
318 |
*
|
319 |
* @throws ClassNotFoundException
|
320 |
* @throws RuntimeException DOCUMENT ME!
|
321 |
*/
|
322 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
323 |
ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException { |
324 |
if (!SwingUtilities.isEventDispatchThread()) { |
325 |
throw new RuntimeException("No Event Dispatch Thread"); |
326 |
} |
327 |
|
328 |
// Para traducir los textos que vengan
|
329 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
330 |
|
331 |
JButton btn;
|
332 |
URL image = loader.getResource(actionTool.getIcon());
|
333 |
|
334 |
if (image != null) { |
335 |
btn = new JButton(actionTool.getText(), new ImageIcon(image)); |
336 |
} else {
|
337 |
btn = new JButton(actionTool.getText()); |
338 |
} |
339 |
|
340 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
341 |
btn.addMouseListener(tooltipListener); |
342 |
btn.addActionListener(this);
|
343 |
btn.setFocusable(false);
|
344 |
btn.setActionCommand(actionTool.getActionCommand()); |
345 |
btn.setEnabled(false);
|
346 |
btn.setVisible(false);
|
347 |
|
348 |
String name = getName(toolBar.getName(), loader);
|
349 |
|
350 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
351 |
|
352 |
if (jtb == null) { |
353 |
jtb = new SelectableToolBar(toolBar.getName());
|
354 |
jtb.setRollover(true);
|
355 |
toolBarMap.put(name, jtb); |
356 |
toolBars.add(jtb); |
357 |
} |
358 |
|
359 |
jtb.add(btn); |
360 |
|
361 |
controlClass.put(btn, loader.loadClass(ext.getClassName())); |
362 |
|
363 |
if (actionTool.getTooltip() != null) { |
364 |
btn.setToolTip(ps.getText(actionTool.getTooltip())); |
365 |
} |
366 |
|
367 |
if (actionTool.getEnableText() != null) { |
368 |
btn.setEnableText(ps.getText(actionTool.getEnableText())); |
369 |
} |
370 |
|
371 |
if (actionTool.getLast() == true) { |
372 |
jtb.addSeparator(); |
373 |
} |
374 |
} |
375 |
|
376 |
/**
|
377 |
* Crea la estructura de men?s necesaria para a?adir el menu a la barra.
|
378 |
* Devuelve el padre del cual deve colgar el menu que se pasa como
|
379 |
* par?metro
|
380 |
*
|
381 |
* @param menu Menu cuya soporte se quiere a?adir
|
382 |
* @param loader DOCUMENT ME!
|
383 |
*
|
384 |
* @return Padre del men? que se pasa como par?metro
|
385 |
*/
|
386 |
private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) { |
387 |
JMenu menuPadre = null; |
388 |
|
389 |
String[] menues = menu.getText().split("/"); |
390 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
391 |
|
392 |
for (int i = 0; i < menues.length; i++) { |
393 |
menues[i] = ps.getText(menues[i]); |
394 |
} |
395 |
|
396 |
//Se busca el padre en la menuBar
|
397 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
398 |
if (menuBar.getMenu(i).getText().compareToIgnoreCase(menues[0]) == 0) { |
399 |
menuPadre = (JMenu) menuBar.getMenu(i);
|
400 |
} |
401 |
} |
402 |
|
403 |
//Si no se encuentra el padre se crea
|
404 |
if (menuPadre == null) { |
405 |
menuPadre = new JMenu(menues[0]); |
406 |
menuBar.add(menuPadre); |
407 |
} |
408 |
|
409 |
//Se crea el resto de menus
|
410 |
Vector temp = new Vector(); |
411 |
|
412 |
for (int i = 1; i < (menues.length - 1); i++) { |
413 |
temp.add(menues[i]); |
414 |
} |
415 |
|
416 |
menuPadre = createMenus(temp, menuPadre); |
417 |
|
418 |
return menuPadre;
|
419 |
} |
420 |
|
421 |
/**
|
422 |
* A?ade la informaci?n del menu al framework. Debido a que los men?es se
|
423 |
* pueden introducir en un orden determinado por el usuario, pero los
|
424 |
* plugins se instalan en un orden arbitrario, primero se almacena la
|
425 |
* informaci?n de todos los menus para luego ordenarlos y posteriormente
|
426 |
* a?adirlos al interfaz
|
427 |
*
|
428 |
* @param loader Posicion del menu. Se ordena por este campo
|
429 |
* @param ext Array con los nombres de los padres del menu
|
430 |
* @param menu Texto del menu
|
431 |
*
|
432 |
* @throws ClassNotFoundException
|
433 |
* @throws RuntimeException DOCUMENT ME!
|
434 |
*/
|
435 |
public void addMenu(PluginClassLoader loader, SkinExtensionType ext, |
436 |
Menu menu) throws ClassNotFoundException { |
437 |
if (!SwingUtilities.isEventDispatchThread()) { |
438 |
throw new RuntimeException("No Event Dispatch Thread"); |
439 |
} |
440 |
|
441 |
JMenu menuPadre = createMenuAncestors(menu, loader);
|
442 |
|
443 |
//Se registra y a?ade el menu
|
444 |
/* String[] aux = menu.getText().split("/");
|
445 |
|
446 |
if (aux.length == 2)
|
447 |
if (aux[1].equals("----"))
|
448 |
{
|
449 |
menuPadre.addSeparator();
|
450 |
return;
|
451 |
} */
|
452 |
if (menu.getIs_separator())
|
453 |
{ |
454 |
menuPadre.addSeparator(); |
455 |
return;
|
456 |
} |
457 |
|
458 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
459 |
nuevoMenu.addMouseListener(tooltipListener); |
460 |
nuevoMenu.addActionListener(this);
|
461 |
menuPadre.add(nuevoMenu); |
462 |
controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName())); |
463 |
} |
464 |
|
465 |
/**
|
466 |
* Dado un array de nombres de menu traducidos, encuentra el men?
|
467 |
*
|
468 |
* @param nombres DOCUMENT ME!
|
469 |
* @param padre DOCUMENT ME!
|
470 |
*
|
471 |
* @return DOCUMENT ME!
|
472 |
*/
|
473 |
private javax.swing.JMenuItem getMenu(Vector nombres, JMenu padre) { |
474 |
javax.swing.JMenuItem buscado = null;
|
475 |
|
476 |
for (int i = 0; i < padre.getMenuComponentCount(); i++) { |
477 |
javax.swing.JMenuItem hijo = (javax.swing.JMenuItem) padre.getMenuComponent(i); |
478 |
|
479 |
if (hijo.getText().compareToIgnoreCase((String) nombres.get(0)) == 0) { |
480 |
buscado = hijo; |
481 |
} |
482 |
} |
483 |
|
484 |
//Si no se encuentra el menu
|
485 |
if (buscado == null) { |
486 |
return null; |
487 |
} |
488 |
|
489 |
nombres.remove(0);
|
490 |
|
491 |
//Si se ha llegado al fin de la ruta completa
|
492 |
if (nombres.isEmpty()) {
|
493 |
return buscado;
|
494 |
} else {
|
495 |
if (buscado instanceof JMenu) { |
496 |
return getMenu(nombres, (JMenu) buscado); |
497 |
} else {
|
498 |
return null; |
499 |
} |
500 |
} |
501 |
} |
502 |
|
503 |
/**
|
504 |
* Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
|
505 |
* en el par?metro nombres el array {"Search", "References", "Workspace"}
|
506 |
* crear? un men? Search, un submen? del anterior que se llamar?
|
507 |
* References y debajo de ?ste ?ltimo otro menu llamado Workspace
|
508 |
*
|
509 |
* @param nombres Array con los nombres de los men?s que se quieren crear
|
510 |
* @param padre Menu padre de los men?s creados. Es ?til porque es un
|
511 |
* algoritmo recursivo
|
512 |
*
|
513 |
* @return Devuelve el men? creado. Al final de toda la recursividad,
|
514 |
* devolver? el men? de m?s abajo en la jerarqu?a
|
515 |
*
|
516 |
* @throws RuntimeException DOCUMENT ME!
|
517 |
*/
|
518 |
private JMenu createMenus(Vector nombres, JMenu padre) { |
519 |
if (!SwingUtilities.isEventDispatchThread()) { |
520 |
throw new RuntimeException("No Event Dispatch Thread"); |
521 |
} |
522 |
|
523 |
//si no quedan nombres de menu por crear se vuelve: caso base
|
524 |
if (nombres.size() == 0) { |
525 |
return padre;
|
526 |
} |
527 |
|
528 |
//Se busca el menu por si ya existiera para no crearlo otra vez
|
529 |
JMenu buscado = null; |
530 |
|
531 |
for (int i = 0; i < padre.getMenuComponentCount(); i++) { |
532 |
try {
|
533 |
JMenu hijo = (JMenu) padre.getMenuComponent(i); |
534 |
|
535 |
if (hijo.getText().compareToIgnoreCase((String) nombres.get(0)) == 0) { |
536 |
buscado = hijo; |
537 |
} |
538 |
} catch (ClassCastException e) { |
539 |
/*
|
540 |
* Se ha encontrado un elemento hoja del arbol de men?es
|
541 |
*/
|
542 |
} |
543 |
} |
544 |
|
545 |
if (buscado != null) { |
546 |
//Si lo hemos encontrado creamos el resto
|
547 |
nombres.remove(0);
|
548 |
|
549 |
return createMenus(nombres, buscado);
|
550 |
} else {
|
551 |
//Si no lo hemos encontrado se crea el menu, se a?ade al padre
|
552 |
//y se crea el resto
|
553 |
JMenu menuPadre = new JMenu((String) nombres.get(0)); |
554 |
padre.add(menuPadre); |
555 |
|
556 |
nombres.remove(0);
|
557 |
|
558 |
return createMenus(nombres, menuPadre);
|
559 |
} |
560 |
} |
561 |
|
562 |
/**
|
563 |
* M?todo invocado en respuesta a ciertos eventos de la interfaz que pueden
|
564 |
* ocultar botones de las barras de herramientas y que redimensiona ?sta
|
565 |
* de manera conveniente para que no se oculte ninguno
|
566 |
*/
|
567 |
private void ajustarToolBar() { |
568 |
int margen = 8; |
569 |
int numFilas = 1; |
570 |
double acum = margen;
|
571 |
|
572 |
int toolHeight = 0; |
573 |
|
574 |
for (int i = 0; i < toolBars.getComponentCount(); i++) { |
575 |
Component c = toolBars.getComponent(i);
|
576 |
|
577 |
if (!c.isVisible()) {
|
578 |
continue;
|
579 |
} |
580 |
|
581 |
double width = c.getPreferredSize().getWidth();
|
582 |
acum = acum + width; |
583 |
|
584 |
if (acum > this.getWidth()) { |
585 |
numFilas++; |
586 |
acum = width + margen; |
587 |
} |
588 |
|
589 |
if (c.getPreferredSize().getHeight() > toolHeight) {
|
590 |
toolHeight = c.getPreferredSize().height; |
591 |
} |
592 |
} |
593 |
|
594 |
toolBars.setPreferredSize(new Dimension(this.getWidth(), |
595 |
(int) (numFilas * toolHeight)));
|
596 |
|
597 |
toolBars.updateUI(); |
598 |
} |
599 |
|
600 |
/**
|
601 |
* DOCUMENT ME!
|
602 |
*
|
603 |
* @param classesExtensions
|
604 |
*/
|
605 |
public void setClassesExtensions(HashMap classesExtensions) { |
606 |
this.classesExtensions = classesExtensions;
|
607 |
} |
608 |
|
609 |
/**
|
610 |
* M?todo de callback invocado cuando se selecciona un men? o un bot?n de
|
611 |
* la barra de herramientas. Se busca la extensi?n asociada y se ejecuta
|
612 |
*
|
613 |
* @param e Evento producido
|
614 |
*/
|
615 |
public void actionPerformed(ActionEvent e) { |
616 |
AbstractButton control = (AbstractButton) e.getSource(); |
617 |
com.iver.andami.plugins.Extension ext = (com.iver.andami.plugins.Extension) classesExtensions.get((Class) controlClass.get(
|
618 |
control)); |
619 |
String actionCommand = control.getActionCommand();
|
620 |
|
621 |
try {
|
622 |
ext.execute(actionCommand); |
623 |
if (control instanceof JToggleButton) |
624 |
{ |
625 |
selectedTool = actionCommand; |
626 |
} |
627 |
} catch (RuntimeException t) { |
628 |
NotificationManager.addError(Messages.getString( |
629 |
"MDIFrame.Error_no_capturado_por_el_usuario"), t);
|
630 |
} |
631 |
|
632 |
enableControls(); |
633 |
showMemory(); |
634 |
} |
635 |
|
636 |
/**
|
637 |
* DOCUMENT ME!
|
638 |
*
|
639 |
* @param name DOCUMENT ME!
|
640 |
* @param loader DOCUMENT ME!
|
641 |
*
|
642 |
* @return DOCUMENT ME!
|
643 |
*/
|
644 |
private String getName(String name, PluginClassLoader loader) { |
645 |
if (name.indexOf('.') == -1) { |
646 |
return loader.getPluginName() + "." + name; |
647 |
} else {
|
648 |
return name;
|
649 |
} |
650 |
} |
651 |
|
652 |
/**
|
653 |
* DOCUMENT ME!
|
654 |
*
|
655 |
* @param loader DOCUMENT ME!
|
656 |
* @param menu DOCUMENT ME!
|
657 |
*
|
658 |
* @throws RuntimeException DOCUMENT ME!
|
659 |
*/
|
660 |
public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) { |
661 |
if (!SwingUtilities.isEventDispatchThread()) { |
662 |
throw new RuntimeException("No Event Dispatch Thread"); |
663 |
} |
664 |
|
665 |
String name = getName(menu.getName(), loader);
|
666 |
|
667 |
//Se crea el control popupmenu
|
668 |
JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name); |
669 |
|
670 |
if (popupMenu == null) { |
671 |
popupMenu = new JPopUpMenu(menu.getName());
|
672 |
popupMap.put(name, popupMenu); |
673 |
} |
674 |
|
675 |
// Se a?aden las entradas
|
676 |
Menu[] menues = menu.getMenu(); |
677 |
|
678 |
for (int i = 0; i < menues.length; i++) { |
679 |
//Se registra y a?ade el menu
|
680 |
JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
|
681 |
|
682 |
popupMenu.add(nuevoMenu); |
683 |
} |
684 |
} |
685 |
|
686 |
/**
|
687 |
* DOCUMENT ME!
|
688 |
*
|
689 |
* @param loader
|
690 |
* @param menu
|
691 |
*
|
692 |
* @return
|
693 |
*
|
694 |
* @throws RuntimeException DOCUMENT ME!
|
695 |
*/
|
696 |
private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) { |
697 |
JMenuItem nuevoMenu = null; |
698 |
|
699 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
700 |
String texto = menu.getText();
|
701 |
texto = texto.substring(texto.lastIndexOf('/') + 1); |
702 |
texto = ps.getText(texto); |
703 |
|
704 |
if (menu.getIcon() != null) { |
705 |
System.out.println("Intentando cargar el icono " + menu.getIcon()); |
706 |
nuevoMenu = new JMenuItem(texto, |
707 |
new ImageIcon(loader.getResource(menu.getIcon()))); |
708 |
} else {
|
709 |
nuevoMenu = new JMenuItem(texto); |
710 |
} |
711 |
|
712 |
if (menu.getMnemonic() != null) { |
713 |
if (menu.getMnemonic().length() != 1) { |
714 |
throw new RuntimeException( |
715 |
"Mnemonic must be 1 character length");
|
716 |
} |
717 |
|
718 |
nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic().charAt(0)));
|
719 |
} |
720 |
|
721 |
if (menu.getKey() != null) { |
722 |
nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping.getKey(
|
723 |
menu.getKey().charAt(0)), ActionEvent.CTRL_MASK)); |
724 |
} |
725 |
|
726 |
nuevoMenu.setActionCommand(menu.getActionCommand()); |
727 |
|
728 |
if (menu.getTooltip() != null) { |
729 |
nuevoMenu.setToolTip(ps.getText(menu.getTooltip())); |
730 |
} |
731 |
|
732 |
if (menu.getEnableText() != null) { |
733 |
nuevoMenu.setEnableText(ps.getText(menu.getEnableText())); |
734 |
} |
735 |
|
736 |
nuevoMenu.setEnabled(true);
|
737 |
nuevoMenu.setVisible(true);
|
738 |
|
739 |
return nuevoMenu;
|
740 |
} |
741 |
|
742 |
/**
|
743 |
* Muestra u oculta el menu de nombre 'name'
|
744 |
*
|
745 |
* @param name Nombre del menu que se quiere mostrar
|
746 |
* @param x Evento de raton
|
747 |
* @param y DOCUMENT ME!
|
748 |
* @param c DOCUMENT ME!
|
749 |
*/
|
750 |
private void showPopupMenu(String name, int x, int y, Component c) { |
751 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
752 |
|
753 |
if (menu != null) { |
754 |
menu.show(c, x, y); |
755 |
} |
756 |
} |
757 |
|
758 |
/**
|
759 |
* DOCUMENT ME!
|
760 |
*
|
761 |
* @param name DOCUMENT ME!
|
762 |
* @param listener DOCUMENT ME!
|
763 |
*/
|
764 |
public void removePopupMenuListener(String name, ActionListener listener) { |
765 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
766 |
|
767 |
if (menu != null) { |
768 |
Component[] jmenuitems = menu.getComponents(); |
769 |
|
770 |
for (int i = 0; i < jmenuitems.length; i++) { |
771 |
if (jmenuitems[i] instanceof JMenuItem) { |
772 |
((JMenuItem) jmenuitems[i]).removeActionListener(listener);
|
773 |
} |
774 |
} |
775 |
} |
776 |
} |
777 |
|
778 |
/**
|
779 |
* DOCUMENT ME!
|
780 |
*
|
781 |
* @param popupName
|
782 |
* @param c DOCUMENT ME!
|
783 |
* @param listener
|
784 |
* @param loader
|
785 |
*/
|
786 |
public void addPopupMenuListener(String popupName, Component c, |
787 |
ActionListener listener, PluginClassLoader loader) {
|
788 |
final String name = getName(popupName, loader); |
789 |
|
790 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
791 |
|
792 |
if (menu != null) { |
793 |
Component[] jmenuitems = menu.getComponents(); |
794 |
|
795 |
for (int i = 0; i < jmenuitems.length; i++) { |
796 |
if (jmenuitems[i] instanceof JMenuItem) { |
797 |
((JMenuItem) jmenuitems[i]).addActionListener(listener);
|
798 |
} |
799 |
} |
800 |
} |
801 |
|
802 |
c.addMouseListener(new MouseAdapter() { |
803 |
public void mousePressed(MouseEvent e) { |
804 |
if (e.isPopupTrigger()) {
|
805 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
806 |
} |
807 |
} |
808 |
|
809 |
public void mouseReleased(MouseEvent e) { |
810 |
if (e.isPopupTrigger()) {
|
811 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
812 |
} |
813 |
} |
814 |
}); |
815 |
} |
816 |
|
817 |
/**
|
818 |
* Itera por los controles preguntando a las extensiones si estos est?n
|
819 |
* habilitados y visibles
|
820 |
*
|
821 |
* @throws RuntimeException DOCUMENT ME!
|
822 |
*/
|
823 |
public void enableControls() { |
824 |
if (!SwingUtilities.isEventDispatchThread()) { |
825 |
throw new RuntimeException("No Event Dispatch Thread"); |
826 |
} |
827 |
|
828 |
Iterator e = classesExtensions.values().iterator();
|
829 |
HashMap estadoExtensiones = new HashMap(); |
830 |
HashMap visibilidadExtensiones = new HashMap(); |
831 |
|
832 |
while (e.hasNext()) {
|
833 |
ExtensionDecorator ext = (ExtensionDecorator) e.next(); |
834 |
|
835 |
try {
|
836 |
if (estadoExtensiones.get(ext) == null) { |
837 |
boolean b;
|
838 |
if (ext.getVisibility() == ExtensionDecorator.ALWAYS_VISIBLE)
|
839 |
b = true;
|
840 |
else if (ext.getVisibility() == ExtensionDecorator.ALWAYS_INVISIBLE) |
841 |
b = false;
|
842 |
else b = ext.isVisible();
|
843 |
Boolean visible = new Boolean(b); |
844 |
Boolean enabled = new Boolean(false); |
845 |
|
846 |
if (visible.booleanValue()) {
|
847 |
enabled = new Boolean(ext.isEnabled()); |
848 |
} |
849 |
|
850 |
estadoExtensiones.put(ext, enabled); |
851 |
visibilidadExtensiones.put(ext, visible); |
852 |
} |
853 |
} catch (Throwable e1) { |
854 |
NotificationManager.addError(Messages.getString( |
855 |
"MDIFrame.Error_no_capturado_por_el_usuario"), e1);
|
856 |
estadoExtensiones.put(ext, Boolean.FALSE);
|
857 |
} |
858 |
} |
859 |
|
860 |
//Se habilitan y deshabilitan los controles
|
861 |
e = controlClass.keySet().iterator(); |
862 |
|
863 |
while (e.hasNext()) {
|
864 |
JComponent control = (JComponent) e.next(); |
865 |
|
866 |
try {
|
867 |
com.iver.andami.plugins.Extension ext = (com.iver.andami.plugins.Extension) classesExtensions.get((Class) controlClass.get(
|
868 |
control)); |
869 |
boolean enabled = ((Boolean) estadoExtensiones.get(ext)).booleanValue(); |
870 |
boolean visible = ((Boolean) visibilidadExtensiones.get(ext)).booleanValue(); |
871 |
control.setEnabled(enabled); |
872 |
control.setVisible(visible); |
873 |
} catch (Exception ex) { |
874 |
control.setEnabled(false);
|
875 |
control.setVisible(false);
|
876 |
} |
877 |
} |
878 |
|
879 |
//Se itera por los men?es para ocultar los que no tengan hijos visibles
|
880 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
881 |
MenuElement menu = menuBar.getMenu(i);
|
882 |
ocultarMenus(menu); |
883 |
} |
884 |
|
885 |
//Se ocultan las barras que no tienen herramientas
|
886 |
Iterator it = toolBarMap.values().iterator();
|
887 |
|
888 |
while (it.hasNext()) {
|
889 |
SelectableToolBar t = (SelectableToolBar) it.next(); |
890 |
boolean todosOcultos = true; |
891 |
|
892 |
for (int i = 0; i < t.getComponentCount(); i++) { |
893 |
if (t.getComponent(i).isVisible()) {
|
894 |
todosOcultos = false;
|
895 |
} |
896 |
} |
897 |
|
898 |
if (todosOcultos) {
|
899 |
t.setVisible(false);
|
900 |
} else {
|
901 |
t.setVisible(true);
|
902 |
} |
903 |
} |
904 |
|
905 |
if (mdiManager != null) { |
906 |
JPanel f = (JPanel) mdiManager.getActiveView(); |
907 |
|
908 |
if (f != null) { |
909 |
if (lastLabelClass != f.getClass()) {
|
910 |
lastLabelClass = f.getClass(); |
911 |
|
912 |
Label[] lbls = (Label[]) classLabels.get(lastLabelClass); |
913 |
|
914 |
if (lbls != null) { |
915 |
bEstado.setLabelSet(lbls); |
916 |
} |
917 |
} |
918 |
} |
919 |
} |
920 |
|
921 |
ajustarToolBar(); |
922 |
|
923 |
showMemory(); |
924 |
} |
925 |
|
926 |
/**
|
927 |
* Establece la visibilidad de un menu y todos sus descendientes en la
|
928 |
* jerarquia teniendo en cuenta la visibilidad de todos los submenus.
|
929 |
*
|
930 |
* @param menu Menu que se quiere visualizar
|
931 |
*
|
932 |
* @return Devuelve true si el menu es visible y false en caso contrario
|
933 |
*/
|
934 |
private boolean ocultarMenus(MenuElement menu) { |
935 |
MenuElement[] submenus = menu.getSubElements(); |
936 |
|
937 |
//Si no tiene hijos se devuelve su visibilidad
|
938 |
if (submenus.length == 0) { |
939 |
return menu.getComponent().isVisible();
|
940 |
} |
941 |
|
942 |
/*
|
943 |
* Si tiene hijos se devuelve true si alg?no de ellos es visible,
|
944 |
* pero se itera por todos ellos
|
945 |
*/
|
946 |
boolean visible = false; |
947 |
|
948 |
for (int i = 0; i < submenus.length; i++) { |
949 |
if (ocultarMenus(submenus[i])) {
|
950 |
if (!(menu instanceof JPopupMenu)) { |
951 |
menu.getComponent().setVisible(true);
|
952 |
} |
953 |
|
954 |
visible = true;
|
955 |
} |
956 |
} |
957 |
|
958 |
if (visible) {
|
959 |
return true; |
960 |
} |
961 |
|
962 |
menu.getComponent().setVisible(false);
|
963 |
|
964 |
return false; |
965 |
} |
966 |
|
967 |
/**
|
968 |
* Muestra la memoria consumida por el programa
|
969 |
*/
|
970 |
private void showMemory() { |
971 |
Runtime r = Runtime.getRuntime(); |
972 |
long mem = r.totalMemory() - r.freeMemory();
|
973 |
logger.debug("Memoria total: " + mem);
|
974 |
} |
975 |
|
976 |
/**
|
977 |
* DOCUMENT ME!
|
978 |
*
|
979 |
* @return
|
980 |
*/
|
981 |
public MDIManager getMDIManager() {
|
982 |
return mdiManager;
|
983 |
} |
984 |
|
985 |
/**
|
986 |
* Establece el mensaje en la barra de estado asociado a una etiqueta
|
987 |
*
|
988 |
* @return DOCUMENT ME!
|
989 |
*/
|
990 |
public NewStatusBar getStatusBar() {
|
991 |
return bEstado;
|
992 |
} |
993 |
/**
|
994 |
* You can use this function to select the appropiate
|
995 |
* tool inside the toolbars
|
996 |
*/
|
997 |
public void setSelectedTool(String actionCommand) |
998 |
{ |
999 |
Iterator it = toolBarMap.values().iterator();
|
1000 |
while (it.hasNext()) {
|
1001 |
SelectableToolBar t = (SelectableToolBar) it.next(); |
1002 |
t.setSelectedTool(actionCommand); |
1003 |
} |
1004 |
selectedTool = actionCommand; |
1005 |
|
1006 |
} |
1007 |
|
1008 |
/**
|
1009 |
* DOCUMENT ME!
|
1010 |
*
|
1011 |
* @param clase
|
1012 |
* @param label
|
1013 |
*/
|
1014 |
public void setLabels(Class clase, Label[] label) { |
1015 |
classLabels.put(clase, label); |
1016 |
} |
1017 |
|
1018 |
/**
|
1019 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#removeMenu(com.iver.andami.plugins.config.generate.Menu)
|
1020 |
*/
|
1021 |
public void removeMenu(Menu menu) { |
1022 |
JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu); |
1023 |
|
1024 |
if (delete == null) { |
1025 |
throw new NoSuchElementException(menu.getText()); |
1026 |
} |
1027 |
|
1028 |
delete.getParent().remove(delete); |
1029 |
infoCodedMenus.remove(menu); |
1030 |
} |
1031 |
|
1032 |
/**
|
1033 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#addMenu(com.iver.andami.plugins.config.generate.Menu,
|
1034 |
* java.awt.event.ActionListener, PluginClassLoader)
|
1035 |
*/
|
1036 |
public void addMenu(Menu menu, ActionListener listener, |
1037 |
PluginClassLoader loader) { |
1038 |
JMenu menuPadre = createMenuAncestors(menu, loader);
|
1039 |
|
1040 |
//Se registra y a?ade el menu
|
1041 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
1042 |
nuevoMenu.addMouseListener(tooltipListener); |
1043 |
nuevoMenu.addActionListener(listener); |
1044 |
menuPadre.add(nuevoMenu); |
1045 |
|
1046 |
infoCodedMenus.put(menu, nuevoMenu); |
1047 |
} |
1048 |
|
1049 |
/**
|
1050 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#changeMenuName(java.lang.String[],
|
1051 |
* String, com.iver.andami.plugins.PluginClassLoader)
|
1052 |
*/
|
1053 |
public void changeMenuName(String[] menu, String newName, |
1054 |
PluginClassLoader loader) { |
1055 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
1056 |
|
1057 |
for (int i = 0; i < menu.length; i++) { |
1058 |
menu[i] = ps.getText(menu[i]); |
1059 |
} |
1060 |
|
1061 |
JMenu menuPadre = null; |
1062 |
|
1063 |
//Se busca el padre en la menuBar
|
1064 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
1065 |
if (menuBar.getMenu(i).getText().compareToIgnoreCase(menu[0]) == 0) { |
1066 |
menuPadre = (JMenu) menuBar.getMenu(i);
|
1067 |
} |
1068 |
} |
1069 |
|
1070 |
if (menuPadre == null) { |
1071 |
throw new NoSuchMenuException(menu[0]); |
1072 |
} |
1073 |
|
1074 |
Vector nombres = new Vector(); |
1075 |
|
1076 |
for (int i = 1; i < menu.length; i++) { |
1077 |
nombres.add(menu[i]); |
1078 |
} |
1079 |
|
1080 |
javax.swing.JMenuItem m = getMenu(nombres, menuPadre); |
1081 |
|
1082 |
if (m != null) { |
1083 |
m.setText(newName); |
1084 |
}else{
|
1085 |
throw new NoSuchMenuException(); |
1086 |
} |
1087 |
} |
1088 |
|
1089 |
/**
|
1090 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
1091 |
*/
|
1092 |
public void componentHidden(ComponentEvent arg0) { |
1093 |
} |
1094 |
|
1095 |
/**
|
1096 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
1097 |
*/
|
1098 |
public void componentMoved(ComponentEvent arg0) { |
1099 |
} |
1100 |
|
1101 |
/**
|
1102 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
1103 |
*/
|
1104 |
public void componentResized(ComponentEvent arg0) { |
1105 |
ajustarToolBar(); |
1106 |
bEstado.setFixedLabelWidth(this.getWidth() * 0.3); |
1107 |
} |
1108 |
|
1109 |
/**
|
1110 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
1111 |
*/
|
1112 |
public void componentShown(ComponentEvent arg0) { |
1113 |
} |
1114 |
|
1115 |
/**
|
1116 |
* @see java.awt.event.ContainerListener#componentAdded(java.awt.event.ContainerEvent)
|
1117 |
*/
|
1118 |
public void componentAdded(ContainerEvent arg0) { |
1119 |
ajustarToolBar(); |
1120 |
} |
1121 |
|
1122 |
/**
|
1123 |
* @see java.awt.event.ContainerListener#componentRemoved(java.awt.event.ContainerEvent)
|
1124 |
*/
|
1125 |
public void componentRemoved(ContainerEvent arg0) { |
1126 |
ajustarToolBar(); |
1127 |
} |
1128 |
|
1129 |
/**
|
1130 |
* DOCUMENT ME!
|
1131 |
*
|
1132 |
* @author $author$
|
1133 |
* @version $Revision: 3513 $
|
1134 |
*/
|
1135 |
public class TooltipListener extends MouseAdapter { |
1136 |
/**
|
1137 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
1138 |
*/
|
1139 |
public void mouseEntered(MouseEvent e) { |
1140 |
JComponent control = (JComponent) e.getSource(); |
1141 |
EnableTextSupport ets = (EnableTextSupport) e.getSource(); |
1142 |
|
1143 |
String texto = null; |
1144 |
texto = control.getToolTipText(); |
1145 |
|
1146 |
if (texto != null) { |
1147 |
bEstado.setInfoTextTemporal(texto); |
1148 |
} |
1149 |
} |
1150 |
|
1151 |
/**
|
1152 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
1153 |
*/
|
1154 |
public void mouseExited(MouseEvent arg0) { |
1155 |
bEstado.restaurarTexto(); |
1156 |
} |
1157 |
|
1158 |
/**
|
1159 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
1160 |
*/
|
1161 |
public void mousePressed(MouseEvent e) { |
1162 |
bEstado.restaurarTexto(); |
1163 |
} |
1164 |
} |
1165 |
public String getTitlePrefix() { |
1166 |
return titlePrefix;
|
1167 |
} |
1168 |
public void setTitlePrefix(String titlePrefix) { |
1169 |
this.titlePrefix = titlePrefix;
|
1170 |
} |
1171 |
|
1172 |
public String getSelectedTool() { |
1173 |
return selectedTool;
|
1174 |
} |
1175 |
|
1176 |
|
1177 |
/**
|
1178 |
* Get a previously added JComponent by name. For example
|
1179 |
* you can use it if you need to obtain a JToolBar to
|
1180 |
* add some customized component.
|
1181 |
* @param name
|
1182 |
* @return the JComponent or null if none has been found
|
1183 |
*/
|
1184 |
public JComponent getComponentByName(String name) |
1185 |
{ |
1186 |
Iterator e = controlClass.keySet().iterator();
|
1187 |
|
1188 |
while (e.hasNext()) {
|
1189 |
JComponent control = (JComponent) e.next(); |
1190 |
String nameCtrl = control.getName();
|
1191 |
if (nameCtrl != null) |
1192 |
if (nameCtrl.compareTo(name) == 0) |
1193 |
return control;
|
1194 |
} |
1195 |
Iterator it = toolBarMap.values().iterator();
|
1196 |
while (it.hasNext()) {
|
1197 |
SelectableToolBar t = (SelectableToolBar) it.next(); |
1198 |
String nameCtrl = t.getName();
|
1199 |
if (nameCtrl != null) |
1200 |
if (nameCtrl.compareTo(name) == 0) |
1201 |
return t;
|
1202 |
|
1203 |
} |
1204 |
|
1205 |
return null; |
1206 |
} |
1207 |
|
1208 |
public void addTextToConsole(String text) { |
1209 |
desktopPane.getConsole().addText(text); |
1210 |
} |
1211 |
|
1212 |
public void addConsoleListener(String prefix, ResponseListener listener) { |
1213 |
consoleResponseAdapter.putSpaceListener(prefix, listener); |
1214 |
|
1215 |
} |
1216 |
|
1217 |
public void removeConsoleListener(ResponseListener listener) { |
1218 |
consoleResponseAdapter.deleteListener(listener); |
1219 |
|
1220 |
} |
1221 |
|
1222 |
public void focusConsole(String text) { |
1223 |
desktopPane.getConsole().addResponseText(text); |
1224 |
FocusManager fm=FocusManager.getCurrentManager(); |
1225 |
fm.focusNextComponent(desktopPane.getConsole()); |
1226 |
|
1227 |
} |
1228 |
|
1229 |
public void hideConsole() { |
1230 |
desktopPane.hideConsole(); |
1231 |
|
1232 |
} |
1233 |
|
1234 |
public void showConsole() { |
1235 |
desktopPane.showConsole(); |
1236 |
|
1237 |
} |
1238 |
private class ResponseAdapter implements ResponseListener{ |
1239 |
|
1240 |
private HashMap spaceListener = new HashMap(); |
1241 |
|
1242 |
public void putSpaceListener(String namespace, ResponseListener listener){ |
1243 |
spaceListener.put(namespace, listener); |
1244 |
} |
1245 |
|
1246 |
/**
|
1247 |
* @see com.iver.utiles.console.ResponseListener#acceptResponse(java.lang.String)
|
1248 |
*/
|
1249 |
public void acceptResponse(String response) { |
1250 |
boolean nameSpace = false; |
1251 |
int n = -1; |
1252 |
if (response != null){ |
1253 |
if ((n = response.indexOf(':')) != -1){ |
1254 |
nameSpace = true;
|
1255 |
} |
1256 |
} |
1257 |
|
1258 |
if (nameSpace){
|
1259 |
ResponseListener listener = (ResponseListener) spaceListener.get(response.substring(0, n));
|
1260 |
if (listener != null) |
1261 |
listener.acceptResponse(response.substring(n+1));
|
1262 |
}else{
|
1263 |
Iterator i = spaceListener.values().iterator();
|
1264 |
while (i.hasNext()) {
|
1265 |
ResponseListener listener = (ResponseListener) i.next(); |
1266 |
listener.acceptResponse(response); |
1267 |
} |
1268 |
} |
1269 |
} |
1270 |
|
1271 |
/**
|
1272 |
* @param listener
|
1273 |
*/
|
1274 |
public void deleteListener(ResponseListener listener) { |
1275 |
Iterator i = spaceListener.keySet().iterator();
|
1276 |
while (i.hasNext()) {
|
1277 |
String namespace = (String) i.next(); |
1278 |
ResponseListener l = (ResponseListener) spaceListener.get(namespace); |
1279 |
if (l == listener){
|
1280 |
spaceListener.remove(namespace); |
1281 |
} |
1282 |
} |
1283 |
} |
1284 |
|
1285 |
} |
1286 |
|
1287 |
|
1288 |
} |