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

History | View | Annotate | Download (67.7 KB)

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

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.awt.Dimension;
29
import java.awt.FlowLayout;
30
import java.awt.Insets;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.ComponentEvent;
34
import java.awt.event.ComponentListener;
35
import java.awt.event.ContainerEvent;
36
import java.awt.event.ContainerListener;
37
import java.awt.event.MouseAdapter;
38
import java.awt.event.MouseEvent;
39
import java.awt.event.WindowAdapter;
40
import java.awt.event.WindowEvent;
41
import java.io.File;
42
import java.util.ArrayList;
43
import java.util.Enumeration;
44
import java.util.HashMap;
45
import java.util.Iterator;
46
import java.util.List;
47
import java.util.Locale;
48
import java.util.Map;
49
import java.util.NoSuchElementException;
50
import java.util.StringTokenizer;
51
import java.util.Vector;
52

    
53
import javax.sql.rowset.spi.SyncResolver;
54
import javax.swing.AbstractButton;
55
import javax.swing.ButtonGroup;
56
import javax.swing.ImageIcon;
57
import javax.swing.JComponent;
58
import javax.swing.JFileChooser;
59
import javax.swing.JFrame;
60
import javax.swing.JMenu;
61
import javax.swing.JMenuBar;
62
import javax.swing.JOptionPane;
63
import javax.swing.JPanel;
64
import javax.swing.JPopupMenu;
65
import javax.swing.JSeparator;
66
import javax.swing.JToolBar;
67
import javax.swing.KeyStroke;
68
import javax.swing.MenuElement;
69
import javax.swing.SwingUtilities;
70
import javax.swing.Timer;
71
import javax.swing.WindowConstants;
72
import javax.swing.filechooser.FileFilter;
73

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

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

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

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

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

    
120
    private static MDIFrame instance = null;
121

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

    
124
    private boolean refreshingControls = false;
125

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

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

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

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

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

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

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

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

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

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

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

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

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

    
205
    private HashMap infoCodedMenus = new HashMap();
206

    
207
    private String titlePrefix;
208

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

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

    
213
    private MDIFrame() {
214

    
215
    }
216

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

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

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

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

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

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

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

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

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

    
271
        this.toolBars.addContainerListener(this);
272

    
273

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

    
287
        mdiManager.init(this);
288
    }
289

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

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

    
340
        I18nManager i18nManager = ToolsLocator.getI18nManager();
341

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

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

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

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

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

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

    
384
        addControl(btn);
385

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

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

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

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

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

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

    
456
        I18nManager i18nManager = ToolsLocator.getI18nManager();
457

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

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

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

    
478

    
479
        jtb.add(btn);
480

    
481
        addControl(btn);
482

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

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

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

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

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

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

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

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

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

    
560
        addControl(btn);
561

    
562
    }
563

    
564
    /**
565
     * Creates the needed menu structure to add the menu to the bar.
566
     * Returns the father which must hold the menu which was
567
     * provided as parameter.
568
     *
569
     * Crea la estructura de menus necesaria para a?adir el menu a la barra.
570
     * Devuelve el padre del cual debe colgar el menu que se pasa como
571
     * parametro.
572
     *
573
     * @param menu
574
     * The Menu whose support is going to be added
575
     * @param loader
576
     * The plugin's class loader
577
     *
578
     * @return The proper father for the menu which was provided as parameter
579
     */
580
    private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) {
581
        return createMenuAncestors(menu.getText());
582
    }
583

    
584
    private JMenu createMenuAncestors(String text) {
585
        I18nManager i18nManager = ToolsLocator.getI18nManager();
586

    
587
        MenuElement menuPadre = null;
588

    
589
        String[] menues = text.split("/");
590
        List menuList = new ArrayList();
591
        menuList.add(menues[0]);
592
        menuPadre = getMenu(menuList, menuBar);
593

    
594
        JMenu padre = null;
595

    
596
        if ( menuPadre == null ) {
597
            padre = new JMenuTraslatable(i18nManager.getTranslation(menues[0]));
598
            ((JMenuTraslatable) padre).setTextKey(menues[0]);
599
            padre.setName(menues[0]);
600
            addControl(padre);
601
            menuBar.add(padre);
602
        } else if ( menuPadre instanceof JMenu ) {
603
            padre = (JMenu) menuPadre;
604
        } else {
605
            logger.warn("Error creating menu. Ancestor does not exist (" + text + ").");
606
            return null;
607
        }
608

    
609
        // Se crea el resto de menus
610
        ArrayList temp = new ArrayList();
611

    
612
        for ( int i = 1; i < (menues.length - 1); i++ ) {
613
            temp.add(menues[i]);
614
        }
615

    
616
        menuPadre = createMenus(temp, padre);
617

    
618
        return (JMenu) menuPadre;
619
    }
620

    
621
    /**
622
     * A?ade la informacion del menu al framework.
623
     * Debido a que los men?es se
624
     * pueden introducir en un orden determinado por el usuario, pero los
625
     * plugins se instalan en un orden arbitrario, primero se almacena la
626
     * informacion de todos los menus para luego ordenarlos y posteriormente
627
     * a?adirlos al interfaz
628
     *
629
     * @param loader
630
     * Posicion del menu. Se ordena por este campo
631
     * @param ext
632
     * Array con los nombres de los padres del menu
633
     * @param menu
634
     * Texto del menu
635
     *
636
     * @throws ClassNotFoundException
637
     * @throws RuntimeException
638
     */
639
    public void addMenu(final PluginClassLoader loader, final SkinExtensionType ext,
640
            final Menu menu) throws ClassNotFoundException {
641
        if ( !SwingUtilities.isEventDispatchThread() ) {
642
            try {
643
                SwingUtilities.invokeAndWait(new Runnable() {
644
                    public void run() {
645
                        try {
646
                            addMenu(loader, ext, menu);
647
                        } catch (ClassNotFoundException ex) {
648
                            logger.warn("??? Eehh????", ex);
649
                        }
650
                    }
651
                });
652
            } catch (Exception ex) {
653
                // Do nothing
654
            }
655
            return;
656
        }
657
        JMenu menuPadre = createMenuAncestors(menu, loader);
658

    
659
        if ( menu.getIs_separator() ) {
660
            menuPadre.addSeparator();
661
            return;
662
        }
663

    
664
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
665
        nuevoMenu.addMouseListener(tooltipListener);
666
        menuPadre.add(nuevoMenu);
667
        addControl(nuevoMenu);
668

    
669
    }
670

    
671
    public void addMenu(final ActionInfo action, final String text) {
672
        if ( !SwingUtilities.isEventDispatchThread() ) {
673
            SwingUtilities.invokeLater(new Runnable() {
674
                public void run() {
675
                    addMenu(action, text);
676
                }
677
            });
678
            return;
679
        }
680
        JMenu menuPadre = createMenuAncestors(text);
681
        JMenuItem nuevoMenu = createJMenuItem(action, text);
682
        nuevoMenu.addMouseListener(tooltipListener);
683
        menuPadre.add(nuevoMenu);
684
        menuPadre.invalidate();
685
        Class<? extends IExtension> classExtension = action.getExtension().getClass();
686
        addControl(nuevoMenu);
687
    }
688

    
689
    /**
690
     * Dado lista de nombres de menu, encuentra el menu
691
     *
692
     * @param nombres
693
     * @param padre
694
     * @return
695
     */
696
    private javax.swing.JMenuItem getMenu(List nombres, MenuElement parent) {
697
        if ( parent instanceof javax.swing.JMenu ) {
698
            javax.swing.JMenu parentItem = (javax.swing.JMenu) parent;
699

    
700
            for ( int i = 0; i < parentItem.getMenuComponentCount(); i++ ) {
701

    
702
                String item_name = parentItem.getMenuComponent(i).getName();
703
                if ( ((item_name != null) && (item_name.compareTo((String) nombres.get(0)) == 0))
704
                        || /*
705
                         * We also accept "leaf menus" with no name
706
                         * (Project manager, View-1, View-2, etc)
707
                         */ lastMenuItemWithoutName(parentItem.getMenuComponent(i), nombres) ) {
708

    
709
                    nombres.remove(0);
710
                    if ( nombres.isEmpty() ) {
711
                        if ( parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem ) {
712
                            return (javax.swing.JMenuItem) parentItem
713
                                    .getMenuComponent(i);
714
                        } else {
715
                            logger.error(PluginServices.getText(this,
716
                                    "Menu_type_not_supported_")
717
                                    + " "
718
                                    + parentItem.getMenuComponent(i).getClass()
719
                                    .getName());
720
                            return null;
721
                        }
722
                    } else {
723
                        return getMenu(nombres,
724
                                (MenuElement) parentItem.getMenuComponent(i));
725
                    }
726
                }
727
            }
728
        } else if ( parent instanceof JMenuBar ) {
729
            javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent;
730

    
731
            for ( int i = 0; i < parentItem.getMenuCount(); i++ ) {
732
                if ( (parentItem.getMenu(i).getName() != null // not a
733
                        // JToolBar.Separator
734
                        )
735
                        && (parentItem.getMenu(i).getName()
736
                        .compareTo((String) nombres.get(0)) == 0) ) {
737
                    nombres.remove(0);
738
                    if ( nombres.isEmpty() ) {
739
                        if ( parentItem.getMenu(i) instanceof javax.swing.JMenuItem ) {
740
                            return parentItem.getMenu(i);
741
                        } else {
742
                            logger.error(PluginServices.getText(this,
743
                                    "Menu_type_not_supported_")
744
                                    + " "
745
                                    + parentItem.getMenu(i).getClass()
746
                                    .getName());
747
                            return null;
748
                        }
749
                    } else {
750
                        return getMenu(nombres, parentItem.getMenu(i));
751
                    }
752
                }
753
            }
754
        } else {
755
            logger.error(PluginServices.getText(this,
756
                    "Menu_type_not_supported_")
757
                    + " "
758
                    + parent.getClass().getName() + " " + parent.toString());
759
        }
760
        return null;
761
    }
762

    
763
    /**
764
     * @param menuComponent
765
     * @param nombres
766
     * @return
767
     */
768
    private boolean lastMenuItemWithoutName(Component mc, List names) {
769

    
770
        /*
771
         * names must have 1 string
772
         */
773
        if ( names == null || names.size() != 1 ) {
774
            return false;
775
        }
776
        if ( !(mc instanceof JMenuItem) ) {
777
            return false;
778
        }
779
        JMenuItem jmi = (JMenuItem) mc;
780
        if ( jmi.getName() != null ) {
781
            /*
782
             * Name must be null, so this is a menu leaf
783
             */
784
            return false;
785
        }
786
        if ( jmi.getText() == null ) {
787
            return false;
788
        }
789
        return jmi.getText().compareTo((String) names.get(0)) == 0;
790
    }
791

    
792
    private class JMenuTraslatable extends JMenu implements TranslatableButton {
793

    
794
        private TranslatableButtonHelper i18nHelper = new TranslatableButtonHelper();
795

    
796
        public JMenuTraslatable(String text) {
797
            super(text);
798
        }
799

    
800
        public void setTextKey(String key) {
801
            this.i18nHelper.setText(key);
802
        }
803

    
804
        public void setToolTipKey(String key) {
805
            this.i18nHelper.setTooltip(key);
806
        }
807

    
808
        public void translate() {
809
            if ( this.i18nHelper.needTranslation() ) {
810
                this.i18nHelper.translate();
811
                this.setText(this.i18nHelper.getText());
812
            }
813
        }
814

    
815
    }
816

    
817
    /**
818
     * Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
819
     * en el par?metro nombres el array {"Search", "References", "Workspace"}
820
     * crear? un men? Search, un submen? del anterior que se llamar?
821
     * References y debajo de ?ste ?ltimo otro menu llamado Workspace
822
     *
823
     * @param nombres
824
     * Array con los nombres de los men?s que se quieren crear
825
     * @param padre
826
     * Menu padre de los men?s creados. Es ?til porque es un
827
     * algoritmo recursivo
828
     *
829
     * @return Devuelve el men? creado. Al final de toda la recursividad,
830
     * devolver? el men? de m?s abajo en la jerarqu?a
831
     *
832
     * @throws RuntimeException
833
     */
834
    private JMenu createMenus(ArrayList nombres, JMenu padre) {
835
        if ( !SwingUtilities.isEventDispatchThread() ) {
836
            logger.warn("Este metodo requiere que se este ejecutando en el hilo de eventos de AWT.");
837
            throw new RuntimeException("No Event Dispatch Thread");
838
        }
839
        I18nManager i18nManager = ToolsLocator.getI18nManager();
840

    
841
        // si no quedan nombres de menu por crear se vuelve: caso base
842
        if ( nombres.isEmpty() ) {
843
            return padre;
844
        }
845

    
846
        // Se busca el menu por si ya existiera para no crearlo otra vez
847
        JMenu buscado = null;
848

    
849
        for ( int i = 0; i < padre.getMenuComponentCount(); i++ ) {
850
            try {
851
                JMenu hijo = (JMenu) padre.getMenuComponent(i);
852

    
853
                if ( hijo.getName().compareTo((String) nombres.get(0)) == 0 ) {
854
                    buscado = hijo;
855
                }
856
            } catch (ClassCastException e) {
857
                /*
858
                 * Se ha encontrado un elemento hoja del arbol de men?es
859
                 */
860
            }
861
        }
862

    
863
        if ( buscado != null ) {
864
            // Si lo hemos encontrado creamos el resto
865
            nombres.remove(0);
866

    
867
            return createMenus(nombres, buscado);
868
        } else {
869
            // Si no lo hemos encontrado se crea el menu, se a?ade al padre
870
            // y se crea el resto
871
            String nombre = (String) nombres.get(0);
872
            JMenuTraslatable menuPadre = new JMenuTraslatable(i18nManager.getTranslation(nombre));
873
            menuPadre.setTextKey(nombre);
874
            menuPadre.setName(nombre);
875
            addControl(menuPadre);
876
            padre.add(menuPadre);
877

    
878
            nombres.remove(0);
879

    
880
            return createMenus(nombres, menuPadre);
881
        }
882
    }
883

    
884
    /**
885
     * M?todo invocado en respuesta a ciertos eventos de la interfaz que
886
     * pueden
887
     * ocultar botones de las barras de herramientas y que redimensiona ?sta
888
     * de manera conveniente para que no se oculte ninguno
889
     */
890
    private void ajustarToolBar() {
891
        int margen = 8;
892
        int numFilas = 1;
893
        double acum = margen;
894

    
895
        int toolHeight = 0;
896

    
897
        for ( int i = 0; i < toolBars.getComponentCount(); i++ ) {
898
            Component c = toolBars.getComponent(i);
899

    
900
            if ( !c.isVisible() ) {
901
                continue;
902
            }
903

    
904
            double width = c.getPreferredSize().getWidth();
905
            acum = acum + width;
906

    
907
            if ( acum > this.getWidth() ) {
908
                numFilas++;
909
                acum = width + margen;
910
            }
911

    
912
            if ( c.getPreferredSize().getHeight() > toolHeight ) {
913
                toolHeight = c.getPreferredSize().height;
914
            }
915
        }
916

    
917
        toolBars.setPreferredSize(new Dimension(this.getWidth(),
918
                (numFilas * toolHeight)));
919

    
920
        toolBars.updateUI();
921
    }
922

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

    
926
//            Map<Class<? extends IExtension>, ExtensionDecorator> extensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
927
//            for ( Entry<Class<? extends IExtension>, ExtensionDecorator>  entry: classesExtensions.entrySet()) {
928
//                        if( ! (entry.getValue().getExtension() instanceof LibraryExtension) ) {
929
//                                extensions.put(entry.getKey(), entry.getValue());
930
//                        }
931
//                }
932
//        this.classesExtensions = extensions;
933
    }
934

    
935
    /**
936
     * Metodo de callback invocado cuando se selecciona un menu o un boton
937
     * de
938
     * la barra de herramientas. Se busca la extensi?n asociada y se ejecuta
939
     *
940
     * @param e
941
     * Evento producido
942
     */
943
    public void actionPerformed(ActionEvent e) {
944

    
945
        String actionName = "(unknow)";
946
        try {
947
            JComponent control = (JComponent) e.getSource();
948
            actionName = control.getName();
949

    
950
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
951
            ActionInfo action = actionManager.getAction(control.getName());
952
            Object args = null;
953
            if ( control instanceof IControl ) {
954
                args = ((IControl) control).getValue();
955
            }
956
            if ( args == null ) {
957
                action.execute();
958
            } else {
959
                action.execute(args);
960
            }
961
            String actionCommand = e.getActionCommand();
962
            try {
963
                JToolBarToggleButton toggle = (JToolBarToggleButton) control;
964
                ToggleButtonModel model = (ToggleButtonModel) toggle.getModel();
965
                selectedTool.put(model.getGroupName(), actionCommand);
966
            } catch (ClassCastException ex) {
967
            } catch (NullPointerException ex) {
968
            }
969

    
970
        } catch (Throwable ex) {
971
            logger.error("Can't perform action '" + actionName + "'.", ex);
972
        }
973

    
974
        enableControls();
975
        showMemory();
976
    }
977

    
978
    private String getName(String name, PluginClassLoader loader) {
979
        if ( name.indexOf('.') == -1 ) {
980
            return loader.getPluginName() + "." + name;
981
        } else {
982
            return name;
983
        }
984
    }
985

    
986
    public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) {
987
        if ( !SwingUtilities.isEventDispatchThread() ) {
988
            throw new RuntimeException("No Event Dispatch Thread");
989
        }
990

    
991
        String name = getName(menu.getName(), loader);
992

    
993
        // Se crea el control popupmenu
994
        JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name);
995

    
996
        if ( popupMenu == null ) {
997
            popupMenu = new JPopUpMenu(menu.getName());
998
            popupMap.put(name, popupMenu);
999
        }
1000

    
1001
        Menu[] menues = menu.getMenu();
1002
        for ( int i = 0; i < menues.length; i++ ) {
1003
            JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
1004
            popupMenu.add(nuevoMenu);
1005
        }
1006
    }
1007

    
1008
    private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) {
1009
        JMenuItem nuevoMenu = null;
1010

    
1011
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1012

    
1013
        String text = menu.getText();
1014
        int n = text.lastIndexOf('/');
1015
        if ( n >= 0 ) {
1016
            text = text.substring(n + 1);
1017
        }
1018
        String translatedText = i18nManager.getTranslation(text);
1019

    
1020
        IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1021
        if ( menu.getIcon() != null ) {
1022
            if ( iconTheme.exists(menu.getIcon()) ) {
1023
                ImageIcon image = iconTheme.get(menu.getIcon());
1024
                nuevoMenu = new JMenuItem(translatedText, image);
1025
            } else {
1026
                nuevoMenu = new JMenuItem(translatedText);
1027
                logger.info("menu icon '" + menu.getIcon() + "' not exists.");
1028
            }
1029
        } else {
1030
            nuevoMenu = new JMenuItem(translatedText);
1031
        }
1032
        nuevoMenu.setTextKey(text);
1033
        nuevoMenu.setName(menu.getName());
1034

    
1035
        if ( menu.getKey() != null ) {
1036
            nuevoMenu.setAccelerator(KeyMapping.getKeyStroke(menu.getKey()));
1037
        }
1038

    
1039
        nuevoMenu.setActionCommand(menu.getActionCommand());
1040

    
1041
        if ( menu.getTooltip() != null ) {
1042
            nuevoMenu.setToolTip(i18nManager.getTranslation(menu.getTooltip()));
1043
            nuevoMenu.setToolTipKey(menu.getTooltip());
1044
        }
1045

    
1046
        if ( menu.getEnableText() != null ) {
1047
            nuevoMenu.setEnableText(i18nManager.getTranslation(menu.getEnableText()));
1048
        }
1049

    
1050
        nuevoMenu.setEnabled(true);
1051
        nuevoMenu.setVisible(true);
1052

    
1053
        if ( menu.getName() != null ) {
1054
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1055
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1056
            if ( actionInfo != null ) {
1057
                nuevoMenu.addActionListener(actionInfo);
1058
            }
1059
        }
1060
        return nuevoMenu;
1061
    }
1062

    
1063
    private JMenuItem createJMenuItem(ActionInfo action, String text) {
1064
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1065
        JMenuItem nuevoMenu = null;
1066
        String label = null;
1067

    
1068
        if ( text == null ) {
1069
            label = action.getLabel();
1070
        } else if ( text.contains("/") ) {
1071
            String[] ss = text.split("/");
1072
            label = ss[ss.length - 1];
1073
        } else {
1074
            label = text;
1075
        }
1076
        String translatedText = i18nManager.getTranslation(label);
1077
        if ( action.getIconName() != null ) {
1078
            ImageIcon image = action.getIcon();
1079
            if ( image != null ) {
1080
                nuevoMenu = new JMenuItem(translatedText, image);
1081
            } else {
1082
                nuevoMenu = new JMenuItem(translatedText);
1083
            }
1084
        } else {
1085
            nuevoMenu = new JMenuItem(translatedText);
1086
        }
1087
        nuevoMenu.setText(translatedText);
1088
        nuevoMenu.setName(action.getName());
1089
        KeyStroke key = action.getKeyStroke();
1090
        if ( key != null ) {
1091
            nuevoMenu.setAccelerator(key);
1092
        }
1093
        nuevoMenu.setActionCommand(action.getCommand());
1094
        if ( action.getTooltip() != null ) {
1095
            nuevoMenu.setToolTip(i18nManager.getTranslation(action.getTooltip()));
1096
        }
1097
        nuevoMenu.setEnabled(true);
1098
        nuevoMenu.setVisible(true);
1099
        nuevoMenu.addActionListener(action);
1100
        return nuevoMenu;
1101
    }
1102

    
1103
    /**
1104
     * Muestra u oculta el menu de nombre 'name'
1105
     *
1106
     * @param name
1107
     * Nombre del menu que se quiere mostrar
1108
     * @param x
1109
     * Evento de raton
1110
     * @param y
1111
     * @param c
1112
     */
1113
    private void showPopupMenu(String name, int x, int y, Component c) {
1114
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1115

    
1116
        if ( menu != null ) {
1117
            menu.show(c, x, y);
1118
        }
1119
    }
1120

    
1121
    public void removePopupMenuListener(String name, ActionListener listener) {
1122
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1123

    
1124
        if ( menu != null ) {
1125
            Component[] jmenuitems = menu.getComponents();
1126

    
1127
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1128
                if ( jmenuitems[i] instanceof JMenuItem ) {
1129
                    ((JMenuItem) jmenuitems[i]).removeActionListener(listener);
1130
                }
1131
            }
1132
        }
1133
    }
1134

    
1135
    public void addPopupMenuListener(String popupName, Component c,
1136
            ActionListener listener, PluginClassLoader loader) {
1137
        final String name = getName(popupName, loader);
1138

    
1139
        JPopupMenu menu = (JPopupMenu) popupMap.get(name);
1140

    
1141
        if ( menu != null ) {
1142
            Component[] jmenuitems = menu.getComponents();
1143

    
1144
            for ( int i = 0; i < jmenuitems.length; i++ ) {
1145
                if ( jmenuitems[i] instanceof JMenuItem ) {
1146
                    ((JMenuItem) jmenuitems[i]).addActionListener(listener);
1147
                }
1148
            }
1149
        }
1150

    
1151
        c.addMouseListener(new MouseAdapter() {
1152

    
1153
            @Override
1154
            public void mousePressed(MouseEvent e) {
1155
                if ( e.isPopupTrigger() ) {
1156
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1157
                }
1158
            }
1159

    
1160
            @Override
1161
            public void mouseReleased(MouseEvent e) {
1162
                if ( e.isPopupTrigger() ) {
1163
                    showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
1164
                }
1165
            }
1166
        });
1167
    }
1168

    
1169
    /**
1170
     * Loop on the controls to enable/disable and show/hide them, according to
1171
     * its associated action (ActionInfo)
1172
     *
1173
     * @throws RuntimeException
1174
     */
1175
    public void enableControls() {
1176
        if ( !SwingUtilities.isEventDispatchThread() ) {
1177
            SwingUtilities.invokeLater(new Runnable() {
1178
                public void run() {
1179
                    enableControls();
1180
                }
1181
            });
1182
            return;
1183
        }
1184

    
1185
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1186
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1187

    
1188
        // Enable or disable controls, according to its associated extensions
1189
        Iterator<JComponent> e = controlsIterator();
1190

    
1191
        while ( e.hasNext() ) {
1192
            JComponent control = (JComponent) e.next();
1193
            String actionName = control.getName();
1194
            ActionInfo action = actionManager.getAction(actionName);
1195
            try {
1196
                boolean enabled = false;
1197
                boolean visible = false;
1198

    
1199
                if ( action == null ) {
1200
                    if( control instanceof DropDownButton ) {
1201
                        DropDownButton dropDownButton = (DropDownButton)control;
1202
                        visible = !dropDownButton.isAllHiden();
1203
                        enabled = !dropDownButton.isAllDisabled();
1204
                    } else if( control instanceof JMenuTraslatable ) {
1205
                        enabled = true;
1206
                        visible = true;
1207
                    } else {
1208
                        IExtension extension = this.control2extensions.get(control);
1209
                        if( extension!=null ) {
1210
                            enabled = extension.isEnabled();
1211
                            visible = extension.isVisible();
1212
                        } else {
1213
                            logger.warn("Can't enable/show control '"+control.getClass().getName()+"/"+control.getName()+".");
1214
                            enabled = true;
1215
                            visible = true;
1216
                        }
1217
                    }
1218
                } else {
1219
                    enabled = false;
1220
                    visible = cache.isVisible(action);
1221
                    if ( visible ) {
1222
                        enabled = cache.isEnabled(action);
1223
                    }
1224
                }
1225
                control.setEnabled(enabled);
1226
                control.setVisible(visible);
1227
            } catch (Throwable ex) {
1228
                // Catch exceptins and errors (class not found)
1229
                logger.info("Can't enable/show control '" + actionName + "'.", ex);
1230
                this.message("Can't enable/show control '" + actionName + "'.", JOptionPane.ERROR_MESSAGE);
1231
                try {
1232
                    control.setEnabled(false);
1233
                    control.setVisible(false);
1234
                } catch (Exception ex2) {
1235
                    // Ignore errors
1236
                }
1237
            }
1238
        }
1239

    
1240
        // Loop in the menus to hide the menus that don't have visible children
1241
        for ( int i = 0; i < menuBar.getMenuCount(); i++ ) {
1242
            MenuElement menu = menuBar.getMenu(i);
1243
            hideMenus(menu);
1244
            if ( menu instanceof JMenu ) {
1245
                // hide (ugly) redundant separators and assign keyboard
1246
                // mnemonics
1247
                Component[] comps = ((JMenu) menu).getMenuComponents();
1248
                // mnemonics have to be unique for each top-level menu
1249
                char mnemonics[] = new char[comps.length];
1250
                if ( comps.length > 0 ) {
1251
                    // Set keyboard mnemonic for this top-level entry
1252
                    String text = ((JMenu) menu).getText();
1253
                    char mnemonic = getMnemonic(text, mnemonics);
1254
                    if ( ' ' != mnemonic ) {
1255
                        ((JMenu) menu).setMnemonic(mnemonic);
1256
                        mnemonics[0] = mnemonic;
1257
                    }
1258
                }
1259
                // now go through all entries in this menu, hid
1260
                // separators if necessary and assing remaining mnemonics
1261
                hideSeparatorsAndMakeMnemonics(menu, mnemonics);
1262
            }
1263
        }
1264

    
1265
        // hide the toolbars that don't contain any visible tool
1266
        Iterator it = toolBarMap.values().iterator();
1267

    
1268
        while ( it.hasNext() ) {
1269
            JComponent t = (JComponent) it.next();
1270
            boolean todosOcultos = true;
1271

    
1272
            for ( int i = 0; i < t.getComponentCount(); i++ ) {
1273
                if ( !(t.getComponent(i) instanceof JSeparator) // separators
1274
                        // don't matter
1275
                        && t.getComponent(i).isVisible() ) {
1276
                    todosOcultos = false;
1277
                }
1278
            }
1279

    
1280
            if ( todosOcultos ) {
1281
                t.setVisible(false);
1282
            } else {
1283
                if ( t instanceof SelectableToolBar ) {
1284
                    t.setVisible(((SelectableToolBar) t).getAndamiVisibility());
1285
                } else {
1286
                    t.setVisible(true);
1287
                }
1288
            }
1289
        }
1290

    
1291
        if ( mdiManager != null ) {
1292
            JPanel f = (JPanel) mdiManager.getActiveWindow();
1293

    
1294
            if ( f != null ) {
1295
                if ( lastLabelClass != f.getClass() ) {
1296
                    lastLabelClass = f.getClass();
1297

    
1298
                    Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
1299

    
1300
                    if ( lbls != null ) {
1301
                        bEstado.setLabelSet(lbls);
1302
                    }
1303
                }
1304
            }
1305
        }
1306

    
1307
        ajustarToolBar();
1308

    
1309
        showMemory();
1310
    }
1311

    
1312
    public synchronized void refreshControls() {
1313
        if ( !SwingUtilities.isEventDispatchThread() ) {
1314
            SwingUtilities.invokeLater(new Runnable() {
1315
                public void run() {
1316
                    refreshControls();
1317
                }
1318
            });
1319
            return;
1320
        }
1321

    
1322
        if(refreshingControls){
1323
            return;
1324
        }
1325
        try {
1326
        refreshingControls = true;
1327
        ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1328
        ActionInfoStatusCache cache = actionManager.createActionStatusCache();
1329
        IconTheme icontheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1330

    
1331
        Iterator e = controlsIterator();
1332

    
1333
        while ( e.hasNext() ) {
1334
            JComponent control = (JComponent) e.next();
1335
            if ( control instanceof TranslatableButton ) {
1336
                ((TranslatableButton) control).translate();
1337
            }
1338
            String actionlName = control.getName();
1339
            ActionInfo action = actionManager.getAction(actionlName);
1340
            if ( action != null ) {
1341
                if ( control instanceof AbstractButton ) {
1342
                    AbstractButton button = (AbstractButton) control;
1343
                    if ( control instanceof javax.swing.JMenuItem ) {
1344
                        if ( action.getIconName() != null && action.getIconName().length() > 0 ) {
1345
                            if ( icontheme.exists(action.getIconName()) ) {
1346
                                button.setIcon(action.getIcon());
1347
                            }
1348
                        }
1349
                    } else {
1350
                        button.setIcon(action.getIcon());
1351
                    }
1352
                }
1353
            }
1354
        }
1355
        enableControls();
1356
        } finally {
1357
            refreshingControls = false;
1358
        }
1359
    }
1360

    
1361
    public void message(String msg, int messageTyoe) {
1362
        this.getStatusBar().message(msg, messageTyoe);
1363
    }
1364

    
1365
    /**
1366
     * Establece la visibilidad de un menu y todos sus descendientes en la
1367
     * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
1368
     *
1369
     * @param menu
1370
     * Menu que se quiere visualizar
1371
     *
1372
     * @return Devuelve true si el menu es visible y false en caso contrario
1373
     */
1374
    private boolean hideMenus(MenuElement menu) {
1375
        MenuElement[] submenus = menu.getSubElements();
1376

    
1377
        // Si no tiene hijos se devuelve su visibilidad
1378
        if ( submenus.length == 0 ) {
1379
            return menu.getComponent().isVisible();
1380
        }
1381

    
1382
        /*
1383
         * Si tiene hijos se devuelve true si alg?no de ellos es visible,
1384
         * pero se itera por todos ellos
1385
         */
1386
        boolean visible = false;
1387

    
1388
        for ( int i = 0; i < submenus.length; i++ ) {
1389
            if ( hideMenus(submenus[i]) ) {
1390
                if ( !(menu instanceof JPopupMenu) ) {
1391
                    menu.getComponent().setVisible(true);
1392
                }
1393

    
1394
                visible = true;
1395
            }
1396
        }
1397

    
1398
        if ( visible ) {
1399
            return true;
1400
        }
1401

    
1402
        menu.getComponent().setVisible(false);
1403

    
1404
        return false;
1405
    }
1406

    
1407
    /**
1408
     *
1409
     * Recurse through all menu elements and make sure there are no
1410
     * redundant separators.
1411
     * This method will make sure that a separator only becomes visible
1412
     * if at least one visible non-separator menu entry preceeded it.
1413
     *
1414
     *
1415
     */
1416
    private void hideSeparatorsAndMakeMnemonics(MenuElement menu,
1417
            char[] mnemonics) {
1418
        // flag that indicates whether a separator is to be displayed or not
1419
        boolean allowSeparator;
1420

    
1421
        allowSeparator = false; // separator not allowed as very first menu item
1422
        Component[] comps = ((JMenu) menu).getMenuComponents();
1423
        if ( comps.length < 1 ) {
1424
            // zero-length menu: skip
1425
            return;
1426
        }
1427

    
1428
        for ( int i = 0; i < comps.length; i++ ) {
1429
            if ( comps[i] instanceof JSeparator ) {
1430
                // got a separator: display only if allowed at this position
1431
                if ( allowSeparator == true ) {
1432
                    // look at all successive menu entries to make sure that at
1433
                    // least one
1434
                    // is visible and not a separator (otherwise, this separator
1435
                    // would
1436
                    // be the last visible item in this menu) -- we don't want
1437
                    // that
1438
                    comps[i].setVisible(false);
1439
                    for ( int j = i; j < comps.length; j++ ) {
1440
                        if ( !(comps[j] instanceof JSeparator) ) {
1441
                            if ( comps[j].isVisible() ) {
1442
                                comps[i].setVisible(true); // display separator!
1443
                                break;
1444
                            }
1445
                        }
1446
                    }
1447
                } else {
1448
                    comps[i].setVisible(false);
1449
                }
1450
                allowSeparator = false; // separator is not allowed right after
1451
                // another separator
1452
            } else {
1453
                if ( comps[i] instanceof JMenu ) { // got a submenu: recurse
1454
                    // through it
1455
                    // get number of submenu components
1456
                    Component[] scomps = ((JMenu) comps[i]).getMenuComponents();
1457
                    // make a new, fresh array to hold unique mnemonics for this
1458
                    // submenu
1459
                    char[] smnemonics = new char[scomps.length];
1460
                    hideSeparatorsAndMakeMnemonics(((MenuElement) comps[i]),
1461
                            smnemonics);
1462
                    if ( comps[i].isVisible() ) {
1463
                        allowSeparator = true; // separators are OK after
1464
                        // visible submenus
1465
                        // Set keyboard mnemonic for this submenu
1466
                        String text = ((JMenu) comps[i]).getText();
1467
                        char mnemonic = getMnemonic(text, mnemonics);
1468
                        if ( ' ' != mnemonic ) {
1469
                            ((JMenu) comps[i]).setMnemonic(mnemonic);
1470
                            mnemonics[i] = mnemonic;
1471
                        }
1472
                    }
1473
                } else {
1474
                    if ( comps[i].isVisible() ) {
1475
                        if ( comps[i] instanceof JMenuItem ) {
1476
                            // Set keyboard mnemonic for this menu item
1477
                            String text = ((JMenuItem) comps[i]).getText();
1478
                            char mnemonic = getMnemonic(text, mnemonics);
1479
                            if ( ' ' != mnemonic ) {
1480
                                ((JMenuItem) comps[i]).setMnemonic(mnemonic);
1481
                                mnemonics[i] = mnemonic;
1482
                            }
1483
                        }
1484
                        allowSeparator = true; // separators are OK after
1485
                        // regular, visible entries
1486
                    }
1487
                }
1488
            }
1489
        }
1490
    }
1491

    
1492
    /**
1493
     * Helper functios for assigning a unique mnemomic char from
1494
     * a pool of unassigned onces, stored in the array "mnemomnics"
1495
     */
1496
    private char getMnemonic(String text, char[] mnemonics) {
1497
        if( text==null ) {
1498
            return ' ';
1499
        }
1500
        Vector words = new Vector();
1501
        StringTokenizer t = new StringTokenizer(text);
1502
        int maxsize = 0;
1503

    
1504
        while ( t.hasMoreTokens() ) {
1505
            String word = t.nextToken();
1506
            if ( word.length() > maxsize ) {
1507
                maxsize = word.length();
1508
            }
1509
            words.addElement(word);
1510
        }
1511
        words.trimToSize();
1512

    
1513
        for ( int i = 0; i < maxsize; ++i ) {
1514
            char mnemonic = getMnemonic(words, mnemonics, i);
1515
            if ( ' ' != mnemonic ) {
1516
                return mnemonic;
1517
            }
1518
        }
1519

    
1520
        return ' ';
1521
    }
1522

    
1523
    private char getMnemonic(Vector words, char[] mnemonics, int index) {
1524
        int numwords = words.size();
1525

    
1526
        for ( int i = 0; i < numwords; ++i ) {
1527
            String word = (String) words.elementAt(i);
1528
            if ( index >= word.length() ) {
1529
                continue;
1530
            }
1531

    
1532
            char c = word.charAt(index);
1533
            if ( !isMnemonicExists(c, mnemonics) ) {
1534
                /* pick only valid chars */
1535
                if ( (c != ':') && (c != '.') && (c != ',') && (c != ';')
1536
                        && (c != '-') && (c != '+') && (c != '/') && (c != '\\')
1537
                        && (c != '\'') && (c != '\"') && (c != ' ') && (c != '=')
1538
                        && (c != '(') && (c != ')') && (c != '[') && (c != ']')
1539
                        && (c != '{') && (c != '}') && (c != '$') && (c != '*')
1540
                        && (c != '&') && (c != '%') && (c != '!') && (c != '?')
1541
                        && (c != '#') && (c != '~') && (c != '_') ) {
1542
                    return c;
1543
                }
1544
            }
1545
        }
1546
        return ' ';
1547
    }
1548

    
1549
    private boolean isMnemonicExists(char c, char[] mnemonics) {
1550
        int num = mnemonics.length;
1551
        for ( int i = 0; i < num; ++i ) {
1552
            if ( mnemonics[i] == c ) {
1553
                return true;
1554
            }
1555
        }
1556
        return false;
1557
    }
1558

    
1559
    /**
1560
     * Muestra la memoria consumida por el programa
1561
     */
1562
    private void showMemory() {
1563
        Runtime r = Runtime.getRuntime();
1564
        long mem = r.totalMemory() - r.freeMemory();
1565
        logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem
1566
                / 1024 + " KB");
1567
    }
1568

    
1569
    public MDIManager getMDIManager() {
1570
        return mdiManager;
1571
    }
1572

    
1573
    public NewStatusBar getStatusBar() {
1574
        return bEstado;
1575
    }
1576

    
1577
    /**
1578
     * You can use this function to select the appropiate
1579
     * tool inside the toolbars
1580
     */
1581
    public void setSelectedTool(String actionCommand) {
1582
        setSelectedTool(defaultGroup, actionCommand);
1583
    }
1584

    
1585
    /**
1586
     * You can use this function to select the appropiate
1587
     * tool inside the toolbars
1588
     */
1589
    public void setSelectedTool(String groupName, String actionCommand) {
1590
        ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1591
        if ( group == null ) {
1592
            return;
1593
        }
1594

    
1595
        Enumeration enumeration = group.getElements();
1596
        while ( enumeration.hasMoreElements() ) {
1597
            AbstractButton button = (AbstractButton) enumeration.nextElement();
1598
            if ( button.getActionCommand().equals(actionCommand) ) {
1599
                button.setSelected(true);
1600
            }
1601
        }
1602

    
1603
        selectedTool.put(groupName, actionCommand);
1604
    }
1605

    
1606
    /**
1607
     * You can use this function to select the appropiate
1608
     * tool inside the toolbars
1609
     */
1610
    public void setSelectedTools(Map selectedTools) {
1611
        selectedTool = selectedTools;
1612
        if ( selectedTools == null ) {
1613
            return;
1614
        }
1615
        Iterator groupNames = selectedTools.keySet().iterator();
1616
        while ( groupNames.hasNext() ) {
1617
            try {
1618
                String groupName = (String) groupNames.next();
1619
                ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1620
                Enumeration enumeration = group.getElements();
1621
                String actionCommand = (String) selectedTools.get(groupName);
1622
                if ( actionCommand == null ) {
1623
                    continue;
1624
                }
1625
                while ( enumeration.hasMoreElements() ) {
1626
                    AbstractButton button
1627
                            = (AbstractButton) enumeration.nextElement();
1628
                    if ( button.getActionCommand().equals(actionCommand) ) {
1629
                        button.setSelected(true);
1630
                    }
1631
                }
1632
            } catch (ClassCastException ex) {
1633
                logger
1634
                        .error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1635
            }
1636
        }
1637
    }
1638

    
1639
    /**
1640
     * DOCUMENT ME!
1641
     *
1642
     * @param clase
1643
     * @param label
1644
     */
1645
    public void setStatusBarLabels(Class<?> clase, Label[] label) {
1646
        classLabels.put(clase, label);
1647
    }
1648

    
1649
    public void removeStatusBarLabels(Class<?> clase) {
1650
        classLabels.remove(clase);
1651
    }
1652

    
1653
    public void addStatusBarControl(Class<?> extensionClass, IControl control) {
1654
        control.addActionListener(this);
1655
        bEstado.addControl(control.getName(), (Component) control);
1656
        if ( control instanceof JComponent ) {
1657
            addControl((JComponent) control);
1658
            PluginsManager pluginsManager = PluginsLocator.getManager();
1659
            IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1660
            this.control2extensions.put((JComponent)control, extension);
1661
        }
1662
    }
1663

    
1664
    public void addToolBarControl(Class<?> extensionClass, JToolBar control, String name) {
1665
        toolBars.add(control);
1666
        addControl(control);
1667

    
1668
        PluginsManager pluginsManager = PluginsLocator.getManager();
1669
        IExtension extension = pluginsManager.getExtension((Class<? extends IExtension>) extensionClass);
1670
        this.control2extensions.put(control, extension);
1671
    }
1672

    
1673
    public void removeStatusBarControl(String name) {
1674
        Component c = bEstado.removeControl(name);
1675
        if ( c instanceof JComponent ) {
1676
            removeControl((JComponent) c);
1677
        }
1678
    }
1679

    
1680
    public void removeMenu(Menu menu) {
1681
        JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1682

    
1683
        if ( delete == null ) {
1684
            throw new NoSuchElementException(menu.getText());
1685
        }
1686

    
1687
        delete.getParent().remove(delete);
1688
        infoCodedMenus.remove(menu);
1689
    }
1690

    
1691
    public void addMenu(Menu menu, ActionListener listener,
1692
            PluginClassLoader loader) {
1693
        JMenu menuPadre = createMenuAncestors(menu, loader);
1694

    
1695
        // Se registra y a?aade el menu
1696
        JMenuItem nuevoMenu = createJMenuItem(loader, menu);
1697
        nuevoMenu.addMouseListener(tooltipListener);
1698
        if ( listener != null && menu.getName() != null && menu.getName().trim().length() > 0 ) {
1699
            ActionInfoManager actionManager = PluginsLocator.getActionInfoManager();
1700
            final ActionInfo actionInfo = actionManager.getAction(menu.getName());
1701
            if ( actionInfo != null ) {
1702
                nuevoMenu.removeActionListener(actionInfo);
1703
            }
1704
            nuevoMenu.addActionListener(listener);
1705
        } else {
1706
            /*
1707
             * We also add action listener for menu with
1708
             * no name but with text:
1709
             *
1710
             * Window/Project manager
1711
             * Window/View - 1
1712
             * Window/View - 2
1713
             * etc
1714
             */
1715
            if ( listener != null && menu.getText() != null && menu.getText().trim().length() > 0 ) {
1716
                nuevoMenu.addActionListener(listener);
1717
            }
1718

    
1719
        }
1720
        menuPadre.add(nuevoMenu);
1721

    
1722
        infoCodedMenus.put(menu, nuevoMenu);
1723
    }
1724

    
1725
    public void changeMenuName(String[] menu, String newName,
1726
            PluginClassLoader loader) {
1727

    
1728
        ArrayList menuList = new ArrayList();
1729
        for ( int i = 0; i < menu.length; i++ ) {
1730
            menuList.add(menu[i]);
1731
        }
1732

    
1733
        javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1734
        if ( newMenu == null ) {
1735
            throw new NoSuchMenuException(menu[0]);
1736
        } else {
1737
            newMenu.setText(PluginServices.getText(this, newName));
1738
        }
1739
    }
1740

    
1741
    public void componentHidden(ComponentEvent arg0) {
1742
    }
1743

    
1744
    public void componentMoved(ComponentEvent arg0) {
1745
    }
1746

    
1747
    public void componentResized(ComponentEvent arg0) {
1748
        ajustarToolBar();
1749
    }
1750

    
1751
    public void componentShown(ComponentEvent arg0) {
1752
    }
1753

    
1754
    public void componentAdded(ContainerEvent arg0) {
1755
        ajustarToolBar();
1756
    }
1757

    
1758
    public void componentRemoved(ContainerEvent arg0) {
1759
        ajustarToolBar();
1760
    }
1761

    
1762
    public class TooltipListener extends MouseAdapter {
1763

    
1764
        @Override
1765
        public void mouseEntered(MouseEvent e) {
1766
            JComponent control = (JComponent) e.getSource();
1767
            EnableTextSupport ets = (EnableTextSupport) e.getSource();
1768

    
1769
            String texto = null;
1770
            texto = control.getToolTipText();
1771

    
1772
            if ( texto != null ) {
1773
                bEstado.setInfoTextTemporal(texto);
1774
            }
1775
        }
1776

    
1777
        @Override
1778
        public void mouseExited(MouseEvent arg0) {
1779
            bEstado.restaurarTexto();
1780
        }
1781

    
1782
        @Override
1783
        public void mousePressed(MouseEvent e) {
1784
            bEstado.restaurarTexto();
1785
        }
1786
    }
1787

    
1788
    public String getTitlePrefix() {
1789
        return titlePrefix;
1790
    }
1791

    
1792
    public void setTitlePrefix(String titlePrefix) {
1793
        this.titlePrefix = titlePrefix;
1794
    }
1795

    
1796
    public Map getSelectedTools() {
1797
        return selectedTool;
1798
    }
1799

    
1800
    public HashMap getInitialSelectedTools() {
1801
        return initialSelectedTools;
1802
    }
1803

    
1804
    /**
1805
     * Get a previously added JComponent by name.
1806
     * For example you can use it if you need to obtain a JToolBar to
1807
     * add some customized component.
1808
     *
1809
     * @param name
1810
     * @return the JComponent or null if none has been found
1811
     */
1812
    public JComponent getComponentByName(String name) {
1813
        Iterator e = controlsIterator();
1814

    
1815
        while ( e.hasNext() ) {
1816
            JComponent control = (JComponent) e.next();
1817
            String nameCtrl = control.getName();
1818
            if ( nameCtrl != null ) {
1819
                if ( nameCtrl.compareTo(name) == 0 ) {
1820
                    return control;
1821
                }
1822
            }
1823
        }
1824
        Iterator it = toolBarMap.values().iterator();
1825
        while ( it.hasNext() ) {
1826
            JComponent t = (JComponent) it.next();
1827
            String nameCtrl = t.getName();
1828
            if ( nameCtrl != null ) {
1829
                if ( nameCtrl.compareTo(name) == 0 ) {
1830
                    return t;
1831
                }
1832
            }
1833

    
1834
        }
1835

    
1836
        return null;
1837
    }
1838

    
1839
    public SelectableToolBar[] getToolbars() {
1840
        return (SelectableToolBar[]) toolBarMap.values().toArray(
1841
                new SelectableToolBar[0]);
1842
    }
1843

    
1844
    public boolean getToolbarVisibility(String name) {
1845
        JComponent component
1846
                = PluginServices.getMainFrame().getComponentByName(name);
1847
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1848
            SelectableToolBar toolBar = (SelectableToolBar) component;
1849
            return toolBar.getAndamiVisibility();
1850
        }
1851
        return false;
1852
    }
1853

    
1854
    public boolean setToolbarVisibility(String name, boolean visibility) {
1855
        JComponent component
1856
                = PluginServices.getMainFrame().getComponentByName(name);
1857
        if ( (component != null) && (component instanceof SelectableToolBar) ) {
1858
            SelectableToolBar toolBar = (SelectableToolBar) component;
1859
            boolean oldVisibility = toolBar.getAndamiVisibility();
1860
            toolBar.setAndamiVisibility(visibility);
1861
            enableControls();
1862
            return oldVisibility;
1863
        }
1864
        return false;
1865
    }
1866

    
1867
    public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1868
        ArrayList menu = new ArrayList();
1869
        for ( int i = 0; i < menuPath.length; i++ ) {
1870
            menu.add(menuPath[i]);
1871
        }
1872
        return getMenu(menu, menuBar);
1873
    }
1874

    
1875
    public void messageDialog(String message, String title, int messageType) {
1876
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1877
        helper.messageDialog(message, title, messageType);
1878
    }
1879

    
1880
    public void messageDialog(String message, String[] messageArgs,
1881
            String title, int messageType) {
1882
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1883
        helper.messageDialog(message, messageArgs, title, messageType);
1884
    }
1885

    
1886
    public int confirmDialog(String message, String title, int optionType,
1887
            int messageType) {
1888
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1889
        return helper.confirmDialog(message, title, optionType, messageType);
1890
    }
1891

    
1892
    public String inputDialog(String message, String title, int messageType,
1893
            String initialValue) {
1894
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1895
        return helper.inputDialog(message, title, messageType, initialValue);
1896
    }
1897

    
1898
    public String inputDialog(String message, String title) {
1899
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1900
        return helper.inputDialog(message, title);
1901
    }
1902

    
1903
    public void showDialog(Component contents, String title) {
1904
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1905
        helper.showDialog(contents, title);
1906
    }
1907

    
1908
    public Component createComponent(Class<? extends Component> theClass,
1909
            Object... parameters) {
1910
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1911
        return helper.createComponentWithParams(theClass, parameters);
1912
    }
1913

    
1914
    public Component createComponentWithParams(
1915
            Class<? extends Component> theClass, Object[] parameters) {
1916
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1917
        return helper.createComponentWithParams(theClass, parameters);
1918
    }
1919

    
1920
    public File[] showChooserDialog(
1921
            final String title,
1922
            final int type, // SAVE_DIALOG / OPEN_DIALOG
1923
            final int selectionMode, //    JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES
1924
            final boolean multiselection,
1925
            final File initialPath,
1926
            final FileFilter filter,
1927
            final boolean fileHidingEnabled
1928
    ) {
1929
        DefaultThreadSafeDialogs helper = new DefaultThreadSafeDialogs(this, this.bEstado);
1930
        return helper.showChooserDialog(title, type, selectionMode, multiselection, initialPath, filter, fileHidingEnabled);
1931
    }
1932

    
1933
    public File[] showOpenDirectoryDialog(String title, File initialPath) {
1934
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false);
1935
    }
1936

    
1937
    public File[] showOpenFileDialog(String title, File initialPath) {
1938
        return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1939
    }
1940

    
1941
    public File[] showSaveFileDialog(String title, File initialPath) {
1942
        return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false);
1943
    }
1944

    
1945
    private void addControl(JComponent control) {
1946
        controls.add(control);
1947
    }
1948

    
1949
    private void removeControl(JComponent control) {
1950
        controls.remove(control);
1951
    }
1952

    
1953
    private Iterator<JComponent> controlsIterator() {
1954
        return this.controls.iterator();
1955
    }
1956

    
1957
    @Override
1958
    public void setLocale(Locale locale) {
1959
        super.setLocale(locale); //To change body of generated methods, choose Tools | Templates.
1960
        MDIManager mdiManager = MDIManagerFactory.createManager();
1961
        mdiManager.setLocale(locale);
1962
        if ( this.controls != null && !this.controls.isEmpty() ) {
1963
            this.refreshControls();
1964
        }
1965
    }
1966

    
1967
}