Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / NewStatusBar.java @ 41078

History | View | Annotate | Download (23.2 KB)

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

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

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

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

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

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

    
103
        private String textoCompleto;
104

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

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

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

    
128
        JPanel panelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0));
129

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

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

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

    
150
        this.add(panelLeft, BorderLayout.CENTER);
151
        this.add(panelRight, BorderLayout.EAST);
152

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

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

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

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

    
285
        if (estadoAnterior == -1) {
286
            return;
287
        }
288

    
289
        switch (estadoAnterior) {
290
        case INFO:
291
            setInfoText(textoAnterior);
292

    
293
            break;
294

    
295
        case WARNING:
296
            setWarningText(textoAnterior);
297

    
298
            break;
299

    
300
        case ERROR:
301
            setErrorText(textoAnterior);
302

    
303
            break;
304
        }
305

    
306
        estadoAnterior = -1;
307
        textoAnterior = null;
308
    }
309

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

    
334
        this.estado = INFO;
335
        lblIcon.setIcon(getImageIcon("statusbar-info"));
336
        lblTexto.setText(texto);
337
    }
338

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

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

    
392
        this.estado = ERROR;
393
        lblIcon.setIcon(getImageIcon("statusbar-error"));
394
        lblTexto.setText(texto);
395
    }
396

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

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

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

    
491
        if (contenidoTemporal) {
492
            textoAnterior = texto;
493
            estadoAnterior = ERROR;
494
        } else {
495
                this.textoCompleto = texto; 
496
            lblTexto.setText(getFirstTextLine(texto));
497
            lblIcon.setIcon(getImageIcon("statusbar-error"));
498
            estado = ERROR;
499
        }
500
    }
501

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

    
522
        getProgressBar().repaint();
523
    }
524

    
525
    /**
526
     * Sets a label-set to be shown in the status bar. This method it is not
527
     * intended to be used directly, because the set will be overwritten when
528
     * the selected
529
     * window changes. Use {@link MainFrame#setStatusBarLabels(Class, Label[])}
530
     * to permanently associate a label set with a window.
531
     * 
532
     * @param labels
533
     *            The labels to set.
534
     * @see MainFrame#setStatusBarLabels(Class, Label[])
535
     */
536
    public void setLabelSet(Label[] labels) {
537
        removeAllLabels();
538
        idLabel.clear();
539

    
540
        for (int i = 0; i < labels.length; i++) {
541
            // Set an initial text so the getPreferredSize works as expected
542
            JLabel lbl = new JLabel();
543
            lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
544
            lbl.setName(labels[i].getId());
545
            controlContainer.add(lbl);
546

    
547
            /*
548
             * if (i != labels.length - 1){
549
             * this.add(new JSeparator(JSeparator.VERTICAL));
550
             * }
551
             */
552
            idLabel.put(labels[i].getId(), lbl);
553
        }
554

    
555
        JLabel[] configlabels =
556
            (JLabel[]) idLabel.values().toArray(new JLabel[0]);
557
        widthlabels = new int[configlabels.length];
558

    
559
        for (int i = 0; i < labels.length; i++) {
560
            widthlabels[i] = configlabels[i].getWidth();
561
        }
562

    
563
        this.validate();
564
    }
565

    
566
    /**
567
     * Hides the empty labels and adjust the space in the bar.
568
     */
569
    public void ajustar() {
570
        if (widthlabels == null) {
571
            return;
572
        }
573

    
574
        JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
575

    
576
        /*
577
         * double total = 1;
578
         * for (int i = 0; i < widthlabels.length; i++) {
579
         * if (labels[i].getText().compareTo("") != 0) {
580
         * total += widthlabels[i];
581
         * }
582
         * }
583
         * double p = (ws - lblTexto.getWidth() - 20) / total;
584
         */
585
        for (int i = 0; i < labels.length; i++) {
586
            JLabel label = (JLabel) labels[i];
587

    
588
            if (label.getText().compareTo("") != 0) {
589
                label.setVisible(true);
590
            } else {
591
                label.setVisible(false);
592
            }
593
        }
594
        validate();
595
    }
596

    
597
    /**
598
     * Removes all the labels from the status bar. It does not remove the
599
     * controls.
600
     */
601
    private void removeAllLabels() {
602
        Component[] controlArray = controlContainer.getComponents();
603

    
604
        for (int i = 0; i < controlArray.length; i++) {
605
            if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)
606
                && !(controlArray[i] instanceof IControl)
607
                && (controlArray[i] instanceof JLabel)) {
608
                controlContainer.remove(controlArray[i]);
609
            }
610
        }
611
    }
612

    
613
    /**
614
     * Sets the text of the provided label.
615
     * 
616
     * @param id
617
     *            The ID of the label to modify. It is defined in the
618
     *            config.xml file
619
     * @param msg
620
     *            The message to show in the label
621
     */
622
    public void setMessage(final String id, final String msg) {
623
        if (!SwingUtilities.isEventDispatchThread()) {
624
            SwingUtilities.invokeLater(new Runnable() {
625
                public void run() {
626
                        setMessage(id, msg);
627
                }
628
            });
629
            return;
630
        }
631

    
632
        JLabel lbl = (JLabel) idLabel.get(id);
633

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

    
656
        ajustar();
657
    }
658

    
659
    /**
660
     * Sets the control identified by 'id' with the provided value.
661
     * 
662
     * @param id
663
     *            The ID of the control to modify
664
     * @param value
665
     *            The value to set in the control
666
     */
667
    public void setControlValue(String id, String value) {
668
        IControl control = (IControl) controls.get(id);
669
        if (control != null) {
670
            control.setValue(value);
671
        } else {
672
            logger.debug("NewStatusBar -- no control called " + id);
673
        }
674
    }
675

    
676
    /**
677
     * This method initializes the progressBar and gets it.
678
     * 
679
     * @return javax.swing.JProgressBar
680
     */
681
    private JProgressBar getProgressBar() {
682
        if (progressBar == null) {
683
            progressBar = new JProgressBar();
684
            // progressBar.setPreferredSize(new java.awt.Dimension(100, 14));
685
            progressBar.setVisible(false);
686
            progressBar.setMinimum(0);
687
            progressBar.setMaximum(100);
688
            progressBar.setValue(50);
689
        }
690

    
691
        return progressBar;
692
    }
693

    
694
    private JTasksStatus getTasksStatus() {
695
        if (tasksStatus == null) {
696
            tasksStatus =
697
                ToolsSwingLocator.getTaskStatusSwingManager()
698
                    .createJTasksStatus();
699
            tasksStatus.setVisible(true);
700
        }
701
        return tasksStatus;
702
    }
703

    
704
    /**
705
     * Sets the width of the main message label.
706
     * 
707
     * @param d
708
     *            The width ob the main label
709
     * @deprecated
710
     */
711
    public void setFixedLabelWidth(double d) {
712
        lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight()));
713
    }
714

    
715
    /**
716
     * Adds a control to the status bar
717
     * 
718
     * @param id
719
     *            The ID of the control, useful to later retrive it or set its
720
     *            value
721
     * @param control
722
     *            The control to add
723
     */
724
    public void addControl(String id, Component control) {
725
        if (!controls.containsKey(control.getName())) {
726
            controls.put(control.getName(), control);
727
            controlContainer.add(control);
728
        } else {
729
            logger.debug("NewStatusBar.addControl -- control 'id' already exists" + id);
730
        }
731
    }
732

    
733
    /**
734
     * Remove a control from the status bar
735
     * 
736
     * @param id
737
     *            The ID of the control to get
738
     */
739
    public Component removeControl(String id) {
740
        try {
741
            Component component = (Component) controls.get(id);
742
            controlContainer.remove(component);
743
            controls.remove(id);
744
            return component;
745
        } catch (ClassCastException ex) {
746
            logger.debug("NewStatusBar.removeControl -- control " + id
747
                + "doesn't exist");
748
        }
749
        return null;
750
    }
751

    
752
    /**
753
     * Gets a control from the status bar
754
     * 
755
     * @param id
756
     *            The ID of the control to get
757
     */
758
    public Component getControl(String id) {
759
        return (Component) controls.get(id);
760
    }
761
} // @jve:decl-index=0:visual-constraint="10,10"