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