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

History | View | Annotate | Download (69.1 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
        logger.info("ENABLE CONTROOOOOLS");
1196
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
1197
        for(int i=0; i<stackTrace.length; i++){
1198
            logger.info(stackTrace[i].toString());
1199
        }
1200

    
1201
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1202
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1203

    
1204
        // Enable or disable controls, according to its associated extensions
1205
        Iterator<JComponent> e = controlsIterator();
1206

    
1207
        while ( e.hasNext() ) {
1208
            JComponent control = (JComponent) e.next();
1209
            String actionName = control.getName();
1210
            ActionInfo action = actionManager.getAction(actionName);
1211
            try {
1212
                boolean enabled = false;
1213
                boolean visible = false;
1214

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

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

    
1284
        // hide the toolbars that don't contain any visible tool
1285
        Iterator it = toolBarMap.values().iterator();
1286

    
1287
        while ( it.hasNext() ) {
1288
            JComponent t = (JComponent) it.next();
1289
            boolean todosOcultos = true;
1290

    
1291
            for ( int i = 0; i < t.getComponentCount(); i++ ) {
1292
                if ( !(t.getComponent(i) instanceof JSeparator) // separators
1293
                        // don't matter
1294
                        && t.getComponent(i).isVisible() ) {
1295
                    todosOcultos = false;
1296
                }
1297
            }
1298

    
1299
            if ( todosOcultos ) {
1300
                t.setVisible(false);
1301
            } else {
1302
                if ( t instanceof SelectableToolBar ) {
1303
                    t.setVisible(((SelectableToolBar) t).getAndamiVisibility());
1304
                } else {
1305
                    t.setVisible(true);
1306
                }
1307
            }
1308
        }
1309

    
1310
        if ( mdiManager != null ) {
1311
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1312

    
1313
            if ( f != null ) {
1314
                if ( lastLabelClass != f.getClass() ) {
1315
                    lastLabelClass = f.getClass();
1316

    
1317
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1318

    
1319
                    if ( lbls != null ) {
1320
                        bEstado.setLabelSet(lbls);
1321
                    }
1322
                }
1323
            }
1324
        }
1325

    
1326
        ajustarToolBar();
1327

    
1328
        showMemory();
1329
    }
1330

    
1331
    public synchronized void refreshControls() {
1332
        logger.info("ESTOY AQUIIIIIIIIIII 1");
1333
        if ( !SwingUtilities.isEventDispatchThread() ) {
1334
            SwingUtilities.invokeLater(new Runnable() {
1335
                public void run() {
1336
                    refreshControls();
1337
                }
1338
            });
1339
            return;
1340
        }
1341

    
1342
        logger.info("ESTOY AQUIIIIIIIIIII 2");
1343
        if(refreshingControls){
1344
            return;
1345
        }
1346
        try {
1347
//        enableControls();
1348
        refreshingControls = true;
1349
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1350
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1351
        IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1352

    
1353
        Iterator e = controlsIterator();
1354

    
1355
        while ( e.hasNext() ) {
1356
            JComponent control = (JComponent) e.next();
1357
            if ( control instanceof TranslatableButton ) {
1358
                ((TranslatableButton) control).translate();
1359
            }
1360
            String actionlName = control.getName();
1361
            ActionInfo action = actionManager.getAction(actionlName);
1362
            if ( action != null ) {
1363
                if ( control instanceof AbstractButton ) {
1364
                    AbstractButton button = (AbstractButton) control;
1365
                    if ( control instanceof javax.swing.JMenuItem ) {
1366
                        if ( action.getIconName() != null && action.getIconName().length() > 0 ) {
1367
                            if ( icontheme.exists(action.getIconName()) ) {
1368
                                button.setIcon(action.getIcon());
1369
                            }
1370
                        }
1371
                    } else {
1372
                        button.setIcon(action.getIcon());
1373
                    }
1374
                }
1375
            }
1376
        }
1377
        logger.info("ESTOY AQUIIIIIIIIIII 3");
1378

    
1379
        enableControls();
1380
        logger.info("ESTOY AQUIIIIIIIIIII 4");
1381
        logger.info("   ");
1382

    
1383
        } finally {
1384
            refreshingControls = false;
1385
        }
1386
    }
1387

    
1388
    public void message(String msg, int messageTyoe) {
1389
        this.getStatusBar().message(msg, messageTyoe);
1390
    }
1391

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

    
1404
        // Si no tiene hijos se devuelve su visibilidad
1405
        if ( submenus.length == 0 ) {
1406
            return menu.getComponent().isVisible();
1407
        }
1408

    
1409
        /*
1410
         * Si tiene hijos se devuelve true si alg�no de ellos es visible,
1411
         * pero se itera por todos ellos
1412
         */
1413
        boolean visible = false;
1414

    
1415
        for ( int i = 0; i < submenus.length; i++ ) {
1416
            if ( hideMenus(submenus[i]) ) {
1417
                if ( !(menu instanceof JPopupMenu) ) {
1418
                    menu.getComponent().setVisible(true);
1419
                }
1420

    
1421
                visible = true;
1422
            }
1423
        }
1424

    
1425
        if ( visible ) {
1426
            return true;
1427
        }
1428

    
1429
        menu.getComponent().setVisible(false);
1430

    
1431
        return false;
1432
    }
1433

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

    
1448
        allowSeparator = false; // separator not allowed as very first menu item
1449
        Component[] comps = ((JMenu) menu).getMenuComponents();
1450
        if ( comps.length < 1 ) {
1451
            // zero-length menu: skip
1452
            return;
1453
        }
1454

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

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

    
1531
        while ( t.hasMoreTokens() ) {
1532
            String word = t.nextToken();
1533
            if ( word.length() > maxsize ) {
1534
                maxsize = word.length();
1535
            }
1536
            words.addElement(word);
1537
        }
1538
        words.trimToSize();
1539

    
1540
        for ( int i = 0; i < maxsize; ++i ) {
1541
            char mnemonic = getMnemonic(words, mnemonics, i);
1542
            if ( ' ' != mnemonic ) {
1543
                return mnemonic;
1544
            }
1545
        }
1546

    
1547
        return ' ';
1548
    }
1549

    
1550
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1551
        int numwords = words.size();
1552

    
1553
        for ( int i = 0; i < numwords; ++i ) {
1554
            String word = (String) words.elementAt(i);
1555
            if ( index >= word.length() ) {
1556
                continue;
1557
            }
1558

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

    
1576
    private boolean isMnemonicExists(char c, char[] mnemonics) {
1577
        int num = mnemonics.length;
1578
        for ( int i = 0; i < num; ++i ) {
1579
            if ( mnemonics[i] == c ) {
1580
                return true;
1581
            }
1582
        }
1583
        return false;
1584
    }
1585

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

    
1596
    public MDIManager getMDIManager() {
1597
        return mdiManager;
1598
    }
1599

    
1600
    public NewStatusBar getStatusBar() {
1601
        return bEstado;
1602
    }
1603

    
1604
    /**
1605
     * You can use this function to select the appropiate
1606
     * tool inside the toolbars
1607
     */
1608
    public void setSelectedTool(String actionCommand) {
1609
        setSelectedTool(defaultGroup, actionCommand);
1610
    }
1611

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

    
1622
        Enumeration enumeration = group.getElements();
1623
        while ( enumeration.hasMoreElements() ) {
1624
            AbstractButton button = (AbstractButton) enumeration.nextElement();
1625
            if ( button.getActionCommand().equals(actionCommand) ) {
1626
                button.setSelected(true);
1627
            }
1628
        }
1629

    
1630
        selectedTool.put(groupName, actionCommand);
1631
    }
1632

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

    
1666
    /**
1667
     * DOCUMENT ME!
1668
     *
1669
     * @param clase
1670
     * @param label
1671
     */
1672
    public void setStatusBarLabels(Class<?> clase, Label[] label) {
1673
        classLabels.put(clase, label);
1674
    }
1675

    
1676
    public void removeStatusBarLabels(Class<?> clase) {
1677
        classLabels.remove(clase);
1678
    }
1679

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

    
1691
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1692
        toolBars.add(control);
1693
        addControl(control);
1694

    
1695
        PluginsManager pluginsManager = PluginsLocator.getManager();
1696
        IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1697
        this.control2extensions.put(control, extension);
1698
    }
1699

    
1700
    public void removeStatusBarControl(String name) {
1701
        Component c = bEstado.removeControl(name);
1702
        if ( c instanceof JComponent ) {
1703
            removeControl((JComponent) c);
1704
        }
1705
    }
1706

    
1707
    public void removeMenu(Menu menu) {
1708
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1709

    
1710
        if ( delete == null ) {
1711
            throw new NoSuchElementException(menu.getText());
1712
        }
1713

    
1714
        delete.getParent().remove(delete);
1715
        infoCodedMenus.remove(menu);
1716
    }
1717

    
1718
    public void addMenu(Menu menu, ActionListener listener,
1719
            PluginClassLoader loader) {
1720
        JMenu menuPadre = createMenuAncestors(menu, loader);
1721

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

    
1746
        }
1747
        menuPadre.add(nuevoMenu);
1748

    
1749
        infoCodedMenus.put(menu, nuevoMenu);
1750
    }
1751

    
1752
    public void changeMenuName(String[] menu, String newName,
1753
            PluginClassLoader loader) {
1754

    
1755
        ArrayList menuList = new ArrayList();
1756
        for ( int i = 0; i < menu.length; i++ ) {
1757
            menuList.add(menu[i]);
1758
        }
1759

    
1760
        javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1761
        if ( newMenu == null ) {
1762
            throw new NoSuchMenuException(menu[0]);
1763
        } else {
1764
            newMenu.setText(PluginServices.getText(this, newName));
1765
        }
1766
    }
1767

    
1768
    public void componentHidden(ComponentEvent arg0) {
1769
    }
1770

    
1771
    public void componentMoved(ComponentEvent arg0) {
1772
    }
1773

    
1774
    public void componentResized(ComponentEvent arg0) {
1775
        ajustarToolBar();
1776
    }
1777

    
1778
    public void componentShown(ComponentEvent arg0) {
1779
    }
1780

    
1781
    public void componentAdded(ContainerEvent arg0) {
1782
        ajustarToolBar();
1783
    }
1784

    
1785
    public void componentRemoved(ContainerEvent arg0) {
1786
        ajustarToolBar();
1787
    }
1788

    
1789
    public class TooltipListener extends MouseAdapter {
1790

    
1791
        @Override
1792
        public void mouseEntered(MouseEvent e) {
1793
            JComponent control = (JComponent) e.getSource();
1794
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1795

    
1796
            String texto = null;
1797
            texto = control.getToolTipText();
1798

    
1799
            if ( texto != null ) {
1800
                bEstado.setInfoTextTemporal(texto);
1801
            }
1802
        }
1803

    
1804
        @Override
1805
        public void mouseExited(MouseEvent arg0) {
1806
            bEstado.restaurarTexto();
1807
        }
1808

    
1809
        @Override
1810
        public void mousePressed(MouseEvent e) {
1811
            bEstado.restaurarTexto();
1812
        }
1813
    }
1814

    
1815
    public String getTitlePrefix() {
1816
        return titlePrefix;
1817
    }
1818

    
1819
    public void setTitlePrefix(String titlePrefix) {
1820
        this.titlePrefix = titlePrefix;
1821
    }
1822

    
1823
    public Map getSelectedTools() {
1824
        return selectedTool;
1825
    }
1826

    
1827
    public HashMap getInitialSelectedTools() {
1828
        return initialSelectedTools;
1829
    }
1830

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

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

    
1861
        }
1862

    
1863
        return null;
1864
    }
1865

    
1866
    public SelectableToolBar[] getToolbars() {
1867
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1868
                new SelectableToolBar[0]);
1869
    }
1870

    
1871
    public boolean getToolbarVisibility(String name) {
1872
        JComponent component
1873
                = PluginServices.getMainFrame().getComponentByName(name);
1874
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1875
            SelectableToolBar toolBar = (SelectableToolBar) component;
1876
            return toolBar.getAndamiVisibility();
1877
        }
1878
        return false;
1879
    }
1880

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

    
1894
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1895
        ArrayList menu = new ArrayList();
1896
        for ( int i = 0; i < menuPath.length; i++ ) {
1897
            menu.add(menuPath[i]);
1898
        }
1899
        return getMenu(menu, menuBar);
1900
    }
1901

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

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

    
1913
    public int confirmDialog(String message, String title, int optionType,
1914
            int messageType) {
1915
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1916
        return helper.confirmDialog(message, title, optionType, messageType);
1917
    }
1918

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

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

    
1930
    public void showDialog(Component contents, String title) {
1931
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1932
        helper.showDialog(contents, title);
1933
    }
1934

    
1935
    public Component createComponent(Class<? extends Component> theClass,
1936
            Object... parameters) {
1937
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1938
        return helper.createComponentWithParams(theClass, parameters);
1939
    }
1940

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

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

    
1960
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1961
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1962
    }
1963

    
1964
    public File[] showOpenFileDialog(String title, File initialPath) {
1965
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1966
    }
1967

    
1968
    public File[] showSaveFileDialog(String title, File initialPath) {
1969
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1970
    }
1971

    
1972
    private void addControl(JComponent control) {
1973
        controls.add(control);
1974
    }
1975

    
1976
    private void removeControl(JComponent control) {
1977
        controls.remove(control);
1978
    }
1979

    
1980
    private Iterator<JComponent> controlsIterator() {
1981
        return this.controls.iterator();
1982
    }
1983

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

    
1994
}