Revision 10818

View differences:

trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/progressPanel/TestProgressPanel.java
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
 * <code>TestProgressPanel</code>. Test para comprobar el funcionamiento del
22
 * objeto <code>TestProgressPanel</code>
23
 *
24
 * @version 20/03/2007
25
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
26
 */
27
public class TestProgressPanel {
28
	private static final long serialVersionUID = 3008529181447712097L;
29

  
30
	private tryPanel frame = null;
31

  
32
	public class tryPanel extends Thread {
33
		private ProgressPanel frame = new ProgressPanel();
34

  
35
		public void showWindow() {
36
			frame.setTitle("Actualizando datos");
37
			frame.showLog(true);
38
			frame.show();
39
			if (this.isAlive())
40
				this.resume();
41
			else
42
				this.start();
43
		}
44

  
45
		public synchronized void run() {
46
			int i = 0;
47
			frame.addLineLog("Realizando testeo...");
48
			while (i < 1000) {
49
				if (i==0) 
50
					frame.addLineLog("Testeo 1 completado al 0%");
51
				if ((i>=0) && (i<=100)) 
52
					frame.replaceLastLineLog("Testeo 1 completado al " + i + "%");
53
				if (i==100) {
54
					frame.replaceLastLineLog("Testeo 1 completado");
55
					frame.addLineLog("Testeo 2 completado al 0%");
56
				}
57
				if ((i>=100) && (i<=800)) 
58
					frame.replaceLastLineLog("Testeo 2 completado al " + (int)((i-100)*100)/700 + "%");
59
				if (i==800) {
60
					frame.replaceLastLineLog("Testeo 2 completado");
61
					frame.addLineLog("Testeo 3 completado al 0%");
62
				}
63
				if ((i>=800) && (i<=1000)) 
64
					frame.replaceLastLineLog("Testeo 3 completado al " + (int)((i-800)*100)/200 + "%");
65
				i++;
66

  
67
				frame.setPercent((int) (i*100)/1000);
68
				try {
69
					sleep(50);
70
				} catch (InterruptedException e) {
71
					e.printStackTrace();
72
				}
73
			}
74
			// Cerramos la ventana
75
			frame.hide();
76
			frame = null;
77

  
78
			this.suspend();
79
		}
80
	}
81

  
82
	/**
83
	 * @param args
84
	 */
85
	public static void main(String[] args) {
86
		// TODO Auto-generated method stub
87
		new TestProgressPanel();
88
	}
89

  
90
	/**
91
	 * This is the default constructor
92
	 */
93
	public TestProgressPanel() {
94
		super();
95
		initialize();
96
	}
97

  
98
	/**
99
	 * This method initializes this
100
	 * 
101
	 * @return void
102
	 */
103
	private void initialize() {
104
		frame = new tryPanel();
105
		frame.showWindow();
106
		frame.run();
107
	}
108
}
0 109

  
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/buttonsPanel/ButtonsPanel.java
49 49
	public static final int BUTTON_NO = 5;
50 50
	public static final int BUTTON_CLOSE = 6;
51 51
	public static final int BUTTON_EXIT = 7;
52
	public static final int BUTTON_SEEDETAILS = 8;
53
	public static final int BUTTON_HIDEDETAILS = 9;
52 54
	
53 55
	public static final int BUTTONS_ACCEPT = 1;
54 56
	public static final int BUTTONS_ACCEPTCANCEL = 2;
55 57
	public static final int BUTTONS_ACCEPTCANCELAPPLY = 3;
56
	public static final int BUTTONS_YESNO = 4;
57
	public static final int BUTTONS_CLOSE = 5;
58
	public static final int BUTTONS_EXIT = 6;
59
	public static final int BUTTONS_NONE = 7;
58
	public static final int BUTTONS_CANCEL = 4;
59
	public static final int BUTTONS_YESNO = 5;
60
	public static final int BUTTONS_CLOSE = 6;
61
	public static final int BUTTONS_EXIT = 7;
62
	public static final int BUTTONS_NONE = 8;
60 63

  
61 64
	/**
62 65
	 * Crea un ButtonsPanel con un Layout por defecto.
......
64 67
	public ButtonsPanel() {
65 68
		setLayout(new java.awt.FlowLayout(FlowLayout.RIGHT));
66 69
	}
67
	
70

  
68 71
	/**
69 72
	 * Crea un ButtonsPanel con un Layout por defecto.
70 73
	 * 
......
85 88
				addCancel();
86 89
				addApply();
87 90
				break;
91
			case BUTTONS_CANCEL:
92
				addCancel();
93
				break;
88 94
			case BUTTONS_YESNO:
89 95
				addYes();
90 96
				addNo();
......
168 174
	}
169 175

  
170 176
	/**
177
	 * A?adir el boton Ver detalles.
178
	 */
179
	public void addSeeDetails() {
180
		addButton(Messages.getText("verdetalles"), BUTTON_SEEDETAILS);
181
	}
182
	
183
	/**
184
	 * A?adir el boton Ocultar detalles.
185
	 */
186
	public void addHideDetails() {
187
		addButton(Messages.getText("ocultardetalles"), BUTTON_HIDEDETAILS);
188
	}
189
	
190
	/**
171 191
	 * A?adimos un bot?n definido por el usuario.
172 192
	 * 
173 193
	 * @param text Texto que contendr? el bot?n
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/translations/text.properties
30 30
no=No
31 31
aplicar=Aplicar
32 32
cerrar=Cerrar
33
salir=Salir
33
salir=Salir
34
verdetalles=Ver detalles
35
ocultardetalles=Ocultar detalles
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/progressPanel/ProgressPanel.java
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.Dimension;
22
import java.awt.FlowLayout;
23
import java.awt.Toolkit;
24

  
25
import javax.swing.JFrame;
26
import javax.swing.JLabel;
27
import javax.swing.JPanel;
28
import javax.swing.JProgressBar;
29
import javax.swing.JScrollPane;
30
import javax.swing.JTextPane;
31

  
32
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
33

  
34
/**
35
 * <code>ProgressPanel</code>. Muestra una ventana de di?logo para representar
36
 * una barra de progreso con su ventana de registro.
37
 *
38
 * @version 20/03/2007
39
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
40
 */
41
public class ProgressPanel extends JFrame {
42
	private static final long serialVersionUID = -6930857769971064429L;
43
	private JPanel jPanel = null;
44
	private JLabel jLabel = null;
45
	private JLabel jLabel1 = null;
46
	private JPanel jPanel1 = null;
47
	private JPanel njp = null;
48
	private ButtonsPanel buttonsPanel = null;
49
	private JProgressBar jProgressBar = null;
50
	private JScrollPane jScrollPane = null;
51
	private JTextPane jTextPane = null;
52
	private String realText = "";
53

  
54
	/**
55
	 * Constructor
56
	 */
57
	public ProgressPanel() {
58
		// TODO Auto-generated constructor stub
59
		initialize();
60
	}
61

  
62
	/**
63
	 * This method initializes this
64
	 * 
65
	 */
66
	private void initialize() {
67
		njp = new JPanel();
68
		njp.setLayout(new java.awt.BorderLayout(5, 5));
69
		njp.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
70
		this.setContentPane(njp);
71
		this.setResizable(false);
72
		njp.add(getJPanel(), java.awt.BorderLayout.NORTH);
73
		njp.add(getJPanel1(), java.awt.BorderLayout.CENTER);
74
		njp.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
75
		showLog(false);
76
		setPercent(0);
77
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
78
		this.setLocation(
79
				(int) (d.getWidth() - this.getWidth()) >> 1,
80
				(int) (d.getHeight() - this.getHeight()) >> 1);
81
		this.show();
82
	}
83

  
84
	/**
85
	 * This method initializes jPanel	
86
	 * 	
87
	 * @return javax.swing.JPanel	
88
	 */
89
	private JPanel getJPanel() {
90
		if (jPanel == null) {
91
			jLabel1 = new JLabel();
92
			jLabel = new JLabel();
93
			jLabel.setText("Espere...");
94
			jPanel = new JPanel();
95
			jPanel.setLayout(new java.awt.BorderLayout(5, 5));
96
			jPanel.add(jLabel, java.awt.BorderLayout.WEST);
97
			jPanel.add(jLabel1, java.awt.BorderLayout.EAST);
98
		}
99
		return jPanel;
100
	}
101

  
102
	/**
103
	 * This method initializes jPanel1	
104
	 * 	
105
	 * @return javax.swing.JPanel	
106
	 */
107
	private JPanel getJPanel1() {
108
		if (jPanel1 == null) {
109
			jPanel1 = new JPanel();
110
			jPanel1.setLayout(new java.awt.BorderLayout(5, 5));
111
			jPanel1.add(getJProgressBar(), java.awt.BorderLayout.NORTH);
112
			jPanel1.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
113
		}
114
		return jPanel1;
115
	}
116

  
117
	public void showLog(boolean visible) {
118
		buttonsPanel.getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible);
119
		buttonsPanel.getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible);
120
		jScrollPane.setVisible(visible);
121

  
122
		int width = 400;
123
		int height = (visible?300:120);
124

  
125
		this.setSize(width, height);
126
		this.show();
127
	}
128
	
129
	/**
130
	 * This method initializes ButtonsPanel	
131
	 * 	
132
	 * @return ButtonsPanel	
133
	 */
134
	private ButtonsPanel getButtonsPanel() {
135
		if (buttonsPanel == null) {
136
			buttonsPanel = new ButtonsPanel(ButtonsPanel.BUTTONS_NONE);
137
			buttonsPanel.addSeeDetails();
138
			buttonsPanel.addHideDetails();
139
			buttonsPanel.addCancel();
140
			buttonsPanel.setLayout(new java.awt.FlowLayout(FlowLayout.CENTER));
141
			buttonsPanel.addActionListener(new java.awt.event.ActionListener() {
142
				public void actionPerformed(java.awt.event.ActionEvent e) {
143
					if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_SEEDETAILS + "") == 0) {
144
						showLog(true);
145
					}
146
					if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_HIDEDETAILS + "") == 0) {
147
						showLog(false);
148
					}
149
				}
150
			});
151
		}
152
		return buttonsPanel;
153
	}
154

  
155
	/**
156
	 * This method initializes jProgressBar	
157
	 * 	
158
	 * @return javax.swing.JProgressBar	
159
	 */
160
	private JProgressBar getJProgressBar() {
161
		if (jProgressBar == null) {
162
			jProgressBar = new JProgressBar();
163
			jProgressBar.setValue(50);
164
		}
165
		return jProgressBar;
166
	}
167

  
168
	/**
169
	 * This method initializes jScrollPane	
170
	 * 	
171
	 * @return javax.swing.JScrollPane	
172
	 */
173
	private JScrollPane getJScrollPane() {
174
		if (jScrollPane == null) {
175
			jScrollPane = new JScrollPane();
176
			jScrollPane.setViewportView(getJTextPane());
177
			jScrollPane.setVisible(false);
178
		}
179
		return jScrollPane;
180
	}
181

  
182
	/**
183
	 * This method initializes jTextPane	
184
	 * 	
185
	 * @return javax.swing.JTextPane	
186
	 */
187
	private JTextPane getJTextPane() {
188
		if (jTextPane == null) {
189
			jTextPane = new JTextPane();
190
		}
191
		return jTextPane;
192
	}
193
	
194
	public void addLineLog(String line) {
195
		realText = jTextPane.getText();
196
		jTextPane.setText(realText + line + "\n");
197
		
198
	}
199

  
200
	public void replaceLastLineLog(String line) {
201
		jTextPane.setText(realText + line + "\n");
202
	}
203
	
204
	public int getPercent() {
205
		return jProgressBar.getValue();
206
	}
207

  
208
	public void setPercent(int value) {
209
		jProgressBar.setValue(value);
210
		jLabel1.setText(value + "%");
211
	}
212
	
213
	public void setLabel(String value) {
214
		jLabel.setText(value);
215
	}
216
}
0 217

  

Also available in: Unified diff