1 |
|
package com.iver.andami.ui.mdiFrame;
|
2 |
|
|
3 |
|
import java.awt.CardLayout;
|
4 |
|
import java.awt.Color;
|
5 |
|
import java.awt.Dimension;
|
6 |
|
import java.awt.FlowLayout;
|
7 |
|
import java.awt.GridBagConstraints;
|
8 |
|
import java.awt.GridBagLayout;
|
9 |
|
import java.util.ArrayList;
|
10 |
|
import java.util.HashMap;
|
11 |
|
|
12 |
|
import javax.swing.BorderFactory;
|
13 |
|
import javax.swing.ImageIcon;
|
14 |
|
import javax.swing.JLabel;
|
15 |
|
import javax.swing.JPanel;
|
16 |
|
import javax.swing.JProgressBar;
|
17 |
|
import javax.swing.SwingConstants;
|
18 |
|
|
19 |
|
import org.apache.log4j.Logger;
|
20 |
|
|
21 |
|
import com.iver.andami.Utilities;
|
22 |
|
import com.iver.andami.messages.Messages;
|
23 |
|
|
24 |
|
|
25 |
|
/**
|
26 |
|
* Barra de estado. Tiene dos tipos de texto. El texto permanente y el texto
|
27 |
|
* temporal. El texto permanente es el que se pone por defecto y el texto
|
28 |
|
* temporal se muestra de la misma manera, pero luego mediante una invocaci?n
|
29 |
|
* a restaurar texto, se vuelve a mostrar el texto permanente que hab?a antes.
|
30 |
|
* Esto es ?til para mostrar informaci?n de los controles cuando el usuario
|
31 |
|
* mueve el rat?n por encima de estos
|
32 |
|
*
|
33 |
|
* @version $Revision$
|
34 |
|
*/
|
35 |
|
public class StatusBar extends JPanel {
|
36 |
|
/** DOCUMENT ME! */
|
37 |
|
private static Logger logger = Logger.getLogger(StatusBar.class.getName());
|
38 |
|
|
39 |
|
/** DOCUMENT ME! */
|
40 |
|
private String[] cards = { "INFO", "WARNING", "ERROR" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
41 |
|
|
42 |
|
/** DOCUMENT ME! */
|
43 |
|
private boolean contenidoTemporal = false;
|
44 |
|
|
45 |
|
/** DOCUMENT ME! */
|
46 |
|
private int estado;
|
47 |
|
|
48 |
|
/** DOCUMENT ME! */
|
49 |
|
private JLabel infoEstado = null;
|
50 |
|
|
51 |
|
/** DOCUMENT ME! */
|
52 |
|
private JLabel imageError = null;
|
53 |
|
|
54 |
|
/** DOCUMENT ME! */
|
55 |
|
private JLabel imageWarning = null;
|
56 |
|
|
57 |
|
/** DOCUMENT ME! */
|
58 |
|
private JLabel imageInfo = null;
|
59 |
|
|
60 |
|
/** DOCUMENT ME! */
|
61 |
|
private JPanel led = null;
|
62 |
|
|
63 |
|
/** DOCUMENT ME! */
|
64 |
|
private JProgressBar progressBar = null;
|
65 |
|
|
66 |
|
/** DOCUMENT ME! */
|
67 |
|
private JPanel labelPane = null;
|
68 |
|
|
69 |
|
/** DOCUMENT ME! */
|
70 |
|
private int estadoAnterior = -1;
|
71 |
|
|
72 |
|
/** DOCUMENT ME! */
|
73 |
|
private String textoAnterior = null;
|
74 |
|
|
75 |
|
/** DOCUMENT ME! */
|
76 |
|
private GridBagLayout layout;
|
77 |
|
|
78 |
|
/** DOCUMENT ME! */
|
79 |
|
private ArrayList etiquetas = new ArrayList();
|
80 |
|
|
81 |
|
/** DOCUMENT ME! */
|
82 |
|
private HashMap nombreEtiqueta = new HashMap();
|
83 |
|
|
84 |
|
/**
|
85 |
|
* Creates a new StatusBar object.
|
86 |
|
*/
|
87 |
|
public StatusBar() {
|
88 |
|
|
89 |
|
this.setBackground(Color.BLUE);
|
90 |
|
|
91 |
|
layout = new GridBagLayout();
|
92 |
|
this.setLayout(layout);
|
93 |
|
|
94 |
|
/* FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
|
95 |
|
layout.setVgap(0);
|
96 |
|
this.setLayout(layout);
|
97 |
|
*/
|
98 |
|
this.setPreferredSize(new Dimension(0, 25));
|
99 |
|
|
100 |
|
infoEstado = new JLabel(Messages.getString("StatusBar.Listo")); //$NON-NLS-1$
|
101 |
|
infoEstado.setHorizontalAlignment(SwingConstants.RIGHT);
|
102 |
|
|
103 |
|
ImageIcon icon = Utilities.createImageIcon("images/info.gif"); //$NON-NLS-1$
|
104 |
|
imageInfo = new JLabel(icon);
|
105 |
|
icon = Utilities.createImageIcon("images/warning.gif"); //$NON-NLS-1$
|
106 |
|
imageWarning = new JLabel(icon);
|
107 |
|
icon = Utilities.createImageIcon("images/error.gif"); //$NON-NLS-1$
|
108 |
|
imageError = new JLabel(icon);
|
109 |
|
|
110 |
|
led = new JPanel(new CardLayout());
|
111 |
|
|
112 |
|
JPanel info = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
113 |
|
info.add(imageInfo);
|
114 |
|
led.add(info, "INFO"); //$NON-NLS-1$
|
115 |
|
|
116 |
|
JPanel warning = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
117 |
|
warning.add(imageWarning);
|
118 |
|
led.add(warning, "WARNING"); //$NON-NLS-1$
|
119 |
|
|
120 |
|
JPanel error = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
121 |
|
error.add(imageError);
|
122 |
|
led.add(error, "ERROR"); //$NON-NLS-1$
|
123 |
|
|
124 |
|
add(led);
|
125 |
|
add(infoEstado);
|
126 |
|
labelPane = new JPanel();
|
127 |
|
|
128 |
|
FlowLayout labelLayout = new FlowLayout(FlowLayout.RIGHT);
|
129 |
|
labelLayout.setVgap(0);
|
130 |
|
labelLayout.setHgap(2);
|
131 |
|
labelPane.setLayout(labelLayout);
|
132 |
|
|
133 |
|
add(labelPane);
|
134 |
|
|
135 |
|
/* progressBar = new JProgressBar(0, 100);
|
136 |
|
progressBar.setVisible(false);
|
137 |
|
add(progressBar);
|
138 |
|
*/
|
139 |
|
GridBagConstraints c = new GridBagConstraints();
|
140 |
|
c.weightx = 0.0;
|
141 |
|
layout.setConstraints(led, c);
|
142 |
|
layout.setConstraints(infoEstado, c);
|
143 |
|
|
144 |
|
// layout.setConstraints(progressBar, c);
|
145 |
|
c = new GridBagConstraints();
|
146 |
|
c.weightx = 1.0;
|
147 |
|
c.fill = GridBagConstraints.HORIZONTAL;
|
148 |
|
layout.setConstraints(labelPane, c);
|
149 |
|
|
150 |
|
/* led.setBorder(BorderFactory.createEtchedBorder());
|
151 |
|
infoEstado.setBorder(BorderFactory.createEtchedBorder());
|
152 |
|
labelPane.setBorder(BorderFactory.createEtchedBorder());
|
153 |
|
*/
|
154 |
|
}
|
155 |
|
|
156 |
|
/**
|
157 |
|
* Obtiene el texto de la barra de estado
|
158 |
|
*
|
159 |
|
* @return texto
|
160 |
|
*/
|
161 |
|
public String getStatusText() {
|
162 |
|
return infoEstado.getText();
|
163 |
|
}
|
164 |
|
|
165 |
|
/**
|
166 |
|
* Restaura el contenido permanente de la barra de estado
|
167 |
|
*/
|
168 |
|
public void restaurarTexto() {
|
169 |
|
if (estadoAnterior == -1) {
|
170 |
|
return;
|
171 |
|
}
|
172 |
|
|
173 |
|
logger.debug("restaurando contenido permanente"); //$NON-NLS-1$
|
174 |
|
contenidoTemporal = false;
|
175 |
|
setStatusText(textoAnterior, estadoAnterior);
|
176 |
|
estadoAnterior = -1;
|
177 |
|
textoAnterior = null;
|
178 |
|
}
|
179 |
|
|
180 |
|
/**
|
181 |
|
* Establece el texto de la barra de estado de forma temporal. Se almacena
|
182 |
|
* el texto que hab?a en la barra de estado.
|
183 |
|
*
|
184 |
|
* @param texto texto
|
185 |
|
* @param status Codigo de la importancia del mensaje ERROR, WARNING o INFO
|
186 |
|
*/
|
187 |
|
public void setStatusTextTemporal(String texto, int status) {
|
188 |
|
logger.debug("estableciendo contenido temporal"); //$NON-NLS-1$
|
189 |
|
contenidoTemporal = true;
|
190 |
|
|
191 |
|
estadoAnterior = this.estado;
|
192 |
|
this.estado = status;
|
193 |
|
((CardLayout) led.getLayout()).show(led, cards[status]);
|
194 |
|
|
195 |
|
textoAnterior = getStatusText();
|
196 |
|
infoEstado.setText(texto);
|
197 |
|
}
|
198 |
|
|
199 |
|
/**
|
200 |
|
* Establece el texto de la barar de manera permanente. Si se est?
|
201 |
|
* mostrando texto de forma temporal no se actualiza la interfaz
|
202 |
|
*
|
203 |
|
* @param texto Texto
|
204 |
|
* @param status Codigo de la importancia del mensaje ERROR, WARNING o INFO
|
205 |
|
*/
|
206 |
|
public void setStatusText(String texto, int status) {
|
207 |
|
logger.debug("estableciendo contenido premanente"); //$NON-NLS-1$
|
208 |
|
|
209 |
|
if (contenidoTemporal) {
|
210 |
|
textoAnterior = texto;
|
211 |
|
estadoAnterior = status;
|
212 |
|
} else {
|
213 |
|
infoEstado.setText(texto);
|
214 |
|
((CardLayout) led.getLayout()).show(led, cards[status]);
|
215 |
|
estado = status;
|
216 |
|
}
|
217 |
|
}
|
218 |
|
|
219 |
|
/**
|
220 |
|
* Establece el estado de la barra de estado
|
221 |
|
*
|
222 |
|
* @param n
|
223 |
|
*/
|
224 |
|
public void setProgress(int n) {
|
225 |
|
progressBar.setValue(n);
|
226 |
|
|
227 |
|
if (n != 100) {
|
228 |
|
progressBar.setVisible(true);
|
229 |
|
} else {
|
230 |
|
progressBar.setVisible(false);
|
231 |
|
}
|
232 |
|
}
|
233 |
|
|
234 |
|
/**
|
235 |
|
* Establece las etiquetas que habr? en la barra de estado.
|
236 |
|
*
|
237 |
|
* @param ets estructura con la informaci?n de las etiquetas
|
238 |
|
*/
|
239 |
|
public void setEtiquetas(ArrayList ets) {
|
240 |
|
//Rellena el array con las etiquetas que faltan
|
241 |
|
for (int i = etiquetas.size(); i < ets.size(); i++) {
|
242 |
|
logger.debug("a?adiendo una etiqueta");
|
243 |
|
|
244 |
|
JLabel nueva = new JLabel();
|
245 |
|
nueva.setBorder(BorderFactory.createLoweredBevelBorder());
|
246 |
|
etiquetas.add(nueva);
|
247 |
|
labelPane.add(nueva);
|
248 |
|
}
|
249 |
|
|
250 |
|
//Visualiza todas las etiquetas necesarias
|
251 |
|
for (int i = 0; i < ets.size(); i++) {
|
252 |
|
JLabel aux = (JLabel) etiquetas.get(i);
|
253 |
|
aux.setVisible(true);
|
254 |
|
}
|
255 |
|
|
256 |
|
//Oculta las que sobran
|
257 |
|
for (int i = ets.size(); i < etiquetas.size(); i++) {
|
258 |
|
logger.debug("Ocultando una etiqueta");
|
259 |
|
|
260 |
|
JLabel aux = (JLabel) etiquetas.get(i);
|
261 |
|
aux.setVisible(false);
|
262 |
|
}
|
263 |
|
|
264 |
|
//Asocia las etiquetas con los nombres
|
265 |
|
nombreEtiqueta.clear();
|
266 |
|
/*
|
267 |
|
* TODO implementar bien
|
268 |
|
*
|
269 |
|
for (int i = 0; i < ets.size(); i++) {
|
270 |
|
JLabel label = (JLabel) etiquetas.get(i);
|
271 |
|
nombreEtiqueta.put(((StatusLabel) ets.get(i)).getText(), label);
|
272 |
|
label.setPreferredSize(new Dimension(
|
273 |
|
((StatusLabel) ets.get(i)).getWidth(), this.getHeight() -
|
274 |
|
5));
|
275 |
|
}
|
276 |
|
*/
|
277 |
|
}
|
278 |
|
|
279 |
|
/**
|
280 |
|
* Establece el texto de una etiqueta
|
281 |
|
*
|
282 |
|
* @param etiqueta Nombre de la etiqueta donde se quiere escribir el texto
|
283 |
|
* @param texto texto que se quiere escribir
|
284 |
|
*/
|
285 |
|
public void setText(String etiqueta, String texto) {
|
286 |
|
JLabel aux = (JLabel) nombreEtiqueta.get(etiqueta);
|
287 |
|
|
288 |
|
if (aux != null) {
|
289 |
|
aux.setText(texto);
|
290 |
|
} else {
|
291 |
|
logger.error("No se encontr? la etiqueta " + etiqueta);
|
292 |
|
}
|
293 |
|
}
|
294 |
|
}
|