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 @ 4171

History | View | Annotate | Download (17.1 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.fmap.dal.coverage.RasterLocator;
34
import org.gvsig.fmap.dal.coverage.RasterManager;
35
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
36
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
37
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
38
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
39
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
40
import org.gvsig.i18n.Messages;
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(Messages.getText("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
                this.setPriority(100);
140
        }
141

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

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

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

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

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

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

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

    
223
                return content;
224
        }
225

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

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

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

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

    
285
                String cabecera = setHTMLTitleTable(cabInfo, 2);
286

    
287
                long[] filesSize = lyr.getDataStore().getFileSizeByProvider();
288
                fileSize = filesSize[selectedDataSet];
289

    
290
                String[] names = lyr.getDataStore().getURIByProvider();
291
                propiedades += setHTMLBasicProperty(Messages.getText("archivo"), names[selectedDataSet]);
292

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

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

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

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

    
319
                double pixelSizeX = lyr.getDataStore().getAffineTransform().getScaleX();
320
                double pixelSizeY = lyr.getDataStore().getAffineTransform().getScaleY();
321

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

    
328
                double rotX = lyr.getDataStore().getAffineTransform().getShearX();
329
                double rotY = lyr.getDataStore().getAffineTransform().getShearY();
330

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

    
336
                return "<br>" + setHTMLTable(cabecera + propiedades);
337
        }
338

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

    
350
                String cabOrig = Messages.getText("origin");
351

    
352
                String cabecera = setHTMLTitleTable(cabOrig, 2);
353

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

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

    
382
                        propiedades += setHTMLBasicProperty("Band " + (j + 1), data);
383

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

    
403
                return "<br>" + setHTMLTable(cabecera + propiedades);
404
        }
405

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

    
417
                boolean datos = false;
418

    
419
                String cabProjection = Messages.getText("projection");
420

    
421
                String cabecera = setHTMLTitleTable(cabProjection, 1);
422

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

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

    
438
                if (datos == false) return "";
439

    
440
                return "<br>" + setHTMLTable(cabecera + propiedades);
441
        }
442

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

    
456
                Metadata meta = null;
457
                boolean datos = false;
458

    
459
                String cabMeta = Messages.getText("metadata");
460

    
461
                String cabecera = setHTMLTitleTable(cabMeta, 2);
462

    
463
                Metadata[] metaList = lyr.getDataStore().getMetadataByProvider();
464

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

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

    
478
                if(datos == false)
479
                        return "";
480

    
481
                return "<br>" + setHTMLTable(cabecera + propiedades);
482
        }
483

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

    
496
                        selectedDataSet = getJComboBox().getSelectedIndex();
497
                        if (selectedDataSet < 0) selectedDataSet = 0;
498

    
499
                        String nameFile = "";
500
                        String[] uris = lyr.getDataStore().getURIByProvider();
501

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

    
515
                        jComboBoxEvent = false;
516
                        refresh = true;
517
                }
518

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

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

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

    
536
                if (!(ref instanceof FLyrRaster))
537
                        return;
538

    
539
                lyr = (FLyrRaster) ref;
540
                refresh();
541
        }
542

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

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

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

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