Statistics
| Revision:

root / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / MDIFrame.java @ 32707

History | View | Annotate | Download (39.9 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.andami.ui.mdiFrame;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.Component;
45
import java.awt.Dimension;
46
import java.awt.FlowLayout;
47
import java.awt.Insets;
48
import java.awt.Toolkit;
49
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionListener;
51
import java.awt.event.ComponentEvent;
52
import java.awt.event.ComponentListener;
53
import java.awt.event.ContainerEvent;
54
import java.awt.event.ContainerListener;
55
import java.awt.event.MouseAdapter;
56
import java.awt.event.MouseEvent;
57
import java.awt.event.WindowAdapter;
58
import java.awt.event.WindowEvent;
59
import java.net.URL;
60
import java.util.ArrayList;
61
import java.util.Enumeration;
62
import java.util.HashMap;
63
import java.util.Iterator;
64
import java.util.NoSuchElementException;
65

    
66
import javax.swing.AbstractButton;
67
import javax.swing.ButtonGroup;
68
import javax.swing.ImageIcon;
69
import javax.swing.JComponent;
70
import javax.swing.JFrame;
71
import javax.swing.JMenu;
72
import javax.swing.JMenuBar;
73
import javax.swing.JPanel;
74
import javax.swing.JPopupMenu;
75
import javax.swing.JSeparator;
76
import javax.swing.KeyStroke;
77
import javax.swing.MenuElement;
78
import javax.swing.SwingUtilities;
79
import javax.swing.Timer;
80

    
81
import org.apache.log4j.Logger;
82
import org.gvsig.gui.beans.controls.IControl;
83

    
84
import com.iver.andami.Launcher;
85
import com.iver.andami.PluginServices;
86
import com.iver.andami.messages.Messages;
87
import com.iver.andami.messages.NotificationManager;
88
import com.iver.andami.plugins.ExtensionDecorator;
89
import com.iver.andami.plugins.PluginClassLoader;
90
import com.iver.andami.plugins.config.generate.ActionTool;
91
import com.iver.andami.plugins.config.generate.Label;
92
import com.iver.andami.plugins.config.generate.Menu;
93
import com.iver.andami.plugins.config.generate.PopupMenu;
94
import com.iver.andami.plugins.config.generate.SelectableTool;
95
import com.iver.andami.plugins.config.generate.SkinExtensionType;
96
import com.iver.andami.plugins.config.generate.ToolBar;
97
import com.iver.andami.ui.mdiManager.MDIManager;
98
import com.iver.andami.ui.mdiManager.MDIManagerFactory;
99

    
100

    
101
/**
102
 * Main application window.
103
 *
104
 * @version $Revision: 32707 $
105
 */
106
public class MDIFrame extends JFrame implements ComponentListener,
107
ContainerListener, ActionListener, MainFrame {
108
        /** DOCUMENT ME! */
109
        private static Logger logger = Logger.getLogger(MDIFrame.class.getName());
110
        private MDIManager mdiManager = MDIManagerFactory.createManager();
111

    
112
        /** Elementos de la aplicaci�n */
113
        private JMenuBar menuBar = new JMenuBar();
114

    
115
        /** Panel which contains the toolbars */
116
        private JPanel toolBars = new JPanel();
117

    
118
        /** Status bar */
119
        private NewStatusBar bEstado = null;
120

    
121
        /** Asocia los nombres con las barras de herramientas */
122
        private HashMap toolBarMap = new HashMap();
123

    
124
        /** Almacena los grupos de selectableTools */
125
        private HashMap buttonGroupMap = new HashMap();
126
        /**
127
         * Stores the initially selected tools.
128
         * It contains pairs (String groupName, JToolBarToggleButton button)
129
         */
130
        private HashMap initialSelectedTools = new HashMap();
131

    
132
        /**
133
         * Stores the actionCommand of the selected tool, for each group.
134
         * It contains pairs (String groupName, JToolBarToggleButton button)
135
         */
136
        private HashMap selectedTool = null;
137
        // this should be the same value defined at plugin-config.xsd
138
        private String defaultGroup = "unico";
139

    
140
        /** Asocia los nombres con los popupMenus */
141
        private HashMap popupMap = new HashMap();
142

    
143
        /** Asocia controles con la clase de la extension asociada */
144
        private HashMap controlClass = new HashMap();
145

    
146
        /**
147
         * Asocia la informaci�n sobre las etiquetas que van en la status bar con
148
         * cada extension
149
         */
150
        private HashMap classLabels = new HashMap();
151

    
152
        //private HashMap classControls = new HashMap();
153

    
154
        /** ProgressListeners (ver interfaz com.iver.mdiApp.ui.ProgressListener) */
155
        private ArrayList progressListeners = new ArrayList();
156

    
157
        /** Timer para invocar los enventos de la interfaz anterior */
158
        private Timer progressTimer = null;
159

    
160
        /** Tabla hash que asocia las clases con las extensiones */
161
        private HashMap classesExtensions = new HashMap();
162

    
163
        /** �ltima clase que activ� etiquetas */
164
        private Class lastLabelClass;
165

    
166
        /** Instancia que pone los tooltip en la barra de estado */
167
        private TooltipListener tooltipListener = new TooltipListener();
168
        private HashMap infoCodedMenus = new HashMap();
169

    
170
        private String titlePrefix;
171

    
172
        private static final String noIcon = "no-icon";
173

    
174
        /**
175
         * Makes some initialization tasks.
176
         *
177
         * @throws RuntimeException DOCUMENT ME!
178
         */
179
        public void init() {
180
                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
181
                if (!SwingUtilities.isEventDispatchThread()) {
182
                        throw new RuntimeException("Not Event Dispatch Thread");
183
                }
184

    
185
                //Se a�aden los listeners del JFrame
186
                this.addWindowListener(new WindowAdapter() {
187
                        public void windowClosing(WindowEvent e) {
188
                                Launcher.closeApplication();
189
                        }
190
                });
191
                this.addComponentListener(this);
192
                this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
193

    
194
                //Se configura la barra de menu
195
                setJMenuBar(menuBar);
196

    
197
                //Se configura el layout del JFrame principal
198
                this.getContentPane().setLayout(new BorderLayout());
199

    
200
                /*
201
                 * Se configura y se a�ade el JPanel de las barras de
202
                 * herramientas
203
                 */
204
                FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
205
                layout.setHgap(0);
206
                layout.setVgap(0);
207
                toolBars.setLayout(layout);
208
                getContentPane().add(toolBars, BorderLayout.PAGE_START);
209

    
210
                // Se a�ade la barra de estado a la aplicaci�n
211
                bEstado = new NewStatusBar();
212
                bEstado.setInfoText(Messages.getString("StatusBar.Aplicacion_iniciada"));
213
                getContentPane().add(bEstado, BorderLayout.SOUTH);
214

    
215
                this.toolBars.addContainerListener(this);
216

    
217
                pack();
218

    
219
                // TODO LWS Aqui deber�a cargar los valores salvados de la �ltima ejecuci�n.
220
                setSize(700, 580);
221
                setLocation(10,10);
222
                setExtendedState(MAXIMIZED_BOTH);
223

    
224
                mdiManager.init(this);
225
        }
226

    
227
        /*
228
         * (non-javadoc)
229
         * @see java.awt.Frame.setTitle(String title)
230
         */
231
        public void setTitle(String title) {
232
                super.setTitle(titlePrefix + ":" + title);
233
        }
234

    
235
        /**
236
         * A�ade un modo de operaci�n a la caja de herramientas
237
         *
238
         * @param ext Texto del boton, si es null no aparece texto
239
         * @param ext Icono del boton, si es null no aparece icono
240
         * @param ext Extensi�n asociada al control
241
         * @param selectableTool Enable text del control
242
         *
243
         * @throws ClassNotFoundException
244
         * @throws RuntimeException DOCUMENT ME!
245
         */
246
        public void addTool(PluginClassLoader loader, SkinExtensionType ext,
247
                        ToolBar toolBar, SelectableTool selectableTool)
248
        throws ClassNotFoundException {
249
                if (!SwingUtilities.isEventDispatchThread()) {
250
                        throw new RuntimeException("No Event Dispatch Thread");
251
                }
252

    
253
                // Para traducir
254
                PluginServices ps = PluginServices.getPluginServices(loader.getPluginName());
255

    
256
                JToolBarToggleButton btn;
257
                ImageIcon image = PluginServices.getIconTheme().get(selectableTool.getIcon());
258

    
259
                if (image != null) {
260
                        btn = new JToolBarToggleButton(selectableTool.getText(), image);
261
                } else {
262
                        logger.error(PluginServices.getText(this, "Unable_to_find_icon") +": "+selectableTool.getIcon());
263
                        btn = new JToolBarToggleButton(selectableTool.getText(),
264
                                        PluginServices.getIconTheme().get(noIcon));
265
                }
266

    
267
                com.iver.andami.ui.mdiFrame.ToggleButtonModel buttonModel = new com.iver.andami.ui.mdiFrame.ToggleButtonModel();
268
                btn.setModel(buttonModel);
269
                btn.setMargin(new Insets(0, 0, 0, 0));
270
                btn.addMouseListener(tooltipListener);
271
                btn.addActionListener(this);
272
                btn.setFocusable(false);
273
                btn.setActionCommand(selectableTool.getActionCommand());
274
                btn.setToolTipText(selectableTool.getTooltip());
275
                btn.setEnabled(false);
276
                btn.setVisible(false);
277
                String name = toolBar.getName();
278

    
279
                SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name);
280

    
281
                if (jtb == null) {
282
                        jtb = new SelectableToolBar(name);
283
                        jtb.setRollover(true);
284
                        jtb.setAndamiVisibility(toolBar.getIsVisible());
285
                        toolBarMap.put(name, jtb);
286
                        toolBars.add(jtb);
287
                }
288

    
289
                ButtonGroup group;
290
                if (buttonGroupMap.containsKey(selectableTool.getGroup())) {
291
                        group = (ButtonGroup) buttonGroupMap.get(selectableTool.getGroup());
292
                }
293
                else {
294
                        group = new ButtonGroup();
295
                        buttonGroupMap.put(selectableTool.getGroup(), group);
296

    
297
                }
298
                jtb.addButton(group, btn);
299
                buttonModel.setGroupName(selectableTool.getGroup());
300

    
301
                if (selectableTool.getIsDefault()) {
302
                        btn.setSelected(true);
303
                        initialSelectedTools.put(selectableTool.getGroup(), btn.getActionCommand());
304
                }
305

    
306
                controlClass.put(btn, loader.loadClass(ext.getClassName()));
307

    
308
                if (selectableTool.getName() != null) {
309
                        btn.setName(selectableTool.getName());
310
                }
311

    
312
                if (selectableTool.getTooltip() != null) {
313
                        btn.setToolTip(ps.getText(selectableTool.getTooltip()));
314
                }
315

    
316
                if (selectableTool.getEnableText() != null) {
317
                        btn.setEnableText(ps.getText(selectableTool.getEnableText()));
318
                }
319

    
320
                if (selectableTool.getLast() == true) {
321
                        jtb.addSeparator();
322
                }
323
        }
324

    
325
        /**
326
         * A�ade un bot�n a la barra de herramientas
327
         *
328
         * @param ext Texto del boton, si es null no aparece texto
329
         * @param ext Extensi�n asociada al control
330
         * @param toolBar Icono del boton, si es null no aparece texto
331
         * @param actionTool Tooltip de la barra de herramientas
332
         *
333
         * @throws ClassNotFoundException
334
         * @throws RuntimeException DOCUMENT ME!
335
         */
336
        public void addTool(PluginClassLoader loader, SkinExtensionType ext,
337
                        ToolBar toolBar, ActionTool actionTool) throws ClassNotFoundException {
338
                if (!SwingUtilities.isEventDispatchThread()) {
339
                        throw new RuntimeException("No Event Dispatch Thread");
340
                }
341

    
342
                // Para traducir los textos que vengan
343
                PluginServices ps = PluginServices.getPluginServices(loader.getPluginName());
344

    
345
                JToolBarButton btn;
346
                ImageIcon image = PluginServices.getIconTheme().get(actionTool.getIcon(),ps.getClassLoader());
347

    
348
                if (image != null) {
349
                        btn = new JToolBarButton(actionTool.getText(), image);
350
                } else {
351
                        logger.error(PluginServices.getText(this, "Unable_to_find_icon") +": "+actionTool.getIcon());
352
                        btn = new JToolBarButton(actionTool.getText(),
353
                                        PluginServices.getIconTheme().get(noIcon));
354
                }
355

    
356
                btn.setMargin(new Insets(0, 0, 0, 0));
357
                btn.addMouseListener(tooltipListener);
358
                btn.addActionListener(this);
359
                btn.setFocusable(false);
360
                btn.setActionCommand(actionTool.getActionCommand());
361
                btn.setEnabled(false);
362
                btn.setVisible(false);
363

    
364
                String name = toolBar.getName();
365

    
366
                SelectableToolBar jtb = (SelectableToolBar) toolBarMap.get(name);
367

    
368
                if (jtb == null) {
369
                        jtb = new SelectableToolBar(name);
370
                        jtb.setRollover(true);
371
                        jtb.setAndamiVisibility(toolBar.getIsVisible());
372
                        toolBarMap.put(name, jtb);
373
                        toolBars.add(jtb);
374
                }
375

    
376
                jtb.add(btn);
377

    
378
                controlClass.put(btn, loader.loadClass(ext.getClassName()));
379

    
380
                if (actionTool.getName() != null) {
381
                        btn.setName(actionTool.getName());
382
                }
383

    
384
                if (actionTool.getTooltip() != null) {
385
                        btn.setToolTip(ps.getText(actionTool.getTooltip()));
386
                }
387

    
388
                if (actionTool.getEnableText() != null) {
389
                        btn.setEnableText(ps.getText(actionTool.getEnableText()));
390
                }
391

    
392
                if (actionTool.getLast() == true) {
393
                        jtb.addSeparator();
394
                }
395
        }
396

    
397
        /**
398
         * Creates the needed menu structure to add the menu to the bar.
399
         * Returns the father which must hold the menu which was
400
         * provided as parameter.
401
         *
402
         * Crea la estructura de men�s necesaria para a�adir el menu a la barra.
403
         * Devuelve el padre del cual debe colgar el menu que se pasa como
404
         * par�metro.
405
         *
406
         * @param menu The Menu whose support is going to be added
407
         * @param loader The plugin's class loader
408
         *
409
         * @return The proper father for the menu which was provided as parameter
410
         */
411
        private JMenu createMenuAncestors(Menu menu, PluginClassLoader loader) {
412
                MenuElement menuPadre = null;
413

    
414
                PluginServices ps = PluginServices.getPluginServices(loader.getPluginName());
415

    
416
                String[] menues = menu.getText().split("/");
417
                ArrayList menuList = new ArrayList();
418
                menuList.add(menues[0]);
419
                menuPadre = getMenu(menuList, menuBar);
420

    
421
                JMenu padre = null;
422

    
423
                if (menuPadre==null) {
424
                        padre = new JMenu(ps.getText(menues[0]));
425
                        padre.setName(menues[0]);
426
                        menuBar.add(padre);
427
                }
428
                else if (menuPadre instanceof JMenu) {
429
                        padre = (JMenu) menuPadre;
430
                }
431
                else {
432
                        logger.error(ps.getText("error_creating_menu_Ancestor_does_not_exist"));
433
                        return null;
434
                }
435

    
436
                //Se crea el resto de menus
437
                ArrayList temp = new ArrayList();
438

    
439
                for (int i = 1; i < (menues.length - 1); i++) {
440
                        temp.add(menues[i]);
441
                }
442

    
443
                menuPadre = createMenus(temp, padre);
444

    
445
                return (JMenu) menuPadre;
446
        }
447

    
448
        /**
449
         * A�ade la informaci�n del menu al framework. Debido a que los men�es se
450
         * pueden introducir en un orden determinado por el usuario, pero los
451
         * plugins se instalan en un orden arbitrario, primero se almacena la
452
         * informaci�n de todos los menus para luego ordenarlos y posteriormente
453
         * a�adirlos al interfaz
454
         *
455
         * @param loader Posicion del menu. Se ordena por este campo
456
         * @param ext Array con los nombres de los padres del menu
457
         * @param menu Texto del menu
458
         *
459
         * @throws ClassNotFoundException
460
         * @throws RuntimeException DOCUMENT ME!
461
         */
462
        public void addMenu(PluginClassLoader loader, SkinExtensionType ext,
463
                        Menu menu) throws ClassNotFoundException {
464
                if (!SwingUtilities.isEventDispatchThread()) {
465
                        throw new RuntimeException("No Event Dispatch Thread");
466
                }
467

    
468
                JMenu menuPadre = createMenuAncestors(menu, loader);
469

    
470
                //Se registra y a�ade el menu
471
                /* String[] aux = menu.getText().split("/");
472

473
        if (aux.length == 2)
474
            if (aux[1].equals("----"))
475
            {
476
                menuPadre.addSeparator();
477
                return;
478
            } */
479
                if (menu.getIs_separator())
480
                {
481
                        menuPadre.addSeparator();
482
                        return;
483
                }
484

    
485
                JMenuItem nuevoMenu = createJMenuItem(loader, menu);
486
                nuevoMenu.addMouseListener(tooltipListener);
487
                nuevoMenu.addActionListener(this);
488
                menuPadre.add(nuevoMenu);
489
                controlClass.put(nuevoMenu, loader.loadClass(ext.getClassName()));
490
        }
491

    
492

    
493
        /**
494
         * Dado un array de nombres de menu, encuentra el  men�
495
         *
496
         * @param nombres DOCUMENT ME!
497
         * @param padre DOCUMENT ME!
498
         *
499
         * @return DOCUMENT ME!
500
         */
501
        private javax.swing.JMenuItem getMenu(ArrayList nombres, MenuElement parent) {
502
                if (parent instanceof javax.swing.JMenu) {
503
                        javax.swing.JMenu parentItem = (javax.swing.JMenu) parent;
504

    
505
                        for (int i=0; i<parentItem.getMenuComponentCount(); i++) {
506
                                if (parentItem.getMenuComponent(i).getName()!=null // not a JToolBar.Separator
507
                                                && parentItem.getMenuComponent(i).getName().compareTo((String)nombres.get(0)) == 0) {
508
                                        nombres.remove(0);
509
                                        if (nombres.isEmpty()) {
510
                                                if (parentItem.getMenuComponent(i) instanceof javax.swing.JMenuItem) {
511
                                                        return (javax.swing.JMenuItem) parentItem.getMenuComponent(i);
512
                                                }
513
                                                else {
514
                                                        logger.error(PluginServices.getText(this, "Menu_type_not_supported_")+" "+parentItem.getMenuComponent(i).getClass().getName());
515
                                                        return null;
516
                                                }
517
                                        }
518
                                        else {
519
                                                return getMenu(nombres, (MenuElement) parentItem.getMenuComponent(i));
520
                                        }
521
                                }
522
                        }
523
                }
524
                else if (parent instanceof JMenuBar) {
525
                        javax.swing.JMenuBar parentItem = (javax.swing.JMenuBar) parent;
526

    
527
                        for (int i=0; i<parentItem.getMenuCount(); i++) {
528
                                if (parentItem.getMenu(i).getName()!=null // not a JToolBar.Separator
529
                                                && parentItem.getMenu(i).getName().compareTo((String)nombres.get(0)) == 0) {
530
                                        nombres.remove(0);
531
                                        if (nombres.isEmpty()) {
532
                                                if (parentItem.getMenu(i) instanceof javax.swing.JMenuItem) {
533
                                                        return (javax.swing.JMenuItem) parentItem.getMenu(i);
534
                                                }
535
                                                else {
536
                                                        logger.error(PluginServices.getText(this, "Menu_type_not_supported_")+" "+parentItem.getMenu(i).getClass().getName());
537
                                                        return null;
538
                                                }
539
                                        }
540
                                        else {
541
                                                return getMenu(nombres, (MenuElement) parentItem.getMenu(i));
542
                                        }
543
                                }
544
                        }
545
                }
546
                else {
547
                        logger.error(PluginServices.getText(this, "Menu_type_not_supported_")+" "+parent.getClass().getName()+" "+parent.toString());
548
                }
549
                return null;
550
        }
551

    
552
        /**
553
         * Crea la estructura de menus recursivamente. Por ejemplo, si se le pasa
554
         * en el par�metro nombres el array {"Search", "References", "Workspace"}
555
         * crear� un men� Search, un submen� del anterior que se llamar�
556
         * References y debajo de �ste �ltimo otro menu llamado Workspace
557
         *
558
         * @param nombres Array con los nombres de los men�s que se quieren crear
559
         * @param padre Menu padre de los men�s creados. Es �til porque es un
560
         *                   algoritmo recursivo
561
         *
562
         * @return Devuelve el men� creado. Al final de toda la recursividad,
563
         *                    devolver� el men� de m�s abajo en la jerarqu�a
564
         *
565
         * @throws RuntimeException DOCUMENT ME!
566
         */
567
        private JMenu createMenus(ArrayList nombres, JMenu padre) {
568
                if (!SwingUtilities.isEventDispatchThread()) {
569
                        throw new RuntimeException("No Event Dispatch Thread");
570
                }
571

    
572
                //si no quedan nombres de menu por crear se vuelve: caso base
573
                if (nombres.size() == 0) {
574
                        return padre;
575
                }
576

    
577
                //Se busca el menu por si ya existiera para no crearlo otra vez
578
                JMenu buscado = null;
579

    
580
                for (int i = 0; i < padre.getMenuComponentCount(); i++) {
581
                        try {
582
                                JMenu hijo = (JMenu) padre.getMenuComponent(i);
583

    
584
                                if (hijo.getName().compareTo((String) nombres.get(0)) == 0) {
585
                                        buscado = hijo;
586
                                }
587
                        } catch (ClassCastException e) {
588
                                /*
589
                                 * Se ha encontrado un elemento hoja del arbol de men�es
590
                                 */
591
                        }
592
                }
593

    
594
                if (buscado != null) {
595
                        //Si lo hemos encontrado creamos el resto
596
                        nombres.remove(0);
597

    
598
                        return createMenus(nombres, buscado);
599
                } else {
600
                        //Si no lo hemos encontrado se crea el menu, se a�ade al padre
601
                        //y se crea el resto
602
                        String nombre = (String) nombres.get(0);
603
                        JMenu menuPadre = new JMenu((String) PluginServices.getText(this, nombre));
604
                        menuPadre.setName(nombre);
605
                        padre.add(menuPadre);
606

    
607
                        nombres.remove(0);
608

    
609
                        return createMenus(nombres, menuPadre);
610
                }
611
        }
612

    
613
        /**
614
         * M�todo invocado en respuesta a ciertos eventos de la interfaz que pueden
615
         * ocultar botones de las barras de herramientas y que redimensiona �sta
616
         * de manera conveniente para que no se oculte ninguno
617
         */
618
        private void ajustarToolBar() {
619
                int margen = 8;
620
                int numFilas = 1;
621
                double acum = margen;
622

    
623
                int toolHeight = 0;
624

    
625
                for (int i = 0; i < toolBars.getComponentCount(); i++) {
626
                        Component c = toolBars.getComponent(i);
627

    
628
                        if (!c.isVisible()) {
629
                                continue;
630
                        }
631

    
632
                        double width = c.getPreferredSize().getWidth();
633
                        acum = acum + width;
634

    
635
                        if (acum > this.getWidth()) {
636
                                numFilas++;
637
                                acum = width + margen;
638
                        }
639

    
640
                        if (c.getPreferredSize().getHeight() > toolHeight) {
641
                                toolHeight = c.getPreferredSize().height;
642
                        }
643
                }
644

    
645
                toolBars.setPreferredSize(new Dimension(this.getWidth(),
646
                                (int) (numFilas * toolHeight)));
647

    
648
                toolBars.updateUI();
649
        }
650

    
651
        /**
652
         * DOCUMENT ME!
653
         *
654
         * @param classesExtensions
655
         */
656
        public void setClassesExtensions(HashMap classesExtensions) {
657
                this.classesExtensions = classesExtensions;
658
        }
659

    
660
        /**
661
         * M�todo de callback invocado cuando se selecciona un men� o un bot�n de
662
         * la barra de herramientas. Se busca la extensi�n asociada y se ejecuta
663
         *
664
         * @param e Evento producido
665
         */
666
        public void actionPerformed(ActionEvent e) {
667
                Object control = e.getSource();
668
                com.iver.andami.plugins.IExtension ext = (com.iver.andami.plugins.IExtension) classesExtensions.get((Class) controlClass.get(
669
                                control));
670
                String actionCommand = e.getActionCommand();
671
                try {
672
                        logger.debug(Messages.getString("Ejecutando comando: ") + actionCommand);
673
                        ext.execute(actionCommand);
674

    
675
                        try {
676
                                JToolBarToggleButton toggle = (JToolBarToggleButton) control;
677
                                ToggleButtonModel model = (ToggleButtonModel)toggle.getModel();
678
                                selectedTool.put(model.getGroupName(), actionCommand);
679
                        }
680
                        catch (ClassCastException ex) {}
681
                        catch (NullPointerException ex) {}
682

    
683
                } catch (RuntimeException t) {
684
                        if (ext==null) {
685
                                logger.error(Messages.getString("No_extension_associated_with_this_event_")+ e.getActionCommand());
686
                        }
687
                        NotificationManager.addError(Messages.getString(
688
                        "MDIFrame.Error_no_capturado_por_el_usuario"), t);
689
                }
690

    
691
                enableControls();
692
                showMemory();
693
        }
694

    
695
        /**
696
         * DOCUMENT ME!
697
         *
698
         * @param name DOCUMENT ME!
699
         * @param loader DOCUMENT ME!
700
         *
701
         * @return DOCUMENT ME!
702
         */
703
        private String getName(String name, PluginClassLoader loader) {
704
                if (name.indexOf('.') == -1) {
705
                        return loader.getPluginName() + "." + name;
706
                } else {
707
                        return name;
708
                }
709
        }
710

    
711
        /**
712
         * DOCUMENT ME!
713
         *
714
         * @param loader DOCUMENT ME!
715
         * @param menu DOCUMENT ME!
716
         *
717
         * @throws RuntimeException DOCUMENT ME!
718
         */
719
        public void addPopupMenu(PluginClassLoader loader, PopupMenu menu) {
720
                if (!SwingUtilities.isEventDispatchThread()) {
721
                        throw new RuntimeException("No Event Dispatch Thread");
722
                }
723

    
724
                String name = getName(menu.getName(), loader);
725

    
726
                //Se crea el control popupmenu
727
                JPopUpMenu popupMenu = (JPopUpMenu) popupMap.get(name);
728

    
729
                if (popupMenu == null) {
730
                        popupMenu = new JPopUpMenu(menu.getName());
731
                        popupMap.put(name, popupMenu);
732
                }
733

    
734
                // Se a�aden las entradas
735
                Menu[] menues = menu.getMenu();
736

    
737
                for (int i = 0; i < menues.length; i++) {
738
                        //Se registra y a�ade el menu
739
                        JMenuItem nuevoMenu = createJMenuItem(loader, menues[i]);
740

    
741
                        popupMenu.add(nuevoMenu);
742
                }
743
        }
744

    
745
        /**
746
         * DOCUMENT ME!
747
         *
748
         * @param loader
749
         * @param menu
750
         *
751
         * @return
752
         *
753
         * @throws RuntimeException DOCUMENT ME!
754
         */
755
        private JMenuItem createJMenuItem(PluginClassLoader loader, Menu menu) {
756
                JMenuItem nuevoMenu = null;
757

    
758
                PluginServices ps = PluginServices.getPluginServices(loader.getPluginName());
759
                String text = menu.getText();
760
                text = text.substring(text.lastIndexOf('/') + 1);
761
                String translatedText = ps.getText(text);
762

    
763
                if (menu.getIcon() != null) {
764
                        ImageIcon image = PluginServices.getIconTheme().get(menu.getIcon(),ps.getClassLoader());
765
                        if (image != null) {
766
                                nuevoMenu = new JMenuItem(translatedText, image);
767
                        } else {
768
                                nuevoMenu = new JMenuItem(translatedText, PluginServices.getIconTheme().get(noIcon));
769
                                logger.error(PluginServices.getText(this, "Unable_to_find_icon") +": "+menu.getIcon());
770
                        }
771
                } else {
772
                        nuevoMenu = new JMenuItem(translatedText);
773
                }
774
                nuevoMenu.setName(text);
775
                if (menu.getMnemonic() != null) {
776
                        if (menu.getMnemonic().length() != 1) {
777
                                throw new RuntimeException(
778
                                "Mnemonic must be 1 character length");
779
                        }
780

    
781
                        nuevoMenu.setMnemonic(KeyMapping.getKey(menu.getMnemonic().charAt(0)));
782
                }
783

    
784
                if (menu.getKey() != null) {
785
                        String osName = (String) System.getProperty("os.name");
786
                        boolean MAC_OS_X = osName.toLowerCase().startsWith("mac os x");
787
                        if (MAC_OS_X) {
788
                                //en OS X, en vez de hardwiring la ShortcutKey, usamos el default sugerido por el OS
789
                                nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping.getKey(
790
                                                menu.getKey().charAt(0)), Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
791
                        } else {
792
                                nuevoMenu.setAccelerator(KeyStroke.getKeyStroke(KeyMapping.getKey(
793
                                                menu.getKey().charAt(0)), ActionEvent.ALT_MASK));
794
                        }
795
                }
796

    
797
                nuevoMenu.setActionCommand(menu.getActionCommand());
798

    
799
                if (menu.getTooltip() != null) {
800
                        nuevoMenu.setToolTip(ps.getText(menu.getTooltip()));
801
                }
802

    
803
                if (menu.getEnableText() != null) {
804
                        nuevoMenu.setEnableText(ps.getText(menu.getEnableText()));
805
                }
806

    
807
                nuevoMenu.setEnabled(true);
808
                nuevoMenu.setVisible(true);
809

    
810
                return nuevoMenu;
811
        }
812

    
813
        /**
814
         * Muestra u oculta el menu de nombre 'name'
815
         *
816
         * @param name Nombre del menu que se quiere mostrar
817
         * @param x Evento de raton
818
         * @param y DOCUMENT ME!
819
         * @param c DOCUMENT ME!
820
         */
821
        private void showPopupMenu(String name, int x, int y, Component c) {
822
                JPopupMenu menu = (JPopupMenu) popupMap.get(name);
823

    
824
                if (menu != null) {
825
                        menu.show(c, x, y);
826
                }
827
        }
828

    
829
        /**
830
         * DOCUMENT ME!
831
         *
832
         * @param name DOCUMENT ME!
833
         * @param listener DOCUMENT ME!
834
         */
835
        public void removePopupMenuListener(String name, ActionListener listener) {
836
                JPopupMenu menu = (JPopupMenu) popupMap.get(name);
837

    
838
                if (menu != null) {
839
                        Component[] jmenuitems = menu.getComponents();
840

    
841
                        for (int i = 0; i < jmenuitems.length; i++) {
842
                                if (jmenuitems[i] instanceof JMenuItem) {
843
                                        ((JMenuItem) jmenuitems[i]).removeActionListener(listener);
844
                                }
845
                        }
846
                }
847
        }
848

    
849
        /**
850
         * DOCUMENT ME!
851
         *
852
         * @param popupName
853
         * @param c DOCUMENT ME!
854
         * @param listener
855
         * @param loader
856
         */
857
        public void addPopupMenuListener(String popupName, Component c,
858
                        ActionListener listener, PluginClassLoader loader) {
859
                final String name = getName(popupName, loader);
860

    
861
                JPopupMenu menu = (JPopupMenu) popupMap.get(name);
862

    
863
                if (menu != null) {
864
                        Component[] jmenuitems = menu.getComponents();
865

    
866
                        for (int i = 0; i < jmenuitems.length; i++) {
867
                                if (jmenuitems[i] instanceof JMenuItem) {
868
                                        ((JMenuItem) jmenuitems[i]).addActionListener(listener);
869
                                }
870
                        }
871
                }
872

    
873
                c.addMouseListener(new MouseAdapter() {
874
                        public void mousePressed(MouseEvent e) {
875
                                if (e.isPopupTrigger()) {
876
                                        showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
877
                                }
878
                        }
879

    
880
                        public void mouseReleased(MouseEvent e) {
881
                                if (e.isPopupTrigger()) {
882
                                        showPopupMenu(name, e.getX(), e.getY(), e.getComponent());
883
                                }
884
                        }
885
                });
886
        }
887

    
888
        /**
889
         * Loop on the controls to enable/disable and show/hide them, according to
890
         * its associated extension
891
         *
892
         * @throws RuntimeException DOCUMENT ME!
893
         */
894
        public void enableControls() {
895
                if (!SwingUtilities.isEventDispatchThread()) {
896
                        throw new RuntimeException("No Event Dispatch Thread");
897
                }
898

    
899
                Iterator e = classesExtensions.values().iterator();
900
                HashMap estadoExtensiones = new HashMap();
901
                HashMap visibilidadExtensiones = new HashMap();
902

    
903
                while (e.hasNext()) {
904
                        ExtensionDecorator ext = (ExtensionDecorator) e.next();
905

    
906
                        try {
907
                                if (estadoExtensiones.get(ext) == null) {
908
                                        boolean b;
909
                                        if (ext.getVisibility() == ExtensionDecorator.ALWAYS_VISIBLE)
910
                                                b = true;
911
                                        else if (ext.getVisibility() == ExtensionDecorator.ALWAYS_INVISIBLE)
912
                                                b = false;
913
                                        else {
914
                                                if (PluginServices.getExclusiveUIExtension() == null) {
915
                                                        b = ext.isVisible();
916
                                                } else {
917
                                                        b = PluginServices.getExclusiveUIExtension().isVisible(ext.getExtension());
918
                                                }
919
                                        }
920
                                        Boolean visible = new Boolean(b);
921
                                        Boolean enabled = new Boolean(false);
922

    
923
                                        if (visible.booleanValue()) {
924
                                                if (PluginServices.getExclusiveUIExtension() == null) {
925
                                                        enabled = new Boolean(ext.isEnabled());
926
                                                }else {
927
                                                        enabled = new Boolean(PluginServices.getExclusiveUIExtension().isEnabled(ext.getExtension()));
928
                                                }
929

    
930
                                        }
931

    
932
                                        estadoExtensiones.put(ext, enabled);
933
                                        visibilidadExtensiones.put(ext, visible);
934
                                }
935
                        } catch (Throwable e1) {
936
                                NotificationManager.addError(Messages.getString(
937
                                "MDIFrame.Error_no_capturado_por_el_usuario"), e1);
938
                                estadoExtensiones.put(ext, Boolean.FALSE);
939
                        }
940
                }
941

    
942
                // Enable or disable controls, according to its associated extensions
943
                e = controlClass.keySet().iterator();
944

    
945
                while (e.hasNext()) {
946
                        JComponent control = (JComponent) e.next();
947

    
948
                        try {
949
                                com.iver.andami.plugins.IExtension ext = (com.iver.andami.plugins.IExtension) classesExtensions.get((Class) controlClass.get(
950
                                                control));
951
                                boolean enabled = ((Boolean) estadoExtensiones.get(ext)).booleanValue();
952
                                boolean visible = ((Boolean) visibilidadExtensiones.get(ext)).booleanValue();
953
                                control.setEnabled(enabled);
954
                                control.setVisible(visible);
955
                        } catch (Exception ex) {
956
                                control.setEnabled(false);
957
                                control.setVisible(false);
958
                        }
959
                }
960

    
961
                // Loop in the menus to hide the menus that don't have visible children
962
                for (int i = 0; i < menuBar.getMenuCount(); i++) {
963
                        MenuElement menu = menuBar.getMenu(i);
964
                        hideMenus(menu);
965
                        hideSeparators(menu);
966
                }
967

    
968
                // hide the toolbars that don't contain any visible tool
969
                Iterator it = toolBarMap.values().iterator();
970

    
971
                while (it.hasNext()) {
972
                        SelectableToolBar t = (SelectableToolBar) it.next();
973
                        boolean todosOcultos = true;
974

    
975
                        for (int i = 0; i < t.getComponentCount(); i++) {
976
                                if (!(t.getComponent(i) instanceof JSeparator) // separators don't matter
977
                                                && t.getComponent(i).isVisible()) {
978
                                        todosOcultos = false;
979
                                }
980
                        }
981

    
982
                        if (todosOcultos) {
983
                                t.setVisible(false);
984
                        }
985
                        else {
986
                                t.setVisible(t.getAndamiVisibility());
987
                        }
988
                }
989

    
990
                if (mdiManager != null) {
991
                        JPanel f = (JPanel) mdiManager.getActiveWindow();
992

    
993
                        if (f != null) {
994
                                if (lastLabelClass != f.getClass()) {
995
                                        lastLabelClass = f.getClass();
996

    
997
                                        Label[] lbls = (Label[]) classLabels.get(lastLabelClass);
998

    
999
                                        if (lbls != null) {
1000
                                                bEstado.setLabelSet(lbls);
1001
                                        }
1002
                                }
1003
                        }
1004
                }
1005

    
1006
                ajustarToolBar();
1007

    
1008
                showMemory();
1009
        }
1010

    
1011
        /**
1012
         * Establece la visibilidad de un menu y todos sus descendientes en la
1013
         * jerarquia teniendo en cuenta la visibilidad de todos los submenus.
1014
         *
1015
         * @param menu Menu que se quiere visualizar
1016
         *
1017
         * @return Devuelve true si el menu es visible y false en caso contrario
1018
         */
1019
        private boolean hideMenus(MenuElement menu) {
1020
                MenuElement[] submenus = menu.getSubElements();
1021

    
1022
                //Si no tiene hijos se devuelve su visibilidad
1023
                if (submenus.length == 0) {
1024
                        return menu.getComponent().isVisible();
1025
                }
1026

    
1027
                /*
1028
                 * Si tiene hijos se devuelve true si alg�no de ellos es visible,
1029
                 * pero se itera por todos ellos
1030
                 */
1031
                boolean visible = false;
1032

    
1033
                for (int i = 0; i < submenus.length; i++) {
1034
                        if (hideMenus(submenus[i])) {
1035
                                if (!(menu instanceof JPopupMenu)) {
1036
                                        menu.getComponent().setVisible(true);
1037
                                }
1038

    
1039
                                visible = true;
1040
                        }
1041
                }
1042

    
1043
                if (visible) {
1044
                        return true;
1045
                }
1046

    
1047
                menu.getComponent().setVisible(false);
1048

    
1049
                return false;
1050
        }
1051

    
1052
        /**
1053
         * Recurse through all menu elements and make sure there are no
1054
         * redundant separators.
1055
         * This method will make sure that a separator only becomes visible
1056
         * if at least one visible non-separator menu entry preceeded it.
1057
         */ 
1058
        private void hideSeparators(MenuElement menu) {
1059

    
1060
                // flag that indicates whether a separator is to be displayed or not
1061
                boolean        allowSeparator;
1062

    
1063
                if (menu instanceof JMenu) {
1064
                        allowSeparator = false; // separator not allowed as very first menu item
1065
                        Component[] comps = ((JMenu)menu).getMenuComponents(); 
1066
                        for (int i=0; i < comps.length; i++) {
1067
                                if (comps[i] instanceof JSeparator){
1068
                                        // got a separator: display only if allowed at this position 
1069
                                        if (allowSeparator == true) {
1070
                                                // look at all successive menu entries to make sure that at least one 
1071
                                                // is visible and not a separator (otherwise, this separator would 
1072
                                                // be the last visible item in this menu) -- we don't want that 
1073
                                                comps[i].setVisible( false );
1074
                                                for ( int j = i; j < comps.length; j ++ ) {
1075
                                                        if ( !(comps[j] instanceof JSeparator)) {
1076
                                                                if ( comps[j].isVisible() ) {
1077
                                                                        comps[i].setVisible(true); // display separator! 
1078
                                                                        break;
1079
                                                                }
1080
                                                        }
1081
                                                }
1082
                                        } else {
1083
                                                comps[i].setVisible(false);
1084
                                        } allowSeparator = false; // separator is not allowed right after another separator
1085
                                }else{
1086
                                        if (comps[i] instanceof JMenu) { 
1087
                                                // got a submenu: recurse through it
1088
                                                hideSeparators ( ((MenuElement)comps[i]) ); if ( comps[i].isVisible() ) {
1089
                                                        allowSeparator = true; // separators are OK after visible submenus
1090
                                                }
1091
                                        } else {
1092
                                                if ( comps[i].isVisible() ) {
1093
                                                        allowSeparator = true; // separators are OK after regular, visible entries
1094
                                                }
1095
                                        }
1096
                                }
1097
                        }
1098
                }
1099
        }
1100

    
1101
        /**
1102
         * Muestra la memoria consumida por el programa
1103
         */
1104
        private void showMemory() {
1105
                Runtime r = Runtime.getRuntime();
1106
                long mem = r.totalMemory() - r.freeMemory();
1107
                logger.debug(PluginServices.getText(this, "memory_usage") + " " + mem/1024 +" KB");
1108
        }
1109

    
1110
        /**
1111
         * DOCUMENT ME!
1112
         *
1113
         * @return
1114
         */
1115
        public MDIManager getMDIManager() {
1116
                return mdiManager;
1117
        }
1118

    
1119
        /**
1120
         * Establece el mensaje en la barra de estado asociado a una etiqueta
1121
         *
1122
         * @return DOCUMENT ME!
1123
         */
1124
        public NewStatusBar getStatusBar() {
1125
                return bEstado;
1126
        }
1127
        /**
1128
         * You can use this function to select the appropiate
1129
         * tool inside the toolbars
1130
         */
1131
        public void setSelectedTool(String actionCommand)
1132
        {
1133
                setSelectedTool(defaultGroup, actionCommand);
1134
        }
1135

    
1136
        /**
1137
         * You can use this function to select the appropiate
1138
         * tool inside the toolbars
1139
         */
1140
        public void setSelectedTool(String groupName, String actionCommand)
1141
        {
1142
                ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1143
                if (group==null)
1144
                        return;
1145

    
1146
                Enumeration enumeration = group.getElements();
1147
                while (enumeration.hasMoreElements()) {
1148
                        AbstractButton button = (AbstractButton) enumeration.nextElement();
1149
                        if (button.getActionCommand().equals(actionCommand)) {
1150
                                button.setSelected(true);
1151
                        }
1152
                }
1153

    
1154
                selectedTool.put(groupName, actionCommand);
1155
        }
1156

    
1157
        /**
1158
         * You can use this function to select the appropiate
1159
         * tool inside the toolbars
1160
         */
1161
        public void setSelectedTools(HashMap selectedTools)
1162
        {
1163
                selectedTool = selectedTools;
1164
                if (selectedTools==null) return;
1165
                Iterator groupNames = selectedTools.keySet().iterator();
1166
                while (groupNames.hasNext()) {
1167
                        try {
1168
                                String groupName = (String) groupNames.next();
1169
                                ButtonGroup group = (ButtonGroup) buttonGroupMap.get(groupName);
1170
                                Enumeration enumeration = group.getElements();
1171
                                String actionCommand = (String) selectedTools.get(groupName);
1172
                                if (actionCommand==null) continue;
1173
                                while (enumeration.hasMoreElements()) {
1174
                                        AbstractButton button = (AbstractButton) enumeration.nextElement();
1175
                                        if (button.getActionCommand().equals(actionCommand)) {
1176
                                                button.setSelected(true);
1177
                                        }
1178
                                }
1179
                        }
1180
                        catch (ClassCastException ex) {
1181
                                logger.error("selectedTool should only contain pairs (String groupName, JToolBarToggleButton button)");
1182
                        }
1183
                }
1184
        }
1185

    
1186
        /**
1187
         * DOCUMENT ME!
1188
         *
1189
         * @param clase
1190
         * @param label
1191
         */
1192
        public void setStatusBarLabels(Class clase, Label[] label) {
1193
                classLabels.put(clase, label);
1194
        }
1195

    
1196
        public void removeStatusBarLabels(Class clase) {
1197
                classLabels.remove(clase);
1198
        }
1199

    
1200
        public void addStatusBarControl(Class extensionClass, IControl control) {
1201
                control.addActionListener(this);
1202
                bEstado.addControl(control.getName(), (Component)control);
1203
                controlClass.put(control, extensionClass);
1204
        }
1205

    
1206
        public void removeStatusBarControl(String name) {
1207
                Component c = bEstado.removeControl(name);
1208
                if (c!=null)
1209
                        controlClass.remove(c);
1210
        }
1211

    
1212
        /**
1213
         * @see com.iver.andami.ui.mdiFrame.MainFrame#removeMenu(com.iver.andami.plugins.config.generate.Menu)
1214
         */
1215
        public void removeMenu(Menu menu) {
1216
                JMenuItem delete = (JMenuItem) infoCodedMenus.get(menu);
1217

    
1218
                if (delete == null) {
1219
                        throw new NoSuchElementException(menu.getText());
1220
                }
1221

    
1222
                delete.getParent().remove(delete);
1223
                infoCodedMenus.remove(menu);
1224
        }
1225

    
1226
        /**
1227
         * @see com.iver.andami.ui.mdiFrame.MainFrame#addMenu(com.iver.andami.plugins.config.generate.Menu,
1228
         *                 java.awt.event.ActionListener, PluginClassLoader)
1229
         */
1230
        public void addMenu(Menu menu, ActionListener listener,
1231
                        PluginClassLoader loader) {
1232
                JMenu menuPadre = createMenuAncestors(menu, loader);
1233

    
1234
                //Se registra y a�ade el menu
1235
                JMenuItem nuevoMenu = createJMenuItem(loader, menu);
1236
                nuevoMenu.addMouseListener(tooltipListener);
1237
                nuevoMenu.addActionListener(listener);
1238
                menuPadre.add(nuevoMenu);
1239

    
1240
                infoCodedMenus.put(menu, nuevoMenu);
1241
        }
1242

    
1243
        /**
1244
         * @see com.iver.andami.ui.mdiFrame.MainFrame#changeMenuName(java.lang.String[],
1245
         *                 String, com.iver.andami.plugins.PluginClassLoader)
1246
         */
1247
        public void changeMenuName(String[] menu, String newName,
1248
                        PluginClassLoader loader) {
1249

    
1250
                ArrayList menuList = new ArrayList();
1251
                for (int i = 0; i < menu.length; i++) {
1252
                        menuList.add(menu[i]);
1253
                }
1254

    
1255
                javax.swing.JMenuItem newMenu = getMenu(menuList, menuBar);
1256
                if (newMenu==null) {
1257
                        throw new NoSuchMenuException(menu[0]);
1258
                }
1259
                else {
1260
                        newMenu.setText(PluginServices.getText(this, newName));
1261
                }
1262
        }
1263

    
1264
        /**
1265
         * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
1266
         */
1267
        public void componentHidden(ComponentEvent arg0) {
1268
        }
1269

    
1270
        /**
1271
         * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
1272
         */
1273
        public void componentMoved(ComponentEvent arg0) {
1274
        }
1275

    
1276
        /**
1277
         * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
1278
         */
1279
        public void componentResized(ComponentEvent arg0) {
1280
                ajustarToolBar();
1281
        }
1282

    
1283
        /**
1284
         * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
1285
         */
1286
        public void componentShown(ComponentEvent arg0) {
1287
        }
1288

    
1289
        /**
1290
         * @see java.awt.event.ContainerListener#componentAdded(java.awt.event.ContainerEvent)
1291
         */
1292
        public void componentAdded(ContainerEvent arg0) {
1293
                ajustarToolBar();
1294
        }
1295

    
1296
        /**
1297
         * @see java.awt.event.ContainerListener#componentRemoved(java.awt.event.ContainerEvent)
1298
         */
1299
        public void componentRemoved(ContainerEvent arg0) {
1300
                ajustarToolBar();
1301
        }
1302

    
1303
        /**
1304
         * DOCUMENT ME!
1305
         *
1306
         * @author $author$
1307
         * @version $Revision: 32707 $
1308
         */
1309
        public class TooltipListener extends MouseAdapter {
1310
                /**
1311
                 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
1312
                 */
1313
                public void mouseEntered(MouseEvent e) {
1314
                        JComponent control = (JComponent) e.getSource();
1315
                        EnableTextSupport ets = (EnableTextSupport) e.getSource();
1316

    
1317
                        String texto = null;
1318
                        texto = control.getToolTipText();
1319

    
1320
                        if (texto != null) {
1321
                                bEstado.setInfoTextTemporal(texto);
1322
                        }
1323
                }
1324

    
1325
                /**
1326
                 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
1327
                 */
1328
                public void mouseExited(MouseEvent arg0) {
1329
                        bEstado.restaurarTexto();
1330
                }
1331

    
1332
                /**
1333
                 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
1334
                 */
1335
                public void mousePressed(MouseEvent e) {
1336
                        bEstado.restaurarTexto();
1337
                }
1338
        }
1339
        public String getTitlePrefix() {
1340
                return titlePrefix;
1341
        }
1342
        public void setTitlePrefix(String titlePrefix) {
1343
                this.titlePrefix = titlePrefix;
1344
        }
1345

    
1346
        public HashMap getSelectedTools() {
1347
                return selectedTool;
1348
        }
1349

    
1350
        public HashMap getInitialSelectedTools() {
1351
                return initialSelectedTools;
1352
        }
1353

    
1354

    
1355
        /**
1356
         * Get a previously added JComponent by name. For example
1357
         * you can use it if you need to obtain a JToolBar to
1358
         * add some customized component.
1359
         * @param name
1360
         * @return the JComponent or null if none has been found
1361
         */
1362
        public JComponent getComponentByName(String name)
1363
        {
1364
                Iterator e = controlClass.keySet().iterator();
1365

    
1366
                while (e.hasNext()) {
1367
                        JComponent control = (JComponent) e.next();
1368
                        String nameCtrl = control.getName();
1369
                        if (nameCtrl != null)
1370
                        {
1371
                                if (nameCtrl.compareTo(name) == 0)
1372
                                        return control;
1373
                        }
1374
                }
1375
                Iterator it = toolBarMap.values().iterator();
1376
                while (it.hasNext()) {
1377
                        SelectableToolBar t = (SelectableToolBar) it.next();
1378
                        String nameCtrl = t.getName();
1379
                        if (nameCtrl != null)
1380
                                if (nameCtrl.compareTo(name) == 0)
1381
                                        return t;
1382

    
1383
                }
1384

    
1385
                return null;
1386
        }
1387

    
1388
        public SelectableToolBar[] getToolbars() {
1389
                return (SelectableToolBar[]) toolBarMap.values().toArray(new SelectableToolBar[0]);
1390
        }
1391

    
1392
        public boolean getToolbarVisibility(String name) {
1393
                JComponent component = PluginServices.getMainFrame().getComponentByName(name);
1394
                if (component!=null && component instanceof SelectableToolBar) {
1395
                        SelectableToolBar toolBar = (SelectableToolBar) component;
1396
                        return toolBar.getAndamiVisibility();
1397
                }
1398
                return false;
1399
        }
1400

    
1401
        public boolean setToolbarVisibility(String name, boolean visibility) {
1402
                JComponent component = PluginServices.getMainFrame().getComponentByName(name);
1403
                if (component!=null && component instanceof SelectableToolBar) {
1404
                        SelectableToolBar toolBar = (SelectableToolBar) component;
1405
                        boolean oldVisibility = toolBar.getAndamiVisibility();
1406
                        toolBar.setAndamiVisibility(visibility);
1407
                        enableControls();
1408
                        return oldVisibility;
1409
                }
1410
                return false;
1411
        }
1412

    
1413
        public javax.swing.JMenuItem getMenuEntry(String[] menuPath) {
1414
                ArrayList menu = new ArrayList();
1415
                for (int i=0; i<menuPath.length; i++)
1416
                        menu.add(menuPath[i]);
1417
                return getMenu(menu, menuBar);
1418
        }
1419
}