root / trunk / libraries / libUIComponent / src-test / org / gvsig / gui / beans / progressPanel / TestProgressPanel.java @ 11042
History | View | Annotate | Download (3.64 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.gui.beans.progressPanel; |
20 |
|
21 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
22 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
23 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
24 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
25 |
|
26 |
/**
|
27 |
* <code>TestProgressPanel</code>. Test para comprobar el funcionamiento del
|
28 |
* objeto <code>TestProgressPanel</code>
|
29 |
*
|
30 |
* @version 20/03/2007
|
31 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
|
32 |
*/
|
33 |
public class TestProgressPanel { |
34 |
|
35 |
private tryPanel frame = null; |
36 |
|
37 |
public class tryPanel implements Runnable, ButtonsPanelListener { |
38 |
private ProgressPanel frame = new ProgressPanel(); |
39 |
private volatile Thread blinker; |
40 |
|
41 |
public void showWindow() { |
42 |
frame.getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(false);
|
43 |
frame.setTitle("Actualizando datos");
|
44 |
frame.showLog(false);
|
45 |
frame.show(); |
46 |
frame.getButtonsPanel().addButtonPressedListener(this);
|
47 |
} |
48 |
|
49 |
private boolean threadSuspended = false; |
50 |
|
51 |
public void start() { |
52 |
blinker = new Thread(this); |
53 |
blinker.start(); |
54 |
} |
55 |
|
56 |
public synchronized void stop() { |
57 |
blinker = null;
|
58 |
notify(); |
59 |
} |
60 |
|
61 |
public void run() { |
62 |
Thread thisThread = Thread.currentThread(); |
63 |
int i = 0; |
64 |
frame.addLineLog("Realizando testeo...");
|
65 |
while ((blinker == thisThread) && (i < 1000)) { |
66 |
try {
|
67 |
Thread.sleep(1); |
68 |
|
69 |
synchronized(this) { |
70 |
while (threadSuspended && blinker==thisThread)
|
71 |
wait(); |
72 |
} |
73 |
} catch (InterruptedException e) { |
74 |
} |
75 |
|
76 |
if (i==0) |
77 |
frame.addLineLog("Testeo 1 completado al 0%");
|
78 |
if ((i>=0) && (i<=100)) |
79 |
frame.replaceLastLineLog("Testeo 1 completado al " + i + "%"); |
80 |
if (i==100) { |
81 |
frame.replaceLastLineLog("Testeo 1 completado");
|
82 |
frame.addLineLog("Testeo 2 completado al 0%");
|
83 |
} |
84 |
if ((i>=100) && (i<=800)) |
85 |
frame.replaceLastLineLog("Testeo 2 completado al " + (int)((i-100)*100)/700 + "%"); |
86 |
if (i==800) { |
87 |
frame.replaceLastLineLog("Testeo 2 completado");
|
88 |
frame.addLineLog("Testeo 3 completado al 0%");
|
89 |
} |
90 |
if ((i>=800) && (i<=1000)) |
91 |
frame.replaceLastLineLog("Testeo 3 completado al " + (int)((i-800)*100)/200 + "%"); |
92 |
i++; |
93 |
|
94 |
frame.setPercent((int) (i*100)/1000); |
95 |
} |
96 |
// Cerramos la ventana
|
97 |
frame.hide(); |
98 |
frame = null;
|
99 |
} |
100 |
|
101 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
102 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
103 |
this.stop();
|
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
/**
|
109 |
* @param args
|
110 |
*/
|
111 |
public static void main(String[] args) { |
112 |
// TODO Auto-generated method stub
|
113 |
new TestProgressPanel();
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* This is the default constructor
|
118 |
*/
|
119 |
public TestProgressPanel() {
|
120 |
super();
|
121 |
initialize(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* This method initializes this
|
126 |
*
|
127 |
* @return void
|
128 |
*/
|
129 |
private void initialize() { |
130 |
frame = new tryPanel();
|
131 |
frame.showWindow(); |
132 |
frame.start(); |
133 |
} |
134 |
} |