root / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / MDIFrame.java @ 598
History | View | Annotate | Download (29.2 KB)
1 |
package com.iver.andami.ui.mdiFrame; |
---|---|
2 |
|
3 |
import com.iver.andami.Launcher; |
4 |
import com.iver.andami.PluginServices; |
5 |
import com.iver.andami.messages.Messages; |
6 |
import com.iver.andami.messages.NotificationManager; |
7 |
import com.iver.andami.plugins.PluginClassLoader; |
8 |
import com.iver.andami.plugins.config.generate.ActionTool; |
9 |
import com.iver.andami.plugins.config.generate.Label; |
10 |
import com.iver.andami.plugins.config.generate.Menu; |
11 |
import com.iver.andami.plugins.config.generate.PopupMenu; |
12 |
import com.iver.andami.plugins.config.generate.SelectableTool; |
13 |
import com.iver.andami.plugins.config.generate.SkinExtensionType; |
14 |
import com.iver.andami.plugins.config.generate.ToolBar; |
15 |
import com.iver.andami.ui.mdiManager.MDIManager; |
16 |
import com.iver.andami.ui.mdiManager.MDIManagerFactory; |
17 |
|
18 |
import org.apache.log4j.Logger; |
19 |
|
20 |
import java.awt.BorderLayout; |
21 |
import java.awt.Component; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.FlowLayout; |
24 |
import java.awt.Insets; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.awt.event.ComponentEvent; |
28 |
import java.awt.event.ComponentListener; |
29 |
import java.awt.event.ContainerEvent; |
30 |
import java.awt.event.ContainerListener; |
31 |
import java.awt.event.MouseAdapter; |
32 |
import java.awt.event.MouseEvent; |
33 |
import java.awt.event.WindowAdapter; |
34 |
import java.awt.event.WindowEvent; |
35 |
|
36 |
import java.net.URL; |
37 |
import java.util.ArrayList; |
38 |
import java.util.HashMap; |
39 |
import java.util.Iterator; |
40 |
import java.util.NoSuchElementException; |
41 |
import java.util.Vector; |
42 |
|
43 |
import javax.swing.AbstractButton; |
44 |
import javax.swing.ImageIcon; |
45 |
import javax.swing.JComponent; |
46 |
import javax.swing.JFrame; |
47 |
import javax.swing.JMenu; |
48 |
import javax.swing.JMenuBar; |
49 |
import javax.swing.JOptionPane; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JPopupMenu; |
52 |
import javax.swing.KeyStroke; |
53 |
import javax.swing.MenuElement; |
54 |
import javax.swing.SwingUtilities; |
55 |
import javax.swing.Timer; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Frame principal de la aplicaci?n.
|
60 |
*
|
61 |
* @version $Revision: 598 $
|
62 |
*/
|
63 |
public class MDIFrame extends JFrame implements ComponentListener, |
64 |
ContainerListener, ActionListener, MainFrame { |
65 |
/** DOCUMENT ME! */
|
66 |
private static Logger logger = Logger.getLogger(MDIFrame.class.getName()); |
67 |
private MDIManager mdiManager = MDIManagerFactory.createManager();
|
68 |
|
69 |
/** Elementos de la aplicaci?n */
|
70 |
private JMenuBar menuBar = new JMenuBar(); |
71 |
|
72 |
/** DOCUMENT ME! */
|
73 |
private JPanel toolBars = new JPanel(); |
74 |
|
75 |
/** DOCUMENT ME! */
|
76 |
private NewStatusBar bEstado = null; |
77 |
|
78 |
/** Asocia los nombres con las barras de herramientas */
|
79 |
private HashMap toolBarMap = new HashMap(); |
80 |
|
81 |
/** Asocia los nombres con los popupMenus */
|
82 |
private HashMap popupMap = new HashMap(); |
83 |
|
84 |
/** Asocia controles con la clase de la extension asociada */
|
85 |
private HashMap controlClass = new HashMap(); |
86 |
|
87 |
/**
|
88 |
* Asocia la informaci?n sobre las etiquetas que van en la status bar con
|
89 |
* cada extension
|
90 |
*/
|
91 |
private HashMap classLabels = new HashMap(); |
92 |
|
93 |
/** ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener) */
|
94 |
private ArrayList progressListeners = new ArrayList(); |
95 |
|
96 |
/** Timer para invocar los enventos de la interfaz anterior */
|
97 |
private Timer progressTimer = null; |
98 |
|
99 |
/** Tabla hash que asocia las clases con las extensiones */
|
100 |
private HashMap classesExtensions = new HashMap(); |
101 |
|
102 |
/** ?ltima clase que activ? etiquetas */
|
103 |
private Class lastLabelClass; |
104 |
|
105 |
/** Instancia que pone los tooltip en la barra de estado */
|
106 |
private TooltipListener tooltipListener = new TooltipListener(); |
107 |
private HashMap infoCodedMenus = new HashMap(); |
108 |
|
109 |
/**
|
110 |
* Realiza tareas para poner en marcha la aplicaci?n
|
111 |
*
|
112 |
* @throws RuntimeException DOCUMENT ME!
|
113 |
*/
|
114 |
public void init() { |
115 |
if (!SwingUtilities.isEventDispatchThread()) { |
116 |
throw new RuntimeException("Not Event Dispatch Thread"); |
117 |
} |
118 |
|
119 |
//Se a?aden los listeners del JFrame
|
120 |
this.addWindowListener(new WindowAdapter() { |
121 |
public void windowClosing(WindowEvent e) { |
122 |
/*JOptionPane dlgSalir = new JOptionPane(Utilities.getMessage(this,"quiere_salir"),
|
123 |
JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
124 |
*/
|
125 |
int option = JOptionPane.showConfirmDialog(MDIFrame.this, |
126 |
Messages.getString("quiere_salir"),
|
127 |
Messages.getString("salir"),
|
128 |
JOptionPane.YES_NO_OPTION);
|
129 |
|
130 |
if (option == JOptionPane.YES_OPTION) { |
131 |
Launcher.closeApplication(); |
132 |
} |
133 |
} |
134 |
}); |
135 |
this.addComponentListener(this); |
136 |
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
137 |
|
138 |
//Se configura la barra de menu
|
139 |
setJMenuBar(menuBar); |
140 |
|
141 |
//Se configura el layout del JFrame principal
|
142 |
this.getContentPane().setLayout(new BorderLayout()); |
143 |
|
144 |
/*
|
145 |
* Se configura y se a?ade el JPanel de las barras de
|
146 |
* herramientas
|
147 |
*/
|
148 |
FlowLayout layout = new FlowLayout(FlowLayout.LEFT); |
149 |
layout.setHgap(0);
|
150 |
layout.setVgap(0);
|
151 |
toolBars.setLayout(layout); |
152 |
getContentPane().add(toolBars, BorderLayout.PAGE_START);
|
153 |
|
154 |
// Se a?ade la barra de estado a la aplicaci?n
|
155 |
bEstado = new NewStatusBar();
|
156 |
getContentPane().add(bEstado, BorderLayout.SOUTH);
|
157 |
|
158 |
this.toolBars.addContainerListener(this); |
159 |
|
160 |
pack(); |
161 |
|
162 |
this.setSize(500, 500); |
163 |
this.setExtendedState(MAXIMIZED_BOTH);
|
164 |
|
165 |
mdiManager.init(this);
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* A?ade un modo de operaci?n a la caja de herramientas
|
170 |
*
|
171 |
* @param ext Texto del boton, si es null no aparece texto
|
172 |
* @param ext Icono del boton, si es null no aparece icono
|
173 |
* @param ext Extensi?n asociada al control
|
174 |
* @param selectableTool Enable text del control
|
175 |
*
|
176 |
* @throws ClassNotFoundException
|
177 |
* @throws RuntimeException DOCUMENT ME!
|
178 |
*/
|
179 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
180 |
ToolBar toolBar, SelectableTool selectableTool) |
181 |
throws ClassNotFoundException { |
182 |
if (!SwingUtilities.isEventDispatchThread()) { |
183 |
throw new RuntimeException("No Event Dispatch Thread"); |
184 |
} |
185 |
|
186 |
JToggleButton btn;
|
187 |
URL image = loader.getResource(selectableTool.getIcon());
|
188 |
if (image != null){ |
189 |
btn = new JToggleButton(selectableTool.getText(), |
190 |
new ImageIcon(image)); |
191 |
}else{
|
192 |
btn = new JToggleButton(selectableTool.getText()); |
193 |
} |
194 |
|
195 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
196 |
btn.addMouseListener(tooltipListener); |
197 |
btn.addActionListener(this);
|
198 |
btn.setFocusable(false);
|
199 |
btn.setActionCommand(selectableTool.getActionCommand()); |
200 |
btn.setToolTipText(selectableTool.getTooltip()); |
201 |
|
202 |
if (selectableTool.getIsDefault()) {
|
203 |
btn.setSelected(true);
|
204 |
} |
205 |
|
206 |
String name = getName(toolBar.getName(), loader);
|
207 |
|
208 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
209 |
|
210 |
if (jtb == null) { |
211 |
jtb = new SelectableToolBar(toolBar.getName());
|
212 |
jtb.setRollover(true);
|
213 |
toolBarMap.put(name, jtb); |
214 |
toolBars.add(jtb); |
215 |
} |
216 |
|
217 |
jtb.addButton(selectableTool.getGroup(), btn); |
218 |
|
219 |
controlClass.put(btn, loader.loadClass(ext.getClassName())); |
220 |
|
221 |
if (selectableTool.getTooltip() != null) { |
222 |
btn.setToolTipText(selectableTool.getTooltip()); |
223 |
} |
224 |
|
225 |
if (selectableTool.getEnableText() != null) { |
226 |
btn.setEnableText(selectableTool.getEnableText()); |
227 |
} |
228 |
|
229 |
if (selectableTool.getLast() == true) { |
230 |
jtb.addSeparator(); |
231 |
} |
232 |
} |
233 |
|
234 |
/**
|
235 |
* A?ade un bot?n a la barra de herramientas
|
236 |
*
|
237 |
* @param ext Texto del boton, si es null no aparece texto
|
238 |
* @param ext Extensi?n asociada al control
|
239 |
* @param toolBar Icono del boton, si es null no aparece texto
|
240 |
* @param actionTool Tooltip de la barra de herramientas
|
241 |
*
|
242 |
* @throws ClassNotFoundException
|
243 |
* @throws RuntimeException DOCUMENT ME!
|
244 |
*/
|
245 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
246 |
ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException { |
247 |
if (!SwingUtilities.isEventDispatchThread()) { |
248 |
throw new RuntimeException("No Event Dispatch Thread"); |
249 |
} |
250 |
|
251 |
JButton btn;
|
252 |
URL image = loader.getResource(actionTool.getIcon());
|
253 |
if (image != null){ |
254 |
btn = new JButton(actionTool.getText(), |
255 |
new ImageIcon(image)); |
256 |
}else{
|
257 |
btn = new JButton(actionTool.getText()); |
258 |
} |
259 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
260 |
btn.addMouseListener(tooltipListener); |
261 |
btn.addActionListener(this);
|
262 |
btn.setFocusable(false);
|
263 |
btn.setActionCommand(actionTool.getActionCommand()); |
264 |
btn.setToolTipText(actionTool.getTooltip()); |
265 |
|
266 |
String name = getName(toolBar.getName(), loader);
|
267 |
|
268 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
269 |
|
270 |
if (jtb == null) { |
271 |
jtb = new SelectableToolBar(toolBar.getName());
|
272 |
jtb.setRollover(true);
|
273 |
toolBarMap.put(name, jtb); |
274 |
toolBars.add(jtb); |
275 |
} |
276 |
|
277 |
jtb.add(btn); |
278 |
|
279 |
controlClass.put(btn, loader.loadClass(ext.getClassName())); |
280 |
|
281 |
if (actionTool.getTooltip() != null) { |
282 |
btn.setToolTipText(actionTool.getTooltip()); |
283 |
} |
284 |
|
285 |
if (actionTool.getEnableText() != null) { |
286 |
btn.setEnableText(actionTool.getEnableText()); |
287 |
} |
288 |
|
289 |
if (actionTool.getLast() == true) { |
290 |
jtb.addSeparator(); |
291 |
} |
292 |
} |
293 |
|
294 |
/**
|
295 |
* Crea la estructura de men?s necesaria para a?adir el menu a la barra. Devuelve
|
296 |
* el padre del cual deve colgar el menu que se pasa como par?metro
|
297 |
*
|
298 |
* @param menu Menu cuya soporte se quiere a?adir
|
299 |
*
|
300 |
* @return Padre del men? que se pasa como par?metro
|
301 |
*/
|
302 |
private JMenu createMenuAncestors(Menu menu) { |
303 |
JMenu menuPadre = null; |
304 |
|
305 |
String[] menues = menu.getText().split("/"); |
306 |
|
307 |
//Se busca el padre en la menuBar
|
308 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
309 |
if (menuBar.getMenu(i).getText().compareToIgnoreCase(menues[0]) == 0) { |
310 |
menuPadre = (JMenu) menuBar.getMenu(i);
|
311 |
} |
312 |
} |
313 |
|
314 |
//Si no se encuentra el padre se crea
|
315 |
if (menuPadre == null) { |
316 |
menuPadre = new JMenu(menues[0]); |
317 |
menuBar.add(menuPadre); |
318 |
} |
319 |
|
320 |
//Se crea el resto de menus
|
321 |
Vector temp = new Vector(); |
322 |
temp.copyInto(menues); |
323 |
menuPadre = createMenus(temp, menuPadre); |
324 |
|
325 |
return menuPadre;
|
326 |
} |
327 |
|
328 |
/**
|
329 |
* A?ade la informaci?n del menu al framework. Debido a que los men?es se
|
330 |
* pueden introducir en un orden determinado por el usuario, pero los
|
331 |
* plugins se instalan en un orden arbitrario, primero se almacena la
|
332 |
* informaci?n de todos los menus para luego ordenarlos y posteriormente
|
333 |
* a?adirlos al interfaz
|
334 |
*
|
335 |
* @param loader Posicion del menu. Se ordena por este campo
|
336 |
* @param ext Array con los nombres de los padres del menu
|
337 |
* @param menu Texto del menu
|
338 |
*
|
339 |
* @throws ClassNotFoundException
|
340 |
* @throws RuntimeException DOCUMENT ME!
|
341 |
*/
|
342 |
public void addMenu(PluginClassLoader loader, SkinExtensionType ext, |
343 |
Menu menu) throws ClassNotFoundException { |
344 |
if (!SwingUtilities.isEventDispatchThread()) { |
345 |
throw new RuntimeException("No Event Dispatch Thread"); |
346 |
} |
347 |
|
348 |
JMenu menuPadre = createMenuAncestors(menu);
|
349 |
|
350 |
//Se registra y a?ade el menu
|
351 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
352 |
nuevoMenu.addMouseListener(tooltipListener); |
353 |
nuevoMenu.addActionListener(this);
|
354 |
menuPadre.add(nuevoMenu); |
355 |
|
356 |
controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName())); |
357 |
} |
358 |
|
359 |
/**
|
360 |
* Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
|
361 |
* en el par?metro nombres el array {"Search", "References", "Workspace"}
|
362 |
* crear? un men? Search, un submen? del anterior que se llamar?
|
363 |
* References y debajo de ?ste ?ltimo otro menu llamado Workspace
|
364 |
*
|
365 |
* @param nombres Array con los nombres de los men?s que se quieren crear
|
366 |
* @param padre Menu padre de los men?s creados. Es ?til porque es un
|
367 |
* algoritmo recursivo
|
368 |
*
|
369 |
* @return Devuelve el men? creado. Al final de toda la recursividad,
|
370 |
* devolver? el men? de m?s abajo en la jerarqu?a
|
371 |
*
|
372 |
* @throws RuntimeException DOCUMENT ME!
|
373 |
*/
|
374 |
private JMenu createMenus(Vector nombres, JMenu padre) { |
375 |
if (!SwingUtilities.isEventDispatchThread()) { |
376 |
throw new RuntimeException("No Event Dispatch Thread"); |
377 |
} |
378 |
|
379 |
//si no quedan nombres de menu por crear se vuelve: caso base
|
380 |
if (nombres.size() == 0) { |
381 |
return padre;
|
382 |
} |
383 |
|
384 |
//Se busca el menu por si ya existiera para no crearlo otra vez
|
385 |
JMenu buscado = null; |
386 |
|
387 |
for (int i = 0; i < padre.getMenuComponentCount(); i++) { |
388 |
try {
|
389 |
JMenu hijo = (JMenu) padre.getMenuComponent(i); |
390 |
|
391 |
if (hijo.getText().compareToIgnoreCase((String) nombres.get(0)) == 0) { |
392 |
buscado = hijo; |
393 |
} |
394 |
} catch (ClassCastException e) { |
395 |
/*
|
396 |
* Se ha encontrado un elemento hoja del arbol de men?es
|
397 |
*/
|
398 |
} |
399 |
} |
400 |
|
401 |
if (buscado != null) { |
402 |
//Si lo hemos encontrado creamos el resto
|
403 |
nombres.remove(0);
|
404 |
|
405 |
return createMenus(nombres, buscado);
|
406 |
} else {
|
407 |
//Si no lo hemos encontrado se crea el menu, se a?ade al padre
|
408 |
//y se crea el resto
|
409 |
JMenu menuPadre = new JMenu((String) nombres.get(0)); |
410 |
padre.add(menuPadre); |
411 |
|
412 |
nombres.remove(0);
|
413 |
|
414 |
return createMenus(nombres, menuPadre);
|
415 |
} |
416 |
} |
417 |
|
418 |
/**
|
419 |
* M?todo invocado en respuesta a ciertos eventos de la interfaz que pueden
|
420 |
* ocultar botones de las barras de herramientas y que redimensiona ?sta
|
421 |
* de manera conveniente para que no se oculte ninguno
|
422 |
*/
|
423 |
private void ajustarToolBar() { |
424 |
int margen = 8; |
425 |
int numFilas = 1; |
426 |
double acum = margen;
|
427 |
|
428 |
int toolHeight = 0; |
429 |
|
430 |
for (int i = 0; i < toolBars.getComponentCount(); i++) { |
431 |
Component c = toolBars.getComponent(i);
|
432 |
double width = c.getPreferredSize().getWidth();
|
433 |
acum = acum + width; |
434 |
|
435 |
if (acum > this.getWidth()) { |
436 |
numFilas++; |
437 |
acum = width + margen; |
438 |
} |
439 |
|
440 |
if (c.getPreferredSize().getHeight() > toolHeight) {
|
441 |
toolHeight = c.getPreferredSize().height; |
442 |
} |
443 |
} |
444 |
|
445 |
toolBars.setPreferredSize(new Dimension(this.getWidth(), |
446 |
(int) (numFilas * toolHeight)));
|
447 |
|
448 |
toolBars.updateUI(); |
449 |
} |
450 |
|
451 |
/**
|
452 |
* DOCUMENT ME!
|
453 |
*
|
454 |
* @param classesExtensions
|
455 |
*/
|
456 |
public void setClassesExtensions(HashMap classesExtensions) { |
457 |
this.classesExtensions = classesExtensions;
|
458 |
} |
459 |
|
460 |
/**
|
461 |
* M?todo de callback invocado cuando se selecciona un men? o un bot?n de
|
462 |
* la barra de herramientas. Se busca la extensi?n asociada y se ejecuta
|
463 |
*
|
464 |
* @param e Evento producido
|
465 |
*/
|
466 |
public void actionPerformed(ActionEvent e) { |
467 |
AbstractButton control = (AbstractButton) e.getSource(); |
468 |
com.iver.andami.plugins.Extension ext = (com.iver.andami.plugins.Extension) classesExtensions.get((Class) controlClass.get(
|
469 |
control)); |
470 |
String actionCommand = control.getActionCommand();
|
471 |
|
472 |
try {
|
473 |
ext.execute(actionCommand); |
474 |
} catch (Throwable t) { |
475 |
NotificationManager.addError("Error no capturado por el usuario", t);
|
476 |
} |
477 |
|
478 |
enableControls(); |
479 |
showMemory(); |
480 |
} |
481 |
|
482 |
/**
|
483 |
* DOCUMENT ME!
|
484 |
*
|
485 |
* @param name DOCUMENT ME!
|
486 |
* @param loader DOCUMENT ME!
|
487 |
*
|
488 |
* @return DOCUMENT ME!
|
489 |
*/
|
490 |
private String getName(String name, PluginClassLoader loader) { |
491 |
if (name.indexOf('.') == -1) { |
492 |
return loader.getPluginName() + "." + name; |
493 |
} else {
|
494 |
return name;
|
495 |
} |
496 |
} |
497 |
|
498 |
/**
|
499 |
* DOCUMENT ME!
|
500 |
*
|
501 |
* @param loader DOCUMENT ME!
|
502 |
* @param menu DOCUMENT ME!
|
503 |
*
|
504 |
* @throws RuntimeException DOCUMENT ME!
|
505 |
*/
|
506 |
public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) { |
507 |
if (!SwingUtilities.isEventDispatchThread()) { |
508 |
throw new RuntimeException("No Event Dispatch Thread"); |
509 |
} |
510 |
|
511 |
String name = getName(menu.getName(), loader);
|
512 |
|
513 |
//Se crea el control popupmenu
|
514 |
JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name); |
515 |
|
516 |
if (popupMenu == null) { |
517 |
popupMenu = new JPopUpMenu(menu.getName());
|
518 |
popupMap.put(name, popupMenu); |
519 |
} |
520 |
|
521 |
// Se a?aden las entradas
|
522 |
Menu[] menues = menu.getMenu(); |
523 |
|
524 |
for (int i = 0; i < menues.length; i++) { |
525 |
//Se registra y a?ade el menu
|
526 |
JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
|
527 |
|
528 |
popupMenu.add(nuevoMenu); |
529 |
} |
530 |
} |
531 |
|
532 |
/**
|
533 |
* DOCUMENT ME!
|
534 |
*
|
535 |
* @param loader
|
536 |
* @param menu
|
537 |
*
|
538 |
* @return
|
539 |
*
|
540 |
* @throws RuntimeException DOCUMENT ME!
|
541 |
*/
|
542 |
private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) { |
543 |
JMenuItem nuevoMenu = null; |
544 |
|
545 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
546 |
String texto = menu.getText();
|
547 |
texto = texto.substring(texto.lastIndexOf('/') + 1); |
548 |
texto = ps.getText(texto); |
549 |
|
550 |
if (menu.getIcon() != null) { |
551 |
nuevoMenu = new JMenuItem(texto, |
552 |
new ImageIcon(loader.getResource(menu.getIcon()))); |
553 |
} else {
|
554 |
nuevoMenu = new JMenuItem(texto); |
555 |
} |
556 |
|
557 |
if (menu.getMnemonic() != null) { |
558 |
if (menu.getMnemonic().length() != 1) { |
559 |
throw new RuntimeException( |
560 |
"Mnemonic must be 1 character length");
|
561 |
} |
562 |
|
563 |
nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic().charAt(0)));
|
564 |
} |
565 |
|
566 |
if (menu.getKey() != null) { |
567 |
nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping.getKey(
|
568 |
menu.getKey().charAt(0)), ActionEvent.CTRL_MASK)); |
569 |
} |
570 |
|
571 |
nuevoMenu.setActionCommand(menu.getActionCommand()); |
572 |
|
573 |
if (menu.getTooltip() != null) { |
574 |
nuevoMenu.setToolTipText(ps.getText(menu.getTooltip())); |
575 |
} |
576 |
|
577 |
if (menu.getEnableText() != null) { |
578 |
nuevoMenu.setEnableText(ps.getText(menu.getEnableText())); |
579 |
} |
580 |
|
581 |
return nuevoMenu;
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* Muestra u oculta el menu de nombre 'name'
|
586 |
*
|
587 |
* @param name Nombre del menu que se quiere mostrar
|
588 |
* @param x Evento de raton
|
589 |
* @param y DOCUMENT ME!
|
590 |
* @param c DOCUMENT ME!
|
591 |
*/
|
592 |
private void showPopupMenu(String name, int x, int y, Component c) { |
593 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
594 |
|
595 |
if (menu != null) { |
596 |
menu.show(c, x, y); |
597 |
} |
598 |
} |
599 |
|
600 |
/**
|
601 |
* DOCUMENT ME!
|
602 |
*
|
603 |
* @param name DOCUMENT ME!
|
604 |
* @param listener DOCUMENT ME!
|
605 |
*/
|
606 |
public void removePopupMenuListener(String name, ActionListener listener) { |
607 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
608 |
|
609 |
if (menu != null) { |
610 |
Component[] jmenuitems = menu.getComponents(); |
611 |
|
612 |
for (int i = 0; i < jmenuitems.length; i++) { |
613 |
if (jmenuitems[i] instanceof JMenuItem) { |
614 |
((JMenuItem) jmenuitems[i]).removeActionListener(listener);
|
615 |
} |
616 |
} |
617 |
} |
618 |
} |
619 |
|
620 |
/**
|
621 |
* DOCUMENT ME!
|
622 |
*
|
623 |
* @param popupName
|
624 |
* @param c DOCUMENT ME!
|
625 |
* @param listener
|
626 |
* @param loader
|
627 |
*/
|
628 |
public void addPopupMenuListener(String popupName, Component c, |
629 |
ActionListener listener, PluginClassLoader loader) {
|
630 |
final String name = getName(popupName, loader); |
631 |
|
632 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
633 |
|
634 |
if (menu != null) { |
635 |
Component[] jmenuitems = menu.getComponents(); |
636 |
|
637 |
for (int i = 0; i < jmenuitems.length; i++) { |
638 |
if (jmenuitems[i] instanceof JMenuItem) { |
639 |
((JMenuItem) jmenuitems[i]).addActionListener(listener);
|
640 |
} |
641 |
} |
642 |
} |
643 |
|
644 |
c.addMouseListener(new MouseAdapter() { |
645 |
public void mousePressed(MouseEvent e) { |
646 |
if (e.isPopupTrigger()) {
|
647 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
648 |
} |
649 |
} |
650 |
|
651 |
public void mouseReleased(MouseEvent e) { |
652 |
if (e.isPopupTrigger()) {
|
653 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
654 |
} |
655 |
} |
656 |
}); |
657 |
} |
658 |
|
659 |
/**
|
660 |
* Itera por los controles preguntando a las extensiones si estos est?n
|
661 |
* habilitados y visibles
|
662 |
*
|
663 |
* @throws RuntimeException DOCUMENT ME!
|
664 |
*/
|
665 |
public void enableControls() { |
666 |
if (!SwingUtilities.isEventDispatchThread()) { |
667 |
throw new RuntimeException("No Event Dispatch Thread"); |
668 |
} |
669 |
|
670 |
Iterator e = classesExtensions.values().iterator();
|
671 |
HashMap estadoExtensiones = new HashMap(); |
672 |
HashMap visibilidadExtensiones = new HashMap(); |
673 |
|
674 |
while (e.hasNext()) {
|
675 |
try {
|
676 |
com.iver.andami.plugins.Extension ext = (com.iver.andami.plugins.Extension) e.next(); |
677 |
|
678 |
if (estadoExtensiones.get(ext) == null) { |
679 |
Boolean visible = new Boolean(ext.isVisible()); |
680 |
Boolean enabled = new Boolean(false); |
681 |
|
682 |
if (visible.booleanValue()) {
|
683 |
enabled = new Boolean(ext.isEnabled()); |
684 |
} |
685 |
|
686 |
estadoExtensiones.put(ext, enabled); |
687 |
visibilidadExtensiones.put(ext, visible); |
688 |
} |
689 |
} catch (Throwable e1) { |
690 |
NotificationManager.addError("error no capturado por el usuario",
|
691 |
e1); |
692 |
} |
693 |
} |
694 |
|
695 |
//Se habilitan y deshabilitan los controles
|
696 |
e = controlClass.keySet().iterator(); |
697 |
|
698 |
while (e.hasNext()) {
|
699 |
try{
|
700 |
JComponent control = (JComponent) e.next(); |
701 |
|
702 |
com.iver.andami.plugins.Extension ext = (com.iver.andami.plugins.Extension) classesExtensions.get((Class) controlClass.get(
|
703 |
control)); |
704 |
boolean enabled = ((Boolean) estadoExtensiones.get(ext)).booleanValue(); |
705 |
boolean visible = ((Boolean) visibilidadExtensiones.get(ext)).booleanValue(); |
706 |
control.setEnabled(enabled); |
707 |
control.setVisible(visible); |
708 |
}catch(Exception ex){ |
709 |
} |
710 |
} |
711 |
|
712 |
//Se itera por los men?es para ocultar los que no tengan hijos visibles
|
713 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
714 |
MenuElement menu = menuBar.getMenu(i);
|
715 |
ocultarMenus(menu); |
716 |
} |
717 |
|
718 |
//Se ocultan las barras que no tienen herramientas
|
719 |
Iterator it = toolBarMap.values().iterator();
|
720 |
|
721 |
while (it.hasNext()) {
|
722 |
SelectableToolBar t = (SelectableToolBar) it.next(); |
723 |
boolean todosOcultos = true; |
724 |
|
725 |
for (int i = 0; i < t.getComponentCount(); i++) { |
726 |
if (t.getComponent(i).isVisible()) {
|
727 |
todosOcultos = false;
|
728 |
} |
729 |
} |
730 |
|
731 |
if (todosOcultos) {
|
732 |
t.setVisible(false);
|
733 |
} else {
|
734 |
t.setVisible(true);
|
735 |
} |
736 |
} |
737 |
|
738 |
if (mdiManager != null) { |
739 |
JPanel f = (JPanel) mdiManager.getActiveView(); |
740 |
|
741 |
if (f != null) { |
742 |
if (lastLabelClass != f.getClass()) {
|
743 |
lastLabelClass = f.getClass(); |
744 |
|
745 |
Label[] lbls = (Label[]) classLabels.get(lastLabelClass); |
746 |
|
747 |
if (lbls != null) { |
748 |
bEstado.setLabelSet(lbls); |
749 |
} |
750 |
} |
751 |
} |
752 |
} |
753 |
|
754 |
showMemory(); |
755 |
} |
756 |
|
757 |
/**
|
758 |
* Establece la visibilidad de un menu y todos sus descendientes en la
|
759 |
* jerarquia teniendo en cuenta la visibilidad de todos los submenus.
|
760 |
*
|
761 |
* @param menu Menu que se quiere visualizar
|
762 |
*
|
763 |
* @return Devuelve true si el menu es visible y false en caso contrario
|
764 |
*/
|
765 |
private boolean ocultarMenus(MenuElement menu) { |
766 |
MenuElement[] submenus = menu.getSubElements(); |
767 |
|
768 |
//Si no tiene hijos se devuelve su visibilidad
|
769 |
if (submenus.length == 0) { |
770 |
return menu.getComponent().isVisible();
|
771 |
} |
772 |
|
773 |
/*
|
774 |
* Si tiene hijos se devuelve true si alg?no de ellos es visible,
|
775 |
* pero se itera por todos ellos
|
776 |
*/
|
777 |
boolean visible = false; |
778 |
|
779 |
for (int i = 0; i < submenus.length; i++) { |
780 |
if (ocultarMenus(submenus[i])) {
|
781 |
if (!(menu instanceof JPopupMenu)) { |
782 |
menu.getComponent().setVisible(true);
|
783 |
} |
784 |
|
785 |
visible = true;
|
786 |
} |
787 |
} |
788 |
|
789 |
if (visible) {
|
790 |
return true; |
791 |
} |
792 |
|
793 |
menu.getComponent().setVisible(false);
|
794 |
|
795 |
return false; |
796 |
} |
797 |
|
798 |
/**
|
799 |
* Muestra la memoria consumida por el programa
|
800 |
*/
|
801 |
private void showMemory() { |
802 |
Runtime r = Runtime.getRuntime(); |
803 |
long mem = r.totalMemory() - r.freeMemory();
|
804 |
logger.debug("Memoria total: " + mem);
|
805 |
} |
806 |
|
807 |
/**
|
808 |
* DOCUMENT ME!
|
809 |
*
|
810 |
* @return
|
811 |
*/
|
812 |
public MDIManager getMDIManager() {
|
813 |
return mdiManager;
|
814 |
} |
815 |
|
816 |
/**
|
817 |
* Establece el mensaje en la barra de estado asociado a una etiqueta
|
818 |
*
|
819 |
* @return DOCUMENT ME!
|
820 |
*/
|
821 |
public NewStatusBar getStatusBar() {
|
822 |
return bEstado;
|
823 |
} |
824 |
|
825 |
/**
|
826 |
* DOCUMENT ME!
|
827 |
*
|
828 |
* @param clase
|
829 |
* @param label
|
830 |
*/
|
831 |
public void setLabels(Class clase, Label[] label) { |
832 |
classLabels.put(clase, label); |
833 |
} |
834 |
|
835 |
/**
|
836 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#removeMenu(com.iver.andami.plugins.config.generate.Menu)
|
837 |
*/
|
838 |
public void removeMenu(Menu menu) { |
839 |
JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu); |
840 |
|
841 |
if (delete == null) throw new NoSuchElementException(menu.getText()); |
842 |
|
843 |
delete.getParent().remove(delete); |
844 |
infoCodedMenus.remove(menu); |
845 |
} |
846 |
|
847 |
/**
|
848 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#addMenu(com.iver.andami.plugins.config.generate.Menu,
|
849 |
* java.awt.event.ActionListener, PluginClassLoader)
|
850 |
*/
|
851 |
public void addMenu(Menu menu, ActionListener listener, |
852 |
PluginClassLoader loader) { |
853 |
|
854 |
JMenu menuPadre = createMenuAncestors(menu);
|
855 |
|
856 |
//Se registra y a?ade el menu
|
857 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
858 |
nuevoMenu.addMouseListener(tooltipListener); |
859 |
nuevoMenu.addActionListener(listener); |
860 |
menuPadre.add(nuevoMenu); |
861 |
|
862 |
infoCodedMenus.put(menu, nuevoMenu); |
863 |
} |
864 |
|
865 |
/**
|
866 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
867 |
*/
|
868 |
public void componentHidden(ComponentEvent arg0) { |
869 |
} |
870 |
|
871 |
/**
|
872 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
873 |
*/
|
874 |
public void componentMoved(ComponentEvent arg0) { |
875 |
} |
876 |
|
877 |
/**
|
878 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
879 |
*/
|
880 |
public void componentResized(ComponentEvent arg0) { |
881 |
ajustarToolBar(); |
882 |
bEstado.setFixedLabelWidth(this.getWidth() * 0.5); |
883 |
} |
884 |
|
885 |
/**
|
886 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
887 |
*/
|
888 |
public void componentShown(ComponentEvent arg0) { |
889 |
} |
890 |
|
891 |
/**
|
892 |
* @see java.awt.event.ContainerListener#componentAdded(java.awt.event.ContainerEvent)
|
893 |
*/
|
894 |
public void componentAdded(ContainerEvent arg0) { |
895 |
ajustarToolBar(); |
896 |
} |
897 |
|
898 |
/**
|
899 |
* @see java.awt.event.ContainerListener#componentRemoved(java.awt.event.ContainerEvent)
|
900 |
*/
|
901 |
public void componentRemoved(ContainerEvent arg0) { |
902 |
ajustarToolBar(); |
903 |
} |
904 |
|
905 |
/**
|
906 |
* DOCUMENT ME!
|
907 |
*
|
908 |
* @author $author$
|
909 |
* @version $Revision: 598 $
|
910 |
*/
|
911 |
public class TooltipListener extends MouseAdapter { |
912 |
/**
|
913 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
914 |
*/
|
915 |
public void mouseEntered(MouseEvent e) { |
916 |
JComponent control = (JComponent) e.getSource(); |
917 |
EnableTextSupport ets = (EnableTextSupport) e.getSource(); |
918 |
|
919 |
String texto = null; |
920 |
texto = control.getToolTipText(); |
921 |
|
922 |
if (texto != null) { |
923 |
bEstado.setInfoTextTemporal(texto); |
924 |
} |
925 |
} |
926 |
|
927 |
/**
|
928 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
929 |
*/
|
930 |
public void mouseExited(MouseEvent arg0) { |
931 |
bEstado.restaurarTexto(); |
932 |
} |
933 |
|
934 |
/**
|
935 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
936 |
*/
|
937 |
public void mousePressed(MouseEvent e) { |
938 |
bEstado.restaurarTexto(); |
939 |
} |
940 |
} |
941 |
} |