Line | Hits | Source |
---|---|---|
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$ | |
37 | 0 | public class StatusBarPanel extends JPanel { |
38 | ||
39 | private JProgressBar progressBar; | |
40 | ||
41 | private JPanel messagePanel; | |
42 | ||
43 | private JLabel messageLabel; | |
44 | ||
45 | 0 | private Timer timer; |
46 | ||
47 | 0 | private boolean taskDone = false; |
48 | ||
49 | 0 | public StatusBarPanel() { |
50 | // MessageLogger.println("StatusBar",MessageLogger.DEBUG_MESSAGE); | |
51 | ||
52 | 0 | initialize(); |
53 | 0 | } |
54 | ||
55 | protected void initialize() { | |
56 | 0 | this.setOpaque(true); |
57 | 0 | this.setPreferredSize(new Dimension(1024, 20)); |
58 | 0 | this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); |
59 | 0 | this.setLayout(new GridLayout(1, 2)); |
60 | 0 | this.add(getMessagePanel(), null); |
61 | ||
62 | 0 | JPanel progressPanel = new JPanel(); |
63 | 0 | progressPanel.setLayout(new GridLayout(1, 3)); |
64 | 0 | progressPanel.add(new JLabel(), null); |
65 | 0 | progressPanel.add(getProgressBar(), null); |
66 | 0 | progressPanel.add(new JLabel(), null); |
67 | 0 | this.add(progressPanel, null); |
68 | 0 | } |
69 | ||
70 | /** | |
71 | * @return Returns the progressBar. | |
72 | */ | |
73 | public JProgressBar getProgressBar() { | |
74 | 0 | if (progressBar == null) { |
75 | 0 | progressBar = new JProgressBar(); |
76 | 0 | progressBar.setMinimum(0); |
77 | 0 | progressBar.setMaximum(110); |
78 | } | |
79 | 0 | return progressBar; |
80 | } | |
81 | ||
82 | /** | |
83 | * @return Returns the messagePanel. | |
84 | */ | |
85 | protected JPanel getMessagePanel() { | |
86 | 0 | if (messagePanel == null) { |
87 | 0 | messagePanel = new JPanel(); |
88 | 0 | messagePanel.setLayout(new BorderLayout()); |
89 | 0 | messagePanel.add(getMessageLabel(), BorderLayout.CENTER); |
90 | } | |
91 | 0 | return messagePanel; |
92 | } | |
93 | ||
94 | /** | |
95 | * @return Returns the messageLabel. | |
96 | */ | |
97 | protected JLabel getMessageLabel() { | |
98 | 0 | if (messageLabel == null) { |
99 | 0 | messageLabel = new JLabel(); |
100 | } | |
101 | 0 | return messageLabel; |
102 | } | |
103 | ||
104 | public void setMessage(String message) { | |
105 | 0 | this.getMessageLabel().setText(message); |
106 | 0 | } |
107 | ||
108 | /** | |
109 | * @return Returns the timer. | |
110 | */ | |
111 | public Timer getTimer() { | |
112 | 0 | if (timer == null || !timer.isRunning()) { |
113 | // Create a timer. | |
114 | 0 | 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 | } | |
126 | 0 | return timer; |
127 | } | |
128 | ||
129 | /** | |
130 | * @return Returns the taskDone. | |
131 | */ | |
132 | public synchronized boolean isTaskDone() { | |
133 | 0 | return taskDone; |
134 | } | |
135 | ||
136 | /** | |
137 | * @param taskDone | |
138 | * The taskDone to set. | |
139 | */ | |
140 | public synchronized void setTaskDone(boolean taskDone) { | |
141 | 0 | this.taskDone = taskDone; |
142 | 0 | getProgressBar().setValue(getProgressBar().getMinimum()); |
143 | 0 | getTimer().stop(); |
144 | 0 | } |
145 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |