Revision 37844
branches/v2_0_0_prep/frameworks/_fwAndami/src/org/gvsig/andami/ui/mdiFrame/NewStatusBar.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
|
2 | 2 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 | 8 |
* as published by the Free Software Foundation; either version 2 |
8 | 9 |
* of the License, or (at your option) any later version. |
9 |
* |
|
10 |
*
|
|
10 | 11 |
* This program is distributed in the hope that it will be useful, |
11 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | 14 |
* GNU General Public License for more details. |
14 |
* |
|
15 |
*
|
|
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
40 | 21 |
*/ |
41 | 22 |
package org.gvsig.andami.ui.mdiFrame; |
42 | 23 |
|
43 | 24 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
|
45 | 25 |
import java.awt.Component; |
46 | 26 |
import java.awt.Dimension; |
47 | 27 |
import java.awt.FlowLayout; |
... | ... | |
54 | 34 |
import javax.swing.JProgressBar; |
55 | 35 |
import javax.swing.SwingConstants; |
56 | 36 |
import javax.swing.border.BevelBorder; |
57 |
import javax.swing.border.LineBorder; |
|
58 | 37 |
|
59 | 38 |
import org.apache.log4j.Logger; |
60 | 39 |
|
... | ... | |
65 | 44 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
66 | 45 |
import org.gvsig.tools.swing.api.task.JTasksStatus; |
67 | 46 |
|
68 |
|
|
69 |
|
|
70 | 47 |
/** |
71 |
* <p>This class contains the status bar. It contains the graphical component, |
|
72 |
* and the methods to manage it. |
|
48 |
* <p> |
|
49 |
* This class contains the status bar. It contains the graphical component, and |
|
50 |
* the methods to manage it. |
|
73 | 51 |
* </p> |
74 | 52 |
* |
75 |
* <p>The status bar is divided in several areas. At the very left, there is |
|
76 |
* an icon and the main status text. There are three icons to show: |
|
77 |
* Info, Warning and Error icons. They can be set together with the main |
|
78 |
* status text using the methods <code>setInfoText()</code>, |
|
79 |
* <code>setWarningText()</code> and <code>setErrorText()</code> (and also with |
|
80 |
* <code>setInfoTextTemporal()</code>, etc). Then, there is a right area which |
|
81 |
* contains labels and other controls. Labels are set in the config.xml files |
|
82 |
* and are visible or not depending on the currently selected Andami window. |
|
83 |
* Controls are associated to extensions, and are enabled/disabled and |
|
84 |
* visible/hidden depending on the associated extension. |
|
53 |
* <p> |
|
54 |
* The status bar is divided in several areas. At the very left, there is an |
|
55 |
* icon and the main status text. There are three icons to show: Info, Warning |
|
56 |
* and Error icons. They can be set together with the main status text using the |
|
57 |
* methods <code>setInfoText()</code>, <code>setWarningText()</code> and |
|
58 |
* <code>setErrorText()</code> (and also with <code>setInfoTextTemporal()</code> |
|
59 |
* , etc). Then, there is a right area which contains labels and other controls. |
|
60 |
* Labels are set in the config.xml files and are visible or not depending on |
|
61 |
* the currently selected Andami window. Controls are associated to extensions, |
|
62 |
* and are enabled/disabled and visible/hidden depending on the associated |
|
63 |
* extension. |
|
85 | 64 |
* </p> |
86 | 65 |
* |
87 | 66 |
*/ |
88 | 67 |
public class NewStatusBar extends JPanel { |
89 |
/** |
|
90 |
* |
|
91 |
*/ |
|
68 |
|
|
92 | 69 |
private static final long serialVersionUID = 5575549032728844632L; |
93 |
private static Logger logger = Logger.getLogger(NewStatusBar.class.getName()); |
|
94 |
private static final int INFO = 0; |
|
95 |
private static final int WARNING = 1; |
|
96 |
private static final int ERROR = 2; |
|
97 |
private JLabel lblIcon = null; |
|
98 |
private JLabel lblTexto = null; |
|
99 |
private boolean contenidoTemporal; |
|
100 |
private String textoAnterior; |
|
101 |
private int estadoAnterior; |
|
102 |
private ImageIcon infoIcon; |
|
103 |
private ImageIcon warningIcon; |
|
104 |
private ImageIcon errorIcon; |
|
105 |
private int estado; |
|
106 |
private JProgressBar progressBar = null; |
|
107 |
private HashMap idLabel = new HashMap(); |
|
108 |
private int[] widthlabels = null; |
|
109 |
private HashMap controls = new HashMap(); |
|
110 |
private JPanel controlContainer; |
|
111 |
private JTasksStatus tasksStatus=null; |
|
112 |
|
|
113 |
/** |
|
114 |
* This is the default constructor |
|
115 |
*/ |
|
116 |
public NewStatusBar() { |
|
117 |
super(); |
|
118 |
initialize(); |
|
119 |
infoIcon = PluginServices.getIconTheme().get("info-icon"); |
|
120 |
warningIcon = PluginServices.getIconTheme().get("warning-icon"); |
|
121 |
errorIcon = PluginServices.getIconTheme().get("error-icon"); |
|
122 |
|
|
123 |
} |
|
70 |
private static Logger LOG = Logger.getLogger(NewStatusBar.class); |
|
71 |
private static final int INFO = 0; |
|
72 |
private static final int WARNING = 1; |
|
73 |
private static final int ERROR = 2; |
|
74 |
private JLabel lblIcon = null; |
|
75 |
private JLabel lblTexto = null; |
|
76 |
private boolean contenidoTemporal; |
|
77 |
private String textoAnterior; |
|
78 |
private int estadoAnterior; |
|
79 |
private ImageIcon infoIcon; |
|
80 |
private ImageIcon warningIcon; |
|
81 |
private ImageIcon errorIcon; |
|
82 |
private int estado; |
|
83 |
private JProgressBar progressBar = null; |
|
84 |
private HashMap idLabel = new HashMap(); |
|
85 |
private int[] widthlabels = null; |
|
86 |
private HashMap controls = new HashMap(); |
|
87 |
private JPanel controlContainer; |
|
88 |
private JTasksStatus tasksStatus = null; |
|
124 | 89 |
|
125 |
/** |
|
126 |
* This method initializes the status bar. It creates the required |
|
127 |
* containers and sets the layout. |
|
128 |
*/ |
|
129 |
private void initialize() { |
|
130 |
BorderLayout mainLayout = new BorderLayout(); |
|
131 |
this.setLayout(mainLayout); |
|
132 |
|
|
133 |
JPanel panelRight = new JPanel(); |
|
134 |
panelRight.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0)); |
|
135 |
|
|
90 |
/** |
|
91 |
* This is the default constructor |
|
92 |
*/ |
|
93 |
public NewStatusBar() { |
|
94 |
super(); |
|
95 |
initialize(); |
|
96 |
infoIcon = PluginServices.getIconTheme().get("info-icon"); |
|
97 |
warningIcon = PluginServices.getIconTheme().get("warning-icon"); |
|
98 |
errorIcon = PluginServices.getIconTheme().get("error-icon"); |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* This method initializes the status bar. It creates the required |
|
104 |
* containers and sets the layout. |
|
105 |
*/ |
|
106 |
private void initialize() { |
|
107 |
BorderLayout mainLayout = new BorderLayout(); |
|
108 |
this.setLayout(mainLayout); |
|
109 |
|
|
110 |
JPanel panelRight = new JPanel(); |
|
111 |
panelRight.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0)); |
|
112 |
|
|
136 | 113 |
controlContainer = new JPanel(); |
137 |
controlContainer.setLayout(new FlowLayout(FlowLayout.RIGHT,1,2));
|
|
114 |
controlContainer.setLayout(new FlowLayout(FlowLayout.RIGHT, 1, 2));
|
|
138 | 115 |
panelRight.add(controlContainer); |
139 | 116 |
panelRight.add(getTasksStatus()); |
140 |
|
|
141 |
this.setPreferredSize(new Dimension(183,20)); |
|
142 |
this.setSize(new Dimension(183,20)); |
|
143 |
lblIcon = new JLabel(); |
|
144 |
lblTexto = new JLabel(); |
|
145 |
lblTexto.setAlignmentX(JLabel.LEFT_ALIGNMENT); |
|
146 |
lblTexto.setHorizontalAlignment(SwingConstants.LEFT); |
|
147 |
lblTexto.setHorizontalTextPosition(SwingConstants.LEFT); |
|
148 | 117 |
|
149 |
lblIcon.setText(""); |
|
150 |
lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada")); |
|
151 |
|
|
118 |
this.setPreferredSize(new Dimension(183, 20)); |
|
119 |
this.setSize(new Dimension(183, 20)); |
|
120 |
lblIcon = new JLabel(); |
|
121 |
lblTexto = new JLabel(); |
|
122 |
lblTexto.setAlignmentX(JLabel.LEFT_ALIGNMENT); |
|
123 |
lblTexto.setHorizontalAlignment(SwingConstants.LEFT); |
|
124 |
lblTexto.setHorizontalTextPosition(SwingConstants.LEFT); |
|
125 |
|
|
126 |
lblIcon.setText(""); |
|
127 |
lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada")); |
|
128 |
|
|
152 | 129 |
JPanel panelLeft = new JPanel(); |
153 |
panelLeft.setLayout(new FlowLayout(FlowLayout.LEFT,1,2));
|
|
130 |
panelLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 2));
|
|
154 | 131 |
panelLeft.add(lblTexto, null); |
155 |
panelLeft.add(lblIcon, null);
|
|
132 |
panelLeft.add(lblIcon, null);
|
|
156 | 133 |
panelLeft.add(getProgressBar(), null); |
157 | 134 |
|
158 | 135 |
this.add(panelLeft, BorderLayout.CENTER); |
159 | 136 |
this.add(panelRight, BorderLayout.EAST); |
160 |
}
|
|
137 |
}
|
|
161 | 138 |
|
162 |
/**
|
|
163 |
* Gets the status bar main text.
|
|
164 |
*
|
|
165 |
* @return The status bar main text.
|
|
166 |
* @see #setInfoText(String)
|
|
167 |
* @see #setWarningText(String)
|
|
168 |
* @see #setErrorText(String)
|
|
169 |
* @see #setInfoTextTemporal(String)
|
|
170 |
* @see #setWarningTextTemporal(String)
|
|
171 |
* @see #setErrorTextTemporal(String)
|
|
172 |
*/
|
|
173 |
public String getStatusText() {
|
|
174 |
return lblTexto.getText();
|
|
175 |
}
|
|
139 |
/**
|
|
140 |
* Gets the status bar main text.
|
|
141 |
*
|
|
142 |
* @return The status bar main text.
|
|
143 |
* @see #setInfoText(String)
|
|
144 |
* @see #setWarningText(String)
|
|
145 |
* @see #setErrorText(String)
|
|
146 |
* @see #setInfoTextTemporal(String)
|
|
147 |
* @see #setWarningTextTemporal(String)
|
|
148 |
* @see #setErrorTextTemporal(String)
|
|
149 |
*/
|
|
150 |
public String getStatusText() {
|
|
151 |
return lblTexto.getText();
|
|
152 |
}
|
|
176 | 153 |
|
177 |
/** |
|
178 |
* Restores the previous contents in the status bar main text, |
|
179 |
* after the {@link #setInfoTextTemporal(String)}, {@link #setWarningTextTemporal(String)} |
|
180 |
* or {@link #setErrorTextTemporal(String)} have been called. |
|
181 |
* |
|
182 |
* @see #setInfoTextTemporal(String) |
|
183 |
* @see #setWarningTextTemporal(String) |
|
184 |
* @see #setErrorTextTemporal(String) |
|
185 |
*/ |
|
186 |
public void restaurarTexto() { |
|
187 |
contenidoTemporal = false; |
|
154 |
/** |
|
155 |
* Restores the previous contents in the status bar main text, |
|
156 |
* after the {@link #setInfoTextTemporal(String)}, |
|
157 |
* {@link #setWarningTextTemporal(String)} or |
|
158 |
* {@link #setErrorTextTemporal(String)} have been called. |
|
159 |
* |
|
160 |
* @see #setInfoTextTemporal(String) |
|
161 |
* @see #setWarningTextTemporal(String) |
|
162 |
* @see #setErrorTextTemporal(String) |
|
163 |
*/ |
|
164 |
public void restaurarTexto() { |
|
165 |
contenidoTemporal = false; |
|
188 | 166 |
|
189 |
if (estadoAnterior == -1) {
|
|
190 |
return;
|
|
191 |
}
|
|
167 |
if (estadoAnterior == -1) {
|
|
168 |
return;
|
|
169 |
}
|
|
192 | 170 |
|
193 |
switch (estadoAnterior) {
|
|
194 |
case INFO:
|
|
195 |
setInfoText(textoAnterior);
|
|
171 |
switch (estadoAnterior) {
|
|
172 |
case INFO:
|
|
173 |
setInfoText(textoAnterior);
|
|
196 | 174 |
|
197 |
break;
|
|
175 |
break;
|
|
198 | 176 |
|
199 |
case WARNING:
|
|
200 |
setWarningText(textoAnterior);
|
|
177 |
case WARNING:
|
|
178 |
setWarningText(textoAnterior);
|
|
201 | 179 |
|
202 |
break;
|
|
180 |
break;
|
|
203 | 181 |
|
204 |
case ERROR:
|
|
205 |
setErrorText(textoAnterior);
|
|
182 |
case ERROR:
|
|
183 |
setErrorText(textoAnterior);
|
|
206 | 184 |
|
207 |
break;
|
|
208 |
}
|
|
185 |
break;
|
|
186 |
}
|
|
209 | 187 |
|
210 |
estadoAnterior = -1;
|
|
211 |
textoAnterior = null;
|
|
212 |
}
|
|
188 |
estadoAnterior = -1;
|
|
189 |
textoAnterior = null;
|
|
190 |
}
|
|
213 | 191 |
|
214 |
/** |
|
215 |
* Sets a temporary information message in the status bar, and changes the |
|
216 |
* icon to an Info icon. The previous text and icon can be restored using |
|
217 |
* the {@link #restaurarTexto()} method. |
|
218 |
* |
|
219 |
* @param texto The text to set |
|
220 |
* @see #restaurarTexto() |
|
221 |
*/ |
|
222 |
public void setInfoTextTemporal(String texto) { |
|
223 |
if (!contenidoTemporal) { |
|
224 |
textoAnterior = getStatusText(); |
|
225 |
estadoAnterior = this.estado; |
|
226 |
contenidoTemporal = true; |
|
227 |
} |
|
228 |
|
|
229 |
this.estado = INFO; |
|
230 |
lblIcon.setIcon(infoIcon); |
|
231 |
lblTexto.setText(texto); |
|
232 |
} |
|
192 |
/** |
|
193 |
* Sets a temporary information message in the status bar, and changes the |
|
194 |
* icon to an Info icon. The previous text and icon can be restored using |
|
195 |
* the {@link #restaurarTexto()} method. |
|
196 |
* |
|
197 |
* @param texto |
|
198 |
* The text to set |
|
199 |
* @see #restaurarTexto() |
|
200 |
*/ |
|
201 |
public void setInfoTextTemporal(String texto) { |
|
202 |
if (!contenidoTemporal) { |
|
203 |
textoAnterior = getStatusText(); |
|
204 |
estadoAnterior = this.estado; |
|
205 |
contenidoTemporal = true; |
|
206 |
} |
|
233 | 207 |
|
234 |
/** |
|
235 |
* Sets a temporary warning message in the status bar, and changes the |
|
236 |
* icon to a Warning icon. The previous text and icon can be restored using |
|
237 |
* the {@link #restaurarTexto()} method. |
|
238 |
* |
|
239 |
* @param texto The text to set |
|
240 |
* @see #restaurarTexto() |
|
241 |
*/ |
|
242 |
public void setWarningTextTemporal(String texto) { |
|
243 |
if (!contenidoTemporal) { |
|
244 |
estadoAnterior = this.estado; |
|
245 |
textoAnterior = getStatusText(); |
|
246 |
contenidoTemporal = true; |
|
247 |
} |
|
248 |
this.estado = WARNING; |
|
249 |
lblIcon.setIcon(warningIcon); |
|
250 |
lblTexto.setText(texto); |
|
251 |
} |
|
208 |
this.estado = INFO; |
|
209 |
lblIcon.setIcon(infoIcon); |
|
210 |
lblTexto.setText(texto); |
|
211 |
} |
|
252 | 212 |
|
253 |
/** |
|
254 |
* Sets a temporary error message in the status bar, and changes the |
|
255 |
* icon to an Error icon. The previous text and icon can be restored using |
|
256 |
* the {@link #restaurarTexto()} method. |
|
257 |
* |
|
258 |
* @param texto The text to set |
|
259 |
* @see #restaurarTexto() |
|
260 |
*/ |
|
261 |
public void setErrorTextTemporal(String texto) { |
|
262 |
if (!contenidoTemporal) { |
|
263 |
estadoAnterior = this.estado; |
|
264 |
textoAnterior = getStatusText(); |
|
265 |
contenidoTemporal = true; |
|
266 |
} |
|
213 |
/** |
|
214 |
* Sets a temporary warning message in the status bar, and changes the |
|
215 |
* icon to a Warning icon. The previous text and icon can be restored using |
|
216 |
* the {@link #restaurarTexto()} method. |
|
217 |
* |
|
218 |
* @param texto |
|
219 |
* The text to set |
|
220 |
* @see #restaurarTexto() |
|
221 |
*/ |
|
222 |
public void setWarningTextTemporal(String texto) { |
|
223 |
if (!contenidoTemporal) { |
|
224 |
estadoAnterior = this.estado; |
|
225 |
textoAnterior = getStatusText(); |
|
226 |
contenidoTemporal = true; |
|
227 |
} |
|
228 |
this.estado = WARNING; |
|
229 |
lblIcon.setIcon(warningIcon); |
|
230 |
lblTexto.setText(texto); |
|
231 |
} |
|
267 | 232 |
|
268 |
this.estado = ERROR; |
|
269 |
lblIcon.setIcon(errorIcon); |
|
270 |
lblTexto.setText(texto); |
|
271 |
} |
|
233 |
/** |
|
234 |
* Sets a temporary error message in the status bar, and changes the |
|
235 |
* icon to an Error icon. The previous text and icon can be restored using |
|
236 |
* the {@link #restaurarTexto()} method. |
|
237 |
* |
|
238 |
* @param texto |
|
239 |
* The text to set |
|
240 |
* @see #restaurarTexto() |
|
241 |
*/ |
|
242 |
public void setErrorTextTemporal(String texto) { |
|
243 |
if (!contenidoTemporal) { |
|
244 |
estadoAnterior = this.estado; |
|
245 |
textoAnterior = getStatusText(); |
|
246 |
contenidoTemporal = true; |
|
247 |
} |
|
272 | 248 |
|
273 |
/** |
|
274 |
* Sets a permanent info message in the status bar, and changes the |
|
275 |
* permanent icon to an Info icon. If there is a temporary message showing |
|
276 |
* at the moment, the message set now is not shown until |
|
277 |
* the {@link #restaurarTexto()} method is called. |
|
278 |
* |
|
279 |
* @param texto The permanent info message to set |
|
280 |
* @see #restaurarTexto() |
|
281 |
*/ |
|
282 |
public void setInfoText(String texto) { |
|
283 |
if (contenidoTemporal) { |
|
284 |
textoAnterior = texto; |
|
285 |
estadoAnterior = INFO; |
|
286 |
} else { |
|
287 |
lblTexto.setText(texto); |
|
288 |
lblIcon.setIcon(infoIcon); |
|
289 |
estado = INFO; |
|
290 |
} |
|
291 |
} |
|
249 |
this.estado = ERROR; |
|
250 |
lblIcon.setIcon(errorIcon); |
|
251 |
lblTexto.setText(texto); |
|
252 |
} |
|
292 | 253 |
|
293 |
/** |
|
294 |
* Sets a permanent warning message in the status bar, and changes the |
|
295 |
* permanent icon to a Warning icon. If there is a temporary message showing |
|
296 |
* at the moment, the message set now is not shown until |
|
297 |
* the {@link #restaurarTexto()} method is called. |
|
298 |
* |
|
299 |
* @param texto The permanent warning message to set |
|
300 |
* @see #restaurarTexto() |
|
301 |
*/ |
|
302 |
public void setWarningText(String texto) { |
|
303 |
if (contenidoTemporal) { |
|
304 |
textoAnterior = texto; |
|
305 |
estadoAnterior = WARNING; |
|
306 |
} else { |
|
307 |
lblTexto.setText(texto); |
|
308 |
lblIcon.setIcon(warningIcon); |
|
309 |
estado = WARNING; |
|
310 |
} |
|
311 |
} |
|
254 |
/** |
|
255 |
* Sets a permanent info message in the status bar, and changes the |
|
256 |
* permanent icon to an Info icon. If there is a temporary message showing |
|
257 |
* at the moment, the message set now is not shown until |
|
258 |
* the {@link #restaurarTexto()} method is called. |
|
259 |
* |
|
260 |
* @param texto |
|
261 |
* The permanent info message to set |
|
262 |
* @see #restaurarTexto() |
|
263 |
*/ |
|
264 |
public void setInfoText(String texto) { |
|
265 |
if (contenidoTemporal) { |
|
266 |
textoAnterior = texto; |
|
267 |
estadoAnterior = INFO; |
|
268 |
} else { |
|
269 |
lblTexto.setText(texto); |
|
270 |
lblIcon.setIcon(infoIcon); |
|
271 |
estado = INFO; |
|
272 |
} |
|
273 |
} |
|
312 | 274 |
|
313 |
/** |
|
314 |
* Sets a permanent error message in the status bar, and changes the |
|
315 |
* permanent icon to an Error icon. If there is a temporary message showing |
|
316 |
* at the moment, the message set now is not shown until |
|
317 |
* the {@link #restaurarTexto()} method is called. |
|
318 |
* |
|
319 |
* @param texto The permanent info message to set |
|
320 |
* @see #restaurarTexto() |
|
321 |
*/ |
|
322 |
public void setErrorText(String texto) { |
|
323 |
if (contenidoTemporal) { |
|
324 |
textoAnterior = texto; |
|
325 |
estadoAnterior = ERROR; |
|
326 |
} else { |
|
327 |
lblTexto.setText(texto); |
|
328 |
lblIcon.setIcon(errorIcon); |
|
329 |
estado = ERROR; |
|
330 |
} |
|
331 |
} |
|
275 |
/** |
|
276 |
* Sets a permanent warning message in the status bar, and changes the |
|
277 |
* permanent icon to a Warning icon. If there is a temporary message showing |
|
278 |
* at the moment, the message set now is not shown until |
|
279 |
* the {@link #restaurarTexto()} method is called. |
|
280 |
* |
|
281 |
* @param texto |
|
282 |
* The permanent warning message to set |
|
283 |
* @see #restaurarTexto() |
|
284 |
*/ |
|
285 |
public void setWarningText(String texto) { |
|
286 |
if (contenidoTemporal) { |
|
287 |
textoAnterior = texto; |
|
288 |
estadoAnterior = WARNING; |
|
289 |
} else { |
|
290 |
lblTexto.setText(texto); |
|
291 |
lblIcon.setIcon(warningIcon); |
|
292 |
estado = WARNING; |
|
293 |
} |
|
294 |
} |
|
332 | 295 |
|
333 |
/** |
|
334 |
* If <code>p</code> is a value between 0 and 99, it shows a progress bar |
|
335 |
* in the left area of the status bar, and sets the specified progress. |
|
336 |
* If <code>p</code> is bigger than 99, it hides the progress bar. |
|
337 |
* |
|
338 |
* @param p The progress to set in the progress bar. If it is bigger |
|
339 |
* than 99, the task will be considered to be finished, and the |
|
340 |
* progress bar will be hidden. |
|
341 |
* |
|
342 |
* @deprecated use instead TaskStatus and TaskStatusManager |
|
343 |
*/ |
|
344 |
public void setProgress(int p) { |
|
345 |
if (p < 100) { |
|
346 |
getProgressBar().setValue(p); |
|
347 |
getProgressBar().setVisible(true); |
|
348 |
} else { |
|
349 |
getProgressBar().setVisible(false); |
|
350 |
} |
|
296 |
/** |
|
297 |
* Sets a permanent error message in the status bar, and changes the |
|
298 |
* permanent icon to an Error icon. If there is a temporary message showing |
|
299 |
* at the moment, the message set now is not shown until |
|
300 |
* the {@link #restaurarTexto()} method is called. |
|
301 |
* |
|
302 |
* @param texto |
|
303 |
* The permanent info message to set |
|
304 |
* @see #restaurarTexto() |
|
305 |
*/ |
|
306 |
public void setErrorText(String texto) { |
|
307 |
if (contenidoTemporal) { |
|
308 |
textoAnterior = texto; |
|
309 |
estadoAnterior = ERROR; |
|
310 |
} else { |
|
311 |
lblTexto.setText(texto); |
|
312 |
lblIcon.setIcon(errorIcon); |
|
313 |
estado = ERROR; |
|
314 |
} |
|
315 |
} |
|
351 | 316 |
|
352 |
getProgressBar().repaint(); |
|
353 |
} |
|
317 |
/** |
|
318 |
* If <code>p</code> is a value between 0 and 99, it shows a progress bar |
|
319 |
* in the left area of the status bar, and sets the specified progress. |
|
320 |
* If <code>p</code> is bigger than 99, it hides the progress bar. |
|
321 |
* |
|
322 |
* @param p |
|
323 |
* The progress to set in the progress bar. If it is bigger |
|
324 |
* than 99, the task will be considered to be finished, and the |
|
325 |
* progress bar will be hidden. |
|
326 |
* |
|
327 |
* @deprecated use instead TaskStatus and TaskStatusManager |
|
328 |
*/ |
|
329 |
public void setProgress(int p) { |
|
330 |
if (p < 100) { |
|
331 |
getProgressBar().setValue(p); |
|
332 |
getProgressBar().setVisible(true); |
|
333 |
} else { |
|
334 |
getProgressBar().setVisible(false); |
|
335 |
} |
|
354 | 336 |
|
355 |
/** |
|
356 |
* Sets a label-set to be shown in the status bar. This method it is not |
|
357 |
* intended to be used directly, because the set will be overwritten when the selected |
|
358 |
* window changes. Use {@link MainFrame#setStatusBarLabels(Class, Label[])} |
|
359 |
* to permanently associate a label set with a window. |
|
360 |
* |
|
361 |
* @param labels The labels to set. |
|
362 |
* @see MainFrame#setStatusBarLabels(Class, Label[]) |
|
363 |
*/ |
|
364 |
public void setLabelSet(Label[] labels) { |
|
365 |
removeAllLabels(); |
|
366 |
idLabel.clear(); |
|
337 |
getProgressBar().repaint(); |
|
338 |
} |
|
367 | 339 |
|
368 |
for (int i = 0; i < labels.length; i++) { |
|
369 |
JLabel lbl = new JLabel(); |
|
370 |
lbl.setPreferredSize(new Dimension(labels[i].getSize(), |
|
371 |
this.getHeight() - 2)); |
|
372 |
lbl.setSize(new Dimension(labels[i].getSize(), this.getHeight() - 2)); |
|
373 |
lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
|
374 |
lbl.setName(labels[i].getId()); |
|
375 |
controlContainer.add(lbl); |
|
340 |
/** |
|
341 |
* Sets a label-set to be shown in the status bar. This method it is not |
|
342 |
* intended to be used directly, because the set will be overwritten when |
|
343 |
* the selected |
|
344 |
* window changes. Use {@link MainFrame#setStatusBarLabels(Class, Label[])} |
|
345 |
* to permanently associate a label set with a window. |
|
346 |
* |
|
347 |
* @param labels |
|
348 |
* The labels to set. |
|
349 |
* @see MainFrame#setStatusBarLabels(Class, Label[]) |
|
350 |
*/ |
|
351 |
public void setLabelSet(Label[] labels) { |
|
352 |
removeAllLabels(); |
|
353 |
idLabel.clear(); |
|
376 | 354 |
|
377 |
/* if (i != labels.length - 1){ |
|
378 |
this.add(new JSeparator(JSeparator.VERTICAL)); |
|
379 |
} |
|
380 |
*/ |
|
381 |
idLabel.put(labels[i].getId(), lbl); |
|
382 |
} |
|
355 |
for (int i = 0; i < labels.length; i++) { |
|
356 |
JLabel lbl = new JLabel(); |
|
357 |
lbl.setPreferredSize(new Dimension(labels[i].getSize(), this |
|
358 |
.getHeight() - 2)); |
|
359 |
lbl.setSize(new Dimension(labels[i].getSize(), this.getHeight() - 2)); |
|
360 |
lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); |
|
361 |
lbl.setName(labels[i].getId()); |
|
362 |
controlContainer.add(lbl); |
|
383 | 363 |
|
384 |
JLabel[] configlabels = (JLabel[]) idLabel.values().toArray(new JLabel[0]); |
|
385 |
widthlabels = new int[configlabels.length]; |
|
364 |
/* |
|
365 |
* if (i != labels.length - 1){ |
|
366 |
* this.add(new JSeparator(JSeparator.VERTICAL)); |
|
367 |
* } |
|
368 |
*/ |
|
369 |
idLabel.put(labels[i].getId(), lbl); |
|
370 |
} |
|
386 | 371 |
|
387 |
for (int i = 0; i < labels.length; i++) {
|
|
388 |
widthlabels[i] = configlabels[i].getWidth();
|
|
389 |
}
|
|
372 |
JLabel[] configlabels =
|
|
373 |
(JLabel[]) idLabel.values().toArray(new JLabel[0]);
|
|
374 |
widthlabels = new int[configlabels.length];
|
|
390 | 375 |
|
391 |
this.repaint(); |
|
392 |
} |
|
376 |
for (int i = 0; i < labels.length; i++) { |
|
377 |
widthlabels[i] = configlabels[i].getWidth(); |
|
378 |
} |
|
393 | 379 |
|
394 |
/** |
|
395 |
* Hides the empty labels and adjust the space in the bar. |
|
396 |
*/ |
|
397 |
public void ajustar() { |
|
398 |
if (widthlabels == null) { |
|
399 |
return; |
|
400 |
} |
|
380 |
this.repaint(); |
|
381 |
} |
|
401 | 382 |
|
402 |
int ws = this.getWidth(); |
|
383 |
/** |
|
384 |
* Hides the empty labels and adjust the space in the bar. |
|
385 |
*/ |
|
386 |
public void ajustar() { |
|
387 |
if (widthlabels == null) { |
|
388 |
return; |
|
389 |
} |
|
403 | 390 |
|
404 |
JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
|
|
391 |
int ws = this.getWidth();
|
|
405 | 392 |
|
406 |
/* double total = 1; |
|
407 |
for (int i = 0; i < widthlabels.length; i++) { |
|
408 |
if (labels[i].getText().compareTo("") != 0) { |
|
409 |
total += widthlabels[i]; |
|
410 |
} |
|
411 |
} |
|
412 |
double p = (ws - lblTexto.getWidth() - 20) / total; |
|
413 |
*/ |
|
414 |
for (int i = 0; i < labels.length; i++) { |
|
415 |
//if (labels[i] instanceof JLabel){ |
|
416 |
JLabel label = (JLabel) labels[i]; |
|
393 |
JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]); |
|
417 | 394 |
|
418 |
if (label.getText().compareTo("") != 0) { |
|
419 |
label.setVisible(true); |
|
420 |
label.setPreferredSize(new Dimension((int) (widthlabels[i]), |
|
421 |
this.getHeight() - 2)); |
|
422 |
} else { |
|
423 |
label.setVisible(false); |
|
395 |
/* |
|
396 |
* double total = 1; |
|
397 |
* for (int i = 0; i < widthlabels.length; i++) { |
|
398 |
* if (labels[i].getText().compareTo("") != 0) { |
|
399 |
* total += widthlabels[i]; |
|
400 |
* } |
|
401 |
* } |
|
402 |
* double p = (ws - lblTexto.getWidth() - 20) / total; |
|
403 |
*/ |
|
404 |
for (int i = 0; i < labels.length; i++) { |
|
405 |
// if (labels[i] instanceof JLabel){ |
|
406 |
JLabel label = (JLabel) labels[i]; |
|
424 | 407 |
|
425 |
//label.setPreferredSize(new Dimension(0,this.getHeight())); |
|
426 |
} |
|
408 |
if (label.getText().compareTo("") != 0) { |
|
409 |
label.setVisible(true); |
|
410 |
label.setPreferredSize(new Dimension((int) (widthlabels[i]), |
|
411 |
this.getHeight() - 2)); |
|
412 |
} else { |
|
413 |
label.setVisible(false); |
|
427 | 414 |
|
428 |
//} |
|
429 |
} |
|
430 |
} |
|
415 |
// label.setPreferredSize(new Dimension(0,this.getHeight())); |
|
416 |
} |
|
431 | 417 |
|
432 |
/** |
|
433 |
* Removes all the labels from the status bar. It does not remove the |
|
434 |
* controls. |
|
435 |
*/ |
|
436 |
private void removeAllLabels() { |
|
437 |
Component[] controlArray = controlContainer.getComponents(); |
|
418 |
// } |
|
419 |
} |
|
420 |
} |
|
438 | 421 |
|
439 |
for (int i = 0; i < controlArray.length; i++) {
|
|
440 |
if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto) && !(controlArray[i] instanceof IControl) && (controlArray[i] instanceof JLabel)) {
|
|
441 |
controlContainer.remove(controlArray[i]);
|
|
442 |
}
|
|
443 |
}
|
|
444 |
}
|
|
422 |
/**
|
|
423 |
* Removes all the labels from the status bar. It does not remove the
|
|
424 |
* controls.
|
|
425 |
*/
|
|
426 |
private void removeAllLabels() {
|
|
427 |
Component[] controlArray = controlContainer.getComponents();
|
|
445 | 428 |
|
429 |
for (int i = 0; i < controlArray.length; i++) { |
|
430 |
if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto) |
|
431 |
&& !(controlArray[i] instanceof IControl) |
|
432 |
&& (controlArray[i] instanceof JLabel)) { |
|
433 |
controlContainer.remove(controlArray[i]); |
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
446 | 437 |
|
447 |
/**
|
|
448 |
* Removes all the controls (including labels) from the status bar.
|
|
449 |
*/
|
|
450 |
private void removeAllControls() {
|
|
451 |
Component[] controlArray = controlContainer.getComponents();
|
|
438 |
/**
|
|
439 |
* Removes all the controls (including labels) from the status bar.
|
|
440 |
*/
|
|
441 |
private void removeAllControls() {
|
|
442 |
Component[] controlArray = controlContainer.getComponents();
|
|
452 | 443 |
|
453 |
for (int i = 0; i < controlArray.length; i++) {
|
|
454 |
if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)) {
|
|
455 |
controlContainer.remove(controlArray[i]);
|
|
456 |
}
|
|
457 |
}
|
|
458 |
}
|
|
444 |
for (int i = 0; i < controlArray.length; i++) {
|
|
445 |
if ((controlArray[i] != lblIcon) && (controlArray[i] != lblTexto)) {
|
|
446 |
controlContainer.remove(controlArray[i]);
|
|
447 |
}
|
|
448 |
}
|
|
449 |
}
|
|
459 | 450 |
|
460 |
/** |
|
461 |
* Sets the text of the provided label. |
|
462 |
* |
|
463 |
* @param id The ID of the label to modify. It is defined in the |
|
464 |
* config.xml file |
|
465 |
* @param msg The message to show in the label |
|
466 |
*/ |
|
467 |
public void setMessage(String id, String msg) { |
|
468 |
JLabel lbl = (JLabel) idLabel.get(id); |
|
469 |
|
|
470 |
if (lbl!=null) { |
|
471 |
lbl.setText(msg); |
|
472 |
} |
|
473 |
else { |
|
474 |
// try with controls |
|
475 |
try { |
|
476 |
IControl control = (IControl) controls.get(id); |
|
477 |
if (control!=null) |
|
478 |
control.setValue(msg); |
|
479 |
} |
|
480 |
catch (ClassCastException ex) { |
|
481 |
logger.debug("no label called " + id); |
|
482 |
} |
|
483 |
} |
|
451 |
/** |
|
452 |
* Sets the text of the provided label. |
|
453 |
* |
|
454 |
* @param id |
|
455 |
* The ID of the label to modify. It is defined in the |
|
456 |
* config.xml file |
|
457 |
* @param msg |
|
458 |
* The message to show in the label |
|
459 |
*/ |
|
460 |
public void setMessage(String id, String msg) { |
|
461 |
JLabel lbl = (JLabel) idLabel.get(id); |
|
484 | 462 |
|
485 |
ajustar(); |
|
486 |
} |
|
463 |
if (lbl != null) { |
|
464 |
lbl.setText(msg); |
|
465 |
} else { |
|
466 |
// try with controls |
|
467 |
try { |
|
468 |
IControl control = (IControl) controls.get(id); |
|
469 |
if (control != null) |
|
470 |
control.setValue(msg); |
|
471 |
} catch (ClassCastException ex) { |
|
472 |
LOG.debug("no label called " + id); |
|
473 |
} |
|
474 |
} |
|
487 | 475 |
|
488 |
/** |
|
489 |
* Sets the control identified by 'id' with the provided value. |
|
490 |
* |
|
491 |
* @param id The ID of the control to modify |
|
492 |
* @param value The value to set in the control |
|
493 |
*/ |
|
494 |
public void setControlValue(String id, String value) { |
|
495 |
IControl control = (IControl) controls.get(id); |
|
496 |
if (control!=null) { |
|
497 |
control.setValue(value); |
|
498 |
} |
|
499 |
else { |
|
500 |
logger.debug("NewStatusBar -- no control called " + id); |
|
501 |
} |
|
502 |
} |
|
476 |
ajustar(); |
|
477 |
} |
|
503 | 478 |
|
504 |
/** |
|
505 |
* This method initializes the progressBar and gets it. |
|
506 |
* |
|
507 |
* @return javax.swing.JProgressBar |
|
508 |
*/ |
|
509 |
private JProgressBar getProgressBar() { |
|
510 |
if (progressBar == null) { |
|
511 |
progressBar = new JProgressBar(); |
|
512 |
progressBar.setPreferredSize(new java.awt.Dimension(100, 14)); |
|
513 |
progressBar.setVisible(false); |
|
514 |
progressBar.setMinimum(0); |
|
515 |
progressBar.setMaximum(100); |
|
516 |
progressBar.setValue(50); |
|
517 |
} |
|
479 |
/** |
|
480 |
* Sets the control identified by 'id' with the provided value. |
|
481 |
* |
|
482 |
* @param id |
|
483 |
* The ID of the control to modify |
|
484 |
* @param value |
|
485 |
* The value to set in the control |
|
486 |
*/ |
|
487 |
public void setControlValue(String id, String value) { |
|
488 |
IControl control = (IControl) controls.get(id); |
|
489 |
if (control != null) { |
|
490 |
control.setValue(value); |
|
491 |
} else { |
|
492 |
LOG.debug("NewStatusBar -- no control called " + id); |
|
493 |
} |
|
494 |
} |
|
518 | 495 |
|
519 |
return progressBar; |
|
520 |
} |
|
496 |
/** |
|
497 |
* This method initializes the progressBar and gets it. |
|
498 |
* |
|
499 |
* @return javax.swing.JProgressBar |
|
500 |
*/ |
|
501 |
private JProgressBar getProgressBar() { |
|
502 |
if (progressBar == null) { |
|
503 |
progressBar = new JProgressBar(); |
|
504 |
progressBar.setPreferredSize(new java.awt.Dimension(100, 14)); |
|
505 |
progressBar.setVisible(false); |
|
506 |
progressBar.setMinimum(0); |
|
507 |
progressBar.setMaximum(100); |
|
508 |
progressBar.setValue(50); |
|
509 |
} |
|
510 |
|
|
511 |
return progressBar; |
|
512 |
} |
|
513 |
|
|
521 | 514 |
private JTasksStatus getTasksStatus() { |
522 | 515 |
if (tasksStatus == null) { |
523 |
tasksStatus = ToolsSwingLocator.getTaskStatusSwingManager().createJTasksStatus(); |
|
516 |
tasksStatus = |
|
517 |
ToolsSwingLocator.getTaskStatusSwingManager() |
|
518 |
.createJTasksStatus(); |
|
524 | 519 |
tasksStatus.setVisible(true); |
525 | 520 |
} |
526 | 521 |
return tasksStatus; |
527 | 522 |
} |
528 | 523 |
|
529 |
/** |
|
530 |
* Sets the width of the main message label. |
|
531 |
* |
|
532 |
* @param d The width ob the main label |
|
533 |
* @deprecated |
|
534 |
*/ |
|
535 |
public void setFixedLabelWidth(double d) { |
|
536 |
lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight())); |
|
537 |
} |
|
524 |
/** |
|
525 |
* Sets the width of the main message label. |
|
526 |
* |
|
527 |
* @param d |
|
528 |
* The width ob the main label |
|
529 |
* @deprecated |
|
530 |
*/ |
|
531 |
public void setFixedLabelWidth(double d) { |
|
532 |
lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight())); |
|
533 |
} |
|
538 | 534 |
|
539 |
/** |
|
540 |
* Adds a control to the status bar |
|
541 |
* |
|
542 |
* @param id The ID of the control, useful to later retrive it or set its value |
|
543 |
* @param control The control to add |
|
544 |
*/ |
|
545 |
public void addControl(String id, Component control) { |
|
546 |
if (!controls.containsKey(control.getName())) { |
|
547 |
controls.put(control.getName(), control); |
|
548 |
controlContainer.add(control); |
|
549 |
} |
|
550 |
else { |
|
551 |
logger.debug("NewStatusBar.addControl -- control 'id' already exists"+ id); |
|
552 |
} |
|
553 |
} |
|
535 |
/** |
|
536 |
* Adds a control to the status bar |
|
537 |
* |
|
538 |
* @param id |
|
539 |
* The ID of the control, useful to later retrive it or set its |
|
540 |
* value |
|
541 |
* @param control |
|
542 |
* The control to add |
|
543 |
*/ |
|
544 |
public void addControl(String id, Component control) { |
|
545 |
if (!controls.containsKey(control.getName())) { |
|
546 |
controls.put(control.getName(), control); |
|
547 |
controlContainer.add(control); |
|
548 |
} else { |
|
549 |
LOG |
|
550 |
.debug("NewStatusBar.addControl -- control 'id' already exists" |
|
551 |
+ id); |
|
552 |
} |
|
553 |
} |
|
554 | 554 |
|
555 |
/** |
|
556 |
* Remove a control from the status bar |
|
557 |
* |
|
558 |
* @param id The ID of the control to get |
|
559 |
*/ |
|
560 |
public Component removeControl(String id) { |
|
561 |
try { |
|
562 |
Component component = (Component) controls.get(id); |
|
563 |
controlContainer.remove(component); |
|
564 |
controls.remove(id); |
|
565 |
return component; |
|
566 |
} |
|
567 |
catch (ClassCastException ex) { |
|
568 |
logger.debug("NewStatusBar.removeControl -- control "+id+"doesn't exist"); |
|
569 |
} |
|
570 |
return null; |
|
571 |
} |
|
572 |
|
|
573 |
/** |
|
574 |
* Gets a control from the status bar |
|
575 |
* |
|
576 |
* @param id The ID of the control to get |
|
577 |
*/ |
|
578 |
public Component getControl(String id) { |
|
579 |
return (Component) controls.get(id); |
|
580 |
} |
|
581 |
} // @jve:decl-index=0:visual-constraint="10,10" |
|
555 |
/** |
|
556 |
* Remove a control from the status bar |
|
557 |
* |
|
558 |
* @param id |
|
559 |
* The ID of the control to get |
|
560 |
*/ |
|
561 |
public Component removeControl(String id) { |
|
562 |
try { |
|
563 |
Component component = (Component) controls.get(id); |
|
564 |
controlContainer.remove(component); |
|
565 |
controls.remove(id); |
|
566 |
return component; |
|
567 |
} catch (ClassCastException ex) { |
|
568 |
LOG.debug("NewStatusBar.removeControl -- control " + id |
|
569 |
+ "doesn't exist"); |
|
570 |
} |
|
571 |
return null; |
|
572 |
} |
|
573 |
|
|
574 |
/** |
|
575 |
* Gets a control from the status bar |
|
576 |
* |
|
577 |
* @param id |
|
578 |
* The ID of the control to get |
|
579 |
*/ |
|
580 |
public Component getControl(String id) { |
|
581 |
return (Component) controls.get(id); |
|
582 |
} |
|
583 |
} // @jve:decl-index=0:visual-constraint="10,10" |
Also available in: Unified diff