svn-gvsig-desktop / tags / v10_RC2c / libraries / libIverUtiles / src / com / iver / utiles / swing / threads / UndefinedProgressMonitor.java @ 8745
History | View | Annotate | Download (7.46 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-mar-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: UndefinedProgressMonitor.java 8745 2006-11-14 13:14:23Z $
|
47 |
* $Log$
|
48 |
* Revision 1.3.4.1 2006-09-27 10:21:20 jorpiell
|
49 |
* A?adida la funcionalidad para que las ventanas de progreso salgan centradas
|
50 |
*
|
51 |
* Revision 1.3 2006/04/18 15:16:14 azabala
|
52 |
* a?adida la posibilidad de personalizar el titulo del dialogo de proceso
|
53 |
*
|
54 |
* Revision 1.2 2006/03/20 16:04:21 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.1 2006/03/14 19:23:58 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
*
|
61 |
*/
|
62 |
package com.iver.utiles.swing.threads; |
63 |
|
64 |
import java.awt.Frame; |
65 |
|
66 |
import javax.swing.JButton; |
67 |
import javax.swing.JDialog; |
68 |
import javax.swing.JLabel; |
69 |
import javax.swing.JPanel; |
70 |
import javax.swing.JProgressBar; |
71 |
|
72 |
import com.iver.utiles.swing.WindowUtils; |
73 |
|
74 |
import java.awt.GridBagLayout; |
75 |
import java.awt.GridBagConstraints; |
76 |
|
77 |
/**
|
78 |
* Dialog that shows the evolution of the execution of a
|
79 |
* ITask.
|
80 |
* If this ITask is a defined task (we know the number of steps
|
81 |
* it must do) it shows a progress bar.
|
82 |
*
|
83 |
* If it doesnt, progress bar is filling and emptying
|
84 |
* @author azabala
|
85 |
*
|
86 |
*/
|
87 |
public class UndefinedProgressMonitor extends JDialog |
88 |
implements IProgressMonitorIF{
|
89 |
|
90 |
|
91 |
private static final long serialVersionUID = 8776505862813807891L; |
92 |
private JPanel jContentPane = null; |
93 |
private JLabel mainTitleLabel = null; |
94 |
private JLabel noteLabel = null; |
95 |
private JProgressBar jProgressBar = null; |
96 |
private JButton cancelButton = null; |
97 |
boolean canceled = false; |
98 |
private String title = "Processing..."; |
99 |
|
100 |
/**
|
101 |
* This is the default constructor
|
102 |
*/
|
103 |
public UndefinedProgressMonitor() {
|
104 |
super();
|
105 |
initialize(); |
106 |
} |
107 |
/**
|
108 |
* Constructor which specify the dialog title
|
109 |
* (for example:processing, etc)
|
110 |
* @param parent
|
111 |
* @param title
|
112 |
*/
|
113 |
public UndefinedProgressMonitor(Frame parent, String title){ |
114 |
super(parent, false); |
115 |
this.title = title;
|
116 |
initialize(); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* This method initializes this
|
121 |
*
|
122 |
* @return void
|
123 |
*
|
124 |
* FIXME Internationalize this
|
125 |
*/
|
126 |
private void initialize() { |
127 |
this.setSize(318, 181); |
128 |
this.setTitle(title);
|
129 |
this.setContentPane(getJContentPane());
|
130 |
WindowUtils.centerWindow(this);
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* This method initializes jContentPane
|
135 |
*
|
136 |
* @return javax.swing.JPanel
|
137 |
*/
|
138 |
private JPanel getJContentPane() { |
139 |
if (jContentPane == null) { |
140 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
141 |
gridBagConstraints3.insets = new java.awt.Insets(6,97,18,125); |
142 |
gridBagConstraints3.gridy = 3;
|
143 |
gridBagConstraints3.ipadx = 4;
|
144 |
gridBagConstraints3.ipady = -4;
|
145 |
gridBagConstraints3.gridx = 0;
|
146 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
147 |
gridBagConstraints2.insets = new java.awt.Insets(11,43,5,32); |
148 |
gridBagConstraints2.gridy = 2;
|
149 |
gridBagConstraints2.ipadx = 109;
|
150 |
gridBagConstraints2.ipady = 4;
|
151 |
gridBagConstraints2.fill = java.awt.GridBagConstraints.NONE; |
152 |
gridBagConstraints2.gridwidth = 2;
|
153 |
gridBagConstraints2.anchor = java.awt.GridBagConstraints.CENTER; |
154 |
gridBagConstraints2.gridx = 0;
|
155 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
156 |
gridBagConstraints1.insets = new java.awt.Insets(9,43,8,32); |
157 |
gridBagConstraints1.gridy = 1;
|
158 |
gridBagConstraints1.ipadx = 180;
|
159 |
gridBagConstraints1.ipady = 0;
|
160 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
161 |
gridBagConstraints1.gridx = 0;
|
162 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
163 |
gridBagConstraints.insets = new java.awt.Insets(10,43,8,32); |
164 |
gridBagConstraints.gridy = 0;
|
165 |
gridBagConstraints.ipadx = 148;
|
166 |
gridBagConstraints.ipady = 11;
|
167 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
168 |
gridBagConstraints.gridx = 0;
|
169 |
noteLabel = new JLabel(); |
170 |
noteLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); |
171 |
noteLabel.setText("noteLabel");
|
172 |
mainTitleLabel = new JLabel(); |
173 |
mainTitleLabel.setText("mainTittleLabel");
|
174 |
mainTitleLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); |
175 |
jContentPane = new JPanel(); |
176 |
jContentPane.setLayout(new GridBagLayout()); |
177 |
jContentPane.add(mainTitleLabel, gridBagConstraints); |
178 |
jContentPane.add(noteLabel, gridBagConstraints1); |
179 |
jContentPane.add(getJProgressBar(), gridBagConstraints2); |
180 |
jContentPane.add(getCancelButton(), gridBagConstraints3); |
181 |
} |
182 |
return jContentPane;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* This method initializes jProgressBar
|
187 |
*
|
188 |
* @return javax.swing.JProgressBar
|
189 |
*/
|
190 |
private JProgressBar getJProgressBar() { |
191 |
if (jProgressBar == null) { |
192 |
jProgressBar = new JProgressBar(); |
193 |
} |
194 |
return jProgressBar;
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* This method initializes cancelButton
|
199 |
*
|
200 |
* @return javax.swing.JButton
|
201 |
*/
|
202 |
private JButton getCancelButton() { |
203 |
if (cancelButton == null) { |
204 |
cancelButton = new JButton(); |
205 |
cancelButton.setText("cancelar");
|
206 |
cancelButton.addActionListener(new java.awt.event.ActionListener() {
|
207 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
208 |
cancel(); |
209 |
} |
210 |
}); |
211 |
cancelButton.addActionListener(new java.awt.event.ActionListener() {
|
212 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
213 |
cancel(); |
214 |
} |
215 |
}); |
216 |
} |
217 |
return cancelButton;
|
218 |
} |
219 |
|
220 |
public void setInitialStep(int step) { |
221 |
jProgressBar.setMinimum(step); |
222 |
} |
223 |
|
224 |
public void setLastStep(int step) { |
225 |
jProgressBar.setMaximum(step); |
226 |
} |
227 |
|
228 |
public void setCurrentStep(int step) { |
229 |
jProgressBar.setValue(step); |
230 |
} |
231 |
|
232 |
public int getInitialStep() { |
233 |
return jProgressBar.getMinimum();
|
234 |
} |
235 |
|
236 |
public int getLastStep() { |
237 |
return jProgressBar.getMaximum();
|
238 |
} |
239 |
|
240 |
public int getCurrentStep() { |
241 |
return jProgressBar.getValue();
|
242 |
} |
243 |
|
244 |
public void setIndeterminated(boolean indeterminated) { |
245 |
jProgressBar.setIndeterminate(indeterminated); |
246 |
} |
247 |
|
248 |
public boolean isIndeterminated() { |
249 |
return jProgressBar.isIndeterminate();
|
250 |
} |
251 |
|
252 |
public void setBarStringDrawed(boolean stringDrawed) { |
253 |
jProgressBar.setStringPainted(stringDrawed); |
254 |
} |
255 |
|
256 |
public void setBarString(String barString) { |
257 |
jProgressBar.setString(barString); |
258 |
} |
259 |
|
260 |
public void setMainTitleLabel(String text) { |
261 |
mainTitleLabel.setText(text); |
262 |
} |
263 |
|
264 |
public void setNote(String note) { |
265 |
noteLabel.setText(note); |
266 |
} |
267 |
|
268 |
public void cancel() { |
269 |
canceled = true;
|
270 |
} |
271 |
|
272 |
// public void taskInBackground() {
|
273 |
// //setModal(false);
|
274 |
// }
|
275 |
|
276 |
public boolean isCanceled() { |
277 |
return canceled == true; |
278 |
} |
279 |
|
280 |
public void close() { |
281 |
this.dispose();
|
282 |
} |
283 |
|
284 |
public void open() { |
285 |
this.setVisible(true); |
286 |
} |
287 |
|
288 |
} // @jve:decl-index=0:visual-constraint="30,10"
|