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

History | View | Annotate | Download (70.5 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
import org.apache.commons.lang3.StringUtils;
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
import org.slf4j.Logger;
102
import org.slf4j.LoggerFactory;
103

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

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

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

    
119
    private static MDIFrame instance = null;
120

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

    
123
    private boolean refreshingControls = false;
124

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

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

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

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

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

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

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

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

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

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

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

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

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

    
204
    private HashMap infoCodedMenus = new HashMap();
205

    
206
    private String titlePrefix;
207

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

    
210
    private MDIFrame() {
211

    
212
    }
213

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

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

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

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

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

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

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

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

    
263
        // Add the status bar of the application
264
        bEstado = new NewStatusBar();
265
        getContentPane().add(bEstado, BorderLayout.SOUTH);
266

    
267
        this.toolBars.addContainerListener(this);
268

    
269

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

    
283
        mdiManager.init(this);
284
    }
285

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

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

    
311
    public SelectableToolBar  addToolBar(final String toolBarName, String description, int position) {
312
        SelectableToolBar toolBar = (SelectableToolBar) toolBarMap.get(toolBarName);
313
        if( toolBar == null ) {
314
            toolBar = new SelectableToolBar(toolBarName, description, position);
315
            toolBar.setRollover(true);
316
            toolBar.setAndamiVisibility(true);
317
            toolBarMap.put(toolBarName, toolBar);
318
            toolBars.add(toolBar);
319
            
320
        } else if( toolBar.getPosition() < 1 ) {
321
            toolBar.setPosition(position);
322
            
323
        } else if( toolBar.getPosition() != position ) {
324
            logger.warn("Add duplicate tool-bar ("+toolBarName+") with diferent position.");
325
        }
326
        
327
        return toolBar;
328
    }
329
    
330
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
331
            final ToolBar toolBar, final SelectableTool selectableTool)
332
            throws ClassNotFoundException {
333
        if ( !SwingUtilities.isEventDispatchThread() ) {
334
            try {
335
                SwingUtilities.invokeAndWait(new Runnable() {
336
                    public void run() {
337
                        try {
338
                            addTool(loader, ext, toolBar, selectableTool);
339
                        } catch (ClassNotFoundException ex) {
340
                            logger.warn("Eehh????", ex);
341
                        }
342
                    }
343
                });
344
            } catch (Exception ex) {
345
                // Do nothing
346
            }
347
            return;
348
        }
349
        String name = toolBar.getName();
350
        SelectableToolBar jtb = getToolBar(name, loader.getPluginName());
351
        if( selectableTool.getDropDownGroup()!=null ) {
352
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
353
            ActionInfo action = actionManager.getAction(selectableTool.getName());
354
            if( action!=null ) {
355
                DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(selectableTool.getDropDownGroup());
356
                if( dropDownButton==null ) {
357
                    dropDownButton = new DropDownButton();
358
                    dropDownButton.setName(selectableTool.getDropDownGroup());
359
                    jtb.add(dropDownButton);
360
                    addControl(dropDownButton);
361
                }
362
                dropDownButton.add(actionManager.getTranslated(action));
363
            }
364
            return;
365
        }
366

    
367
        I18nManager i18nManager = ToolsLocator.getI18nManager();
368

    
369
        ImageIcon image = PluginServices.getIconTheme().get(selectableTool.getIcon());
370
        if ( image == null ) {
371
            logger.warn("Unable to find icon '" + selectableTool.getIcon() + "'.");
372
            image = PluginServices.getIconTheme().getDefaultIcon();
373
        }
374

    
375
        ToggleButtonModel buttonModel = new ToggleButtonModel();
376
        JToolBarToggleButton btn = new JToolBarToggleButton(selectableTool.getText(), image);
377
        btn.setModel(buttonModel);
378
        btn.setMargin(new Insets(0, 0, 0, 0));
379
        btn.addMouseListener(tooltipListener);
380
        btn.addActionListener(this);
381
        btn.setFocusable(false);
382
        btn.setActionCommand(selectableTool.getActionCommand());
383
        btn.setToolTipText(selectableTool.getTooltip());
384
        btn.setEnabled(false);
385
        btn.setVisible(false);
386

    
387
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
388
        if ( group == null ) {
389
            group = new ButtonGroup();
390
            buttonGroupMap.put(selectableTool.getGroup(), group);
391
        }
392

    
393
        jtb.addButton(group, btn);
394

    
395
        buttonModel.setGroupName(selectableTool.getGroup());
396
        if ( selectableTool.getIsDefault() ) {
397
            btn.setSelected(true);
398
            initialSelectedTools.put(selectableTool.getGroup(),
399
                    btn.getActionCommand());
400
        }
401

    
402
        addControl(btn);
403

    
404
        if ( selectableTool.getName() != null ) {
405
            btn.setName(selectableTool.getName());
406
        }
407

    
408
        if ( selectableTool.getTooltip() != null ) {
409
            btn.setToolTip(i18nManager.getTranslation(selectableTool.getTooltip()));
410
            btn.setToolTipKey(selectableTool.getTooltip());
411
        }
412

    
413
        if ( selectableTool.getEnableText() != null ) {
414
            btn.setEnableText(i18nManager.getTranslation(selectableTool.getEnableText()));
415
        }
416

    
417
        if ( selectableTool.getLast() == true ) {
418
            jtb.addSeparator();
419
        }
420
    }
421

    
422
    public void addTool(final PluginClassLoader loader, final SkinExtensionType ext,
423
            final ToolBar toolBar, final ActionTool actionTool) throws ClassNotFoundException {
424
        if ( !SwingUtilities.isEventDispatchThread() ) {
425
            try {
426
                SwingUtilities.invokeAndWait(new Runnable() {
427
                    public void run() {
428
                        try {
429
                            addTool(loader, ext, toolBar, actionTool);
430
                        } catch (ClassNotFoundException ex) {
431
                            logger.warn("Eehh????", ex);
432
                        }
433
                    }
434
                });
435
            } catch (Exception ex) {
436
                // Do nothing
437
            }
438
            return;
439
        }
440

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

    
459
        I18nManager i18nManager = ToolsLocator.getI18nManager();
460

    
461
        ImageIcon image = IconThemeHelper.getImageIcon(actionTool.getIcon());
462
        if ( image == null ) {
463
            logger.warn("Unable to find icon '" + actionTool.getIcon() + "'.");
464
            image =  PluginServices.getIconTheme().getDefaultIcon();
465
        }
466

    
467
        JToolBarButton btn = new JToolBarButton(actionTool.getText(), image);
468
        btn.setMargin(new Insets(0, 0, 0, 0));
469
        btn.addMouseListener(tooltipListener);
470
        btn.addActionListener(this);
471
        btn.setFocusable(false);
472
        btn.setActionCommand(actionTool.getActionCommand());
473
        btn.setEnabled(false);
474
        btn.setVisible(false);
475

    
476
        jtb.add(btn);
477

    
478
        addControl(btn);
479

    
480
        if ( actionTool.getName() != null ) {
481
            btn.setName(actionTool.getName());
482
        }
483

    
484
        if ( actionTool.getTooltip() != null ) {
485
            btn.setToolTip(i18nManager.getTranslation(actionTool.getTooltip()));
486
            btn.setToolTipKey(actionTool.getTooltip());
487
        }
488

    
489
        if ( actionTool.getEnableText() != null ) {
490
            btn.setEnableText(i18nManager.getTranslation(actionTool.getEnableText()));
491
        }
492

    
493
        if ( actionTool.getLast() == true ) {
494
            jtb.addSeparator();
495
        }
496
    }
497

    
498
    public void addTool(final ActionInfo action, final String toolBarName, final String dropDownName) {
499
        if ( !SwingUtilities.isEventDispatchThread() ) {
500
            SwingUtilities.invokeLater(new Runnable() {
501
                public void run() {
502
                    addTool(action, toolBarName,dropDownName);
503
                }
504
            });
505
            return;
506
        }
507
        SelectableToolBar jtb = getToolBar(toolBarName, action.getPluginName());
508
        DropDownButton dropDownButton = (DropDownButton) jtb.findComponent(dropDownName);
509
        if( dropDownButton == null ) {
510
            dropDownButton = new DropDownButton();
511
            jtb.add(dropDownButton);
512
        }
513
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
514
        dropDownButton.add(actionManager.getTranslated(action));
515
    }
516
    public void addTool(final ActionInfo action, final String toolBarName) {
517
        addTool(action, toolBarName, false);
518
    }
519

    
520
    public void addTool(final ActionInfo action, final String toolBarName, final boolean useText) {
521
        I18nManager i18nManager = ToolsLocator.getI18nManager();
522

    
523
        if ( !SwingUtilities.isEventDispatchThread() ) {
524
            SwingUtilities.invokeLater(new Runnable() {
525
                public void run() {
526
                    addTool(action, toolBarName, useText);
527
                }
528
            });
529
            return;
530
        }
531
        JToolBarButton btn = new JToolBarButton(action.getIcon());
532
        btn.setMargin(new Insets(0, 0, 0, 0));
533
        btn.addMouseListener(tooltipListener);
534
        btn.addActionListener(this);
535
        btn.setFocusable(false);
536
        btn.setActionCommand(action.getCommand());
537
        btn.setEnabled(false);
538
        btn.setVisible(false);
539
        btn.setName(action.getName());
540
        if( useText ) {
541
            btn.setText(action.getLabel());
542
        }
543
        if ( action.getTooltip() != null ) {
544
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
545
            btn.setToolTipKey(action.getTooltip());
546
        }
547

    
548
        SelectableToolBar jtb = getToolBar(toolBarName, action.getPluginName());
549
        jtb.add(btn);
550

    
551
        addControl(btn);
552

    
553
    }
554

    
555
    public void addSelectableTool(final ActionInfo action, final String toolBarName, final String groupName, final boolean useText) {
556
        I18nManager i18nManager = ToolsLocator.getI18nManager();
557

    
558
        if ( !SwingUtilities.isEventDispatchThread() ) {
559
            SwingUtilities.invokeLater(new Runnable() {
560
                public void run() {
561
                    addSelectableTool(action, toolBarName,groupName,useText);
562
                }
563
            });
564
            return;
565
        }
566

    
567
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
568
        if ( group == null ) {
569
            group = new ButtonGroup();
570
            buttonGroupMap.put(groupName, group);
571
        }
572
        ToggleButtonModel buttonModel = new ToggleButtonModel();
573
        buttonModel.setGroupName(groupName);
574

    
575
        JToolBarToggleButton btn = new JToolBarToggleButton(action.getIcon());
576
        btn.setModel(buttonModel);
577
        btn.setMargin(new Insets(0, 0, 0, 0));
578
        btn.addMouseListener(tooltipListener);
579
        btn.addActionListener(this);
580
        btn.setFocusable(false);
581
        btn.setActionCommand(action.getCommand());
582
        btn.setEnabled(false);
583
        btn.setVisible(false);
584
        btn.setName(action.getName());
585
        if( useText ) {
586
            btn.setText(action.getLabel());
587
        }
588
        if ( action.getTooltip() != null ) {
589
            btn.setToolTip(i18nManager.getTranslation(action.getTooltip()));
590
            btn.setToolTipKey(action.getTooltip());
591
        }
592

    
593
        SelectableToolBar jtb = getToolBar(toolBarName, action.getPluginName());
594
        jtb.addButton(group, btn);
595

    
596
        addControl(btn);
597

    
598
    }
599

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

    
620
    private JMenu createMenuAncestors(String text) {
621
        I18nManager i18nManager = ToolsLocator.getI18nManager();
622

    
623
        MenuElement menuPadre = null;
624

    
625
        String[] menues = text.split("/");
626
        List menuList = new ArrayList();
627
        menuList.add(menues[0]);
628
        menuPadre = getMenu(menuList, menuBar);
629

    
630
        JMenu padre = null;
631

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

    
645
        // Se crea el resto de menus
646
        ArrayList temp = new ArrayList();
647

    
648
        for ( int i = 1; i < (menues.length - 1); i++ ) {
649
            temp.add(menues[i]);
650
        }
651

    
652
        menuPadre = createMenus(temp, padre);
653

    
654
        return (JMenu) menuPadre;
655
    }
656

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

    
695
        if ( menu.getIs_separator() ) {
696
            menuPadre.addSeparator();
697
            return;
698
        }
699

    
700
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
701
        nuevoMenu.addMouseListener(tooltipListener);
702
        menuPadre.add(nuevoMenu);
703
        addControl(nuevoMenu);
704

    
705
    }
706

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

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

    
736
            for ( int i = 0; i < parentItem.getMenuComponentCount(); i++ ) {
737

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

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

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

    
799
    /**
800
     * @param menuComponent
801
     * @param nombres
802
     * @return
803
     */
804
    private boolean lastMenuItemWithoutName(Component mc, List names) {
805

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

    
828
    private class JMenuTraslatable extends JMenu implements TranslatableButton {
829

    
830
        private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
831

    
832
        public JMenuTraslatable(String text) {
833
            super(text);
834
        }
835

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

    
840
        public void setToolTipKey(String key) {
841
            this.i18nHelper.setTooltip(key);
842
        }
843

    
844
        public void translate() {
845
            if ( this.i18nHelper.needTranslation() ) {
846
                this.i18nHelper.translate();
847
                this.setText(this.i18nHelper.getText());
848
            }
849
        }
850

    
851
    }
852

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

    
877
        // si no quedan nombres de menu por crear se vuelve: caso base
878
        if ( nombres.isEmpty() ) {
879
            return padre;
880
        }
881

    
882
        // Se busca el menu por si ya existiera para no crearlo otra vez
883
        JMenu buscado = null;
884

    
885
        for ( int i = 0; i < padre.getMenuComponentCount(); i++ ) {
886
            try {
887
                JMenu hijo = (JMenu) padre.getMenuComponent(i);
888

    
889
                if ( hijo.getName().compareTo((String) nombres.get(0)) == 0 ) {
890
                    buscado = hijo;
891
                }
892
            } catch (ClassCastException e) {
893
                /*
894
                 * Se ha encontrado un elemento hoja del arbol de men�es
895
                 */
896
            }
897
        }
898

    
899
        if ( buscado != null ) {
900
            // Si lo hemos encontrado creamos el resto
901
            nombres.remove(0);
902

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

    
914
            nombres.remove(0);
915

    
916
            return createMenus(nombres, menuPadre);
917
        }
918
    }
919

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

    
931
        int toolHeight = 0;
932

    
933
        for ( int i = 0; i < toolBars.getComponentCount(); i++ ) {
934
            Component c = toolBars.getComponent(i);
935

    
936
            if ( !c.isVisible() ) {
937
                continue;
938
            }
939

    
940
            double width = c.getPreferredSize().getWidth();
941
            acum = acum + width;
942

    
943
            if ( acum > this.getWidth() ) {
944
                numFilas++;
945
                acum = width + margen;
946
            }
947

    
948
            if ( c.getPreferredSize().getHeight() > toolHeight ) {
949
                toolHeight = c.getPreferredSize().height;
950
            }
951
        }
952

    
953
        toolBars.setPreferredSize(new Dimension(this.getWidth(),
954
                (numFilas * toolHeight)));
955

    
956
        toolBars.updateUI();
957
    }
958

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

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

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

    
981
        String actionName = "(unknow)";
982
        try {
983
            JComponent control = (JComponent) e.getSource();
984
            actionName = control.getName();
985

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

    
1006
        } catch (Throwable ex) {
1007
            logger.error("Can't perform action '" + actionName + "'.", ex);
1008
        }
1009

    
1010
        enableControls();
1011
        showMemory();
1012
    }
1013

    
1014
    private String getName(String name, PluginClassLoader loader) {
1015
        if ( name.indexOf('.') == -1 ) {
1016
            return loader.getPluginName() + "." + name;
1017
        } else {
1018
            return name;
1019
        }
1020
    }
1021

    
1022
    public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) {
1023
        if ( !SwingUtilities.isEventDispatchThread() ) {
1024
            throw new RuntimeException("No Event Dispatch Thread");
1025
        }
1026

    
1027
        String name = getName(menu.getName(), loader);
1028

    
1029
        // Se crea el control popupmenu
1030
        JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name);
1031

    
1032
        if ( popupMenu == null ) {
1033
            popupMenu = new JPopUpMenu(menu.getName());
1034
            popupMap.put(name, popupMenu);
1035
        }
1036

    
1037
        Menu[] menues = menu.getMenu();
1038
        for ( int i = 0; i < menues.length; i++ ) {
1039
            JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
1040
            popupMenu.add(nuevoMenu);
1041
        }
1042
    }
1043

    
1044
    private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) {
1045
        JMenuItem nuevoMenu = null;
1046

    
1047
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1048

    
1049
        String text = menu.getText();
1050
        int n = text.lastIndexOf('/');
1051
        if ( n >= 0 ) {
1052
            text = text.substring(n + 1);
1053
        }
1054
        String translatedText = i18nManager.getTranslation(text);
1055

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

    
1071
        if ( menu.getKey() != null ) {
1072
            nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey()));
1073
        }
1074

    
1075
        nuevoMenu.setActionCommand(menu.getActionCommand());
1076

    
1077
        if ( menu.getTooltip() != null ) {
1078
            nuevoMenu.setToolTip(i18nManager.getTranslation(menu.getTooltip()));
1079
            nuevoMenu.setToolTipKey(menu.getTooltip());
1080
        }
1081

    
1082
        if ( menu.getEnableText() != null ) {
1083
            nuevoMenu.setEnableText(i18nManager.getTranslation(menu.getEnableText()));
1084
        }
1085

    
1086
        nuevoMenu.setEnabled(true);
1087
        nuevoMenu.setVisible(true);
1088

    
1089
        if ( menu.getName() != null ) {
1090
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1091
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1092
            if ( actionInfo != null ) {
1093
                nuevoMenu.addActionListener(actionInfo);
1094
            }
1095
        }
1096
        return nuevoMenu;
1097
    }
1098

    
1099
    private JMenuItem createJMenuItem(ActionInfo action, String text) {
1100
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1101
        String label = null;
1102

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

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

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

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

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

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

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

    
1169
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1170

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

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

    
1181
        c.addMouseListener(new MouseAdapter() {
1182

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

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

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

    
1215
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1216
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1217

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

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

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

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

    
1302
        // hide the toolbars that don't contain any visible tool
1303
        Iterator it = toolBarMap.values().iterator();
1304

    
1305
        while ( it.hasNext() ) {
1306
            JComponent t = (JComponent) it.next();
1307
            boolean todosOcultos = true;
1308

    
1309
            for ( int i = 0; i < t.getComponentCount(); i++ ) {
1310
                if ( !(t.getComponent(i) instanceof JSeparator) // separators
1311
                        // don't matter
1312
                        && t.getComponent(i).isVisible() ) {
1313
                    todosOcultos = false;
1314
                }
1315
            }
1316

    
1317
            if ( todosOcultos ) {
1318
                t.setVisible(false);
1319
            } else {
1320
                if ( t instanceof SelectableToolBar ) {
1321
                    t.setVisible(((SelectableToolBar) t).getAndamiVisibility());
1322
                } else {
1323
                    t.setVisible(true);
1324
                }
1325
            }
1326
        }
1327

    
1328
        if ( mdiManager != null ) {
1329
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1330

    
1331
            if ( f != null ) {
1332
                if ( lastLabelClass != f.getClass() ) {
1333
                    lastLabelClass = f.getClass();
1334

    
1335
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1336

    
1337
                    if ( lbls != null ) {
1338
                        bEstado.setLabelSet(lbls);
1339
                    }
1340
                }
1341
            }
1342
        }
1343

    
1344
        ajustarToolBar();
1345

    
1346
        showMemory();
1347
    }
1348

    
1349
    public synchronized void refreshControls() {
1350
        if ( !SwingUtilities.isEventDispatchThread() ) {
1351
            SwingUtilities.invokeLater(new Runnable() {
1352
                public void run() {
1353
                    refreshControls();
1354
                }
1355
            });
1356
            return;
1357
        }
1358

    
1359
        if(refreshingControls){
1360
            return;
1361
        }
1362
        try {
1363
        refreshingControls = true;
1364
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1365
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1366
        IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1367

    
1368
        Iterator e = controlsIterator();
1369

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

    
1393
        enableControls();
1394
        } finally {
1395
            refreshingControls = false;
1396
        }
1397
    }
1398

    
1399
    @Override
1400
    public void message(String msg, int messageTyoe) {
1401
        this.getStatusBar().message(msg, messageTyoe);
1402
    }
1403

    
1404
    /**
1405
     * Establece la visibilidad de un menu y todos sus descendientes en la
1406
     * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
1407
     *
1408
     * @param menu
1409
     * Menu que se quiere visualizar
1410
     *
1411
     * @return Devuelve true si el menu es visible y false en caso contrario
1412
     */
1413
    private boolean hideMenus(MenuElement menu) {
1414
        MenuElement[] submenus = menu.getSubElements();
1415

    
1416
        // Si no tiene hijos se devuelve su visibilidad
1417
        if ( submenus.length == 0 ) {
1418
            return menu.getComponent().isVisible();
1419
        }
1420

    
1421
        /*
1422
         * Si tiene hijos se devuelve true si alg�no de ellos es visible,
1423
         * pero se itera por todos ellos
1424
         */
1425
        boolean visible = false;
1426

    
1427
        for ( int i = 0; i < submenus.length; i++ ) {
1428
            if ( hideMenus(submenus[i]) ) {
1429
                if ( !(menu instanceof JPopupMenu) ) {
1430
                    menu.getComponent().setVisible(true);
1431
                }
1432

    
1433
                visible = true;
1434
            }
1435
        }
1436

    
1437
        if ( visible ) {
1438
            return true;
1439
        }
1440

    
1441
        menu.getComponent().setVisible(false);
1442

    
1443
        return false;
1444
    }
1445

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

    
1460
        allowSeparator = false; // separator not allowed as very first menu item
1461
        Component[] comps = ((JMenu) menu).getMenuComponents();
1462
        if ( comps.length < 1 ) {
1463
            // zero-length menu: skip
1464
            return;
1465
        }
1466

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

    
1531
    /**
1532
     * Helper functios for assigning a unique mnemomic char from
1533
     * a pool of unassigned onces, stored in the array "mnemomnics"
1534
     */
1535
    private char getMnemonic(String text, char[] mnemonics) {
1536
        if( text==null ) {
1537
            return ' ';
1538
        }
1539
        Vector words = new Vector();
1540
        StringTokenizer t = new StringTokenizer(text);
1541
        int maxsize = 0;
1542

    
1543
        while ( t.hasMoreTokens() ) {
1544
            String word = t.nextToken();
1545
            if ( word.length() > maxsize ) {
1546
                maxsize = word.length();
1547
            }
1548
            words.addElement(word);
1549
        }
1550
        words.trimToSize();
1551

    
1552
        for ( int i = 0; i < maxsize; ++i ) {
1553
            char mnemonic = getMnemonic(words, mnemonics, i);
1554
            if ( ' ' != mnemonic ) {
1555
                return mnemonic;
1556
            }
1557
        }
1558

    
1559
        return ' ';
1560
    }
1561

    
1562
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1563
        int numwords = words.size();
1564

    
1565
        for ( int i = 0; i < numwords; ++i ) {
1566
            String word = (String) words.elementAt(i);
1567
            if ( index >= word.length() ) {
1568
                continue;
1569
            }
1570

    
1571
            char c = word.charAt(index);
1572
            if ( !isMnemonicExists(c, mnemonics) ) {
1573
                /* pick only valid chars */
1574
                if ( (c != ':') && (c != '.') && (c != ',') && (c != ';')
1575
                        && (c != '-') && (c != '+') && (c != '/') && (c != '\\')
1576
                        && (c != '\'') && (c != '\"') && (c != ' ') && (c != '=')
1577
                        && (c != '(') && (c != ')') && (c != '[') && (c != ']')
1578
                        && (c != '{') && (c != '}') && (c != '$') && (c != '*')
1579
                        && (c != '&') && (c != '%') && (c != '!') && (c != '?')
1580
                        && (c != '#') && (c != '~') && (c != '_') ) {
1581
                    return c;
1582
                }
1583
            }
1584
        }
1585
        return ' ';
1586
    }
1587

    
1588
    private boolean isMnemonicExists(char c, char[] mnemonics) {
1589
        int num = mnemonics.length;
1590
        for ( int i = 0; i < num; ++i ) {
1591
            if ( mnemonics[i] == c ) {
1592
                return true;
1593
            }
1594
        }
1595
        return false;
1596
    }
1597

    
1598
    /**
1599
     * Muestra la memoria consumida por el programa
1600
     */
1601
    private void showMemory() {
1602
        Runtime r = Runtime.getRuntime();
1603
        long mem = r.totalMemory() - r.freeMemory();
1604
        logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem
1605
                / 1024 + " KB");
1606
    }
1607

    
1608
    public MDIManager getMDIManager() {
1609
        return mdiManager;
1610
    }
1611

    
1612
    public NewStatusBar getStatusBar() {
1613
        return bEstado;
1614
    }
1615

    
1616
    /**
1617
     * You can use this function to select the appropiate
1618
     * tool inside the toolbars
1619
     */
1620
    public void setSelectedTool(String actionCommand) {
1621
        setSelectedTool(defaultGroup, actionCommand);
1622
    }
1623

    
1624
    /**
1625
     * You can use this function to select the appropiate
1626
     * tool inside the toolbars
1627
     */
1628
    public void setSelectedTool(String groupName, String actionCommand) {
1629
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1630
        if ( group == null ) {
1631
            return;
1632
        }
1633

    
1634
        Enumeration enumeration = group.getElements();
1635
        while ( enumeration.hasMoreElements() ) {
1636
            AbstractButton button = (AbstractButton) enumeration.nextElement();
1637
            if ( button.getActionCommand().equals(actionCommand) ) {
1638
                button.setSelected(true);
1639
            }
1640
        }
1641

    
1642
        selectedTool.put(groupName, actionCommand);
1643
    }
1644

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

    
1678
    /**
1679
     * DOCUMENT ME!
1680
     *
1681
     * @param clase
1682
     * @param label
1683
     */
1684
    public void setStatusBarLabels(Class<?> clase, Label[] label) {
1685
        classLabels.put(clase, label);
1686
    }
1687

    
1688
    public void removeStatusBarLabels(Class<?> clase) {
1689
        classLabels.remove(clase);
1690
    }
1691

    
1692
    public void addStatusBarControl(Class<?> extensionClass, IControl control) {
1693
        control.addActionListener(this);
1694
        bEstado.addControl(control.getName(), (Component) control);
1695
        if ( control instanceof JComponent ) {
1696
            addControl((JComponent) control);
1697
            PluginsManager pluginsManager = PluginsLocator.getManager();
1698
            IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1699
            this.control2extensions.put((JComponent)control, extension);
1700
        }
1701
    }
1702

    
1703
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1704
        toolBars.add(control);
1705
        addControl(control);
1706

    
1707
        PluginsManager pluginsManager = PluginsLocator.getManager();
1708
        IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1709
        this.control2extensions.put(control, extension);
1710
    }
1711

    
1712
    public void removeStatusBarControl(String name) {
1713
        Component c = bEstado.removeControl(name);
1714
        if ( c instanceof JComponent ) {
1715
            removeControl((JComponent) c);
1716
        }
1717
    }
1718

    
1719
    public void removeMenu(Menu menu) {
1720
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1721

    
1722
        if ( delete == null ) {
1723
            throw new NoSuchElementException(menu.getText());
1724
        }
1725

    
1726
        delete.getParent().remove(delete);
1727
        infoCodedMenus.remove(menu);
1728
    }
1729

    
1730
    public void addMenu(Menu menu, ActionListener listener,
1731
            PluginClassLoader loader) {
1732
        JMenu menuPadre = createMenuAncestors(menu, loader);
1733

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

    
1758
        }
1759
        menuPadre.add(nuevoMenu);
1760

    
1761
        infoCodedMenus.put(menu, nuevoMenu);
1762
    }
1763

    
1764
    public void changeMenuName(String[] menu, String newName,
1765
            PluginClassLoader loader) {
1766

    
1767
        ArrayList menuList = new ArrayList();
1768
        for ( int i = 0; i < menu.length; i++ ) {
1769
            menuList.add(menu[i]);
1770
        }
1771

    
1772
        javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1773
        if ( newMenu == null ) {
1774
            throw new NoSuchMenuException(menu[0]);
1775
        } else {
1776
            newMenu.setText(PluginServices.getText(this, newName));
1777
        }
1778
    }
1779

    
1780
    public void componentHidden(ComponentEvent arg0) {
1781
    }
1782

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

    
1786
    public void componentResized(ComponentEvent arg0) {
1787
        ajustarToolBar();
1788
    }
1789

    
1790
    public void componentShown(ComponentEvent arg0) {
1791
    }
1792

    
1793
    public void componentAdded(ContainerEvent arg0) {
1794
        ajustarToolBar();
1795
    }
1796

    
1797
    public void componentRemoved(ContainerEvent arg0) {
1798
        ajustarToolBar();
1799
    }
1800

    
1801
    public class TooltipListener extends MouseAdapter {
1802

    
1803
        @Override
1804
        public void mouseEntered(MouseEvent e) {
1805
            JComponent control = (JComponent) e.getSource();
1806
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1807

    
1808
            String texto = null;
1809
            texto = control.getToolTipText();
1810

    
1811
            if ( texto != null ) {
1812
                bEstado.setInfoTextTemporal(texto);
1813
            }
1814
        }
1815

    
1816
        @Override
1817
        public void mouseExited(MouseEvent arg0) {
1818
            bEstado.restaurarTexto();
1819
        }
1820

    
1821
        @Override
1822
        public void mousePressed(MouseEvent e) {
1823
            bEstado.restaurarTexto();
1824
        }
1825
    }
1826

    
1827
    public String getTitlePrefix() {
1828
        return titlePrefix;
1829
    }
1830

    
1831
    public void setTitlePrefix(String titlePrefix) {
1832
        this.titlePrefix = titlePrefix;
1833
    }
1834

    
1835
    public Map getSelectedTools() {
1836
        return selectedTool;
1837
    }
1838

    
1839
    public HashMap getInitialSelectedTools() {
1840
        return initialSelectedTools;
1841
    }
1842

    
1843
    /**
1844
     * Get a previously added JComponent by name.
1845
     * For example you can use it if you need to obtain a JToolBar to
1846
     * add some customized component.
1847
     *
1848
     * @param name
1849
     * @return the JComponent or null if none has been found
1850
     */
1851
    public JComponent getComponentByName(String name) {
1852
        Iterator e = controlsIterator();
1853

    
1854
        while ( e.hasNext() ) {
1855
            JComponent control = (JComponent) e.next();
1856
            String nameCtrl = control.getName();
1857
            if ( nameCtrl != null ) {
1858
                if ( nameCtrl.compareTo(name) == 0 ) {
1859
                    return control;
1860
                }
1861
            }
1862
        }
1863
        Iterator it = toolBarMap.values().iterator();
1864
        while ( it.hasNext() ) {
1865
            JComponent t = (JComponent) it.next();
1866
            String nameCtrl = t.getName();
1867
            if ( nameCtrl != null ) {
1868
                if ( nameCtrl.compareTo(name) == 0 ) {
1869
                    return t;
1870
                }
1871
            }
1872

    
1873
        }
1874

    
1875
        return null;
1876
    }
1877

    
1878
    public SelectableToolBar[] getToolbars() {
1879
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1880
                new SelectableToolBar[0]);
1881
    }
1882

    
1883
    public boolean getToolbarVisibility(String name) {
1884
        JComponent component
1885
                = PluginServices.getMainFrame().getComponentByName(name);
1886
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1887
            SelectableToolBar toolBar = (SelectableToolBar) component;
1888
            return toolBar.getAndamiVisibility();
1889
        }
1890
        return false;
1891
    }
1892

    
1893
    public boolean setToolbarVisibility(String name, boolean visibility) {
1894
        JComponent component
1895
                = PluginServices.getMainFrame().getComponentByName(name);
1896
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1897
            SelectableToolBar toolBar = (SelectableToolBar) component;
1898
            boolean oldVisibility = toolBar.getAndamiVisibility();
1899
            toolBar.setAndamiVisibility(visibility);
1900
            enableControls();
1901
            return oldVisibility;
1902
        }
1903
        return false;
1904
    }
1905

    
1906
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1907
        ArrayList menu = new ArrayList();
1908
        for ( int i = 0; i < menuPath.length; i++ ) {
1909
            menu.add(menuPath[i]);
1910
        }
1911
        return getMenu(menu, menuBar);
1912
    }
1913

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

    
1919
    public void messageDialog(String message, String[] messageArgs,
1920
            String title, int messageType) {
1921
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1922
        helper.messageDialog(message, messageArgs, title, messageType);
1923
    }
1924

    
1925
    @Override
1926
    public void messageDialog(String message, String[] messageArgs,
1927
            String title, int messageType, String msgid) {
1928
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1929
        helper.messageDialog(message, messageArgs, title, messageType, msgid);
1930
    }
1931

    
1932
    @Override
1933
    public int confirmDialog(String message, String title, int optionType,
1934
            int messageType) {
1935
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1936
        return helper.confirmDialog(message, title, optionType, messageType);
1937
    }
1938

    
1939
    
1940
    @Override
1941
    public int confirmDialog(String message, String title, int optionType,
1942
            int messageType, String msgid) {
1943
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1944
        return helper.confirmDialog(message, title, optionType, messageType, msgid);
1945
    }
1946

    
1947
    @Override
1948
    public String inputDialog(String message, String title, int messageType,
1949
            String initialValue) {
1950
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1951
        return helper.inputDialog(message, title, messageType, initialValue);
1952
    }
1953

    
1954
    @Override
1955
    public String inputDialog(String message, String title) {
1956
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1957
        return helper.inputDialog(message, title);
1958
    }
1959

    
1960
    @Override
1961
    public void showDialog(Component contents, String title) {
1962
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1963
        helper.showDialog(contents, title);
1964
    }
1965

    
1966
    @Override
1967
    public Component createComponent(Class<? extends Component> theClass,
1968
            Object... parameters) {
1969
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1970
        return helper.createComponentWithParams(theClass, parameters);
1971
    }
1972

    
1973
    @Override
1974
    public Component createComponentWithParams(
1975
            Class<? extends Component> theClass, Object[] parameters) {
1976
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1977
        return helper.createComponentWithParams(theClass, parameters);
1978
    }
1979

    
1980
    @Override
1981
    public File[] showChooserDialog(
1982
            final String title,
1983
            final int type, // SAVE_DIALOG / OPEN_DIALOG
1984
            final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
1985
            final boolean multiselection,
1986
            final File initialPath,
1987
            final FileFilter filter,
1988
            final boolean fileHidingEnabled
1989
    ) {
1990
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1991
        return helper.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
1992
    }
1993

    
1994
    @Override
1995
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1996
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1997
    }
1998

    
1999
    @Override
2000
    public File[] showOpenFileDialog(String title, File initialPath) {
2001
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
2002
    }
2003

    
2004
    @Override
2005
    public File[] showSaveFileDialog(String title, File initialPath) {
2006
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
2007
    }
2008
        
2009
    private void addControl(JComponent control) {
2010
        controls.add(control);
2011
    }
2012

    
2013
    private void removeControl(JComponent control) {
2014
        controls.remove(control);
2015
    }
2016

    
2017
    private Iterator<JComponent> controlsIterator() {
2018
        return this.controls.iterator();
2019
    }
2020

    
2021
    @Override
2022
    public void setLocale(Locale locale) {
2023
        super.setLocale(locale); //To change body of generated methods, choose Tools | Templates.
2024
        MDIManager mdiManager = MDIManagerFactory.createManager();
2025
        mdiManager.setLocale(locale);
2026
        if ( this.controls != null && !this.controls.isEmpty() ) {
2027
            this.refreshControls();
2028
        }
2029
    }
2030

    
2031
}