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

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

    
73
import org.gvsig.andami.IconThemeHelper;
74
import org.gvsig.andami.Launcher;
75
import org.gvsig.andami.PluginServices;
76
import org.gvsig.andami.PluginsLocator;
77
import org.gvsig.andami.PluginsManager;
78
import org.gvsig.andami.actioninfo.ActionInfo;
79
import org.gvsig.andami.actioninfo.ActionInfoManager;
80
import org.gvsig.andami.actioninfo.ActionInfoStatusCache;
81
import org.gvsig.andami.messages.Messages;
82
import org.gvsig.andami.plugins.ExtensionDecorator;
83
import org.gvsig.andami.plugins.IExtension;
84
import org.gvsig.andami.plugins.PluginClassLoader;
85
import org.gvsig.andami.plugins.config.generate.ActionTool;
86
import org.gvsig.andami.plugins.config.generate.Label;
87
import org.gvsig.andami.plugins.config.generate.Menu;
88
import org.gvsig.andami.plugins.config.generate.PopupMenu;
89
import org.gvsig.andami.plugins.config.generate.SelectableTool;
90
import org.gvsig.andami.plugins.config.generate.SkinExtensionType;
91
import org.gvsig.andami.plugins.config.generate.ToolBar;
92
import org.gvsig.andami.ui.mdiFrame.TranslatableButtonHelper.TranslatableButton;
93
import org.gvsig.andami.ui.mdiManager.MDIManager;
94
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
95
import org.gvsig.gui.beans.controls.IControl;
96
import org.gvsig.tools.ToolsLocator;
97
import org.gvsig.tools.i18n.I18nManager;
98
import org.gvsig.tools.swing.api.ToolsSwingLocator;
99
import org.gvsig.tools.swing.icontheme.IconTheme;
100
import org.slf4j.Logger;
101
import org.slf4j.LoggerFactory;
102

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

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

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

    
118
    private static MDIFrame instance = null;
119

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

    
122
    private boolean refreshingControls = false;
123

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

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

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

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

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

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

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

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

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

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

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

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

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

    
203
    private HashMap infoCodedMenus = new HashMap();
204

    
205
    private String titlePrefix;
206

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

    
209
    private MDIFrame() {
210

    
211
    }
212

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

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

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

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

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

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

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

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

    
262
        // Add the status bar of the application
263
        bEstado = new NewStatusBar();
264
        bEstado.message(Messages.getString("StatusBar.Aplicacion_iniciada"), JOptionPane.INFORMATION_MESSAGE);
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
            ActionInfo action = actionManager.getAction(actionName);
1225
            try {
1226
                boolean enabled = false;
1227
                boolean visible = false;
1228

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

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

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

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

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

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

    
1325
        if ( mdiManager != null ) {
1326
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1327

    
1328
            if ( f != null ) {
1329
                if ( lastLabelClass != f.getClass() ) {
1330
                    lastLabelClass = f.getClass();
1331

    
1332
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1333

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

    
1341
        ajustarToolBar();
1342

    
1343
        showMemory();
1344
    }
1345

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

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

    
1365
        Iterator e = controlsIterator();
1366

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

    
1390
        enableControls();
1391
        } finally {
1392
            refreshingControls = false;
1393
        }
1394
    }
1395

    
1396
    public void message(String msg, int messageTyoe) {
1397
        this.getStatusBar().message(msg, messageTyoe);
1398
    }
1399

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

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

    
1417
        /*
1418
         * Si tiene hijos se devuelve true si alg�no de ellos es visible,
1419
         * pero se itera por todos ellos
1420
         */
1421
        boolean visible = false;
1422

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

    
1429
                visible = true;
1430
            }
1431
        }
1432

    
1433
        if ( visible ) {
1434
            return true;
1435
        }
1436

    
1437
        menu.getComponent().setVisible(false);
1438

    
1439
        return false;
1440
    }
1441

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

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

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

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

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

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

    
1555
        return ' ';
1556
    }
1557

    
1558
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1559
        int numwords = words.size();
1560

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

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

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

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

    
1604
    public MDIManager getMDIManager() {
1605
        return mdiManager;
1606
    }
1607

    
1608
    public NewStatusBar getStatusBar() {
1609
        return bEstado;
1610
    }
1611

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

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

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

    
1638
        selectedTool.put(groupName, actionCommand);
1639
    }
1640

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

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

    
1684
    public void removeStatusBarLabels(Class<?> clase) {
1685
        classLabels.remove(clase);
1686
    }
1687

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

    
1699
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1700
        toolBars.add(control);
1701
        addControl(control);
1702

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

    
1708
    public void removeStatusBarControl(String name) {
1709
        Component c = bEstado.removeControl(name);
1710
        if ( c instanceof JComponent ) {
1711
            removeControl((JComponent) c);
1712
        }
1713
    }
1714

    
1715
    public void removeMenu(Menu menu) {
1716
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1717

    
1718
        if ( delete == null ) {
1719
            throw new NoSuchElementException(menu.getText());
1720
        }
1721

    
1722
        delete.getParent().remove(delete);
1723
        infoCodedMenus.remove(menu);
1724
    }
1725

    
1726
    public void addMenu(Menu menu, ActionListener listener,
1727
            PluginClassLoader loader) {
1728
        JMenu menuPadre = createMenuAncestors(menu, loader);
1729

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

    
1754
        }
1755
        menuPadre.add(nuevoMenu);
1756

    
1757
        infoCodedMenus.put(menu, nuevoMenu);
1758
    }
1759

    
1760
    public void changeMenuName(String[] menu, String newName,
1761
            PluginClassLoader loader) {
1762

    
1763
        ArrayList menuList = new ArrayList();
1764
        for ( int i = 0; i < menu.length; i++ ) {
1765
            menuList.add(menu[i]);
1766
        }
1767

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

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

    
1779
    public void componentMoved(ComponentEvent arg0) {
1780
    }
1781

    
1782
    public void componentResized(ComponentEvent arg0) {
1783
        ajustarToolBar();
1784
    }
1785

    
1786
    public void componentShown(ComponentEvent arg0) {
1787
    }
1788

    
1789
    public void componentAdded(ContainerEvent arg0) {
1790
        ajustarToolBar();
1791
    }
1792

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

    
1797
    public class TooltipListener extends MouseAdapter {
1798

    
1799
        @Override
1800
        public void mouseEntered(MouseEvent e) {
1801
            JComponent control = (JComponent) e.getSource();
1802
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1803

    
1804
            String texto = null;
1805
            texto = control.getToolTipText();
1806

    
1807
            if ( texto != null ) {
1808
                bEstado.setInfoTextTemporal(texto);
1809
            }
1810
        }
1811

    
1812
        @Override
1813
        public void mouseExited(MouseEvent arg0) {
1814
            bEstado.restaurarTexto();
1815
        }
1816

    
1817
        @Override
1818
        public void mousePressed(MouseEvent e) {
1819
            bEstado.restaurarTexto();
1820
        }
1821
    }
1822

    
1823
    public String getTitlePrefix() {
1824
        return titlePrefix;
1825
    }
1826

    
1827
    public void setTitlePrefix(String titlePrefix) {
1828
        this.titlePrefix = titlePrefix;
1829
    }
1830

    
1831
    public Map getSelectedTools() {
1832
        return selectedTool;
1833
    }
1834

    
1835
    public HashMap getInitialSelectedTools() {
1836
        return initialSelectedTools;
1837
    }
1838

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

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

    
1869
        }
1870

    
1871
        return null;
1872
    }
1873

    
1874
    public SelectableToolBar[] getToolbars() {
1875
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1876
                new SelectableToolBar[0]);
1877
    }
1878

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

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

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

    
1910
    public void messageDialog(String message, String title, int messageType) {
1911
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1912
        helper.messageDialog(message, title, messageType);
1913
    }
1914

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

    
1921
    @Override
1922
    public void messageDialog(String message, String[] messageArgs,
1923
            String title, int messageType, String msgid) {
1924
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1925
        helper.messageDialog(message, messageArgs, title, messageType, msgid);
1926
    }
1927

    
1928
    @Override
1929
    public int confirmDialog(String message, String title, int optionType,
1930
            int messageType) {
1931
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1932
        return helper.confirmDialog(message, title, optionType, messageType);
1933
    }
1934

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

    
1942
    @Override
1943
    public String inputDialog(String message, String title, int messageType,
1944
            String initialValue) {
1945
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1946
        return helper.inputDialog(message, title, messageType, initialValue);
1947
    }
1948

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

    
1955
    @Override
1956
    public void showDialog(Component contents, String title) {
1957
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1958
        helper.showDialog(contents, title);
1959
    }
1960

    
1961
    @Override
1962
    public Component createComponent(Class<? extends Component> theClass,
1963
            Object... parameters) {
1964
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1965
        return helper.createComponentWithParams(theClass, parameters);
1966
    }
1967

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

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

    
1989
    @Override
1990
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1991
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1992
    }
1993

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

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

    
2004
    private void addControl(JComponent control) {
2005
        controls.add(control);
2006
    }
2007

    
2008
    private void removeControl(JComponent control) {
2009
        controls.remove(control);
2010
    }
2011

    
2012
    private Iterator<JComponent> controlsIterator() {
2013
        return this.controls.iterator();
2014
    }
2015

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

    
2026
}