svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiFrame / NewStatusBar.java @ 44075
History | View | Annotate | Download (23.7 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.andami.ui.mdiFrame; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Component; |
28 |
import java.awt.Cursor; |
29 |
import java.awt.Dimension; |
30 |
import java.awt.FlowLayout; |
31 |
import java.awt.LayoutManager; |
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
import java.awt.event.MouseEvent; |
35 |
import java.awt.event.MouseListener; |
36 |
import java.util.HashMap; |
37 |
import java.util.Map; |
38 |
|
39 |
import javax.swing.BorderFactory; |
40 |
import javax.swing.ImageIcon; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JOptionPane; |
43 |
import javax.swing.JPanel; |
44 |
import javax.swing.JPopupMenu; |
45 |
import javax.swing.JProgressBar; |
46 |
import javax.swing.SwingConstants; |
47 |
import javax.swing.SwingUtilities; |
48 |
import javax.swing.Timer; |
49 |
import javax.swing.border.BevelBorder; |
50 |
import org.apache.commons.lang3.StringUtils; |
51 |
|
52 |
import org.gvsig.andami.IconThemeHelper; |
53 |
import org.gvsig.andami.messages.Messages; |
54 |
import org.gvsig.andami.plugins.config.generate.Label; |
55 |
import org.gvsig.gui.beans.controls.IControl; |
56 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
57 |
import org.gvsig.tools.swing.api.task.JTasksStatus; |
58 |
import org.slf4j.Logger; |
59 |
import org.slf4j.LoggerFactory; |
60 |
|
61 |
/**
|
62 |
* <p>
|
63 |
* This class contains the status bar. It contains the graphical component, and
|
64 |
* the methods to manage it.
|
65 |
* </p>
|
66 |
*
|
67 |
* <p>
|
68 |
* The status bar is divided in several areas. At the very left, there is an
|
69 |
* icon and the main status text. There are three icons to show: Info, Warning
|
70 |
* and Error icons. They can be set together with the main status text using the
|
71 |
* methods <code>setInfoText()</code>, <code>setWarningText()</code> and
|
72 |
* <code>setErrorText()</code> (and also with <code>setInfoTextTemporal()</code>
|
73 |
* , etc). Then, there is a right area which contains labels and other controls.
|
74 |
* Labels are set in the config.xml files and are visible or not depending on
|
75 |
* the currently selected Andami window. Controls are associated to extensions,
|
76 |
* and are enabled/disabled and visible/hidden depending on the associated
|
77 |
* extension.
|
78 |
* </p>
|
79 |
*
|
80 |
*/
|
81 |
public class NewStatusBar extends JPanel { |
82 |
|
83 |
private static final long serialVersionUID = 5575549032728844632L; |
84 |
|
85 |
private static Logger logger = LoggerFactory.getLogger(NewStatusBar.class); |
86 |
|
87 |
private static final int INFO = 0; |
88 |
private static final int WARNING = 1; |
89 |
private static final int ERROR = 2; |
90 |
private JLabel lblIcon = null; |
91 |
private JLabel lblTexto = null; |
92 |
private boolean contenidoTemporal; |
93 |
private String textoAnterior; |
94 |
private int estadoAnterior; |
95 |
private int estado; |
96 |
private JProgressBar progressBar = null; |
97 |
private Map<String, JLabel> idLabel = new HashMap<String, JLabel>(); |
98 |
private int[] widthlabels = null; |
99 |
private Map<String, Component> controls = new HashMap<String, Component>(); |
100 |
private JPanel controlContainer; |
101 |
private JTasksStatus tasksStatus = null; |
102 |
private Timer messageTimer; |
103 |
|
104 |
private String textoCompleto; |
105 |
|
106 |
|
107 |
/**
|
108 |
* This is the default constructor
|
109 |
*/
|
110 |
public NewStatusBar() {
|
111 |
super();
|
112 |
initialize(); |
113 |
} |
114 |
|
115 |
private ImageIcon getImageIcon(String iconName) { |
116 |
// return PluginServices.getIconTheme().get(iconName);
|
117 |
return IconThemeHelper.getImageIcon(iconName);
|
118 |
} |
119 |
|
120 |
|
121 |
/**
|
122 |
* This method initializes the status bar. It creates the required
|
123 |
* containers and sets the layout.
|
124 |
*/
|
125 |
private void initialize() { |
126 |
LayoutManager mainLayout = new BorderLayout(); |
127 |
this.setLayout(mainLayout);
|
128 |
|
129 |
JPanel panelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0)); |
130 |
|
131 |
controlContainer = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0)); |
132 |
panelRight.add(controlContainer); |
133 |
panelRight.add(getTasksStatus()); |
134 |
|
135 |
lblIcon = new JLabel(); |
136 |
lblTexto = new JLabel(); |
137 |
lblTexto.setAlignmentX(JLabel.LEFT_ALIGNMENT);
|
138 |
lblTexto.setHorizontalAlignment(SwingConstants.LEFT);
|
139 |
lblTexto.setHorizontalTextPosition(SwingConstants.LEFT);
|
140 |
lblTexto.setVerticalAlignment(SwingConstants.CENTER);
|
141 |
lblTexto.setVerticalTextPosition(SwingConstants.CENTER);
|
142 |
lblIcon.setText("");
|
143 |
lblTexto.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
144 |
lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada"));
|
145 |
|
146 |
JPanel panelLeft = new JPanel(); |
147 |
panelLeft.setLayout(new BorderLayout(1,1)); |
148 |
panelLeft.add(lblIcon, BorderLayout.LINE_START);
|
149 |
panelLeft.add(lblTexto, BorderLayout.CENTER);
|
150 |
// panelLeft.add(getProgressBar());
|
151 |
|
152 |
this.add(panelLeft, BorderLayout.CENTER); |
153 |
this.add(panelRight, BorderLayout.EAST); |
154 |
|
155 |
buildMesagePopupMenu(); |
156 |
|
157 |
messageTimer = new Timer(30000, new ActionListener() { |
158 |
public void actionPerformed(ActionEvent e) { |
159 |
try {
|
160 |
clearMessage(); |
161 |
} catch( Throwable ex) { |
162 |
logger.info("Can't clear message", ex);
|
163 |
} |
164 |
} |
165 |
}); |
166 |
} |
167 |
|
168 |
public void clearMessage() { |
169 |
this.textoCompleto = ""; |
170 |
lblTexto.setText("");
|
171 |
lblIcon.setIcon(null);
|
172 |
lblTexto.paintImmediately(lblTexto.getVisibleRect()); |
173 |
lblIcon.paintImmediately(lblIcon.getVisibleRect()); |
174 |
estado = INFO; |
175 |
} |
176 |
|
177 |
|
178 |
public void message(final String msg, final int messageType) { |
179 |
if (!SwingUtilities.isEventDispatchThread()) { |
180 |
SwingUtilities.invokeLater(new Runnable() { |
181 |
public void run() { |
182 |
message(msg,messageType); |
183 |
} |
184 |
}); |
185 |
return;
|
186 |
} |
187 |
messageTimer.stop(); |
188 |
if( StringUtils.isBlank(msg) ) {
|
189 |
this.clearMessage();
|
190 |
return;
|
191 |
} |
192 |
switch (messageType) {
|
193 |
case JOptionPane.ERROR_MESSAGE: |
194 |
setErrorText(msg); |
195 |
break;
|
196 |
case JOptionPane.WARNING_MESSAGE: |
197 |
setWarningText(msg); |
198 |
break;
|
199 |
default:
|
200 |
case JOptionPane.INFORMATION_MESSAGE: |
201 |
setInfoText(msg); |
202 |
break;
|
203 |
} |
204 |
lblTexto.paintImmediately(lblTexto.getVisibleRect()); |
205 |
lblIcon.paintImmediately(lblIcon.getVisibleRect()); |
206 |
messageTimer.start(); |
207 |
} |
208 |
|
209 |
private void buildMesagePopupMenu() { |
210 |
final JPopupMenu menu = new JPopupMenu(); |
211 |
|
212 |
JMenuItem item = new JMenuItem("View details"); |
213 |
item.addActionListener(new ActionListener() { |
214 |
public void actionPerformed(ActionEvent arg0) { |
215 |
switch (estado) {
|
216 |
default:
|
217 |
case INFO:
|
218 |
JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.INFORMATION_MESSAGE); |
219 |
break;
|
220 |
case WARNING:
|
221 |
JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.WARNING_MESSAGE); |
222 |
break;
|
223 |
case ERROR:
|
224 |
JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.ERROR_MESSAGE); |
225 |
break;
|
226 |
} |
227 |
} |
228 |
}); |
229 |
menu.add(item); |
230 |
item = new JMenuItem("Clear"); |
231 |
item.addActionListener(new ActionListener() { |
232 |
public void actionPerformed(ActionEvent e) { |
233 |
clearMessage(); |
234 |
} |
235 |
}); |
236 |
menu.add(item); |
237 |
menu.addSeparator(); |
238 |
item = new JMenuItem("Cancel"); |
239 |
menu.add(item); |
240 |
|
241 |
this.lblTexto.addMouseListener( new MouseListener() { |
242 |
public void mouseReleased(MouseEvent e) { |
243 |
// if( e.isPopupTrigger() ) {
|
244 |
// if( getStatusText().length() > 0 || estado!=INFO ) {
|
245 |
// menu.show(lblTexto, e.getX(), e.getY());
|
246 |
// }
|
247 |
// }
|
248 |
} |
249 |
public void mousePressed(MouseEvent e) { |
250 |
if( e.isPopupTrigger() || e.getClickCount()==1 ) { |
251 |
if( getStatusText().length() > 0 || estado!=INFO ) { |
252 |
menu.show(lblTexto, e.getX(), e.getY()); |
253 |
} |
254 |
} |
255 |
} |
256 |
public void mouseExited(MouseEvent e) { |
257 |
} |
258 |
public void mouseEntered(MouseEvent e) { |
259 |
} |
260 |
public void mouseClicked(MouseEvent e) { |
261 |
} |
262 |
}); |
263 |
} |
264 |
|
265 |
/**
|
266 |
* Gets the status bar main text.
|
267 |
*
|
268 |
* @return The status bar main text.
|
269 |
* @see #setInfoText(String)
|
270 |
* @see #setWarningText(String)
|
271 |
* @see #setErrorText(String)
|
272 |
* @see #setInfoTextTemporal(String)
|
273 |
* @see #setWarningTextTemporal(String)
|
274 |
* @see #setErrorTextTemporal(String)
|
275 |
*/
|
276 |
public String getStatusText() { |
277 |
return textoCompleto; //lblTexto.getText(); |
278 |
} |
279 |
|
280 |
/**
|
281 |
* Restores the previous contents in the status bar main text,
|
282 |
* after the {@link #setInfoTextTemporal(String)},
|
283 |
* {@link #setWarningTextTemporal(String)} or
|
284 |
* {@link #setErrorTextTemporal(String)} have been called.
|
285 |
*
|
286 |
* @see #setInfoTextTemporal(String)
|
287 |
* @see #setWarningTextTemporal(String)
|
288 |
* @see #setErrorTextTemporal(String)
|
289 |
*/
|
290 |
public void restaurarTexto() { |
291 |
contenidoTemporal = false;
|
292 |
|
293 |
if (estadoAnterior == -1) { |
294 |
return;
|
295 |
} |
296 |
|
297 |
switch (estadoAnterior) {
|
298 |
case INFO:
|
299 |
setInfoText(textoAnterior); |
300 |
|
301 |
break;
|
302 |
|
303 |
case WARNING:
|
304 |
setWarningText(textoAnterior); |
305 |
|
306 |
break;
|
307 |
|
308 |
case ERROR:
|
309 |
setErrorText(textoAnterior); |
310 |
|
311 |
break;
|
312 |
} |
313 |
|
314 |
estadoAnterior = -1;
|
315 |
textoAnterior = null;
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* Sets a temporary information message in the status bar, and changes the
|
320 |
* icon to an Info icon. The previous text and icon can be restored using
|
321 |
* the {@link #restaurarTexto()} method.
|
322 |
*
|
323 |
* @param texto
|
324 |
* The text to set
|
325 |
* @see #restaurarTexto()
|
326 |
*/
|
327 |
public void setInfoTextTemporal(final String texto) { |
328 |
if (!SwingUtilities.isEventDispatchThread()) { |
329 |
SwingUtilities.invokeLater(new Runnable() { |
330 |
public void run() { |
331 |
setInfoTextTemporal(texto); |
332 |
} |
333 |
}); |
334 |
return;
|
335 |
} |
336 |
if (!contenidoTemporal) {
|
337 |
textoAnterior = getStatusText(); |
338 |
estadoAnterior = this.estado;
|
339 |
contenidoTemporal = true;
|
340 |
} |
341 |
|
342 |
this.estado = INFO;
|
343 |
lblIcon.setIcon(getImageIcon("statusbar-info"));
|
344 |
lblTexto.setText(texto); |
345 |
} |
346 |
|
347 |
/**
|
348 |
* Sets a temporary warning message in the status bar, and changes the
|
349 |
* icon to a Warning icon. The previous text and icon can be restored using
|
350 |
* the {@link #restaurarTexto()} method.
|
351 |
*
|
352 |
* @param texto
|
353 |
* The text to set
|
354 |
* @see #restaurarTexto()
|
355 |
*/
|
356 |
public void setWarningTextTemporal(final String texto) { |
357 |
if (!SwingUtilities.isEventDispatchThread()) { |
358 |
SwingUtilities.invokeLater(new Runnable() { |
359 |
public void run() { |
360 |
setWarningTextTemporal(texto); |
361 |
} |
362 |
}); |
363 |
return;
|
364 |
} |
365 |
|
366 |
if (!contenidoTemporal) {
|
367 |
estadoAnterior = this.estado;
|
368 |
textoAnterior = getStatusText(); |
369 |
contenidoTemporal = true;
|
370 |
} |
371 |
this.estado = WARNING;
|
372 |
lblIcon.setIcon(getImageIcon("statusbar-warning"));
|
373 |
lblTexto.setText(texto); |
374 |
} |
375 |
|
376 |
/**
|
377 |
* Sets a temporary error message in the status bar, and changes the
|
378 |
* icon to an Error icon. The previous text and icon can be restored using
|
379 |
* the {@link #restaurarTexto()} method.
|
380 |
*
|
381 |
* @param texto
|
382 |
* The text to set
|
383 |
* @see #restaurarTexto()
|
384 |
*/
|
385 |
public void setErrorTextTemporal(final String texto) { |
386 |
if (!SwingUtilities.isEventDispatchThread()) { |
387 |
SwingUtilities.invokeLater(new Runnable() { |
388 |
public void run() { |
389 |
setErrorTextTemporal(texto); |
390 |
} |
391 |
}); |
392 |
return;
|
393 |
} |
394 |
if (!contenidoTemporal) {
|
395 |
estadoAnterior = this.estado;
|
396 |
textoAnterior = getStatusText(); |
397 |
contenidoTemporal = true;
|
398 |
} |
399 |
|
400 |
this.estado = ERROR;
|
401 |
lblIcon.setIcon(getImageIcon("statusbar-error"));
|
402 |
lblTexto.setText(texto); |
403 |
} |
404 |
|
405 |
/**
|
406 |
* Sets a permanent info message in the status bar, and changes the
|
407 |
* permanent icon to an Info icon. If there is a temporary message showing
|
408 |
* at the moment, the message set now is not shown until
|
409 |
* the {@link #restaurarTexto()} method is called.
|
410 |
*
|
411 |
* @param texto
|
412 |
* The permanent info message to set
|
413 |
* @see #restaurarTexto()
|
414 |
*/
|
415 |
public void setInfoText(final String texto) { |
416 |
if (!SwingUtilities.isEventDispatchThread()) { |
417 |
SwingUtilities.invokeLater(new Runnable() { |
418 |
public void run() { |
419 |
setInfoText(texto); |
420 |
} |
421 |
}); |
422 |
return;
|
423 |
} |
424 |
if (contenidoTemporal) {
|
425 |
textoAnterior = texto; |
426 |
estadoAnterior = INFO; |
427 |
} else {
|
428 |
this.textoCompleto = texto;
|
429 |
lblTexto.setText(getFirstTextLine(texto)); |
430 |
lblIcon.setIcon(getImageIcon("statusbar-info"));
|
431 |
estado = INFO; |
432 |
} |
433 |
} |
434 |
|
435 |
private String getFirstTextLine(String text) { |
436 |
|
437 |
if (text == null) { |
438 |
return null; |
439 |
} |
440 |
|
441 |
int n = text.indexOf("\n"); |
442 |
if( n == -1 ) { |
443 |
return text;
|
444 |
} |
445 |
return text.substring(0,n) + "..."; |
446 |
} |
447 |
|
448 |
/**
|
449 |
* Sets a permanent warning message in the status bar, and changes the
|
450 |
* permanent icon to a Warning icon. If there is a temporary message showing
|
451 |
* at the moment, the message set now is not shown until
|
452 |
* the {@link #restaurarTexto()} method is called.
|
453 |
*
|
454 |
* @param texto
|
455 |
* The permanent warning message to set
|
456 |
* @see #restaurarTexto()
|
457 |
*/
|
458 |
public void setWarningText(final String texto) { |
459 |
if (!SwingUtilities.isEventDispatchThread()) { |
460 |
SwingUtilities.invokeLater(new Runnable() { |
461 |
public void run() { |
462 |
setWarningText(texto); |
463 |
} |
464 |
}); |
465 |
return;
|
466 |
} |
467 |
|
468 |
if (contenidoTemporal) {
|
469 |
textoAnterior = texto; |
470 |
estadoAnterior = WARNING; |
471 |
} else {
|
472 |
this.textoCompleto = texto;
|
473 |
lblTexto.setText(getFirstTextLine(texto)); |
474 |
lblIcon.setIcon(getImageIcon("statusbar-warning"));
|
475 |
estado = WARNING; |
476 |
} |
477 |
} |
478 |
|
479 |
/**
|
480 |
* Sets a permanent error message in the status bar, and changes the
|
481 |
* permanent icon to an Error icon. If there is a temporary message showing
|
482 |
* at the moment, the message set now is not shown until
|
483 |
* the {@link #restaurarTexto()} method is called.
|
484 |
*
|
485 |
* @param texto
|
486 |
* The permanent info message to set
|
487 |
* @see #restaurarTexto()
|
488 |
*/
|
489 |
public void setErrorText(final String texto) { |
490 |
if (!SwingUtilities.isEventDispatchThread()) { |
491 |
SwingUtilities.invokeLater(new Runnable() { |
492 |
public void run() { |
493 |
setErrorText(texto); |
494 |
} |
495 |
}); |
496 |
return;
|
497 |
} |
498 |
|
499 |
if (contenidoTemporal) {
|
500 |
textoAnterior = texto; |
501 |
estadoAnterior = ERROR; |
502 |
} else {
|
503 |
this.textoCompleto = texto;
|
504 |
lblTexto.setText(getFirstTextLine(texto)); |
505 |
lblIcon.setIcon(getImageIcon("statusbar-error"));
|
506 |
estado = ERROR; |
507 |
} |
508 |
} |
509 |
|
510 |
/**
|
511 |
* If <code>p</code> is a value between 0 and 99, it shows a progress bar
|
512 |
* in the left area of the status bar, and sets the specified progress.
|
513 |
* If <code>p</code> is bigger than 99, it hides the progress bar.
|
514 |
*
|
515 |
* @param p
|
516 |
* The progress to set in the progress bar. If it is bigger
|
517 |
* than 99, the task will be considered to be finished, and the
|
518 |
* progress bar will be hidden.
|
519 |
*
|
520 |
* @deprecated use instead TaskStatus and TaskStatusManager
|
521 |
*/
|
522 |
public void setProgress(int p) { |
523 |
if (p < 100) { |
524 |
getProgressBar().setValue(p); |
525 |
getProgressBar().setVisible(true);
|
526 |
} else {
|
527 |
getProgressBar().setVisible(false);
|
528 |
} |
529 |
|
530 |
getProgressBar().repaint(); |
531 |
} |
532 |
|
533 |
/**
|
534 |
* Sets a label-set to be shown in the status bar. This method it is not
|
535 |
* intended to be used directly, because the set will be overwritten when
|
536 |
* the selected
|
537 |
* window changes. Use {@link MainFrame#setStatusBarLabels(Class, Label[])}
|
538 |
* to permanently associate a label set with a window.
|
539 |
*
|
540 |
* @param labels
|
541 |
* The labels to set.
|
542 |
* @see MainFrame#setStatusBarLabels(Class, Label[])
|
543 |
*/
|
544 |
public void setLabelSet(Label[] labels) { |
545 |
removeAllLabels(); |
546 |
idLabel.clear(); |
547 |
|
548 |
for (int i = 0; i < labels.length; i++) { |
549 |
// Set an initial text so the getPreferredSize works as expected
|
550 |
JLabel lbl = new JLabel(); |
551 |
lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
552 |
lbl.setName(labels[i].getId()); |
553 |
controlContainer.add(lbl); |
554 |
|
555 |
/*
|
556 |
* if (i != labels.length - 1){
|
557 |
* this.add(new JSeparator(JSeparator.VERTICAL));
|
558 |
* }
|
559 |
*/
|
560 |
idLabel.put(labels[i].getId(), lbl); |
561 |
} |
562 |
|
563 |
JLabel[] configlabels = |
564 |
(JLabel[]) idLabel.values().toArray(new JLabel[0]); |
565 |
widthlabels = new int[configlabels.length]; |
566 |
|
567 |
for (int i = 0; i < labels.length; i++) { |
568 |
widthlabels[i] = configlabels[i].getWidth(); |
569 |
} |
570 |
|
571 |
this.validate();
|
572 |
} |
573 |
|
574 |
/**
|
575 |
* Hides the empty labels and adjust the space in the bar.
|
576 |
*/
|
577 |
public void ajustar() { |
578 |
if (widthlabels == null) { |
579 |
return;
|
580 |
} |
581 |
|
582 |
JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]); |
583 |
|
584 |
/*
|
585 |
* double total = 1;
|
586 |
* for (int i = 0; i < widthlabels.length; i++) {
|
587 |
* if (labels[i].getText().compareTo("") != 0) {
|
588 |
* total += widthlabels[i];
|
589 |
* }
|
590 |
* }
|
591 |
* double p = (ws - lblTexto.getWidth() - 20) / total;
|
592 |
*/
|
593 |
for (int i = 0; i < labels.length; i++) { |
594 |
JLabel label = (JLabel) labels[i]; |
595 |
|
596 |
if (label.getText().compareTo("") != 0) { |
597 |
label.setVisible(true);
|
598 |
} else {
|
599 |
label.setVisible(false);
|
600 |
} |
601 |
} |
602 |
validate(); |
603 |
} |
604 |
|
605 |
/**
|
606 |
* Removes all the labels from the status bar. It does not remove the
|
607 |
* controls.
|
608 |
*/
|
609 |
private void removeAllLabels() { |
610 |
Component[] controlArray = controlContainer.getComponents(); |
611 |
|
612 |
for (int i = 0; i < controlArray.length; i++) { |
613 |
if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)
|
614 |
&& !(controlArray[i] instanceof IControl)
|
615 |
&& (controlArray[i] instanceof JLabel)) { |
616 |
controlContainer.remove(controlArray[i]); |
617 |
} |
618 |
} |
619 |
} |
620 |
|
621 |
/**
|
622 |
* Sets the text of the provided label.
|
623 |
*
|
624 |
* @param id
|
625 |
* The ID of the label to modify. It is defined in the
|
626 |
* config.xml file
|
627 |
* @param msg
|
628 |
* The message to show in the label
|
629 |
*/
|
630 |
public void setMessage(final String id, final String msg) { |
631 |
if (!SwingUtilities.isEventDispatchThread()) { |
632 |
SwingUtilities.invokeLater(new Runnable() { |
633 |
public void run() { |
634 |
setMessage(id, msg); |
635 |
} |
636 |
}); |
637 |
return;
|
638 |
} |
639 |
|
640 |
JLabel lbl = (JLabel) idLabel.get(id); |
641 |
|
642 |
if (lbl != null) { |
643 |
Dimension originalPreferredSize = lbl.getPreferredSize();
|
644 |
lbl.setText(msg); |
645 |
// Set preferred size to null just in case it has been set
|
646 |
// previously, as we want it to be calculated from the text size.
|
647 |
lbl.setPreferredSize(null);
|
648 |
// Allow only to increase label width, to avoid too much ugly
|
649 |
// width changes in the status bar components.
|
650 |
if (lbl.getPreferredSize().width < originalPreferredSize.width) {
|
651 |
lbl.setPreferredSize(originalPreferredSize); |
652 |
} |
653 |
} else {
|
654 |
// try with controls
|
655 |
try {
|
656 |
IControl control = (IControl) controls.get(id); |
657 |
if (control != null) |
658 |
control.setValue(msg); |
659 |
} catch (ClassCastException ex) { |
660 |
logger.debug("no label called " + id);
|
661 |
} |
662 |
} |
663 |
|
664 |
ajustar(); |
665 |
} |
666 |
|
667 |
/**
|
668 |
* Sets the control identified by 'id' with the provided value.
|
669 |
*
|
670 |
* @param id
|
671 |
* The ID of the control to modify
|
672 |
* @param value
|
673 |
* The value to set in the control
|
674 |
*/
|
675 |
public void setControlValue(String id, String value) { |
676 |
IControl control = (IControl) controls.get(id); |
677 |
if (control != null) { |
678 |
control.setValue(value); |
679 |
} else {
|
680 |
logger.debug("NewStatusBar -- no control called " + id);
|
681 |
} |
682 |
} |
683 |
|
684 |
/**
|
685 |
* This method initializes the progressBar and gets it.
|
686 |
*
|
687 |
* @return javax.swing.JProgressBar
|
688 |
*/
|
689 |
private JProgressBar getProgressBar() { |
690 |
if (progressBar == null) { |
691 |
progressBar = new JProgressBar(); |
692 |
// progressBar.setPreferredSize(new java.awt.Dimension(100, 14));
|
693 |
progressBar.setVisible(false);
|
694 |
progressBar.setMinimum(0);
|
695 |
progressBar.setMaximum(100);
|
696 |
progressBar.setValue(50);
|
697 |
} |
698 |
|
699 |
return progressBar;
|
700 |
} |
701 |
|
702 |
private JTasksStatus getTasksStatus() {
|
703 |
if (tasksStatus == null) { |
704 |
tasksStatus = |
705 |
ToolsSwingLocator.getTaskStatusSwingManager() |
706 |
.createJTasksStatus(); |
707 |
tasksStatus.setVisible(true);
|
708 |
} |
709 |
return tasksStatus;
|
710 |
} |
711 |
|
712 |
/**
|
713 |
* Sets the width of the main message label.
|
714 |
*
|
715 |
* @param d
|
716 |
* The width ob the main label
|
717 |
* @deprecated
|
718 |
*/
|
719 |
public void setFixedLabelWidth(double d) { |
720 |
lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight())); |
721 |
} |
722 |
|
723 |
/**
|
724 |
* Adds a control to the status bar
|
725 |
*
|
726 |
* @param id
|
727 |
* The ID of the control, useful to later retrive it or set its
|
728 |
* value
|
729 |
* @param control
|
730 |
* The control to add
|
731 |
*/
|
732 |
public void addControl(String id, Component control) { |
733 |
if (!controls.containsKey(control.getName())) {
|
734 |
controls.put(control.getName(), control); |
735 |
controlContainer.add(control); |
736 |
} else {
|
737 |
logger.debug("NewStatusBar.addControl -- control 'id' already exists" + id);
|
738 |
} |
739 |
} |
740 |
|
741 |
/**
|
742 |
* Remove a control from the status bar
|
743 |
*
|
744 |
* @param id
|
745 |
* The ID of the control to get
|
746 |
*/
|
747 |
public Component removeControl(String id) { |
748 |
try {
|
749 |
Component component = (Component) controls.get(id); |
750 |
controlContainer.remove(component); |
751 |
controls.remove(id); |
752 |
return component;
|
753 |
} catch (ClassCastException ex) { |
754 |
logger.debug("NewStatusBar.removeControl -- control " + id
|
755 |
+ "doesn't exist");
|
756 |
} |
757 |
return null; |
758 |
} |
759 |
|
760 |
/**
|
761 |
* Gets a control from the status bar
|
762 |
*
|
763 |
* @param id
|
764 |
* The ID of the control to get
|
765 |
*/
|
766 |
public Component getControl(String id) { |
767 |
return (Component) controls.get(id); |
768 |
} |
769 |
} // @jve:decl-index=0:visual-constraint="10,10"
|