svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / MDIFrame.java @ 41080
History | View | Annotate | Download (66.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.andami.ui.mdiFrame; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Component; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.FlowLayout; |
30 |
import java.awt.Insets; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.awt.event.ComponentEvent; |
34 |
import java.awt.event.ComponentListener; |
35 |
import java.awt.event.ContainerEvent; |
36 |
import java.awt.event.ContainerListener; |
37 |
import java.awt.event.MouseAdapter; |
38 |
import java.awt.event.MouseEvent; |
39 |
import java.awt.event.WindowAdapter; |
40 |
import java.awt.event.WindowEvent; |
41 |
import java.io.File; |
42 |
import java.util.ArrayList; |
43 |
import java.util.Enumeration; |
44 |
import java.util.HashMap; |
45 |
import java.util.Iterator; |
46 |
import java.util.List; |
47 |
import java.util.Map; |
48 |
import java.util.Map.Entry; |
49 |
import java.util.NoSuchElementException; |
50 |
import java.util.StringTokenizer; |
51 |
import java.util.Vector; |
52 |
|
53 |
import javax.swing.AbstractButton; |
54 |
import javax.swing.ButtonGroup; |
55 |
import javax.swing.ImageIcon; |
56 |
import javax.swing.JButton; |
57 |
import javax.swing.JComponent; |
58 |
import javax.swing.JFileChooser; |
59 |
import javax.swing.JFrame; |
60 |
import javax.swing.JMenu; |
61 |
import javax.swing.JMenuBar; |
62 |
import javax.swing.JOptionPane; |
63 |
import javax.swing.JPanel; |
64 |
import javax.swing.JPopupMenu; |
65 |
import javax.swing.JSeparator; |
66 |
import javax.swing.JToolBar; |
67 |
import javax.swing.KeyStroke; |
68 |
import javax.swing.MenuElement; |
69 |
import javax.swing.SwingUtilities; |
70 |
import javax.swing.Timer; |
71 |
import javax.swing.WindowConstants; |
72 |
import javax.swing.filechooser.FileFilter; |
73 |
|
74 |
import org.gvsig.andami.IconThemeHelper; |
75 |
import org.gvsig.andami.Launcher; |
76 |
import org.gvsig.andami.LibraryExtension; |
77 |
import org.gvsig.andami.PluginServices; |
78 |
import org.gvsig.andami.PluginsLocator; |
79 |
import org.gvsig.andami.actioninfo.ActionInfo; |
80 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
81 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
82 |
import org.gvsig.andami.messages.Messages; |
83 |
import org.gvsig.andami.plugins.ExtensionDecorator; |
84 |
import org.gvsig.andami.plugins.IExtension; |
85 |
import org.gvsig.andami.plugins.PluginClassLoader; |
86 |
import org.gvsig.andami.plugins.config.generate.ActionTool; |
87 |
import org.gvsig.andami.plugins.config.generate.Label; |
88 |
import org.gvsig.andami.plugins.config.generate.Menu; |
89 |
import org.gvsig.andami.plugins.config.generate.PopupMenu; |
90 |
import org.gvsig.andami.plugins.config.generate.SelectableTool; |
91 |
import org.gvsig.andami.plugins.config.generate.SkinExtensionType; |
92 |
import org.gvsig.andami.plugins.config.generate.ToolBar; |
93 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
94 |
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory; |
95 |
import org.gvsig.gui.beans.controls.IControl; |
96 |
import org.gvsig.tools.ToolsLocator; |
97 |
import org.gvsig.tools.i18n.I18nManager; |
98 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
99 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
100 |
import org.slf4j.Logger; |
101 |
import org.slf4j.LoggerFactory; |
102 |
|
103 |
/**
|
104 |
* Main application window.
|
105 |
*
|
106 |
* @version $Revision: 39484 $
|
107 |
*/
|
108 |
@SuppressWarnings("unchecked") |
109 |
public class MDIFrame extends JFrame implements ComponentListener, |
110 |
ContainerListener, ActionListener, MainFrame { |
111 |
|
112 |
private static final long serialVersionUID = -2472484309160847654L; |
113 |
|
114 |
private static Logger logger = LoggerFactory.getLogger(MDIFrame.class); |
115 |
private MDIManager mdiManager = MDIManagerFactory.createManager();
|
116 |
|
117 |
/** Elementos de la aplicaci�n */
|
118 |
private JMenuBar menuBar = new JMenuBar(); |
119 |
|
120 |
/** Panel which contains the toolbars */
|
121 |
private JPanel toolBars = new JPanel(); |
122 |
|
123 |
/** Status bar */
|
124 |
private NewStatusBar bEstado = null; |
125 |
|
126 |
/** Asocia los nombres con las barras de herramientas */
|
127 |
private HashMap toolBarMap = new HashMap(); |
128 |
|
129 |
/** Almacena los grupos de selectableTools */
|
130 |
private HashMap buttonGroupMap = new HashMap(); |
131 |
/**
|
132 |
* Stores the initially selected tools.
|
133 |
* It contains pairs (String groupName, JToolBarToggleButton button)
|
134 |
*/
|
135 |
private HashMap initialSelectedTools = new HashMap(); |
136 |
|
137 |
/**
|
138 |
* Stores the actionCommand of the selected tool, for each group.
|
139 |
* It contains pairs (String groupName, JToolBarToggleButton button)
|
140 |
*/
|
141 |
private Map selectedTool = null; |
142 |
// this should be the same value defined at plugin-config.xsd
|
143 |
private String defaultGroup = "unico"; |
144 |
|
145 |
/** Asocia los nombres con los popupMenus */
|
146 |
private HashMap popupMap = new HashMap(); |
147 |
|
148 |
/** Asocia controles con la clase de la extension asociada */
|
149 |
private HashMap controlClass = new HashMap(); |
150 |
|
151 |
/**
|
152 |
* Asocia la informaci�n sobre las etiquetas que van en la status bar con
|
153 |
* cada extension
|
154 |
*/
|
155 |
private HashMap classLabels = new HashMap(); |
156 |
|
157 |
// private HashMap classControls = new HashMap();
|
158 |
|
159 |
/** ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener) */
|
160 |
private ArrayList progressListeners = new ArrayList(); |
161 |
|
162 |
/** Timer para invocar los enventos de la interfaz anterior */
|
163 |
private Timer progressTimer = null; |
164 |
|
165 |
/** Tabla hash que asocia las clases con las extensiones */
|
166 |
private Map classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>(); |
167 |
|
168 |
/** �ltima clase que activ� etiquetas */
|
169 |
private Class lastLabelClass; |
170 |
|
171 |
/** Instancia que pone los tooltip en la barra de estado */
|
172 |
private TooltipListener tooltipListener = new TooltipListener(); |
173 |
|
174 |
private HashMap infoCodedMenus = new HashMap(); |
175 |
|
176 |
private String titlePrefix; |
177 |
|
178 |
private static final String noIcon = "no-icon"; |
179 |
|
180 |
/**
|
181 |
* Makes some initialization tasks.
|
182 |
*
|
183 |
* @throws RuntimeException
|
184 |
* DOCUMENT ME!
|
185 |
*/
|
186 |
public void init() { |
187 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
188 |
if (!SwingUtilities.isEventDispatchThread()) { |
189 |
throw new RuntimeException("Not Event Dispatch Thread"); |
190 |
} |
191 |
|
192 |
// Se a�aden los listeners del JFrame
|
193 |
this.addWindowListener(new WindowAdapter() { |
194 |
|
195 |
@Override
|
196 |
public void windowClosing(WindowEvent e) { |
197 |
Launcher.closeApplication(); |
198 |
} |
199 |
}); |
200 |
this.addComponentListener(this); |
201 |
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
202 |
|
203 |
// Se configura la barra de menu
|
204 |
setJMenuBar(menuBar); |
205 |
|
206 |
// Se configura el layout del JFrame principal
|
207 |
this.getContentPane().setLayout(new BorderLayout()); |
208 |
|
209 |
/*
|
210 |
* Se configura y se a�ade el JPanel de las barras de
|
211 |
* herramientas
|
212 |
*/
|
213 |
FlowLayout layout = new FlowLayout(FlowLayout.LEFT); |
214 |
layout.setHgap(0);
|
215 |
layout.setVgap(0);
|
216 |
toolBars.setLayout(layout); |
217 |
getContentPane().add(toolBars, BorderLayout.PAGE_START);
|
218 |
|
219 |
// Se a�ade la barra de estado a la aplicaci�n
|
220 |
bEstado = new NewStatusBar();
|
221 |
bEstado.message(Messages.getString("StatusBar.Aplicacion_iniciada"), JOptionPane.INFORMATION_MESSAGE); |
222 |
getContentPane().add(bEstado, BorderLayout.SOUTH);
|
223 |
|
224 |
this.toolBars.addContainerListener(this); |
225 |
|
226 |
|
227 |
/*
|
228 |
* Setting default values. Persistence is read
|
229 |
* afterwards
|
230 |
*/
|
231 |
setSize( |
232 |
MainFrame.MAIN_FRAME_SIZE_DEFAULT[0],
|
233 |
MainFrame.MAIN_FRAME_SIZE_DEFAULT[1]);
|
234 |
setLocation( |
235 |
MainFrame.MAIN_FRAME_POS_DEFAULT[0],
|
236 |
MainFrame.MAIN_FRAME_POS_DEFAULT[1]);
|
237 |
setExtendedState( |
238 |
MainFrame.MAIN_FRAME_EXT_STATE_DEFAULT); |
239 |
|
240 |
mdiManager.init(this);
|
241 |
|
242 |
/*
|
243 |
* pack() would resize the main frame
|
244 |
*
|
245 |
*/
|
246 |
// pack();
|
247 |
|
248 |
} |
249 |
|
250 |
|
251 |
|
252 |
/*
|
253 |
* (non-javadoc)
|
254 |
*
|
255 |
* @see java.awt.Frame.setTitle(String title)
|
256 |
*/
|
257 |
@Override
|
258 |
public void setTitle(final String title) { |
259 |
if (!SwingUtilities.isEventDispatchThread()) { |
260 |
SwingUtilities.invokeLater(new Runnable() { |
261 |
public void run() { |
262 |
setTitle(title); |
263 |
} |
264 |
}); |
265 |
return;
|
266 |
} |
267 |
super.setTitle(titlePrefix + " : " + title); |
268 |
} |
269 |
|
270 |
/**
|
271 |
* A�ade un modo de operaci�n a la caja de herramientas
|
272 |
*
|
273 |
* @param ext
|
274 |
* Texto del boton, si es null no aparece texto
|
275 |
* @param ext
|
276 |
* Icono del boton, si es null no aparece icono
|
277 |
* @param ext
|
278 |
* Extensi�n asociada al control
|
279 |
* @param selectableTool
|
280 |
* Enable text del control
|
281 |
*
|
282 |
* @throws ClassNotFoundException
|
283 |
* @throws RuntimeException
|
284 |
* DOCUMENT ME!
|
285 |
*/
|
286 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
287 |
ToolBar toolBar, SelectableTool selectableTool) |
288 |
throws ClassNotFoundException { |
289 |
if (!SwingUtilities.isEventDispatchThread()) { |
290 |
throw new RuntimeException("No Event Dispatch Thread"); |
291 |
} |
292 |
|
293 |
Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName()); |
294 |
|
295 |
// Para traducir
|
296 |
PluginServices ps = |
297 |
PluginServices.getPluginServices(loader.getPluginName()); |
298 |
|
299 |
JToolBarToggleButton btn; |
300 |
ImageIcon image =
|
301 |
PluginServices.getIconTheme().get(selectableTool.getIcon()); |
302 |
|
303 |
if (image != null) { |
304 |
btn = new JToolBarToggleButton(selectableTool.getText(), image);
|
305 |
} else {
|
306 |
logger.error(PluginServices.getText(this, "Unable_to_find_icon") |
307 |
+ ": " + selectableTool.getIcon());
|
308 |
btn = |
309 |
new JToolBarToggleButton(selectableTool.getText(),
|
310 |
PluginServices.getIconTheme().get(noIcon)); |
311 |
} |
312 |
|
313 |
org.gvsig.andami.ui.mdiFrame.ToggleButtonModel buttonModel = |
314 |
new org.gvsig.andami.ui.mdiFrame.ToggleButtonModel();
|
315 |
btn.setModel(buttonModel); |
316 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
317 |
btn.addMouseListener(tooltipListener); |
318 |
btn.addActionListener(this);
|
319 |
btn.setFocusable(false);
|
320 |
btn.setActionCommand(selectableTool.getActionCommand()); |
321 |
btn.setToolTipText(selectableTool.getTooltip()); |
322 |
btn.setEnabled(false);
|
323 |
btn.setVisible(false);
|
324 |
String name = toolBar.getName();
|
325 |
|
326 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
327 |
|
328 |
if (jtb == null) { |
329 |
jtb = new SelectableToolBar(name);
|
330 |
jtb.setRollover(true);
|
331 |
jtb.setAndamiVisibility(toolBar.getIsVisible()); |
332 |
toolBarMap.put(name, jtb); |
333 |
toolBars.add(jtb); |
334 |
} |
335 |
|
336 |
ButtonGroup group;
|
337 |
if (buttonGroupMap.containsKey(selectableTool.getGroup())) {
|
338 |
group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
|
339 |
} else {
|
340 |
group = new ButtonGroup(); |
341 |
buttonGroupMap.put(selectableTool.getGroup(), group); |
342 |
|
343 |
} |
344 |
jtb.addButton(group, btn); |
345 |
buttonModel.setGroupName(selectableTool.getGroup()); |
346 |
|
347 |
if (selectableTool.getIsDefault()) {
|
348 |
btn.setSelected(true);
|
349 |
initialSelectedTools.put(selectableTool.getGroup(), |
350 |
btn.getActionCommand()); |
351 |
} |
352 |
|
353 |
controlClass.put(btn, classExtension); |
354 |
|
355 |
if (selectableTool.getName() != null) { |
356 |
btn.setName(selectableTool.getName()); |
357 |
} |
358 |
|
359 |
if (selectableTool.getTooltip() != null) { |
360 |
btn.setToolTip(ps.getText(selectableTool.getTooltip())); |
361 |
} |
362 |
|
363 |
if (selectableTool.getEnableText() != null) { |
364 |
btn.setEnableText(ps.getText(selectableTool.getEnableText())); |
365 |
} |
366 |
|
367 |
if (selectableTool.getLast() == true) { |
368 |
jtb.addSeparator(); |
369 |
} |
370 |
} |
371 |
|
372 |
/**
|
373 |
* A�ade un bot�n a la barra de herramientas
|
374 |
*
|
375 |
* @param ext
|
376 |
* Texto del boton, si es null no aparece texto
|
377 |
* @param ext
|
378 |
* Extensi�n asociada al control
|
379 |
* @param toolBar
|
380 |
* Icono del boton, si es null no aparece texto
|
381 |
* @param actionTool
|
382 |
* Tooltip de la barra de herramientas
|
383 |
*
|
384 |
* @throws ClassNotFoundException
|
385 |
* @throws RuntimeException
|
386 |
* DOCUMENT ME!
|
387 |
*/
|
388 |
public void addTool(PluginClassLoader loader, SkinExtensionType ext, |
389 |
ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException { |
390 |
if (!SwingUtilities.isEventDispatchThread()) { |
391 |
throw new RuntimeException("No Event Dispatch Thread"); |
392 |
} |
393 |
Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName()); |
394 |
|
395 |
// Para traducir los textos que vengan
|
396 |
PluginServices ps = |
397 |
PluginServices.getPluginServices(loader.getPluginName()); |
398 |
|
399 |
JToolBarButton btn; |
400 |
ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
|
401 |
|
402 |
if (image != null) { |
403 |
btn = new JToolBarButton(actionTool.getText(), image);
|
404 |
} else {
|
405 |
logger.error(PluginServices.getText(this, "Unable_to_find_icon") |
406 |
+ ": " + actionTool.getIcon());
|
407 |
btn = |
408 |
new JToolBarButton(actionTool.getText(), PluginServices
|
409 |
.getIconTheme().get(noIcon)); |
410 |
} |
411 |
|
412 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
413 |
btn.addMouseListener(tooltipListener); |
414 |
btn.addActionListener(this);
|
415 |
btn.setFocusable(false);
|
416 |
btn.setActionCommand(actionTool.getActionCommand()); |
417 |
btn.setEnabled(false);
|
418 |
btn.setVisible(false);
|
419 |
|
420 |
String name = toolBar.getName();
|
421 |
|
422 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name); |
423 |
|
424 |
if (jtb == null) { |
425 |
jtb = new SelectableToolBar(name);
|
426 |
jtb.setRollover(true);
|
427 |
jtb.setAndamiVisibility(toolBar.getIsVisible()); |
428 |
toolBarMap.put(name, jtb); |
429 |
toolBars.add(jtb); |
430 |
} |
431 |
|
432 |
jtb.add(btn); |
433 |
|
434 |
controlClass.put(btn, classExtension); |
435 |
|
436 |
if (actionTool.getName() != null) { |
437 |
btn.setName(actionTool.getName()); |
438 |
} |
439 |
|
440 |
if (actionTool.getTooltip() != null) { |
441 |
btn.setToolTip(ps.getText(actionTool.getTooltip())); |
442 |
} |
443 |
|
444 |
if (actionTool.getEnableText() != null) { |
445 |
btn.setEnableText(ps.getText(actionTool.getEnableText())); |
446 |
} |
447 |
|
448 |
if (actionTool.getLast() == true) { |
449 |
jtb.addSeparator(); |
450 |
} |
451 |
} |
452 |
|
453 |
public void addTool(final ActionInfo action, final String toolBarName) { |
454 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
455 |
|
456 |
if (!SwingUtilities.isEventDispatchThread()) { |
457 |
SwingUtilities.invokeLater(new Runnable() { |
458 |
public void run() { |
459 |
addTool(action, toolBarName); |
460 |
} |
461 |
}); |
462 |
return;
|
463 |
} |
464 |
JToolBarButton btn = new JToolBarButton(action.getIcon());
|
465 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
466 |
btn.addMouseListener(tooltipListener); |
467 |
btn.addActionListener(this);
|
468 |
btn.setFocusable(false);
|
469 |
btn.setActionCommand(action.getCommand()); |
470 |
btn.setEnabled(false);
|
471 |
btn.setVisible(false);
|
472 |
btn.setName(action.getName()); |
473 |
if (action.getTooltip() != null) { |
474 |
btn.setToolTip(i18nManager.getTranslation(action.getTooltip())); |
475 |
} |
476 |
|
477 |
SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName); |
478 |
if (jtb == null) { |
479 |
jtb = new SelectableToolBar(toolBarName);
|
480 |
jtb.setRollover(true);
|
481 |
jtb.setAndamiVisibility(true);
|
482 |
toolBarMap.put(toolBarName, jtb); |
483 |
toolBars.add(jtb); |
484 |
} |
485 |
jtb.add(btn); |
486 |
|
487 |
controlClass.put(btn, action.getExtension().getClass()); |
488 |
} |
489 |
|
490 |
/**
|
491 |
* Creates the needed menu structure to add the menu to the bar.
|
492 |
* Returns the father which must hold the menu which was
|
493 |
* provided as parameter.
|
494 |
*
|
495 |
* Crea la estructura de men�s necesaria para a�adir el menu a la barra.
|
496 |
* Devuelve el padre del cual debe colgar el menu que se pasa como
|
497 |
* par�metro.
|
498 |
*
|
499 |
* @param menu
|
500 |
* The Menu whose support is going to be added
|
501 |
* @param loader
|
502 |
* The plugin's class loader
|
503 |
*
|
504 |
* @return The proper father for the menu which was provided as parameter
|
505 |
*/
|
506 |
private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) { |
507 |
return createMenuAncestors(menu.getText());
|
508 |
} |
509 |
|
510 |
private JMenu createMenuAncestors(String text) { |
511 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
512 |
|
513 |
MenuElement menuPadre = null; |
514 |
|
515 |
String[] menues = text.split("/"); |
516 |
List menuList = new ArrayList(); |
517 |
menuList.add(menues[0]);
|
518 |
menuPadre = getMenu(menuList, menuBar); |
519 |
|
520 |
JMenu padre = null; |
521 |
|
522 |
if (menuPadre == null) { |
523 |
padre = new JMenu(i18nManager.getTranslation(menues[0])); |
524 |
padre.setName(menues[0]);
|
525 |
menuBar.add(padre); |
526 |
} else
|
527 |
if (menuPadre instanceof JMenu) { |
528 |
padre = (JMenu) menuPadre;
|
529 |
} else {
|
530 |
logger.error(i18nManager.getTranslation("error_creating_menu_Ancestor_does_not_exist"));
|
531 |
return null; |
532 |
} |
533 |
|
534 |
// Se crea el resto de menus
|
535 |
ArrayList temp = new ArrayList(); |
536 |
|
537 |
for (int i = 1; i < (menues.length - 1); i++) { |
538 |
temp.add(menues[i]); |
539 |
} |
540 |
|
541 |
menuPadre = createMenus(temp, padre); |
542 |
|
543 |
return (JMenu) menuPadre; |
544 |
} |
545 |
|
546 |
/**
|
547 |
* A�ade la informaci�n del menu al framework. Debido a que los men�es
|
548 |
* se
|
549 |
* pueden introducir en un orden determinado por el usuario, pero los
|
550 |
* plugins se instalan en un orden arbitrario, primero se almacena la
|
551 |
* informaci�n de todos los menus para luego ordenarlos y posteriormente
|
552 |
* a�adirlos al interfaz
|
553 |
*
|
554 |
* @param loader
|
555 |
* Posicion del menu. Se ordena por este campo
|
556 |
* @param ext
|
557 |
* Array con los nombres de los padres del menu
|
558 |
* @param menu
|
559 |
* Texto del menu
|
560 |
*
|
561 |
* @throws ClassNotFoundException
|
562 |
* @throws RuntimeException
|
563 |
* DOCUMENT ME!
|
564 |
*/
|
565 |
public void addMenu(PluginClassLoader loader, SkinExtensionType ext, |
566 |
Menu menu) throws ClassNotFoundException { |
567 |
if (!SwingUtilities.isEventDispatchThread()) { |
568 |
throw new RuntimeException("No Event Dispatch Thread"); |
569 |
} |
570 |
JMenu menuPadre = createMenuAncestors(menu, loader);
|
571 |
|
572 |
if (menu.getIs_separator()) {
|
573 |
menuPadre.addSeparator(); |
574 |
return;
|
575 |
} |
576 |
|
577 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
578 |
nuevoMenu.addMouseListener(tooltipListener); |
579 |
//nuevoMenu.addActionListener(this);
|
580 |
menuPadre.add(nuevoMenu); |
581 |
Class<? extends IExtension> classExtension = (Class<? extends IExtension>) loader.loadClass(ext.getClassName()); |
582 |
controlClass.put(nuevoMenu, classExtension); |
583 |
} |
584 |
|
585 |
public void addMenu(final ActionInfo action, final String text) { |
586 |
if (!SwingUtilities.isEventDispatchThread()) { |
587 |
SwingUtilities.invokeLater(new Runnable() { |
588 |
public void run() { |
589 |
addMenu(action,text); |
590 |
} |
591 |
}); |
592 |
return;
|
593 |
} |
594 |
JMenu menuPadre = createMenuAncestors(text);
|
595 |
JMenuItem nuevoMenu = createJMenuItem(action, text);
|
596 |
nuevoMenu.addMouseListener(tooltipListener); |
597 |
menuPadre.add(nuevoMenu); |
598 |
Class<? extends IExtension> classExtension = action.getExtension().getClass(); |
599 |
controlClass.put(nuevoMenu, classExtension); |
600 |
} |
601 |
|
602 |
/**
|
603 |
* Dado un array de nombres de menu, encuentra el men�
|
604 |
*
|
605 |
* @param nombres
|
606 |
* DOCUMENT ME!
|
607 |
* @param padre
|
608 |
* DOCUMENT ME!
|
609 |
*
|
610 |
* @return DOCUMENT ME!
|
611 |
*/
|
612 |
private javax.swing.JMenuItem getMenu(List nombres, MenuElement parent) { |
613 |
if (parent instanceof javax.swing.JMenu) { |
614 |
javax.swing.JMenu parentItem = (javax.swing.JMenu) parent; |
615 |
|
616 |
for (int i = 0; i < parentItem.getMenuComponentCount(); i++) { |
617 |
|
618 |
String item_name = parentItem.getMenuComponent(i).getName();
|
619 |
if (((item_name != null) && (item_name.compareTo((String) nombres.get(0)) == 0)) |
620 |
|| |
621 |
/*
|
622 |
* We also accept "leaf menus" with no name
|
623 |
* (Project manager, View-1, View-2, etc)
|
624 |
*/
|
625 |
lastMenuItemWithoutName(parentItem.getMenuComponent(i), nombres)) |
626 |
{ |
627 |
|
628 |
nombres.remove(0);
|
629 |
if (nombres.isEmpty()) {
|
630 |
if (parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem) { |
631 |
return (javax.swing.JMenuItem) parentItem
|
632 |
.getMenuComponent(i); |
633 |
} else {
|
634 |
logger.error(PluginServices.getText(this,
|
635 |
"Menu_type_not_supported_")
|
636 |
+ " "
|
637 |
+ parentItem.getMenuComponent(i).getClass() |
638 |
.getName()); |
639 |
return null; |
640 |
} |
641 |
} else {
|
642 |
return getMenu(nombres,
|
643 |
(MenuElement) parentItem.getMenuComponent(i));
|
644 |
} |
645 |
} |
646 |
} |
647 |
} else
|
648 |
if (parent instanceof JMenuBar) { |
649 |
javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent; |
650 |
|
651 |
for (int i = 0; i < parentItem.getMenuCount(); i++) { |
652 |
if ((parentItem.getMenu(i).getName() != null // not a |
653 |
// JToolBar.Separator
|
654 |
) |
655 |
&& (parentItem.getMenu(i).getName() |
656 |
.compareTo((String) nombres.get(0)) == 0)) { |
657 |
nombres.remove(0);
|
658 |
if (nombres.isEmpty()) {
|
659 |
if (parentItem.getMenu(i) instanceof javax.swing.JMenuItem) { |
660 |
return parentItem.getMenu(i);
|
661 |
} else {
|
662 |
logger.error(PluginServices.getText(this,
|
663 |
"Menu_type_not_supported_")
|
664 |
+ " "
|
665 |
+ parentItem.getMenu(i).getClass() |
666 |
.getName()); |
667 |
return null; |
668 |
} |
669 |
} else {
|
670 |
return getMenu(nombres, parentItem.getMenu(i));
|
671 |
} |
672 |
} |
673 |
} |
674 |
} else {
|
675 |
logger.error(PluginServices.getText(this,
|
676 |
"Menu_type_not_supported_")
|
677 |
+ " "
|
678 |
+ parent.getClass().getName() + " " + parent.toString());
|
679 |
} |
680 |
return null; |
681 |
} |
682 |
|
683 |
/**
|
684 |
* @param menuComponent
|
685 |
* @param nombres
|
686 |
* @return
|
687 |
*/
|
688 |
private boolean lastMenuItemWithoutName(Component mc, List names) { |
689 |
|
690 |
/*
|
691 |
* names must have 1 string
|
692 |
*/
|
693 |
if (names == null || names.size() != 1) { |
694 |
return false; |
695 |
} |
696 |
if (!(mc instanceof JMenuItem)) { |
697 |
return false; |
698 |
} |
699 |
JMenuItem jmi = (JMenuItem) mc; |
700 |
if (jmi.getName() != null) { |
701 |
/*
|
702 |
* Name must be null, so this is a menu leaf
|
703 |
*/
|
704 |
return false; |
705 |
} |
706 |
if (jmi.getText() == null) { |
707 |
return false; |
708 |
} |
709 |
return jmi.getText().compareTo((String) names.get(0)) == 0; |
710 |
} |
711 |
|
712 |
/**
|
713 |
* Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
|
714 |
* en el par�metro nombres el array {"Search", "References", "Workspace"}
|
715 |
* crear� un men� Search, un submen� del anterior que se llamar�
|
716 |
* References y debajo de �ste �ltimo otro menu llamado Workspace
|
717 |
*
|
718 |
* @param nombres
|
719 |
* Array con los nombres de los men�s que se quieren crear
|
720 |
* @param padre
|
721 |
* Menu padre de los men�s creados. Es �til porque es un
|
722 |
* algoritmo recursivo
|
723 |
*
|
724 |
* @return Devuelve el men� creado. Al final de toda la recursividad,
|
725 |
* devolver� el men� de m�s abajo en la jerarqu�a
|
726 |
*
|
727 |
* @throws RuntimeException
|
728 |
* DOCUMENT ME!
|
729 |
*/
|
730 |
private JMenu createMenus(ArrayList nombres, JMenu padre) { |
731 |
if (!SwingUtilities.isEventDispatchThread()) { |
732 |
throw new RuntimeException("No Event Dispatch Thread"); |
733 |
} |
734 |
|
735 |
// si no quedan nombres de menu por crear se vuelve: caso base
|
736 |
if (nombres.size() == 0) { |
737 |
return padre;
|
738 |
} |
739 |
|
740 |
// Se busca el menu por si ya existiera para no crearlo otra vez
|
741 |
JMenu buscado = null; |
742 |
|
743 |
for (int i = 0; i < padre.getMenuComponentCount(); i++) { |
744 |
try {
|
745 |
JMenu hijo = (JMenu) padre.getMenuComponent(i); |
746 |
|
747 |
if (hijo.getName().compareTo((String) nombres.get(0)) == 0) { |
748 |
buscado = hijo; |
749 |
} |
750 |
} catch (ClassCastException e) { |
751 |
/*
|
752 |
* Se ha encontrado un elemento hoja del arbol de men�es
|
753 |
*/
|
754 |
} |
755 |
} |
756 |
|
757 |
if (buscado != null) { |
758 |
// Si lo hemos encontrado creamos el resto
|
759 |
nombres.remove(0);
|
760 |
|
761 |
return createMenus(nombres, buscado);
|
762 |
} else {
|
763 |
// Si no lo hemos encontrado se crea el menu, se a�ade al padre
|
764 |
// y se crea el resto
|
765 |
String nombre = (String) nombres.get(0); |
766 |
JMenu menuPadre = new JMenu(PluginServices.getText(this, nombre)); |
767 |
menuPadre.setName(nombre); |
768 |
padre.add(menuPadre); |
769 |
|
770 |
nombres.remove(0);
|
771 |
|
772 |
return createMenus(nombres, menuPadre);
|
773 |
} |
774 |
} |
775 |
|
776 |
/**
|
777 |
* M�todo invocado en respuesta a ciertos eventos de la interfaz que
|
778 |
* pueden
|
779 |
* ocultar botones de las barras de herramientas y que redimensiona �sta
|
780 |
* de manera conveniente para que no se oculte ninguno
|
781 |
*/
|
782 |
private void ajustarToolBar() { |
783 |
int margen = 8; |
784 |
int numFilas = 1; |
785 |
double acum = margen;
|
786 |
|
787 |
int toolHeight = 0; |
788 |
|
789 |
for (int i = 0; i < toolBars.getComponentCount(); i++) { |
790 |
Component c = toolBars.getComponent(i);
|
791 |
|
792 |
if (!c.isVisible()) {
|
793 |
continue;
|
794 |
} |
795 |
|
796 |
double width = c.getPreferredSize().getWidth();
|
797 |
acum = acum + width; |
798 |
|
799 |
if (acum > this.getWidth()) { |
800 |
numFilas++; |
801 |
acum = width + margen; |
802 |
} |
803 |
|
804 |
if (c.getPreferredSize().getHeight() > toolHeight) {
|
805 |
toolHeight = c.getPreferredSize().height; |
806 |
} |
807 |
} |
808 |
|
809 |
toolBars.setPreferredSize(new Dimension(this.getWidth(), |
810 |
(numFilas * toolHeight))); |
811 |
|
812 |
toolBars.updateUI(); |
813 |
} |
814 |
|
815 |
/**
|
816 |
* DOCUMENT ME!
|
817 |
*
|
818 |
* @param classesExtensions
|
819 |
*/
|
820 |
public void setClassesExtensions(Map<Class<? extends IExtension>, ExtensionDecorator> classesExtensions) { |
821 |
Map<Class<? extends IExtension>, ExtensionDecorator> extensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>(); |
822 |
for ( Entry<Class<? extends IExtension>, ExtensionDecorator> entry: classesExtensions.entrySet()) { |
823 |
if( ! (entry.getValue().getExtension() instanceof LibraryExtension) ) { |
824 |
extensions.put(entry.getKey(), entry.getValue()); |
825 |
} |
826 |
} |
827 |
this.classesExtensions = extensions;
|
828 |
} |
829 |
|
830 |
/**
|
831 |
* Metodo de callback invocado cuando se selecciona un menu o un boton
|
832 |
* de
|
833 |
* la barra de herramientas. Se busca la extensi�n asociada y se ejecuta
|
834 |
*
|
835 |
* @param e
|
836 |
* Evento producido
|
837 |
*/
|
838 |
public void actionPerformed(ActionEvent e) { |
839 |
|
840 |
// org.gvsig.andami.plugins.IExtension ext =
|
841 |
// (org.gvsig.andami.plugins.IExtension) classesExtensions
|
842 |
// .get(controlClass.get(control));
|
843 |
String actionName = "(unknow)"; |
844 |
try {
|
845 |
JComponent control = (JComponent) e.getSource(); |
846 |
actionName = control.getName(); |
847 |
|
848 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
849 |
ActionInfo action = actionManager.getAction(control.getName()); |
850 |
Object args = null; |
851 |
if( control instanceof IControl ) { |
852 |
args = ((IControl) control).getValue(); |
853 |
} |
854 |
if( args == null ) { |
855 |
action.execute(); |
856 |
} else {
|
857 |
action.execute(args); |
858 |
} |
859 |
|
860 |
// logger.info("{}.execute('{}')", ext.getClass().getSimpleName(), actionCommand);
|
861 |
// ext.execute(actionCommand);
|
862 |
|
863 |
String actionCommand = e.getActionCommand();
|
864 |
try {
|
865 |
JToolBarToggleButton toggle = (JToolBarToggleButton) control; |
866 |
ToggleButtonModel model = (ToggleButtonModel) toggle.getModel(); |
867 |
selectedTool.put(model.getGroupName(), actionCommand); |
868 |
} catch (ClassCastException ex) { |
869 |
} catch (NullPointerException ex) { |
870 |
} |
871 |
|
872 |
} catch (Throwable ex) { |
873 |
logger.error("Can't perform action '"+actionName+"'.",ex); |
874 |
// if (ext == null) {
|
875 |
// logger.error(Messages
|
876 |
// .getString("No_extension_associated_with_this_event_")
|
877 |
// + e.getActionCommand());
|
878 |
// }
|
879 |
// NotificationManager.addError(Messages
|
880 |
// .getString("MDIFrame.Error_no_capturado_por_el_usuario"), t);
|
881 |
} |
882 |
|
883 |
enableControls(); |
884 |
showMemory(); |
885 |
} |
886 |
|
887 |
/**
|
888 |
* DOCUMENT ME!
|
889 |
*
|
890 |
* @param name
|
891 |
* DOCUMENT ME!
|
892 |
* @param loader
|
893 |
* DOCUMENT ME!
|
894 |
*
|
895 |
* @return DOCUMENT ME!
|
896 |
*/
|
897 |
private String getName(String name, PluginClassLoader loader) { |
898 |
if (name.indexOf('.') == -1) { |
899 |
return loader.getPluginName() + "." + name; |
900 |
} else {
|
901 |
return name;
|
902 |
} |
903 |
} |
904 |
|
905 |
/**
|
906 |
* DOCUMENT ME!
|
907 |
*
|
908 |
* @param loader
|
909 |
* DOCUMENT ME!
|
910 |
* @param menu
|
911 |
* DOCUMENT ME!
|
912 |
*
|
913 |
* @throws RuntimeException
|
914 |
* DOCUMENT ME!
|
915 |
*/
|
916 |
public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) { |
917 |
if (!SwingUtilities.isEventDispatchThread()) { |
918 |
throw new RuntimeException("No Event Dispatch Thread"); |
919 |
} |
920 |
|
921 |
String name = getName(menu.getName(), loader);
|
922 |
|
923 |
// Se crea el control popupmenu
|
924 |
JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name); |
925 |
|
926 |
if (popupMenu == null) { |
927 |
popupMenu = new JPopUpMenu(menu.getName());
|
928 |
popupMap.put(name, popupMenu); |
929 |
} |
930 |
|
931 |
Menu[] menues = menu.getMenu(); |
932 |
for (int i = 0; i < menues.length; i++) { |
933 |
JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
|
934 |
popupMenu.add(nuevoMenu); |
935 |
} |
936 |
} |
937 |
|
938 |
/**
|
939 |
* DOCUMENT ME!
|
940 |
*
|
941 |
* @param loader
|
942 |
* @param menu
|
943 |
*
|
944 |
* @return
|
945 |
*
|
946 |
* @throws RuntimeException
|
947 |
* DOCUMENT ME!
|
948 |
*/
|
949 |
private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) { |
950 |
JMenuItem nuevoMenu = null; |
951 |
|
952 |
PluginServices ps = |
953 |
PluginServices.getPluginServices(loader.getPluginName()); |
954 |
|
955 |
String text = menu.getText();
|
956 |
int n = text.lastIndexOf('/'); |
957 |
if( n>=0 ) { |
958 |
text = text.substring(n + 1);
|
959 |
} |
960 |
String translatedText = ps.getText(text);
|
961 |
|
962 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
963 |
if (menu.getIcon() != null) { |
964 |
if( iconTheme.exists(menu.getIcon()) ) {
|
965 |
ImageIcon image = iconTheme.get(menu.getIcon());
|
966 |
nuevoMenu = new JMenuItem(translatedText, image); |
967 |
} else {
|
968 |
nuevoMenu = new JMenuItem(translatedText); |
969 |
logger.info("menu icon '"+ menu.getIcon()+ "' not exists."); |
970 |
} |
971 |
} else {
|
972 |
nuevoMenu = new JMenuItem(translatedText); |
973 |
} |
974 |
nuevoMenu.setName(menu.getName()); |
975 |
// if (menu.getMnemonic() != null) {
|
976 |
// if (menu.getMnemonic().length() != 1) {
|
977 |
// throw new RuntimeException(
|
978 |
// "Mnemonic must be 1 character length");
|
979 |
// }
|
980 |
// nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic()
|
981 |
// .charAt(0)));
|
982 |
// }
|
983 |
|
984 |
if (menu.getKey() != null) { |
985 |
nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey())); |
986 |
} |
987 |
|
988 |
nuevoMenu.setActionCommand(menu.getActionCommand()); |
989 |
|
990 |
if (menu.getTooltip() != null) { |
991 |
nuevoMenu.setToolTip(ps.getText(menu.getTooltip())); |
992 |
} |
993 |
|
994 |
if (menu.getEnableText() != null) { |
995 |
nuevoMenu.setEnableText(ps.getText(menu.getEnableText())); |
996 |
} |
997 |
|
998 |
nuevoMenu.setEnabled(true);
|
999 |
nuevoMenu.setVisible(true);
|
1000 |
|
1001 |
if( menu.getName() != null ) { |
1002 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
1003 |
final ActionInfo actionInfo = actionManager.getAction(menu.getName());
|
1004 |
if( actionInfo != null ) { |
1005 |
nuevoMenu.addActionListener(actionInfo); |
1006 |
} |
1007 |
} |
1008 |
return nuevoMenu;
|
1009 |
} |
1010 |
|
1011 |
private JMenuItem createJMenuItem(ActionInfo action, String text) { |
1012 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
1013 |
JMenuItem nuevoMenu = null; |
1014 |
String label = null; |
1015 |
|
1016 |
if( text == null ) { |
1017 |
label = action.getLabel(); |
1018 |
} else if( text.contains("/") ) { |
1019 |
String[] ss = text.split("/"); |
1020 |
label = ss[ss.length-1];
|
1021 |
} else {
|
1022 |
label = text; |
1023 |
} |
1024 |
String translatedText = i18nManager.getTranslation(label);
|
1025 |
if( action.getIconName()!=null ) { |
1026 |
ImageIcon image = action.getIcon();
|
1027 |
if ( image != null) { |
1028 |
nuevoMenu = new JMenuItem(translatedText, image); |
1029 |
} else {
|
1030 |
nuevoMenu = new JMenuItem(translatedText); |
1031 |
} |
1032 |
} else {
|
1033 |
nuevoMenu = new JMenuItem(translatedText); |
1034 |
} |
1035 |
nuevoMenu.setName(action.getName()); |
1036 |
KeyStroke key = action.getKeyStroke();
|
1037 |
if ( key!= null) { |
1038 |
nuevoMenu.setAccelerator(key); |
1039 |
} |
1040 |
nuevoMenu.setActionCommand(action.getCommand()); |
1041 |
if (action.getTooltip() != null) { |
1042 |
nuevoMenu.setToolTip(i18nManager.getTranslation(action.getTooltip())); |
1043 |
} |
1044 |
nuevoMenu.setEnabled(true);
|
1045 |
nuevoMenu.setVisible(true);
|
1046 |
nuevoMenu.addActionListener(action); |
1047 |
return nuevoMenu;
|
1048 |
} |
1049 |
|
1050 |
/**
|
1051 |
* Muestra u oculta el menu de nombre 'name'
|
1052 |
*
|
1053 |
* @param name
|
1054 |
* Nombre del menu que se quiere mostrar
|
1055 |
* @param x
|
1056 |
* Evento de raton
|
1057 |
* @param y
|
1058 |
* DOCUMENT ME!
|
1059 |
* @param c
|
1060 |
* DOCUMENT ME!
|
1061 |
*/
|
1062 |
private void showPopupMenu(String name, int x, int y, Component c) { |
1063 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
1064 |
|
1065 |
if (menu != null) { |
1066 |
menu.show(c, x, y); |
1067 |
} |
1068 |
} |
1069 |
|
1070 |
/**
|
1071 |
* DOCUMENT ME!
|
1072 |
*
|
1073 |
* @param name
|
1074 |
* DOCUMENT ME!
|
1075 |
* @param listener
|
1076 |
* DOCUMENT ME!
|
1077 |
*/
|
1078 |
public void removePopupMenuListener(String name, ActionListener listener) { |
1079 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
1080 |
|
1081 |
if (menu != null) { |
1082 |
Component[] jmenuitems = menu.getComponents(); |
1083 |
|
1084 |
for (int i = 0; i < jmenuitems.length; i++) { |
1085 |
if (jmenuitems[i] instanceof JMenuItem) { |
1086 |
((JMenuItem) jmenuitems[i]).removeActionListener(listener);
|
1087 |
} |
1088 |
} |
1089 |
} |
1090 |
} |
1091 |
|
1092 |
/**
|
1093 |
* DOCUMENT ME!
|
1094 |
*
|
1095 |
* @param popupName
|
1096 |
* @param c
|
1097 |
* DOCUMENT ME!
|
1098 |
* @param listener
|
1099 |
* @param loader
|
1100 |
*/
|
1101 |
public void addPopupMenuListener(String popupName, Component c, |
1102 |
ActionListener listener, PluginClassLoader loader) {
|
1103 |
final String name = getName(popupName, loader); |
1104 |
|
1105 |
JPopupMenu menu = (JPopupMenu) popupMap.get(name); |
1106 |
|
1107 |
if (menu != null) { |
1108 |
Component[] jmenuitems = menu.getComponents(); |
1109 |
|
1110 |
for (int i = 0; i < jmenuitems.length; i++) { |
1111 |
if (jmenuitems[i] instanceof JMenuItem) { |
1112 |
((JMenuItem) jmenuitems[i]).addActionListener(listener);
|
1113 |
} |
1114 |
} |
1115 |
} |
1116 |
|
1117 |
c.addMouseListener(new MouseAdapter() { |
1118 |
|
1119 |
@Override
|
1120 |
public void mousePressed(MouseEvent e) { |
1121 |
if (e.isPopupTrigger()) {
|
1122 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
1123 |
} |
1124 |
} |
1125 |
|
1126 |
@Override
|
1127 |
public void mouseReleased(MouseEvent e) { |
1128 |
if (e.isPopupTrigger()) {
|
1129 |
showPopupMenu(name, e.getX(), e.getY(), e.getComponent()); |
1130 |
} |
1131 |
} |
1132 |
}); |
1133 |
} |
1134 |
|
1135 |
/**
|
1136 |
* Loop on the controls to enable/disable and show/hide them, according to
|
1137 |
* its associated extension
|
1138 |
*
|
1139 |
* @throws RuntimeException
|
1140 |
* DOCUMENT ME!
|
1141 |
*/
|
1142 |
public void enableControls() { |
1143 |
if (!SwingUtilities.isEventDispatchThread()) { |
1144 |
SwingUtilities.invokeLater(new Runnable() { |
1145 |
public void run() { |
1146 |
enableControls(); |
1147 |
} |
1148 |
}); |
1149 |
return;
|
1150 |
} |
1151 |
|
1152 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
1153 |
ActionInfoStatusCache cache = actionManager.createActionStatusCache(); |
1154 |
|
1155 |
Iterator e = classesExtensions.values().iterator();
|
1156 |
|
1157 |
// HashMap estadoExtensiones = new HashMap();
|
1158 |
// HashMap visibilidadExtensiones = new HashMap();
|
1159 |
//
|
1160 |
// while (e.hasNext()) {
|
1161 |
// ExtensionDecorator ext = (ExtensionDecorator) e.next();
|
1162 |
//
|
1163 |
// try {
|
1164 |
// if (estadoExtensiones.get(ext) == null) {
|
1165 |
// boolean b;
|
1166 |
// if (ext.getVisibility() == ExtensionDecorator.ALWAYS_VISIBLE) {
|
1167 |
// b = true;
|
1168 |
// } else
|
1169 |
// if (ext.getVisibility() == ExtensionDecorator.ALWAYS_INVISIBLE) {
|
1170 |
// b = false;
|
1171 |
// } else {
|
1172 |
// if (PluginServices.getExclusiveUIExtension() == null) {
|
1173 |
// b = ext.isVisible();
|
1174 |
// } else {
|
1175 |
// b =
|
1176 |
// PluginServices.getExclusiveUIExtension()
|
1177 |
// .isVisible(ext.getExtension());
|
1178 |
// }
|
1179 |
// }
|
1180 |
// Boolean visible = new Boolean(b);
|
1181 |
// Boolean enabled = new Boolean(false);
|
1182 |
//
|
1183 |
// if (visible.booleanValue()) {
|
1184 |
// if (PluginServices.getExclusiveUIExtension() == null) {
|
1185 |
// enabled = new Boolean(ext.isEnabled());
|
1186 |
// } else {
|
1187 |
// enabled =
|
1188 |
// new Boolean(PluginServices
|
1189 |
// .getExclusiveUIExtension().isEnabled(
|
1190 |
// ext.getExtension()));
|
1191 |
// }
|
1192 |
//
|
1193 |
// }
|
1194 |
//
|
1195 |
// estadoExtensiones.put(ext, enabled);
|
1196 |
// visibilidadExtensiones.put(ext, visible);
|
1197 |
// }
|
1198 |
// } catch (Throwable e1) {
|
1199 |
// NotificationManager.addError(Messages
|
1200 |
// .getString("MDIFrame.Error_no_capturado_por_el_usuario"),
|
1201 |
// e1);
|
1202 |
// estadoExtensiones.put(ext, Boolean.FALSE);
|
1203 |
// }
|
1204 |
// }
|
1205 |
|
1206 |
// Enable or disable controls, according to its associated extensions
|
1207 |
e = controlClass.keySet().iterator(); |
1208 |
|
1209 |
while (e.hasNext()) {
|
1210 |
JComponent control = (JComponent) e.next(); |
1211 |
String actionlName = control.getName();
|
1212 |
ActionInfo action = actionManager.getAction(actionlName); |
1213 |
try {
|
1214 |
boolean enabled = false; |
1215 |
boolean visible = false; |
1216 |
|
1217 |
if(action == null) { |
1218 |
IExtension ext = |
1219 |
(IExtension) classesExtensions.get(controlClass.get(control)); |
1220 |
enabled = ext.isEnabled(); |
1221 |
visible = ext.isVisible(); |
1222 |
} else {
|
1223 |
enabled = false;
|
1224 |
visible = cache.isVisible(action); |
1225 |
if( visible ) {
|
1226 |
enabled = cache.isEnabled(action); |
1227 |
} |
1228 |
} |
1229 |
control.setEnabled(enabled); |
1230 |
control.setVisible(visible); |
1231 |
} catch (Exception ex) { |
1232 |
logger.info("Can't enable/show control '"+actionlName +"'.",ex); |
1233 |
this.message("Can't enable/show control '"+actionlName +"'.", JOptionPane.ERROR_MESSAGE); |
1234 |
control.setEnabled(false);
|
1235 |
control.setVisible(false);
|
1236 |
} |
1237 |
} |
1238 |
|
1239 |
// Loop in the menus to hide the menus that don't have visible children
|
1240 |
for (int i = 0; i < menuBar.getMenuCount(); i++) { |
1241 |
MenuElement menu = menuBar.getMenu(i);
|
1242 |
hideMenus(menu); |
1243 |
if (menu instanceof JMenu) { |
1244 |
// hide (ugly) redundant separators and assign keyboard
|
1245 |
// mnemonics
|
1246 |
Component[] comps = ((JMenu) menu).getMenuComponents(); |
1247 |
// mnemonics have to be unique for each top-level menu
|
1248 |
char mnemonics[] = new char[comps.length]; |
1249 |
if (comps.length > 0) { |
1250 |
// Set keyboard mnemonic for this top-level entry
|
1251 |
String text = ((JMenu) menu).getText(); |
1252 |
char mnemonic = getMnemonic(text, mnemonics);
|
1253 |
if (' ' != mnemonic) { |
1254 |
((JMenu) menu).setMnemonic(mnemonic);
|
1255 |
mnemonics[0] = mnemonic;
|
1256 |
} |
1257 |
} |
1258 |
// now go through all entries in this menu, hid
|
1259 |
// separators if necessary and assing remaining mnemonics
|
1260 |
hideSeparatorsAndMakeMnemonics(menu, mnemonics); |
1261 |
} |
1262 |
} |
1263 |
|
1264 |
// hide the toolbars that don't contain any visible tool
|
1265 |
Iterator it = toolBarMap.values().iterator();
|
1266 |
|
1267 |
while (it.hasNext()) {
|
1268 |
JComponent t = (JComponent) it.next(); |
1269 |
boolean todosOcultos = true; |
1270 |
|
1271 |
for (int i = 0; i < t.getComponentCount(); i++) { |
1272 |
if (!(t.getComponent(i) instanceof JSeparator) // separators |
1273 |
// don't matter
|
1274 |
&& t.getComponent(i).isVisible()) { |
1275 |
todosOcultos = false;
|
1276 |
} |
1277 |
} |
1278 |
|
1279 |
if (todosOcultos) {
|
1280 |
t.setVisible(false);
|
1281 |
} else {
|
1282 |
if(t instanceof SelectableToolBar) { |
1283 |
t.setVisible(((SelectableToolBar)t).getAndamiVisibility()); |
1284 |
} else
|
1285 |
t.setVisible(true);
|
1286 |
} |
1287 |
} |
1288 |
|
1289 |
if (mdiManager != null) { |
1290 |
JPanel f = (JPanel) mdiManager.getActiveWindow(); |
1291 |
|
1292 |
if (f != null) { |
1293 |
if (lastLabelClass != f.getClass()) {
|
1294 |
lastLabelClass = f.getClass(); |
1295 |
|
1296 |
Label[] lbls = (Label[]) classLabels.get(lastLabelClass); |
1297 |
|
1298 |
if (lbls != null) { |
1299 |
bEstado.setLabelSet(lbls); |
1300 |
} |
1301 |
} |
1302 |
} |
1303 |
} |
1304 |
|
1305 |
ajustarToolBar(); |
1306 |
|
1307 |
showMemory(); |
1308 |
} |
1309 |
|
1310 |
public void refreshControls() { |
1311 |
if (!SwingUtilities.isEventDispatchThread()) { |
1312 |
SwingUtilities.invokeLater(new Runnable() { |
1313 |
public void run() { |
1314 |
refreshControls(); |
1315 |
} |
1316 |
}); |
1317 |
return;
|
1318 |
} |
1319 |
|
1320 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
1321 |
ActionInfoStatusCache cache = actionManager.createActionStatusCache(); |
1322 |
IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1323 |
|
1324 |
Iterator e = controlClass.keySet().iterator();
|
1325 |
|
1326 |
while (e.hasNext()) {
|
1327 |
JComponent control = (JComponent) e.next(); |
1328 |
String actionlName = control.getName();
|
1329 |
ActionInfo action = actionManager.getAction(actionlName); |
1330 |
if( action!=null ) { |
1331 |
if( control instanceof AbstractButton ) { |
1332 |
|
1333 |
AbstractButton button = (AbstractButton) control; |
1334 |
|
1335 |
if (control instanceof javax.swing.JMenuItem) { |
1336 |
|
1337 |
if (action.getIconName() != null && action.getIconName().length() > 0) { |
1338 |
|
1339 |
if( icontheme.exists(action.getIconName()) ) {
|
1340 |
button.setIcon(action.getIcon()); |
1341 |
} |
1342 |
} |
1343 |
|
1344 |
} else {
|
1345 |
button.setIcon(action.getIcon()); |
1346 |
} |
1347 |
} |
1348 |
} |
1349 |
} |
1350 |
enableControls(); |
1351 |
} |
1352 |
|
1353 |
public void message(String msg, int messageTyoe) { |
1354 |
this.getStatusBar().message(msg, messageTyoe);
|
1355 |
} |
1356 |
|
1357 |
/**
|
1358 |
* Establece la visibilidad de un menu y todos sus descendientes en la
|
1359 |
* jerarquia teniendo en cuenta la visibilidad de todos los submenus.
|
1360 |
*
|
1361 |
* @param menu
|
1362 |
* Menu que se quiere visualizar
|
1363 |
*
|
1364 |
* @return Devuelve true si el menu es visible y false en caso contrario
|
1365 |
*/
|
1366 |
private boolean hideMenus(MenuElement menu) { |
1367 |
MenuElement[] submenus = menu.getSubElements(); |
1368 |
|
1369 |
// Si no tiene hijos se devuelve su visibilidad
|
1370 |
if (submenus.length == 0) { |
1371 |
return menu.getComponent().isVisible();
|
1372 |
} |
1373 |
|
1374 |
/*
|
1375 |
* Si tiene hijos se devuelve true si alg�no de ellos es visible,
|
1376 |
* pero se itera por todos ellos
|
1377 |
*/
|
1378 |
boolean visible = false; |
1379 |
|
1380 |
for (int i = 0; i < submenus.length; i++) { |
1381 |
if (hideMenus(submenus[i])) {
|
1382 |
if (!(menu instanceof JPopupMenu)) { |
1383 |
menu.getComponent().setVisible(true);
|
1384 |
} |
1385 |
|
1386 |
visible = true;
|
1387 |
} |
1388 |
} |
1389 |
|
1390 |
if (visible) {
|
1391 |
return true; |
1392 |
} |
1393 |
|
1394 |
menu.getComponent().setVisible(false);
|
1395 |
|
1396 |
return false; |
1397 |
} |
1398 |
|
1399 |
/**
|
1400 |
*
|
1401 |
* Recurse through all menu elements and make sure there are no
|
1402 |
* redundant separators.
|
1403 |
* This method will make sure that a separator only becomes visible
|
1404 |
* if at least one visible non-separator menu entry preceeded it.
|
1405 |
*
|
1406 |
**/
|
1407 |
private void hideSeparatorsAndMakeMnemonics(MenuElement menu, |
1408 |
char[] mnemonics) { |
1409 |
// flag that indicates whether a separator is to be displayed or not
|
1410 |
boolean allowSeparator;
|
1411 |
|
1412 |
allowSeparator = false; // separator not allowed as very first menu item |
1413 |
Component[] comps = ((JMenu) menu).getMenuComponents(); |
1414 |
if (comps.length < 1) { |
1415 |
// zero-length menu: skip
|
1416 |
return;
|
1417 |
} |
1418 |
|
1419 |
for (int i = 0; i < comps.length; i++) { |
1420 |
if (comps[i] instanceof JSeparator) { |
1421 |
// got a separator: display only if allowed at this position
|
1422 |
if (allowSeparator == true) { |
1423 |
// look at all successive menu entries to make sure that at
|
1424 |
// least one
|
1425 |
// is visible and not a separator (otherwise, this separator
|
1426 |
// would
|
1427 |
// be the last visible item in this menu) -- we don't want
|
1428 |
// that
|
1429 |
comps[i].setVisible(false);
|
1430 |
for (int j = i; j < comps.length; j++) { |
1431 |
if (!(comps[j] instanceof JSeparator)) { |
1432 |
if (comps[j].isVisible()) {
|
1433 |
comps[i].setVisible(true); // display separator! |
1434 |
break;
|
1435 |
} |
1436 |
} |
1437 |
} |
1438 |
} else {
|
1439 |
comps[i].setVisible(false);
|
1440 |
} |
1441 |
allowSeparator = false; // separator is not allowed right after |
1442 |
// another separator
|
1443 |
} else {
|
1444 |
if (comps[i] instanceof JMenu) { // got a submenu: recurse |
1445 |
// through it
|
1446 |
// get number of submenu components
|
1447 |
Component[] scomps = ((JMenu) comps[i]).getMenuComponents(); |
1448 |
// make a new, fresh array to hold unique mnemonics for this
|
1449 |
// submenu
|
1450 |
char[] smnemonics = new char[scomps.length]; |
1451 |
hideSeparatorsAndMakeMnemonics(((MenuElement) comps[i]),
|
1452 |
smnemonics); |
1453 |
if (comps[i].isVisible()) {
|
1454 |
allowSeparator = true; // separators are OK after |
1455 |
// visible submenus
|
1456 |
// Set keyboard mnemonic for this submenu
|
1457 |
String text = ((JMenu) comps[i]).getText(); |
1458 |
char mnemonic = getMnemonic(text, mnemonics);
|
1459 |
if (' ' != mnemonic) { |
1460 |
((JMenu) comps[i]).setMnemonic(mnemonic);
|
1461 |
mnemonics[i] = mnemonic; |
1462 |
} |
1463 |
} |
1464 |
} else {
|
1465 |
if (comps[i].isVisible()) {
|
1466 |
if (comps[i] instanceof JMenuItem) { |
1467 |
// Set keyboard mnemonic for this menu item
|
1468 |
String text = ((JMenuItem) comps[i]).getText(); |
1469 |
char mnemonic = getMnemonic(text, mnemonics);
|
1470 |
if (' ' != mnemonic) { |
1471 |
((JMenuItem) comps[i]).setMnemonic(mnemonic);
|
1472 |
mnemonics[i] = mnemonic; |
1473 |
} |
1474 |
} |
1475 |
allowSeparator = true; // separators are OK after |
1476 |
// regular, visible entries
|
1477 |
} |
1478 |
} |
1479 |
} |
1480 |
} |
1481 |
} |
1482 |
|
1483 |
/**
|
1484 |
* Helper functios for assigning a unique mnemomic char from
|
1485 |
* a pool of unassigned onces, stored in the array "mnemomnics"
|
1486 |
*/
|
1487 |
private char getMnemonic(String text, char[] mnemonics) { |
1488 |
Vector words = new Vector(); |
1489 |
StringTokenizer t = new StringTokenizer(text); |
1490 |
int maxsize = 0; |
1491 |
|
1492 |
while (t.hasMoreTokens()) {
|
1493 |
String word = t.nextToken();
|
1494 |
if (word.length() > maxsize) {
|
1495 |
maxsize = word.length(); |
1496 |
} |
1497 |
words.addElement(word); |
1498 |
} |
1499 |
words.trimToSize(); |
1500 |
|
1501 |
for (int i = 0; i < maxsize; ++i) { |
1502 |
char mnemonic = getMnemonic(words, mnemonics, i);
|
1503 |
if (' ' != mnemonic) { |
1504 |
return mnemonic;
|
1505 |
} |
1506 |
} |
1507 |
|
1508 |
return ' '; |
1509 |
} |
1510 |
|
1511 |
private char getMnemonic(Vector words, char[] mnemonics, int index) { |
1512 |
int numwords = words.size();
|
1513 |
|
1514 |
for (int i = 0; i < numwords; ++i) { |
1515 |
String word = (String) words.elementAt(i); |
1516 |
if (index >= word.length()) {
|
1517 |
continue;
|
1518 |
} |
1519 |
|
1520 |
char c = word.charAt(index);
|
1521 |
if (!isMnemonicExists(c, mnemonics)) {
|
1522 |
/* pick only valid chars */
|
1523 |
if ((c != ':') && (c != '.') && (c != ',') && (c != ';') |
1524 |
&& (c != '-') && (c != '+') && (c != '/') && (c != '\\') |
1525 |
&& (c != '\'') && (c != '\"') && (c != ' ') && (c != '=') |
1526 |
&& (c != '(') && (c != ')') && (c != '[') && (c != ']') |
1527 |
&& (c != '{') && (c != '}') && (c != '$') && (c != '*') |
1528 |
&& (c != '&') && (c != '%') && (c != '!') && (c != '?') |
1529 |
&& (c != '#') && (c != '~') && (c != '_')) { |
1530 |
return c;
|
1531 |
} |
1532 |
} |
1533 |
} |
1534 |
return ' '; |
1535 |
} |
1536 |
|
1537 |
private boolean isMnemonicExists(char c, char[] mnemonics) { |
1538 |
int num = mnemonics.length;
|
1539 |
for (int i = 0; i < num; ++i) { |
1540 |
if (mnemonics[i] == c) {
|
1541 |
return true; |
1542 |
} |
1543 |
} |
1544 |
return false; |
1545 |
} |
1546 |
|
1547 |
/**
|
1548 |
* Muestra la memoria consumida por el programa
|
1549 |
*/
|
1550 |
private void showMemory() { |
1551 |
Runtime r = Runtime.getRuntime(); |
1552 |
long mem = r.totalMemory() - r.freeMemory();
|
1553 |
logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem |
1554 |
/ 1024 + " KB"); |
1555 |
} |
1556 |
|
1557 |
/**
|
1558 |
* DOCUMENT ME!
|
1559 |
*
|
1560 |
* @return
|
1561 |
*/
|
1562 |
public MDIManager getMDIManager() {
|
1563 |
return mdiManager;
|
1564 |
} |
1565 |
|
1566 |
/**
|
1567 |
* Establece el mensaje en la barra de estado asociado a una etiqueta
|
1568 |
*
|
1569 |
* @return DOCUMENT ME!
|
1570 |
*/
|
1571 |
public NewStatusBar getStatusBar() {
|
1572 |
return bEstado;
|
1573 |
} |
1574 |
|
1575 |
/**
|
1576 |
* You can use this function to select the appropiate
|
1577 |
* tool inside the toolbars
|
1578 |
*/
|
1579 |
public void setSelectedTool(String actionCommand) { |
1580 |
setSelectedTool(defaultGroup, actionCommand); |
1581 |
} |
1582 |
|
1583 |
/**
|
1584 |
* You can use this function to select the appropiate
|
1585 |
* tool inside the toolbars
|
1586 |
*/
|
1587 |
public void setSelectedTool(String groupName, String actionCommand) { |
1588 |
ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName); |
1589 |
if (group == null) { |
1590 |
return;
|
1591 |
} |
1592 |
|
1593 |
Enumeration enumeration = group.getElements();
|
1594 |
while (enumeration.hasMoreElements()) {
|
1595 |
AbstractButton button = (AbstractButton) enumeration.nextElement(); |
1596 |
if (button.getActionCommand().equals(actionCommand)) {
|
1597 |
button.setSelected(true);
|
1598 |
} |
1599 |
} |
1600 |
|
1601 |
selectedTool.put(groupName, actionCommand); |
1602 |
} |
1603 |
|
1604 |
/**
|
1605 |
* You can use this function to select the appropiate
|
1606 |
* tool inside the toolbars
|
1607 |
*/
|
1608 |
public void setSelectedTools(Map selectedTools) { |
1609 |
selectedTool = selectedTools; |
1610 |
if (selectedTools == null) { |
1611 |
return;
|
1612 |
} |
1613 |
Iterator groupNames = selectedTools.keySet().iterator();
|
1614 |
while (groupNames.hasNext()) {
|
1615 |
try {
|
1616 |
String groupName = (String) groupNames.next(); |
1617 |
ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName); |
1618 |
Enumeration enumeration = group.getElements();
|
1619 |
String actionCommand = (String) selectedTools.get(groupName); |
1620 |
if (actionCommand == null) { |
1621 |
continue;
|
1622 |
} |
1623 |
while (enumeration.hasMoreElements()) {
|
1624 |
AbstractButton button =
|
1625 |
(AbstractButton) enumeration.nextElement();
|
1626 |
if (button.getActionCommand().equals(actionCommand)) {
|
1627 |
button.setSelected(true);
|
1628 |
} |
1629 |
} |
1630 |
} catch (ClassCastException ex) { |
1631 |
logger |
1632 |
.error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
|
1633 |
} |
1634 |
} |
1635 |
} |
1636 |
|
1637 |
/**
|
1638 |
* DOCUMENT ME!
|
1639 |
*
|
1640 |
* @param clase
|
1641 |
* @param label
|
1642 |
*/
|
1643 |
public void setStatusBarLabels(Class<?> clase, Label[] label) { |
1644 |
classLabels.put(clase, label); |
1645 |
} |
1646 |
|
1647 |
public void removeStatusBarLabels(Class<?> clase) { |
1648 |
classLabels.remove(clase); |
1649 |
} |
1650 |
|
1651 |
public void addStatusBarControl(Class<?> extensionClass, IControl control) { |
1652 |
control.addActionListener(this);
|
1653 |
bEstado.addControl(control.getName(), (Component) control);
|
1654 |
controlClass.put(control, extensionClass); |
1655 |
} |
1656 |
|
1657 |
public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) { |
1658 |
//toolBarMap.put(name, control);
|
1659 |
toolBars.add(control); |
1660 |
controlClass.put(control, extensionClass); |
1661 |
} |
1662 |
|
1663 |
public void removeStatusBarControl(String name) { |
1664 |
Component c = bEstado.removeControl(name);
|
1665 |
if (c != null) { |
1666 |
controlClass.remove(c); |
1667 |
} |
1668 |
} |
1669 |
|
1670 |
/**
|
1671 |
* @see org.gvsig.andami.ui.mdiFrame.MainFrame#removeMenu(org.gvsig.andami.plugins.config.generate.Menu)
|
1672 |
*/
|
1673 |
public void removeMenu(Menu menu) { |
1674 |
JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu); |
1675 |
|
1676 |
if (delete == null) { |
1677 |
throw new NoSuchElementException(menu.getText()); |
1678 |
} |
1679 |
|
1680 |
delete.getParent().remove(delete); |
1681 |
infoCodedMenus.remove(menu); |
1682 |
} |
1683 |
|
1684 |
/**
|
1685 |
* @see org.gvsig.andami.ui.mdiFrame.MainFrame#addMenu(org.gvsig.andami.plugins.config.generate.Menu,
|
1686 |
* java.awt.event.ActionListener, PluginClassLoader)
|
1687 |
*/
|
1688 |
public void addMenu(Menu menu, ActionListener listener, |
1689 |
PluginClassLoader loader) { |
1690 |
JMenu menuPadre = createMenuAncestors(menu, loader);
|
1691 |
|
1692 |
// Se registra y a�ade el menu
|
1693 |
JMenuItem nuevoMenu = createJMenuItem(loader, menu);
|
1694 |
nuevoMenu.addMouseListener(tooltipListener); |
1695 |
if( listener != null && menu.getName() != null && menu.getName().trim().length()>0 ) { |
1696 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
1697 |
final ActionInfo actionInfo = actionManager.getAction(menu.getName());
|
1698 |
if( actionInfo != null ) { |
1699 |
nuevoMenu.removeActionListener(actionInfo); |
1700 |
} |
1701 |
nuevoMenu.addActionListener(listener); |
1702 |
} else {
|
1703 |
/*
|
1704 |
* We also add action listener for menu with
|
1705 |
* no name but with text:
|
1706 |
*
|
1707 |
* Window/Project manager
|
1708 |
* Window/View - 1
|
1709 |
* Window/View - 2
|
1710 |
* etc
|
1711 |
*/
|
1712 |
if( listener != null && menu.getText() != null && menu.getText().trim().length()>0) { |
1713 |
nuevoMenu.addActionListener(listener); |
1714 |
} |
1715 |
|
1716 |
} |
1717 |
menuPadre.add(nuevoMenu); |
1718 |
|
1719 |
infoCodedMenus.put(menu, nuevoMenu); |
1720 |
} |
1721 |
|
1722 |
/**
|
1723 |
* @see org.gvsig.andami.ui.mdiFrame.MainFrame#changeMenuName(java.lang.String[],
|
1724 |
* String, org.gvsig.andami.plugins.PluginClassLoader)
|
1725 |
*/
|
1726 |
public void changeMenuName(String[] menu, String newName, |
1727 |
PluginClassLoader loader) { |
1728 |
|
1729 |
ArrayList menuList = new ArrayList(); |
1730 |
for (int i = 0; i < menu.length; i++) { |
1731 |
menuList.add(menu[i]); |
1732 |
} |
1733 |
|
1734 |
javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar); |
1735 |
if (newMenu == null) { |
1736 |
throw new NoSuchMenuException(menu[0]); |
1737 |
} else {
|
1738 |
newMenu.setText(PluginServices.getText(this, newName));
|
1739 |
} |
1740 |
} |
1741 |
|
1742 |
/**
|
1743 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
1744 |
*/
|
1745 |
public void componentHidden(ComponentEvent arg0) { |
1746 |
} |
1747 |
|
1748 |
/**
|
1749 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
1750 |
*/
|
1751 |
public void componentMoved(ComponentEvent arg0) { |
1752 |
} |
1753 |
|
1754 |
/**
|
1755 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
1756 |
*/
|
1757 |
public void componentResized(ComponentEvent arg0) { |
1758 |
ajustarToolBar(); |
1759 |
} |
1760 |
|
1761 |
/**
|
1762 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
1763 |
*/
|
1764 |
public void componentShown(ComponentEvent arg0) { |
1765 |
} |
1766 |
|
1767 |
/**
|
1768 |
* @see java.awt.event.ContainerListener#componentAdded(java.awt.event.ContainerEvent)
|
1769 |
*/
|
1770 |
public void componentAdded(ContainerEvent arg0) { |
1771 |
ajustarToolBar(); |
1772 |
} |
1773 |
|
1774 |
/**
|
1775 |
* @see java.awt.event.ContainerListener#componentRemoved(java.awt.event.ContainerEvent)
|
1776 |
*/
|
1777 |
public void componentRemoved(ContainerEvent arg0) { |
1778 |
ajustarToolBar(); |
1779 |
} |
1780 |
|
1781 |
/**
|
1782 |
* DOCUMENT ME!
|
1783 |
*
|
1784 |
* @author $author$
|
1785 |
* @version $Revision: 39484 $
|
1786 |
*/
|
1787 |
public class TooltipListener extends MouseAdapter { |
1788 |
|
1789 |
/**
|
1790 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
|
1791 |
*/
|
1792 |
@Override
|
1793 |
public void mouseEntered(MouseEvent e) { |
1794 |
JComponent control = (JComponent) e.getSource(); |
1795 |
EnableTextSupport ets = (EnableTextSupport) e.getSource(); |
1796 |
|
1797 |
String texto = null; |
1798 |
texto = control.getToolTipText(); |
1799 |
|
1800 |
if (texto != null) { |
1801 |
bEstado.setInfoTextTemporal(texto); |
1802 |
} |
1803 |
} |
1804 |
|
1805 |
/**
|
1806 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
|
1807 |
*/
|
1808 |
@Override
|
1809 |
public void mouseExited(MouseEvent arg0) { |
1810 |
bEstado.restaurarTexto(); |
1811 |
} |
1812 |
|
1813 |
/**
|
1814 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
1815 |
*/
|
1816 |
@Override
|
1817 |
public void mousePressed(MouseEvent e) { |
1818 |
bEstado.restaurarTexto(); |
1819 |
} |
1820 |
} |
1821 |
|
1822 |
public String getTitlePrefix() { |
1823 |
return titlePrefix;
|
1824 |
} |
1825 |
|
1826 |
public void setTitlePrefix(String titlePrefix) { |
1827 |
this.titlePrefix = titlePrefix;
|
1828 |
} |
1829 |
|
1830 |
public Map getSelectedTools() { |
1831 |
return selectedTool;
|
1832 |
} |
1833 |
|
1834 |
public HashMap getInitialSelectedTools() { |
1835 |
return initialSelectedTools;
|
1836 |
} |
1837 |
|
1838 |
/**
|
1839 |
* Get a previously added JComponent by name. For example
|
1840 |
* you can use it if you need to obtain a JToolBar to
|
1841 |
* add some customized component.
|
1842 |
*
|
1843 |
* @param name
|
1844 |
* @return the JComponent or null if none has been found
|
1845 |
*/
|
1846 |
public JComponent getComponentByName(String name) { |
1847 |
Iterator e = controlClass.keySet().iterator();
|
1848 |
|
1849 |
while (e.hasNext()) {
|
1850 |
JComponent control = (JComponent) e.next(); |
1851 |
String nameCtrl = control.getName();
|
1852 |
if (nameCtrl != null) { |
1853 |
if (nameCtrl.compareTo(name) == 0) { |
1854 |
return control;
|
1855 |
} |
1856 |
} |
1857 |
} |
1858 |
Iterator it = toolBarMap.values().iterator();
|
1859 |
while (it.hasNext()) {
|
1860 |
JComponent t = (JComponent) it.next(); |
1861 |
String nameCtrl = t.getName();
|
1862 |
if (nameCtrl != null) { |
1863 |
if (nameCtrl.compareTo(name) == 0) { |
1864 |
return t;
|
1865 |
} |
1866 |
} |
1867 |
|
1868 |
} |
1869 |
|
1870 |
return null; |
1871 |
} |
1872 |
|
1873 |
public SelectableToolBar[] getToolbars() { |
1874 |
return (SelectableToolBar[]) toolBarMap.values().toArray( |
1875 |
new SelectableToolBar[0]); |
1876 |
} |
1877 |
|
1878 |
public boolean getToolbarVisibility(String name) { |
1879 |
JComponent component =
|
1880 |
PluginServices.getMainFrame().getComponentByName(name); |
1881 |
if ((component != null) && (component instanceof SelectableToolBar)) { |
1882 |
SelectableToolBar toolBar = (SelectableToolBar) component; |
1883 |
return toolBar.getAndamiVisibility();
|
1884 |
} |
1885 |
return false; |
1886 |
} |
1887 |
|
1888 |
public boolean setToolbarVisibility(String name, boolean visibility) { |
1889 |
JComponent component =
|
1890 |
PluginServices.getMainFrame().getComponentByName(name); |
1891 |
if ((component != null) && (component instanceof SelectableToolBar)) { |
1892 |
SelectableToolBar toolBar = (SelectableToolBar) component; |
1893 |
boolean oldVisibility = toolBar.getAndamiVisibility();
|
1894 |
toolBar.setAndamiVisibility(visibility); |
1895 |
enableControls(); |
1896 |
return oldVisibility;
|
1897 |
} |
1898 |
return false; |
1899 |
} |
1900 |
|
1901 |
public javax.swing.JMenuItem getMenuEntry(String[] menuPath) { |
1902 |
ArrayList menu = new ArrayList(); |
1903 |
for (int i = 0; i < menuPath.length; i++) { |
1904 |
menu.add(menuPath[i]); |
1905 |
} |
1906 |
return getMenu(menu, menuBar);
|
1907 |
} |
1908 |
|
1909 |
public void messageDialog(String message, String title, int messageType) { |
1910 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1911 |
helper.messageDialog(message, title, messageType); |
1912 |
} |
1913 |
|
1914 |
public void messageDialog(String message, String[] messageArgs, |
1915 |
String title, int messageType) { |
1916 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1917 |
helper.messageDialog(message, messageArgs, title, messageType); |
1918 |
} |
1919 |
|
1920 |
public int confirmDialog(String message, String title, int optionType, |
1921 |
int messageType) {
|
1922 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1923 |
return helper.confirmDialog(message, title, optionType, messageType);
|
1924 |
} |
1925 |
|
1926 |
public String inputDialog(String message, String title, int messageType, |
1927 |
String initialValue) {
|
1928 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1929 |
return helper.inputDialog(message, title, messageType, initialValue);
|
1930 |
} |
1931 |
|
1932 |
public String inputDialog(String message, String title) { |
1933 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1934 |
return helper.inputDialog(message, title);
|
1935 |
} |
1936 |
|
1937 |
public void showDialog(Component contents, String title) { |
1938 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1939 |
helper.showDialog(contents, title); |
1940 |
} |
1941 |
|
1942 |
public Component createComponent(Class<? extends Component> theClass, |
1943 |
Object... parameters) {
|
1944 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1945 |
return helper.createComponentWithParams(theClass, parameters);
|
1946 |
} |
1947 |
|
1948 |
public Component createComponentWithParams( |
1949 |
Class<? extends Component> theClass, Object[] parameters) { |
1950 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1951 |
return helper.createComponentWithParams(theClass, parameters);
|
1952 |
} |
1953 |
|
1954 |
public File[] showChooserDialog( |
1955 |
final String title, |
1956 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
1957 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
1958 |
final boolean multiselection, |
1959 |
final File initialPath, |
1960 |
final FileFilter filter, |
1961 |
final boolean fileHidingEnabled |
1962 |
) { |
1963 |
DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado); |
1964 |
return helper.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
|
1965 |
} |
1966 |
|
1967 |
public File[] showOpenDirectoryDialog(String title, File initialPath) { |
1968 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
1969 |
} |
1970 |
|
1971 |
|
1972 |
public File[] showOpenFileDialog(String title, File initialPath) { |
1973 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
1974 |
} |
1975 |
|
1976 |
|
1977 |
public File[] showSaveFileDialog(String title, File initialPath) { |
1978 |
return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
1979 |
} |
1980 |
|
1981 |
|
1982 |
} |