Coverage details for ui.panel.StatusBarPanel

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
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, MA 02110-1301, USA.
19  *******************************************************************************/
20 package ui.panel;
21  
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.GridLayout;
25 import java.awt.Toolkit;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28  
29 import javax.swing.BorderFactory;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JProgressBar;
33 import javax.swing.Timer;
34 import javax.swing.border.EtchedBorder;
35  
36 @SuppressWarnings("serial") //$NON-NLS-1$
370public class StatusBarPanel extends JPanel {
38  
39     private JProgressBar progressBar;
40  
41     private JPanel messagePanel;
42  
43     private JLabel messageLabel;
44  
450    private Timer timer;
46  
470    private boolean taskDone = false;
48  
490    public StatusBarPanel() {
50         // MessageLogger.println("StatusBar",MessageLogger.DEBUG_MESSAGE);
51  
520        initialize();
530    }
54  
55     protected void initialize() {
560        this.setOpaque(true);
570        this.setPreferredSize(new Dimension(1024, 20));
580        this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
590        this.setLayout(new GridLayout(1, 2));
600        this.add(getMessagePanel(), null);
61  
620        JPanel progressPanel = new JPanel();
630        progressPanel.setLayout(new GridLayout(1, 3));
640        progressPanel.add(new JLabel(), null);
650        progressPanel.add(getProgressBar(), null);
660        progressPanel.add(new JLabel(), null);
670        this.add(progressPanel, null);
680    }
69  
70     /**
71      * @return Returns the progressBar.
72      */
73     public JProgressBar getProgressBar() {
740        if (progressBar == null) {
750            progressBar = new JProgressBar();
760            progressBar.setMinimum(0);
770            progressBar.setMaximum(110);
78         }
790        return progressBar;
80     }
81  
82     /**
83      * @return Returns the messagePanel.
84      */
85     protected JPanel getMessagePanel() {
860        if (messagePanel == null) {
870            messagePanel = new JPanel();
880            messagePanel.setLayout(new BorderLayout());
890            messagePanel.add(getMessageLabel(), BorderLayout.CENTER);
90         }
910        return messagePanel;
92     }
93  
94     /**
95      * @return Returns the messageLabel.
96      */
97     protected JLabel getMessageLabel() {
980        if (messageLabel == null) {
990            messageLabel = new JLabel();
100         }
1010        return messageLabel;
102     }
103  
104     public void setMessage(String message) {
1050        this.getMessageLabel().setText(message);
1060    }
107  
108     /**
109      * @return Returns the timer.
110      */
111     public Timer getTimer() {
1120        if (timer == null || !timer.isRunning()) {
113             // Create a timer.
1140            timer = new Timer(100, new ActionListener() {
115                 public void actionPerformed(ActionEvent evt) {
116                     getProgressBar().setValue(getProgressBar().getValue() + 1);
117                     if (isTaskDone()) {
118                         Toolkit.getDefaultToolkit().beep();
119                         timer.stop();
120                         getProgressBar()
121                                 .setValue(getProgressBar().getMinimum());
122                     }
123                 }
124             });
125         }
1260        return timer;
127     }
128  
129     /**
130      * @return Returns the taskDone.
131      */
132     public synchronized boolean isTaskDone() {
1330        return taskDone;
134     }
135  
136     /**
137      * @param taskDone
138      * The taskDone to set.
139      */
140     public synchronized void setTaskDone(boolean taskDone) {
1410        this.taskDone = taskDone;
1420        getProgressBar().setValue(getProgressBar().getMinimum());
1430        getTimer().stop();
1440    }
145 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.