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