root / branches / v2_0_0_prep / libraries / libUIComponent / src / org / gvsig / gui / beans / progresspanel / ProgressPanel.java @ 31952
History | View | Annotate | Download (10.8 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.gui.beans.progresspanel; |
23 |
|
24 |
import java.awt.Dialog; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.FlowLayout; |
27 |
import java.awt.Frame; |
28 |
import java.awt.GraphicsConfiguration; |
29 |
import java.awt.HeadlessException; |
30 |
import java.awt.Toolkit; |
31 |
|
32 |
import javax.swing.JDialog; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JProgressBar; |
36 |
import javax.swing.JScrollPane; |
37 |
import javax.swing.JTextPane; |
38 |
|
39 |
import org.gvsig.gui.beans.Messages; |
40 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
41 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
42 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
43 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
44 |
|
45 |
/**
|
46 |
* <code>ProgressPanel</code>. Muestra una ventana de di?logo para representar
|
47 |
* una barra de progreso con su ventana de registro.
|
48 |
*
|
49 |
* @version 15/07/2008
|
50 |
*
|
51 |
* @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
|
52 |
*/
|
53 |
public class ProgressPanel extends JDialog { |
54 |
private static final long serialVersionUID = 4321011219898234352L; |
55 |
|
56 |
private JPanel jPanel = null; |
57 |
private JLabel jLabel = null; |
58 |
private JLabel jLabel1 = null; |
59 |
private JPanel jPanel1 = null; |
60 |
private JPanel njp = null; |
61 |
private DefaultButtonsPanel defaultButtonsPanel = null; |
62 |
private JProgressBar jProgressBar = null; |
63 |
private JScrollPane jScrollPane = null; |
64 |
private JTextPane jTextPane = null; |
65 |
private LogControl text = new LogControl(); |
66 |
private long startTime = System.currentTimeMillis(); |
67 |
private boolean showPause = true; |
68 |
|
69 |
/**
|
70 |
* Constructor
|
71 |
*/
|
72 |
public ProgressPanel() {
|
73 |
super();
|
74 |
initialize(); |
75 |
} |
76 |
|
77 |
public ProgressPanel(boolean showPause) { |
78 |
super();
|
79 |
this.showPause = showPause;
|
80 |
initialize(); |
81 |
} |
82 |
|
83 |
/**
|
84 |
* @see JDialog#JDialog(Dialog, boolean)
|
85 |
*/
|
86 |
public ProgressPanel(Dialog owner, boolean modal) throws HeadlessException { |
87 |
super(owner, modal);
|
88 |
initialize(); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* @see JDialog#JDialog(Dialog, String, boolean, GraphicsConfiguration)
|
93 |
*/
|
94 |
public ProgressPanel(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException { |
95 |
super(owner, title, modal, gc);
|
96 |
initialize(); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* @see JDialog#JDialog(Dialog, String, boolean)
|
101 |
*/
|
102 |
public ProgressPanel(Dialog owner, String title, boolean modal) |
103 |
throws HeadlessException { |
104 |
super(owner, title, modal);
|
105 |
initialize(); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* @see JDialog#JDialog(Dialog, String)
|
110 |
*/
|
111 |
public ProgressPanel(Dialog owner, String title) throws HeadlessException { |
112 |
super(owner, title);
|
113 |
initialize(); |
114 |
} |
115 |
|
116 |
/**
|
117 |
* @see JDialog#JDialog(Dialog)
|
118 |
*/
|
119 |
public ProgressPanel(Dialog owner) throws HeadlessException { |
120 |
super(owner);
|
121 |
initialize(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* @see JDialog#JDialog(Frame, boolean)
|
126 |
*/
|
127 |
public ProgressPanel(Frame owner, boolean modal) throws HeadlessException { |
128 |
super(owner, modal);
|
129 |
initialize(); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* @see JDialog#JDialog(Frame, String, boolean, GraphicsConfiguration)
|
134 |
*/
|
135 |
public ProgressPanel(Frame owner, String title, boolean modal, GraphicsConfiguration gc) { |
136 |
super(owner, title, modal, gc);
|
137 |
initialize(); |
138 |
} |
139 |
|
140 |
/**
|
141 |
* @see JDialog#JDialog(Frame, String, boolean)
|
142 |
*/
|
143 |
public ProgressPanel(Frame owner, String title, boolean modal) |
144 |
throws HeadlessException { |
145 |
super(owner, title, modal);
|
146 |
initialize(); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* @see JDialog#JDialog(Frame, String)
|
151 |
*/
|
152 |
public ProgressPanel(Frame owner, String title) throws HeadlessException { |
153 |
super(owner, title);
|
154 |
initialize(); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* @see JDialog#JDialog(Frame)
|
159 |
*/
|
160 |
public ProgressPanel(Frame owner) throws HeadlessException { |
161 |
super(owner);
|
162 |
initialize(); |
163 |
} |
164 |
|
165 |
/**
|
166 |
* This method initializes this
|
167 |
*/
|
168 |
private void initialize() { |
169 |
njp = new JPanel(); |
170 |
njp.setLayout(new java.awt.BorderLayout(5, 5)); |
171 |
njp.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 15, 5, 15)); |
172 |
this.setContentPane(njp);
|
173 |
this.setResizable(false); |
174 |
njp.add(getJPanel(), java.awt.BorderLayout.NORTH); |
175 |
njp.add(getJPanel1(), java.awt.BorderLayout.CENTER); |
176 |
njp.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH); |
177 |
showLog(false);
|
178 |
setPercent(0);
|
179 |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); |
180 |
this.setLocation(
|
181 |
(int) (d.getWidth() - this.getWidth()) >> 1, |
182 |
(int) (d.getHeight() - this.getHeight()) >> 1); |
183 |
this.setVisible(true); |
184 |
} |
185 |
|
186 |
/**
|
187 |
* This method initializes jPanel
|
188 |
*
|
189 |
* @return javax.swing.JPanel
|
190 |
*/
|
191 |
private JPanel getJPanel() { |
192 |
if (jPanel == null) { |
193 |
jLabel1 = new JLabel(); |
194 |
jLabel = new JLabel(); |
195 |
jLabel.setText(Messages.getText("espere") + "..."); |
196 |
jPanel = new JPanel(); |
197 |
jPanel.setLayout(new java.awt.BorderLayout(5, 5)); |
198 |
jPanel.add(jLabel, java.awt.BorderLayout.WEST); |
199 |
jPanel.add(jLabel1, java.awt.BorderLayout.EAST); |
200 |
} |
201 |
return jPanel;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* This method initializes jPanel1
|
206 |
*
|
207 |
* @return javax.swing.JPanel
|
208 |
*/
|
209 |
private JPanel getJPanel1() { |
210 |
if (jPanel1 == null) { |
211 |
jPanel1 = new JPanel(); |
212 |
jPanel1.setLayout(new java.awt.BorderLayout(5, 5)); |
213 |
jPanel1.add(getJProgressBar(), java.awt.BorderLayout.NORTH); |
214 |
jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
215 |
} |
216 |
return jPanel1;
|
217 |
} |
218 |
|
219 |
public void addButtonPressedListener(ButtonsPanelListener listener) { |
220 |
getDefaultButtonsPanel().addButtonPressedListener(listener); |
221 |
} |
222 |
|
223 |
public void removeButtonPressedListener(ButtonsPanelListener listener) { |
224 |
getDefaultButtonsPanel().removeButtonPressedListener(listener); |
225 |
} |
226 |
|
227 |
public void showLog(boolean visible) { |
228 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible); |
229 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible); |
230 |
jScrollPane.setVisible(visible); |
231 |
|
232 |
this.setIgnoreRepaint(true); |
233 |
|
234 |
if (visible)
|
235 |
this.setSize(this.getWidth(), 300); |
236 |
else
|
237 |
this.pack();
|
238 |
|
239 |
this.setIgnoreRepaint(false); |
240 |
if (this.isVisible()) |
241 |
this.setVisible(true); |
242 |
} |
243 |
|
244 |
public void showPause(boolean visible) { |
245 |
if (showPause) {
|
246 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_RESTART).setVisible(!visible); |
247 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(visible); |
248 |
} else {
|
249 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_RESTART).setVisible(false);
|
250 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(false);
|
251 |
} |
252 |
} |
253 |
|
254 |
/**
|
255 |
* @see DefaultButtonsPanel#getButtonsPanel()
|
256 |
*/
|
257 |
public ButtonsPanel getButtonsPanel() {
|
258 |
return getDefaultButtonsPanel().getButtonsPanel();
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* This method initializes DefaultButtonsPanel
|
263 |
*
|
264 |
* @return DefaultButtonsPanel
|
265 |
*/
|
266 |
public DefaultButtonsPanel getDefaultButtonsPanel() {
|
267 |
if (defaultButtonsPanel == null) { |
268 |
defaultButtonsPanel = new DefaultButtonsPanel(ButtonsPanel.BUTTONS_NONE);
|
269 |
getButtonsPanel().addSeeDetails(); |
270 |
getButtonsPanel().addHideDetails(); |
271 |
getButtonsPanel().addPause(); |
272 |
getButtonsPanel().addRestart(); |
273 |
showPause(true);
|
274 |
getButtonsPanel().addCancel(); |
275 |
getButtonsPanel().setLayout(new java.awt.FlowLayout(FlowLayout.CENTER)); |
276 |
getButtonsPanel().addButtonPressedListener(new ButtonsPanelListener() {
|
277 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
278 |
switch (e.getButton()) {
|
279 |
case ButtonsPanel.BUTTON_SEEDETAILS:
|
280 |
showLog(true);
|
281 |
break;
|
282 |
case ButtonsPanel.BUTTON_HIDEDETAILS:
|
283 |
showLog(false);
|
284 |
break;
|
285 |
case ButtonsPanel.BUTTON_PAUSE:
|
286 |
showPause(false);
|
287 |
break;
|
288 |
case ButtonsPanel.BUTTON_RESTART:
|
289 |
showPause(true);
|
290 |
break;
|
291 |
} |
292 |
} |
293 |
}); |
294 |
} |
295 |
return defaultButtonsPanel;
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* This method initializes jProgressBar
|
300 |
*
|
301 |
* @return javax.swing.JProgressBar
|
302 |
*/
|
303 |
private JProgressBar getJProgressBar() { |
304 |
if (jProgressBar == null) { |
305 |
jProgressBar = new JProgressBar(); |
306 |
jProgressBar.setValue(50);
|
307 |
jProgressBar.setPreferredSize(new Dimension(450, 18)); |
308 |
} |
309 |
return jProgressBar;
|
310 |
} |
311 |
|
312 |
/**
|
313 |
* This method initializes jScrollPane
|
314 |
*
|
315 |
* @return javax.swing.JScrollPane
|
316 |
*/
|
317 |
private JScrollPane getJScrollPane() { |
318 |
if (jScrollPane == null) { |
319 |
jScrollPane = new JScrollPane(); |
320 |
jScrollPane.setViewportView(getJTextPane()); |
321 |
jScrollPane.setVisible(false);
|
322 |
} |
323 |
return jScrollPane;
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* This method initializes jTextPane
|
328 |
*
|
329 |
* @return javax.swing.JTextPane
|
330 |
*/
|
331 |
private JTextPane getJTextPane() { |
332 |
if (jTextPane == null) { |
333 |
jTextPane = new JTextPane(); |
334 |
jTextPane.setEditable(false);
|
335 |
} |
336 |
return jTextPane;
|
337 |
} |
338 |
|
339 |
private void updateLog() { |
340 |
jTextPane.setText(text.getText()); |
341 |
jTextPane.setCaretPosition(jTextPane.getText().length()); |
342 |
} |
343 |
|
344 |
public void addLineLog(String line) { |
345 |
text.addLine(line); |
346 |
updateLog(); |
347 |
} |
348 |
|
349 |
public void replaceLastLineLog(String line) { |
350 |
text.replaceLastLine(line); |
351 |
updateLog(); |
352 |
} |
353 |
|
354 |
public void setLog(String value) { |
355 |
long time = (System.currentTimeMillis() - startTime) / 1000; |
356 |
text.setText(value + "\n" + Messages.getText("tiempo_transcurrido") + ": " + time + "s"); |
357 |
updateLog(); |
358 |
} |
359 |
|
360 |
public int getPercent() { |
361 |
return jProgressBar.getValue();
|
362 |
} |
363 |
|
364 |
public void setPercent(int value) { |
365 |
if ((value == 0) && (!jProgressBar.isIndeterminate())) { |
366 |
jProgressBar.setIndeterminate(true);
|
367 |
jLabel1.setVisible(false);
|
368 |
} |
369 |
if ((value != 0) && (jProgressBar.isIndeterminate())) { |
370 |
jProgressBar.setIndeterminate(false);
|
371 |
jLabel1.setVisible(true);
|
372 |
} |
373 |
jProgressBar.setValue(value); |
374 |
jLabel1.setText(value + "%");
|
375 |
} |
376 |
|
377 |
public void setLabel(String value) { |
378 |
jLabel.setText(value); |
379 |
} |
380 |
|
381 |
/**
|
382 |
* <p>Sets whether this panel will show a normal progress bar
|
383 |
* or an indeterminate one.</p>
|
384 |
*
|
385 |
* @see JProgressBar.setIndeterminate(boolean)
|
386 |
* @param indeterminate
|
387 |
*/
|
388 |
public void setIndeterminate(boolean indeterminate) { |
389 |
getJProgressBar().setIndeterminate(indeterminate); |
390 |
} |
391 |
|
392 |
/**
|
393 |
* <p>Gets whether this panel will show a normal progress bar
|
394 |
* or an indeterminate one.</p>
|
395 |
*
|
396 |
* @see JProgressBar.setIndeterminate(boolean)
|
397 |
* @param indeterminate
|
398 |
*/
|
399 |
public boolean getIndeterminate() { |
400 |
return getJProgressBar().isIndeterminate();
|
401 |
} |
402 |
} |