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