Statistics
| Revision:

root / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / NewStatusBar.java @ 2884

History | View | Annotate | Download (9.59 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * 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
40
 */
41
package com.iver.andami.ui.mdiFrame;
42

    
43
import java.awt.Component;
44
import java.awt.Dimension;
45
import java.awt.FlowLayout;
46
import java.util.HashMap;
47

    
48
import javax.swing.BorderFactory;
49
import javax.swing.ImageIcon;
50
import javax.swing.JLabel;
51
import javax.swing.JPanel;
52
import javax.swing.JProgressBar;
53
import javax.swing.border.BevelBorder;
54

    
55
import org.apache.log4j.Logger;
56

    
57
import com.iver.andami.plugins.config.generate.Label;
58

    
59

    
60
/**
61
 */
62
public class NewStatusBar extends JPanel {
63
        private static Logger logger = Logger.getLogger(NewStatusBar.class.getName());
64
        private static final int INFO = 0;
65
        private static final int WARNING = 1;
66
        private static final int ERROR = 2;
67
        private JLabel lblIcon = null;
68
        private JLabel lblTexto = null;
69
        private boolean contenidoTemporal;
70
        private String textoAnterior;
71
        private int estadoAnterior;
72
        private ImageIcon infoIcon;
73
        private ImageIcon warningIcon;
74
        private ImageIcon errorIcon;
75
        private int estado;
76
        private JProgressBar progressBar = null;
77
        private HashMap idLabel = new HashMap();
78
        private int[] widthlabels = null;
79

    
80
        /**
81
         * This is the default constructor
82
         */
83
        public NewStatusBar() {
84
                super();
85
                initialize();
86
                infoIcon = new ImageIcon(NewStatusBar.class.getClassLoader()
87
                                                                                                   .getResource("images/info.gif"));
88
                warningIcon = new ImageIcon(NewStatusBar.class.getClassLoader()
89
                                                                                                          .getResource("images/warning.gif"));
90
                errorIcon = new ImageIcon(NewStatusBar.class.getClassLoader()
91
                                                                                                        .getResource("images/error.gif"));
92
        }
93

    
94
        /**
95
         * This method initializes this
96
         */
97
        private void initialize() {
98
                init();
99
                lblIcon = new JLabel();
100
                lblTexto = new JLabel();
101

    
102
                FlowLayout flowLayout2 = new FlowLayout();
103
                this.setLayout(flowLayout2);
104
                flowLayout2.setHgap(1);
105
                flowLayout2.setVgap(0);
106
                flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
107
                lblIcon.setText("");
108
                //lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada"));
109
                this.add(lblIcon, null);
110
                this.add(getProgressBar(), null);
111
                this.add(lblTexto, null);
112
        }
113

    
114
        /**
115
         * Obtiene el texto de la barra de estado
116
         *
117
         * @return texto
118
         */
119
        public String getStatusText() {
120
                return lblTexto.getText();
121
        }
122

    
123
        /**
124
         * Restaura el contenido permanente de la barra de estado
125
         */
126
        public void restaurarTexto() {
127
                contenidoTemporal = false;
128

    
129
                if (estadoAnterior == -1) {
130
                        return;
131
                }
132

    
133
                switch (estadoAnterior) {
134
                        case INFO:
135
                                setInfoText(textoAnterior);
136

    
137
                                break;
138

    
139
                        case WARNING:
140
                                setWarningText(textoAnterior);
141

    
142
                                break;
143

    
144
                        case ERROR:
145
                                setErrorText(textoAnterior);
146

    
147
                                break;
148
                }
149

    
150
                estadoAnterior = -1;
151
                textoAnterior = null;
152
        }
153

    
154
        /**
155
         * Establece el texto de la barra de estado de forma temporal. Se almacena
156
         * el texto que hab?a en la barra de estado.
157
         *
158
         * @param texto texto
159
         */
160
        public void setInfoTextTemporal(String texto) {
161
                contenidoTemporal = true;
162

    
163
                estadoAnterior = this.estado;
164
                this.estado = INFO;
165
                lblIcon.setIcon(infoIcon);
166

    
167
                textoAnterior = getStatusText();
168
                lblTexto.setText(texto);
169
        }
170

    
171
        /**
172
         * Establece el texto de la barra de estado de forma temporal. Se almacena
173
         * el texto que hab?a en la barra de estado.
174
         *
175
         * @param texto texto
176
         */
177
        public void setWarningTextTemporal(String texto) {
178
                contenidoTemporal = true;
179

    
180
                estadoAnterior = this.estado;
181
                this.estado = WARNING;
182
                lblIcon.setIcon(warningIcon);
183

    
184
                textoAnterior = getStatusText();
185
                lblTexto.setText(texto);
186
        }
187

    
188
        /**
189
         * Establece el texto de la barra de estado de forma temporal. Se almacena
190
         * el texto que hab?a en la barra de estado.
191
         *
192
         * @param texto texto
193
         */
194
        public void setErrorTextTemporal(String texto) {
195
                contenidoTemporal = true;
196

    
197
                estadoAnterior = this.estado;
198
                this.estado = ERROR;
199
                lblIcon.setIcon(errorIcon);
200

    
201
                textoAnterior = getStatusText();
202
                lblTexto.setText(texto);
203
        }
204

    
205
        /**
206
         * Establece el texto de la barar de manera permanente. Si se est?
207
         * mostrando texto de forma temporal no se actualiza la interfaz
208
         *
209
         * @param texto Texto
210
         */
211
        public void setInfoText(String texto) {
212
                if (contenidoTemporal) {
213
                        textoAnterior = texto;
214
                        estadoAnterior = INFO;
215
                } else {
216
                        lblTexto.setText(texto);
217
                        lblIcon.setIcon(infoIcon);
218
                        estado = INFO;
219
                }
220
        }
221
        public void init(){
222
                //lblIcon.setIcon(null);
223
                this.setPreferredSize(new Dimension(0,20));
224
        }
225
        /**
226
         * Establece el texto de la barar de manera permanente. Si se est?
227
         * mostrando texto de forma temporal no se actualiza la interfaz
228
         *
229
         * @param texto Texto
230
         */
231
        public void setWarningText(String texto) {
232
                if (contenidoTemporal) {
233
                        textoAnterior = texto;
234
                        estadoAnterior = WARNING;
235
                } else {
236
                        lblTexto.setText(texto);
237
                        lblIcon.setIcon(warningIcon);
238
                        estado = WARNING;
239
                }
240
        }
241

    
242
        /**
243
         * Establece el texto de la barar de manera permanente. Si se est?
244
         * mostrando texto de forma temporal no se actualiza la interfaz
245
         *
246
         * @param texto Texto
247
         */
248
        public void setErrorText(String texto) {
249
                if (contenidoTemporal) {
250
                        textoAnterior = texto;
251
                        estadoAnterior = ERROR;
252
                } else {
253
                        lblTexto.setText(texto);
254
                        lblIcon.setIcon(errorIcon);
255
                        estado = ERROR;
256
                }
257
        }
258

    
259
        /**
260
         * Establece el porcentaje en la barra de progreso. Si es 100 se oculta la
261
         * barra
262
         *
263
         * @param p DOCUMENT ME!
264
         */
265
        public void setProgress(int p) {
266
                if (p < 100) {
267
                        getProgressBar().setValue(p);
268
                        getProgressBar().setVisible(true);
269
                } else {
270
                        getProgressBar().setVisible(false);
271
                }
272

    
273
                getProgressBar().repaint();
274
        }
275

    
276
        /**
277
         * DOCUMENT ME!
278
         *
279
         * @param labels DOCUMENT ME!
280
         */
281
        public void setLabelSet(Label[] labels) {
282
                removeAllLabels();
283
                idLabel.clear();
284

    
285
                for (int i = 0; i < labels.length; i++) {
286
                        JLabel lbl = new JLabel();
287
                        lbl.setPreferredSize(new Dimension(labels[i].getSize(),
288
                                        this.getHeight()));
289
                        lbl.setSize(new Dimension(labels[i].getSize(), this.getHeight()));
290
                        lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
291
                        this.add(lbl);
292

    
293
                        /*            if (i != labels.length - 1){
294
                           this.add(new JSeparator(JSeparator.VERTICAL));
295
                           }
296
                         */
297
                        idLabel.put(labels[i].getId(), lbl);
298
                }
299

    
300
                JLabel[] configlabels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
301
                widthlabels = new int[configlabels.length];
302

    
303
                for (int i = 0; i < labels.length; i++) {
304
                        widthlabels[i] = configlabels[i].getWidth();
305
                }
306

    
307
                this.repaint();
308
        }
309

    
310
        /**
311
         * Los Labels que estan sin texto no se a?aden a la barra y su espacio es
312
         * utilizado por otros labels. Si se quiere acer en un futuro la
313
         * asignaci?n de espacio de los elementos que se a?adan a la barra se
314
         * puede hacer aqu?.
315
         */
316
        public void ajustar() {
317
                if (widthlabels == null) {
318
                        return;
319
                }
320

    
321
                int ws = this.getWidth();
322

    
323
                JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
324

    
325
                /*        double total = 1;
326
                   for (int i = 0; i < widthlabels.length; i++) {
327
                           if (labels[i].getText().compareTo("") != 0) {
328
                                   total += widthlabels[i];
329
                           }
330
                   }
331
                   double p = (ws - lblTexto.getWidth() - 20) / total;
332
                 */
333
                for (int i = 0; i < labels.length; i++) {
334
                        //if (labels[i] instanceof JLabel){
335
                        JLabel label = (JLabel) labels[i];
336

    
337
                        if (label.getText().compareTo("") != 0) {
338
                                label.setVisible(true);
339
                                label.setPreferredSize(new Dimension((int) (widthlabels[i]),
340
                                                this.getHeight()));
341
                        } else {
342
                                label.setVisible(false);
343

    
344
                                //label.setPreferredSize(new Dimension(0,this.getHeight()));
345
                        }
346

    
347
                        //}
348
                }
349
        }
350

    
351
        /**
352
         *
353
         */
354
        private void removeAllLabels() {
355
                Component[] labels = this.getComponents();
356

    
357
                for (int i = 0; i < labels.length; i++) {
358
                        if ((labels[i] != lblIcon) && (labels[i] != lblTexto)) {
359
                                remove(labels[i]);
360
                        }
361
                }
362
        }
363

    
364
        /**
365
         * Establece el texto de una de las etiquetas
366
         *
367
         * @param id Identificador de las etiquetas
368
         * @param msg Mensaje que se quiere poner en la etiqueta
369
         */
370
        public void setMessage(String id, String msg) {
371
                JLabel lbl = (JLabel) idLabel.get(id);
372

    
373
                if (lbl == null) {
374
                        logger.debug("no label called " + id);
375
                } else {
376
                        lbl.setText(msg);
377
                }
378

    
379
                ajustar();
380
        }
381

    
382
        /**
383
         * This method initializes progressBar
384
         *
385
         * @return javax.swing.JProgressBar
386
         */
387
        private JProgressBar getProgressBar() {
388
                if (progressBar == null) {
389
                        progressBar = new JProgressBar();
390
                        progressBar.setPreferredSize(new java.awt.Dimension(100, 14));
391
                        progressBar.setVisible(false);
392
                        progressBar.setMinimum(0);
393
                        progressBar.setMaximum(100);
394
                        progressBar.setValue(50);
395
                }
396

    
397
                return progressBar;
398
        }
399

    
400
        /**
401
         * DOCUMENT ME!
402
         *
403
         * @param d
404
         */
405
        public void setFixedLabelWidth(double d) {
406
                lblTexto.setPreferredSize(new Dimension((int) d, lblTexto.getHeight()));
407
        }
408
} //  @jve:decl-index=0:visual-constraint="10,10"