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