Statistics
| Revision:

svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiFrame / NewStatusBar.java @ 2938

History | View | Annotate | Download (9.64 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 com.iver.andami.Launcher;
44
import com.iver.andami.messages.Messages;
45
import com.iver.andami.plugins.config.generate.Label;
46

    
47
import org.apache.log4j.Logger;
48

    
49
import java.awt.Color;
50
import java.awt.Component;
51
import java.awt.Dimension;
52
import java.awt.FlowLayout;
53

    
54
import java.util.HashMap;
55

    
56
import javax.swing.BorderFactory;
57
import javax.swing.ImageIcon;
58
import javax.swing.JLabel;
59
import javax.swing.JPanel;
60
import javax.swing.JProgressBar;
61
import javax.swing.JSeparator;
62
import javax.swing.border.BevelBorder;
63
import javax.swing.border.Border;
64

    
65

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

    
86
        /**
87
         * This is the default constructor
88
         */
89
        public NewStatusBar() {
90
                super();
91
                initialize();
92
                infoIcon = new ImageIcon(NewStatusBar.class.getClassLoader()
93
                                                                                                   .getResource("images/info.gif"));
94
                warningIcon = new ImageIcon(NewStatusBar.class.getClassLoader()
95
                                                                                                          .getResource("images/warning.gif"));
96
                errorIcon = new ImageIcon(NewStatusBar.class.getClassLoader()
97
                                                                                                        .getResource("images/error.gif"));
98
        }
99

    
100
        /**
101
         * This method initializes this
102
         */
103
        private void initialize() {
104
                lblIcon = new JLabel();
105
                lblTexto = new JLabel();
106

    
107
                FlowLayout flowLayout2 = new FlowLayout();
108
                this.setLayout(flowLayout2);
109
                flowLayout2.setHgap(1);
110
                flowLayout2.setVgap(0);
111
                flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
112
                lblIcon.setText("");
113
                lblTexto.setText(Messages.getString("StatusBar.Aplicacion_iniciada"));
114
                this.add(lblIcon, null);
115
                this.add(getProgressBar(), null);
116
                this.add(lblTexto, null);
117
        }
118

    
119
        /**
120
         * Obtiene el texto de la barra de estado
121
         *
122
         * @return texto
123
         */
124
        public String getStatusText() {
125
                return lblTexto.getText();
126
        }
127

    
128
        /**
129
         * Restaura el contenido permanente de la barra de estado
130
         */
131
        public void restaurarTexto() {
132
                contenidoTemporal = false;
133

    
134
                if (estadoAnterior == -1) {
135
                        return;
136
                }
137

    
138
                switch (estadoAnterior) {
139
                        case INFO:
140
                                setInfoText(textoAnterior);
141

    
142
                                break;
143

    
144
                        case WARNING:
145
                                setWarningText(textoAnterior);
146

    
147
                                break;
148

    
149
                        case ERROR:
150
                                setErrorText(textoAnterior);
151

    
152
                                break;
153
                }
154

    
155
                estadoAnterior = -1;
156
                textoAnterior = null;
157
        }
158

    
159
        /**
160
         * Establece el texto de la barra de estado de forma temporal. Se almacena
161
         * el texto que hab?a en la barra de estado.
162
         *
163
         * @param texto texto
164
         */
165
        public void setInfoTextTemporal(String texto) {
166
                contenidoTemporal = true;
167

    
168
                estadoAnterior = this.estado;
169
                this.estado = INFO;
170
                lblIcon.setIcon(infoIcon);
171

    
172
                textoAnterior = getStatusText();
173
                lblTexto.setText(texto);
174
        }
175

    
176
        /**
177
         * Establece el texto de la barra de estado de forma temporal. Se almacena
178
         * el texto que hab?a en la barra de estado.
179
         *
180
         * @param texto texto
181
         */
182
        public void setWarningTextTemporal(String texto) {
183
                contenidoTemporal = true;
184

    
185
                estadoAnterior = this.estado;
186
                this.estado = WARNING;
187
                lblIcon.setIcon(warningIcon);
188

    
189
                textoAnterior = getStatusText();
190
                lblTexto.setText(texto);
191
        }
192

    
193
        /**
194
         * Establece el texto de la barra de estado de forma temporal. Se almacena
195
         * el texto que hab?a en la barra de estado.
196
         *
197
         * @param texto texto
198
         */
199
        public void setErrorTextTemporal(String texto) {
200
                contenidoTemporal = true;
201

    
202
                estadoAnterior = this.estado;
203
                this.estado = ERROR;
204
                lblIcon.setIcon(errorIcon);
205

    
206
                textoAnterior = getStatusText();
207
                lblTexto.setText(texto);
208
        }
209

    
210
        /**
211
         * Establece el texto de la barar de manera permanente. Si se est?
212
         * mostrando texto de forma temporal no se actualiza la interfaz
213
         *
214
         * @param texto Texto
215
         */
216
        public void setInfoText(String texto) {
217
                if (contenidoTemporal) {
218
                        textoAnterior = texto;
219
                        estadoAnterior = INFO;
220
                } else {
221
                        lblTexto.setText(texto);
222
                        lblIcon.setIcon(infoIcon);
223
                        estado = INFO;
224
                }
225
        }
226

    
227
        /**
228
         * Establece el texto de la barar de manera permanente. Si se est?
229
         * mostrando texto de forma temporal no se actualiza la interfaz
230
         *
231
         * @param texto Texto
232
         */
233
        public void setWarningText(String texto) {
234
                if (contenidoTemporal) {
235
                        textoAnterior = texto;
236
                        estadoAnterior = WARNING;
237
                } else {
238
                        lblTexto.setText(texto);
239
                        lblIcon.setIcon(warningIcon);
240
                        estado = WARNING;
241
                }
242
        }
243

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

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

    
275
                getProgressBar().repaint();
276
        }
277

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

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

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

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

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

    
309
                this.repaint();
310
        }
311

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

    
323
                int ws = this.getWidth();
324

    
325
                JLabel[] labels = (JLabel[]) idLabel.values().toArray(new JLabel[0]);
326

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

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

    
346
                                //label.setPreferredSize(new Dimension(0,this.getHeight()));
347
                        }
348

    
349
                        //}
350
                }
351
        }
352

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

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

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

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

    
381
                ajustar();
382
        }
383

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

    
399
                return progressBar;
400
        }
401

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