Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / properties / panel / InfoPanel.java @ 987

History | View | Annotate | Download (17.4 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.basic.tool.properties.panel;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.Dimension;
26
import java.awt.event.ItemEvent;
27
import java.awt.event.ItemListener;
28
import java.io.File;
29

    
30
import javax.swing.JEditorPane;
31
import javax.swing.JScrollPane;
32

    
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.coverage.RasterManager;
36
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
37
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
38
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
39
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
40
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
41
import org.gvsig.raster.fmap.layers.FLyrRaster;
42
import org.gvsig.utils.swing.JComboBox;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

    
46
/**
47
 * Panel de informaci?n sobre raster. La informaci?n que aparece en este panel
48
 * es la siguiente:
49
 * <P>
50
 * Informaci?n b?sica sobre el dataset:
51
 * <UL>
52
 * <LI>Fichero/s que forman el dataset</LI>
53
 * <LI>Tama?o por fichero</LI>
54
 * <LI>Ancho y alto</LI>
55
 * <LI>Formato</LI>
56
 * <LI>Si tiene georreferenciaci?n o no</LI>
57
 * <LI>N?mero de bandas</LI>
58
 * <LI>Tipo de dato.</LI>
59
 * </UL>
60
 * </P>
61
 * <P>
62
 * Datos de georreferenciaci?n:
63
 * <UL>
64
 * <LI>Proyecci?n</LI>
65
 * <LI>Coordenadas UTM o geogr?ficas</LI>
66
 * <LI>Tama?o de pixel</LI>
67
 * </UL>
68
 * </P>
69
 * <P>
70
 * Bandas:
71
 * <UL>
72
 * <LI>Bandas de todos los datasets asociados con el tipo de dato de cada uno y
73
 * banda de visualizaci?n asignada (R, G o B)</LI>
74
 * <LI>Coordenadas UTM o geogr?ficas</LI>
75
 * <LI>Tama?o de pixel</LI>
76
 * </UL>
77
 * </P>
78
 * <P>
79
 * Metadatos
80
 * </P>
81
 *
82
 * @author Nacho Brodin (nachobrodin@gmail.com)
83
 *
84
 */
85
public class InfoPanel extends AbstractPanel {
86
        private static final long   serialVersionUID  = -3764465947289974528L;
87
        private static final Logger logger            = LoggerFactory.getLogger(InfoPanel.class);
88
        private final String        bgColor0          = "\"#FEEDD6\""; // light salmon
89
        private final String        bgColor1          = "\"#EAEAEA\""; // light grey
90
        private final String        bgColor3          = "\"#FBFFE1\""; // light yellow
91
        private final String        bgColor4          = "\"#D6D6D6\""; // Gris
92
        private final String        bgColorBody       = "\"#FFFFFF\""; // white
93

    
94
        private JScrollPane         jScrollPane       = null;
95
        public JEditorPane          jEditorPane       = null;
96
        private JComboBox           jComboBox         = null;
97
        private int                 selectedDataSet   = 0;
98
        private boolean             jComboBoxEvent    = false;
99
        /**
100
         * Cabecera de las columnas del dialogo
101
         */
102
        public Object[]             columnNames       = { "Propiedad", "Valor" };
103
        private FLyrRaster          lyr               = null;
104
        /**
105
         * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
106
         * es impar.
107
         */
108
        private boolean             rowColor          = true;
109
        private RasterManager       rManager          = null;
110

    
111
        /**
112
         * This is the default constructor
113
         */
114
        public InfoPanel() {
115
                super();
116
                rManager = RasterLocator.getManager();
117
                setLabel(PluginServices.getText(this, "info"));
118
                initialize();
119
        }
120

    
121
        /**
122
         * This method initializes this
123
         *
124
         * @return void
125
         */
126
        protected void initialize() {
127
                this.setLayout(new BorderLayout(5, 5));
128
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
129
                this.add(getJScrollPane(), BorderLayout.CENTER);
130
                this.add(getJComboBox(), BorderLayout.SOUTH);
131
                this.getJEditorPane().repaint();
132

    
133
                getJComboBox().addItemListener(new ItemListener() {
134
                        public void itemStateChanged(ItemEvent e) {
135
                                refresh();
136
                        }
137
                });
138
                this.setPreferredSize(new Dimension(100, 80));
139
        }
140

    
141
        /*
142
         * (non-Javadoc)
143
         * @see org.gvsig.raster.gui.properties.dialog.IRegistrablePanel#initializeUI()
144
         */
145
        public void initializeUI() {
146
        }
147

    
148
        /**
149
         * This method initializes jScrollPane
150
         *
151
         * @return javax.swing.JScrollPane
152
         */
153
        private JScrollPane getJScrollPane() {
154
                if (jScrollPane == null) {
155
                        jScrollPane = new JScrollPane();
156
                        jScrollPane.setViewportView(getJEditorPane());
157
                }
158
                return jScrollPane;
159
        }
160

    
161
        /**
162
         * This method initializes jComboBox
163
         *
164
         * @return javax.swing.JComboBox
165
         */
166
        private JComboBox getJComboBox() {
167
                if (jComboBox == null) {
168
                        jComboBox = new JComboBox();
169
                }
170
                return jComboBox;
171
        }
172

    
173
        /**
174
         * This method initializes jEditorPane
175
         *
176
         * @return javax.swing.JEditorPane
177
         */
178
        private JEditorPane getJEditorPane() {
179
                if (jEditorPane == null) {
180
                        jEditorPane = new JEditorPane();
181
                        jEditorPane.setEditable(false);
182
                        jEditorPane.setContentType("text/html");
183
                }
184
                return jEditorPane;
185
        }
186

    
187
        public void resetTable() {
188
                this.jEditorPane = null;
189
        }
190

    
191
        /**
192
         * Controla la alternatividad de colores en la tabla.
193
         *
194
         * @return Cadena con el color de la fila siguiente.
195
         */
196
        private String getColor() {
197
                String color = (rowColor ? bgColor0 : bgColor1);
198
                rowColor = !rowColor;
199
                return color;
200
        }
201

    
202
        /**
203
         * Obtiene una entrada de la tabla en formato HTML a partir de una propiedad,
204
         * un valor y un color.
205
         *
206
         * @param prop
207
         *          Nombre de la propiedad
208
         * @param value
209
         *          Valor
210
         * @param color
211
         *          Color
212
         *
213
         * @return Entrada HTML de la tabla
214
         */
215
        private String setHTMLBasicProperty(String prop, String value) {
216
                String content = "<tr valign=\"top\">";
217
                if (prop != null)
218
                        content += "<td bgcolor=" + bgColor4 + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + prop + ":&nbsp;</font></td>";
219
                content += "<td bgcolor=" + getColor() + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value + "</font></td>";
220
                content += "</tr>";
221

    
222
                return content;
223
        }
224

    
225
        /**
226
         * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
227
         *
228
         * @param title
229
         *          Nombre del titulo
230
         * @param colspan
231
         *          Numero de celdas que ocupara el titulo
232
         *
233
         * @return Entrada HTML del titulo
234
         */
235
        private String setHTMLTitleTable(String title, int colspan) {
236
                return
237
                        "<tr valign=\"middle\" >" +
238
                        "<td bgcolor=" + bgColor3 + " align=\"center\" colspan=\"" + colspan + "\"><font face=\"Arial\" size=\"3\"><b> " + title + "</b></font></td>" +
239
                        "</tr>";
240
        }
241

    
242
        /**
243
         * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
244
         *
245
         * @param content
246
         *          Codigo HTML de las filas que componen la tabla.
247
         *
248
         * @return Entrada HTML de la tabla completa
249
         */
250
        private String setHTMLTable(String content) {
251
                return "<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">" + content + "</table>";
252
        }
253

    
254
        /**
255
         * Genera el HTML para todo el contenido.
256
         *
257
         * @param content
258
         *          Codigo HTML que ira en el <body>...</body>.
259
         *
260
         * @return HTML completo
261
         */
262
        private String setHTMLBody(String content) {
263
                String html = "<html>";
264
                html += "<body bgcolor=" + bgColorBody + " topmargin=\"0\" marginheight=\"0\">";
265
                html += content;
266
                html += "</body>";
267
                html += "</html>";
268
                return html;
269
        }
270

    
271
        /**
272
         * M?todo que crea el c?digo HTML para la tabla de informaci?n general dentro
273
         * del panel de informaci?n de raster
274
         *
275
         * @return String con el c?figo HTML que corresponde con la tabla de
276
         * informaci?n general
277
         */
278
        public String tablaInfo() {
279
                rowColor = true;
280
                String cabInfo = PluginServices.getText(this, "general_info");
281
                String propiedades = "";
282
                long fileSize = 0;
283
                
284
                String cabecera = setHTMLTitleTable(cabInfo, 2);
285

    
286
                long[] filesSize = lyr.getDataStore().getFileSizeByProvider();
287
                fileSize = filesSize[selectedDataSet];
288
                
289
                String[] names = lyr.getDataStore().getURIByProvider();
290
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), names[selectedDataSet]);
291

    
292
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "size"), rManager.getFileUtils().formatFileSize(fileSize) + " ");
293
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ancho_alto"), lyr.getPxWidth() + " X " + lyr.getPxHeight());
294
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "formato"), lyr.getFileFormat());
295
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "georref"), lyr.isGeoreferenced() ? PluginServices.getText(this, "si") : PluginServices.getText(this, "no"));
296
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas"), new Integer(lyr.getDataStore().getBandCount()).toString());
297
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas_file"), new Integer(lyr.getBandCountFromDataset()[selectedDataSet]).toString());
298
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tipo_dato"), rManager.getRasterUtils().typesToString(lyr.getDataStore().getDataType()[0]));
299
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tipo_proveedor"), lyr.getDataStore().getProviderName());
300

    
301
                return setHTMLTable(cabecera + propiedades);
302
        }
303

    
304
        /**
305
         * M?todo que crea el c?digo HTML para la tabla de Coordenadas Geogr?ficas
306
         * dentro del panel de informaci?n de raster
307
         *
308
         * @return String con el c?figo HTML que corresponde con la tabla de
309
         *         Coordenadas Geogr?ficas
310
         */
311
        public String tablaCoord() {
312
                rowColor = true;
313
                String cabCoord = PluginServices.getText(this, "coor_geograficas");
314
                String propiedades = "";
315

    
316
                String cabecera = setHTMLTitleTable(cabCoord, 2);
317

    
318
                Extent ext = lyr.getFullRasterExtent();
319
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ul"), ext.getULX() + ", " + ext.getULY());
320
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "lr"), ext.getLRX() + ", " + ext.getLRY());
321
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ur"), ext.getURX() + ", " + ext.getURY());
322
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ll"), ext.getLLX() + ", " + ext.getLLY());
323

    
324
                double pixelSizeX = lyr.getDataStore().getAffineTransform().getScaleX();
325
                double pixelSizeY = lyr.getDataStore().getAffineTransform().getScaleY();
326
                double rotX = lyr.getDataStore().getAffineTransform().getShearX();
327
                double rotY = lyr.getDataStore().getAffineTransform().getShearY();
328

    
329
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixX"), String.valueOf(pixelSizeX));
330
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixY"), String.valueOf(pixelSizeY));
331
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "rotX"), String.valueOf(rotX));
332
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "rotY"), String.valueOf(rotY));
333

    
334
                return "<br>" + setHTMLTable(cabecera + propiedades);
335
        }
336

    
337
        /**
338
         * M?todo que crea la tabla de origen de datos dentro del panel
339
         * de Informaci?n.
340
         *
341
         * @return String con el c?digo HTML de la tabla.
342
         */
343
        public String tablaOrigen() {
344
                rowColor = true;
345
                String propiedades = "";
346
                String bandType = "";
347

    
348
                String cabOrig = PluginServices.getText(this, "origin");
349

    
350
                String cabecera = setHTMLTitleTable(cabOrig, 2);
351

    
352
                for(int j = 0; j < lyr.getBandCountFromDataset()[selectedDataSet] ; j++) {
353
                        bandType = rManager.getRasterUtils().typesToString(lyr.getDataStore().getDataType()[j]);
354

    
355
                        String data = "";
356
                        data += "Type=" + bandType;
357
                        data += ", ";
358
                        data += "ColorInterp=" + lyr.getColorInterpretation(j, selectedDataSet);
359
                        if (lyr.getNoDataValue().isDefined()) {
360
                                data += ", ";
361
                                switch (lyr.getDataStore().getDataType()[0]) {
362
                                case org.gvsig.fmap.dal.coverage.dataset.Buffer.TYPE_BYTE:
363
                                        data += "NoData=" + lyr.getNoDataValue().getValue().byteValue();
364
                                        break;
365
                                case org.gvsig.fmap.dal.coverage.dataset.Buffer.TYPE_SHORT:
366
                                        data += "NoData=" + lyr.getNoDataValue().getValue().shortValue();
367
                                        break;
368
                                case org.gvsig.fmap.dal.coverage.dataset.Buffer.TYPE_INT:
369
                                        data += "NoData=" + lyr.getNoDataValue().getValue().intValue();
370
                                        break;
371
                                case org.gvsig.fmap.dal.coverage.dataset.Buffer.TYPE_FLOAT:
372
                                        data += "NoData=" + lyr.getNoDataValue().getValue().floatValue();
373
                                        break;
374
                                case org.gvsig.fmap.dal.coverage.dataset.Buffer.TYPE_DOUBLE:
375
                                        data += "NoData=" + lyr.getNoDataValue().getValue().doubleValue();
376
                                        break;
377
                                }
378
                        }
379

    
380
                        propiedades += setHTMLBasicProperty("Band " + (j + 1), data);
381

    
382
                        data = "";
383
                        try {
384
                                int count = lyr.getDataStore().getOverviewCount(j);
385
                                if (count > 0) {
386
                                        for (int i = 0; i < count; i++) {
387
                                                int w = lyr.getDataStore().getOverviewWidth(j, i);
388
                                                int h = lyr.getDataStore().getOverviewHeight(j, i);
389
                                                if(w != 0 && h != 0)
390
                                                        data += i + ": " + "(" + w + "X" + h + ")<BR>";
391
                                        }
392
                                        propiedades += setHTMLBasicProperty("Overviews", data);
393
                                }
394
                        } catch (BandAccessException e) {
395
                                logger.info("Error reading overviews", e);
396
                        } catch (RasterDriverException e) {
397
                                logger.info("Error reading overviews", e);
398
                        }
399
                }
400

    
401
                return "<br>" + setHTMLTable(cabecera + propiedades);
402
        }
403

    
404
        /**
405
         * M?todo para crear la tabla de proyecci?n del raster en el
406
         * panel de informaci?n de propiedades de raster.
407
         *
408
         * @return String con el c?digo HTML que genera la tabla de proyecci?n.
409
         */
410
        public String tablaProjection() {
411
                rowColor = true;
412
                String propiedades = "";
413
                String projection = null;
414

    
415
                boolean datos = false;
416

    
417
                String cabProjection = PluginServices.getText(this, "projection");
418

    
419
                String cabecera = setHTMLTitleTable(cabProjection, 1);
420

    
421
                String wktProj = null;
422
                try {
423
                        wktProj = lyr.getWktProjection();
424
                } catch (RasterDriverException e) {
425
                        //No se obtiene la proyecci?n pero no hacemos nada al respecto
426
                }
427

    
428
                if(wktProj != null) {
429
                        projection = rManager.getRasterUtils().parserGdalProj(wktProj);
430
                        if (projection != null){
431
                                datos = true;
432
                                propiedades += setHTMLBasicProperty(null, projection);
433
                        }
434
                }
435

    
436
                if (datos == false) return "";
437

    
438
                return "<br>" + setHTMLTable(cabecera + propiedades);
439
        }
440

    
441
        /**
442
         * M?todo para crear la tabla de informaci?n de metadatos del raster en el
443
         * panel de informaci?n de propiedades de raster.
444
         *
445
         * @param Vector
446
         *          con los georasterfiles cargados en la capa.
447
         * @return String con el c?digo HTML que genera la tabla.
448
         */
449
        public String tablaMetadatos() {
450
                rowColor = true;
451
                String propiedades = "";
452
                String[] metadatos = null;
453

    
454
                Metadata meta = null;
455
                boolean datos = false;
456

    
457
                String cabMeta = PluginServices.getText(this, "metadata");
458

    
459
                String cabecera = setHTMLTitleTable(cabMeta, 2);
460

    
461
                Metadata[] metaList = lyr.getDataStore().getMetadataByProvider();
462
                
463
                meta = metaList[selectedDataSet];
464
                if (meta != null) {
465
                        metadatos = meta.getMetadataString();
466
                        if(metadatos != null) {
467
                                for(int j = 0 ; j < metadatos.length ; j++) {
468
                                        datos = true;
469
                                        int index = metadatos[j].indexOf("=");
470

    
471
                                        propiedades += setHTMLBasicProperty(metadatos[j].substring(0,index), metadatos[j].substring(index+1));
472
                                }
473
                        }
474
                }
475

    
476
                if(datos == false)
477
                        return "";
478

    
479
                return "<br>" + setHTMLTable(cabecera + propiedades);
480
        }
481

    
482
        /**
483
         * M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
484
         * propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las
485
         * tablas.
486
         *
487
         */
488
        public void refresh() {
489
                boolean refresh = false;
490
                if (!jComboBoxEvent) {
491
                        // Set flag to ensure that an infinite loop is not created
492
                        jComboBoxEvent = true;
493

    
494
                        selectedDataSet = getJComboBox().getSelectedIndex();
495
                        if (selectedDataSet < 0) selectedDataSet = 0;
496

    
497
                        String nameFile = "";
498
                        String[] uris = lyr.getDataStore().getURIByProvider();
499
                        
500
                        getJComboBox().removeAllItems();
501
                        for (int i = 0; i < uris.length; i++) {
502
                                nameFile = uris[i];
503
                                nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1);
504
                                getJComboBox().addItem(nameFile);
505
                        }
506
                        try {
507
                                // Select previous item
508
                                getJComboBox().setSelectedIndex(selectedDataSet);
509
                        } catch (IllegalArgumentException iae) {
510
                                selectedDataSet = 0;
511
                        }
512

    
513
                        jComboBoxEvent = false;
514
                        refresh = true;
515
                }
516

    
517
                String html = "";
518
                if ((refresh) && (lyr.getDataStore().getProviderCount() >= 1)) {
519
                        html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos());
520
                }
521

    
522
                this.getJEditorPane().setContentType("text/html");
523
                this.getJEditorPane().setText(html);
524
                this.getJEditorPane().setCaretPosition(0);
525
        }
526

    
527
        /*
528
         * (non-Javadoc)
529
         * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
530
         */
531
        public void setReference(Object ref) {
532
                super.setReference(ref);
533

    
534
                if (!(ref instanceof FLyrRaster))
535
                        return;
536

    
537
                lyr = (FLyrRaster) ref;
538
                refresh();
539
        }
540

    
541
        /*
542
         * (non-Javadoc)
543
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#selected()
544
         */
545
        public void selected() {
546
                refresh();
547
        }
548

    
549
        /*
550
         * (non-Javadoc)
551
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
552
         */
553
        public void accept() {
554
        }
555

    
556
        /*
557
         * (non-Javadoc)
558
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#apply()
559
         */
560
        public void apply() {
561
        }
562

    
563
        /*
564
         * (non-Javadoc)
565
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
566
         */
567
        public void cancel() {
568
        }
569
}