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