Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / progresspanel / TestProgressPanel.java @ 40561

History | View | Annotate | Download (4.61 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.progresspanel;
25

    
26
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
27
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
28
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
29

    
30
/* gvSIG. Geographic Information System of the Valencian Government
31
 *
32
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
33
 * of the Valencian Government (CIT)
34
 * 
35
 * This program is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU General Public License
37
 * as published by the Free Software Foundation; either version 2
38
 * of the License, or (at your option) any later version.
39
 * 
40
 * This program is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43
 * GNU General Public License for more details.
44
 *  
45
 * You should have received a copy of the GNU General Public License
46
 * along with this program; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
48
 * MA  02110-1301, USA.
49
 * 
50
 */
51

    
52
/**
53
 * <code>TestProgressPanel</code>. Test para comprobar el funcionamiento del
54
 * objeto <code>TestProgressPanel</code>
55
 *
56
 * @version 20/03/2007
57
 * @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
58
 */
59
public class TestProgressPanel {
60

    
61
        private tryPanel frame = null;
62

    
63
        public class tryPanel implements Runnable, ButtonsPanelListener {
64
                private ProgressPanel frame = new ProgressPanel();
65
                private volatile Thread blinker;
66

    
67
                public void showWindow() {
68
                        frame.getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(false);
69
                        frame.setTitle("Actualizando datos");
70
                        frame.showLog(false);
71
                        frame.getButtonsPanel().addButtonPressedListener(this);
72
                        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
73
                        frame.setVisible(true);
74
                }
75

    
76
                private boolean threadSuspended = false;
77

    
78
                public void start() {
79
                        blinker = new Thread(this);
80
                        blinker.start();
81
                }
82

    
83
                public synchronized void stop() {
84
                        blinker = null;
85
                        notify();
86
                }
87

    
88
                public void run() {
89
                        Thread thisThread = Thread.currentThread();
90
                        int i = 0;
91
                        frame.addLineLog("Realizando testeo...");
92
                        while ((blinker == thisThread) && (i < 1000)) {
93
                                try {
94
                                        Thread.sleep(1);
95

    
96
                                        synchronized(this) {
97
                                                while (threadSuspended && blinker==thisThread)
98
                                                        wait();
99
                                        }
100
                                } catch (InterruptedException e) {
101
                                }
102

    
103
                                if (i==0)
104
                                        frame.addLineLog("Testeo 1 completado al 0%");
105
                                if ((i>=0) && (i<=100))
106
                                        frame.replaceLastLineLog("Testeo 1 completado al " + i + "%");
107
                                if (i==100) {
108
                                        frame.replaceLastLineLog("Testeo 1 completado");
109
                                        frame.addLineLog("Testeo 2 completado al 0%");
110
                                }
111
                                if ((i>=100) && (i<=800))
112
                                        frame.replaceLastLineLog("Testeo 2 completado al " + (int)((i-100)*100)/700 + "%");
113
                                if (i==800) {
114
                                        frame.replaceLastLineLog("Testeo 2 completado");
115
                                        frame.addLineLog("Testeo 3 completado al 0%");
116
                                }
117
                                if ((i>=800) && (i<=1000))
118
                                        frame.replaceLastLineLog("Testeo 3 completado al " + (int)((i-800)*100)/200 + "%");
119
                                i++;
120

    
121
                                frame.setPercent((int) (i*100)/1000);
122
                        }
123
                        // Cerramos la ventana
124
                        frame.setVisible(false);
125
                        frame = null;
126
                }
127

    
128
                public void actionButtonPressed(ButtonsPanelEvent e) {
129
                        if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
130
                                this.stop();
131
                        }
132
                }
133
        }
134

    
135
        public static void main(String[] args) {
136
                new TestProgressPanel();
137
        }
138

    
139
        /**
140
         * This is the default constructor
141
         */
142
        public TestProgressPanel() {
143
                super();
144
                initialize();
145
        }
146

    
147
        /**
148
         * This method initializes this
149
         *
150
         * @return void
151
         */
152
        private void initialize() {
153
                frame = new tryPanel();
154
                frame.showWindow();
155
                frame.start();
156
        }
157
}