Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / InfoPanel.java @ 6252

History | View | Annotate | Download (13.9 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.raster;
25

    
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ComponentEvent;
29
import java.awt.event.ComponentListener;
30
import java.awt.image.DataBuffer;
31

    
32
import javax.swing.JEditorPane;
33
import javax.swing.JPanel;
34
import javax.swing.JScrollPane;
35

    
36
import org.cresques.io.GeoRasterFile;
37
import org.cresques.io.data.Metadata;
38

    
39
/**
40
 * 
41
 * @author Miguel Angel Querol Carratal? <querol_mig@gva.es>
42
 * Panel de informacion de la imagen r?ster de la que se muestran las propiedades
43
 *
44
 */
45
public class InfoPanel extends JPanel implements ComponentListener{
46

    
47
        private final String bgColor0 = "\"#FEEDD6\""; // light salmon
48
    private final String bgColor1 = "\"#EAEAEA\""; // light grey
49
    private final String bgColor2 = "\"#F2FEFF\""; // light blue
50
    private final String bgColor3 = "\"#FBFFE1\""; // light yellow
51
        private JScrollPane jScrollPane = null;
52
        public JEditorPane jEditorPane = null;
53
    
54
        /**
55
         * Nombre del Panel
56
         */
57
        public String nom = "Info";
58
        
59
        /**
60
         * Dialogo padre que contiene a este
61
         */
62
        public FilterRasterDialogPanel parent = null;
63
        
64
        /**
65
         * Matriz de tama?o Nx2 que contiene a las propiedades en forma propiedad/valor
66
         */
67
        public Object[][]                                         props = null;
68
        
69
        /**
70
         * Cabecera de las columnas del dialogo
71
         */
72
        public Object[] columnNames = { "Propiedad", "Valor" };
73
        
74
        /**
75
         * Cadenas de caracterres que corresponden con las cabeceras de las tablas
76
         * de informaci?n
77
         */
78
        public String                                                 cabInfo = null;
79
        public String                                                 cabCoord = null;
80
        public String                                                 cabProy = null;
81
        public String                                                 cabOrig = null;
82
        public String                                                cabMeta = null;
83
        /**
84
         * Vector de GeoRasterFiles para almacenar los archivos que forman
85
         * parte de la capa.
86
         */
87
        private GeoRasterFile[]                                files = null;
88
        
89
        /**
90
         * Flags que indican que archivo corresponde a cada banda de color
91
         */
92
        private int                                                        redBand = -1;
93
        private int                                                        greenBand = -1;
94
        private int                                                        blueBand = -1;
95
        
96
        
97
        
98
        /**
99
         * This is the default constructor
100
         */
101
        public InfoPanel(FilterRasterDialogPanel parent) {
102
                super();
103
                this.files = parent.grf;
104
                this.parent = parent;
105
                this.props = parent.props;
106
                initialize();
107
        }
108

    
109
        /**
110
         * This method initializes this
111
         * 
112
         * @return void
113
         */
114
        public void initialize() {
115
                GridBagConstraints gridBagConstraints = new GridBagConstraints();
116
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
117
                gridBagConstraints.gridx = 0;
118
                gridBagConstraints.gridy = 0;
119
                gridBagConstraints.weightx = 1.0;
120
                gridBagConstraints.weighty = 1.0;
121
                gridBagConstraints.insets = new java.awt.Insets(5,8,5,8);
122
                this.setLayout(new GridBagLayout());
123
                this.setSize(445, 239);
124
                this.setPreferredSize(new java.awt.Dimension(445,239));
125
                this.add(getJScrollPane(), gridBagConstraints);
126
                this.addComponentListener(this);
127
                //refresh();
128
                this.getJEditorPane().repaint();
129
                
130
        }
131

    
132
        /**
133
         * This method initializes jScrollPane        
134
         *         
135
         * @return javax.swing.JScrollPane        
136
         */
137
        private JScrollPane getJScrollPane() {
138
                if (jScrollPane == null) {
139
                        jScrollPane = new JScrollPane();
140
                        jScrollPane.setPreferredSize(new java.awt.Dimension(440,260));
141
                        jScrollPane.setViewportView(getJEditorPane());
142
                        
143

    
144
                }
145
                return jScrollPane;
146
        }
147

    
148
        /**
149
         * This method initializes jEditorPane        
150
         *         
151
         * @return javax.swing.JEditorPane        
152
         */
153
        private JEditorPane getJEditorPane() {
154
                if (jEditorPane == null) {
155
                        jEditorPane = new JEditorPane();
156
                        jEditorPane.setEditable(false);
157
                        jEditorPane.setSize(new java.awt.Dimension(425,220));
158
                        
159
                }
160
                return jEditorPane;
161
        }
162
        
163
        public void resetTable(){
164
                this.jEditorPane = null;
165
        }
166
        
167
        /**
168
         * Obtiene el nombre del panel.
169
         */
170
        public String getName(){
171
            return this.nom;
172
    }
173
                
174
        /**
175
         * A?ade los GeoRasterFiles que forman parte de la capa
176
         * @param Vector de GeoRasterFiles que corresponde con los
177
         * archivos cargados.
178
         */
179
        public void addFiles(GeoRasterFile[] files){
180
                this.files = files;
181
                refresh();
182
        }
183
        
184
        /**
185
         * Asigna el n?mero de l?nea del archivo que corresponde a cada bada de color
186
         * @param bandR N?mero de linea del archivo que corresponde a la banda roja
187
         * @param bandG N?mero de linea del archivo que corresponde a la banda verde
188
         * @param bandB N?mero de linea del archivo que corresponde a la banda azul
189
         */
190
        public void setBands(int bandR, int bandG, int bandB){
191
                this.redBand = bandR;
192
                this.greenBand = bandG;
193
                this.blueBand = bandB;
194
                refresh();
195
        }
196
        
197
        
198
        /**
199
         * M?todo que crea el c?digo HTML para la tabla de informaci?n general
200
         * dentro del panel de informaci?n de raster
201
         * @return String con el c?figo HTML que corresponde con la tabla de informaci?n
202
         * general
203
         */
204
        public String tablaInfo(){
205
                String tablaInfo = null;
206
                String propiedades="";
207
                String color = "\"#FEEDD6\"";
208
                
209
                String cabecera = 
210
                        "  <tr valign=\"top\">" +
211
            "     <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"2\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabInfo+"</b></font></td>" +
212
            "  </tr>";
213
                
214
                for(int i = 0; i <= 5; i++){
215
                        
216
                        if ((i%2 == 0) || i == 0) color = bgColor0;
217
                        else color = bgColor1;
218
                        
219
                        //if(props[i][1] == null) props[i][1] = "";
220
                        
221
                        if(props.length > 1){
222
                                String propiedad = 
223
                                        "  <tr valign=\"top\">" +
224
                                        "     <td width=\"140\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\">"+props[i][0]+"</font></td>" +
225
                                        "     <td width=\"270\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+props[i][1]+"</font></td>" +
226
                                        "  </tr>";
227
                                propiedades = propiedades + propiedad; 
228
                        }
229
                }
230
                
231
                tablaInfo = "<table>" + cabecera + propiedades + "<tr></tr>" + "</table>";
232
                
233
                return tablaInfo;
234
        }
235
        
236
        
237
        
238
        
239
        /**
240
         * M?todo que crea el c?digo HTML para la tabla de coordenadas geogr?ficas
241
         * dentro del panel de informaci?n de raster
242
         * @return String con el c?figo HTML que corresponde con la tabla de coordenadas
243
         * geogr?ficas.
244
         */
245
        public String tablaCoord(){
246
                String tablaCoord = null;
247
                String propiedades = "";
248
                String color = "\"#FEEDD6\"";
249
                
250
                if(props.length > 1){
251
                        String cabecera = 
252
                                "  <tr valign=\"top\">" +
253
                    "     <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"2\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabCoord+"</b></font></td>" +
254
                    "  </tr>";
255
                        
256
                        for(int i = 7; i <= 12; i++){
257
                                
258
                                if ((i%2 == 1) || i == 7) color = bgColor0;
259
                                else color = bgColor1;
260
                                
261
                                if(props[i][1] == null) props[i][1] = "";
262
                                
263
                                if(props[i][0] != null){
264
                                        String propiedad = 
265
                                                "  <tr valign=\"top\">" +
266
                                                "     <td width=\"140\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\">"+props[i][0]+"</font></td>" +
267
                                                "     <td width=\"270\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+props[i][1]+"</font></td>" +
268
                                                "  </tr>";
269
                                        propiedades = propiedades + propiedad; 
270
                                }
271
                        }
272
                        tablaCoord = "<table>" + cabecera + propiedades + "<tr></tr>" + "</table>";
273
                        
274
                        return tablaCoord;
275
                        }
276
                return "";
277
        }
278

    
279
        
280
        
281
        /**
282
         * M?todo que crea la tabla de origen de datos dentro del panel
283
         * de Informaci?n.
284
         * @param vector con todos los GeoRasterFiles que est?n dentro de la capa
285
         * @return String con el c?digo HTML de la tabla.
286
         */
287
        public String tablaOrigen(GeoRasterFile[] files){
288
                String tablaOrigen = null;
289
                String propiedades = "";
290
                String color = "\"#FEEDD6\"";
291
                String rBand = "";
292
                String gBand = "";
293
                String bBand = "";
294
                String bandType = "";
295
                int k = 0;
296
                
297
                
298
                String cabecera = 
299
                        "  <tr valign=\"top\">" +
300
                        "     <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabOrig+"</b></font></td>" +
301
                        "  </tr>";
302
                
303
                for(int i = 0; i<files.length ; i++){
304
                        String fName = files[i].getName();
305
                        String propiedad = 
306
                                "  <tr valign=\"top\">" +
307
                                "     <td width=\"417\" height=\"18\" bgcolor="+bgColor1+"align=\"left\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\">"+fName+"</font></td>" +
308
                                "  </tr>";
309
                        
310
                        switch (files[i].getDataType()) {
311
            case DataBuffer.TYPE_BYTE:
312
                bandType = "8U";
313
                break;
314
            case DataBuffer.TYPE_INT:
315
                bandType = "32";
316
                break;
317
            case DataBuffer.TYPE_DOUBLE:
318
                bandType = "64";
319
                break;
320
            case DataBuffer.TYPE_FLOAT:
321
                bandType = "32";
322
                break;
323
            case DataBuffer.TYPE_SHORT:
324
                bandType = "16";
325
                break;
326
            case DataBuffer.TYPE_USHORT:
327
                bandType = "16U";
328
                break;
329
            case DataBuffer.TYPE_UNDEFINED:
330
                bandType = "??";
331
                break;
332
            }
333
                        
334
                        for(int j = 0; j < files[i].getBandCount() ; j++){
335
                                if ((j%2 == 0) || j == 0) color = bgColor0;
336
                                else color = bgColor1;
337
                                
338
                                if(k == redBand) rBand = "R";                 else rBand = "";
339
                                if(k == greenBand) gBand = "G";                else gBand = "";
340
                                if(k == blueBand) bBand = "B";                else bBand = "";
341
                                
342
                                String banda = 
343
                                        "  <tr valign=\"top\">" +
344
                                        "     <td width=\"20\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"center\" colspan=\"1/2\"><font face=\"Arial\" size=\"3\" align=\"right\">"+rBand+"</font></td>" +
345
                                        "     <td width=\"20\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"center\" colspan=\"1/2\"><font face=\"Arial\" size=\"3\" align=\"right\">"+gBand+"</font></td>" +
346
                                        "     <td width=\"20\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"center\" colspan=\"1/2\"><font face=\"Arial\" size=\"3\" align=\"right\">"+bBand+"</font></td>" +
347
                                        "     <td width=\"357\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+"band "+(j+1)+"["+bandType+"]"+"</font></td>" +
348
                                        "  </tr>";
349
                                propiedad = propiedad + banda;
350
                                k++;
351
                        }
352
                        propiedades = propiedades + propiedad;
353
                }
354
                
355
                tablaOrigen = "<table>" + cabecera + propiedades + "<tr></tr>" + "</table>";
356
                
357
                return tablaOrigen;
358
        }
359
        
360
        
361
        /**
362
         * M?todo para crear la tabla de informaci?n de metadatos del raster en el
363
         * panel de informaci?n de propiedades de raster.
364
         * @param Vector con los georasterfiles cargados en la capa.
365
         * @return String con el c?digo HTML que genera la tabla.
366
         */
367
        public String tablaMetadatos(GeoRasterFile[] files){
368
                String tablaMetadatos = "";
369
                String propiedades = "";
370
                String[] metadatos = null;
371
                String color = "\"#FEEDD6\"";
372
                
373
                Metadata meta = null;
374
                boolean datos = false;
375
                
376
                String cabecera = 
377
                        "  <tr valign=\"top\">" +
378
                        "     <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabMeta+"</b></font></td>" +
379
                        "  </tr>";
380
                
381
                for (int i = 0 ; i < files.length ; i++){
382
                        meta = files[i].getMetadata();
383
                        if (meta != null){
384
                                datos = true;
385
                                metadatos = meta.getMetadataString();
386
                                String fichero = 
387
                                        "  <tr valign=\"top\">" +
388
                                        "     <td width=\"417\" height=\"18\" bgcolor="+bgColor1+"align=\"left\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\">"+files[i].getName()+"</font></td>" +
389
                                        "  </tr>";
390
                                propiedades = propiedades + fichero;
391
                                for(int j = 0 ; j<metadatos.length ; j++){
392
                                        if ((j%2 == 0) || j == 0) color = bgColor0;
393
                                        else color = bgColor1;
394
                                        int index = metadatos[j].indexOf("=");
395
                                        
396
                                        String propiedad = 
397
                                                "  <tr valign=\"top\">" +
398
                                                "     <td width=\"140\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\">"+metadatos[j].substring(0,index)+"</font></td>" +
399
                                                "     <td width=\"270\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+metadatos[j].substring(index+1)+"</font></td>" +
400
                                                "  </tr>";
401
                                        propiedades = propiedades + propiedad; 
402
                                }
403
                        }
404
                }
405
                
406
                tablaMetadatos = cabecera + propiedades;
407
                if(datos == false)
408
                        return "";
409
                
410
                return tablaMetadatos;
411
        }
412
        
413
        /**
414
         * M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
415
         * propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las 
416
         * tablas.
417
         *
418
         */
419
        public void refresh(){
420
                String html = null;
421
                
422
                html = 
423
                        "<html>"+
424
                        this.tablaInfo()+
425
                        this.tablaCoord();
426
                
427
                if(this.files != null){
428
                        html = html + this.tablaOrigen(files) + this.tablaMetadatos(files) +"</html>";
429
                }
430
                
431
                else
432
                        html = html + "</html>";
433
                        
434
                this.getJEditorPane().setContentType("text/html");
435
                this.getJEditorPane().setText(html);
436
                this.getJScrollPane().setAlignmentY(0);
437
        }
438

    
439
        public void componentHidden(ComponentEvent e) {
440
                // TODO Auto-generated method stub
441
                
442
        }
443

    
444
        public void componentMoved(ComponentEvent e) {
445
                // TODO Auto-generated method stub
446
                
447
        }
448
        /**
449
         * Cambia el tama?o del panel cuando se redimensiona su contenedor
450
         */
451
        public void componentResized(ComponentEvent e) {
452
                if(e.getSource() == this){
453
                        this.getJScrollPane().setSize(this.getJScrollPane().getWidth() + 1, this.getJScrollPane().getHeight() + 1);
454
                        this.getJEditorPane().setSize(this.getJEditorPane().getWidth() + 1, this.getJEditorPane().getHeight() + 1);
455
                        jScrollPane.getVerticalScrollBar().setValue(0);
456
                }
457
                
458
        }
459

    
460
        public void componentShown(ComponentEvent e) {
461
                // TODO Auto-generated method stub
462
                
463
        }
464
        
465
}
466

    
467