Statistics
| Revision:

root / trunk / libraries / libUIComponent / src-test / org / gvsig / gui / beans / progressPanel / TestProgressPanel.java @ 10896

History | View | Annotate | Download (3.56 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
        private static final long serialVersionUID = 3008529181447712097L;
35

    
36
        private tryPanel frame = null;
37

    
38
        public class tryPanel implements Runnable, ActionListener {
39
                private ProgressPanel frame = new ProgressPanel();
40
                private volatile Thread blinker;
41

    
42
                public void showWindow() {
43
                        frame.setTitle("Actualizando datos");
44
                        frame.showLog(false);
45
                        frame.show();
46
                        frame.getButtonsPanel().addActionListener(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
                        System.out.println("fin");
100
                }
101

    
102
                public void actionPerformed(ActionEvent e) {
103
                        if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "" ) == 0) {
104
                                this.stop();
105
                        }
106
                        
107
                }
108
        }
109

    
110
        /**
111
         * @param args
112
         */
113
        public static void main(String[] args) {
114
                // TODO Auto-generated method stub
115
                new TestProgressPanel();
116
        }
117

    
118
        /**
119
         * This is the default constructor
120
         */
121
        public TestProgressPanel() {
122
                super();
123
                initialize();
124
        }
125

    
126
        /**
127
         * This method initializes this
128
         * 
129
         * @return void
130
         */
131
        private void initialize() {
132
                frame = new tryPanel();
133
                frame.showWindow();
134
                frame.start();
135
        }
136
}