Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / InfoPanel.java @ 21228

History | View | Annotate | Download (16.1 KB)

1 10740 nacho
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.properties.panels;
20
21
import java.awt.BorderLayout;
22 17047 nbrodin
import java.awt.Dimension;
23 10740 nacho
import java.awt.event.ItemEvent;
24
import java.awt.event.ItemListener;
25
import java.io.File;
26
27
import javax.swing.JEditorPane;
28
import javax.swing.JScrollPane;
29
30 16409 bsanchez
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
31 15781 bsanchez
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
32 20722 bsanchez
import org.gvsig.raster.dataset.BandAccessException;
33 16591 nbrodin
import org.gvsig.raster.dataset.io.RasterDriverException;
34 10940 nacho
import org.gvsig.raster.dataset.properties.DatasetMetadata;
35 12793 nacho
import org.gvsig.raster.datastruct.Extent;
36 12383 nacho
import org.gvsig.raster.hierarchy.IRasterProperties;
37 10940 nacho
import org.gvsig.raster.util.RasterUtilities;
38 10740 nacho
39
import com.iver.andami.PluginServices;
40
import com.iver.cit.gvsig.fmap.layers.FLayer;
41
import com.iver.utiles.swing.JComboBox;
42
/**
43
 * Panel de informaci?n sobre raster. La informaci?n que aparece en este panel
44
 * es la siguiente:
45
 * <P>
46
 * Informaci?n b?sica sobre el dataset:
47
 * <UL>
48
 * <LI>Fichero/s que forman el dataset</LI>
49
 * <LI>Tama?o por fichero</LI>
50
 * <LI>Ancho y alto</LI>
51
 * <LI>Formato</LI>
52
 * <LI>Si tiene georreferenciaci?n o no</LI>
53
 * <LI>N?mero de bandas</LI>
54
 * <LI>Tipo de dato.</LI>
55
 * </UL>
56
 * </P>
57
 * <P>
58
 * Datos de georreferenciaci?n:
59
 * <UL>
60
 * <LI>Proyecci?n</LI>
61
 * <LI>Coordenadas UTM o geogr?ficas</LI>
62
 * <LI>Tama?o de pixel</LI>
63
 * </UL>
64
 * </P>
65
 * <P>
66
 * Bandas:
67
 * <UL>
68
 * <LI>Bandas de todos los datasets asociados con el tipo de dato de cada uno y
69
 * banda de visualizaci?n asignada (R, G o B)</LI>
70
 * <LI>Coordenadas UTM o geogr?ficas</LI>
71
 * <LI>Tama?o de pixel</LI>
72
 * </UL>
73
 * </P>
74
 * <P>
75
 * Metadatos
76
 * </P>
77 12716 bsanchez
 *
78 10740 nacho
 * @author Nacho Brodin (nachobrodin@gmail.com)
79 12716 bsanchez
 *
80 10740 nacho
 */
81 18001 bsanchez
public class InfoPanel extends AbstractPanel {
82 19306 bsanchez
        private static final long serialVersionUID = -3764465947289974528L;
83 18001 bsanchez
        private final String      bgColor0        = "\"#FEEDD6\""; // light salmon
84
        private final String      bgColor1        = "\"#EAEAEA\""; // light grey
85
        private final String      bgColor3        = "\"#FBFFE1\""; // light yellow
86
        private final String      bgColor4        = "\"#D6D6D6\""; // Gris
87
        private final String      bgColorBody     = "\"#FFFFFF\""; // white
88 10740 nacho
89 18001 bsanchez
        private JScrollPane       jScrollPane     = null;
90
        public JEditorPane        jEditorPane     = null;
91
        private JComboBox         jComboBox       = null;
92
        private int               selectedDataSet = 0;
93 10740 nacho
94 18001 bsanchez
        private boolean           jComboBoxEvent  = false;
95 10740 nacho
96
        /**
97
         * Cabecera de las columnas del dialogo
98
         */
99 18001 bsanchez
        public Object[]           columnNames     = { "Propiedad", "Valor" };
100 10740 nacho
101 18001 bsanchez
        private IRasterProperties op              = null;
102 10740 nacho
103
        /**
104
         * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
105
         * es impar.
106
         */
107 18001 bsanchez
        private boolean           rowColor        = true;
108 10740 nacho
109
        /**
110
         * This is the default constructor
111
         */
112
        public InfoPanel() {
113
                super();
114 15781 bsanchez
                setLabel(PluginServices.getText(this, "info"));
115 10740 nacho
                initialize();
116
        }
117
118
        /**
119
         * This method initializes this
120 12716 bsanchez
         *
121 10740 nacho
         * @return void
122
         */
123 15781 bsanchez
        protected void initialize() {
124 11117 bsanchez
                this.setLayout(new BorderLayout(5, 5));
125
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
126
                this.add(getJScrollPane(), BorderLayout.CENTER);
127
                this.add(getJComboBox(), BorderLayout.SOUTH);
128 10740 nacho
                this.getJEditorPane().repaint();
129
130
                getJComboBox().addItemListener(new ItemListener() {
131
                        public void itemStateChanged(ItemEvent e) {
132
                                refresh();
133
                        }
134
                });
135 17047 nbrodin
                this.setPreferredSize(new Dimension(100, 80));
136 10740 nacho
        }
137
138 15804 bsanchez
        /*
139
         * (non-Javadoc)
140
         * @see org.gvsig.raster.gui.properties.dialog.IRegistrablePanel#initializeUI()
141
         */
142 13599 bsanchez
        public void initializeUI() {
143 15804 bsanchez
        }
144 13599 bsanchez
145 10740 nacho
        /**
146
         * This method initializes jScrollPane
147 12716 bsanchez
         *
148 10740 nacho
         * @return javax.swing.JScrollPane
149
         */
150
        private JScrollPane getJScrollPane() {
151
                if (jScrollPane == null) {
152
                        jScrollPane = new JScrollPane();
153
                        jScrollPane.setViewportView(getJEditorPane());
154
                }
155
                return jScrollPane;
156
        }
157
158
        /**
159
         * This method initializes jComboBox
160 12716 bsanchez
         *
161 10740 nacho
         * @return javax.swing.JComboBox
162
         */
163
        private JComboBox getJComboBox() {
164
                if (jComboBox == null) {
165
                        jComboBox = new JComboBox();
166
                }
167
                return jComboBox;
168
        }
169
170
        /**
171
         * This method initializes jEditorPane
172 12716 bsanchez
         *
173 10740 nacho
         * @return javax.swing.JEditorPane
174
         */
175
        private JEditorPane getJEditorPane() {
176
                if (jEditorPane == null) {
177
                        jEditorPane = new JEditorPane();
178
                        jEditorPane.setEditable(false);
179
                        jEditorPane.setContentType("text/html");
180
                }
181
                return jEditorPane;
182
        }
183
184
        public void resetTable() {
185
                this.jEditorPane = null;
186
        }
187
188
        /**
189
         * Controla la alternatividad de colores en la tabla.
190 12716 bsanchez
         *
191 10740 nacho
         * @return Cadena con el color de la fila siguiente.
192
         */
193
        private String getColor() {
194
                String color = (rowColor ? bgColor0 : bgColor1);
195
                rowColor = !rowColor;
196
                return color;
197
        }
198
199
        /**
200
         * Obtiene una entrada de la tabla en formato HTML a partir de una propiedad,
201
         * un valor y un color.
202 12716 bsanchez
         *
203 10740 nacho
         * @param prop
204
         *          Nombre de la propiedad
205
         * @param value
206
         *          Valor
207
         * @param color
208
         *          Color
209 12716 bsanchez
         *
210 10740 nacho
         * @return Entrada HTML de la tabla
211
         */
212
        private String setHTMLBasicProperty(String prop, String value) {
213
                String content = "<tr valign=\"top\">";
214
                if (prop != null)
215
                        content += "<td bgcolor=" + bgColor4 + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + prop + ":&nbsp;</font></td>";
216
                content += "<td bgcolor=" + getColor() + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value + "</font></td>";
217
                content += "</tr>";
218
219
                return content;
220
        }
221
222
        /**
223
         * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
224 12716 bsanchez
         *
225 10740 nacho
         * @param title
226
         *          Nombre del titulo
227
         * @param colspan
228
         *          Numero de celdas que ocupara el titulo
229 12716 bsanchez
         *
230 10740 nacho
         * @return Entrada HTML del titulo
231
         */
232
        private String setHTMLTitleTable(String title, int colspan) {
233
                return
234
                        "<tr valign=\"middle\" >" +
235
                        "<td bgcolor=" + bgColor3 + " align=\"center\" colspan=\"" + colspan + "\"><font face=\"Arial\" size=\"3\"><b> " + title + "</b></font></td>" +
236
                        "</tr>";
237
        }
238
239
        /**
240
         * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
241 12716 bsanchez
         *
242 10740 nacho
         * @param content
243
         *          Codigo HTML de las filas que componen la tabla.
244 12716 bsanchez
         *
245 10740 nacho
         * @return Entrada HTML de la tabla completa
246
         */
247
        private String setHTMLTable(String content) {
248
                return "<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">" + content + "</table>";
249
        }
250
251
        /**
252
         * Genera el HTML para todo el contenido.
253 12716 bsanchez
         *
254 10740 nacho
         * @param content
255
         *          Codigo HTML que ira en el <body>...</body>.
256 12716 bsanchez
         *
257 10740 nacho
         * @return HTML completo
258
         */
259
        private String setHTMLBody(String content) {
260
                String html = "<html>";
261
                html += "<body bgcolor=" + bgColorBody + " topmargin=\"0\" marginheight=\"0\">";
262
                html += content;
263
                html += "</body>";
264
                html += "</html>";
265
                return html;
266
        }
267
268
        /**
269
         * M?todo que crea el c?digo HTML para la tabla de informaci?n general dentro
270
         * del panel de informaci?n de raster
271 12716 bsanchez
         *
272 10740 nacho
         * @return String con el c?figo HTML que corresponde con la tabla de
273
         * informaci?n general
274
         */
275
        public String tablaInfo() {
276
                rowColor = true;
277
                String cabInfo = PluginServices.getText(this, "general_info");
278
                String propiedades = "";
279
280
                String cabecera = setHTMLTitleTable(cabInfo, 2);
281
282
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), op.getFileName()[selectedDataSet]);
283 16409 bsanchez
284
                long fileSize = op.getFileSize()[selectedDataSet];
285
                if (op instanceof FLyrRasterSE) {
286
                        FLyrRasterSE rasterSE = (FLyrRasterSE) op;
287
                        fileSize = rasterSE.getDataSource().getDataset(selectedDataSet)[0].getFileSize();
288
                }
289 20640 bsanchez
290 16409 bsanchez
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "size"), RasterUtilities.formatFileSize(fileSize) + " ");
291 10740 nacho
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ancho_alto"), op.getPxWidth() + " X " + op.getPxHeight());
292
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "formato"), op.getFileFormat());
293
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "georref"), op.isGeoreferenced() ? PluginServices.getText(this, "si") : PluginServices.getText(this, "no"));
294 20640 bsanchez
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas"), new Integer(op.getBandCountFromDataset()[selectedDataSet]).toString());
295 10740 nacho
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tipo_dato"), RasterUtilities.typesToString(op.getDataType()[0]));
296
297
                return setHTMLTable(cabecera + propiedades);
298
        }
299
300
        /**
301
         * M?todo que crea el c?digo HTML para la tabla de Coordenadas Geogr?ficas
302
         * dentro del panel de informaci?n de raster
303 12716 bsanchez
         *
304 10740 nacho
         * @return String con el c?figo HTML que corresponde con la tabla de
305
         *         Coordenadas Geogr?ficas
306
         */
307
        public String tablaCoord() {
308
                rowColor = true;
309
                String cabCoord = PluginServices.getText(this, "coor_geograficas");
310
                String propiedades = "";
311
312
                String cabecera = setHTMLTitleTable(cabCoord, 2);
313
314 12793 nacho
                Extent ext = op.getFullRasterExtent();
315
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ul"), ext.getULX() + ", " + ext.getULY());
316
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "lr"), ext.getLRX() + ", " + ext.getLRY());
317
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ur"), ext.getURX() + ", " + ext.getURY());
318
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ll"), ext.getLLX() + ", " + ext.getLLY());
319 10740 nacho
320 12706 nacho
                double pixelSizeX = op.getAffineTransform().getScaleX();
321
                double pixelSizeY = op.getAffineTransform().getScaleY();
322 12811 nacho
                double rotX = op.getAffineTransform().getShearX();
323
                double rotY = op.getAffineTransform().getShearY();
324 12716 bsanchez
325 12706 nacho
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixX"), String.valueOf(pixelSizeX));
326
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixY"), String.valueOf(pixelSizeY));
327 12811 nacho
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "rotX"), String.valueOf(rotX));
328
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "rotY"), String.valueOf(rotY));
329 10740 nacho
330
                return "<br>" + setHTMLTable(cabecera + propiedades);
331
        }
332
333
        /**
334
         * M?todo que crea la tabla de origen de datos dentro del panel
335
         * de Informaci?n.
336 12716 bsanchez
         *
337 10740 nacho
         * @return String con el c?digo HTML de la tabla.
338
         */
339
        public String tablaOrigen() {
340
                rowColor = true;
341
                String propiedades = "";
342
                String bandType = "";
343 12716 bsanchez
344 10740 nacho
                String cabOrig = PluginServices.getText(this, "origin");
345 12716 bsanchez
346 10740 nacho
                String cabecera = setHTMLTitleTable(cabOrig, 2);
347 15804 bsanchez
348 13540 nacho
                for(int j = 0; j < op.getBandCountFromDataset()[selectedDataSet] ; j++) {
349 13377 nacho
                        bandType = RasterUtilities.typesToString(op.getDataType()[j]);
350 17044 bsanchez
351
                        String data = "";
352
                        data += "Type=" + bandType;
353
                        data += ", ";
354 20999 bsanchez
                        data += "ColorInterp=" + op.getColorInterpretation(j, selectedDataSet);
355 21228 bsanchez
                        if (((FLyrRasterSE) op).getNoDataType() != 0) {
356
                                data += ", ";
357
                                data += "NoData=" + ((FLyrRasterSE) op).getNoDataValue();
358
                        }
359 17044 bsanchez
360
                        propiedades += setHTMLBasicProperty("Band " + (j + 1), data);
361 20722 bsanchez
362
                        if (op instanceof FLyrRasterSE) {
363
                                FLyrRasterSE rasterSE = (FLyrRasterSE) op;
364
                                data = "";
365
                                try {
366
                                        int count = rasterSE.getDataSource().getDataset(selectedDataSet)[0].getOverviewCount(j);
367
                                        if (count > 0) {
368
                                                for (int i = 0; i < count; i++) {
369
                                                        if (!data.equals(""))
370
                                                                data += ", ";
371
                                                        data += rasterSE.getDataSource().getDataset(selectedDataSet)[0].getOverviewWidth(j, i);
372
                                                        data += "x";
373
                                                        data += rasterSE.getDataSource().getDataset(selectedDataSet)[0].getOverviewHeight(j, i);
374
                                                }
375
                                                propiedades += setHTMLBasicProperty("Overviews", data);
376
                                        }
377
                                } catch (BandAccessException e) {
378
                                        // No se obtiene el contador de overviews
379
                                } catch (RasterDriverException e) {
380
                                        // No se obtiene el contador de overviews
381
                                }
382
                        }
383 10740 nacho
                }
384
385
                return "<br>" + setHTMLTable(cabecera + propiedades);
386
        }
387 12716 bsanchez
388 10740 nacho
        /**
389
         * M?todo para crear la tabla de proyecci?n del raster en el
390
         * panel de informaci?n de propiedades de raster.
391 12716 bsanchez
         *
392 10740 nacho
         * @return String con el c?digo HTML que genera la tabla de proyecci?n.
393
         */
394
        public String tablaProjection() {
395
                rowColor = true;
396
                String propiedades = "";
397
                String projection = null;
398 12716 bsanchez
399 10740 nacho
                boolean datos = false;
400
401
                String cabProjection = PluginServices.getText(this, "projection");
402
403
                String cabecera = setHTMLTitleTable(cabProjection, 1);
404
405 13163 nacho
                String wktProj = null;
406
                try {
407
                        wktProj = op.getWktProjection();
408
                } catch (RasterDriverException e) {
409
                        //No se obtiene la proyecci?n pero no hacemos nada al respecto
410 10740 nacho
                }
411 15804 bsanchez
412 13163 nacho
                if(wktProj != null) {
413
                        projection = RasterUtilities.parserGdalProj(wktProj);
414
                        if (projection != null){
415
                                datos = true;
416
                                propiedades += setHTMLBasicProperty(null, projection);
417
                        }
418
                }
419 12716 bsanchez
420 10740 nacho
                if (datos == false) return "";
421
422
                return "<br>" + setHTMLTable(cabecera + propiedades);
423
        }
424 12716 bsanchez
425 10740 nacho
        /**
426
         * M?todo para crear la tabla de informaci?n de metadatos del raster en el
427
         * panel de informaci?n de propiedades de raster.
428 12716 bsanchez
         *
429 10740 nacho
         * @param Vector
430
         *          con los georasterfiles cargados en la capa.
431
         * @return String con el c?digo HTML que genera la tabla.
432
         */
433
        public String tablaMetadatos() {
434
                rowColor = true;
435
                String propiedades = "";
436
                String[] metadatos = null;
437 12716 bsanchez
438 10740 nacho
                DatasetMetadata meta = null;
439
                boolean datos = false;
440
441
                String cabMeta = PluginServices.getText(this, "metadata");
442
443
                String cabecera = setHTMLTitleTable(cabMeta, 2);
444
445
                meta = op.getMetadata()[selectedDataSet];
446
                if (meta != null){
447
                        metadatos = meta.getMetadataString();
448
                        for(int j = 0 ; j<metadatos.length ; j++){
449
                                datos = true;
450
                                int index = metadatos[j].indexOf("=");
451 12716 bsanchez
452 10740 nacho
                                propiedades += setHTMLBasicProperty(metadatos[j].substring(0,index), metadatos[j].substring(index+1));
453
                        }
454
                }
455 12716 bsanchez
456 10740 nacho
                if(datos == false)
457
                        return "";
458
459
                return "<br>" + setHTMLTable(cabecera + propiedades);
460
        }
461
462 12716 bsanchez
        /**
463 10740 nacho
         * M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
464
         * propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las
465
         * tablas.
466 12716 bsanchez
         *
467 10740 nacho
         */
468
        public void refresh() {
469
                boolean refresh = false;
470
                if (!jComboBoxEvent) {
471
                        // Set flag to ensure that an infinite loop is not created
472
                        jComboBoxEvent = true;
473
474
                        selectedDataSet = getJComboBox().getSelectedIndex();
475
                        if (selectedDataSet < 0) selectedDataSet = 0;
476
477
                        String nameFile = "";
478
                        getJComboBox().removeAllItems();
479
                        for (int i = 0; i < op.getFileCount(); i++) {
480
                                nameFile = op.getFileName()[i];
481
                                nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1);
482
                                getJComboBox().addItem(nameFile);
483
                        }
484
                        try {
485
                                // Select previous item
486
                                getJComboBox().setSelectedIndex(selectedDataSet);
487
                        } catch (IllegalArgumentException iae) {
488
                                selectedDataSet = 0;
489
                        }
490
491
                        jComboBoxEvent = false;
492
                        refresh = true;
493
                }
494
495
                String html = "";
496
                if ((refresh) && (op.getFileCount() >= 1)) {
497
                        html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos());
498
                }
499
500
                this.getJEditorPane().setContentType("text/html");
501
                this.getJEditorPane().setText(html);
502 11117 bsanchez
                this.getJEditorPane().setCaretPosition(0);
503 10740 nacho
        }
504
505 17699 nbrodin
        /*
506
         * (non-Javadoc)
507
         * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
508
         */
509 15781 bsanchez
        public void setReference(Object ref) {
510
                super.setReference(ref);
511 15804 bsanchez
512 15781 bsanchez
                if (!(ref instanceof FLayer))
513
                        return;
514 15804 bsanchez
515 15781 bsanchez
                FLayer lyr = (FLayer) ref;
516
517 10740 nacho
                if (lyr instanceof IRasterProperties) {
518
                        op = (IRasterProperties) lyr;
519
                        refresh();
520
                }
521
        }
522 15804 bsanchez
523 17699 nbrodin
        /*
524
         * (non-Javadoc)
525
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#selected()
526
         */
527 15781 bsanchez
        public void selected() {
528
                refresh();
529 10740 nacho
        }
530
531 17699 nbrodin
        /*
532
         * (non-Javadoc)
533
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
534
         */
535 10740 nacho
        public void accept() {
536
        }
537
538 17699 nbrodin
        /*
539
         * (non-Javadoc)
540
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#apply()
541
         */
542 10740 nacho
        public void apply() {
543
        }
544
545 17699 nbrodin
        /*
546
         * (non-Javadoc)
547
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
548
         */
549 10740 nacho
        public void cancel() {
550
        }
551
}