Statistics
| Revision:

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

History | View | Annotate | Download (3.6 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
import org.gvsig.gui.beans.progresspanel.ProgressPanel;
26

    
27
/**
28
 * <code>TestProgressPanel</code>. Test para comprobar el funcionamiento del
29
 * objeto <code>TestProgressPanel</code>
30
 *
31
 * @version 20/03/2007
32
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
33
 */
34
public class TestProgressPanel {
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.getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(false);
44
                        frame.setTitle("Actualizando datos");
45
                        frame.showLog(false);
46
                        frame.show();
47
                        frame.getButtonsPanel().addActionListener(this);
48
                }
49

    
50
                private boolean threadSuspended = false;
51

    
52
    public void start() {
53
      blinker = new Thread(this);
54
      blinker.start();
55
    }
56

    
57
                public synchronized void stop() {
58
                        blinker = null;
59
                        notify();
60
                }
61

    
62
                public void run() {
63
                        Thread thisThread = Thread.currentThread();
64
                        int i = 0;
65
                        frame.addLineLog("Realizando testeo...");
66
                        while ((blinker == thisThread) && (i < 1000)) {
67
                                try {
68
                                        Thread.sleep(1);
69

    
70
                                        synchronized(this) {
71
                                                while (threadSuspended && blinker==thisThread)
72
                                                        wait();
73
                                        }
74
                                } catch (InterruptedException e) {
75
                                }
76
                                
77
                                if (i==0) 
78
                                        frame.addLineLog("Testeo 1 completado al 0%");
79
                                if ((i>=0) && (i<=100)) 
80
                                        frame.replaceLastLineLog("Testeo 1 completado al " + i + "%");
81
                                if (i==100) {
82
                                        frame.replaceLastLineLog("Testeo 1 completado");
83
                                        frame.addLineLog("Testeo 2 completado al 0%");
84
                                }
85
                                if ((i>=100) && (i<=800)) 
86
                                        frame.replaceLastLineLog("Testeo 2 completado al " + (int)((i-100)*100)/700 + "%");
87
                                if (i==800) {
88
                                        frame.replaceLastLineLog("Testeo 2 completado");
89
                                        frame.addLineLog("Testeo 3 completado al 0%");
90
                                }
91
                                if ((i>=800) && (i<=1000)) 
92
                                        frame.replaceLastLineLog("Testeo 3 completado al " + (int)((i-800)*100)/200 + "%");
93
                                i++;
94

    
95
                                frame.setPercent((int) (i*100)/1000);
96
                        }
97
                        // Cerramos la ventana
98
                        frame.hide();
99
                        frame = null;
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
}