17 |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
18 |
*/
|
19 |
19 |
package org.gvsig.gui.beans.progressPanel;
|
|
20 |
|
|
21 |
import java.awt.event.ActionEvent;
|
|
22 |
import java.awt.event.ActionListener;
|
|
23 |
|
|
24 |
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
|
|
25 |
|
20 |
26 |
/**
|
21 |
27 |
* <code>TestProgressPanel</code>. Test para comprobar el funcionamiento del
|
22 |
28 |
* objeto <code>TestProgressPanel</code>
|
... | ... | |
29 |
35 |
|
30 |
36 |
private tryPanel frame = null;
|
31 |
37 |
|
32 |
|
public class tryPanel extends Thread {
|
|
38 |
public class tryPanel implements Runnable, ActionListener {
|
33 |
39 |
private ProgressPanel frame = new ProgressPanel();
|
|
40 |
private volatile Thread blinker;
|
34 |
41 |
|
35 |
42 |
public void showWindow() {
|
36 |
43 |
frame.setTitle("Actualizando datos");
|
37 |
44 |
frame.showLog(false);
|
38 |
45 |
frame.show();
|
39 |
|
if (this.isAlive())
|
40 |
|
this.resume();
|
41 |
|
else
|
42 |
|
this.start();
|
|
46 |
frame.getButtonsPanel().addActionListener(this);
|
43 |
47 |
}
|
44 |
48 |
|
45 |
|
public synchronized void run() {
|
|
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();
|
46 |
63 |
int i = 0;
|
47 |
64 |
frame.addLineLog("Realizando testeo...");
|
48 |
|
while (i < 1000) {
|
|
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 |
|
49 |
76 |
if (i==0)
|
50 |
77 |
frame.addLineLog("Testeo 1 completado al 0%");
|
51 |
78 |
if ((i>=0) && (i<=100))
|
... | ... | |
65 |
92 |
i++;
|
66 |
93 |
|
67 |
94 |
frame.setPercent((int) (i*100)/1000);
|
68 |
|
try {
|
69 |
|
sleep(50);
|
70 |
|
} catch (InterruptedException e) {
|
71 |
|
e.printStackTrace();
|
72 |
|
}
|
73 |
95 |
}
|
74 |
96 |
// Cerramos la ventana
|
75 |
97 |
frame.hide();
|
76 |
98 |
frame = null;
|
|
99 |
System.out.println("fin");
|
|
100 |
}
|
77 |
101 |
|
78 |
|
this.suspend();
|
|
102 |
public void actionPerformed(ActionEvent e) {
|
|
103 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "" ) == 0) {
|
|
104 |
this.stop();
|
|
105 |
}
|
|
106 |
|
79 |
107 |
}
|
80 |
108 |
}
|
81 |
109 |
|
... | ... | |
103 |
131 |
private void initialize() {
|
104 |
132 |
frame = new tryPanel();
|
105 |
133 |
frame.showWindow();
|
106 |
|
frame.run();
|
|
134 |
frame.start();
|
107 |
135 |
}
|
108 |
136 |
}
|