Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / ui / mdiFrame / NewStatusBar.java @ 38780

History | View | Annotate | Download (23.1 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.andami.ui.mdiFrame;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.awt.Dimension;
27
import java.awt.FlowLayout;
28
import java.awt.LayoutManager;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.awt.event.MouseEvent;
32
import java.awt.event.MouseListener;
33
import java.util.HashMap;
34
import java.util.Map;
35

    
36
import javax.swing.BorderFactory;
37
import javax.swing.ImageIcon;
38
import javax.swing.JLabel;
39
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
41
import javax.swing.JPopupMenu;
42
import javax.swing.JProgressBar;
43
import javax.swing.SwingConstants;
44
import javax.swing.SwingUtilities;
45
import javax.swing.Timer;
46
import javax.swing.border.BevelBorder;
47

    
48
import org.gvsig.andami.IconThemeHelper;
49
import org.gvsig.andami.PluginServices;
50
import org.gvsig.andami.messages.Messages;
51
import org.gvsig.andami.plugins.config.generate.Label;
52
import org.gvsig.gui.beans.controls.IControl;
53
import org.gvsig.tools.swing.api.ToolsSwingLocator;
54
import org.gvsig.tools.swing.api.task.JTasksStatus;
55
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
57

    
58
/**
59
 * <p>
60
 * This class contains the status bar. It contains the graphical component, and
61
 * the methods to manage it.
62
 * </p>
63
 * 
64
 * <p>
65
 * The status bar is divided in several areas. At the very left, there is an
66
 * icon and the main status text. There are three icons to show: Info, Warning
67
 * and Error icons. They can be set together with the main status text using the
68
 * methods <code>setInfoText()</code>, <code>setWarningText()</code> and
69
 * <code>setErrorText()</code> (and also with <code>setInfoTextTemporal()</code>
70
 * , etc). Then, there is a right area which contains labels and other controls.
71
 * Labels are set in the config.xml files and are visible or not depending on
72
 * the currently selected Andami window. Controls are associated to extensions,
73
 * and are enabled/disabled and visible/hidden depending on the associated
74
 * extension.
75
 * </p>
76
 * 
77
 */
78
public class NewStatusBar extends JPanel {
79

    
80
    private static final long serialVersionUID = 5575549032728844632L;
81
    
82
    private static Logger logger = LoggerFactory.getLogger(NewStatusBar.class);
83
    
84
    private static final int INFO = 0;
85
    private static final int WARNING = 1;
86
    private static final int ERROR = 2;
87
    private JLabel lblIcon = null;
88
    private JLabel lblTexto = null;
89
    private boolean contenidoTemporal;
90
    private String textoAnterior;
91
    private int estadoAnterior;
92
    private int estado;
93
    private JProgressBar progressBar = null;
94
    private Map<String, JLabel> idLabel = new HashMap<String, JLabel>();
95
    private int[] widthlabels = null;
96
    private Map<String, Component> controls = new HashMap<String, Component>();
97
    private JPanel controlContainer;
98
    private JTasksStatus tasksStatus = null;
99
        private Timer messageTimer;
100

    
101
        private String textoCompleto;
102

    
103
        
104
    /**
105
     * This is the default constructor
106
     */
107
    public NewStatusBar() {
108
        super();
109
        initialize();
110
    }
111

    
112
        private ImageIcon getImageIcon(String iconName) {
113
//                return PluginServices.getIconTheme().get(iconName);
114
                return IconThemeHelper.getImageIcon(iconName);
115
        }
116
        
117

    
118
    /**
119
     * This method initializes the status bar. It creates the required
120
     * containers and sets the layout.
121
     */
122
    private void initialize() {
123
        LayoutManager mainLayout = new BorderLayout();
124
        this.setLayout(mainLayout);
125

    
126
        JPanel panelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0));
127

    
128
        controlContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0));
129
        panelRight.add(controlContainer);
130
        panelRight.add(getTasksStatus());
131

    
132
        lblIcon = new JLabel();
133
        lblTexto = new JLabel();
134
        lblTexto.setAlignmentX(JLabel.LEFT_ALIGNMENT);
135
        lblTexto.setHorizontalAlignment(SwingConstants.LEFT);
136
        lblTexto.setHorizontalTextPosition(SwingConstants.LEFT);
137
        lblTexto.setVerticalAlignment(SwingConstants.CENTER);
138
        lblTexto.setVerticalTextPosition(SwingConstants.CENTER);
139
        lblIcon.setText("");
140
        lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada"));
141

    
142
        JPanel panelLeft = new JPanel();
143
        panelLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0));
144
        panelLeft.add(lblIcon);
145
        panelLeft.add(lblTexto);
146
        panelLeft.add(getProgressBar());
147

    
148
        this.add(panelLeft, BorderLayout.CENTER);
149
        this.add(panelRight, BorderLayout.EAST);
150

    
151
        buildMesagePopupMenu();
152
        
153
        messageTimer = new Timer(30000, new ActionListener() {
154
                        public void actionPerformed(ActionEvent e) {
155
                                try {
156
                                        clearMessage();
157
                                } catch( Throwable ex) {
158
                                        logger.info("Can't clear message", ex);
159
                                }
160
                        }
161
                });
162
    }
163
    
164
    public void clearMessage() {
165
            this.textoCompleto = "";
166
            lblTexto.setText("");
167
            lblIcon.setIcon(null);
168
            estado = INFO;
169
    }
170

    
171
    
172
    public void message(final String msg, final int messageTyoe) {
173
        if (!SwingUtilities.isEventDispatchThread()) {
174
            SwingUtilities.invokeLater(new Runnable() {
175
                public void run() {
176
                        message(msg,messageTyoe);
177
                }
178
            });
179
            return;
180
        }
181
        messageTimer.stop();
182
            switch (messageTyoe) {
183
                case JOptionPane.ERROR_MESSAGE:
184
                        setErrorText(msg);
185
                        break;
186
                case JOptionPane.WARNING_MESSAGE:
187
                        setWarningText(msg);
188
                        break;
189
                default:
190
                case JOptionPane.INFORMATION_MESSAGE:
191
                        setInfoText(msg);
192
                        break;
193
                }
194
            messageTimer.start();
195
        }
196

    
197
    private void buildMesagePopupMenu() {
198
            final JPopupMenu menu = new JPopupMenu();
199
            
200
            JMenuItem item = new JMenuItem("View details");
201
            item.addActionListener(new ActionListener() {
202
                        public void actionPerformed(ActionEvent arg0) {
203
                                switch (estado) {
204
                                default:
205
                                case INFO:
206
                                        JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.INFORMATION_MESSAGE);
207
                                        break;
208
                                case WARNING:
209
                                        JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.WARNING_MESSAGE);
210
                                        break;
211
                                case ERROR:
212
                                        JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.ERROR_MESSAGE);
213
                                        break;
214
                                }
215
                        }
216
                });
217
            menu.add(item);
218
            item = new JMenuItem("Clear");
219
            item.addActionListener(new ActionListener() {
220
                        public void actionPerformed(ActionEvent e) {
221
                                clearMessage();
222
                        }
223
                });
224
            menu.add(item);
225
            menu.addSeparator();
226
            item = new JMenuItem("Cancel");
227
            menu.add(item);
228
            
229
            this.lblTexto.addMouseListener( new MouseListener() {
230
                        public void mouseReleased(MouseEvent e) {
231
                                if( e.isPopupTrigger() ) {
232
                                        if( getStatusText().length() > 0 || estado!=INFO ) {
233
                                                menu.show(lblTexto, e.getX(), e.getY());
234
                                        }
235
                                }
236
                        }
237
                        public void mousePressed(MouseEvent e) {
238
                                if( e.isPopupTrigger() ) {
239
                                        if( getStatusText().length() > 0 || estado!=INFO ) {
240
                                                menu.show(lblTexto, e.getX(), e.getY());
241
                                        }
242
                                }
243
                        }
244
                        public void mouseExited(MouseEvent e) {
245
                        }
246
                        public void mouseEntered(MouseEvent e) {
247
                        }
248
                        public void mouseClicked(MouseEvent e) {
249
                        }
250
                });
251
    }
252
    
253
    /**
254
     * Gets the status bar main text.
255
     * 
256
     * @return The status bar main text.
257
     * @see #setInfoText(String)
258
     * @see #setWarningText(String)
259
     * @see #setErrorText(String)
260
     * @see #setInfoTextTemporal(String)
261
     * @see #setWarningTextTemporal(String)
262
     * @see #setErrorTextTemporal(String)
263
     */
264
    public String getStatusText() {
265
        return textoCompleto; //lblTexto.getText();
266
    }
267

    
268
    /**
269
     * Restores the previous contents in the status bar main text,
270
     * after the {@link #setInfoTextTemporal(String)},
271
     * {@link #setWarningTextTemporal(String)} or
272
     * {@link #setErrorTextTemporal(String)} have been called.
273
     * 
274
     * @see #setInfoTextTemporal(String)
275
     * @see #setWarningTextTemporal(String)
276
     * @see #setErrorTextTemporal(String)
277
     */
278
    public void restaurarTexto() {
279
        contenidoTemporal = false;
280

    
281
        if (estadoAnterior == -1) {
282
            return;
283
        }
284

    
285
        switch (estadoAnterior) {
286
        case INFO:
287
            setInfoText(textoAnterior);
288

    
289
            break;
290

    
291
        case WARNING:
292
            setWarningText(textoAnterior);
293

    
294
            break;
295

    
296
        case ERROR:
297
            setErrorText(textoAnterior);
298

    
299
            break;
300
        }
301

    
302
        estadoAnterior = -1;
303
        textoAnterior = null;
304
    }
305

    
306
    /**
307
     * Sets a temporary information message in the status bar, and changes the
308
     * icon to an Info icon. The previous text and icon can be restored using
309
     * the {@link #restaurarTexto()} method.
310
     * 
311
     * @param texto
312
     *            The text to set
313
     * @see #restaurarTexto()
314
     */
315
    public void setInfoTextTemporal(final String texto) {
316
        if (!SwingUtilities.isEventDispatchThread()) {
317
            SwingUtilities.invokeLater(new Runnable() {
318
                public void run() {
319
                        setInfoTextTemporal(texto);
320
                }
321
            });
322
            return;
323
        }
324
        if (!contenidoTemporal) {
325
            textoAnterior = getStatusText();
326
            estadoAnterior = this.estado;
327
            contenidoTemporal = true;
328
        }
329

    
330
        this.estado = INFO;
331
        lblIcon.setIcon(getImageIcon("statusbar-info"));
332
        lblTexto.setText(texto);
333
    }
334

    
335
    /**
336
     * Sets a temporary warning message in the status bar, and changes the
337
     * icon to a Warning icon. The previous text and icon can be restored using
338
     * the {@link #restaurarTexto()} method.
339
     * 
340
     * @param texto
341
     *            The text to set
342
     * @see #restaurarTexto()
343
     */
344
    public void setWarningTextTemporal(final String texto) {
345
        if (!SwingUtilities.isEventDispatchThread()) {
346
            SwingUtilities.invokeLater(new Runnable() {
347
                public void run() {
348
                        setWarningTextTemporal(texto);
349
                }
350
            });
351
            return;
352
        }
353
              
354
        if (!contenidoTemporal) {
355
            estadoAnterior = this.estado;
356
            textoAnterior = getStatusText();
357
            contenidoTemporal = true;
358
        }
359
        this.estado = WARNING;
360
        lblIcon.setIcon(getImageIcon("statusbar-warning"));
361
        lblTexto.setText(texto);
362
    }
363

    
364
    /**
365
     * Sets a temporary error message in the status bar, and changes the
366
     * icon to an Error icon. The previous text and icon can be restored using
367
     * the {@link #restaurarTexto()} method.
368
     * 
369
     * @param texto
370
     *            The text to set
371
     * @see #restaurarTexto()
372
     */
373
    public void setErrorTextTemporal(final String texto) {
374
        if (!SwingUtilities.isEventDispatchThread()) {
375
            SwingUtilities.invokeLater(new Runnable() {
376
                public void run() {
377
                        setErrorTextTemporal(texto);
378
                }
379
            });
380
            return;
381
        }
382
       if (!contenidoTemporal) {
383
            estadoAnterior = this.estado;
384
            textoAnterior = getStatusText();
385
            contenidoTemporal = true;
386
        }
387

    
388
        this.estado = ERROR;
389
        lblIcon.setIcon(getImageIcon("statusbar-error"));
390
        lblTexto.setText(texto);
391
    }
392

    
393
    /**
394
     * Sets a permanent info message in the status bar, and changes the
395
     * permanent icon to an Info icon. If there is a temporary message showing
396
     * at the moment, the message set now is not shown until
397
     * the {@link #restaurarTexto()} method is called.
398
     * 
399
     * @param texto
400
     *            The permanent info message to set
401
     * @see #restaurarTexto()
402
     */
403
    public void setInfoText(final String texto) {
404
        if (!SwingUtilities.isEventDispatchThread()) {
405
            SwingUtilities.invokeLater(new Runnable() {
406
                public void run() {
407
                        setInfoText(texto);
408
                }
409
            });
410
            return;
411
        }
412
        if (contenidoTemporal) {
413
            textoAnterior = texto;
414
            estadoAnterior = INFO;
415
        } else {
416
                this.textoCompleto = texto; 
417
            lblTexto.setText(getFirstTextLine(texto));
418
            lblIcon.setIcon(getImageIcon("statusbar-info"));
419
            estado = INFO;
420
        }
421
    }
422
    
423
    private String getFirstTextLine(String text) {
424
            int n = text.indexOf("\n");
425
            if( n == -1 ) {
426
                    return text;
427
            }
428
            return text.substring(0,n) + "...";
429
    }
430

    
431
    /**
432
     * Sets a permanent warning message in the status bar, and changes the
433
     * permanent icon to a Warning icon. If there is a temporary message showing
434
     * at the moment, the message set now is not shown until
435
     * the {@link #restaurarTexto()} method is called.
436
     * 
437
     * @param texto
438
     *            The permanent warning message to set
439
     * @see #restaurarTexto()
440
     */
441
    public void setWarningText(final String texto) {
442
        if (!SwingUtilities.isEventDispatchThread()) {
443
            SwingUtilities.invokeLater(new Runnable() {
444
                public void run() {
445
                        setWarningText(texto);
446
                }
447
            });
448
            return;
449
        }
450
        
451
        if (contenidoTemporal) {
452
            textoAnterior = texto;
453
            estadoAnterior = WARNING;
454
        } else {
455
                this.textoCompleto = texto; 
456
            lblTexto.setText(getFirstTextLine(texto));
457
            lblIcon.setIcon(getImageIcon("statusbar-warning"));
458
            estado = WARNING;
459
        }
460
    }
461

    
462
    /**
463
     * Sets a permanent error message in the status bar, and changes the
464
     * permanent icon to an Error icon. If there is a temporary message showing
465
     * at the moment, the message set now is not shown until
466
     * the {@link #restaurarTexto()} method is called.
467
     * 
468
     * @param texto
469
     *            The permanent info message to set
470
     * @see #restaurarTexto()
471
     */
472
    public void setErrorText(final String texto) {
473
        if (!SwingUtilities.isEventDispatchThread()) {
474
            SwingUtilities.invokeLater(new Runnable() {
475
                public void run() {
476
                        setErrorText(texto);
477
                }
478
            });
479
            return;
480
        }
481

    
482
        if (contenidoTemporal) {
483
            textoAnterior = texto;
484
            estadoAnterior = ERROR;
485
        } else {
486
                this.textoCompleto = texto; 
487
            lblTexto.setText(getFirstTextLine(texto));
488
            lblIcon.setIcon(getImageIcon("statusbar-error"));
489
            estado = ERROR;
490
        }
491
    }
492

    
493
    /**
494
     * If <code>p</code> is a value between 0 and 99, it shows a progress bar
495
     * in the left area of the status bar, and sets the specified progress.
496
     * If <code>p</code> is bigger than 99, it hides the progress bar.
497
     * 
498
     * @param p
499
     *            The progress to set in the progress bar. If it is bigger
500
     *            than 99, the task will be considered to be finished, and the
501
     *            progress bar will be hidden.
502
     * 
503
     * @deprecated use instead TaskStatus and TaskStatusManager
504
     */
505
    public void setProgress(int p) {
506
        if (p < 100) {
507
            getProgressBar().setValue(p);
508
            getProgressBar().setVisible(true);
509
        } else {
510
            getProgressBar().setVisible(false);
511
        }
512

    
513
        getProgressBar().repaint();
514
    }
515

    
516
    /**
517
     * Sets a label-set to be shown in the status bar. This method it is not
518
     * intended to be used directly, because the set will be overwritten when
519
     * the selected
520
     * window changes. Use {@link MainFrame#setStatusBarLabels(Class, Label[])}
521
     * to permanently associate a label set with a window.
522
     * 
523
     * @param labels
524
     *            The labels to set.
525
     * @see MainFrame#setStatusBarLabels(Class, Label[])
526
     */
527
    public void setLabelSet(Label[] labels) {
528
        removeAllLabels();
529
        idLabel.clear();
530

    
531
        for (int i = 0; i < labels.length; i++) {
532
            // Set an initial text so the getPreferredSize works as expected
533
            JLabel lbl = new JLabel();
534
            lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
535
            lbl.setName(labels[i].getId());
536
            controlContainer.add(lbl);
537

    
538
            /*
539
             * if (i != labels.length - 1){
540
             * this.add(new JSeparator(JSeparator.VERTICAL));
541
             * }
542
             */
543
            idLabel.put(labels[i].getId(), lbl);
544
        }
545

    
546
        JLabel[] configlabels =
547
            (JLabel[]) idLabel.values().toArray(new JLabel[0]);
548
        widthlabels = new int[configlabels.length];
549

    
550
        for (int i = 0; i < labels.length; i++) {
551
            widthlabels[i] = configlabels[i].getWidth();
552
        }
553

    
554
        this.validate();
555
    }
556

    
557
    /**
558
     * Hides the empty labels and adjust the space in the bar.
559
     */
560
    public void ajustar() {
561
        if (widthlabels == null) {
562
            return;
563
        }
564

    
565
        JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
566

    
567
        /*
568
         * double total = 1;
569
         * for (int i = 0; i < widthlabels.length; i++) {
570
         * if (labels[i].getText().compareTo("") != 0) {
571
         * total += widthlabels[i];
572
         * }
573
         * }
574
         * double p = (ws - lblTexto.getWidth() - 20) / total;
575
         */
576
        for (int i = 0; i < labels.length; i++) {
577
            JLabel label = (JLabel) labels[i];
578

    
579
            if (label.getText().compareTo("") != 0) {
580
                label.setVisible(true);
581
            } else {
582
                label.setVisible(false);
583
            }
584
        }
585
        validate();
586
    }
587

    
588
    /**
589
     * Removes all the labels from the status bar. It does not remove the
590
     * controls.
591
     */
592
    private void removeAllLabels() {
593
        Component[] controlArray = controlContainer.getComponents();
594

    
595
        for (int i = 0; i < controlArray.length; i++) {
596
            if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)
597
                && !(controlArray[i] instanceof IControl)
598
                && (controlArray[i] instanceof JLabel)) {
599
                controlContainer.remove(controlArray[i]);
600
            }
601
        }
602
    }
603

    
604
    /**
605
     * Sets the text of the provided label.
606
     * 
607
     * @param id
608
     *            The ID of the label to modify. It is defined in the
609
     *            config.xml file
610
     * @param msg
611
     *            The message to show in the label
612
     */
613
    public void setMessage(final String id, final String msg) {
614
        if (!SwingUtilities.isEventDispatchThread()) {
615
            SwingUtilities.invokeLater(new Runnable() {
616
                public void run() {
617
                        setMessage(id, msg);
618
                }
619
            });
620
            return;
621
        }
622

    
623
        JLabel lbl = (JLabel) idLabel.get(id);
624

    
625
        if (lbl != null) {
626
                Dimension originalPreferredSize = lbl.getPreferredSize();
627
            lbl.setText(msg);
628
            // Set preferred size to null just in case it has been set
629
            // previously, as we want it to be calculated from the text size.
630
            lbl.setPreferredSize(null);
631
            // Allow only to increase label width, to avoid too much ugly 
632
            // width changes in the status bar components.
633
            if (lbl.getPreferredSize().width < originalPreferredSize.width) {
634
                    lbl.setPreferredSize(originalPreferredSize);
635
            }
636
        } else {
637
            // try with controls
638
            try {
639
                IControl control = (IControl) controls.get(id);
640
                if (control != null)
641
                    control.setValue(msg);
642
            } catch (ClassCastException ex) {
643
                logger.debug("no label called " + id);
644
            }
645
        }
646

    
647
        ajustar();
648
    }
649

    
650
    /**
651
     * Sets the control identified by 'id' with the provided value.
652
     * 
653
     * @param id
654
     *            The ID of the control to modify
655
     * @param value
656
     *            The value to set in the control
657
     */
658
    public void setControlValue(String id, String value) {
659
        IControl control = (IControl) controls.get(id);
660
        if (control != null) {
661
            control.setValue(value);
662
        } else {
663
            logger.debug("NewStatusBar -- no control called " + id);
664
        }
665
    }
666

    
667
    /**
668
     * This method initializes the progressBar and gets it.
669
     * 
670
     * @return javax.swing.JProgressBar
671
     */
672
    private JProgressBar getProgressBar() {
673
        if (progressBar == null) {
674
            progressBar = new JProgressBar();
675
            // progressBar.setPreferredSize(new java.awt.Dimension(100, 14));
676
            progressBar.setVisible(false);
677
            progressBar.setMinimum(0);
678
            progressBar.setMaximum(100);
679
            progressBar.setValue(50);
680
        }
681

    
682
        return progressBar;
683
    }
684

    
685
    private JTasksStatus getTasksStatus() {
686
        if (tasksStatus == null) {
687
            tasksStatus =
688
                ToolsSwingLocator.getTaskStatusSwingManager()
689
                    .createJTasksStatus();
690
            tasksStatus.setVisible(true);
691
        }
692
        return tasksStatus;
693
    }
694

    
695
    /**
696
     * Sets the width of the main message label.
697
     * 
698
     * @param d
699
     *            The width ob the main label
700
     * @deprecated
701
     */
702
    public void setFixedLabelWidth(double d) {
703
        lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight()));
704
    }
705

    
706
    /**
707
     * Adds a control to the status bar
708
     * 
709
     * @param id
710
     *            The ID of the control, useful to later retrive it or set its
711
     *            value
712
     * @param control
713
     *            The control to add
714
     */
715
    public void addControl(String id, Component control) {
716
        if (!controls.containsKey(control.getName())) {
717
            controls.put(control.getName(), control);
718
            controlContainer.add(control);
719
        } else {
720
            logger.debug("NewStatusBar.addControl -- control 'id' already exists" + id);
721
        }
722
    }
723

    
724
    /**
725
     * Remove a control from the status bar
726
     * 
727
     * @param id
728
     *            The ID of the control to get
729
     */
730
    public Component removeControl(String id) {
731
        try {
732
            Component component = (Component) controls.get(id);
733
            controlContainer.remove(component);
734
            controls.remove(id);
735
            return component;
736
        } catch (ClassCastException ex) {
737
            logger.debug("NewStatusBar.removeControl -- control " + id
738
                + "doesn't exist");
739
        }
740
        return null;
741
    }
742

    
743
    /**
744
     * Gets a control from the status bar
745
     * 
746
     * @param id
747
     *            The ID of the control to get
748
     */
749
    public Component getControl(String id) {
750
        return (Component) controls.get(id);
751
    }
752
} // @jve:decl-index=0:visual-constraint="10,10"