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 @ 42349

History | View | Annotate | Download (68.8 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.sql.rowset.spi.SyncResolver;
54
import javax.swing.AbstractButton;
55
import javax.swing.ButtonGroup;
56
import javax.swing.ImageIcon;
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.PluginServices;
77
import org.gvsig.andami.PluginsLocator;
78
import org.gvsig.andami.PluginsManager;
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.mdiFrame.TranslatableButtonHelper.TranslatableButton;
94
import org.gvsig.andami.ui.mdiManager.MDIManager;
95
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
96
import org.gvsig.gui.beans.controls.IControl;
97
import org.gvsig.tools.ToolsLocator;
98
import org.gvsig.tools.i18n.I18nManager;
99
import org.gvsig.tools.swing.api.ToolsSwingLocator;
100
import org.gvsig.tools.swing.icontheme.IconTheme;
101

    
102
import org.slf4j.Logger;
103
import org.slf4j.LoggerFactory;
104

    
105
/**
106
 * Main application window.
107
 *
108
 * Use Launcher.getMDIFrame to get the instance of this class.
109
 *
110
 * @version $Revision: 39484 $
111
 */
112
@SuppressWarnings("unchecked")
113
public class MDIFrame extends JFrame implements ComponentListener,
114
        ContainerListener, ActionListener, MainFrame {
115

    
116
    private static final long serialVersionUID = -2472484309160847654L;
117

    
118
    private static Logger logger = LoggerFactory.getLogger(MDIFrame.class);
119

    
120
    private static MDIFrame instance = null;
121

    
122
    private MDIManager mdiManager = MDIManagerFactory.createManager();
123

    
124
    private boolean refreshingControls = false;
125

    
126
    /**
127
     * Elementos de la aplicaci?n
128
     */
129
    private JMenuBar menuBar = new JMenuBar();
130

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

    
136
    /**
137
     * Status bar
138
     */
139
    private NewStatusBar bEstado = null;
140

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

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

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

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

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

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

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

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

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

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

    
205
    private HashMap infoCodedMenus = new HashMap();
206

    
207
    private String titlePrefix;
208

    
209
    private static final String noIcon = "no-icon";
210

    
211
    private Map<JComponent,IExtension> control2extensions = new HashMap<JComponent, IExtension>();
212

    
213
    private MDIFrame() {
214

    
215
    }
216

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

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

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

    
239
        // Se a?aden los listeners del JFrame
240
        this.addWindowListener(new WindowAdapter() {
241

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

    
250
        // Se configura la barra de menu
251
        setJMenuBar(menuBar);
252

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

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

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

    
271
        this.toolBars.addContainerListener(this);
272

    
273

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

    
287
        mdiManager.init(this);
288
    }
289

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

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

    
340
        I18nManager i18nManager = ToolsLocator.getI18nManager();
341

    
342
        JToolBarToggleButton btn;
343
        ImageIcon image
344
                = PluginServices.getIconTheme().get(selectableTool.getIcon());
345

    
346
        if ( image != null ) {
347
            btn = new JToolBarToggleButton(selectableTool.getText(), image);
348
        } else {
349
            logger.warn("Unable to find icon '" + selectableTool.getIcon() + "'.");
350
            btn
351
                    = new JToolBarToggleButton(selectableTool.getText(),
352
                            PluginServices.getIconTheme().get(noIcon));
353
        }
354

    
355
        org.gvsig.andami.ui.mdiFrame.ToggleButtonModel buttonModel
356
                = new org.gvsig.andami.ui.mdiFrame.ToggleButtonModel();
357
        btn.setModel(buttonModel);
358
        btn.setMargin(new Insets(0, 0, 0, 0));
359
        btn.addMouseListener(tooltipListener);
360
        btn.addActionListener(this);
361
        btn.setFocusable(false);
362
        btn.setActionCommand(selectableTool.getActionCommand());
363
        btn.setToolTipText(selectableTool.getTooltip());
364
        btn.setEnabled(false);
365
        btn.setVisible(false);
366

    
367
        ButtonGroup group;
368
        if ( buttonGroupMap.containsKey(selectableTool.getGroup()) ) {
369
            group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
370
        } else {
371
            group = new ButtonGroup();
372
            buttonGroupMap.put(selectableTool.getGroup(), group);
373

    
374
        }
375
        jtb.addButton(group, btn);
376
        buttonModel.setGroupName(selectableTool.getGroup());
377

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

    
384
        addControl(btn);
385

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

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

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

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

    
404
    /**
405
     * Add a button to the toolbar.
406
     *
407
     * @param ext
408
     * Texto del boton, si es null no aparece texto
409
     * @param ext
410
     * Extension asociada al control
411
     * @param toolBar
412
     * Icono del boton, si es null no aparece texto
413
     * @param actionTool
414
     * Tooltip de la barra de herramientas
415
     *
416
     * @throws ClassNotFoundException
417
     * @throws RuntimeException
418
     */
419
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
420
            final ToolBar toolBar, final ActionTool actionTool) throws ClassNotFoundException {
421
        if ( !SwingUtilities.isEventDispatchThread() ) {
422
            try {
423
                SwingUtilities.invokeAndWait(new Runnable() {
424
                    public void run() {
425
                        try {
426
                            addTool(loader, ext, toolBar, actionTool);
427
                        } catch (ClassNotFoundException ex) {
428
                            logger.warn("??? Eehh????", ex);
429
                        }
430
                    }
431
                });
432
            } catch (Exception ex) {
433
                // Do nothing
434
            }
435
            return;
436
        }
437

    
438
        String name = toolBar.getName();
439
        SelectableToolBar jtb = getToolBar(name);
440
        if( actionTool.getDropDownGroup()!=null ) {
441
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
442
            ActionInfo action = actionManager.getAction(actionTool.getName());
443
            if( action!=null ) {
444
                DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(actionTool.getDropDownGroup());
445
                if( dropDownButton==null ) {
446
                    dropDownButton = new DropDownButton();
447
                    dropDownButton.setName(actionTool.getDropDownGroup());
448
                    jtb.add(dropDownButton);
449
                    addControl(dropDownButton);
450
                }
451
                dropDownButton.add(actionManager.getTranslated(action));
452
            }
453
            return;
454
        }
455

    
456
        I18nManager i18nManager = ToolsLocator.getI18nManager();
457

    
458
        JToolBarButton btn;
459
        ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
460

    
461
        if ( image != null ) {
462
            btn = new JToolBarButton(actionTool.getText(), image);
463
        } else {
464
            logger.warn("Unable to find icon '" + actionTool.getIcon() + "'.");
465
            btn
466
                    = new JToolBarButton(actionTool.getText(), PluginServices
467
                            .getIconTheme().get(noIcon));
468
        }
469

    
470
        btn.setMargin(new Insets(0, 0, 0, 0));
471
        btn.addMouseListener(tooltipListener);
472
        btn.addActionListener(this);
473
        btn.setFocusable(false);
474
        btn.setActionCommand(actionTool.getActionCommand());
475
        btn.setEnabled(false);
476
        btn.setVisible(false);
477

    
478

    
479
        jtb.add(btn);
480

    
481
        addControl(btn);
482

    
483
        if ( actionTool.getName() != null ) {
484
            btn.setName(actionTool.getName());
485
        }
486

    
487
        if ( actionTool.getTooltip() != null ) {
488
            btn.setToolTip(i18nManager.getTranslation(actionTool.getTooltip()));
489
            btn.setToolTipKey(actionTool.getTooltip());
490
        }
491

    
492
        if ( actionTool.getEnableText() != null ) {
493
            btn.setEnableText(i18nManager.getTranslation(actionTool.getEnableText()));
494
        }
495

    
496
        if ( actionTool.getLast() == true ) {
497
            jtb.addSeparator();
498
        }
499
    }
500

    
501
    private SelectableToolBar getToolBar(final String toolBarName) {
502
        SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(toolBarName);
503
        if ( jtb == null ) {
504
            jtb = new SelectableToolBar(toolBarName);
505
            jtb.setRollover(true);
506
            jtb.setAndamiVisibility(true);
507
            toolBarMap.put(toolBarName, jtb);
508
            toolBars.add(jtb);
509
        }
510
        return jtb;
511
    }
512

    
513
    public void addTool(final ActionInfo action, final String toolBarName, final String dropDownName) {
514
        if ( !SwingUtilities.isEventDispatchThread() ) {
515
            SwingUtilities.invokeLater(new Runnable() {
516
                public void run() {
517
                    addTool(action, toolBarName,dropDownName);
518
                }
519
            });
520
            return;
521
        }
522
        SelectableToolBar jtb = getToolBar(toolBarName);
523
        DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(dropDownName);
524
        if( dropDownButton == null ) {
525
            dropDownButton = new DropDownButton();
526
            jtb.add(dropDownButton);
527
        }
528
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
529
        dropDownButton.add(actionManager.getTranslated(action));
530
    }
531

    
532
    public void addTool(final ActionInfo action, final String toolBarName) {
533
        I18nManager i18nManager = ToolsLocator.getI18nManager();
534

    
535
        if ( !SwingUtilities.isEventDispatchThread() ) {
536
            SwingUtilities.invokeLater(new Runnable() {
537
                public void run() {
538
                    addTool(action, toolBarName);
539
                }
540
            });
541
            return;
542
        }
543
        JToolBarButton btn = new JToolBarButton(action.getIcon());
544
        btn.setMargin(new Insets(0, 0, 0, 0));
545
        btn.addMouseListener(tooltipListener);
546
        btn.addActionListener(this);
547
        btn.setFocusable(false);
548
        btn.setActionCommand(action.getCommand());
549
        btn.setEnabled(false);
550
        btn.setVisible(false);
551
        btn.setName(action.getName());
552
        if ( action.getTooltip() != null ) {
553
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
554
            btn.setToolTipKey(action.getTooltip());
555
        }
556

    
557
        SelectableToolBar jtb = getToolBar(toolBarName);
558
        jtb.add(btn);
559

    
560
        addControl(btn);
561

    
562
    }
563

    
564
    public void addTool(final ActionInfo action, final String toolBarName) {
565
        I18nManager i18nManager = ToolsLocator.getI18nManager();
566

    
567
        if ( !SwingUtilities.isEventDispatchThread() ) {
568
            SwingUtilities.invokeLater(new Runnable() {
569
                public void run() {
570
                    addTool(action, toolBarName);
571
                }
572
            });
573
            return;
574
        }
575
        JToolBarButton btn = new JToolBarButton(action.getIcon());
576
        btn.setMargin(new Insets(0, 0, 0, 0));
577
        btn.addMouseListener(tooltipListener);
578
        btn.addActionListener(this);
579
        btn.setFocusable(false);
580
        btn.setActionCommand(action.getCommand());
581
        btn.setEnabled(false);
582
        btn.setVisible(false);
583
        btn.setName(action.getName());
584
        if ( action.getTooltip() != null ) {
585
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
586
            btn.setToolTipKey(action.getTooltip());
587
        }
588

    
589
        SelectableToolBar jtb = getToolBar(toolBarName);
590
        jtb.add(btn);
591

    
592
        addControl(btn);
593

    
594
    }
595
    
596
    /**
597
     * Creates the needed menu structure to add the menu to the bar.
598
     * Returns the father which must hold the menu which was
599
     * provided as parameter.
600
     *
601
     * Crea la estructura de menus necesaria para a?adir el menu a la barra.
602
     * Devuelve el padre del cual debe colgar el menu que se pasa como
603
     * parametro.
604
     *
605
     * @param menu
606
     * The Menu whose support is going to be added
607
     * @param loader
608
     * The plugin's class loader
609
     *
610
     * @return The proper father for the menu which was provided as parameter
611
     */
612
    private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) {
613
        return createMenuAncestors(menu.getText());
614
    }
615

    
616
    private JMenu createMenuAncestors(String text) {
617
        I18nManager i18nManager = ToolsLocator.getI18nManager();
618

    
619
        MenuElement menuPadre = null;
620

    
621
        String[] menues = text.split("/");
622
        List menuList = new ArrayList();
623
        menuList.add(menues[0]);
624
        menuPadre = getMenu(menuList, menuBar);
625

    
626
        JMenu padre = null;
627

    
628
        if ( menuPadre == null ) {
629
            padre = new JMenuTraslatable(i18nManager.getTranslation(menues[0]));
630
            ((JMenuTraslatable) padre).setTextKey(menues[0]);
631
            padre.setName(menues[0]);
632
            addControl(padre);
633
            menuBar.add(padre);
634
        } else if ( menuPadre instanceof JMenu ) {
635
            padre = (JMenu) menuPadre;
636
        } else {
637
            logger.warn("Error creating menu. Ancestor does not exist (" + text + ").");
638
            return null;
639
        }
640

    
641
        // Se crea el resto de menus
642
        ArrayList temp = new ArrayList();
643

    
644
        for ( int i = 1; i < (menues.length - 1); i++ ) {
645
            temp.add(menues[i]);
646
        }
647

    
648
        menuPadre = createMenus(temp, padre);
649

    
650
        return (JMenu) menuPadre;
651
    }
652

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

    
691
        if ( menu.getIs_separator() ) {
692
            menuPadre.addSeparator();
693
            return;
694
        }
695

    
696
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
697
        nuevoMenu.addMouseListener(tooltipListener);
698
        menuPadre.add(nuevoMenu);
699
        addControl(nuevoMenu);
700

    
701
    }
702

    
703
    public void addMenu(final ActionInfo action, final String text) {
704
        if ( !SwingUtilities.isEventDispatchThread() ) {
705
            SwingUtilities.invokeLater(new Runnable() {
706
                public void run() {
707
                    addMenu(action, text);
708
                }
709
            });
710
            return;
711
        }
712
        JMenu menuPadre = createMenuAncestors(text);
713
        JMenuItem nuevoMenu = createJMenuItem(action, text);
714
        nuevoMenu.addMouseListener(tooltipListener);
715
        menuPadre.add(nuevoMenu);
716
        menuPadre.invalidate();
717
        Class<? extends IExtension> classExtension = action.getExtension().getClass();
718
        addControl(nuevoMenu);
719
    }
720

    
721
    /**
722
     * Dado lista de nombres de menu, encuentra el menu
723
     *
724
     * @param nombres
725
     * @param padre
726
     * @return
727
     */
728
    private javax.swing.JMenuItem getMenu(List nombres, MenuElement parent) {
729
        if ( parent instanceof javax.swing.JMenu ) {
730
            javax.swing.JMenu parentItem = (javax.swing.JMenu) parent;
731

    
732
            for ( int i = 0; i < parentItem.getMenuComponentCount(); i++ ) {
733

    
734
                String item_name = parentItem.getMenuComponent(i).getName();
735
                if ( ((item_name != null) && (item_name.compareTo((String) nombres.get(0)) == 0))
736
                        || /*
737
                         * We also accept "leaf menus" with no name
738
                         * (Project manager, View-1, View-2, etc)
739
                         */ lastMenuItemWithoutName(parentItem.getMenuComponent(i), nombres) ) {
740

    
741
                    nombres.remove(0);
742
                    if ( nombres.isEmpty() ) {
743
                        if ( parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem ) {
744
                            return (javax.swing.JMenuItem) parentItem
745
                                    .getMenuComponent(i);
746
                        } else {
747
                            logger.error(PluginServices.getText(this,
748
                                    "Menu_type_not_supported_")
749
                                    + " "
750
                                    + parentItem.getMenuComponent(i).getClass()
751
                                    .getName());
752
                            return null;
753
                        }
754
                    } else {
755
                        return getMenu(nombres,
756
                                (MenuElement) parentItem.getMenuComponent(i));
757
                    }
758
                }
759
            }
760
        } else if ( parent instanceof JMenuBar ) {
761
            javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent;
762

    
763
            for ( int i = 0; i < parentItem.getMenuCount(); i++ ) {
764
                if ( (parentItem.getMenu(i).getName() != null // not a
765
                        // JToolBar.Separator
766
                        )
767
                        && (parentItem.getMenu(i).getName()
768
                        .compareTo((String) nombres.get(0)) == 0) ) {
769
                    nombres.remove(0);
770
                    if ( nombres.isEmpty() ) {
771
                        if ( parentItem.getMenu(i) instanceof javax.swing.JMenuItem ) {
772
                            return parentItem.getMenu(i);
773
                        } else {
774
                            logger.error(PluginServices.getText(this,
775
                                    "Menu_type_not_supported_")
776
                                    + " "
777
                                    + parentItem.getMenu(i).getClass()
778
                                    .getName());
779
                            return null;
780
                        }
781
                    } else {
782
                        return getMenu(nombres, parentItem.getMenu(i));
783
                    }
784
                }
785
            }
786
        } else {
787
            logger.error(PluginServices.getText(this,
788
                    "Menu_type_not_supported_")
789
                    + " "
790
                    + parent.getClass().getName() + " " + parent.toString());
791
        }
792
        return null;
793
    }
794

    
795
    /**
796
     * @param menuComponent
797
     * @param nombres
798
     * @return
799
     */
800
    private boolean lastMenuItemWithoutName(Component mc, List names) {
801

    
802
        /*
803
         * names must have 1 string
804
         */
805
        if ( names == null || names.size() != 1 ) {
806
            return false;
807
        }
808
        if ( !(mc instanceof JMenuItem) ) {
809
            return false;
810
        }
811
        JMenuItem jmi = (JMenuItem) mc;
812
        if ( jmi.getName() != null ) {
813
            /*
814
             * Name must be null, so this is a menu leaf
815
             */
816
            return false;
817
        }
818
        if ( jmi.getText() == null ) {
819
            return false;
820
        }
821
        return jmi.getText().compareTo((String) names.get(0)) == 0;
822
    }
823

    
824
    private class JMenuTraslatable extends JMenu implements TranslatableButton {
825

    
826
        private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
827

    
828
        public JMenuTraslatable(String text) {
829
            super(text);
830
        }
831

    
832
        public void setTextKey(String key) {
833
            this.i18nHelper.setText(key);
834
        }
835

    
836
        public void setToolTipKey(String key) {
837
            this.i18nHelper.setTooltip(key);
838
        }
839

    
840
        public void translate() {
841
            if ( this.i18nHelper.needTranslation() ) {
842
                this.i18nHelper.translate();
843
                this.setText(this.i18nHelper.getText());
844
            }
845
        }
846

    
847
    }
848

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

    
873
        // si no quedan nombres de menu por crear se vuelve: caso base
874
        if ( nombres.isEmpty() ) {
875
            return padre;
876
        }
877

    
878
        // Se busca el menu por si ya existiera para no crearlo otra vez
879
        JMenu buscado = null;
880

    
881
        for ( int i = 0; i < padre.getMenuComponentCount(); i++ ) {
882
            try {
883
                JMenu hijo = (JMenu) padre.getMenuComponent(i);
884

    
885
                if ( hijo.getName().compareTo((String) nombres.get(0)) == 0 ) {
886
                    buscado = hijo;
887
                }
888
            } catch (ClassCastException e) {
889
                /*
890
                 * Se ha encontrado un elemento hoja del arbol de men?es
891
                 */
892
            }
893
        }
894

    
895
        if ( buscado != null ) {
896
            // Si lo hemos encontrado creamos el resto
897
            nombres.remove(0);
898

    
899
            return createMenus(nombres, buscado);
900
        } else {
901
            // Si no lo hemos encontrado se crea el menu, se a?ade al padre
902
            // y se crea el resto
903
            String nombre = (String) nombres.get(0);
904
            JMenuTraslatable menuPadre = new JMenuTraslatable(i18nManager.getTranslation(nombre));
905
            menuPadre.setTextKey(nombre);
906
            menuPadre.setName(nombre);
907
            addControl(menuPadre);
908
            padre.add(menuPadre);
909

    
910
            nombres.remove(0);
911

    
912
            return createMenus(nombres, menuPadre);
913
        }
914
    }
915

    
916
    /**
917
     * M?todo invocado en respuesta a ciertos eventos de la interfaz que
918
     * pueden
919
     * ocultar botones de las barras de herramientas y que redimensiona ?sta
920
     * de manera conveniente para que no se oculte ninguno
921
     */
922
    private void ajustarToolBar() {
923
        int margen = 8;
924
        int numFilas = 1;
925
        double acum = margen;
926

    
927
        int toolHeight = 0;
928

    
929
        for ( int i = 0; i < toolBars.getComponentCount(); i++ ) {
930
            Component c = toolBars.getComponent(i);
931

    
932
            if ( !c.isVisible() ) {
933
                continue;
934
            }
935

    
936
            double width = c.getPreferredSize().getWidth();
937
            acum = acum + width;
938

    
939
            if ( acum > this.getWidth() ) {
940
                numFilas++;
941
                acum = width + margen;
942
            }
943

    
944
            if ( c.getPreferredSize().getHeight() > toolHeight ) {
945
                toolHeight = c.getPreferredSize().height;
946
            }
947
        }
948

    
949
        toolBars.setPreferredSize(new Dimension(this.getWidth(),
950
                (numFilas * toolHeight)));
951

    
952
        toolBars.updateUI();
953
    }
954

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

    
958
//            Map<Class<? extends IExtension>, ExtensionDecorator> extensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
959
//            for ( Entry<Class<? extends IExtension>, ExtensionDecorator>  entry: classesExtensions.entrySet()) {
960
//                        if( ! (entry.getValue().getExtension() instanceof LibraryExtension) ) {
961
//                                extensions.put(entry.getKey(), entry.getValue());
962
//                        }
963
//                }
964
//        this.classesExtensions = extensions;
965
    }
966

    
967
    /**
968
     * Metodo de callback invocado cuando se selecciona un menu o un boton
969
     * de
970
     * la barra de herramientas. Se busca la extensi?n asociada y se ejecuta
971
     *
972
     * @param e
973
     * Evento producido
974
     */
975
    public void actionPerformed(ActionEvent e) {
976

    
977
        String actionName = "(unknow)";
978
        try {
979
            JComponent control = (JComponent) e.getSource();
980
            actionName = control.getName();
981

    
982
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
983
            ActionInfo action = actionManager.getAction(control.getName());
984
            Object args = null;
985
            if ( control instanceof IControl ) {
986
                args = ((IControl) control).getValue();
987
            }
988
            if ( args == null ) {
989
                action.execute();
990
            } else {
991
                action.execute(args);
992
            }
993
            String actionCommand = e.getActionCommand();
994
            try {
995
                JToolBarToggleButton toggle = (JToolBarToggleButton) control;
996
                ToggleButtonModel model = (ToggleButtonModel) toggle.getModel();
997
                selectedTool.put(model.getGroupName(), actionCommand);
998
            } catch (ClassCastException ex) {
999
            } catch (NullPointerException ex) {
1000
            }
1001

    
1002
        } catch (Throwable ex) {
1003
            logger.error("Can't perform action '" + actionName + "'.", ex);
1004
        }
1005

    
1006
        enableControls();
1007
        showMemory();
1008
    }
1009

    
1010
    private String getName(String name, PluginClassLoader loader) {
1011
        if ( name.indexOf('.') == -1 ) {
1012
            return loader.getPluginName() + "." + name;
1013
        } else {
1014
            return name;
1015
        }
1016
    }
1017

    
1018
    public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) {
1019
        if ( !SwingUtilities.isEventDispatchThread() ) {
1020
            throw new RuntimeException("No Event Dispatch Thread");
1021
        }
1022

    
1023
        String name = getName(menu.getName(), loader);
1024

    
1025
        // Se crea el control popupmenu
1026
        JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name);
1027

    
1028
        if ( popupMenu == null ) {
1029
            popupMenu = new JPopUpMenu(menu.getName());
1030
            popupMap.put(name, popupMenu);
1031
        }
1032

    
1033
        Menu[] menues = menu.getMenu();
1034
        for ( int i = 0; i < menues.length; i++ ) {
1035
            JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
1036
            popupMenu.add(nuevoMenu);
1037
        }
1038
    }
1039

    
1040
    private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) {
1041
        JMenuItem nuevoMenu = null;
1042

    
1043
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1044

    
1045
        String text = menu.getText();
1046
        int n = text.lastIndexOf('/');
1047
        if ( n >= 0 ) {
1048
            text = text.substring(n + 1);
1049
        }
1050
        String translatedText = i18nManager.getTranslation(text);
1051

    
1052
        IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1053
        if ( menu.getIcon() != null ) {
1054
            if ( iconTheme.exists(menu.getIcon()) ) {
1055
                ImageIcon image = iconTheme.get(menu.getIcon());
1056
                nuevoMenu = new JMenuItem(translatedText, image);
1057
            } else {
1058
                nuevoMenu = new JMenuItem(translatedText);
1059
                logger.info("menu icon '" + menu.getIcon() + "' not exists.");
1060
            }
1061
        } else {
1062
            nuevoMenu = new JMenuItem(translatedText);
1063
        }
1064
        nuevoMenu.setTextKey(text);
1065
        nuevoMenu.setName(menu.getName());
1066

    
1067
        if ( menu.getKey() != null ) {
1068
            nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey()));
1069
        }
1070

    
1071
        nuevoMenu.setActionCommand(menu.getActionCommand());
1072

    
1073
        if ( menu.getTooltip() != null ) {
1074
            nuevoMenu.setToolTip(i18nManager.getTranslation(menu.getTooltip()));
1075
            nuevoMenu.setToolTipKey(menu.getTooltip());
1076
        }
1077

    
1078
        if ( menu.getEnableText() != null ) {
1079
            nuevoMenu.setEnableText(i18nManager.getTranslation(menu.getEnableText()));
1080
        }
1081

    
1082
        nuevoMenu.setEnabled(true);
1083
        nuevoMenu.setVisible(true);
1084

    
1085
        if ( menu.getName() != null ) {
1086
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1087
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1088
            if ( actionInfo != null ) {
1089
                nuevoMenu.addActionListener(actionInfo);
1090
            }
1091
        }
1092
        return nuevoMenu;
1093
    }
1094

    
1095
    private JMenuItem createJMenuItem(ActionInfo action, String text) {
1096
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1097
        JMenuItem nuevoMenu = null;
1098
        String label = null;
1099

    
1100
        if ( text == null ) {
1101
            label = action.getLabel();
1102
        } else if ( text.contains("/") ) {
1103
            String[] ss = text.split("/");
1104
            label = ss[ss.length - 1];
1105
        } else {
1106
            label = text;
1107
        }
1108
        String translatedText = i18nManager.getTranslation(label);
1109
        if ( action.getIconName() != null ) {
1110
            ImageIcon image = action.getIcon();
1111
            if ( image != null ) {
1112
                nuevoMenu = new JMenuItem(translatedText, image);
1113
            } else {
1114
                nuevoMenu = new JMenuItem(translatedText);
1115
            }
1116
        } else {
1117
            nuevoMenu = new JMenuItem(translatedText);
1118
        }
1119
        nuevoMenu.setText(translatedText);
1120
        nuevoMenu.setName(action.getName());
1121
        KeyStroke key = action.getKeyStroke();
1122
        if ( key != null ) {
1123
            nuevoMenu.setAccelerator(key);
1124
        }
1125
        nuevoMenu.setActionCommand(action.getCommand());
1126
        if ( action.getTooltip() != null ) {
1127
            nuevoMenu.setToolTip(i18nManager.getTranslation(action.getTooltip()));
1128
        }
1129
        nuevoMenu.setEnabled(true);
1130
        nuevoMenu.setVisible(true);
1131
        nuevoMenu.addActionListener(action);
1132
        return nuevoMenu;
1133
    }
1134

    
1135
    /**
1136
     * Muestra u oculta el menu de nombre 'name'
1137
     *
1138
     * @param name
1139
     * Nombre del menu que se quiere mostrar
1140
     * @param x
1141
     * Evento de raton
1142
     * @param y
1143
     * @param c
1144
     */
1145
    private void showPopupMenu(String name, int x, int y, Component c) {
1146
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1147

    
1148
        if ( menu != null ) {
1149
            menu.show(c, x, y);
1150
        }
1151
    }
1152

    
1153
    public void removePopupMenuListener(String name, ActionListener listener) {
1154
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1155

    
1156
        if ( menu != null ) {
1157
            Component[] jmenuitems = menu.getComponents();
1158

    
1159
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1160
                if ( jmenuitems[i] instanceof JMenuItem ) {
1161
                    ((JMenuItem) jmenuitems[i]).removeActionListener(listener);
1162
                }
1163
            }
1164
        }
1165
    }
1166

    
1167
    public void addPopupMenuListener(String popupName, Component c,
1168
            ActionListener listener, PluginClassLoader loader) {
1169
        final String name = getName(popupName, loader);
1170

    
1171
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1172

    
1173
        if ( menu != null ) {
1174
            Component[] jmenuitems = menu.getComponents();
1175

    
1176
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1177
                if ( jmenuitems[i] instanceof JMenuItem ) {
1178
                    ((JMenuItem) jmenuitems[i]).addActionListener(listener);
1179
                }
1180
            }
1181
        }
1182

    
1183
        c.addMouseListener(new MouseAdapter() {
1184

    
1185
            @Override
1186
            public void mousePressed(MouseEvent e) {
1187
                if ( e.isPopupTrigger() ) {
1188
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1189
                }
1190
            }
1191

    
1192
            @Override
1193
            public void mouseReleased(MouseEvent e) {
1194
                if ( e.isPopupTrigger() ) {
1195
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1196
                }
1197
            }
1198
        });
1199
    }
1200

    
1201
    /**
1202
     * Loop on the controls to enable/disable and show/hide them, according to
1203
     * its associated action (ActionInfo)
1204
     *
1205
     * @throws RuntimeException
1206
     */
1207
    public void enableControls() {
1208
        if ( !SwingUtilities.isEventDispatchThread() ) {
1209
            SwingUtilities.invokeLater(new Runnable() {
1210
                public void run() {
1211
                    enableControls();
1212
                }
1213
            });
1214
            return;
1215
        }
1216

    
1217
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1218
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1219

    
1220
        // Enable or disable controls, according to its associated extensions
1221
        Iterator<JComponent> e = controlsIterator();
1222

    
1223
        while ( e.hasNext() ) {
1224
            JComponent control = (JComponent) e.next();
1225
            String actionName = control.getName();
1226
            ActionInfo action = actionManager.getAction(actionName);
1227
            try {
1228
                boolean enabled = false;
1229
                boolean visible = false;
1230

    
1231
                if ( action == null ) {
1232
                    if( control instanceof DropDownButton ) {
1233
                        DropDownButton dropDownButton = (DropDownButton)control;
1234
                        visible = !dropDownButton.isAllHiden();
1235
                        enabled = !dropDownButton.isAllDisabled();
1236
                    } else if( control instanceof JMenuTraslatable ) {
1237
                        enabled = true;
1238
                        visible = true;
1239
                    } else {
1240
                        IExtension extension = this.control2extensions.get(control);
1241
                        if( extension!=null ) {
1242
                            enabled = extension.isEnabled();
1243
                            visible = extension.isVisible();
1244
                        } else {
1245
                            logger.warn("Can't enable/show control '"+control.getClass().getName()+"/"+control.getName()+".");
1246
                            enabled = true;
1247
                            visible = true;
1248
                        }
1249
                    }
1250
                } else {
1251
                    enabled = false;
1252
                    visible = cache.isVisible(action);
1253
                    if ( visible ) {
1254
                        enabled = cache.isEnabled(action);
1255
                    }
1256
                }
1257
                control.setEnabled(enabled);
1258
                control.setVisible(visible);
1259
            } catch (Throwable ex) {
1260
                // Catch exceptins and errors (class not found)
1261
                logger.info("Can't enable/show control '" + actionName + "'.", ex);
1262
                this.message("Can't enable/show control '" + actionName + "'.", JOptionPane.ERROR_MESSAGE);
1263
                try {
1264
                    control.setEnabled(false);
1265
                    control.setVisible(false);
1266
                } catch (Exception ex2) {
1267
                    // Ignore errors
1268
                }
1269
            }
1270
        }
1271

    
1272
        // Loop in the menus to hide the menus that don't have visible children
1273
        for ( int i = 0; i < menuBar.getMenuCount(); i++ ) {
1274
            MenuElement menu = menuBar.getMenu(i);
1275
            hideMenus(menu);
1276
            if ( menu instanceof JMenu ) {
1277
                // hide (ugly) redundant separators and assign keyboard
1278
                // mnemonics
1279
                Component[] comps = ((JMenu) menu).getMenuComponents();
1280
                // mnemonics have to be unique for each top-level menu
1281
                char mnemonics[] = new char[comps.length];
1282
                if ( comps.length > 0 ) {
1283
                    // Set keyboard mnemonic for this top-level entry
1284
                    String text = ((JMenu) menu).getText();
1285
                    char mnemonic = getMnemonic(text, mnemonics);
1286
                    if ( ' ' != mnemonic ) {
1287
                        ((JMenu) menu).setMnemonic(mnemonic);
1288
                        mnemonics[0] = mnemonic;
1289
                    }
1290
                }
1291
                // now go through all entries in this menu, hid
1292
                // separators if necessary and assing remaining mnemonics
1293
                hideSeparatorsAndMakeMnemonics(menu, mnemonics);
1294
            }
1295
        }
1296

    
1297
        // hide the toolbars that don't contain any visible tool
1298
        Iterator it = toolBarMap.values().iterator();
1299

    
1300
        while ( it.hasNext() ) {
1301
            JComponent t = (JComponent) it.next();
1302
            boolean todosOcultos = true;
1303

    
1304
            for ( int i = 0; i < t.getComponentCount(); i++ ) {
1305
                if ( !(t.getComponent(i) instanceof JSeparator) // separators
1306
                        // don't matter
1307
                        && t.getComponent(i).isVisible() ) {
1308
                    todosOcultos = false;
1309
                }
1310
            }
1311

    
1312
            if ( todosOcultos ) {
1313
                t.setVisible(false);
1314
            } else {
1315
                if ( t instanceof SelectableToolBar ) {
1316
                    t.setVisible(((SelectableToolBar) t).getAndamiVisibility());
1317
                } else {
1318
                    t.setVisible(true);
1319
                }
1320
            }
1321
        }
1322

    
1323
        if ( mdiManager != null ) {
1324
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1325

    
1326
            if ( f != null ) {
1327
                if ( lastLabelClass != f.getClass() ) {
1328
                    lastLabelClass = f.getClass();
1329

    
1330
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1331

    
1332
                    if ( lbls != null ) {
1333
                        bEstado.setLabelSet(lbls);
1334
                    }
1335
                }
1336
            }
1337
        }
1338

    
1339
        ajustarToolBar();
1340

    
1341
        showMemory();
1342
    }
1343

    
1344
    public synchronized void refreshControls() {
1345
        if ( !SwingUtilities.isEventDispatchThread() ) {
1346
            SwingUtilities.invokeLater(new Runnable() {
1347
                public void run() {
1348
                    refreshControls();
1349
                }
1350
            });
1351
            return;
1352
        }
1353

    
1354
        if(refreshingControls){
1355
            return;
1356
        }
1357
        try {
1358
        refreshingControls = true;
1359
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1360
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1361
        IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1362

    
1363
        Iterator e = controlsIterator();
1364

    
1365
        while ( e.hasNext() ) {
1366
            JComponent control = (JComponent) e.next();
1367
            if ( control instanceof TranslatableButton ) {
1368
                ((TranslatableButton) control).translate();
1369
            }
1370
            String actionlName = control.getName();
1371
            ActionInfo action = actionManager.getAction(actionlName);
1372
            if ( action != null ) {
1373
                if ( control instanceof AbstractButton ) {
1374
                    AbstractButton button = (AbstractButton) control;
1375
                    if ( control instanceof javax.swing.JMenuItem ) {
1376
                        if ( action.getIconName() != null && action.getIconName().length() > 0 ) {
1377
                            if ( icontheme.exists(action.getIconName()) ) {
1378
                                button.setIcon(action.getIcon());
1379
                            }
1380
                        }
1381
                    } else {
1382
                        button.setIcon(action.getIcon());
1383
                    }
1384
                }
1385
            }
1386
        }
1387
        enableControls();
1388
        } finally {
1389
            refreshingControls = false;
1390
        }
1391
    }
1392

    
1393
    public void message(String msg, int messageTyoe) {
1394
        this.getStatusBar().message(msg, messageTyoe);
1395
    }
1396

    
1397
    /**
1398
     * Establece la visibilidad de un menu y todos sus descendientes en la
1399
     * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
1400
     *
1401
     * @param menu
1402
     * Menu que se quiere visualizar
1403
     *
1404
     * @return Devuelve true si el menu es visible y false en caso contrario
1405
     */
1406
    private boolean hideMenus(MenuElement menu) {
1407
        MenuElement[] submenus = menu.getSubElements();
1408

    
1409
        // Si no tiene hijos se devuelve su visibilidad
1410
        if ( submenus.length == 0 ) {
1411
            return menu.getComponent().isVisible();
1412
        }
1413

    
1414
        /*
1415
         * Si tiene hijos se devuelve true si alg?no de ellos es visible,
1416
         * pero se itera por todos ellos
1417
         */
1418
        boolean visible = false;
1419

    
1420
        for ( int i = 0; i < submenus.length; i++ ) {
1421
            if ( hideMenus(submenus[i]) ) {
1422
                if ( !(menu instanceof JPopupMenu) ) {
1423
                    menu.getComponent().setVisible(true);
1424
                }
1425

    
1426
                visible = true;
1427
            }
1428
        }
1429

    
1430
        if ( visible ) {
1431
            return true;
1432
        }
1433

    
1434
        menu.getComponent().setVisible(false);
1435

    
1436
        return false;
1437
    }
1438

    
1439
    /**
1440
     *
1441
     * Recurse through all menu elements and make sure there are no
1442
     * redundant separators.
1443
     * This method will make sure that a separator only becomes visible
1444
     * if at least one visible non-separator menu entry preceeded it.
1445
     *
1446
     *
1447
     */
1448
    private void hideSeparatorsAndMakeMnemonics(MenuElement menu,
1449
            char[] mnemonics) {
1450
        // flag that indicates whether a separator is to be displayed or not
1451
        boolean allowSeparator;
1452

    
1453
        allowSeparator = false; // separator not allowed as very first menu item
1454
        Component[] comps = ((JMenu) menu).getMenuComponents();
1455
        if ( comps.length < 1 ) {
1456
            // zero-length menu: skip
1457
            return;
1458
        }
1459

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

    
1524
    /**
1525
     * Helper functios for assigning a unique mnemomic char from
1526
     * a pool of unassigned onces, stored in the array "mnemomnics"
1527
     */
1528
    private char getMnemonic(String text, char[] mnemonics) {
1529
        if( text==null ) {
1530
            return ' ';
1531
        }
1532
        Vector words = new Vector();
1533
        StringTokenizer t = new StringTokenizer(text);
1534
        int maxsize = 0;
1535

    
1536
        while ( t.hasMoreTokens() ) {
1537
            String word = t.nextToken();
1538
            if ( word.length() > maxsize ) {
1539
                maxsize = word.length();
1540
            }
1541
            words.addElement(word);
1542
        }
1543
        words.trimToSize();
1544

    
1545
        for ( int i = 0; i < maxsize; ++i ) {
1546
            char mnemonic = getMnemonic(words, mnemonics, i);
1547
            if ( ' ' != mnemonic ) {
1548
                return mnemonic;
1549
            }
1550
        }
1551

    
1552
        return ' ';
1553
    }
1554

    
1555
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1556
        int numwords = words.size();
1557

    
1558
        for ( int i = 0; i < numwords; ++i ) {
1559
            String word = (String) words.elementAt(i);
1560
            if ( index >= word.length() ) {
1561
                continue;
1562
            }
1563

    
1564
            char c = word.charAt(index);
1565
            if ( !isMnemonicExists(c, mnemonics) ) {
1566
                /* pick only valid chars */
1567
                if ( (c != ':') && (c != '.') && (c != ',') && (c != ';')
1568
                        && (c != '-') && (c != '+') && (c != '/') && (c != '\\')
1569
                        && (c != '\'') && (c != '\"') && (c != ' ') && (c != '=')
1570
                        && (c != '(') && (c != ')') && (c != '[') && (c != ']')
1571
                        && (c != '{') && (c != '}') && (c != '$') && (c != '*')
1572
                        && (c != '&') && (c != '%') && (c != '!') && (c != '?')
1573
                        && (c != '#') && (c != '~') && (c != '_') ) {
1574
                    return c;
1575
                }
1576
            }
1577
        }
1578
        return ' ';
1579
    }
1580

    
1581
    private boolean isMnemonicExists(char c, char[] mnemonics) {
1582
        int num = mnemonics.length;
1583
        for ( int i = 0; i < num; ++i ) {
1584
            if ( mnemonics[i] == c ) {
1585
                return true;
1586
            }
1587
        }
1588
        return false;
1589
    }
1590

    
1591
    /**
1592
     * Muestra la memoria consumida por el programa
1593
     */
1594
    private void showMemory() {
1595
        Runtime r = Runtime.getRuntime();
1596
        long mem = r.totalMemory() - r.freeMemory();
1597
        logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem
1598
                / 1024 + " KB");
1599
    }
1600

    
1601
    public MDIManager getMDIManager() {
1602
        return mdiManager;
1603
    }
1604

    
1605
    public NewStatusBar getStatusBar() {
1606
        return bEstado;
1607
    }
1608

    
1609
    /**
1610
     * You can use this function to select the appropiate
1611
     * tool inside the toolbars
1612
     */
1613
    public void setSelectedTool(String actionCommand) {
1614
        setSelectedTool(defaultGroup, actionCommand);
1615
    }
1616

    
1617
    /**
1618
     * You can use this function to select the appropiate
1619
     * tool inside the toolbars
1620
     */
1621
    public void setSelectedTool(String groupName, String actionCommand) {
1622
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1623
        if ( group == null ) {
1624
            return;
1625
        }
1626

    
1627
        Enumeration enumeration = group.getElements();
1628
        while ( enumeration.hasMoreElements() ) {
1629
            AbstractButton button = (AbstractButton) enumeration.nextElement();
1630
            if ( button.getActionCommand().equals(actionCommand) ) {
1631
                button.setSelected(true);
1632
            }
1633
        }
1634

    
1635
        selectedTool.put(groupName, actionCommand);
1636
    }
1637

    
1638
    /**
1639
     * You can use this function to select the appropiate
1640
     * tool inside the toolbars
1641
     */
1642
    public void setSelectedTools(Map selectedTools) {
1643
        selectedTool = selectedTools;
1644
        if ( selectedTools == null ) {
1645
            return;
1646
        }
1647
        Iterator groupNames = selectedTools.keySet().iterator();
1648
        while ( groupNames.hasNext() ) {
1649
            try {
1650
                String groupName = (String) groupNames.next();
1651
                ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1652
                Enumeration enumeration = group.getElements();
1653
                String actionCommand = (String) selectedTools.get(groupName);
1654
                if ( actionCommand == null ) {
1655
                    continue;
1656
                }
1657
                while ( enumeration.hasMoreElements() ) {
1658
                    AbstractButton button
1659
                            = (AbstractButton) enumeration.nextElement();
1660
                    if ( button.getActionCommand().equals(actionCommand) ) {
1661
                        button.setSelected(true);
1662
                    }
1663
                }
1664
            } catch (ClassCastException ex) {
1665
                logger
1666
                        .error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1667
            }
1668
        }
1669
    }
1670

    
1671
    /**
1672
     * DOCUMENT ME!
1673
     *
1674
     * @param clase
1675
     * @param label
1676
     */
1677
    public void setStatusBarLabels(Class<?> clase, Label[] label) {
1678
        classLabels.put(clase, label);
1679
    }
1680

    
1681
    public void removeStatusBarLabels(Class<?> clase) {
1682
        classLabels.remove(clase);
1683
    }
1684

    
1685
    public void addStatusBarControl(Class<?> extensionClass, IControl control) {
1686
        control.addActionListener(this);
1687
        bEstado.addControl(control.getName(), (Component) control);
1688
        if ( control instanceof JComponent ) {
1689
            addControl((JComponent) control);
1690
            PluginsManager pluginsManager = PluginsLocator.getManager();
1691
            IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1692
            this.control2extensions.put((JComponent)control, extension);
1693
        }
1694
    }
1695

    
1696
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1697
        toolBars.add(control);
1698
        addControl(control);
1699

    
1700
        PluginsManager pluginsManager = PluginsLocator.getManager();
1701
        IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1702
        this.control2extensions.put(control, extension);
1703
    }
1704

    
1705
    public void removeStatusBarControl(String name) {
1706
        Component c = bEstado.removeControl(name);
1707
        if ( c instanceof JComponent ) {
1708
            removeControl((JComponent) c);
1709
        }
1710
    }
1711

    
1712
    public void removeMenu(Menu menu) {
1713
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1714

    
1715
        if ( delete == null ) {
1716
            throw new NoSuchElementException(menu.getText());
1717
        }
1718

    
1719
        delete.getParent().remove(delete);
1720
        infoCodedMenus.remove(menu);
1721
    }
1722

    
1723
    public void addMenu(Menu menu, ActionListener listener,
1724
            PluginClassLoader loader) {
1725
        JMenu menuPadre = createMenuAncestors(menu, loader);
1726

    
1727
        // Se registra y a?aade el menu
1728
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
1729
        nuevoMenu.addMouseListener(tooltipListener);
1730
        if ( listener != null && menu.getName() != null && menu.getName().trim().length() > 0 ) {
1731
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1732
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1733
            if ( actionInfo != null ) {
1734
                nuevoMenu.removeActionListener(actionInfo);
1735
            }
1736
            nuevoMenu.addActionListener(listener);
1737
        } else {
1738
            /*
1739
             * We also add action listener for menu with
1740
             * no name but with text:
1741
             *
1742
             * Window/Project manager
1743
             * Window/View - 1
1744
             * Window/View - 2
1745
             * etc
1746
             */
1747
            if ( listener != null && menu.getText() != null && menu.getText().trim().length() > 0 ) {
1748
                nuevoMenu.addActionListener(listener);
1749
            }
1750

    
1751
        }
1752
        menuPadre.add(nuevoMenu);
1753

    
1754
        infoCodedMenus.put(menu, nuevoMenu);
1755
    }
1756

    
1757
    public void changeMenuName(String[] menu, String newName,
1758
            PluginClassLoader loader) {
1759

    
1760
        ArrayList menuList = new ArrayList();
1761
        for ( int i = 0; i < menu.length; i++ ) {
1762
            menuList.add(menu[i]);
1763
        }
1764

    
1765
        javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1766
        if ( newMenu == null ) {
1767
            throw new NoSuchMenuException(menu[0]);
1768
        } else {
1769
            newMenu.setText(PluginServices.getText(this, newName));
1770
        }
1771
    }
1772

    
1773
    public void componentHidden(ComponentEvent arg0) {
1774
    }
1775

    
1776
    public void componentMoved(ComponentEvent arg0) {
1777
    }
1778

    
1779
    public void componentResized(ComponentEvent arg0) {
1780
        ajustarToolBar();
1781
    }
1782

    
1783
    public void componentShown(ComponentEvent arg0) {
1784
    }
1785

    
1786
    public void componentAdded(ContainerEvent arg0) {
1787
        ajustarToolBar();
1788
    }
1789

    
1790
    public void componentRemoved(ContainerEvent arg0) {
1791
        ajustarToolBar();
1792
    }
1793

    
1794
    public class TooltipListener extends MouseAdapter {
1795

    
1796
        @Override
1797
        public void mouseEntered(MouseEvent e) {
1798
            JComponent control = (JComponent) e.getSource();
1799
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1800

    
1801
            String texto = null;
1802
            texto = control.getToolTipText();
1803

    
1804
            if ( texto != null ) {
1805
                bEstado.setInfoTextTemporal(texto);
1806
            }
1807
        }
1808

    
1809
        @Override
1810
        public void mouseExited(MouseEvent arg0) {
1811
            bEstado.restaurarTexto();
1812
        }
1813

    
1814
        @Override
1815
        public void mousePressed(MouseEvent e) {
1816
            bEstado.restaurarTexto();
1817
        }
1818
    }
1819

    
1820
    public String getTitlePrefix() {
1821
        return titlePrefix;
1822
    }
1823

    
1824
    public void setTitlePrefix(String titlePrefix) {
1825
        this.titlePrefix = titlePrefix;
1826
    }
1827

    
1828
    public Map getSelectedTools() {
1829
        return selectedTool;
1830
    }
1831

    
1832
    public HashMap getInitialSelectedTools() {
1833
        return initialSelectedTools;
1834
    }
1835

    
1836
    /**
1837
     * Get a previously added JComponent by name.
1838
     * For example you can use it if you need to obtain a JToolBar to
1839
     * add some customized component.
1840
     *
1841
     * @param name
1842
     * @return the JComponent or null if none has been found
1843
     */
1844
    public JComponent getComponentByName(String name) {
1845
        Iterator e = controlsIterator();
1846

    
1847
        while ( e.hasNext() ) {
1848
            JComponent control = (JComponent) e.next();
1849
            String nameCtrl = control.getName();
1850
            if ( nameCtrl != null ) {
1851
                if ( nameCtrl.compareTo(name) == 0 ) {
1852
                    return control;
1853
                }
1854
            }
1855
        }
1856
        Iterator it = toolBarMap.values().iterator();
1857
        while ( it.hasNext() ) {
1858
            JComponent t = (JComponent) it.next();
1859
            String nameCtrl = t.getName();
1860
            if ( nameCtrl != null ) {
1861
                if ( nameCtrl.compareTo(name) == 0 ) {
1862
                    return t;
1863
                }
1864
            }
1865

    
1866
        }
1867

    
1868
        return null;
1869
    }
1870

    
1871
    public SelectableToolBar[] getToolbars() {
1872
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1873
                new SelectableToolBar[0]);
1874
    }
1875

    
1876
    public boolean getToolbarVisibility(String name) {
1877
        JComponent component
1878
                = PluginServices.getMainFrame().getComponentByName(name);
1879
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1880
            SelectableToolBar toolBar = (SelectableToolBar) component;
1881
            return toolBar.getAndamiVisibility();
1882
        }
1883
        return false;
1884
    }
1885

    
1886
    public boolean setToolbarVisibility(String name, boolean visibility) {
1887
        JComponent component
1888
                = PluginServices.getMainFrame().getComponentByName(name);
1889
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1890
            SelectableToolBar toolBar = (SelectableToolBar) component;
1891
            boolean oldVisibility = toolBar.getAndamiVisibility();
1892
            toolBar.setAndamiVisibility(visibility);
1893
            enableControls();
1894
            return oldVisibility;
1895
        }
1896
        return false;
1897
    }
1898

    
1899
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1900
        ArrayList menu = new ArrayList();
1901
        for ( int i = 0; i < menuPath.length; i++ ) {
1902
            menu.add(menuPath[i]);
1903
        }
1904
        return getMenu(menu, menuBar);
1905
    }
1906

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

    
1912
    public void messageDialog(String message, String[] messageArgs,
1913
            String title, int messageType) {
1914
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1915
        helper.messageDialog(message, messageArgs, title, messageType);
1916
    }
1917

    
1918
    public int confirmDialog(String message, String title, int optionType,
1919
            int messageType) {
1920
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1921
        return helper.confirmDialog(message, title, optionType, messageType);
1922
    }
1923

    
1924
    public String inputDialog(String message, String title, int messageType,
1925
            String initialValue) {
1926
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1927
        return helper.inputDialog(message, title, messageType, initialValue);
1928
    }
1929

    
1930
    public String inputDialog(String message, String title) {
1931
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1932
        return helper.inputDialog(message, title);
1933
    }
1934

    
1935
    public void showDialog(Component contents, String title) {
1936
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1937
        helper.showDialog(contents, title);
1938
    }
1939

    
1940
    public Component createComponent(Class<? extends Component> theClass,
1941
            Object... parameters) {
1942
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1943
        return helper.createComponentWithParams(theClass, parameters);
1944
    }
1945

    
1946
    public Component createComponentWithParams(
1947
            Class<? extends Component> theClass, Object[] parameters) {
1948
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1949
        return helper.createComponentWithParams(theClass, parameters);
1950
    }
1951

    
1952
    public File[] showChooserDialog(
1953
            final String title,
1954
            final int type, // SAVE_DIALOG / OPEN_DIALOG
1955
            final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
1956
            final boolean multiselection,
1957
            final File initialPath,
1958
            final FileFilter filter,
1959
            final boolean fileHidingEnabled
1960
    ) {
1961
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1962
        return helper.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
1963
    }
1964

    
1965
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1966
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1967
    }
1968

    
1969
    public File[] showOpenFileDialog(String title, File initialPath) {
1970
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1971
    }
1972

    
1973
    public File[] showSaveFileDialog(String title, File initialPath) {
1974
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1975
    }
1976

    
1977
    private void addControl(JComponent control) {
1978
        controls.add(control);
1979
    }
1980

    
1981
    private void removeControl(JComponent control) {
1982
        controls.remove(control);
1983
    }
1984

    
1985
    private Iterator<JComponent> controlsIterator() {
1986
        return this.controls.iterator();
1987
    }
1988

    
1989
    @Override
1990
    public void setLocale(Locale locale) {
1991
        super.setLocale(locale); //To change body of generated methods, choose Tools | Templates.
1992
        MDIManager mdiManager = MDIManagerFactory.createManager();
1993
        mdiManager.setLocale(locale);
1994
        if ( this.controls != null && !this.controls.isEmpty() ) {
1995
            this.refreshControls();
1996
        }
1997
    }
1998

    
1999
}