Statistics
| Revision:

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

History | View | Annotate | Download (17.2 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
import java.net.URI;
30

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

    
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.i18n.Messages;
42
import org.gvsig.raster.fmap.layers.FLyrRaster;
43
import org.gvsig.utils.swing.JComboBox;
44

    
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

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

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

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

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

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

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

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

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

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

    
190
        public void resetTable() {
191
                this.jEditorPane = null;
192
        }
193

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

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

    
225
                return content;
226
        }
227

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

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

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

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

    
287
                String cabecera = setHTMLTitleTable(cabInfo, 2);
288

    
289
                long[] filesSize = lyr.getDataStore().getFileSizeByProvider();
290
                fileSize = filesSize[selectedDataSet];
291

    
292
                URI[] names = lyr.getDataStore().getURIByProvider();
293
                propiedades += setHTMLBasicProperty(Messages.getText("archivo"), names[selectedDataSet].getPath());
294

    
295
                propiedades += setHTMLBasicProperty(Messages.getText("size"), rManager.getFileUtils().formatFileSize(fileSize) + " ");
296
                propiedades += setHTMLBasicProperty(Messages.getText("ancho_alto"), lyr.getDataStore().getWidth() + " X " + lyr.getDataStore().getHeight());
297
                propiedades += setHTMLBasicProperty(Messages.getText("formato"), lyr.getFileFormat());
298
                propiedades += setHTMLBasicProperty(Messages.getText("georref"), lyr.isGeoreferenced() ? Messages.getText("si") : Messages.getText("no"));
299
                propiedades += setHTMLBasicProperty(Messages.getText("nbandas"), new Integer(lyr.getDataStore().getBandCount()).toString());
300
                propiedades += setHTMLBasicProperty(Messages.getText("nbandas_file"), new Integer(lyr.getBandCountFromDataset()[selectedDataSet]).toString());
301
                propiedades += setHTMLBasicProperty(Messages.getText("tipo_dato"), rManager.getRasterUtils().typesToString(lyr.getDataStore().getDataType()[0]));
302
                propiedades += setHTMLBasicProperty(Messages.getText("tipo_proveedor"), lyr.getDataStore().getProviderName());
303

    
304
                return setHTMLTable(cabecera + propiedades);
305
        }
306

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

    
319
                String cabecera = setHTMLTitleTable(cabCoord, 2);
320

    
321
                double pixelSizeX = lyr.getDataStore().getAffineTransform().getScaleX();
322
                double pixelSizeY = lyr.getDataStore().getAffineTransform().getScaleY();
323

    
324
                Extent ext = lyr.getFullRasterExtent();
325
                propiedades += setHTMLBasicProperty(Messages.getText("ul"), ext.getULX() + ", " + ext.getULY());
326
                propiedades += setHTMLBasicProperty(Messages.getText("lr"), ext.getLRX() + ", " + ext.getLRY());
327
                propiedades += setHTMLBasicProperty(Messages.getText("ur"), ext.getURX() + ", " + ext.getURY());
328
                propiedades += setHTMLBasicProperty(Messages.getText("ll"), ext.getLLX() + ", " + ext.getLLY());
329

    
330
                double rotX = lyr.getDataStore().getAffineTransform().getShearX();
331
                double rotY = lyr.getDataStore().getAffineTransform().getShearY();
332

    
333
                propiedades += setHTMLBasicProperty(Messages.getText("tamPixX"), String.valueOf(pixelSizeX));
334
                propiedades += setHTMLBasicProperty(Messages.getText("tamPixY"), String.valueOf(pixelSizeY));
335
                propiedades += setHTMLBasicProperty(Messages.getText("rotX"), String.valueOf(rotX));
336
                propiedades += setHTMLBasicProperty(Messages.getText( "rotY"), String.valueOf(rotY));
337

    
338
                return "<br>" + setHTMLTable(cabecera + propiedades);
339
        }
340

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

    
352
                String cabOrig = Messages.getText("origin");
353

    
354
                String cabecera = setHTMLTitleTable(cabOrig, 2);
355

    
356
                for(int j = 0; j < lyr.getBandCountFromDataset()[selectedDataSet] ; j++) {
357
                        bandType = rManager.getRasterUtils().typesToString(lyr.getDataStore().getDataType()[j]);
358

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

    
384
                        propiedades += setHTMLBasicProperty("Band " + (j + 1), data);
385

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

    
405
                return "<br>" + setHTMLTable(cabecera + propiedades);
406
        }
407

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

    
419
                boolean datos = false;
420

    
421
                String cabProjection = Messages.getText("projection");
422

    
423
                String cabecera = setHTMLTitleTable(cabProjection, 1);
424

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

    
432
                if(wktProj != null) {
433
                        projection = rManager.getRasterUtils().parserGdalProj(wktProj);
434
                        if (projection != null){
435
                                datos = true;
436
                                propiedades += setHTMLBasicProperty(null, projection);
437
                        }
438
                }
439

    
440
                if (datos == false) return "";
441

    
442
                return "<br>" + setHTMLTable(cabecera + propiedades);
443
        }
444

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

    
458
                Metadata meta = null;
459
                boolean datos = false;
460

    
461
                String cabMeta = Messages.getText("metadata");
462

    
463
                String cabecera = setHTMLTitleTable(cabMeta, 2);
464

    
465
                Metadata[] metaList = lyr.getDataStore().getMetadataByProvider();
466

    
467
                meta = metaList[selectedDataSet];
468
                if (meta != null) {
469
                        metadatos = meta.getMetadataString();
470
                        if(metadatos != null) {
471
                                for(int j = 0 ; j < metadatos.length ; j++) {
472
                                        datos = true;
473
                                        int index = metadatos[j].indexOf("=");
474

    
475
                                        propiedades += setHTMLBasicProperty(metadatos[j].substring(0,index), metadatos[j].substring(index+1));
476
                                }
477
                        }
478
                }
479

    
480
                if(datos == false)
481
                        return "";
482

    
483
                return "<br>" + setHTMLTable(cabecera + propiedades);
484
        }
485

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

    
498
                        selectedDataSet = getJComboBox().getSelectedIndex();
499
                        if (selectedDataSet < 0) selectedDataSet = 0;
500

    
501
                        String nameFile = "";
502
                        URI[] uris = lyr.getDataStore().getURIByProvider();
503

    
504
                        getJComboBox().removeAllItems();
505
                        for (int i = 0; i < uris.length; i++) {
506
                                nameFile = uris[i].getPath();
507
                                nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1);
508
                                getJComboBox().addItem(nameFile);
509
                        }
510
                        try {
511
                                // Select previous item
512
                                getJComboBox().setSelectedIndex(selectedDataSet);
513
                        } catch (IllegalArgumentException iae) {
514
                                selectedDataSet = 0;
515
                        }
516

    
517
                        jComboBoxEvent = false;
518
                        refresh = true;
519
                }
520

    
521
                String html = "";
522
                if ((refresh) && (lyr.getDataStore().getProviderCount() >= 1)) {
523
                        html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos());
524
                }
525

    
526
                this.getJEditorPane().setContentType("text/html");
527
                this.getJEditorPane().setText(html);
528
                this.getJEditorPane().setCaretPosition(0);
529
        }
530

    
531
        /*
532
         * (non-Javadoc)
533
         * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
534
         */
535
        public void setReference(Object ref) {
536
                super.setReference(ref);
537

    
538
                if (!(ref instanceof FLyrRaster))
539
                        return;
540

    
541
                lyr = (FLyrRaster) ref;
542
                refresh();
543
        }
544

    
545
        /*
546
         * (non-Javadoc)
547
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#selected()
548
         */
549
        public void selected() {
550
                refresh();
551
        }
552

    
553
        /*
554
         * (non-Javadoc)
555
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
556
         */
557
        public void accept() {
558
        }
559

    
560
        /*
561
         * (non-Javadoc)
562
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#apply()
563
         */
564
        public void apply() {
565
        }
566

    
567
        /*
568
         * (non-Javadoc)
569
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
570
         */
571
        public void cancel() {
572
        }
573
}