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