Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / MDIFrame.java @ 43888

History | View | Annotate | Download (70.6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami.ui.mdiFrame;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.awt.Dimension;
29
import java.awt.FlowLayout;
30
import java.awt.Insets;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.ComponentEvent;
34
import java.awt.event.ComponentListener;
35
import java.awt.event.ContainerEvent;
36
import java.awt.event.ContainerListener;
37
import java.awt.event.MouseAdapter;
38
import java.awt.event.MouseEvent;
39
import java.awt.event.WindowAdapter;
40
import java.awt.event.WindowEvent;
41
import java.io.File;
42
import java.util.ArrayList;
43
import java.util.Enumeration;
44
import java.util.HashMap;
45
import java.util.Iterator;
46
import java.util.List;
47
import java.util.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
        bEstado.message(Messages.getString("StatusBar.Aplicacion_iniciada"), JOptionPane.INFORMATION_MESSAGE);
266
        getContentPane().add(bEstado, BorderLayout.SOUTH);
267

    
268
        this.toolBars.addContainerListener(this);
269

    
270

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

    
284
        mdiManager.init(this);
285
    }
286

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

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

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

    
368
        I18nManager i18nManager = ToolsLocator.getI18nManager();
369

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

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

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

    
394
        jtb.addButton(group, btn);
395

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

    
403
        addControl(btn);
404

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

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

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

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

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

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

    
460
        I18nManager i18nManager = ToolsLocator.getI18nManager();
461

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

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

    
477
        jtb.add(btn);
478

    
479
        addControl(btn);
480

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

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

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

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

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

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

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

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

    
552
        addControl(btn);
553

    
554
    }
555

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

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

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

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

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

    
597
        addControl(btn);
598

    
599
    }
600

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

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

    
624
        MenuElement menuPadre = null;
625

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

    
631
        JMenu padre = null;
632

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

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

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

    
653
        menuPadre = createMenus(temp, padre);
654

    
655
        return (JMenu) menuPadre;
656
    }
657

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

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

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

    
706
    }
707

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

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

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

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

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

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

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

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

    
829
    private class JMenuTraslatable extends JMenu implements TranslatableButton {
830

    
831
        private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
832

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

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

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

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

    
852
    }
853

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

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

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

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

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

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

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

    
915
            nombres.remove(0);
916

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

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

    
932
        int toolHeight = 0;
933

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

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

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

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

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

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

    
957
        toolBars.updateUI();
958
    }
959

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1048
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1049

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1182
        c.addMouseListener(new MouseAdapter() {
1183

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1345
        ajustarToolBar();
1346

    
1347
        showMemory();
1348
    }
1349

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

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

    
1369
        Iterator e = controlsIterator();
1370

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

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

    
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
    @Override
1940
    public int confirmDialog(String message, String title, int optionType,
1941
            int messageType, String msgid) {
1942
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1943
        return helper.confirmDialog(message, title, optionType, messageType, msgid);
1944
    }
1945

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

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

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

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

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

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

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

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

    
2003
    @Override
2004
    public File[] showSaveFileDialog(String title, File initialPath) {
2005
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
2006
    }
2007

    
2008
    private void addControl(JComponent control) {
2009
        controls.add(control);
2010
    }
2011

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

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

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

    
2030
}