svn-gvsig-desktop / tags / v10_RC2c / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / NewStatusBar.java @ 8745
History | View | Annotate | Download (11.3 KB)
1 | 1104 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 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 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 598 | fernando | package com.iver.andami.ui.mdiFrame; |
42 | |||
43 | 663 | fernando | import java.awt.Component; |
44 | 598 | fernando | import java.awt.Dimension; |
45 | import java.awt.FlowLayout; |
||
46 | import java.util.HashMap; |
||
47 | |||
48 | import javax.swing.BorderFactory; |
||
49 | import javax.swing.ImageIcon; |
||
50 | import javax.swing.JLabel; |
||
51 | import javax.swing.JPanel; |
||
52 | import javax.swing.JProgressBar; |
||
53 | 663 | fernando | import javax.swing.border.BevelBorder; |
54 | 598 | fernando | |
55 | 5275 | jaume | import org.apache.log4j.Logger; |
56 | 6623 | cesar | import org.gvsig.gui.beans.controls.IControl; |
57 | 598 | fernando | |
58 | 5275 | jaume | import com.iver.andami.messages.Messages; |
59 | import com.iver.andami.plugins.config.generate.Label; |
||
60 | |||
61 | |||
62 | 598 | fernando | /**
|
63 | */
|
||
64 | public class NewStatusBar extends JPanel { |
||
65 | 1268 | vcaballero | private static Logger logger = Logger.getLogger(NewStatusBar.class.getName()); |
66 | private static final int INFO = 0; |
||
67 | private static final int WARNING = 1; |
||
68 | private static final int ERROR = 2; |
||
69 | private JLabel lblIcon = null; |
||
70 | private JLabel lblTexto = null; |
||
71 | private boolean contenidoTemporal; |
||
72 | private String textoAnterior; |
||
73 | private int estadoAnterior; |
||
74 | private ImageIcon infoIcon; |
||
75 | private ImageIcon warningIcon; |
||
76 | private ImageIcon errorIcon; |
||
77 | private int estado; |
||
78 | private JProgressBar progressBar = null; |
||
79 | private HashMap idLabel = new HashMap(); |
||
80 | private int[] widthlabels = null; |
||
81 | 6623 | cesar | private HashMap controls = new HashMap(); |
82 | 598 | fernando | |
83 | 1268 | vcaballero | /**
|
84 | * This is the default constructor
|
||
85 | */
|
||
86 | public NewStatusBar() {
|
||
87 | super();
|
||
88 | initialize(); |
||
89 | infoIcon = new ImageIcon(NewStatusBar.class.getClassLoader() |
||
90 | .getResource("images/info.gif"));
|
||
91 | warningIcon = new ImageIcon(NewStatusBar.class.getClassLoader() |
||
92 | .getResource("images/warning.gif"));
|
||
93 | errorIcon = new ImageIcon(NewStatusBar.class.getClassLoader() |
||
94 | .getResource("images/error.gif"));
|
||
95 | } |
||
96 | 598 | fernando | |
97 | 1268 | vcaballero | /**
|
98 | * This method initializes this
|
||
99 | */
|
||
100 | private void initialize() { |
||
101 | 7346 | maquerol | this.setPreferredSize(new java.awt.Dimension(183,20)); |
102 | this.setSize(new java.awt.Dimension(183,20)); |
||
103 | 1268 | vcaballero | lblIcon = new JLabel(); |
104 | lblTexto = new JLabel(); |
||
105 | 2938 | fjp | |
106 | FlowLayout flowLayout2 = new FlowLayout(); |
||
107 | 1268 | vcaballero | this.setLayout(flowLayout2);
|
108 | flowLayout2.setHgap(1);
|
||
109 | 7346 | maquerol | flowLayout2.setVgap(2);
|
110 | 1268 | vcaballero | flowLayout2.setAlignment(java.awt.FlowLayout.LEFT); |
111 | lblIcon.setText("");
|
||
112 | 2938 | fjp | lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada"));
|
113 | 1268 | vcaballero | this.add(lblIcon, null); |
114 | this.add(getProgressBar(), null); |
||
115 | this.add(lblTexto, null); |
||
116 | } |
||
117 | 598 | fernando | |
118 | 1268 | vcaballero | /**
|
119 | * Obtiene el texto de la barra de estado
|
||
120 | *
|
||
121 | * @return texto
|
||
122 | */
|
||
123 | public String getStatusText() { |
||
124 | return lblTexto.getText();
|
||
125 | } |
||
126 | 598 | fernando | |
127 | 1268 | vcaballero | /**
|
128 | * Restaura el contenido permanente de la barra de estado
|
||
129 | */
|
||
130 | public void restaurarTexto() { |
||
131 | contenidoTemporal = false;
|
||
132 | 598 | fernando | |
133 | 1268 | vcaballero | if (estadoAnterior == -1) { |
134 | return;
|
||
135 | } |
||
136 | 598 | fernando | |
137 | 1268 | vcaballero | switch (estadoAnterior) {
|
138 | case INFO:
|
||
139 | setInfoText(textoAnterior); |
||
140 | 598 | fernando | |
141 | 1268 | vcaballero | break;
|
142 | 598 | fernando | |
143 | 1268 | vcaballero | case WARNING:
|
144 | setWarningText(textoAnterior); |
||
145 | 598 | fernando | |
146 | 1268 | vcaballero | break;
|
147 | 598 | fernando | |
148 | 1268 | vcaballero | case ERROR:
|
149 | setErrorText(textoAnterior); |
||
150 | 598 | fernando | |
151 | 1268 | vcaballero | break;
|
152 | } |
||
153 | 598 | fernando | |
154 | 1268 | vcaballero | estadoAnterior = -1;
|
155 | textoAnterior = null;
|
||
156 | } |
||
157 | 598 | fernando | |
158 | 1268 | vcaballero | /**
|
159 | * Establece el texto de la barra de estado de forma temporal. Se almacena
|
||
160 | * el texto que hab?a en la barra de estado.
|
||
161 | *
|
||
162 | * @param texto texto
|
||
163 | */
|
||
164 | public void setInfoTextTemporal(String texto) { |
||
165 | contenidoTemporal = true;
|
||
166 | 598 | fernando | |
167 | 1268 | vcaballero | estadoAnterior = this.estado;
|
168 | this.estado = INFO;
|
||
169 | lblIcon.setIcon(infoIcon); |
||
170 | 598 | fernando | |
171 | 1268 | vcaballero | textoAnterior = getStatusText(); |
172 | lblTexto.setText(texto); |
||
173 | } |
||
174 | 598 | fernando | |
175 | 1268 | vcaballero | /**
|
176 | * Establece el texto de la barra de estado de forma temporal. Se almacena
|
||
177 | * el texto que hab?a en la barra de estado.
|
||
178 | *
|
||
179 | * @param texto texto
|
||
180 | */
|
||
181 | public void setWarningTextTemporal(String texto) { |
||
182 | contenidoTemporal = true;
|
||
183 | 598 | fernando | |
184 | 1268 | vcaballero | estadoAnterior = this.estado;
|
185 | this.estado = WARNING;
|
||
186 | lblIcon.setIcon(warningIcon); |
||
187 | 598 | fernando | |
188 | 1268 | vcaballero | textoAnterior = getStatusText(); |
189 | lblTexto.setText(texto); |
||
190 | } |
||
191 | 598 | fernando | |
192 | 1268 | vcaballero | /**
|
193 | * Establece el texto de la barra de estado de forma temporal. Se almacena
|
||
194 | * el texto que hab?a en la barra de estado.
|
||
195 | *
|
||
196 | * @param texto texto
|
||
197 | */
|
||
198 | public void setErrorTextTemporal(String texto) { |
||
199 | contenidoTemporal = true;
|
||
200 | 598 | fernando | |
201 | 1268 | vcaballero | estadoAnterior = this.estado;
|
202 | this.estado = ERROR;
|
||
203 | lblIcon.setIcon(errorIcon); |
||
204 | 598 | fernando | |
205 | 1268 | vcaballero | textoAnterior = getStatusText(); |
206 | lblTexto.setText(texto); |
||
207 | } |
||
208 | 598 | fernando | |
209 | 1268 | vcaballero | /**
|
210 | * Establece el texto de la barar de manera permanente. Si se est?
|
||
211 | * mostrando texto de forma temporal no se actualiza la interfaz
|
||
212 | *
|
||
213 | * @param texto Texto
|
||
214 | */
|
||
215 | public void setInfoText(String texto) { |
||
216 | if (contenidoTemporal) {
|
||
217 | textoAnterior = texto; |
||
218 | estadoAnterior = INFO; |
||
219 | } else {
|
||
220 | lblTexto.setText(texto); |
||
221 | lblIcon.setIcon(infoIcon); |
||
222 | estado = INFO; |
||
223 | } |
||
224 | } |
||
225 | 2938 | fjp | |
226 | 1268 | vcaballero | /**
|
227 | * Establece el texto de la barar de manera permanente. Si se est?
|
||
228 | * mostrando texto de forma temporal no se actualiza la interfaz
|
||
229 | *
|
||
230 | * @param texto Texto
|
||
231 | */
|
||
232 | public void setWarningText(String texto) { |
||
233 | if (contenidoTemporal) {
|
||
234 | textoAnterior = texto; |
||
235 | estadoAnterior = WARNING; |
||
236 | } else {
|
||
237 | lblTexto.setText(texto); |
||
238 | lblIcon.setIcon(warningIcon); |
||
239 | estado = WARNING; |
||
240 | } |
||
241 | } |
||
242 | 598 | fernando | |
243 | 1268 | vcaballero | /**
|
244 | * Establece el texto de la barar de manera permanente. Si se est?
|
||
245 | * mostrando texto de forma temporal no se actualiza la interfaz
|
||
246 | *
|
||
247 | * @param texto Texto
|
||
248 | */
|
||
249 | public void setErrorText(String texto) { |
||
250 | if (contenidoTemporal) {
|
||
251 | textoAnterior = texto; |
||
252 | estadoAnterior = ERROR; |
||
253 | } else {
|
||
254 | lblTexto.setText(texto); |
||
255 | lblIcon.setIcon(errorIcon); |
||
256 | estado = ERROR; |
||
257 | } |
||
258 | } |
||
259 | 598 | fernando | |
260 | 1268 | vcaballero | /**
|
261 | * Establece el porcentaje en la barra de progreso. Si es 100 se oculta la
|
||
262 | * barra
|
||
263 | *
|
||
264 | * @param p DOCUMENT ME!
|
||
265 | */
|
||
266 | public void setProgress(int p) { |
||
267 | if (p < 100) { |
||
268 | getProgressBar().setValue(p); |
||
269 | getProgressBar().setVisible(true);
|
||
270 | } else {
|
||
271 | getProgressBar().setVisible(false);
|
||
272 | } |
||
273 | 598 | fernando | |
274 | 1268 | vcaballero | getProgressBar().repaint(); |
275 | } |
||
276 | 6860 | jaume | |
277 | 6614 | cesar | /*public void setControls(Label[] labels, ArrayList controlArray) {
|
278 | removeAllLabels();
|
||
279 | 6588 | cesar | if (labels!=null)
|
280 | setLabelSet(labels);
|
||
281 | if (controlArray!=null)
|
||
282 | setControls(controlArray);
|
||
283 | this.repaint();
|
||
284 | 6614 | cesar | }*/
|
285 | 6860 | jaume | |
286 | 1268 | vcaballero | public void setLabelSet(Label[] labels) { |
287 | 6614 | cesar | removeAllLabels(); |
288 | 1268 | vcaballero | idLabel.clear(); |
289 | |||
290 | for (int i = 0; i < labels.length; i++) { |
||
291 | JLabel lbl = new JLabel(); |
||
292 | lbl.setPreferredSize(new Dimension(labels[i].getSize(), |
||
293 | 7346 | maquerol | this.getHeight() - 2)); |
294 | lbl.setSize(new Dimension(labels[i].getSize(), this.getHeight() - 2)); |
||
295 | 1268 | vcaballero | lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
296 | this.add(lbl);
|
||
297 | |||
298 | /* if (i != labels.length - 1){
|
||
299 | this.add(new JSeparator(JSeparator.VERTICAL));
|
||
300 | }
|
||
301 | */
|
||
302 | idLabel.put(labels[i].getId(), lbl); |
||
303 | } |
||
304 | |||
305 | JLabel[] configlabels = (JLabel[]) idLabel.values().toArray(new JLabel[0]); |
||
306 | widthlabels = new int[configlabels.length]; |
||
307 | |||
308 | for (int i = 0; i < labels.length; i++) { |
||
309 | widthlabels[i] = configlabels[i].getWidth(); |
||
310 | } |
||
311 | 6614 | cesar | |
312 | this.repaint();
|
||
313 | 1268 | vcaballero | } |
314 | 6860 | jaume | |
315 | 6614 | cesar | /*public void setControls(ArrayList controlList) {
|
316 | 6860 | jaume | |
317 | 6588 | cesar | for (int i = 0; i < controlList.size(); i++) {
|
318 | Component control = (Component) controlList.get(i);
|
||
319 | control.setVisible(true);
|
||
320 | control.setEnabled(true);
|
||
321 | this.add(control);
|
||
322 | }
|
||
323 | 6614 | cesar | }*/
|
324 | 1268 | vcaballero | |
325 | /**
|
||
326 | * Los Labels que estan sin texto no se a?aden a la barra y su espacio es
|
||
327 | 6588 | cesar | * utilizado por otros labels. Si se quiere hacer en un futuro la
|
328 | 1268 | vcaballero | * asignaci?n de espacio de los elementos que se a?adan a la barra se
|
329 | * puede hacer aqu?.
|
||
330 | */
|
||
331 | public void ajustar() { |
||
332 | if (widthlabels == null) { |
||
333 | return;
|
||
334 | } |
||
335 | |||
336 | int ws = this.getWidth(); |
||
337 | |||
338 | JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]); |
||
339 | |||
340 | /* double total = 1;
|
||
341 | for (int i = 0; i < widthlabels.length; i++) {
|
||
342 | if (labels[i].getText().compareTo("") != 0) {
|
||
343 | total += widthlabels[i];
|
||
344 | }
|
||
345 | }
|
||
346 | double p = (ws - lblTexto.getWidth() - 20) / total;
|
||
347 | */
|
||
348 | for (int i = 0; i < labels.length; i++) { |
||
349 | //if (labels[i] instanceof JLabel){
|
||
350 | JLabel label = (JLabel) labels[i]; |
||
351 | |||
352 | if (label.getText().compareTo("") != 0) { |
||
353 | label.setVisible(true);
|
||
354 | label.setPreferredSize(new Dimension((int) (widthlabels[i]), |
||
355 | 7346 | maquerol | this.getHeight() - 2)); |
356 | 1268 | vcaballero | } else {
|
357 | label.setVisible(false);
|
||
358 | |||
359 | //label.setPreferredSize(new Dimension(0,this.getHeight()));
|
||
360 | } |
||
361 | |||
362 | //}
|
||
363 | } |
||
364 | } |
||
365 | |||
366 | /**
|
||
367 | 6614 | cesar | * Removes all the labels from the status bar.
|
368 | 1268 | vcaballero | */
|
369 | 6614 | cesar | private void removeAllLabels() { |
370 | Component[] controlArray = this.getComponents(); |
||
371 | |||
372 | for (int i = 0; i < controlArray.length; i++) { |
||
373 | if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto && controlArray[i] instanceof JLabel)) { |
||
374 | remove(controlArray[i]); |
||
375 | } |
||
376 | } |
||
377 | } |
||
378 | 6860 | jaume | |
379 | |||
380 | 6614 | cesar | /**
|
381 | * Removes all the controls (including labels) from the status bar.
|
||
382 | */
|
||
383 | 6588 | cesar | private void removeAllControls() { |
384 | Component[] controlArray = this.getComponents(); |
||
385 | 1268 | vcaballero | |
386 | 6588 | cesar | for (int i = 0; i < controlArray.length; i++) { |
387 | if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)) {
|
||
388 | remove(controlArray[i]); |
||
389 | 663 | fernando | } |
390 | } |
||
391 | } |
||
392 | |||
393 | /**
|
||
394 | 1268 | vcaballero | * Establece el texto de una de las etiquetas
|
395 | *
|
||
396 | * @param id Identificador de las etiquetas
|
||
397 | * @param msg Mensaje que se quiere poner en la etiqueta
|
||
398 | */
|
||
399 | public void setMessage(String id, String msg) { |
||
400 | JLabel lbl = (JLabel) idLabel.get(id); |
||
401 | 598 | fernando | |
402 | 1268 | vcaballero | if (lbl == null) { |
403 | logger.debug("no label called " + id);
|
||
404 | } else {
|
||
405 | lbl.setText(msg); |
||
406 | } |
||
407 | 598 | fernando | |
408 | 1268 | vcaballero | ajustar(); |
409 | } |
||
410 | 6860 | jaume | |
411 | 6623 | cesar | /**
|
412 | * Sets the control identified by 'id' with the provided value.
|
||
413 | 6860 | jaume | *
|
414 | 6623 | cesar | * @param id
|
415 | * @param value
|
||
416 | */
|
||
417 | public void setControlValue(String id, String value) { |
||
418 | IControl control = (IControl) controls.get(id); |
||
419 | if (control!=null) { |
||
420 | control.setValue(value); |
||
421 | } |
||
422 | else {
|
||
423 | logger.debug("NewStatusBar -- no control called " + id);
|
||
424 | } |
||
425 | } |
||
426 | 598 | fernando | |
427 | 1268 | vcaballero | /**
|
428 | * This method initializes progressBar
|
||
429 | *
|
||
430 | * @return javax.swing.JProgressBar
|
||
431 | */
|
||
432 | private JProgressBar getProgressBar() { |
||
433 | if (progressBar == null) { |
||
434 | progressBar = new JProgressBar(); |
||
435 | 2112 | fernando | progressBar.setPreferredSize(new java.awt.Dimension(100, 14)); |
436 | 1268 | vcaballero | progressBar.setVisible(false);
|
437 | progressBar.setMinimum(0);
|
||
438 | progressBar.setMaximum(100);
|
||
439 | 2112 | fernando | progressBar.setValue(50);
|
440 | 1268 | vcaballero | } |
441 | 598 | fernando | |
442 | 1268 | vcaballero | return progressBar;
|
443 | } |
||
444 | |||
445 | 598 | fernando | /**
|
446 | 1268 | vcaballero | * DOCUMENT ME!
|
447 | *
|
||
448 | 598 | fernando | * @param d
|
449 | */
|
||
450 | public void setFixedLabelWidth(double d) { |
||
451 | lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight())); |
||
452 | } |
||
453 | 6860 | jaume | |
454 | 6623 | cesar | /**
|
455 | * Adds a control to the status bar
|
||
456 | */
|
||
457 | public void addControl(String id, Component control) { |
||
458 | this.add(control);
|
||
459 | if (!controls.containsKey(control.getName()))
|
||
460 | controls.put(control.getName(), control); |
||
461 | else
|
||
462 | logger.debug("NewStatusBar.addControl -- control 'id' already exists"+ id);
|
||
463 | } |
||
464 | 6860 | jaume | |
465 | 6623 | cesar | /**
|
466 | * Gets a control from the status bar
|
||
467 | */
|
||
468 | public Component getControl(String id, Component control) { |
||
469 | return (Component) controls.get(id); |
||
470 | } |
||
471 | 598 | fernando | } // @jve:decl-index=0:visual-constraint="10,10" |