Revision 663

View differences:

trunk/frameworks/_fwAndami/src/com/iver/andami/ui/mdiFrame/StatusBar.java
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
}
trunk/frameworks/_fwAndami/src/com/iver/andami/ui/mdiFrame/NewStatusBar.java
5 5
import org.apache.log4j.Logger;
6 6

  
7 7
import java.awt.Color;
8
import java.awt.Component;
8 9
import java.awt.Dimension;
9 10
import java.awt.FlowLayout;
10 11

  
......
16 17
import javax.swing.JPanel;
17 18
import javax.swing.JProgressBar;
18 19
import javax.swing.JSeparator;
20
import javax.swing.border.BevelBorder;
21
import javax.swing.border.Border;
19 22

  
20 23

  
21 24
/**
......
25 28
    private static final int INFO = 0;
26 29
    private static final int WARNING = 1;
27 30
    private static final int ERROR = 2;
28
    private JPanel labelPanel = null;
29 31
    private JLabel lblIcon = null;
30 32
    private JLabel lblTexto = null;
31 33
    private boolean contenidoTemporal;
......
61 63

  
62 64
        FlowLayout flowLayout2 = new FlowLayout();
63 65
        this.setLayout(flowLayout2);
64
        flowLayout2.setHgap(3);
66
        flowLayout2.setHgap(1);
65 67
        flowLayout2.setVgap(0);
66 68
        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
67 69
        lblIcon.setText("");
......
69 71
        this.add(lblIcon, null);
70 72
        this.add(getProgressBar(), null);
71 73
        this.add(lblTexto, null);
72
        this.add(getLabelPanel(), null);
73 74
    }
74 75

  
75 76
    /**
76
     * This method initializes labelPanel
77
     *
78
     * @return javax.swing.JPanel
79
     */
80
    private JPanel getLabelPanel() {
81
        if (labelPanel == null) {
82
            FlowLayout flowLayout1 = new FlowLayout();
83
            labelPanel = new JPanel();
84
            labelPanel.setLayout(flowLayout1);
85
            flowLayout1.setHgap(0);
86
            flowLayout1.setVgap(0);
87
        }
88

  
89
        return labelPanel;
90
    }
91

  
92
    /**
93 77
     * Obtiene el texto de la barra de estado
94 78
     *
95 79
     * @return texto
......
262 246
     * @param labels DOCUMENT ME!
263 247
     */
264 248
    public void setLabelSet(Label[] labels) {
265
        getLabelPanel().removeAll();
249
        removeAllLabels();
266 250
        idLabel.clear();
267 251

  
268 252
        for (int i = 0; i < labels.length; i++) {
269 253
            JLabel lbl = new JLabel();
270 254
            lbl.setPreferredSize(new Dimension(labels[i].getSize(),
271 255
                    this.getHeight()));
272
            getLabelPanel().add(lbl);
273
            if (i != labels.length - 1){
274
            	getLabelPanel().add(new JSeparator(JSeparator.VERTICAL));
256
            lbl.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
257
            this.add(lbl);
258
/*            if (i != labels.length - 1){
259
            	this.add(new JSeparator(JSeparator.VERTICAL));
275 260
            }
276
            
261
  */          
277 262
            idLabel.put(labels[i].getId(), lbl);
278 263
        }
264
        this.repaint();
279 265
    }
280 266

  
281 267
    /**
268
	 * 
269
	 */
270
	private void removeAllLabels() {
271
		Component[] labels = this.getComponents();
272
		
273
		for (int i = 0; i < labels.length; i++) {
274
			if ( (labels[i] != lblIcon) &&
275
				 (labels[i] != lblTexto)){
276
				remove(labels[i]);
277
			}
278
		}
279
	}
280

  
281
	/**
282 282
     * Establece el texto de una de las etiquetas
283 283
     *
284 284
     * @param id Identificador de las etiquetas
......
288 288
        JLabel lbl = (JLabel) idLabel.get(id);
289 289

  
290 290
        if (lbl == null) {
291
            throw new RuntimeException("No such label " + id);
291
            logger.debug("no label called " + id);
292
        }else{
293
            lbl.setText(msg);
292 294
        }
293

  
294
        lbl.setText(msg);
295 295
    }
296 296

  
297 297
    /**

Also available in: Unified diff