Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libUIComponent / src-test-ui / org / gvsig / gui / beans / progresspanel / TestProgressPanel.java @ 31952

History | View | Annotate | Download (3.67 KB)

1
package org.gvsig.gui.beans.progresspanel;
2

    
3
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
4
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
5
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
6

    
7
/* gvSIG. Geographic Information System of the Valencian Government
8
 *
9
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
10
 * of the Valencian Government (CIT)
11
 * 
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 * 
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *  
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
25
 * MA  02110-1301, USA.
26
 * 
27
 */
28

    
29
/**
30
 * <code>TestProgressPanel</code>. Test para comprobar el funcionamiento del
31
 * objeto <code>TestProgressPanel</code>
32
 *
33
 * @version 20/03/2007
34
 * @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
35
 */
36
public class TestProgressPanel {
37

    
38
        private tryPanel frame = null;
39

    
40
        public class tryPanel implements Runnable, ButtonsPanelListener {
41
                private ProgressPanel frame = new ProgressPanel();
42
                private volatile Thread blinker;
43

    
44
                public void showWindow() {
45
                        frame.getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(false);
46
                        frame.setTitle("Actualizando datos");
47
                        frame.showLog(false);
48
                        frame.getButtonsPanel().addButtonPressedListener(this);
49
                        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
50
                        frame.setVisible(true);
51
                }
52

    
53
                private boolean threadSuspended = false;
54

    
55
                public void start() {
56
                        blinker = new Thread(this);
57
                        blinker.start();
58
                }
59

    
60
                public synchronized void stop() {
61
                        blinker = null;
62
                        notify();
63
                }
64

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

    
73
                                        synchronized(this) {
74
                                                while (threadSuspended && blinker==thisThread)
75
                                                        wait();
76
                                        }
77
                                } catch (InterruptedException e) {
78
                                }
79

    
80
                                if (i==0)
81
                                        frame.addLineLog("Testeo 1 completado al 0%");
82
                                if ((i>=0) && (i<=100))
83
                                        frame.replaceLastLineLog("Testeo 1 completado al " + i + "%");
84
                                if (i==100) {
85
                                        frame.replaceLastLineLog("Testeo 1 completado");
86
                                        frame.addLineLog("Testeo 2 completado al 0%");
87
                                }
88
                                if ((i>=100) && (i<=800))
89
                                        frame.replaceLastLineLog("Testeo 2 completado al " + (int)((i-100)*100)/700 + "%");
90
                                if (i==800) {
91
                                        frame.replaceLastLineLog("Testeo 2 completado");
92
                                        frame.addLineLog("Testeo 3 completado al 0%");
93
                                }
94
                                if ((i>=800) && (i<=1000))
95
                                        frame.replaceLastLineLog("Testeo 3 completado al " + (int)((i-800)*100)/200 + "%");
96
                                i++;
97

    
98
                                frame.setPercent((int) (i*100)/1000);
99
                        }
100
                        // Cerramos la ventana
101
                        frame.setVisible(false);
102
                        frame = null;
103
                }
104

    
105
                public void actionButtonPressed(ButtonsPanelEvent e) {
106
                        if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
107
                                this.stop();
108
                        }
109
                }
110
        }
111

    
112
        public static void main(String[] args) {
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
}