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