svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / MDIFrame.java @ 12697
History | View | Annotate | Download (38.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.andami.ui.mdiFrame; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.Insets; |
48 |
import java.awt.Toolkit; |
49 |
import java.awt.event.ActionEvent; |
50 |
import java.awt.event.ActionListener; |
51 |
import java.awt.event.ComponentEvent; |
52 |
import java.awt.event.ComponentListener; |
53 |
import java.awt.event.ContainerEvent; |
54 |
import java.awt.event.ContainerListener; |
55 |
import java.awt.event.MouseAdapter; |
56 |
import java.awt.event.MouseEvent; |
57 |
import java.awt.event.WindowAdapter; |
58 |
import java.awt.event.WindowEvent; |
59 |
import java.io.FileNotFoundException; |
60 |
import java.net.URL; |
61 |
import java.util.ArrayList; |
62 |
import java.util.Enumeration; |
63 |
import java.util.HashMap; |
64 |
import java.util.Iterator; |
65 |
import java.util.NoSuchElementException; |
66 |
|
67 |
import javax.swing.AbstractButton; |
68 |
import javax.swing.ButtonGroup; |
69 |
import javax.swing.ImageIcon; |
70 |
import javax.swing.JComponent; |
71 |
import javax.swing.JFrame; |
72 |
import javax.swing.JMenu; |
73 |
import javax.swing.JMenuBar; |
74 |
import javax.swing.JOptionPane; |
75 |
import javax.swing.JPanel; |
76 |
import javax.swing.JPopupMenu; |
77 |
import javax.swing.JSeparator; |
78 |
import javax.swing.KeyStroke; |
79 |
import javax.swing.MenuElement; |
80 |
import javax.swing.SwingUtilities; |
81 |
import javax.swing.Timer; |
82 |
|
83 |
import org.apache.log4j.Logger; |
84 |
import org.gvsig.gui.beans.controls.IControl; |
85 |
|
86 |
import com.iver.andami.Launcher; |
87 |
import com.iver.andami.PluginServices; |
88 |
import com.iver.andami.messages.Messages; |
89 |
import com.iver.andami.messages.NotificationManager; |
90 |
import com.iver.andami.plugins.ExtensionDecorator; |
91 |
import com.iver.andami.plugins.PluginClassLoader; |
92 |
import com.iver.andami.plugins.config.generate.ActionTool; |
93 |
import com.iver.andami.plugins.config.generate.Label; |
94 |
import com.iver.andami.plugins.config.generate.Menu; |
95 |
import com.iver.andami.plugins.config.generate.PopupMenu; |
96 |
import com.iver.andami.plugins.config.generate.SelectableTool; |
97 |
import com.iver.andami.plugins.config.generate.SkinExtensionType; |
98 |
import com.iver.andami.plugins.config.generate.ToolBar; |
99 |
import com.iver.andami.ui.mdiManager.MDIManager; |
100 |
import com.iver.andami.ui.mdiManager.MDIManagerFactory; |
101 |
|
102 |
|
103 |
/**
|
104 |
* Main application window.
|
105 |
*
|
106 |
* @version $Revision: 12697 $
|
107 |
*/
|
108 |
public class MDIFrame extends JFrame implements ComponentListener, |
109 |
ContainerListener, ActionListener, MainFrame { |
110 |
/** DOCUMENT ME! */
|
111 |
private static Logger logger = Logger.getLogger(MDIFrame.class.getName()); |
112 |
private MDIManager mdiManager = MDIManagerFactory.createManager();
|
113 |
|
114 |
/** Elementos de la aplicaci?n */
|
115 |
private JMenuBar menuBar = new JMenuBar(); |
116 |
|
117 |
/** Panel which contains the toolbars */
|
118 |
private JPanel toolBars = new JPanel(); |
119 |
|
120 |
/** Status bar */
|
121 |
private NewStatusBar bEstado = null; |
122 |
|
123 |
/** Asocia los nombres con las barras de herramientas */
|
124 |
private HashMap toolBarMap = new HashMap(); |
125 |
|
126 |
/** Almacena los grupos de selectableTools */
|
127 |
private HashMap buttonGroupMap = new HashMap(); |
128 |
/**
|
129 |
* Stores the initially selected tools.
|
130 |
* It contains pairs (String groupName, JToolBarToggleButton button)
|
131 |
*/
|
132 |
private HashMap initialSelectedTools = new HashMap(); |
133 |
|
134 |
/**
|
135 |
* Stores the actionCommand of the selected tool, for each group.
|
136 |
* It contains pairs (String groupName, JToolBarToggleButton button)
|
137 |
*/
|
138 |
private HashMap selectedTool = null; |
139 |
// this should be the same value defined at plugin-config.xsd
|
140 |
private String defaultGroup = "unico"; |
141 |
|
142 |
/** Asocia los nombres con los popupMenus */
|
143 |
private HashMap popupMap = new HashMap(); |
144 |
|
145 |
/** Asocia controles con la clase de la extension asociada */
|
146 |
private HashMap controlClass = new HashMap(); |
147 |
|
148 |
/**
|
149 |
* Asocia la informaci?n sobre las etiquetas que van en la status bar con
|
150 |
* cada extension
|
151 |
*/
|
152 |
private HashMap classLabels = new HashMap(); |
153 |
|
154 |
//private HashMap classControls = new HashMap();
|
155 |
|
156 |
/** ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener) */
|
157 |
private ArrayList progressListeners = new ArrayList(); |
158 |
|
159 |
/** Timer para invocar los enventos de la interfaz anterior */
|
160 |
private Timer progressTimer = null; |
161 |
|
162 |
/** Tabla hash que asocia las clases con las extensiones */
|
163 |
private HashMap classesExtensions = new HashMap(); |
164 |
|
165 |
/** ?ltima clase que activ? etiquetas */
|
166 |
private Class lastLabelClass; |
167 |
|
168 |
/** Instancia que pone los tooltip en la barra de estado */
|
169 |
private TooltipListener tooltipListener = new TooltipListener(); |
170 |
private HashMap infoCodedMenus = new HashMap(); |
171 |
|
172 |
private String titlePrefix; |
173 |
|
174 |
private static final String noIcon = "images/no_icon.png"; |
175 |
|
176 |
/**
|
177 |
* Makes some initialization tasks.
|
178 |
*
|
179 |
* @throws RuntimeException DOCUMENT ME!
|
180 |
*/
|
181 |
public void init() { |
182 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
183 |
if (!SwingUtilities.isEventDispatchThread()) { |
184 |
throw new RuntimeException("Not Event Dispatch Thread"); |
185 |
} |
186 |
|
187 |
//Se a?aden los listeners del JFrame
|
188 |
this.addWindowListener(new WindowAdapter() { |
189 |
public void windowClosing(WindowEvent e) { |
190 |
Launcher.closeApplication(); |
191 |
} |
192 |
}); |
193 |
this.addComponentListener(this); |
194 |
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
195 |
|
196 |
//Se configura la barra de menu
|
197 |
setJMenuBar(menuBar); |
198 |
|
199 |
//Se configura el layout del JFrame principal
|
200 |
this.getContentPane().setLayout(new BorderLayout()); |
201 |
|
202 |
/*
|
203 |
* Se configura y se a?ade el JPanel de las barras de
|
204 |
* herramientas
|
205 |
*/
|
206 |
FlowLayout layout = new FlowLayout(FlowLayout.LEFT); |
207 |
layout.setHgap(0);
|
208 |
layout.setVgap(0);
|
209 |
toolBars.setLayout(layout); |
210 |
getContentPane().add(toolBars, BorderLayout.PAGE_START);
|
211 |
|
212 |
// Se a?ade la barra de estado a la aplicaci?n
|
213 |
bEstado = new NewStatusBar();
|
214 |
bEstado.setInfoText(Messages.getString("StatusBar.Aplicacion_iniciada"));
|
215 |
getContentPane().add(bEstado, BorderLayout.SOUTH);
|
216 |
|
217 |
this.toolBars.addContainerListener(this); |
218 |
|
219 |
pack(); |
220 |
|
221 |
// TODO LWS Aqui deber?a cargar los valores salvados de la ?ltima ejecuci?n.
|
222 |
setSize(700, 580); |
223 |
setLocation(10,10); |
224 |
setExtendedState(MAXIMIZED_BOTH); |
225 |
|
226 |
mdiManager.init(this);
|
227 |
} |
228 |
|
229 |
/*
|
230 |
* (non-javadoc)
|
231 |
* @see java.awt.Frame.setTitle(String title)
|
232 |
*/
|
233 |
public void setTitle(String title) { |
234 |
super.setTitle(titlePrefix + ":" + title); |
235 |
} |
236 |
|
237 |
/**
|
238 |
* A?ade un modo de operaci?n a la caja de herramientas
|
239 |
*
|
240 |
* @param ext Texto del boton, si es null no aparece texto
|
241 |
* @param ext Icono del boton, si es null no aparece icono
|
242 |
* @param ext Extensi?n asociada al control
|
243 |
* @param selectableTool Enable text del control
|
244 |
*
|
245 |
* @throws ClassNotFoundException
|
246 |
* @throws RuntimeException DOCUMENT ME!
|
247 |
*/
|
248 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
249 |
ToolBar toolBar, SelectableTool selectableTool) |
250 |
throws ClassNotFoundException { |
251 |
if (!SwingUtilities.isEventDispatchThread()) { |
252 |
throw new RuntimeException("No Event Dispatch Thread"); |
253 |
} |
254 |
|
255 |
// Para traducir
|
256 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
257 |
|
258 |
JToolBarToggleButton btn; |
259 |
URL image = loader.getResource(selectableTool.getIcon());
|
260 |
|
261 |
if (image != null) { |
262 |
btn = new JToolBarToggleButton(selectableTool.getText(),
|
263 |
new ImageIcon(image)); |
264 |
} else {
|
265 |
logger.error(PluginServices.getText(this, "Unable_to_find_icon") +": "+selectableTool.getIcon()); |
266 |
URL noIconURL = getClass().getClassLoader().getResource(noIcon);
|
267 |
btn = new JToolBarToggleButton(selectableTool.getText(), new ImageIcon(noIconURL)); |
268 |
} |
269 |
|
270 |
com.iver.andami.ui.mdiFrame.ToggleButtonModel buttonModel = new com.iver.andami.ui.mdiFrame.ToggleButtonModel();
|
271 |
btn.setModel(buttonModel); |
272 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
273 |
btn.addMouseListener(tooltipListener); |
274 |
btn.addActionListener(this);
|
275 |
btn.setFocusable(false);
|
276 |
btn.setActionCommand(selectableTool.getActionCommand()); |
277 |
btn.setToolTipText(selectableTool.getTooltip()); |
278 |
btn.setEnabled(false);
|
279 |
btn.setVisible(false);
|
280 |
String name = toolBar.getName();
|
281 |
|
282 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
283 |
|
284 |
if (jtb == null) { |
285 |
jtb = new SelectableToolBar(name);
|
286 |
jtb.setRollover(true);
|
287 |
jtb.setAndamiVisibility(toolBar.getIsVisible()); |
288 |
toolBarMap.put(name, jtb); |
289 |
toolBars.add(jtb); |
290 |
} |
291 |
|
292 |
ButtonGroup group;
|
293 |
if (buttonGroupMap.containsKey(selectableTool.getGroup())) {
|
294 |
group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
|
295 |
} |
296 |
else {
|
297 |
group = new ButtonGroup(); |
298 |
buttonGroupMap.put(selectableTool.getGroup(), group); |
299 |
|
300 |
} |
301 |
jtb.addButton(group, btn); |
302 |
buttonModel.setGroupName(selectableTool.getGroup()); |
303 |
|
304 |
if (selectableTool.getIsDefault()) {
|
305 |
btn.setSelected(true);
|
306 |
initialSelectedTools.put(selectableTool.getGroup(), btn.getActionCommand()); |
307 |
} |
308 |
|
309 |
controlClass.put(btn, loader.loadClass(ext.getClassName())); |
310 |
|
311 |
if (selectableTool.getName() != null) { |
312 |
btn.setName(selectableTool.getName()); |
313 |
} |
314 |
|
315 |
if (selectableTool.getTooltip() != null) { |
316 |
btn.setToolTip(ps.getText(selectableTool.getTooltip())); |
317 |
} |
318 |
|
319 |
if (selectableTool.getEnableText() != null) { |
320 |
btn.setEnableText(ps.getText(selectableTool.getEnableText())); |
321 |
} |
322 |
|
323 |
if (selectableTool.getLast() == true) { |
324 |
jtb.addSeparator(); |
325 |
} |
326 |
} |
327 |
|
328 |
/**
|
329 |
* A?ade un bot?n a la barra de herramientas
|
330 |
*
|
331 |
* @param ext Texto del boton, si es null no aparece texto
|
332 |
* @param ext Extensi?n asociada al control
|
333 |
* @param toolBar Icono del boton, si es null no aparece texto
|
334 |
* @param actionTool Tooltip de la barra de herramientas
|
335 |
*
|
336 |
* @throws ClassNotFoundException
|
337 |
* @throws RuntimeException DOCUMENT ME!
|
338 |
*/
|
339 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
340 |
ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException { |
341 |
if (!SwingUtilities.isEventDispatchThread()) { |
342 |
throw new RuntimeException("No Event Dispatch Thread"); |
343 |
} |
344 |
|
345 |
// Para traducir los textos que vengan
|
346 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
347 |
|
348 |
JToolBarButton btn; |
349 |
URL image = loader.getResource(actionTool.getIcon());
|
350 |
|
351 |
if (image != null) { |
352 |
btn = new JToolBarButton(actionTool.getText(), new ImageIcon(image)); |
353 |
} else {
|
354 |
logger.error(PluginServices.getText(this, "Unable_to_find_icon") +": "+actionTool.getIcon()); |
355 |
URL noIconURL = getClass().getClassLoader().getResource(noIcon);
|
356 |
btn = new JToolBarButton(actionTool.getText(), new ImageIcon(noIconURL)); |
357 |
} |
358 |
|
359 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
360 |
btn.addMouseListener(tooltipListener); |
361 |
btn.addActionListener(this);
|
362 |
btn.setFocusable(false);
|
363 |
btn.setActionCommand(actionTool.getActionCommand()); |
364 |
btn.setEnabled(false);
|
365 |
btn.setVisible(false);
|
366 |
|
367 |
String name = toolBar.getName();
|
368 |
|
369 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
370 |
|
371 |
if (jtb == null) { |
372 |
jtb = new SelectableToolBar(name);
|
373 |
jtb.setRollover(true);
|
374 |
jtb.setAndamiVisibility(toolBar.getIsVisible()); |
375 |
toolBarMap.put(name, jtb); |
376 |
toolBars.add(jtb); |
377 |
} |
378 |
|
379 |
jtb.add(btn); |
380 |
|
381 |
controlClass.put(btn, loader.loadClass(ext.getClassName())); |
382 |
|
383 |
if (actionTool.getName() != null) { |
384 |
btn.setName(actionTool.getName()); |
385 |
} |
386 |
|
387 |
if (actionTool.getTooltip() != null) { |
388 |
btn.setToolTip(ps.getText(actionTool.getTooltip())); |
389 |
} |
390 |
|
391 |
if (actionTool.getEnableText() != null) { |
392 |
btn.setEnableText(ps.getText(actionTool.getEnableText())); |
393 |
} |
394 |
|
395 |
if (actionTool.getLast() == true) { |
396 |
jtb.addSeparator(); |
397 |
} |
398 |
} |
399 |
|
400 |
/**
|
401 |
* Creates the needed menu structure to add the menu to the bar.
|
402 |
* Returns the father which must hold the menu which was
|
403 |
* provided as parameter.
|
404 |
*
|
405 |
* Crea la estructura de men?s necesaria para a?adir el menu a la barra.
|
406 |
* Devuelve el padre del cual debe colgar el menu que se pasa como
|
407 |
* par?metro.
|
408 |
*
|
409 |
* @param menu The Menu whose support is going to be added
|
410 |
* @param loader The plugin's class loader
|
411 |
*
|
412 |
* @return The proper father for the menu which was provided as parameter
|
413 |
*/
|
414 |
private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) { |
415 |
MenuElement menuPadre = null; |
416 |
|
417 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
418 |
|
419 |
String[] menues = menu.getText().split("/"); |
420 |
ArrayList menuList = new ArrayList(); |
421 |
menuList.add(menues[0]);
|
422 |
menuPadre = getMenu(menuList, menuBar); |
423 |
|
424 |
JMenu padre = null; |
425 |
|
426 |
if (menuPadre==null) { |
427 |
padre = new JMenu(ps.getText(menues[0])); |
428 |
padre.setName(menues[0]);
|
429 |
menuBar.add(padre); |
430 |
} |
431 |
else if (menuPadre instanceof JMenu) { |
432 |
padre = (JMenu) menuPadre;
|
433 |
} |
434 |
else {
|
435 |
logger.error(ps.getText("error_creating_menu_Ancestor_does_not_exist"));
|
436 |
return null; |
437 |
} |
438 |
|
439 |
//Se crea el resto de menus
|
440 |
ArrayList temp = new ArrayList(); |
441 |
|
442 |
for (int i = 1; i < (menues.length - 1); i++) { |
443 |
temp.add(menues[i]); |
444 |
} |
445 |
|
446 |
menuPadre = createMenus(temp, padre); |
447 |
|
448 |
return (JMenu) menuPadre; |
449 |
} |
450 |
|
451 |
/**
|
452 |
* A?ade la informaci?n del menu al framework. Debido a que los men?es se
|
453 |
* pueden introducir en un orden determinado por el usuario, pero los
|
454 |
* plugins se instalan en un orden arbitrario, primero se almacena la
|
455 |
* informaci?n de todos los menus para luego ordenarlos y posteriormente
|
456 |
* a?adirlos al interfaz
|
457 |
*
|
458 |
* @param loader Posicion del menu. Se ordena por este campo
|
459 |
* @param ext Array con los nombres de los padres del menu
|
460 |
* @param menu Texto del menu
|
461 |
*
|
462 |
* @throws ClassNotFoundException
|
463 |
* @throws RuntimeException DOCUMENT ME!
|
464 |
*/
|
465 |
public void addMenu(PluginClassLoader loader, SkinExtensionType ext, |
466 |
Menu menu) throws ClassNotFoundException { |
467 |
if (!SwingUtilities.isEventDispatchThread()) { |
468 |
throw new RuntimeException("No Event Dispatch Thread"); |
469 |
} |
470 |
|
471 |
JMenu menuPadre = createMenuAncestors(menu, loader);
|
472 |
|
473 |
//Se registra y a?ade el menu
|
474 |
/* String[] aux = menu.getText().split("/");
|
475 |
|
476 |
if (aux.length == 2)
|
477 |
if (aux[1].equals("----"))
|
478 |
{
|
479 |
menuPadre.addSeparator();
|
480 |
return;
|
481 |
} */
|
482 |
if (menu.getIs_separator())
|
483 |
{ |
484 |
menuPadre.addSeparator(); |
485 |
return;
|
486 |
} |
487 |
|
488 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
489 |
nuevoMenu.addMouseListener(tooltipListener); |
490 |
nuevoMenu.addActionListener(this);
|
491 |
menuPadre.add(nuevoMenu); |
492 |
controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName())); |
493 |
} |
494 |
|
495 |
|
496 |
/**
|
497 |
* Dado un array de nombres de menu, encuentra el men?
|
498 |
*
|
499 |
* @param nombres DOCUMENT ME!
|
500 |
* @param padre DOCUMENT ME!
|
501 |
*
|
502 |
* @return DOCUMENT ME!
|
503 |
*/
|
504 |
private javax.swing.JMenuItem getMenu(ArrayList nombres, MenuElement parent) { |
505 |
if (parent instanceof javax.swing.JMenu) { |
506 |
javax.swing.JMenu parentItem = (javax.swing.JMenu) parent; |
507 |
|
508 |
for (int i=0; i<parentItem.getMenuComponentCount(); i++) { |
509 |
if (parentItem.getMenuComponent(i).getName()!=null // not a JToolBar.Separator |
510 |
&& parentItem.getMenuComponent(i).getName().compareTo((String)nombres.get(0)) == 0) { |
511 |
nombres.remove(0);
|
512 |
if (nombres.isEmpty()) {
|
513 |
if (parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem) { |
514 |
return (javax.swing.JMenuItem) parentItem.getMenuComponent(i);
|
515 |
} |
516 |
else {
|
517 |
logger.error(PluginServices.getText(this, "Menu_type_not_supported_")+" "+parentItem.getMenuComponent(i).getClass().getName()); |
518 |
return null; |
519 |
} |
520 |
} |
521 |
else {
|
522 |
return getMenu(nombres, (MenuElement) parentItem.getMenuComponent(i)); |
523 |
} |
524 |
} |
525 |
} |
526 |
} |
527 |
else if (parent instanceof JMenuBar) { |
528 |
javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent; |
529 |
|
530 |
for (int i=0; i<parentItem.getMenuCount(); i++) { |
531 |
if (parentItem.getMenu(i).getName()!=null // not a JToolBar.Separator |
532 |
&& parentItem.getMenu(i).getName().compareTo((String)nombres.get(0)) == 0) { |
533 |
nombres.remove(0);
|
534 |
if (nombres.isEmpty()) {
|
535 |
if (parentItem.getMenu(i) instanceof javax.swing.JMenuItem) { |
536 |
return (javax.swing.JMenuItem) parentItem.getMenu(i);
|
537 |
} |
538 |
else {
|
539 |
logger.error(PluginServices.getText(this, "Menu_type_not_supported_")+" "+parentItem.getMenu(i).getClass().getName()); |
540 |
return null; |
541 |
} |
542 |
} |
543 |
else {
|
544 |
return getMenu(nombres, (MenuElement) parentItem.getMenu(i)); |
545 |
} |
546 |
} |
547 |
} |
548 |
} |
549 |
else {
|
550 |
logger.error(PluginServices.getText(this, "Menu_type_not_supported_")+" "+parent.getClass().getName()+" "+parent.toString()); |
551 |
} |
552 |
return null; |
553 |
} |
554 |
|
555 |
/**
|
556 |
* Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
|
557 |
* en el par?metro nombres el array {"Search", "References", "Workspace"}
|
558 |
* crear? un men? Search, un submen? del anterior que se llamar?
|
559 |
* References y debajo de ?ste ?ltimo otro menu llamado Workspace
|
560 |
*
|
561 |
* @param nombres Array con los nombres de los men?s que se quieren crear
|
562 |
* @param padre Menu padre de los men?s creados. Es ?til porque es un
|
563 |
* algoritmo recursivo
|
564 |
*
|
565 |
* @return Devuelve el men? creado. Al final de toda la recursividad,
|
566 |
* devolver? el men? de m?s abajo en la jerarqu?a
|
567 |
*
|
568 |
* @throws RuntimeException DOCUMENT ME!
|
569 |
*/
|
570 |
private JMenu createMenus(ArrayList nombres, JMenu padre) { |
571 |
if (!SwingUtilities.isEventDispatchThread()) { |
572 |
throw new RuntimeException("No Event Dispatch Thread"); |
573 |
} |
574 |
|
575 |
//si no quedan nombres de menu por crear se vuelve: caso base
|
576 |
if (nombres.size() == 0) { |
577 |
return padre;
|
578 |
} |
579 |
|
580 |
//Se busca el menu por si ya existiera para no crearlo otra vez
|
581 |
JMenu buscado = null; |
582 |
|
583 |
for (int i = 0; i < padre.getMenuComponentCount(); i++) { |
584 |
try {
|
585 |
JMenu hijo = (JMenu) padre.getMenuComponent(i); |
586 |
|
587 |
if (hijo.getName().compareTo((String) nombres.get(0)) == 0) { |
588 |
buscado = hijo; |
589 |
} |
590 |
} catch (ClassCastException e) { |
591 |
/*
|
592 |
* Se ha encontrado un elemento hoja del arbol de men?es
|
593 |
*/
|
594 |
} |
595 |
} |
596 |
|
597 |
if (buscado != null) { |
598 |
//Si lo hemos encontrado creamos el resto
|
599 |
nombres.remove(0);
|
600 |
|
601 |
return createMenus(nombres, buscado);
|
602 |
} else {
|
603 |
//Si no lo hemos encontrado se crea el menu, se a?ade al padre
|
604 |
//y se crea el resto
|
605 |
String nombre = (String) nombres.get(0); |
606 |
JMenu menuPadre = new JMenu((String) PluginServices.getText(this, nombre)); |
607 |
menuPadre.setName(nombre); |
608 |
padre.add(menuPadre); |
609 |
|
610 |
nombres.remove(0);
|
611 |
|
612 |
return createMenus(nombres, menuPadre);
|
613 |
} |
614 |
} |
615 |
|
616 |
/**
|
617 |
* M?todo invocado en respuesta a ciertos eventos de la interfaz que pueden
|
618 |
* ocultar botones de las barras de herramientas y que redimensiona ?sta
|
619 |
* de manera conveniente para que no se oculte ninguno
|
620 |
*/
|
621 |
private void ajustarToolBar() { |
622 |
int margen = 8; |
623 |
int numFilas = 1; |
624 |
double acum = margen;
|
625 |
|
626 |
int toolHeight = 0; |
627 |
|
628 |
for (int i = 0; i < toolBars.getComponentCount(); i++) { |
629 |
Component c = toolBars.getComponent(i);
|
630 |
|
631 |
if (!c.isVisible()) {
|
632 |
continue;
|
633 |
} |
634 |
|
635 |
double width = c.getPreferredSize().getWidth();
|
636 |
acum = acum + width; |
637 |
|
638 |
if (acum > this.getWidth()) { |
639 |
numFilas++; |
640 |
acum = width + margen; |
641 |
} |
642 |
|
643 |
if (c.getPreferredSize().getHeight() > toolHeight) {
|
644 |
toolHeight = c.getPreferredSize().height; |
645 |
} |
646 |
} |
647 |
|
648 |
toolBars.setPreferredSize(new Dimension(this.getWidth(), |
649 |
(int) (numFilas * toolHeight)));
|
650 |
|
651 |
toolBars.updateUI(); |
652 |
} |
653 |
|
654 |
/**
|
655 |
* DOCUMENT ME!
|
656 |
*
|
657 |
* @param classesExtensions
|
658 |
*/
|
659 |
public void setClassesExtensions(HashMap classesExtensions) { |
660 |
this.classesExtensions = classesExtensions;
|
661 |
} |
662 |
|
663 |
/**
|
664 |
* M?todo de callback invocado cuando se selecciona un men? o un bot?n de
|
665 |
* la barra de herramientas. Se busca la extensi?n asociada y se ejecuta
|
666 |
*
|
667 |
* @param e Evento producido
|
668 |
*/
|
669 |
public void actionPerformed(ActionEvent e) { |
670 |
Object control = e.getSource();
|
671 |
com.iver.andami.plugins.IExtension ext = (com.iver.andami.plugins.IExtension) classesExtensions.get((Class) controlClass.get(
|
672 |
control)); |
673 |
String actionCommand = e.getActionCommand();
|
674 |
try {
|
675 |
logger.debug(Messages.getString("Ejecutando comando: ") + actionCommand);
|
676 |
ext.execute(actionCommand); |
677 |
|
678 |
try {
|
679 |
JToolBarToggleButton toggle = (JToolBarToggleButton) control; |
680 |
ToggleButtonModel model = (ToggleButtonModel)toggle.getModel(); |
681 |
selectedTool.put(model.getGroupName(), actionCommand); |
682 |
} |
683 |
catch (ClassCastException ex) {} |
684 |
catch (NullPointerException ex) {} |
685 |
|
686 |
} catch (RuntimeException t) { |
687 |
if (ext==null) { |
688 |
logger.error(Messages.getString("No_extension_associated_with_this_event_")+ e.getActionCommand());
|
689 |
} |
690 |
NotificationManager.addError(Messages.getString( |
691 |
"MDIFrame.Error_no_capturado_por_el_usuario"), t);
|
692 |
} |
693 |
|
694 |
enableControls(); |
695 |
showMemory(); |
696 |
} |
697 |
|
698 |
/**
|
699 |
* DOCUMENT ME!
|
700 |
*
|
701 |
* @param name DOCUMENT ME!
|
702 |
* @param loader DOCUMENT ME!
|
703 |
*
|
704 |
* @return DOCUMENT ME!
|
705 |
*/
|
706 |
private String getName(String name, PluginClassLoader loader) { |
707 |
if (name.indexOf('.') == -1) { |
708 |
return loader.getPluginName() + "." + name; |
709 |
} else {
|
710 |
return name;
|
711 |
} |
712 |
} |
713 |
|
714 |
/**
|
715 |
* DOCUMENT ME!
|
716 |
*
|
717 |
* @param loader DOCUMENT ME!
|
718 |
* @param menu DOCUMENT ME!
|
719 |
*
|
720 |
* @throws RuntimeException DOCUMENT ME!
|
721 |
*/
|
722 |
public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) { |
723 |
if (!SwingUtilities.isEventDispatchThread()) { |
724 |
throw new RuntimeException("No Event Dispatch Thread"); |
725 |
} |
726 |
|
727 |
String name = getName(menu.getName(), loader);
|
728 |
|
729 |
//Se crea el control popupmenu
|
730 |
JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name); |
731 |
|
732 |
if (popupMenu == null) { |
733 |
popupMenu = new JPopUpMenu(menu.getName());
|
734 |
popupMap.put(name, popupMenu); |
735 |
} |
736 |
|
737 |
// Se a?aden las entradas
|
738 |
Menu[] menues = menu.getMenu(); |
739 |
|
740 |
for (int i = 0; i < menues.length; i++) { |
741 |
//Se registra y a?ade el menu
|
742 |
JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
|
743 |
|
744 |
popupMenu.add(nuevoMenu); |
745 |
} |
746 |
} |
747 |
|
748 |
/**
|
749 |
* DOCUMENT ME!
|
750 |
*
|
751 |
* @param loader
|
752 |
* @param menu
|
753 |
*
|
754 |
* @return
|
755 |
*
|
756 |
* @throws RuntimeException DOCUMENT ME!
|
757 |
*/
|
758 |
private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) { |
759 |
JMenuItem nuevoMenu = null; |
760 |
|
761 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
762 |
String text = menu.getText();
|
763 |
text = text.substring(text.lastIndexOf('/') + 1); |
764 |
String translatedText = ps.getText(text);
|
765 |
|
766 |
if (menu.getIcon() != null) { |
767 |
URL url = loader.getResource(menu.getIcon());
|
768 |
if (url != null) { |
769 |
nuevoMenu = new JMenuItem(translatedText, new ImageIcon(url)); |
770 |
} else {
|
771 |
URL noIconURL = loader.getResource(noIcon);
|
772 |
nuevoMenu = new JMenuItem(translatedText, new ImageIcon(noIconURL)); |
773 |
logger.error(PluginServices.getText(this, "Unable_to_find_icon") +": "+menu.getIcon()); |
774 |
} |
775 |
} else {
|
776 |
nuevoMenu = new JMenuItem(translatedText); |
777 |
} |
778 |
nuevoMenu.setName(text); |
779 |
if (menu.getMnemonic() != null) { |
780 |
if (menu.getMnemonic().length() != 1) { |
781 |
throw new RuntimeException( |
782 |
"Mnemonic must be 1 character length");
|
783 |
} |
784 |
|
785 |
nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic().charAt(0)));
|
786 |
} |
787 |
|
788 |
if (menu.getKey() != null) { |
789 |
String osName = (String) System.getProperty("os.name"); |
790 |
boolean MAC_OS_X = osName.toLowerCase().startsWith("mac os x"); |
791 |
if (MAC_OS_X) {
|
792 |
//en OS X, en vez de hardwiring la ShortcutKey, usamos el default sugerido por el OS
|
793 |
nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping.getKey(
|
794 |
menu.getKey().charAt(0)), Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); |
795 |
} else {
|
796 |
nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping.getKey(
|
797 |
menu.getKey().charAt(0)), ActionEvent.ALT_MASK)); |
798 |
} |
799 |
} |
800 |
|
801 |
nuevoMenu.setActionCommand(menu.getActionCommand()); |
802 |
|
803 |
if (menu.getTooltip() != null) { |
804 |
nuevoMenu.setToolTip(ps.getText(menu.getTooltip())); |
805 |
} |
806 |
|
807 |
if (menu.getEnableText() != null) { |
808 |
nuevoMenu.setEnableText(ps.getText(menu.getEnableText())); |
809 |
} |
810 |
|
811 |
nuevoMenu.setEnabled(true);
|
812 |
nuevoMenu.setVisible(true);
|
813 |
|
814 |
return nuevoMenu;
|
815 |
} |
816 |
|
817 |
/**
|
818 |
* Muestra u oculta el menu de nombre 'name'
|
819 |
*
|
820 |
* @param name Nombre del menu que se quiere mostrar
|
821 |
* @param x Evento de raton
|
822 |
* @param y DOCUMENT ME!
|
823 |
* @param c DOCUMENT ME!
|
824 |
*/
|
825 |
private void showPopupMenu(String name, int x, int y, Component c) { |
826 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
827 |
|
828 |
if (menu != null) { |
829 |
menu.show(c, x, y); |
830 |
} |
831 |
} |
832 |
|
833 |
/**
|
834 |
* DOCUMENT ME!
|
835 |
*
|
836 |
* @param name DOCUMENT ME!
|
837 |
* @param listener DOCUMENT ME!
|
838 |
*/
|
839 |
public void removePopupMenuListener(String name, ActionListener listener) { |
840 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
841 |
|
842 |
if (menu != null) { |
843 |
Component[] jmenuitems = menu.getComponents(); |
844 |
|
845 |
for (int i = 0; i < jmenuitems.length; i++) { |
846 |
if (jmenuitems[i] instanceof JMenuItem) { |
847 |
((JMenuItem) jmenuitems[i]).removeActionListener(listener);
|
848 |
} |
849 |
} |
850 |
} |
851 |
} |
852 |
|
853 |
/**
|
854 |
* DOCUMENT ME!
|
855 |
*
|
856 |
* @param popupName
|
857 |
* @param c DOCUMENT ME!
|
858 |
* @param listener
|
859 |
* @param loader
|
860 |
*/
|
861 |
public void addPopupMenuListener(String popupName, Component c, |
862 |
ActionListener listener, PluginClassLoader loader) {
|
863 |
final String name = getName(popupName, loader); |
864 |
|
865 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
866 |
|
867 |
if (menu != null) { |
868 |
Component[] jmenuitems = menu.getComponents(); |
869 |
|
870 |
for (int i = 0; i < jmenuitems.length; i++) { |
871 |
if (jmenuitems[i] instanceof JMenuItem) { |
872 |
((JMenuItem) jmenuitems[i]).addActionListener(listener);
|
873 |
} |
874 |
} |
875 |
} |
876 |
|
877 |
c.addMouseListener(new MouseAdapter() { |
878 |
public void mousePressed(MouseEvent e) { |
879 |
if (e.isPopupTrigger()) {
|
880 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
881 |
} |
882 |
} |
883 |
|
884 |
public void mouseReleased(MouseEvent e) { |
885 |
if (e.isPopupTrigger()) {
|
886 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
887 |
} |
888 |
} |
889 |
}); |
890 |
} |
891 |
|
892 |
/**
|
893 |
* Loop on the controls to enable/disable and show/hide them, according to
|
894 |
* its associated extension
|
895 |
*
|
896 |
* @throws RuntimeException DOCUMENT ME!
|
897 |
*/
|
898 |
public void enableControls() { |
899 |
if (!SwingUtilities.isEventDispatchThread()) { |
900 |
throw new RuntimeException("No Event Dispatch Thread"); |
901 |
} |
902 |
|
903 |
Iterator e = classesExtensions.values().iterator();
|
904 |
HashMap estadoExtensiones = new HashMap(); |
905 |
HashMap visibilidadExtensiones = new HashMap(); |
906 |
|
907 |
while (e.hasNext()) {
|
908 |
ExtensionDecorator ext = (ExtensionDecorator) e.next(); |
909 |
|
910 |
try {
|
911 |
if (estadoExtensiones.get(ext) == null) { |
912 |
boolean b;
|
913 |
if (ext.getVisibility() == ExtensionDecorator.ALWAYS_VISIBLE)
|
914 |
b = true;
|
915 |
else if (ext.getVisibility() == ExtensionDecorator.ALWAYS_INVISIBLE) |
916 |
b = false;
|
917 |
else {
|
918 |
if (PluginServices.getExclusiveUIExtension() == null) { |
919 |
b = ext.isVisible(); |
920 |
} else {
|
921 |
b = PluginServices.getExclusiveUIExtension().isVisible(ext.getExtension()); |
922 |
} |
923 |
} |
924 |
Boolean visible = new Boolean(b); |
925 |
Boolean enabled = new Boolean(false); |
926 |
|
927 |
if (visible.booleanValue()) {
|
928 |
if (PluginServices.getExclusiveUIExtension() == null) { |
929 |
enabled = new Boolean(ext.isEnabled()); |
930 |
}else {
|
931 |
enabled = new Boolean(PluginServices.getExclusiveUIExtension().isEnabled(ext.getExtension())); |
932 |
} |
933 |
|
934 |
} |
935 |
|
936 |
estadoExtensiones.put(ext, enabled); |
937 |
visibilidadExtensiones.put(ext, visible); |
938 |
} |
939 |
} catch (Throwable e1) { |
940 |
NotificationManager.addError(Messages.getString( |
941 |
"MDIFrame.Error_no_capturado_por_el_usuario"), e1);
|
942 |
estadoExtensiones.put(ext, Boolean.FALSE);
|
943 |
} |
944 |
} |
945 |
|
946 |
// Enable or disable controls, according to its associated extensions
|
947 |
e = controlClass.keySet().iterator(); |
948 |
|
949 |
while (e.hasNext()) {
|
950 |
JComponent control = (JComponent) e.next(); |
951 |
|
952 |
try {
|
953 |
com.iver.andami.plugins.IExtension ext = (com.iver.andami.plugins.IExtension) classesExtensions.get((Class) controlClass.get(
|
954 |
control)); |
955 |
boolean enabled = ((Boolean) estadoExtensiones.get(ext)).booleanValue(); |
956 |
boolean visible = ((Boolean) visibilidadExtensiones.get(ext)).booleanValue(); |
957 |
control.setEnabled(enabled); |
958 |
control.setVisible(visible); |
959 |
} catch (Exception ex) { |
960 |
control.setEnabled(false);
|
961 |
control.setVisible(false);
|
962 |
} |
963 |
} |
964 |
|
965 |
// Loop in the menus to hide the menus that don't have visible children
|
966 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
967 |
MenuElement menu = menuBar.getMenu(i);
|
968 |
hideMenus(menu); |
969 |
} |
970 |
|
971 |
// hide the toolbars that don't contain any visible tool
|
972 |
Iterator it = toolBarMap.values().iterator();
|
973 |
|
974 |
while (it.hasNext()) {
|
975 |
SelectableToolBar t = (SelectableToolBar) it.next(); |
976 |
boolean todosOcultos = true; |
977 |
|
978 |
for (int i = 0; i < t.getComponentCount(); i++) { |
979 |
if (!(t.getComponent(i) instanceof JSeparator) // separators don't matter |
980 |
&& t.getComponent(i).isVisible()) { |
981 |
todosOcultos = false;
|
982 |
} |
983 |
} |
984 |
|
985 |
if (todosOcultos) {
|
986 |
t.setVisible(false);
|
987 |
} |
988 |
else {
|
989 |
t.setVisible(t.getAndamiVisibility()); |
990 |
} |
991 |
} |
992 |
|
993 |
if (mdiManager != null) { |
994 |
JPanel f = (JPanel) mdiManager.getActiveWindow(); |
995 |
|
996 |
if (f != null) { |
997 |
if (lastLabelClass != f.getClass()) {
|
998 |
lastLabelClass = f.getClass(); |
999 |
|
1000 |
Label[] lbls = (Label[]) classLabels.get(lastLabelClass); |
1001 |
|
1002 |
if (lbls != null) { |
1003 |
bEstado.setLabelSet(lbls); |
1004 |
} |
1005 |
} |
1006 |
} |
1007 |
} |
1008 |
|
1009 |
ajustarToolBar(); |
1010 |
|
1011 |
showMemory(); |
1012 |
} |
1013 |
|
1014 |
/**
|
1015 |
* Establece la visibilidad de un menu y todos sus descendientes en la
|
1016 |
* jerarquia teniendo en cuenta la visibilidad de todos los submenus.
|
1017 |
*
|
1018 |
* @param menu Menu que se quiere visualizar
|
1019 |
*
|
1020 |
* @return Devuelve true si el menu es visible y false en caso contrario
|
1021 |
*/
|
1022 |
private boolean hideMenus(MenuElement menu) { |
1023 |
MenuElement[] submenus = menu.getSubElements(); |
1024 |
|
1025 |
//Si no tiene hijos se devuelve su visibilidad
|
1026 |
if (submenus.length == 0) { |
1027 |
return menu.getComponent().isVisible();
|
1028 |
} |
1029 |
|
1030 |
/*
|
1031 |
* Si tiene hijos se devuelve true si alg?no de ellos es visible,
|
1032 |
* pero se itera por todos ellos
|
1033 |
*/
|
1034 |
boolean visible = false; |
1035 |
|
1036 |
for (int i = 0; i < submenus.length; i++) { |
1037 |
if (hideMenus(submenus[i])) {
|
1038 |
if (!(menu instanceof JPopupMenu)) { |
1039 |
menu.getComponent().setVisible(true);
|
1040 |
} |
1041 |
|
1042 |
visible = true;
|
1043 |
} |
1044 |
} |
1045 |
|
1046 |
if (visible) {
|
1047 |
return true; |
1048 |
} |
1049 |
|
1050 |
menu.getComponent().setVisible(false);
|
1051 |
|
1052 |
return false; |
1053 |
} |
1054 |
|
1055 |
/**
|
1056 |
* Muestra la memoria consumida por el programa
|
1057 |
*/
|
1058 |
private void showMemory() { |
1059 |
Runtime r = Runtime.getRuntime(); |
1060 |
long mem = r.totalMemory() - r.freeMemory();
|
1061 |
logger.debug("Memoria total: " + mem);
|
1062 |
} |
1063 |
|
1064 |
/**
|
1065 |
* DOCUMENT ME!
|
1066 |
*
|
1067 |
* @return
|
1068 |
*/
|
1069 |
public MDIManager getMDIManager() {
|
1070 |
return mdiManager;
|
1071 |
} |
1072 |
|
1073 |
/**
|
1074 |
* Establece el mensaje en la barra de estado asociado a una etiqueta
|
1075 |
*
|
1076 |
* @return DOCUMENT ME!
|
1077 |
*/
|
1078 |
public NewStatusBar getStatusBar() {
|
1079 |
return bEstado;
|
1080 |
} |
1081 |
/**
|
1082 |
* You can use this function to select the appropiate
|
1083 |
* tool inside the toolbars
|
1084 |
*/
|
1085 |
public void setSelectedTool(String actionCommand) |
1086 |
{ |
1087 |
setSelectedTool(defaultGroup, actionCommand); |
1088 |
} |
1089 |
|
1090 |
/**
|
1091 |
* You can use this function to select the appropiate
|
1092 |
* tool inside the toolbars
|
1093 |
*/
|
1094 |
public void setSelectedTool(String groupName, String actionCommand) |
1095 |
{ |
1096 |
ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName); |
1097 |
if (group==null) |
1098 |
return;
|
1099 |
|
1100 |
Enumeration enumeration = group.getElements();
|
1101 |
while (enumeration.hasMoreElements()) {
|
1102 |
AbstractButton button = (AbstractButton) enumeration.nextElement(); |
1103 |
if (button.getActionCommand().equals(actionCommand)) {
|
1104 |
button.setSelected(true);
|
1105 |
} |
1106 |
} |
1107 |
|
1108 |
selectedTool.put(groupName, actionCommand); |
1109 |
} |
1110 |
|
1111 |
/**
|
1112 |
* You can use this function to select the appropiate
|
1113 |
* tool inside the toolbars
|
1114 |
*/
|
1115 |
public void setSelectedTools(HashMap selectedTools) |
1116 |
{ |
1117 |
selectedTool = selectedTools; |
1118 |
if (selectedTools==null) return; |
1119 |
Iterator groupNames = selectedTools.keySet().iterator();
|
1120 |
while (groupNames.hasNext()) {
|
1121 |
try {
|
1122 |
String groupName = (String) groupNames.next(); |
1123 |
ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName); |
1124 |
Enumeration enumeration = group.getElements();
|
1125 |
String actionCommand = (String) selectedTools.get(groupName); |
1126 |
if (actionCommand==null) continue; |
1127 |
while (enumeration.hasMoreElements()) {
|
1128 |
AbstractButton button = (AbstractButton) enumeration.nextElement(); |
1129 |
if (button.getActionCommand().equals(actionCommand)) {
|
1130 |
button.setSelected(true);
|
1131 |
} |
1132 |
} |
1133 |
} |
1134 |
catch (ClassCastException ex) { |
1135 |
logger.error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
|
1136 |
} |
1137 |
} |
1138 |
} |
1139 |
|
1140 |
/**
|
1141 |
* DOCUMENT ME!
|
1142 |
*
|
1143 |
* @param clase
|
1144 |
* @param label
|
1145 |
*/
|
1146 |
public void setStatusBarLabels(Class clase, Label[] label) { |
1147 |
classLabels.put(clase, label); |
1148 |
} |
1149 |
|
1150 |
public void removeStatusBarLabels(Class clase) { |
1151 |
classLabels.remove(clase); |
1152 |
} |
1153 |
|
1154 |
public void addStatusBarControl(Class extensionClass, IControl control) { |
1155 |
control.addActionListener(this);
|
1156 |
bEstado.addControl(control.getName(), (Component)control);
|
1157 |
controlClass.put(control, extensionClass); |
1158 |
} |
1159 |
|
1160 |
public void removeStatusBarControl(String name) { |
1161 |
Component c = bEstado.removeControl(name);
|
1162 |
if (c!=null) |
1163 |
controlClass.remove(c); |
1164 |
} |
1165 |
|
1166 |
/**
|
1167 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#removeMenu(com.iver.andami.plugins.config.generate.Menu)
|
1168 |
*/
|
1169 |
public void removeMenu(Menu menu) { |
1170 |
JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu); |
1171 |
|
1172 |
if (delete == null) { |
1173 |
throw new NoSuchElementException(menu.getText()); |
1174 |
} |
1175 |
|
1176 |
delete.getParent().remove(delete); |
1177 |
infoCodedMenus.remove(menu); |
1178 |
} |
1179 |
|
1180 |
/**
|
1181 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#addMenu(com.iver.andami.plugins.config.generate.Menu,
|
1182 |
* java.awt.event.ActionListener, PluginClassLoader)
|
1183 |
*/
|
1184 |
public void addMenu(Menu menu, ActionListener listener, |
1185 |
PluginClassLoader loader) { |
1186 |
JMenu menuPadre = createMenuAncestors(menu, loader);
|
1187 |
|
1188 |
//Se registra y a?ade el menu
|
1189 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
1190 |
nuevoMenu.addMouseListener(tooltipListener); |
1191 |
nuevoMenu.addActionListener(listener); |
1192 |
menuPadre.add(nuevoMenu); |
1193 |
|
1194 |
infoCodedMenus.put(menu, nuevoMenu); |
1195 |
} |
1196 |
|
1197 |
/**
|
1198 |
* @see com.iver.andami.ui.mdiFrame.MainFrame#changeMenuName(java.lang.String[],
|
1199 |
* String, com.iver.andami.plugins.PluginClassLoader)
|
1200 |
*/
|
1201 |
public void changeMenuName(String[] menu, String newName, |
1202 |
PluginClassLoader loader) { |
1203 |
|
1204 |
ArrayList menuList = new ArrayList(); |
1205 |
for (int i = 0; i < menu.length; i++) { |
1206 |
menuList.add(menu[i]); |
1207 |
} |
1208 |
|
1209 |
javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar); |
1210 |
if (newMenu==null) { |
1211 |
throw new NoSuchMenuException(menu[0]); |
1212 |
} |
1213 |
else {
|
1214 |
newMenu.setText(PluginServices.getText(this, newName));
|
1215 |
} |
1216 |
} |
1217 |
|
1218 |
/**
|
1219 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
1220 |
*/
|
1221 |
public void componentHidden(ComponentEvent arg0) { |
1222 |
} |
1223 |
|
1224 |
/**
|
1225 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
1226 |
*/
|
1227 |
public void componentMoved(ComponentEvent arg0) { |
1228 |
} |
1229 |
|
1230 |
/**
|
1231 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
1232 |
*/
|
1233 |
public void componentResized(ComponentEvent arg0) { |
1234 |
ajustarToolBar(); |
1235 |
} |
1236 |
|
1237 |
/**
|
1238 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
1239 |
*/
|
1240 |
public void componentShown(ComponentEvent arg0) { |
1241 |
} |
1242 |
|
1243 |
/**
|
1244 |
* @see java.awt.event.ContainerListener#componentAdded(java.awt.event.ContainerEvent)
|
1245 |
*/
|
1246 |
public void componentAdded(ContainerEvent arg0) { |
1247 |
ajustarToolBar(); |
1248 |
} |
1249 |
|
1250 |
/**
|
1251 |
* @see java.awt.event.ContainerListener#componentRemoved(java.awt.event.ContainerEvent)
|
1252 |
*/
|
1253 |
public void componentRemoved(ContainerEvent arg0) { |
1254 |
ajustarToolBar(); |
1255 |
} |
1256 |
|
1257 |
/**
|
1258 |
* DOCUMENT ME!
|
1259 |
*
|
1260 |
* @author $author$
|
1261 |
* @version $Revision: 12697 $
|
1262 |
*/
|
1263 |
public class TooltipListener extends MouseAdapter { |
1264 |
/**
|
1265 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
1266 |
*/
|
1267 |
public void mouseEntered(MouseEvent e) { |
1268 |
JComponent control = (JComponent) e.getSource(); |
1269 |
EnableTextSupport ets = (EnableTextSupport) e.getSource(); |
1270 |
|
1271 |
String texto = null; |
1272 |
texto = control.getToolTipText(); |
1273 |
|
1274 |
if (texto != null) { |
1275 |
bEstado.setInfoTextTemporal(texto); |
1276 |
} |
1277 |
} |
1278 |
|
1279 |
/**
|
1280 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
1281 |
*/
|
1282 |
public void mouseExited(MouseEvent arg0) { |
1283 |
bEstado.restaurarTexto(); |
1284 |
} |
1285 |
|
1286 |
/**
|
1287 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
1288 |
*/
|
1289 |
public void mousePressed(MouseEvent e) { |
1290 |
bEstado.restaurarTexto(); |
1291 |
} |
1292 |
} |
1293 |
public String getTitlePrefix() { |
1294 |
return titlePrefix;
|
1295 |
} |
1296 |
public void setTitlePrefix(String titlePrefix) { |
1297 |
this.titlePrefix = titlePrefix;
|
1298 |
} |
1299 |
|
1300 |
public HashMap getSelectedTools() { |
1301 |
return selectedTool;
|
1302 |
} |
1303 |
|
1304 |
public HashMap getInitialSelectedTools() { |
1305 |
return initialSelectedTools;
|
1306 |
} |
1307 |
|
1308 |
|
1309 |
/**
|
1310 |
* Get a previously added JComponent by name. For example
|
1311 |
* you can use it if you need to obtain a JToolBar to
|
1312 |
* add some customized component.
|
1313 |
* @param name
|
1314 |
* @return the JComponent or null if none has been found
|
1315 |
*/
|
1316 |
public JComponent getComponentByName(String name) |
1317 |
{ |
1318 |
Iterator e = controlClass.keySet().iterator();
|
1319 |
|
1320 |
while (e.hasNext()) {
|
1321 |
JComponent control = (JComponent) e.next(); |
1322 |
String nameCtrl = control.getName();
|
1323 |
if (nameCtrl != null) |
1324 |
{ |
1325 |
if (nameCtrl.compareTo(name) == 0) |
1326 |
return control;
|
1327 |
} |
1328 |
} |
1329 |
Iterator it = toolBarMap.values().iterator();
|
1330 |
while (it.hasNext()) {
|
1331 |
SelectableToolBar t = (SelectableToolBar) it.next(); |
1332 |
String nameCtrl = t.getName();
|
1333 |
if (nameCtrl != null) |
1334 |
if (nameCtrl.compareTo(name) == 0) |
1335 |
return t;
|
1336 |
|
1337 |
} |
1338 |
|
1339 |
return null; |
1340 |
} |
1341 |
|
1342 |
public SelectableToolBar[] getToolbars() { |
1343 |
return (SelectableToolBar[]) toolBarMap.values().toArray(new SelectableToolBar[0]); |
1344 |
} |
1345 |
|
1346 |
public boolean getToolbarVisibility(String name) { |
1347 |
JComponent component = PluginServices.getMainFrame().getComponentByName(name);
|
1348 |
if (component!=null && component instanceof SelectableToolBar) { |
1349 |
SelectableToolBar toolBar = (SelectableToolBar) component; |
1350 |
return toolBar.getAndamiVisibility();
|
1351 |
} |
1352 |
return false; |
1353 |
} |
1354 |
|
1355 |
public boolean setToolbarVisibility(String name, boolean visibility) { |
1356 |
JComponent component = PluginServices.getMainFrame().getComponentByName(name);
|
1357 |
if (component!=null && component instanceof SelectableToolBar) { |
1358 |
SelectableToolBar toolBar = (SelectableToolBar) component; |
1359 |
boolean oldVisibility = toolBar.getAndamiVisibility();
|
1360 |
toolBar.setAndamiVisibility(visibility); |
1361 |
enableControls(); |
1362 |
return oldVisibility;
|
1363 |
} |
1364 |
return false; |
1365 |
} |
1366 |
|
1367 |
public javax.swing.JMenuItem getMenuEntry(String[] menuPath) { |
1368 |
ArrayList menu = new ArrayList(); |
1369 |
for (int i=0; i<menuPath.length; i++) |
1370 |
menu.add(menuPath[i]); |
1371 |
return getMenu(menu, menuBar);
|
1372 |
} |
1373 |
} |