Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / InfoPanel.java @ 8026

History | View | Annotate | Download (14 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.datastruct.Metadata;
38
import org.cresques.ui.filter.FilterRasterDialogPanel;
39

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

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

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

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

    
145
                }
146
                return jScrollPane;
147
        }
148

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

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

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

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

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

    
468