svn-gvsig-desktop / tags / v1_0_2_Build_892 / libraries / libIverUtiles / src / com / iver / utiles / swing / threads / UndefinedProgressMonitor.java @ 10278
History | View | Annotate | Download (7.4 KB)
1 | 4419 | azabala | /*
|
---|---|---|---|
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$
|
||
47 | * $Log$
|
||
48 | 8765 | jjdelcerro | * Revision 1.3.4.2 2006-11-15 00:08:28 jjdelcerro
|
49 | * *** empty log message ***
|
||
50 | 7612 | jorpiell | *
|
51 | 8765 | jjdelcerro | * Revision 1.4 2006/11/06 07:29:59 jaume
|
52 | * organize imports
|
||
53 | *
|
||
54 | 7612 | jorpiell | * Revision 1.3 2006/04/18 15:16:14 azabala
|
55 | 4855 | azabala | * a?adida la posibilidad de personalizar el titulo del dialogo de proceso
|
56 | *
|
||
57 | * Revision 1.2 2006/03/20 16:04:21 azabala
|
||
58 | 4419 | azabala | * *** empty log message ***
|
59 | *
|
||
60 | 4483 | azabala | * Revision 1.1 2006/03/14 19:23:58 azabala
|
61 | * *** empty log message ***
|
||
62 | 4419 | azabala | *
|
63 | 4483 | azabala | *
|
64 | 4419 | azabala | */
|
65 | package com.iver.utiles.swing.threads; |
||
66 | |||
67 | import java.awt.Frame; |
||
68 | 8765 | jjdelcerro | import java.awt.GridBagConstraints; |
69 | import java.awt.GridBagLayout; |
||
70 | 4419 | azabala | |
71 | import javax.swing.JButton; |
||
72 | import javax.swing.JDialog; |
||
73 | import javax.swing.JLabel; |
||
74 | import javax.swing.JPanel; |
||
75 | import javax.swing.JProgressBar; |
||
76 | 7612 | jorpiell | |
77 | 4855 | azabala | /**
|
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 | 4419 | azabala | 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 | 4855 | azabala | private String title = "Processing..."; |
99 | 4419 | azabala | |
100 | /**
|
||
101 | * This is the default constructor
|
||
102 | */
|
||
103 | public UndefinedProgressMonitor() {
|
||
104 | super();
|
||
105 | initialize(); |
||
106 | } |
||
107 | 4855 | azabala | /**
|
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 | 4419 | azabala | super(parent, false); |
115 | 4855 | azabala | this.title = title;
|
116 | 4419 | azabala | initialize(); |
117 | } |
||
118 | |||
119 | /**
|
||
120 | * This method initializes this
|
||
121 | *
|
||
122 | * @return void
|
||
123 | *
|
||
124 | * FIXME Internationalize this
|
||
125 | */
|
||
126 | private void initialize() { |
||
127 | 4483 | azabala | this.setSize(318, 181); |
128 | 4855 | azabala | this.setTitle(title);
|
129 | 4419 | azabala | this.setContentPane(getJContentPane());
|
130 | } |
||
131 | |||
132 | /**
|
||
133 | * This method initializes jContentPane
|
||
134 | *
|
||
135 | * @return javax.swing.JPanel
|
||
136 | */
|
||
137 | private JPanel getJContentPane() { |
||
138 | if (jContentPane == null) { |
||
139 | 4483 | azabala | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
140 | gridBagConstraints3.insets = new java.awt.Insets(6,97,18,125); |
||
141 | gridBagConstraints3.gridy = 3;
|
||
142 | gridBagConstraints3.ipadx = 4;
|
||
143 | gridBagConstraints3.ipady = -4;
|
||
144 | gridBagConstraints3.gridx = 0;
|
||
145 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
||
146 | gridBagConstraints2.insets = new java.awt.Insets(11,43,5,32); |
||
147 | gridBagConstraints2.gridy = 2;
|
||
148 | gridBagConstraints2.ipadx = 109;
|
||
149 | gridBagConstraints2.ipady = 4;
|
||
150 | gridBagConstraints2.fill = java.awt.GridBagConstraints.NONE; |
||
151 | gridBagConstraints2.gridwidth = 2;
|
||
152 | gridBagConstraints2.anchor = java.awt.GridBagConstraints.CENTER; |
||
153 | gridBagConstraints2.gridx = 0;
|
||
154 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
155 | gridBagConstraints1.insets = new java.awt.Insets(9,43,8,32); |
||
156 | gridBagConstraints1.gridy = 1;
|
||
157 | gridBagConstraints1.ipadx = 180;
|
||
158 | gridBagConstraints1.ipady = 0;
|
||
159 | gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
160 | gridBagConstraints1.gridx = 0;
|
||
161 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
162 | gridBagConstraints.insets = new java.awt.Insets(10,43,8,32); |
||
163 | gridBagConstraints.gridy = 0;
|
||
164 | gridBagConstraints.ipadx = 148;
|
||
165 | gridBagConstraints.ipady = 11;
|
||
166 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
167 | gridBagConstraints.gridx = 0;
|
||
168 | 4419 | azabala | noteLabel = new JLabel(); |
169 | noteLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12)); |
||
170 | noteLabel.setText("noteLabel");
|
||
171 | mainTitleLabel = new JLabel(); |
||
172 | mainTitleLabel.setText("mainTittleLabel");
|
||
173 | mainTitleLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); |
||
174 | jContentPane = new JPanel(); |
||
175 | 4483 | azabala | jContentPane.setLayout(new GridBagLayout()); |
176 | jContentPane.add(mainTitleLabel, gridBagConstraints); |
||
177 | jContentPane.add(noteLabel, gridBagConstraints1); |
||
178 | jContentPane.add(getJProgressBar(), gridBagConstraints2); |
||
179 | jContentPane.add(getCancelButton(), gridBagConstraints3); |
||
180 | 4419 | azabala | } |
181 | return jContentPane;
|
||
182 | } |
||
183 | |||
184 | /**
|
||
185 | * This method initializes jProgressBar
|
||
186 | *
|
||
187 | * @return javax.swing.JProgressBar
|
||
188 | */
|
||
189 | private JProgressBar getJProgressBar() { |
||
190 | if (jProgressBar == null) { |
||
191 | jProgressBar = new JProgressBar(); |
||
192 | } |
||
193 | return jProgressBar;
|
||
194 | } |
||
195 | |||
196 | /**
|
||
197 | * This method initializes cancelButton
|
||
198 | *
|
||
199 | * @return javax.swing.JButton
|
||
200 | */
|
||
201 | private JButton getCancelButton() { |
||
202 | if (cancelButton == null) { |
||
203 | cancelButton = new JButton(); |
||
204 | cancelButton.setText("cancelar");
|
||
205 | cancelButton.addActionListener(new java.awt.event.ActionListener() {
|
||
206 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
207 | cancel(); |
||
208 | } |
||
209 | }); |
||
210 | cancelButton.addActionListener(new java.awt.event.ActionListener() {
|
||
211 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
212 | cancel(); |
||
213 | } |
||
214 | }); |
||
215 | } |
||
216 | return cancelButton;
|
||
217 | } |
||
218 | |||
219 | public void setInitialStep(int step) { |
||
220 | jProgressBar.setMinimum(step); |
||
221 | } |
||
222 | |||
223 | public void setLastStep(int step) { |
||
224 | jProgressBar.setMaximum(step); |
||
225 | } |
||
226 | |||
227 | public void setCurrentStep(int step) { |
||
228 | jProgressBar.setValue(step); |
||
229 | } |
||
230 | |||
231 | public int getInitialStep() { |
||
232 | return jProgressBar.getMinimum();
|
||
233 | } |
||
234 | |||
235 | public int getLastStep() { |
||
236 | return jProgressBar.getMaximum();
|
||
237 | } |
||
238 | |||
239 | public int getCurrentStep() { |
||
240 | return jProgressBar.getValue();
|
||
241 | } |
||
242 | |||
243 | public void setIndeterminated(boolean indeterminated) { |
||
244 | jProgressBar.setIndeterminate(indeterminated); |
||
245 | } |
||
246 | |||
247 | public boolean isIndeterminated() { |
||
248 | return jProgressBar.isIndeterminate();
|
||
249 | } |
||
250 | |||
251 | public void setBarStringDrawed(boolean stringDrawed) { |
||
252 | jProgressBar.setStringPainted(stringDrawed); |
||
253 | } |
||
254 | |||
255 | public void setBarString(String barString) { |
||
256 | jProgressBar.setString(barString); |
||
257 | } |
||
258 | |||
259 | public void setMainTitleLabel(String text) { |
||
260 | mainTitleLabel.setText(text); |
||
261 | } |
||
262 | |||
263 | public void setNote(String note) { |
||
264 | noteLabel.setText(note); |
||
265 | } |
||
266 | |||
267 | public void cancel() { |
||
268 | canceled = true;
|
||
269 | } |
||
270 | |||
271 | 4483 | azabala | // public void taskInBackground() {
|
272 | // //setModal(false);
|
||
273 | // }
|
||
274 | 4419 | azabala | |
275 | public boolean isCanceled() { |
||
276 | return canceled == true; |
||
277 | } |
||
278 | |||
279 | public void close() { |
||
280 | this.dispose();
|
||
281 | } |
||
282 | |||
283 | public void open() { |
||
284 | this.setVisible(true); |
||
285 | } |
||
286 | |||
287 | } // @jve:decl-index=0:visual-constraint="30,10" |