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