Statistics
| Revision:

root / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / ui / mdiFrame / NewStatusBar.java @ 38611

History | View | Annotate | Download (20.5 KB)

1 37844 cordinyana
/* gvSIG. Geographic Information System of the Valencian Government
2 1104 fjp
 *
3 37844 cordinyana
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6 1104 fjp
 * 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 37844 cordinyana
 *
11 1104 fjp
 * 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 37844 cordinyana
 *
16 1104 fjp
 * 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 37844 cordinyana
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21 1104 fjp
 */
22 29593 jpiera
package org.gvsig.andami.ui.mdiFrame;
23 598 fernando
24 37849 cordinyana
import java.awt.BorderLayout;
25 663 fernando
import java.awt.Component;
26 598 fernando
import java.awt.Dimension;
27
import java.awt.FlowLayout;
28 37848 cordinyana
import java.awt.LayoutManager;
29 38564 jjdelcerro
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.awt.event.MouseEvent;
32
import java.awt.event.MouseListener;
33 598 fernando
import java.util.HashMap;
34 37848 cordinyana
import java.util.Map;
35 598 fernando
36
import javax.swing.BorderFactory;
37
import javax.swing.ImageIcon;
38
import javax.swing.JLabel;
39 38564 jjdelcerro
import javax.swing.JOptionPane;
40 598 fernando
import javax.swing.JPanel;
41 38564 jjdelcerro
import javax.swing.JPopupMenu;
42 598 fernando
import javax.swing.JProgressBar;
43 10400 cesar
import javax.swing.SwingConstants;
44 38564 jjdelcerro
import javax.swing.Timer;
45 663 fernando
import javax.swing.border.BevelBorder;
46 598 fernando
47 29593 jpiera
import org.gvsig.andami.PluginServices;
48
import org.gvsig.andami.messages.Messages;
49
import org.gvsig.andami.plugins.config.generate.Label;
50 6623 cesar
import org.gvsig.gui.beans.controls.IControl;
51 34925 nfrancisco
import org.gvsig.tools.swing.api.ToolsSwingLocator;
52
import org.gvsig.tools.swing.api.task.JTasksStatus;
53 38564 jjdelcerro
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55 598 fernando
56
/**
57 37844 cordinyana
 * <p>
58
 * This class contains the status bar. It contains the graphical component, and
59
 * the methods to manage it.
60 12015 cesar
 * </p>
61
 *
62 37844 cordinyana
 * <p>
63
 * The status bar is divided in several areas. At the very left, there is an
64
 * icon and the main status text. There are three icons to show: Info, Warning
65
 * and Error icons. They can be set together with the main status text using the
66
 * methods <code>setInfoText()</code>, <code>setWarningText()</code> and
67
 * <code>setErrorText()</code> (and also with <code>setInfoTextTemporal()</code>
68
 * , etc). Then, there is a right area which contains labels and other controls.
69
 * Labels are set in the config.xml files and are visible or not depending on
70
 * the currently selected Andami window. Controls are associated to extensions,
71
 * and are enabled/disabled and visible/hidden depending on the associated
72
 * extension.
73 12015 cesar
 * </p>
74
 *
75 598 fernando
 */
76
public class NewStatusBar extends JPanel {
77 37844 cordinyana
78 34933 jjdelcerro
    private static final long serialVersionUID = 5575549032728844632L;
79 38564 jjdelcerro
80
    private static Logger logger = LoggerFactory.getLogger(NewStatusBar.class);
81
82 37844 cordinyana
    private static final int INFO = 0;
83
    private static final int WARNING = 1;
84
    private static final int ERROR = 2;
85
    private JLabel lblIcon = null;
86
    private JLabel lblTexto = null;
87
    private boolean contenidoTemporal;
88
    private String textoAnterior;
89
    private int estadoAnterior;
90
    private int estado;
91
    private JProgressBar progressBar = null;
92 37848 cordinyana
    private Map<String, JLabel> idLabel = new HashMap<String, JLabel>();
93 37844 cordinyana
    private int[] widthlabels = null;
94 37848 cordinyana
    private Map<String, Component> controls = new HashMap<String, Component>();
95 37844 cordinyana
    private JPanel controlContainer;
96
    private JTasksStatus tasksStatus = null;
97 38564 jjdelcerro
        private Timer messageTimer;
98 598 fernando
99 38564 jjdelcerro
100 37844 cordinyana
    /**
101
     * This is the default constructor
102
     */
103
    public NewStatusBar() {
104
        super();
105
        initialize();
106
    }
107
108 38564 jjdelcerro
        private ImageIcon getImageIcon(String iconName) {
109
                return PluginServices.getIconTheme().get(iconName);
110
        }
111
112
113 37844 cordinyana
    /**
114
     * This method initializes the status bar. It creates the required
115
     * containers and sets the layout.
116
     */
117
    private void initialize() {
118 37849 cordinyana
        LayoutManager mainLayout = new BorderLayout();
119 37844 cordinyana
        this.setLayout(mainLayout);
120
121 37848 cordinyana
        JPanel panelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0));
122 37844 cordinyana
123 37848 cordinyana
        controlContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0));
124 34933 jjdelcerro
        panelRight.add(controlContainer);
125
        panelRight.add(getTasksStatus());
126 2938 fjp
127 37844 cordinyana
        lblIcon = new JLabel();
128
        lblTexto = new JLabel();
129
        lblTexto.setAlignmentX(JLabel.LEFT_ALIGNMENT);
130
        lblTexto.setHorizontalAlignment(SwingConstants.LEFT);
131
        lblTexto.setHorizontalTextPosition(SwingConstants.LEFT);
132 37848 cordinyana
        lblTexto.setVerticalAlignment(SwingConstants.CENTER);
133
        lblTexto.setVerticalTextPosition(SwingConstants.CENTER);
134 37844 cordinyana
        lblIcon.setText("");
135
        lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada"));
136
137 34933 jjdelcerro
        JPanel panelLeft = new JPanel();
138 37848 cordinyana
        panelLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0));
139 38564 jjdelcerro
        panelLeft.add(lblIcon);
140 37848 cordinyana
        panelLeft.add(lblTexto);
141
        panelLeft.add(getProgressBar());
142 34933 jjdelcerro
143 37849 cordinyana
        this.add(panelLeft, BorderLayout.CENTER);
144
        this.add(panelRight, BorderLayout.EAST);
145 38564 jjdelcerro
146
        buildMesagePopupMenu();
147
148
        messageTimer = new Timer(30000, new ActionListener() {
149
                        public void actionPerformed(ActionEvent e) {
150
                                try {
151
                                        clearMessage();
152
                                } catch( Throwable ex) {
153
                                        logger.info("Can't clear message", ex);
154
                                }
155
                        }
156
                });
157 37844 cordinyana
    }
158 38564 jjdelcerro
159
    public void clearMessage() {
160
            lblTexto.setText("");
161
            lblIcon.setIcon(null);
162
            estado = INFO;
163
    }
164 598 fernando
165 38564 jjdelcerro
166
    public void message(String msg, int messageTyoe) {
167
            messageTimer.stop();
168
            switch (messageTyoe) {
169
                case JOptionPane.ERROR_MESSAGE:
170
                        setErrorText(msg);
171
                        break;
172
                case JOptionPane.WARNING_MESSAGE:
173
                        setWarningText(msg);
174
                        break;
175
                default:
176
                case JOptionPane.INFORMATION_MESSAGE:
177
                        setInfoText(msg);
178
                        break;
179
                }
180
            messageTimer.start();
181
        }
182
183
    private void buildMesagePopupMenu() {
184
            final JPopupMenu menu = new JPopupMenu();
185
186
            JMenuItem item = new JMenuItem("View details");
187
            item.addActionListener(new ActionListener() {
188
                        public void actionPerformed(ActionEvent arg0) {
189
                                switch (estado) {
190
                                default:
191
                                case INFO:
192
                                        JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.INFORMATION_MESSAGE);
193
                                        break;
194
                                case WARNING:
195
                                        JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.WARNING_MESSAGE);
196
                                        break;
197
                                case ERROR:
198
                                        JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.ERROR_MESSAGE);
199
                                        break;
200
                                }
201
                        }
202
                });
203
            menu.add(item);
204
            item = new JMenuItem("Clear");
205
            item.addActionListener(new ActionListener() {
206
                        public void actionPerformed(ActionEvent e) {
207
                                clearMessage();
208
                        }
209
                });
210
            menu.add(item);
211
            menu.addSeparator();
212
            item = new JMenuItem("Cancel");
213
            menu.add(item);
214
215
            this.lblTexto.addMouseListener( new MouseListener() {
216
                        public void mouseReleased(MouseEvent e) {
217
                                if( e.isPopupTrigger() ) {
218
                                        if( getStatusText().length() > 0 || estado!=INFO ) {
219
                                                menu.show(lblTexto, e.getX(), e.getY());
220
                                        }
221
                                }
222
                        }
223
                        public void mousePressed(MouseEvent e) {
224
                                if( e.isPopupTrigger() ) {
225
                                        if( getStatusText().length() > 0 || estado!=INFO ) {
226
                                                menu.show(lblTexto, e.getX(), e.getY());
227
                                        }
228
                                }
229
                        }
230
                        public void mouseExited(MouseEvent e) {
231
                        }
232
                        public void mouseEntered(MouseEvent e) {
233
                        }
234
                        public void mouseClicked(MouseEvent e) {
235
                        }
236
                });
237
    }
238
239 37844 cordinyana
    /**
240
     * Gets the status bar main text.
241
     *
242
     * @return The status bar main text.
243
     * @see #setInfoText(String)
244
     * @see #setWarningText(String)
245
     * @see #setErrorText(String)
246
     * @see #setInfoTextTemporal(String)
247
     * @see #setWarningTextTemporal(String)
248
     * @see #setErrorTextTemporal(String)
249
     */
250
    public String getStatusText() {
251
        return lblTexto.getText();
252
    }
253 598 fernando
254 37844 cordinyana
    /**
255
     * Restores the previous contents in the status bar main text,
256
     * after the {@link #setInfoTextTemporal(String)},
257
     * {@link #setWarningTextTemporal(String)} or
258
     * {@link #setErrorTextTemporal(String)} have been called.
259
     *
260
     * @see #setInfoTextTemporal(String)
261
     * @see #setWarningTextTemporal(String)
262
     * @see #setErrorTextTemporal(String)
263
     */
264
    public void restaurarTexto() {
265
        contenidoTemporal = false;
266 598 fernando
267 37844 cordinyana
        if (estadoAnterior == -1) {
268
            return;
269
        }
270 598 fernando
271 37844 cordinyana
        switch (estadoAnterior) {
272
        case INFO:
273
            setInfoText(textoAnterior);
274 598 fernando
275 37844 cordinyana
            break;
276 598 fernando
277 37844 cordinyana
        case WARNING:
278
            setWarningText(textoAnterior);
279 598 fernando
280 37844 cordinyana
            break;
281 598 fernando
282 37844 cordinyana
        case ERROR:
283
            setErrorText(textoAnterior);
284 598 fernando
285 37844 cordinyana
            break;
286
        }
287 598 fernando
288 37844 cordinyana
        estadoAnterior = -1;
289
        textoAnterior = null;
290
    }
291 598 fernando
292 37844 cordinyana
    /**
293
     * Sets a temporary information message in the status bar, and changes the
294
     * icon to an Info icon. The previous text and icon can be restored using
295
     * the {@link #restaurarTexto()} method.
296
     *
297
     * @param texto
298
     *            The text to set
299
     * @see #restaurarTexto()
300
     */
301
    public void setInfoTextTemporal(String texto) {
302
        if (!contenidoTemporal) {
303
            textoAnterior = getStatusText();
304
            estadoAnterior = this.estado;
305
            contenidoTemporal = true;
306
        }
307 598 fernando
308 37844 cordinyana
        this.estado = INFO;
309 38564 jjdelcerro
        lblIcon.setIcon(getImageIcon("statusbar-info"));
310 37844 cordinyana
        lblTexto.setText(texto);
311
    }
312 598 fernando
313 37844 cordinyana
    /**
314
     * Sets a temporary warning message in the status bar, and changes the
315
     * icon to a Warning icon. The previous text and icon can be restored using
316
     * the {@link #restaurarTexto()} method.
317
     *
318
     * @param texto
319
     *            The text to set
320
     * @see #restaurarTexto()
321
     */
322
    public void setWarningTextTemporal(String texto) {
323
        if (!contenidoTemporal) {
324
            estadoAnterior = this.estado;
325
            textoAnterior = getStatusText();
326
            contenidoTemporal = true;
327
        }
328
        this.estado = WARNING;
329 38564 jjdelcerro
        lblIcon.setIcon(getImageIcon("statusbar-warning"));
330 37844 cordinyana
        lblTexto.setText(texto);
331
    }
332 598 fernando
333 37844 cordinyana
    /**
334
     * Sets a temporary error message in the status bar, and changes the
335
     * icon to an Error icon. The previous text and icon can be restored using
336
     * the {@link #restaurarTexto()} method.
337
     *
338
     * @param texto
339
     *            The text to set
340
     * @see #restaurarTexto()
341
     */
342
    public void setErrorTextTemporal(String texto) {
343
        if (!contenidoTemporal) {
344
            estadoAnterior = this.estado;
345
            textoAnterior = getStatusText();
346
            contenidoTemporal = true;
347
        }
348 598 fernando
349 37844 cordinyana
        this.estado = ERROR;
350 38564 jjdelcerro
        lblIcon.setIcon(getImageIcon("statusbar-error"));
351 37844 cordinyana
        lblTexto.setText(texto);
352
    }
353 2938 fjp
354 37844 cordinyana
    /**
355
     * Sets a permanent info message in the status bar, and changes the
356
     * permanent icon to an Info icon. If there is a temporary message showing
357
     * at the moment, the message set now is not shown until
358
     * the {@link #restaurarTexto()} method is called.
359
     *
360
     * @param texto
361
     *            The permanent info message to set
362
     * @see #restaurarTexto()
363
     */
364
    public void setInfoText(String texto) {
365
        if (contenidoTemporal) {
366
            textoAnterior = texto;
367
            estadoAnterior = INFO;
368
        } else {
369
            lblTexto.setText(texto);
370 38564 jjdelcerro
            lblIcon.setIcon(getImageIcon("statusbar-info"));
371 37844 cordinyana
            estado = INFO;
372
        }
373
    }
374 598 fernando
375 37844 cordinyana
    /**
376
     * Sets a permanent warning message in the status bar, and changes the
377
     * permanent icon to a Warning icon. If there is a temporary message showing
378
     * at the moment, the message set now is not shown until
379
     * the {@link #restaurarTexto()} method is called.
380
     *
381
     * @param texto
382
     *            The permanent warning message to set
383
     * @see #restaurarTexto()
384
     */
385
    public void setWarningText(String texto) {
386
        if (contenidoTemporal) {
387
            textoAnterior = texto;
388
            estadoAnterior = WARNING;
389
        } else {
390
            lblTexto.setText(texto);
391 38564 jjdelcerro
            lblIcon.setIcon(getImageIcon("statusbar-warning"));
392 37844 cordinyana
            estado = WARNING;
393
        }
394
    }
395 598 fernando
396 37844 cordinyana
    /**
397
     * Sets a permanent error message in the status bar, and changes the
398
     * permanent icon to an Error icon. If there is a temporary message showing
399
     * at the moment, the message set now is not shown until
400
     * the {@link #restaurarTexto()} method is called.
401
     *
402
     * @param texto
403
     *            The permanent info message to set
404
     * @see #restaurarTexto()
405
     */
406
    public void setErrorText(String texto) {
407
        if (contenidoTemporal) {
408
            textoAnterior = texto;
409
            estadoAnterior = ERROR;
410
        } else {
411
            lblTexto.setText(texto);
412 38564 jjdelcerro
            lblIcon.setIcon(getImageIcon("statusbar-error"));
413 37844 cordinyana
            estado = ERROR;
414
        }
415
    }
416 598 fernando
417 37844 cordinyana
    /**
418
     * If <code>p</code> is a value between 0 and 99, it shows a progress bar
419
     * in the left area of the status bar, and sets the specified progress.
420
     * If <code>p</code> is bigger than 99, it hides the progress bar.
421
     *
422
     * @param p
423
     *            The progress to set in the progress bar. If it is bigger
424
     *            than 99, the task will be considered to be finished, and the
425
     *            progress bar will be hidden.
426
     *
427
     * @deprecated use instead TaskStatus and TaskStatusManager
428
     */
429
    public void setProgress(int p) {
430
        if (p < 100) {
431
            getProgressBar().setValue(p);
432
            getProgressBar().setVisible(true);
433
        } else {
434
            getProgressBar().setVisible(false);
435
        }
436 6860 jaume
437 37844 cordinyana
        getProgressBar().repaint();
438
    }
439 1268 vcaballero
440 37844 cordinyana
    /**
441
     * Sets a label-set to be shown in the status bar. This method it is not
442
     * intended to be used directly, because the set will be overwritten when
443
     * the selected
444
     * window changes. Use {@link MainFrame#setStatusBarLabels(Class, Label[])}
445
     * to permanently associate a label set with a window.
446
     *
447
     * @param labels
448
     *            The labels to set.
449
     * @see MainFrame#setStatusBarLabels(Class, Label[])
450
     */
451
    public void setLabelSet(Label[] labels) {
452
        removeAllLabels();
453
        idLabel.clear();
454 1268 vcaballero
455 37844 cordinyana
        for (int i = 0; i < labels.length; i++) {
456 37848 cordinyana
            // Set an initial text so the getPreferredSize works as expected
457 37844 cordinyana
            JLabel lbl = new JLabel();
458
            lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
459
            lbl.setName(labels[i].getId());
460
            controlContainer.add(lbl);
461 1268 vcaballero
462 37844 cordinyana
            /*
463
             * if (i != labels.length - 1){
464
             * this.add(new JSeparator(JSeparator.VERTICAL));
465
             * }
466
             */
467
            idLabel.put(labels[i].getId(), lbl);
468
        }
469 1268 vcaballero
470 37844 cordinyana
        JLabel[] configlabels =
471
            (JLabel[]) idLabel.values().toArray(new JLabel[0]);
472
        widthlabels = new int[configlabels.length];
473 6614 cesar
474 37844 cordinyana
        for (int i = 0; i < labels.length; i++) {
475
            widthlabels[i] = configlabels[i].getWidth();
476
        }
477 6860 jaume
478 37848 cordinyana
        this.validate();
479 37844 cordinyana
    }
480 1268 vcaballero
481 37844 cordinyana
    /**
482
     * Hides the empty labels and adjust the space in the bar.
483
     */
484
    public void ajustar() {
485
        if (widthlabels == null) {
486
            return;
487
        }
488 1268 vcaballero
489 37844 cordinyana
        JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
490 1268 vcaballero
491 37844 cordinyana
        /*
492
         * double total = 1;
493
         * for (int i = 0; i < widthlabels.length; i++) {
494
         * if (labels[i].getText().compareTo("") != 0) {
495
         * total += widthlabels[i];
496
         * }
497
         * }
498
         * double p = (ws - lblTexto.getWidth() - 20) / total;
499
         */
500
        for (int i = 0; i < labels.length; i++) {
501
            JLabel label = (JLabel) labels[i];
502 1268 vcaballero
503 37844 cordinyana
            if (label.getText().compareTo("") != 0) {
504
                label.setVisible(true);
505
            } else {
506
                label.setVisible(false);
507
            }
508
        }
509 37848 cordinyana
        validate();
510 37844 cordinyana
    }
511 6614 cesar
512 37844 cordinyana
    /**
513
     * Removes all the labels from the status bar. It does not remove the
514
     * controls.
515
     */
516
    private void removeAllLabels() {
517
        Component[] controlArray = controlContainer.getComponents();
518 6860 jaume
519 37844 cordinyana
        for (int i = 0; i < controlArray.length; i++) {
520
            if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)
521
                && !(controlArray[i] instanceof IControl)
522
                && (controlArray[i] instanceof JLabel)) {
523
                controlContainer.remove(controlArray[i]);
524
            }
525
        }
526
    }
527 6860 jaume
528 37844 cordinyana
    /**
529
     * Sets the text of the provided label.
530
     *
531
     * @param id
532
     *            The ID of the label to modify. It is defined in the
533
     *            config.xml file
534
     * @param msg
535
     *            The message to show in the label
536
     */
537
    public void setMessage(String id, String msg) {
538
        JLabel lbl = (JLabel) idLabel.get(id);
539 10542 cesar
540 37844 cordinyana
        if (lbl != null) {
541 38512 cordinyana
                Dimension originalPreferredSize = lbl.getPreferredSize();
542 37844 cordinyana
            lbl.setText(msg);
543 38512 cordinyana
            // Set preferred size to null just in case it has been set
544
            // previously, as we want it to be calculated from the text size.
545
            lbl.setPreferredSize(null);
546
            // Allow only to increase label width, to avoid too much ugly
547
            // width changes in the status bar components.
548
            if (lbl.getPreferredSize().width < originalPreferredSize.width) {
549
                    lbl.setPreferredSize(originalPreferredSize);
550
            }
551 37844 cordinyana
        } else {
552
            // try with controls
553
            try {
554
                IControl control = (IControl) controls.get(id);
555
                if (control != null)
556
                    control.setValue(msg);
557
            } catch (ClassCastException ex) {
558 38564 jjdelcerro
                logger.debug("no label called " + id);
559 37844 cordinyana
            }
560
        }
561 6860 jaume
562 37844 cordinyana
        ajustar();
563
    }
564 598 fernando
565 37844 cordinyana
    /**
566
     * Sets the control identified by 'id' with the provided value.
567
     *
568
     * @param id
569
     *            The ID of the control to modify
570
     * @param value
571
     *            The value to set in the control
572
     */
573
    public void setControlValue(String id, String value) {
574
        IControl control = (IControl) controls.get(id);
575
        if (control != null) {
576
            control.setValue(value);
577
        } else {
578 38564 jjdelcerro
            logger.debug("NewStatusBar -- no control called " + id);
579 37844 cordinyana
        }
580
    }
581 598 fernando
582 37844 cordinyana
    /**
583
     * This method initializes the progressBar and gets it.
584
     *
585
     * @return javax.swing.JProgressBar
586
     */
587
    private JProgressBar getProgressBar() {
588
        if (progressBar == null) {
589
            progressBar = new JProgressBar();
590 37848 cordinyana
            // progressBar.setPreferredSize(new java.awt.Dimension(100, 14));
591 37844 cordinyana
            progressBar.setVisible(false);
592
            progressBar.setMinimum(0);
593
            progressBar.setMaximum(100);
594
            progressBar.setValue(50);
595
        }
596
597
        return progressBar;
598
    }
599
600 34925 nfrancisco
    private JTasksStatus getTasksStatus() {
601
        if (tasksStatus == null) {
602 37844 cordinyana
            tasksStatus =
603
                ToolsSwingLocator.getTaskStatusSwingManager()
604
                    .createJTasksStatus();
605 34925 nfrancisco
            tasksStatus.setVisible(true);
606
        }
607
        return tasksStatus;
608
    }
609 1268 vcaballero
610 37844 cordinyana
    /**
611
     * Sets the width of the main message label.
612
     *
613
     * @param d
614
     *            The width ob the main label
615
     * @deprecated
616
     */
617
    public void setFixedLabelWidth(double d) {
618
        lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight()));
619
    }
620 6860 jaume
621 37844 cordinyana
    /**
622
     * Adds a control to the status bar
623
     *
624
     * @param id
625
     *            The ID of the control, useful to later retrive it or set its
626
     *            value
627
     * @param control
628
     *            The control to add
629
     */
630
    public void addControl(String id, Component control) {
631
        if (!controls.containsKey(control.getName())) {
632
            controls.put(control.getName(), control);
633
            controlContainer.add(control);
634
        } else {
635 38564 jjdelcerro
            logger.debug("NewStatusBar.addControl -- control 'id' already exists" + id);
636 37844 cordinyana
        }
637
    }
638 6860 jaume
639 37844 cordinyana
    /**
640
     * Remove a control from the status bar
641
     *
642
     * @param id
643
     *            The ID of the control to get
644
     */
645
    public Component removeControl(String id) {
646
        try {
647
            Component component = (Component) controls.get(id);
648
            controlContainer.remove(component);
649
            controls.remove(id);
650
            return component;
651
        } catch (ClassCastException ex) {
652 38564 jjdelcerro
            logger.debug("NewStatusBar.removeControl -- control " + id
653 37844 cordinyana
                + "doesn't exist");
654
        }
655
        return null;
656
    }
657
658
    /**
659
     * Gets a control from the status bar
660
     *
661
     * @param id
662
     *            The ID of the control to get
663
     */
664
    public Component getControl(String id) {
665
        return (Component) controls.get(id);
666
    }
667
} // @jve:decl-index=0:visual-constraint="10,10"