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