Revision 38564 branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/ui/mdiFrame/NewStatusBar.java
NewStatusBar.java | ||
---|---|---|
26 | 26 |
import java.awt.Dimension; |
27 | 27 |
import java.awt.FlowLayout; |
28 | 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; |
|
29 | 33 |
import java.util.HashMap; |
30 | 34 |
import java.util.Map; |
31 | 35 |
|
32 | 36 |
import javax.swing.BorderFactory; |
33 | 37 |
import javax.swing.ImageIcon; |
34 | 38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JOptionPane; |
|
35 | 40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JPopupMenu; |
|
36 | 42 |
import javax.swing.JProgressBar; |
37 | 43 |
import javax.swing.SwingConstants; |
44 |
import javax.swing.Timer; |
|
38 | 45 |
import javax.swing.border.BevelBorder; |
39 | 46 |
|
40 |
import org.apache.log4j.Logger; |
|
41 |
|
|
42 | 47 |
import org.gvsig.andami.PluginServices; |
43 | 48 |
import org.gvsig.andami.messages.Messages; |
44 | 49 |
import org.gvsig.andami.plugins.config.generate.Label; |
45 | 50 |
import org.gvsig.gui.beans.controls.IControl; |
46 | 51 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
47 | 52 |
import org.gvsig.tools.swing.api.task.JTasksStatus; |
53 |
import org.slf4j.Logger; |
|
54 |
import org.slf4j.LoggerFactory; |
|
48 | 55 |
|
49 | 56 |
/** |
50 | 57 |
* <p> |
... | ... | |
69 | 76 |
public class NewStatusBar extends JPanel { |
70 | 77 |
|
71 | 78 |
private static final long serialVersionUID = 5575549032728844632L; |
72 |
private static Logger LOG = Logger.getLogger(NewStatusBar.class); |
|
79 |
|
|
80 |
private static Logger logger = LoggerFactory.getLogger(NewStatusBar.class); |
|
81 |
|
|
73 | 82 |
private static final int INFO = 0; |
74 | 83 |
private static final int WARNING = 1; |
75 | 84 |
private static final int ERROR = 2; |
... | ... | |
78 | 87 |
private boolean contenidoTemporal; |
79 | 88 |
private String textoAnterior; |
80 | 89 |
private int estadoAnterior; |
81 |
private ImageIcon infoIcon; |
|
82 |
private ImageIcon warningIcon; |
|
83 |
private ImageIcon errorIcon; |
|
84 | 90 |
private int estado; |
85 | 91 |
private JProgressBar progressBar = null; |
86 | 92 |
private Map<String, JLabel> idLabel = new HashMap<String, JLabel>(); |
... | ... | |
88 | 94 |
private Map<String, Component> controls = new HashMap<String, Component>(); |
89 | 95 |
private JPanel controlContainer; |
90 | 96 |
private JTasksStatus tasksStatus = null; |
97 |
private Timer messageTimer; |
|
91 | 98 |
|
99 |
|
|
92 | 100 |
/** |
93 | 101 |
* This is the default constructor |
94 | 102 |
*/ |
95 | 103 |
public NewStatusBar() { |
96 | 104 |
super(); |
97 | 105 |
initialize(); |
98 |
infoIcon = PluginServices.getIconTheme().get("info-icon"); |
|
99 |
warningIcon = PluginServices.getIconTheme().get("warning-icon"); |
|
100 |
errorIcon = PluginServices.getIconTheme().get("error-icon"); |
|
101 | 106 |
} |
102 | 107 |
|
108 |
private ImageIcon getImageIcon(String iconName) { |
|
109 |
return PluginServices.getIconTheme().get(iconName); |
|
110 |
} |
|
111 |
|
|
112 |
|
|
103 | 113 |
/** |
104 | 114 |
* This method initializes the status bar. It creates the required |
105 | 115 |
* containers and sets the layout. |
... | ... | |
126 | 136 |
|
127 | 137 |
JPanel panelLeft = new JPanel(); |
128 | 138 |
panelLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0)); |
139 |
panelLeft.add(lblIcon); |
|
129 | 140 |
panelLeft.add(lblTexto); |
130 |
panelLeft.add(lblIcon); |
|
131 | 141 |
panelLeft.add(getProgressBar()); |
132 | 142 |
|
133 | 143 |
this.add(panelLeft, BorderLayout.CENTER); |
134 | 144 |
this.add(panelRight, BorderLayout.EAST); |
145 |
|
|
146 |
buildMesagePopupMenu(); |
|
147 |
|
|
148 |
messageTimer = new Timer(30000, new ActionListener() { |
|
149 |
public void actionPerformed(ActionEvent e) { |
|
150 |
try { |
|
151 |
clearMessage(); |
|
152 |
} catch( Throwable ex) { |
|
153 |
logger.info("Can't clear message", ex); |
|
154 |
} |
|
155 |
} |
|
156 |
}); |
|
135 | 157 |
} |
158 |
|
|
159 |
public void clearMessage() { |
|
160 |
lblTexto.setText(""); |
|
161 |
lblIcon.setIcon(null); |
|
162 |
estado = INFO; |
|
163 |
} |
|
136 | 164 |
|
165 |
|
|
166 |
public void message(String msg, int messageTyoe) { |
|
167 |
messageTimer.stop(); |
|
168 |
switch (messageTyoe) { |
|
169 |
case JOptionPane.ERROR_MESSAGE: |
|
170 |
setErrorText(msg); |
|
171 |
break; |
|
172 |
case JOptionPane.WARNING_MESSAGE: |
|
173 |
setWarningText(msg); |
|
174 |
break; |
|
175 |
default: |
|
176 |
case JOptionPane.INFORMATION_MESSAGE: |
|
177 |
setInfoText(msg); |
|
178 |
break; |
|
179 |
} |
|
180 |
messageTimer.start(); |
|
181 |
} |
|
182 |
|
|
183 |
private void buildMesagePopupMenu() { |
|
184 |
final JPopupMenu menu = new JPopupMenu(); |
|
185 |
|
|
186 |
JMenuItem item = new JMenuItem("View details"); |
|
187 |
item.addActionListener(new ActionListener() { |
|
188 |
public void actionPerformed(ActionEvent arg0) { |
|
189 |
switch (estado) { |
|
190 |
default: |
|
191 |
case INFO: |
|
192 |
JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.INFORMATION_MESSAGE); |
|
193 |
break; |
|
194 |
case WARNING: |
|
195 |
JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.WARNING_MESSAGE); |
|
196 |
break; |
|
197 |
case ERROR: |
|
198 |
JOptionPane.showMessageDialog(lblTexto, getStatusText(), "", JOptionPane.ERROR_MESSAGE); |
|
199 |
break; |
|
200 |
} |
|
201 |
} |
|
202 |
}); |
|
203 |
menu.add(item); |
|
204 |
item = new JMenuItem("Clear"); |
|
205 |
item.addActionListener(new ActionListener() { |
|
206 |
public void actionPerformed(ActionEvent e) { |
|
207 |
clearMessage(); |
|
208 |
} |
|
209 |
}); |
|
210 |
menu.add(item); |
|
211 |
menu.addSeparator(); |
|
212 |
item = new JMenuItem("Cancel"); |
|
213 |
menu.add(item); |
|
214 |
|
|
215 |
this.lblTexto.addMouseListener( new MouseListener() { |
|
216 |
public void mouseReleased(MouseEvent e) { |
|
217 |
if( e.isPopupTrigger() ) { |
|
218 |
if( getStatusText().length() > 0 || estado!=INFO ) { |
|
219 |
menu.show(lblTexto, e.getX(), e.getY()); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
public void mousePressed(MouseEvent e) { |
|
224 |
if( e.isPopupTrigger() ) { |
|
225 |
if( getStatusText().length() > 0 || estado!=INFO ) { |
|
226 |
menu.show(lblTexto, e.getX(), e.getY()); |
|
227 |
} |
|
228 |
} |
|
229 |
} |
|
230 |
public void mouseExited(MouseEvent e) { |
|
231 |
} |
|
232 |
public void mouseEntered(MouseEvent e) { |
|
233 |
} |
|
234 |
public void mouseClicked(MouseEvent e) { |
|
235 |
} |
|
236 |
}); |
|
237 |
} |
|
238 |
|
|
137 | 239 |
/** |
138 | 240 |
* Gets the status bar main text. |
139 | 241 |
* |
... | ... | |
204 | 306 |
} |
205 | 307 |
|
206 | 308 |
this.estado = INFO; |
207 |
lblIcon.setIcon(infoIcon);
|
|
309 |
lblIcon.setIcon(getImageIcon("statusbar-info"));
|
|
208 | 310 |
lblTexto.setText(texto); |
209 | 311 |
} |
210 | 312 |
|
... | ... | |
224 | 326 |
contenidoTemporal = true; |
225 | 327 |
} |
226 | 328 |
this.estado = WARNING; |
227 |
lblIcon.setIcon(warningIcon);
|
|
329 |
lblIcon.setIcon(getImageIcon("statusbar-warning"));
|
|
228 | 330 |
lblTexto.setText(texto); |
229 | 331 |
} |
230 | 332 |
|
... | ... | |
245 | 347 |
} |
246 | 348 |
|
247 | 349 |
this.estado = ERROR; |
248 |
lblIcon.setIcon(errorIcon);
|
|
350 |
lblIcon.setIcon(getImageIcon("statusbar-error"));
|
|
249 | 351 |
lblTexto.setText(texto); |
250 | 352 |
} |
251 | 353 |
|
... | ... | |
265 | 367 |
estadoAnterior = INFO; |
266 | 368 |
} else { |
267 | 369 |
lblTexto.setText(texto); |
268 |
lblIcon.setIcon(infoIcon);
|
|
370 |
lblIcon.setIcon(getImageIcon("statusbar-info"));
|
|
269 | 371 |
estado = INFO; |
270 | 372 |
} |
271 | 373 |
} |
... | ... | |
286 | 388 |
estadoAnterior = WARNING; |
287 | 389 |
} else { |
288 | 390 |
lblTexto.setText(texto); |
289 |
lblIcon.setIcon(warningIcon);
|
|
391 |
lblIcon.setIcon(getImageIcon("statusbar-warning"));
|
|
290 | 392 |
estado = WARNING; |
291 | 393 |
} |
292 | 394 |
} |
... | ... | |
307 | 409 |
estadoAnterior = ERROR; |
308 | 410 |
} else { |
309 | 411 |
lblTexto.setText(texto); |
310 |
lblIcon.setIcon(errorIcon);
|
|
412 |
lblIcon.setIcon(getImageIcon("statusbar-error"));
|
|
311 | 413 |
estado = ERROR; |
312 | 414 |
} |
313 | 415 |
} |
... | ... | |
453 | 555 |
if (control != null) |
454 | 556 |
control.setValue(msg); |
455 | 557 |
} catch (ClassCastException ex) { |
456 |
LOG.debug("no label called " + id);
|
|
558 |
logger.debug("no label called " + id);
|
|
457 | 559 |
} |
458 | 560 |
} |
459 | 561 |
|
... | ... | |
473 | 575 |
if (control != null) { |
474 | 576 |
control.setValue(value); |
475 | 577 |
} else { |
476 |
LOG.debug("NewStatusBar -- no control called " + id);
|
|
578 |
logger.debug("NewStatusBar -- no control called " + id);
|
|
477 | 579 |
} |
478 | 580 |
} |
479 | 581 |
|
... | ... | |
530 | 632 |
controls.put(control.getName(), control); |
531 | 633 |
controlContainer.add(control); |
532 | 634 |
} else { |
533 |
LOG |
|
534 |
.debug("NewStatusBar.addControl -- control 'id' already exists" |
|
535 |
+ id); |
|
635 |
logger.debug("NewStatusBar.addControl -- control 'id' already exists" + id); |
|
536 | 636 |
} |
537 | 637 |
} |
538 | 638 |
|
... | ... | |
549 | 649 |
controls.remove(id); |
550 | 650 |
return component; |
551 | 651 |
} catch (ClassCastException ex) { |
552 |
LOG.debug("NewStatusBar.removeControl -- control " + id
|
|
652 |
logger.debug("NewStatusBar.removeControl -- control " + id
|
|
553 | 653 |
+ "doesn't exist"); |
554 | 654 |
} |
555 | 655 |
return null; |
Also available in: Unified diff