root / trunk / libraries / libUIComponent / src-test / org / gvsig / gui / beans / progressPanel / TestProgressPanel.java @ 10945
History | View | Annotate | Download (3.5 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 java.awt.event.ActionEvent; |
22 |
import java.awt.event.ActionListener; |
23 |
|
24 |
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel; |
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, ActionListener { |
38 |
private ProgressPanel frame = new ProgressPanel(); |
39 |
private volatile Thread blinker; |
40 |
|
41 |
public void showWindow() { |
42 |
frame.setTitle("Actualizando datos");
|
43 |
frame.showLog(false);
|
44 |
frame.show(); |
45 |
frame.getButtonsPanel().addActionListener(this);
|
46 |
} |
47 |
|
48 |
private boolean threadSuspended = false; |
49 |
|
50 |
public void start() { |
51 |
blinker = new Thread(this); |
52 |
blinker.start(); |
53 |
} |
54 |
|
55 |
public synchronized void stop() { |
56 |
blinker = null;
|
57 |
notify(); |
58 |
} |
59 |
|
60 |
public void run() { |
61 |
Thread thisThread = Thread.currentThread(); |
62 |
int i = 0; |
63 |
frame.addLineLog("Realizando testeo...");
|
64 |
while ((blinker == thisThread) && (i < 1000)) { |
65 |
try {
|
66 |
Thread.sleep(1); |
67 |
|
68 |
synchronized(this) { |
69 |
while (threadSuspended && blinker==thisThread)
|
70 |
wait(); |
71 |
} |
72 |
} catch (InterruptedException e) { |
73 |
} |
74 |
|
75 |
if (i==0) |
76 |
frame.addLineLog("Testeo 1 completado al 0%");
|
77 |
if ((i>=0) && (i<=100)) |
78 |
frame.replaceLastLineLog("Testeo 1 completado al " + i + "%"); |
79 |
if (i==100) { |
80 |
frame.replaceLastLineLog("Testeo 1 completado");
|
81 |
frame.addLineLog("Testeo 2 completado al 0%");
|
82 |
} |
83 |
if ((i>=100) && (i<=800)) |
84 |
frame.replaceLastLineLog("Testeo 2 completado al " + (int)((i-100)*100)/700 + "%"); |
85 |
if (i==800) { |
86 |
frame.replaceLastLineLog("Testeo 2 completado");
|
87 |
frame.addLineLog("Testeo 3 completado al 0%");
|
88 |
} |
89 |
if ((i>=800) && (i<=1000)) |
90 |
frame.replaceLastLineLog("Testeo 3 completado al " + (int)((i-800)*100)/200 + "%"); |
91 |
i++; |
92 |
|
93 |
frame.setPercent((int) (i*100)/1000); |
94 |
} |
95 |
// Cerramos la ventana
|
96 |
frame.hide(); |
97 |
frame = null;
|
98 |
System.out.println("fin"); |
99 |
} |
100 |
|
101 |
public void actionPerformed(ActionEvent e) { |
102 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "" ) == 0) { |
103 |
this.stop();
|
104 |
} |
105 |
|
106 |
} |
107 |
} |
108 |
|
109 |
/**
|
110 |
* @param args
|
111 |
*/
|
112 |
public static void main(String[] args) { |
113 |
// TODO Auto-generated method stub
|
114 |
new TestProgressPanel();
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* This is the default constructor
|
119 |
*/
|
120 |
public TestProgressPanel() {
|
121 |
super();
|
122 |
initialize(); |
123 |
} |
124 |
|
125 |
/**
|
126 |
* This method initializes this
|
127 |
*
|
128 |
* @return void
|
129 |
*/
|
130 |
private void initialize() { |
131 |
frame = new tryPanel();
|
132 |
frame.showWindow(); |
133 |
frame.start(); |
134 |
} |
135 |
} |