Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / MDIFrame.java @ 42550

History | View | Annotate | Download (68.7 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.Locale;
48
import java.util.Map;
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.JComponent;
57
import javax.swing.JFileChooser;
58
import javax.swing.JFrame;
59
import javax.swing.JMenu;
60
import javax.swing.JMenuBar;
61
import javax.swing.JOptionPane;
62
import javax.swing.JPanel;
63
import javax.swing.JPopupMenu;
64
import javax.swing.JSeparator;
65
import javax.swing.JToolBar;
66
import javax.swing.KeyStroke;
67
import javax.swing.MenuElement;
68
import javax.swing.SwingUtilities;
69
import javax.swing.Timer;
70
import javax.swing.WindowConstants;
71
import javax.swing.filechooser.FileFilter;
72

    
73
import org.gvsig.andami.IconThemeHelper;
74
import org.gvsig.andami.Launcher;
75
import org.gvsig.andami.PluginServices;
76
import org.gvsig.andami.PluginsLocator;
77
import org.gvsig.andami.PluginsManager;
78
import org.gvsig.andami.actioninfo.ActionInfo;
79
import org.gvsig.andami.actioninfo.ActionInfoManager;
80
import org.gvsig.andami.actioninfo.ActionInfoStatusCache;
81
import org.gvsig.andami.messages.Messages;
82
import org.gvsig.andami.plugins.ExtensionDecorator;
83
import org.gvsig.andami.plugins.IExtension;
84
import org.gvsig.andami.plugins.PluginClassLoader;
85
import org.gvsig.andami.plugins.config.generate.ActionTool;
86
import org.gvsig.andami.plugins.config.generate.Label;
87
import org.gvsig.andami.plugins.config.generate.Menu;
88
import org.gvsig.andami.plugins.config.generate.PopupMenu;
89
import org.gvsig.andami.plugins.config.generate.SelectableTool;
90
import org.gvsig.andami.plugins.config.generate.SkinExtensionType;
91
import org.gvsig.andami.plugins.config.generate.ToolBar;
92
import org.gvsig.andami.ui.mdiFrame.TranslatableButtonHelper.TranslatableButton;
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
 * Use Launcher.getMDIFrame to get the instance of this class.
107
 *
108
 * @version $Revision: 39484 $
109
 */
110
@SuppressWarnings("unchecked")
111
public class MDIFrame extends JFrame implements ComponentListener,
112
        ContainerListener, ActionListener, MainFrame {
113

    
114
    private static final long serialVersionUID = -2472484309160847654L;
115

    
116
    private static Logger logger = LoggerFactory.getLogger(MDIFrame.class);
117

    
118
    private static MDIFrame instance = null;
119

    
120
    private MDIManager mdiManager = MDIManagerFactory.createManager();
121

    
122
    private boolean refreshingControls = false;
123

    
124
    /**
125
     * Elementos de la aplicaci�n
126
     */
127
    private JMenuBar menuBar = new JMenuBar();
128

    
129
    /**
130
     * Panel which contains the toolbars
131
     */
132
    private JPanel toolBars = new JPanel();
133

    
134
    /**
135
     * Status bar
136
     */
137
    private NewStatusBar bEstado = null;
138

    
139
    /**
140
     * Asocia los nombres con las barras de herramientas
141
     */
142
    private HashMap toolBarMap = new HashMap();
143

    
144
    /**
145
     * Almacena los grupos de selectableTools
146
     */
147
    private HashMap buttonGroupMap = new HashMap();
148
    /**
149
     * Stores the initially selected tools.
150
     * It contains pairs (String groupName, JToolBarToggleButton button)
151
     */
152
    private HashMap initialSelectedTools = new HashMap();
153

    
154
    /**
155
     * Stores the actionCommand of the selected tool, for each group.
156
     * It contains pairs (String groupName, JToolBarToggleButton button)
157
     */
158
    private Map selectedTool = null;
159
    // this should be the same value defined at plugin-config.xsd
160
    private String defaultGroup = "unico";
161

    
162
    /**
163
     * Asocia los nombres con los popupMenus
164
     */
165
    private HashMap popupMap = new HashMap();
166

    
167
    /**
168
     * Asocia controles con la clase de la extension asociada
169
     */
170
    private List<JComponent> controls = new ArrayList<JComponent>();
171

    
172
    /**
173
     * Asocia la informaci�n sobre las etiquetas que van en la status bar con
174
     * cada extension
175
     */
176
    private HashMap classLabels = new HashMap();
177

    
178
    // private HashMap classControls = new HashMap();
179
    /**
180
     * ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener)
181
     */
182
    private ArrayList progressListeners = new ArrayList();
183

    
184
    /**
185
     * Timer para invocar los enventos de la interfaz anterior
186
     */
187
    private Timer progressTimer = null;
188

    
189
    /**
190
     * Tabla hash que asocia las clases con las extensiones
191
     */
192
    // private Map classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
193
    /**
194
     * �ltima clase que activ� etiquetas
195
     */
196
    private Class lastLabelClass;
197

    
198
    /**
199
     * Instancia que pone los tooltip en la barra de estado
200
     */
201
    private TooltipListener tooltipListener = new TooltipListener();
202

    
203
    private HashMap infoCodedMenus = new HashMap();
204

    
205
    private String titlePrefix;
206

    
207
    private static final String noIcon = "no-icon";
208

    
209
    private Map<JComponent,IExtension> control2extensions = new HashMap<JComponent, IExtension>();
210

    
211
    private MDIFrame() {
212

    
213
    }
214

    
215
    public static boolean isInitialized() {
216
        return instance!=null ;
217
    }
218

    
219
    public static MDIFrame getInstance() {
220
        if ( instance == null ) {
221
            instance = new MDIFrame();
222
        }
223
        return instance;
224
    }
225

    
226
    /**
227
     * Makes some initialization tasks.
228
     *
229
     * @throws RuntimeException
230
     */
231
    public void init() {
232
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
233
        if ( !SwingUtilities.isEventDispatchThread() ) {
234
            throw new RuntimeException("Not Event Dispatch Thread");
235
        }
236

    
237
        // Se añaden los listeners del JFrame
238
        this.addWindowListener(new WindowAdapter() {
239

    
240
            @Override
241
            public void windowClosing(WindowEvent e) {
242
                Launcher.closeApplication();
243
            }
244
        });
245
        this.addComponentListener(this);
246
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
247

    
248
        // Se configura la barra de menu
249
        setJMenuBar(menuBar);
250

    
251
        // Se configura el layout del JFrame principal
252
        this.getContentPane().setLayout(new BorderLayout());
253

    
254
        /*
255
         * Se configura y se añade el JPanel de las barras de
256
         * herramientas
257
         */
258
        FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
259
        layout.setHgap(0);
260
        layout.setVgap(0);
261
        toolBars.setLayout(layout);
262
        getContentPane().add(toolBars, BorderLayout.PAGE_START);
263

    
264
        // Add the status bar of the application
265
        bEstado = new NewStatusBar();
266
        bEstado.message(Messages.getString("StatusBar.Aplicacion_iniciada"), JOptionPane.INFORMATION_MESSAGE);
267
        getContentPane().add(bEstado, BorderLayout.SOUTH);
268

    
269
        this.toolBars.addContainerListener(this);
270

    
271

    
272
        /*
273
         * Setting default values. Persistence is read
274
         * afterwards
275
         */
276
        setSize(
277
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[0],
278
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[1]);
279
        setLocation(
280
                MainFrame.MAIN_FRAME_POS_DEFAULT[0],
281
                MainFrame.MAIN_FRAME_POS_DEFAULT[1]);
282
        setExtendedState(
283
                MainFrame.MAIN_FRAME_EXT_STATE_DEFAULT);
284

    
285
        mdiManager.init(this);
286
    }
287

    
288
    @Override
289
    public void setTitle(final String title) {
290
        if ( !SwingUtilities.isEventDispatchThread() ) {
291
            SwingUtilities.invokeLater(new Runnable() {
292
                public void run() {
293
                    setTitle(title);
294
                }
295
            });
296
            return;
297
        }
298
        super.setTitle(titlePrefix + " : " + title);
299
    }
300

    
301
    private SelectableToolBar getToolBar(final String toolBarName) {
302
        SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName);
303
        if ( jtb == null ) {
304
            jtb = new SelectableToolBar(toolBarName);
305
            jtb.setRollover(true);
306
            jtb.setAndamiVisibility(true);
307
            toolBarMap.put(toolBarName, jtb);
308
            toolBars.add(jtb);
309
        }
310
        return jtb;
311
    }
312

    
313
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
314
            final ToolBar toolBar, final SelectableTool selectableTool)
315
            throws ClassNotFoundException {
316
        if ( !SwingUtilities.isEventDispatchThread() ) {
317
            try {
318
                SwingUtilities.invokeAndWait(new Runnable() {
319
                    public void run() {
320
                        try {
321
                            addTool(loader, ext, toolBar, selectableTool);
322
                        } catch (ClassNotFoundException ex) {
323
                            logger.warn("¿¿¿ Eehh????", ex);
324
                        }
325
                    }
326
                });
327
            } catch (Exception ex) {
328
                // Do nothing
329
            }
330
            return;
331
        }
332
        String name = toolBar.getName();
333
        SelectableToolBar jtb = getToolBar(name);
334
        if( selectableTool.getDropDownGroup()!=null ) {
335
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
336
            ActionInfo action = actionManager.getAction(selectableTool.getName());
337
            if( action!=null ) {
338
                DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(selectableTool.getDropDownGroup());
339
                if( dropDownButton==null ) {
340
                    dropDownButton = new DropDownButton();
341
                    dropDownButton.setName(selectableTool.getDropDownGroup());
342
                    jtb.add(dropDownButton);
343
                    addControl(dropDownButton);
344
                }
345
                dropDownButton.add(actionManager.getTranslated(action));
346
            }
347
            return;
348
        }
349

    
350
        I18nManager i18nManager = ToolsLocator.getI18nManager();
351

    
352
        ImageIcon image = PluginServices.getIconTheme().get(selectableTool.getIcon());
353
        if ( image != null ) {
354
            logger.warn("Unable to find icon '" + selectableTool.getIcon() + "'.");
355
            image = PluginServices.getIconTheme().get(noIcon);
356
        }
357

    
358
        ToggleButtonModel buttonModel = new ToggleButtonModel();
359
        JToolBarToggleButton btn = new JToolBarToggleButton(selectableTool.getText(), image);
360
        btn.setModel(buttonModel);
361
        btn.setMargin(new Insets(0, 0, 0, 0));
362
        btn.addMouseListener(tooltipListener);
363
        btn.addActionListener(this);
364
        btn.setFocusable(false);
365
        btn.setActionCommand(selectableTool.getActionCommand());
366
        btn.setToolTipText(selectableTool.getTooltip());
367
        btn.setEnabled(false);
368
        btn.setVisible(false);
369

    
370
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
371
        if ( group == null ) {
372
            group = new ButtonGroup();
373
            buttonGroupMap.put(selectableTool.getGroup(), group);
374
        }
375

    
376
        jtb.addButton(group, btn);
377

    
378
        buttonModel.setGroupName(selectableTool.getGroup());
379
        if ( selectableTool.getIsDefault() ) {
380
            btn.setSelected(true);
381
            initialSelectedTools.put(selectableTool.getGroup(),
382
                    btn.getActionCommand());
383
        }
384

    
385
        addControl(btn);
386

    
387
        if ( selectableTool.getName() != null ) {
388
            btn.setName(selectableTool.getName());
389
        }
390

    
391
        if ( selectableTool.getTooltip() != null ) {
392
            btn.setToolTip(i18nManager.getTranslation(selectableTool.getTooltip()));
393
            btn.setToolTipKey(selectableTool.getTooltip());
394
        }
395

    
396
        if ( selectableTool.getEnableText() != null ) {
397
            btn.setEnableText(i18nManager.getTranslation(selectableTool.getEnableText()));
398
        }
399

    
400
        if ( selectableTool.getLast() == true ) {
401
            jtb.addSeparator();
402
        }
403
    }
404

    
405
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
406
            final ToolBar toolBar, final ActionTool actionTool) throws ClassNotFoundException {
407
        if ( !SwingUtilities.isEventDispatchThread() ) {
408
            try {
409
                SwingUtilities.invokeAndWait(new Runnable() {
410
                    public void run() {
411
                        try {
412
                            addTool(loader, ext, toolBar, actionTool);
413
                        } catch (ClassNotFoundException ex) {
414
                            logger.warn("¿¿¿ Eehh????", ex);
415
                        }
416
                    }
417
                });
418
            } catch (Exception ex) {
419
                // Do nothing
420
            }
421
            return;
422
        }
423

    
424
        String name = toolBar.getName();
425
        SelectableToolBar jtb = getToolBar(name);
426
        if( actionTool.getDropDownGroup()!=null ) {
427
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
428
            ActionInfo action = actionManager.getAction(actionTool.getName());
429
            if( action!=null ) {
430
                DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(actionTool.getDropDownGroup());
431
                if( dropDownButton==null ) {
432
                    dropDownButton = new DropDownButton();
433
                    dropDownButton.setName(actionTool.getDropDownGroup());
434
                    jtb.add(dropDownButton);
435
                    addControl(dropDownButton);
436
                }
437
                dropDownButton.add(actionManager.getTranslated(action));
438
            }
439
            return;
440
        }
441

    
442
        I18nManager i18nManager = ToolsLocator.getI18nManager();
443

    
444
        ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
445
        if ( image != null ) {
446
            logger.warn("Unable to find icon '" + actionTool.getIcon() + "'.");
447
            image =  PluginServices.getIconTheme().get(noIcon);
448
        }
449

    
450
        JToolBarButton btn = new JToolBarButton(actionTool.getText(), image);
451
        btn.setMargin(new Insets(0, 0, 0, 0));
452
        btn.addMouseListener(tooltipListener);
453
        btn.addActionListener(this);
454
        btn.setFocusable(false);
455
        btn.setActionCommand(actionTool.getActionCommand());
456
        btn.setEnabled(false);
457
        btn.setVisible(false);
458

    
459
        jtb.add(btn);
460

    
461
        addControl(btn);
462

    
463
        if ( actionTool.getName() != null ) {
464
            btn.setName(actionTool.getName());
465
        }
466

    
467
        if ( actionTool.getTooltip() != null ) {
468
            btn.setToolTip(i18nManager.getTranslation(actionTool.getTooltip()));
469
            btn.setToolTipKey(actionTool.getTooltip());
470
        }
471

    
472
        if ( actionTool.getEnableText() != null ) {
473
            btn.setEnableText(i18nManager.getTranslation(actionTool.getEnableText()));
474
        }
475

    
476
        if ( actionTool.getLast() == true ) {
477
            jtb.addSeparator();
478
        }
479
    }
480

    
481
    public void addTool(final ActionInfo action, final String toolBarName, final String dropDownName) {
482
        if ( !SwingUtilities.isEventDispatchThread() ) {
483
            SwingUtilities.invokeLater(new Runnable() {
484
                public void run() {
485
                    addTool(action, toolBarName,dropDownName);
486
                }
487
            });
488
            return;
489
        }
490
        SelectableToolBar jtb = getToolBar(toolBarName);
491
        DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(dropDownName);
492
        if( dropDownButton == null ) {
493
            dropDownButton = new DropDownButton();
494
            jtb.add(dropDownButton);
495
        }
496
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
497
        dropDownButton.add(actionManager.getTranslated(action));
498
    }
499
    public void addTool(final ActionInfo action, final String toolBarName) {
500
        addTool(action, toolBarName, false);
501
    }
502

    
503
    public void addTool(final ActionInfo action, final String toolBarName, final boolean useText) {
504
        I18nManager i18nManager = ToolsLocator.getI18nManager();
505

    
506
        if ( !SwingUtilities.isEventDispatchThread() ) {
507
            SwingUtilities.invokeLater(new Runnable() {
508
                public void run() {
509
                    addTool(action, toolBarName, useText);
510
                }
511
            });
512
            return;
513
        }
514
        JToolBarButton btn = new JToolBarButton(action.getIcon());
515
        btn.setMargin(new Insets(0, 0, 0, 0));
516
        btn.addMouseListener(tooltipListener);
517
        btn.addActionListener(this);
518
        btn.setFocusable(false);
519
        btn.setActionCommand(action.getCommand());
520
        btn.setEnabled(false);
521
        btn.setVisible(false);
522
        btn.setName(action.getName());
523
        if( useText ) {
524
            btn.setText(action.getLabel());
525
        }
526
        if ( action.getTooltip() != null ) {
527
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
528
            btn.setToolTipKey(action.getTooltip());
529
        }
530

    
531
        SelectableToolBar jtb = getToolBar(toolBarName);
532
        jtb.add(btn);
533

    
534
        addControl(btn);
535

    
536
    }
537

    
538
    public void addSelectableTool(final ActionInfo action, final String toolBarName, final String groupName, final boolean useText) {
539
        I18nManager i18nManager = ToolsLocator.getI18nManager();
540

    
541
        if ( !SwingUtilities.isEventDispatchThread() ) {
542
            SwingUtilities.invokeLater(new Runnable() {
543
                public void run() {
544
                    addSelectableTool(action, toolBarName,groupName,useText);
545
                }
546
            });
547
            return;
548
        }
549

    
550
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
551
        if ( group == null ) {
552
            group = new ButtonGroup();
553
            buttonGroupMap.put(groupName, group);
554
        }
555
        ToggleButtonModel buttonModel = new ToggleButtonModel();
556
        buttonModel.setGroupName(groupName);
557

    
558
        JToolBarToggleButton btn = new JToolBarToggleButton(action.getIcon());
559
        btn.setModel(buttonModel);
560
        btn.setMargin(new Insets(0, 0, 0, 0));
561
        btn.addMouseListener(tooltipListener);
562
        btn.addActionListener(this);
563
        btn.setFocusable(false);
564
        btn.setActionCommand(action.getCommand());
565
        btn.setEnabled(false);
566
        btn.setVisible(false);
567
        btn.setName(action.getName());
568
        if( useText ) {
569
            btn.setText(action.getLabel());
570
        }
571
        if ( action.getTooltip() != null ) {
572
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
573
            btn.setToolTipKey(action.getTooltip());
574
        }
575

    
576
        SelectableToolBar jtb = getToolBar(toolBarName);
577
        jtb.addButton(group, btn);
578

    
579
        addControl(btn);
580

    
581
    }
582

    
583
    /**
584
     * Creates the needed menu structure to add the menu to the bar.
585
     * Returns the father which must hold the menu which was
586
     * provided as parameter.
587
     *
588
     * Crea la estructura de menus necesaria para añadir el menu a la barra.
589
     * Devuelve el padre del cual debe colgar el menu que se pasa como
590
     * parametro.
591
     *
592
     * @param menu
593
     * The Menu whose support is going to be added
594
     * @param loader
595
     * The plugin's class loader
596
     *
597
     * @return The proper father for the menu which was provided as parameter
598
     */
599
    private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) {
600
        return createMenuAncestors(menu.getText());
601
    }
602

    
603
    private JMenu createMenuAncestors(String text) {
604
        I18nManager i18nManager = ToolsLocator.getI18nManager();
605

    
606
        MenuElement menuPadre = null;
607

    
608
        String[] menues = text.split("/");
609
        List menuList = new ArrayList();
610
        menuList.add(menues[0]);
611
        menuPadre = getMenu(menuList, menuBar);
612

    
613
        JMenu padre = null;
614

    
615
        if ( menuPadre == null ) {
616
            padre = new JMenuTraslatable(i18nManager.getTranslation(menues[0]));
617
            ((JMenuTraslatable) padre).setTextKey(menues[0]);
618
            padre.setName(menues[0]);
619
            addControl(padre);
620
            menuBar.add(padre);
621
        } else if ( menuPadre instanceof JMenu ) {
622
            padre = (JMenu) menuPadre;
623
        } else {
624
            logger.warn("Error creating menu. Ancestor does not exist (" + text + ").");
625
            return null;
626
        }
627

    
628
        // Se crea el resto de menus
629
        ArrayList temp = new ArrayList();
630

    
631
        for ( int i = 1; i < (menues.length - 1); i++ ) {
632
            temp.add(menues[i]);
633
        }
634

    
635
        menuPadre = createMenus(temp, padre);
636

    
637
        return (JMenu) menuPadre;
638
    }
639

    
640
    /**
641
     * Añade la informacion del menu al framework.
642
     * Debido a que los men�es se
643
     * pueden introducir en un orden determinado por el usuario, pero los
644
     * plugins se instalan en un orden arbitrario, primero se almacena la
645
     * informacion de todos los menus para luego ordenarlos y posteriormente
646
     * añadirlos al interfaz
647
     *
648
     * @param loader
649
     * Posicion del menu. Se ordena por este campo
650
     * @param ext
651
     * Array con los nombres de los padres del menu
652
     * @param menu
653
     * Texto del menu
654
     *
655
     * @throws ClassNotFoundException
656
     * @throws RuntimeException
657
     */
658
    public void addMenu(final PluginClassLoader loader, final SkinExtensionType ext,
659
            final Menu menu) throws ClassNotFoundException {
660
        if ( !SwingUtilities.isEventDispatchThread() ) {
661
            try {
662
                SwingUtilities.invokeAndWait(new Runnable() {
663
                    public void run() {
664
                        try {
665
                            addMenu(loader, ext, menu);
666
                        } catch (ClassNotFoundException ex) {
667
                            logger.warn("¿¿¿ Eehh????", ex);
668
                        }
669
                    }
670
                });
671
            } catch (Exception ex) {
672
                // Do nothing
673
            }
674
            return;
675
        }
676
        JMenu menuPadre = createMenuAncestors(menu, loader);
677

    
678
        if ( menu.getIs_separator() ) {
679
            menuPadre.addSeparator();
680
            return;
681
        }
682

    
683
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
684
        nuevoMenu.addMouseListener(tooltipListener);
685
        menuPadre.add(nuevoMenu);
686
        addControl(nuevoMenu);
687

    
688
    }
689

    
690
    public void addMenu(final ActionInfo action, final String text) {
691
        if ( !SwingUtilities.isEventDispatchThread() ) {
692
            SwingUtilities.invokeLater(new Runnable() {
693
                public void run() {
694
                    addMenu(action, text);
695
                }
696
            });
697
            return;
698
        }
699
        JMenu menuPadre = createMenuAncestors(text);
700
        JMenuItem nuevoMenu = createJMenuItem(action, text);
701
        nuevoMenu.addMouseListener(tooltipListener);
702
        menuPadre.add(nuevoMenu);
703
        menuPadre.invalidate();
704
        Class<? extends IExtension> classExtension = action.getExtension().getClass();
705
        addControl(nuevoMenu);
706
    }
707

    
708
    /**
709
     * Dado lista de nombres de menu, encuentra el menu
710
     *
711
     * @param nombres
712
     * @param padre
713
     * @return
714
     */
715
    private javax.swing.JMenuItem getMenu(List nombres, MenuElement parent) {
716
        if ( parent instanceof javax.swing.JMenu ) {
717
            javax.swing.JMenu parentItem = (javax.swing.JMenu) parent;
718

    
719
            for ( int i = 0; i < parentItem.getMenuComponentCount(); i++ ) {
720

    
721
                String item_name = parentItem.getMenuComponent(i).getName();
722
                if ( ((item_name != null) && (item_name.compareTo((String) nombres.get(0)) == 0))
723
                        || /*
724
                         * We also accept "leaf menus" with no name
725
                         * (Project manager, View-1, View-2, etc)
726
                         */ lastMenuItemWithoutName(parentItem.getMenuComponent(i), nombres) ) {
727

    
728
                    nombres.remove(0);
729
                    if ( nombres.isEmpty() ) {
730
                        if ( parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem ) {
731
                            return (javax.swing.JMenuItem) parentItem
732
                                    .getMenuComponent(i);
733
                        } else {
734
                            logger.error(PluginServices.getText(this,
735
                                    "Menu_type_not_supported_")
736
                                    + " "
737
                                    + parentItem.getMenuComponent(i).getClass()
738
                                    .getName());
739
                            return null;
740
                        }
741
                    } else {
742
                        return getMenu(nombres,
743
                                (MenuElement) parentItem.getMenuComponent(i));
744
                    }
745
                }
746
            }
747
        } else if ( parent instanceof JMenuBar ) {
748
            javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent;
749

    
750
            for ( int i = 0; i < parentItem.getMenuCount(); i++ ) {
751
                if ( (parentItem.getMenu(i).getName() != null // not a
752
                        // JToolBar.Separator
753
                        )
754
                        && (parentItem.getMenu(i).getName()
755
                        .compareTo((String) nombres.get(0)) == 0) ) {
756
                    nombres.remove(0);
757
                    if ( nombres.isEmpty() ) {
758
                        if ( parentItem.getMenu(i) instanceof javax.swing.JMenuItem ) {
759
                            return parentItem.getMenu(i);
760
                        } else {
761
                            logger.error(PluginServices.getText(this,
762
                                    "Menu_type_not_supported_")
763
                                    + " "
764
                                    + parentItem.getMenu(i).getClass()
765
                                    .getName());
766
                            return null;
767
                        }
768
                    } else {
769
                        return getMenu(nombres, parentItem.getMenu(i));
770
                    }
771
                }
772
            }
773
        } else {
774
            logger.error(PluginServices.getText(this,
775
                    "Menu_type_not_supported_")
776
                    + " "
777
                    + parent.getClass().getName() + " " + parent.toString());
778
        }
779
        return null;
780
    }
781

    
782
    /**
783
     * @param menuComponent
784
     * @param nombres
785
     * @return
786
     */
787
    private boolean lastMenuItemWithoutName(Component mc, List names) {
788

    
789
        /*
790
         * names must have 1 string
791
         */
792
        if ( names == null || names.size() != 1 ) {
793
            return false;
794
        }
795
        if ( !(mc instanceof JMenuItem) ) {
796
            return false;
797
        }
798
        JMenuItem jmi = (JMenuItem) mc;
799
        if ( jmi.getName() != null ) {
800
            /*
801
             * Name must be null, so this is a menu leaf
802
             */
803
            return false;
804
        }
805
        if ( jmi.getText() == null ) {
806
            return false;
807
        }
808
        return jmi.getText().compareTo((String) names.get(0)) == 0;
809
    }
810

    
811
    private class JMenuTraslatable extends JMenu implements TranslatableButton {
812

    
813
        private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
814

    
815
        public JMenuTraslatable(String text) {
816
            super(text);
817
        }
818

    
819
        public void setTextKey(String key) {
820
            this.i18nHelper.setText(key);
821
        }
822

    
823
        public void setToolTipKey(String key) {
824
            this.i18nHelper.setTooltip(key);
825
        }
826

    
827
        public void translate() {
828
            if ( this.i18nHelper.needTranslation() ) {
829
                this.i18nHelper.translate();
830
                this.setText(this.i18nHelper.getText());
831
            }
832
        }
833

    
834
    }
835

    
836
    /**
837
     * Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
838
     * en el par�metro nombres el array {"Search", "References", "Workspace"}
839
     * crear� un men� Search, un submen� del anterior que se llamar�
840
     * References y debajo de �ste �ltimo otro menu llamado Workspace
841
     *
842
     * @param nombres
843
     * Array con los nombres de los men�s que se quieren crear
844
     * @param padre
845
     * Menu padre de los men�s creados. Es �til porque es un
846
     * algoritmo recursivo
847
     *
848
     * @return Devuelve el men� creado. Al final de toda la recursividad,
849
     * devolver� el men� de m�s abajo en la jerarqu�a
850
     *
851
     * @throws RuntimeException
852
     */
853
    private JMenu createMenus(ArrayList nombres, JMenu padre) {
854
        if ( !SwingUtilities.isEventDispatchThread() ) {
855
            logger.warn("Este metodo requiere que se este ejecutando en el hilo de eventos de AWT.");
856
            throw new RuntimeException("No Event Dispatch Thread");
857
        }
858
        I18nManager i18nManager = ToolsLocator.getI18nManager();
859

    
860
        // si no quedan nombres de menu por crear se vuelve: caso base
861
        if ( nombres.isEmpty() ) {
862
            return padre;
863
        }
864

    
865
        // Se busca el menu por si ya existiera para no crearlo otra vez
866
        JMenu buscado = null;
867

    
868
        for ( int i = 0; i < padre.getMenuComponentCount(); i++ ) {
869
            try {
870
                JMenu hijo = (JMenu) padre.getMenuComponent(i);
871

    
872
                if ( hijo.getName().compareTo((String) nombres.get(0)) == 0 ) {
873
                    buscado = hijo;
874
                }
875
            } catch (ClassCastException e) {
876
                /*
877
                 * Se ha encontrado un elemento hoja del arbol de men�es
878
                 */
879
            }
880
        }
881

    
882
        if ( buscado != null ) {
883
            // Si lo hemos encontrado creamos el resto
884
            nombres.remove(0);
885

    
886
            return createMenus(nombres, buscado);
887
        } else {
888
            // Si no lo hemos encontrado se crea el menu, se a�ade al padre
889
            // y se crea el resto
890
            String nombre = (String) nombres.get(0);
891
            JMenuTraslatable menuPadre = new JMenuTraslatable(i18nManager.getTranslation(nombre));
892
            menuPadre.setTextKey(nombre);
893
            menuPadre.setName(nombre);
894
            addControl(menuPadre);
895
            padre.add(menuPadre);
896

    
897
            nombres.remove(0);
898

    
899
            return createMenus(nombres, menuPadre);
900
        }
901
    }
902

    
903
    /**
904
     * M�todo invocado en respuesta a ciertos eventos de la interfaz que
905
     * pueden
906
     * ocultar botones de las barras de herramientas y que redimensiona �sta
907
     * de manera conveniente para que no se oculte ninguno
908
     */
909
    private void ajustarToolBar() {
910
        int margen = 8;
911
        int numFilas = 1;
912
        double acum = margen;
913

    
914
        int toolHeight = 0;
915

    
916
        for ( int i = 0; i < toolBars.getComponentCount(); i++ ) {
917
            Component c = toolBars.getComponent(i);
918

    
919
            if ( !c.isVisible() ) {
920
                continue;
921
            }
922

    
923
            double width = c.getPreferredSize().getWidth();
924
            acum = acum + width;
925

    
926
            if ( acum > this.getWidth() ) {
927
                numFilas++;
928
                acum = width + margen;
929
            }
930

    
931
            if ( c.getPreferredSize().getHeight() > toolHeight ) {
932
                toolHeight = c.getPreferredSize().height;
933
            }
934
        }
935

    
936
        toolBars.setPreferredSize(new Dimension(this.getWidth(),
937
                (numFilas * toolHeight)));
938

    
939
        toolBars.updateUI();
940
    }
941

    
942
    public void setClassesExtensions(Map<Class<? extends IExtension>, ExtensionDecorator> classesExtensions) {
943
        // Ya no es necesario que se mantenga el Map con las extensiones.
944

    
945
//            Map<Class<? extends IExtension>, ExtensionDecorator> extensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
946
//            for ( Entry<Class<? extends IExtension>, ExtensionDecorator>  entry: classesExtensions.entrySet()) {
947
//                        if( ! (entry.getValue().getExtension() instanceof LibraryExtension) ) {
948
//                                extensions.put(entry.getKey(), entry.getValue());
949
//                        }
950
//                }
951
//        this.classesExtensions = extensions;
952
    }
953

    
954
    /**
955
     * Metodo de callback invocado cuando se selecciona un menu o un boton
956
     * de
957
     * la barra de herramientas. Se busca la extensi�n asociada y se ejecuta
958
     *
959
     * @param e
960
     * Evento producido
961
     */
962
    public void actionPerformed(ActionEvent e) {
963

    
964
        String actionName = "(unknow)";
965
        try {
966
            JComponent control = (JComponent) e.getSource();
967
            actionName = control.getName();
968

    
969
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
970
            ActionInfo action = actionManager.getAction(control.getName());
971
            Object args = null;
972
            if ( control instanceof IControl ) {
973
                args = ((IControl) control).getValue();
974
            }
975
            if ( args == null ) {
976
                action.execute();
977
            } else {
978
                action.execute(args);
979
            }
980
            String actionCommand = e.getActionCommand();
981
            try {
982
                JToolBarToggleButton toggle = (JToolBarToggleButton) control;
983
                ToggleButtonModel model = (ToggleButtonModel) toggle.getModel();
984
                selectedTool.put(model.getGroupName(), actionCommand);
985
            } catch (ClassCastException ex) {
986
            } catch (NullPointerException ex) {
987
            }
988

    
989
        } catch (Throwable ex) {
990
            logger.error("Can't perform action '" + actionName + "'.", ex);
991
        }
992

    
993
        enableControls();
994
        showMemory();
995
    }
996

    
997
    private String getName(String name, PluginClassLoader loader) {
998
        if ( name.indexOf('.') == -1 ) {
999
            return loader.getPluginName() + "." + name;
1000
        } else {
1001
            return name;
1002
        }
1003
    }
1004

    
1005
    public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) {
1006
        if ( !SwingUtilities.isEventDispatchThread() ) {
1007
            throw new RuntimeException("No Event Dispatch Thread");
1008
        }
1009

    
1010
        String name = getName(menu.getName(), loader);
1011

    
1012
        // Se crea el control popupmenu
1013
        JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name);
1014

    
1015
        if ( popupMenu == null ) {
1016
            popupMenu = new JPopUpMenu(menu.getName());
1017
            popupMap.put(name, popupMenu);
1018
        }
1019

    
1020
        Menu[] menues = menu.getMenu();
1021
        for ( int i = 0; i < menues.length; i++ ) {
1022
            JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
1023
            popupMenu.add(nuevoMenu);
1024
        }
1025
    }
1026

    
1027
    private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) {
1028
        JMenuItem nuevoMenu = null;
1029

    
1030
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1031

    
1032
        String text = menu.getText();
1033
        int n = text.lastIndexOf('/');
1034
        if ( n >= 0 ) {
1035
            text = text.substring(n + 1);
1036
        }
1037
        String translatedText = i18nManager.getTranslation(text);
1038

    
1039
        IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1040
        if ( menu.getIcon() != null ) {
1041
            if ( iconTheme.exists(menu.getIcon()) ) {
1042
                ImageIcon image = iconTheme.get(menu.getIcon());
1043
                nuevoMenu = new JMenuItem(translatedText, image);
1044
            } else {
1045
                nuevoMenu = new JMenuItem(translatedText);
1046
                logger.info("menu icon '" + menu.getIcon() + "' not exists.");
1047
            }
1048
        } else {
1049
            nuevoMenu = new JMenuItem(translatedText);
1050
        }
1051
        nuevoMenu.setTextKey(text);
1052
        nuevoMenu.setName(menu.getName());
1053

    
1054
        if ( menu.getKey() != null ) {
1055
            nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey()));
1056
        }
1057

    
1058
        nuevoMenu.setActionCommand(menu.getActionCommand());
1059

    
1060
        if ( menu.getTooltip() != null ) {
1061
            nuevoMenu.setToolTip(i18nManager.getTranslation(menu.getTooltip()));
1062
            nuevoMenu.setToolTipKey(menu.getTooltip());
1063
        }
1064

    
1065
        if ( menu.getEnableText() != null ) {
1066
            nuevoMenu.setEnableText(i18nManager.getTranslation(menu.getEnableText()));
1067
        }
1068

    
1069
        nuevoMenu.setEnabled(true);
1070
        nuevoMenu.setVisible(true);
1071

    
1072
        if ( menu.getName() != null ) {
1073
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1074
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1075
            if ( actionInfo != null ) {
1076
                nuevoMenu.addActionListener(actionInfo);
1077
            }
1078
        }
1079
        return nuevoMenu;
1080
    }
1081

    
1082
    private JMenuItem createJMenuItem(ActionInfo action, String text) {
1083
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1084
        String label = null;
1085

    
1086
        if ( text == null ) {
1087
            label = action.getLabel();
1088
        } else if ( text.contains("/") ) {
1089
            String[] ss = text.split("/");
1090
            label = ss[ss.length - 1];
1091
        } else {
1092
            label = text;
1093
        }
1094
        JMenuItem nuevoMenu = new JMenuItem();
1095
        nuevoMenu.setText(i18nManager.getTranslation(label));
1096
        nuevoMenu.setName(action.getName());
1097
        if ( action.getIconName() != null ) {
1098
            nuevoMenu.setIcon(action.getIcon());
1099
        }
1100
        KeyStroke key = action.getKeyStroke();
1101
        if ( key != null ) {
1102
            nuevoMenu.setAccelerator(key);
1103
        }
1104
        nuevoMenu.setActionCommand(action.getCommand());
1105
        if ( action.getTooltip() != null ) {
1106
            nuevoMenu.setToolTip(i18nManager.getTranslation(action.getTooltip()));
1107
        }
1108
        nuevoMenu.setEnabled(true);
1109
        nuevoMenu.setVisible(true);
1110
        nuevoMenu.addActionListener(action);
1111
        return nuevoMenu;
1112
    }
1113

    
1114
    /**
1115
     * Muestra u oculta el menu de nombre 'name'
1116
     *
1117
     * @param name
1118
     * Nombre del menu que se quiere mostrar
1119
     * @param x
1120
     * Evento de raton
1121
     * @param y
1122
     * @param c
1123
     */
1124
    private void showPopupMenu(String name, int x, int y, Component c) {
1125
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1126

    
1127
        if ( menu != null ) {
1128
            menu.show(c, x, y);
1129
        }
1130
    }
1131

    
1132
    public void removePopupMenuListener(String name, ActionListener listener) {
1133
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1134

    
1135
        if ( menu != null ) {
1136
            Component[] jmenuitems = menu.getComponents();
1137

    
1138
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1139
                if ( jmenuitems[i] instanceof JMenuItem ) {
1140
                    ((JMenuItem) jmenuitems[i]).removeActionListener(listener);
1141
                }
1142
            }
1143
        }
1144
    }
1145

    
1146
    public void addPopupMenuListener(String popupName, Component c,
1147
            ActionListener listener, PluginClassLoader loader) {
1148
        final String name = getName(popupName, loader);
1149

    
1150
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1151

    
1152
        if ( menu != null ) {
1153
            Component[] jmenuitems = menu.getComponents();
1154

    
1155
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1156
                if ( jmenuitems[i] instanceof JMenuItem ) {
1157
                    ((JMenuItem) jmenuitems[i]).addActionListener(listener);
1158
                }
1159
            }
1160
        }
1161

    
1162
        c.addMouseListener(new MouseAdapter() {
1163

    
1164
            @Override
1165
            public void mousePressed(MouseEvent e) {
1166
                if ( e.isPopupTrigger() ) {
1167
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1168
                }
1169
            }
1170

    
1171
            @Override
1172
            public void mouseReleased(MouseEvent e) {
1173
                if ( e.isPopupTrigger() ) {
1174
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1175
                }
1176
            }
1177
        });
1178
    }
1179

    
1180
    /**
1181
     * Loop on the controls to enable/disable and show/hide them, according to
1182
     * its associated action (ActionInfo)
1183
     *
1184
     * @throws RuntimeException
1185
     */
1186
    public void enableControls() {
1187
        if ( !SwingUtilities.isEventDispatchThread() ) {
1188
            SwingUtilities.invokeLater(new Runnable() {
1189
                public void run() {
1190
                    enableControls();
1191
                }
1192
            });
1193
            return;
1194
        }
1195

    
1196
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1197
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1198

    
1199
        // Enable or disable controls, according to its associated extensions
1200
        Iterator<JComponent> e = controlsIterator();
1201

    
1202
        while ( e.hasNext() ) {
1203
            JComponent control = (JComponent) e.next();
1204
            String actionName = control.getName();
1205
            ActionInfo action = actionManager.getAction(actionName);
1206
            try {
1207
                boolean enabled = false;
1208
                boolean visible = false;
1209

    
1210
                if ( action == null ) {
1211
                    if( control instanceof DropDownButton ) {
1212
                        DropDownButton dropDownButton = (DropDownButton)control;
1213
                        visible = !dropDownButton.isAllHiden();
1214
                        enabled = !dropDownButton.isAllDisabled();
1215
                        if (visible && enabled){
1216
                            dropDownButton.updateMainButton();
1217
                        }
1218
                    } else if( control instanceof JMenuTraslatable ) {
1219
                        enabled = true;
1220
                        visible = true;
1221
                    } else {
1222
                        IExtension extension = this.control2extensions.get(control);
1223
                        if( extension!=null ) {
1224
                            enabled = extension.isEnabled();
1225
                            visible = extension.isVisible();
1226
                        } else {
1227
                            logger.warn("Can't enable/show control '"+control.getClass().getName()+"/"+control.getName()+".");
1228
                            enabled = true;
1229
                            visible = true;
1230
                        }
1231
                    }
1232
                } else {
1233
                    enabled = false;
1234
                    visible = cache.isVisible(action);
1235
                    if ( visible ) {
1236
                        enabled = cache.isEnabled(action);
1237
                    }
1238
                }
1239
                control.setEnabled(enabled);
1240
                control.setVisible(visible);
1241
            } catch (Throwable ex) {
1242
                // Catch exceptions and errors (class not found)
1243
                logger.info("Can't enable/show control '" + actionName + "'.", ex);
1244
                this.message("Can't enable/show control '" + actionName + "'.", JOptionPane.ERROR_MESSAGE);
1245
                try {
1246
                    control.setEnabled(false);
1247
                    control.setVisible(false);
1248
                } catch (Exception ex2) {
1249
                    // Ignore errors
1250
                }
1251
            }
1252
        }
1253

    
1254
        // Loop in the menus to hide the menus that don't have visible children
1255
        for ( int i = 0; i < menuBar.getMenuCount(); i++ ) {
1256
            MenuElement menu = menuBar.getMenu(i);
1257
            hideMenus(menu);
1258
            if ( menu instanceof JMenu ) {
1259
                // hide (ugly) redundant separators and assign keyboard
1260
                // mnemonics
1261
                Component[] comps = ((JMenu) menu).getMenuComponents();
1262
                // mnemonics have to be unique for each top-level menu
1263
                char mnemonics[] = new char[comps.length];
1264
                if ( comps.length > 0 ) {
1265
                    // Set keyboard mnemonic for this top-level entry
1266
                    String text = ((JMenu) menu).getText();
1267
                    char mnemonic = getMnemonic(text, mnemonics);
1268
                    if ( ' ' != mnemonic ) {
1269
                        ((JMenu) menu).setMnemonic(mnemonic);
1270
                        mnemonics[0] = mnemonic;
1271
                    }
1272
                }
1273
                // now go through all entries in this menu, hid
1274
                // separators if necessary and assing remaining mnemonics
1275
                hideSeparatorsAndMakeMnemonics(menu, mnemonics);
1276
            }
1277
        }
1278

    
1279
        // hide the toolbars that don't contain any visible tool
1280
        Iterator it = toolBarMap.values().iterator();
1281

    
1282
        while ( it.hasNext() ) {
1283
            JComponent t = (JComponent) it.next();
1284
            boolean todosOcultos = true;
1285

    
1286
            for ( int i = 0; i < t.getComponentCount(); i++ ) {
1287
                if ( !(t.getComponent(i) instanceof JSeparator) // separators
1288
                        // don't matter
1289
                        && t.getComponent(i).isVisible() ) {
1290
                    todosOcultos = false;
1291
                }
1292
            }
1293

    
1294
            if ( todosOcultos ) {
1295
                t.setVisible(false);
1296
            } else {
1297
                if ( t instanceof SelectableToolBar ) {
1298
                    t.setVisible(((SelectableToolBar) t).getAndamiVisibility());
1299
                } else {
1300
                    t.setVisible(true);
1301
                }
1302
            }
1303
        }
1304

    
1305
        if ( mdiManager != null ) {
1306
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1307

    
1308
            if ( f != null ) {
1309
                if ( lastLabelClass != f.getClass() ) {
1310
                    lastLabelClass = f.getClass();
1311

    
1312
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1313

    
1314
                    if ( lbls != null ) {
1315
                        bEstado.setLabelSet(lbls);
1316
                    }
1317
                }
1318
            }
1319
        }
1320

    
1321
        ajustarToolBar();
1322

    
1323
        showMemory();
1324
    }
1325

    
1326
    public synchronized void refreshControls() {
1327
        if ( !SwingUtilities.isEventDispatchThread() ) {
1328
            SwingUtilities.invokeLater(new Runnable() {
1329
                public void run() {
1330
                    refreshControls();
1331
                }
1332
            });
1333
            return;
1334
        }
1335

    
1336
        if(refreshingControls){
1337
            return;
1338
        }
1339
        try {
1340
        refreshingControls = true;
1341
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1342
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1343
        IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1344

    
1345
        Iterator e = controlsIterator();
1346

    
1347
        while ( e.hasNext() ) {
1348
            JComponent control = (JComponent) e.next();
1349
            if ( control instanceof TranslatableButton ) {
1350
                ((TranslatableButton) control).translate();
1351
            }
1352
            String actionlName = control.getName();
1353
            ActionInfo action = actionManager.getAction(actionlName);
1354
            if ( action != null ) {
1355
                if ( control instanceof AbstractButton ) {
1356
                    AbstractButton button = (AbstractButton) control;
1357
                    if ( control instanceof javax.swing.JMenuItem ) {
1358
                        if ( action.getIconName() != null && action.getIconName().length() > 0 ) {
1359
                            if ( icontheme.exists(action.getIconName()) ) {
1360
                                button.setIcon(action.getIcon());
1361
                            }
1362
                        }
1363
                    } else {
1364
                        button.setIcon(action.getIcon());
1365
                    }
1366
                }
1367
            }
1368
        }
1369

    
1370
        enableControls();
1371
        } finally {
1372
            refreshingControls = false;
1373
        }
1374
    }
1375

    
1376
    public void message(String msg, int messageTyoe) {
1377
        this.getStatusBar().message(msg, messageTyoe);
1378
    }
1379

    
1380
    /**
1381
     * Establece la visibilidad de un menu y todos sus descendientes en la
1382
     * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
1383
     *
1384
     * @param menu
1385
     * Menu que se quiere visualizar
1386
     *
1387
     * @return Devuelve true si el menu es visible y false en caso contrario
1388
     */
1389
    private boolean hideMenus(MenuElement menu) {
1390
        MenuElement[] submenus = menu.getSubElements();
1391

    
1392
        // Si no tiene hijos se devuelve su visibilidad
1393
        if ( submenus.length == 0 ) {
1394
            return menu.getComponent().isVisible();
1395
        }
1396

    
1397
        /*
1398
         * Si tiene hijos se devuelve true si alg�no de ellos es visible,
1399
         * pero se itera por todos ellos
1400
         */
1401
        boolean visible = false;
1402

    
1403
        for ( int i = 0; i < submenus.length; i++ ) {
1404
            if ( hideMenus(submenus[i]) ) {
1405
                if ( !(menu instanceof JPopupMenu) ) {
1406
                    menu.getComponent().setVisible(true);
1407
                }
1408

    
1409
                visible = true;
1410
            }
1411
        }
1412

    
1413
        if ( visible ) {
1414
            return true;
1415
        }
1416

    
1417
        menu.getComponent().setVisible(false);
1418

    
1419
        return false;
1420
    }
1421

    
1422
    /**
1423
     *
1424
     * Recurse through all menu elements and make sure there are no
1425
     * redundant separators.
1426
     * This method will make sure that a separator only becomes visible
1427
     * if at least one visible non-separator menu entry preceeded it.
1428
     *
1429
     *
1430
     */
1431
    private void hideSeparatorsAndMakeMnemonics(MenuElement menu,
1432
            char[] mnemonics) {
1433
        // flag that indicates whether a separator is to be displayed or not
1434
        boolean allowSeparator;
1435

    
1436
        allowSeparator = false; // separator not allowed as very first menu item
1437
        Component[] comps = ((JMenu) menu).getMenuComponents();
1438
        if ( comps.length < 1 ) {
1439
            // zero-length menu: skip
1440
            return;
1441
        }
1442

    
1443
        for ( int i = 0; i < comps.length; i++ ) {
1444
            if ( comps[i] instanceof JSeparator ) {
1445
                // got a separator: display only if allowed at this position
1446
                if ( allowSeparator == true ) {
1447
                    // look at all successive menu entries to make sure that at
1448
                    // least one
1449
                    // is visible and not a separator (otherwise, this separator
1450
                    // would
1451
                    // be the last visible item in this menu) -- we don't want
1452
                    // that
1453
                    comps[i].setVisible(false);
1454
                    for ( int j = i; j < comps.length; j++ ) {
1455
                        if ( !(comps[j] instanceof JSeparator) ) {
1456
                            if ( comps[j].isVisible() ) {
1457
                                comps[i].setVisible(true); // display separator!
1458
                                break;
1459
                            }
1460
                        }
1461
                    }
1462
                } else {
1463
                    comps[i].setVisible(false);
1464
                }
1465
                allowSeparator = false; // separator is not allowed right after
1466
                // another separator
1467
            } else {
1468
                if ( comps[i] instanceof JMenu ) { // got a submenu: recurse
1469
                    // through it
1470
                    // get number of submenu components
1471
                    Component[] scomps = ((JMenu) comps[i]).getMenuComponents();
1472
                    // make a new, fresh array to hold unique mnemonics for this
1473
                    // submenu
1474
                    char[] smnemonics = new char[scomps.length];
1475
                    hideSeparatorsAndMakeMnemonics(((MenuElement) comps[i]),
1476
                            smnemonics);
1477
                    if ( comps[i].isVisible() ) {
1478
                        allowSeparator = true; // separators are OK after
1479
                        // visible submenus
1480
                        // Set keyboard mnemonic for this submenu
1481
                        String text = ((JMenu) comps[i]).getText();
1482
                        char mnemonic = getMnemonic(text, mnemonics);
1483
                        if ( ' ' != mnemonic ) {
1484
                            ((JMenu) comps[i]).setMnemonic(mnemonic);
1485
                            mnemonics[i] = mnemonic;
1486
                        }
1487
                    }
1488
                } else {
1489
                    if ( comps[i].isVisible() ) {
1490
                        if ( comps[i] instanceof JMenuItem ) {
1491
                            // Set keyboard mnemonic for this menu item
1492
                            String text = ((JMenuItem) comps[i]).getText();
1493
                            char mnemonic = getMnemonic(text, mnemonics);
1494
                            if ( ' ' != mnemonic ) {
1495
                                ((JMenuItem) comps[i]).setMnemonic(mnemonic);
1496
                                mnemonics[i] = mnemonic;
1497
                            }
1498
                        }
1499
                        allowSeparator = true; // separators are OK after
1500
                        // regular, visible entries
1501
                    }
1502
                }
1503
            }
1504
        }
1505
    }
1506

    
1507
    /**
1508
     * Helper functios for assigning a unique mnemomic char from
1509
     * a pool of unassigned onces, stored in the array "mnemomnics"
1510
     */
1511
    private char getMnemonic(String text, char[] mnemonics) {
1512
        if( text==null ) {
1513
            return ' ';
1514
        }
1515
        Vector words = new Vector();
1516
        StringTokenizer t = new StringTokenizer(text);
1517
        int maxsize = 0;
1518

    
1519
        while ( t.hasMoreTokens() ) {
1520
            String word = t.nextToken();
1521
            if ( word.length() > maxsize ) {
1522
                maxsize = word.length();
1523
            }
1524
            words.addElement(word);
1525
        }
1526
        words.trimToSize();
1527

    
1528
        for ( int i = 0; i < maxsize; ++i ) {
1529
            char mnemonic = getMnemonic(words, mnemonics, i);
1530
            if ( ' ' != mnemonic ) {
1531
                return mnemonic;
1532
            }
1533
        }
1534

    
1535
        return ' ';
1536
    }
1537

    
1538
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1539
        int numwords = words.size();
1540

    
1541
        for ( int i = 0; i < numwords; ++i ) {
1542
            String word = (String) words.elementAt(i);
1543
            if ( index >= word.length() ) {
1544
                continue;
1545
            }
1546

    
1547
            char c = word.charAt(index);
1548
            if ( !isMnemonicExists(c, mnemonics) ) {
1549
                /* pick only valid chars */
1550
                if ( (c != ':') && (c != '.') && (c != ',') && (c != ';')
1551
                        && (c != '-') && (c != '+') && (c != '/') && (c != '\\')
1552
                        && (c != '\'') && (c != '\"') && (c != ' ') && (c != '=')
1553
                        && (c != '(') && (c != ')') && (c != '[') && (c != ']')
1554
                        && (c != '{') && (c != '}') && (c != '$') && (c != '*')
1555
                        && (c != '&') && (c != '%') && (c != '!') && (c != '?')
1556
                        && (c != '#') && (c != '~') && (c != '_') ) {
1557
                    return c;
1558
                }
1559
            }
1560
        }
1561
        return ' ';
1562
    }
1563

    
1564
    private boolean isMnemonicExists(char c, char[] mnemonics) {
1565
        int num = mnemonics.length;
1566
        for ( int i = 0; i < num; ++i ) {
1567
            if ( mnemonics[i] == c ) {
1568
                return true;
1569
            }
1570
        }
1571
        return false;
1572
    }
1573

    
1574
    /**
1575
     * Muestra la memoria consumida por el programa
1576
     */
1577
    private void showMemory() {
1578
        Runtime r = Runtime.getRuntime();
1579
        long mem = r.totalMemory() - r.freeMemory();
1580
        logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem
1581
                / 1024 + " KB");
1582
    }
1583

    
1584
    public MDIManager getMDIManager() {
1585
        return mdiManager;
1586
    }
1587

    
1588
    public NewStatusBar getStatusBar() {
1589
        return bEstado;
1590
    }
1591

    
1592
    /**
1593
     * You can use this function to select the appropiate
1594
     * tool inside the toolbars
1595
     */
1596
    public void setSelectedTool(String actionCommand) {
1597
        setSelectedTool(defaultGroup, actionCommand);
1598
    }
1599

    
1600
    /**
1601
     * You can use this function to select the appropiate
1602
     * tool inside the toolbars
1603
     */
1604
    public void setSelectedTool(String groupName, String actionCommand) {
1605
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1606
        if ( group == null ) {
1607
            return;
1608
        }
1609

    
1610
        Enumeration enumeration = group.getElements();
1611
        while ( enumeration.hasMoreElements() ) {
1612
            AbstractButton button = (AbstractButton) enumeration.nextElement();
1613
            if ( button.getActionCommand().equals(actionCommand) ) {
1614
                button.setSelected(true);
1615
            }
1616
        }
1617

    
1618
        selectedTool.put(groupName, actionCommand);
1619
    }
1620

    
1621
    /**
1622
     * You can use this function to select the appropiate
1623
     * tool inside the toolbars
1624
     */
1625
    public void setSelectedTools(Map selectedTools) {
1626
        selectedTool = selectedTools;
1627
        if ( selectedTools == null ) {
1628
            return;
1629
        }
1630
        Iterator groupNames = selectedTools.keySet().iterator();
1631
        while ( groupNames.hasNext() ) {
1632
            try {
1633
                String groupName = (String) groupNames.next();
1634
                ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1635
                Enumeration enumeration = group.getElements();
1636
                String actionCommand = (String) selectedTools.get(groupName);
1637
                if ( actionCommand == null ) {
1638
                    continue;
1639
                }
1640
                while ( enumeration.hasMoreElements() ) {
1641
                    AbstractButton button
1642
                            = (AbstractButton) enumeration.nextElement();
1643
                    if ( button.getActionCommand().equals(actionCommand) ) {
1644
                        button.setSelected(true);
1645
                    }
1646
                }
1647
            } catch (ClassCastException ex) {
1648
                logger
1649
                        .error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1650
            }
1651
        }
1652
    }
1653

    
1654
    /**
1655
     * DOCUMENT ME!
1656
     *
1657
     * @param clase
1658
     * @param label
1659
     */
1660
    public void setStatusBarLabels(Class<?> clase, Label[] label) {
1661
        classLabels.put(clase, label);
1662
    }
1663

    
1664
    public void removeStatusBarLabels(Class<?> clase) {
1665
        classLabels.remove(clase);
1666
    }
1667

    
1668
    public void addStatusBarControl(Class<?> extensionClass, IControl control) {
1669
        control.addActionListener(this);
1670
        bEstado.addControl(control.getName(), (Component) control);
1671
        if ( control instanceof JComponent ) {
1672
            addControl((JComponent) control);
1673
            PluginsManager pluginsManager = PluginsLocator.getManager();
1674
            IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1675
            this.control2extensions.put((JComponent)control, extension);
1676
        }
1677
    }
1678

    
1679
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1680
        toolBars.add(control);
1681
        addControl(control);
1682

    
1683
        PluginsManager pluginsManager = PluginsLocator.getManager();
1684
        IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1685
        this.control2extensions.put(control, extension);
1686
    }
1687

    
1688
    public void removeStatusBarControl(String name) {
1689
        Component c = bEstado.removeControl(name);
1690
        if ( c instanceof JComponent ) {
1691
            removeControl((JComponent) c);
1692
        }
1693
    }
1694

    
1695
    public void removeMenu(Menu menu) {
1696
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1697

    
1698
        if ( delete == null ) {
1699
            throw new NoSuchElementException(menu.getText());
1700
        }
1701

    
1702
        delete.getParent().remove(delete);
1703
        infoCodedMenus.remove(menu);
1704
    }
1705

    
1706
    public void addMenu(Menu menu, ActionListener listener,
1707
            PluginClassLoader loader) {
1708
        JMenu menuPadre = createMenuAncestors(menu, loader);
1709

    
1710
        // Se registra y añaade el menu
1711
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
1712
        nuevoMenu.addMouseListener(tooltipListener);
1713
        if ( listener != null && menu.getName() != null && menu.getName().trim().length() > 0 ) {
1714
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1715
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1716
            if ( actionInfo != null ) {
1717
                nuevoMenu.removeActionListener(actionInfo);
1718
            }
1719
            nuevoMenu.addActionListener(listener);
1720
        } else {
1721
            /*
1722
             * We also add action listener for menu with
1723
             * no name but with text:
1724
             *
1725
             * Window/Project manager
1726
             * Window/View - 1
1727
             * Window/View - 2
1728
             * etc
1729
             */
1730
            if ( listener != null && menu.getText() != null && menu.getText().trim().length() > 0 ) {
1731
                nuevoMenu.addActionListener(listener);
1732
            }
1733

    
1734
        }
1735
        menuPadre.add(nuevoMenu);
1736

    
1737
        infoCodedMenus.put(menu, nuevoMenu);
1738
    }
1739

    
1740
    public void changeMenuName(String[] menu, String newName,
1741
            PluginClassLoader loader) {
1742

    
1743
        ArrayList menuList = new ArrayList();
1744
        for ( int i = 0; i < menu.length; i++ ) {
1745
            menuList.add(menu[i]);
1746
        }
1747

    
1748
        javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1749
        if ( newMenu == null ) {
1750
            throw new NoSuchMenuException(menu[0]);
1751
        } else {
1752
            newMenu.setText(PluginServices.getText(this, newName));
1753
        }
1754
    }
1755

    
1756
    public void componentHidden(ComponentEvent arg0) {
1757
    }
1758

    
1759
    public void componentMoved(ComponentEvent arg0) {
1760
    }
1761

    
1762
    public void componentResized(ComponentEvent arg0) {
1763
        ajustarToolBar();
1764
    }
1765

    
1766
    public void componentShown(ComponentEvent arg0) {
1767
    }
1768

    
1769
    public void componentAdded(ContainerEvent arg0) {
1770
        ajustarToolBar();
1771
    }
1772

    
1773
    public void componentRemoved(ContainerEvent arg0) {
1774
        ajustarToolBar();
1775
    }
1776

    
1777
    public class TooltipListener extends MouseAdapter {
1778

    
1779
        @Override
1780
        public void mouseEntered(MouseEvent e) {
1781
            JComponent control = (JComponent) e.getSource();
1782
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1783

    
1784
            String texto = null;
1785
            texto = control.getToolTipText();
1786

    
1787
            if ( texto != null ) {
1788
                bEstado.setInfoTextTemporal(texto);
1789
            }
1790
        }
1791

    
1792
        @Override
1793
        public void mouseExited(MouseEvent arg0) {
1794
            bEstado.restaurarTexto();
1795
        }
1796

    
1797
        @Override
1798
        public void mousePressed(MouseEvent e) {
1799
            bEstado.restaurarTexto();
1800
        }
1801
    }
1802

    
1803
    public String getTitlePrefix() {
1804
        return titlePrefix;
1805
    }
1806

    
1807
    public void setTitlePrefix(String titlePrefix) {
1808
        this.titlePrefix = titlePrefix;
1809
    }
1810

    
1811
    public Map getSelectedTools() {
1812
        return selectedTool;
1813
    }
1814

    
1815
    public HashMap getInitialSelectedTools() {
1816
        return initialSelectedTools;
1817
    }
1818

    
1819
    /**
1820
     * Get a previously added JComponent by name.
1821
     * For example you can use it if you need to obtain a JToolBar to
1822
     * add some customized component.
1823
     *
1824
     * @param name
1825
     * @return the JComponent or null if none has been found
1826
     */
1827
    public JComponent getComponentByName(String name) {
1828
        Iterator e = controlsIterator();
1829

    
1830
        while ( e.hasNext() ) {
1831
            JComponent control = (JComponent) e.next();
1832
            String nameCtrl = control.getName();
1833
            if ( nameCtrl != null ) {
1834
                if ( nameCtrl.compareTo(name) == 0 ) {
1835
                    return control;
1836
                }
1837
            }
1838
        }
1839
        Iterator it = toolBarMap.values().iterator();
1840
        while ( it.hasNext() ) {
1841
            JComponent t = (JComponent) it.next();
1842
            String nameCtrl = t.getName();
1843
            if ( nameCtrl != null ) {
1844
                if ( nameCtrl.compareTo(name) == 0 ) {
1845
                    return t;
1846
                }
1847
            }
1848

    
1849
        }
1850

    
1851
        return null;
1852
    }
1853

    
1854
    public SelectableToolBar[] getToolbars() {
1855
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1856
                new SelectableToolBar[0]);
1857
    }
1858

    
1859
    public boolean getToolbarVisibility(String name) {
1860
        JComponent component
1861
                = PluginServices.getMainFrame().getComponentByName(name);
1862
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1863
            SelectableToolBar toolBar = (SelectableToolBar) component;
1864
            return toolBar.getAndamiVisibility();
1865
        }
1866
        return false;
1867
    }
1868

    
1869
    public boolean setToolbarVisibility(String name, boolean visibility) {
1870
        JComponent component
1871
                = PluginServices.getMainFrame().getComponentByName(name);
1872
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1873
            SelectableToolBar toolBar = (SelectableToolBar) component;
1874
            boolean oldVisibility = toolBar.getAndamiVisibility();
1875
            toolBar.setAndamiVisibility(visibility);
1876
            enableControls();
1877
            return oldVisibility;
1878
        }
1879
        return false;
1880
    }
1881

    
1882
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1883
        ArrayList menu = new ArrayList();
1884
        for ( int i = 0; i < menuPath.length; i++ ) {
1885
            menu.add(menuPath[i]);
1886
        }
1887
        return getMenu(menu, menuBar);
1888
    }
1889

    
1890
    public void messageDialog(String message, String title, int messageType) {
1891
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1892
        helper.messageDialog(message, title, messageType);
1893
    }
1894

    
1895
    public void messageDialog(String message, String[] messageArgs,
1896
            String title, int messageType) {
1897
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1898
        helper.messageDialog(message, messageArgs, title, messageType);
1899
    }
1900

    
1901
    public int confirmDialog(String message, String title, int optionType,
1902
            int messageType) {
1903
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1904
        return helper.confirmDialog(message, title, optionType, messageType);
1905
    }
1906

    
1907
    public String inputDialog(String message, String title, int messageType,
1908
            String initialValue) {
1909
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1910
        return helper.inputDialog(message, title, messageType, initialValue);
1911
    }
1912

    
1913
    public String inputDialog(String message, String title) {
1914
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1915
        return helper.inputDialog(message, title);
1916
    }
1917

    
1918
    public void showDialog(Component contents, String title) {
1919
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1920
        helper.showDialog(contents, title);
1921
    }
1922

    
1923
    public Component createComponent(Class<? extends Component> theClass,
1924
            Object... parameters) {
1925
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1926
        return helper.createComponentWithParams(theClass, parameters);
1927
    }
1928

    
1929
    public Component createComponentWithParams(
1930
            Class<? extends Component> theClass, Object[] parameters) {
1931
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1932
        return helper.createComponentWithParams(theClass, parameters);
1933
    }
1934

    
1935
    public File[] showChooserDialog(
1936
            final String title,
1937
            final int type, // SAVE_DIALOG / OPEN_DIALOG
1938
            final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
1939
            final boolean multiselection,
1940
            final File initialPath,
1941
            final FileFilter filter,
1942
            final boolean fileHidingEnabled
1943
    ) {
1944
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1945
        return helper.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
1946
    }
1947

    
1948
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1949
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1950
    }
1951

    
1952
    public File[] showOpenFileDialog(String title, File initialPath) {
1953
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1954
    }
1955

    
1956
    public File[] showSaveFileDialog(String title, File initialPath) {
1957
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1958
    }
1959

    
1960
    private void addControl(JComponent control) {
1961
        controls.add(control);
1962
    }
1963

    
1964
    private void removeControl(JComponent control) {
1965
        controls.remove(control);
1966
    }
1967

    
1968
    private Iterator<JComponent> controlsIterator() {
1969
        return this.controls.iterator();
1970
    }
1971

    
1972
    @Override
1973
    public void setLocale(Locale locale) {
1974
        super.setLocale(locale); //To change body of generated methods, choose Tools | Templates.
1975
        MDIManager mdiManager = MDIManagerFactory.createManager();
1976
        mdiManager.setLocale(locale);
1977
        if ( this.controls != null && !this.controls.isEmpty() ) {
1978
            this.refreshControls();
1979
        }
1980
    }
1981

    
1982
}