Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / layer / properties / InfoPanel3D.java @ 25901

History | View | Annotate | Download (17.4 KB)

1
/* 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

    
20
package org.gvsig.gvsig3dgui.layer.properties;
21

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

    
28
import javax.swing.JEditorPane;
29
import javax.swing.JScrollPane;
30

    
31
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
32
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
33
import org.gvsig.raster.dataset.BandAccessException;
34
import org.gvsig.raster.dataset.io.RasterDriverException;
35
import org.gvsig.raster.dataset.properties.DatasetMetadata;
36
import org.gvsig.raster.datastruct.Extent;
37
import org.gvsig.raster.hierarchy.IRasterProperties;
38
import org.gvsig.raster.util.RasterUtilities;
39

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

    
91
        private JScrollPane       jScrollPane     = null;
92
        public JEditorPane        jEditorPane     = null;
93
        private JComboBox         jComboBox       = null;
94
        private int               selectedDataSet = 0;
95

    
96
        private boolean           jComboBoxEvent  = false;
97

    
98
        /**
99
         * Cabecera de las columnas del dialogo
100
         */
101
        public Object[]           columnNames     = { "Propiedad", "Valor" };
102

    
103
        private IRasterProperties op              = null;
104

    
105
        /**
106
         * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
107
         * es impar.
108
         */
109
        private boolean           rowColor        = true;
110
        
111
        
112
        private Layer3DProps props3D;
113
        private FLayer lyr;
114
        private FLyrRasterSE lyr2;
115

    
116
        /**
117
         * This is the default constructor
118
         */
119
        public InfoPanel3D() {
120
                super();
121
                
122
                initialize();
123
        }
124

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

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

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

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

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

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

    
192
        public void resetTable() {
193
                this.jEditorPane = null;
194
        }
195

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

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

    
227
                return content;
228
        }
229

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

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

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

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

    
288
                String cabecera = setHTMLTitleTable(cabInfo, 2);
289
                
290
                if(op!=null) {
291
                        
292
                        op.getFileFormat();
293
                        
294
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), op.getFileName()[selectedDataSet]);
295
                        long fileSize = op.getFileSize()[selectedDataSet];
296
                        if (op instanceof FLyrRasterSE) {
297
                                FLyrRasterSE rasterSE = (FLyrRasterSE) op;
298
                                fileSize = rasterSE.getDataSource().getDataset(selectedDataSet)[0].getFileSize();
299
                        }
300
                        
301
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "size"), RasterUtilities.formatFileSize(fileSize) + " ");
302
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ancho_alto"), op.getPxWidth() + " X " + op.getPxHeight());
303
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "formato"), op.getFileFormat());
304
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "georref"), op.isGeoreferenced() ? PluginServices.getText(this, "si") : PluginServices.getText(this, "no"));
305
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas"), new Integer(op.getBandCountFromDataset()[selectedDataSet]).toString());
306
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tipo_dato"), RasterUtilities.typesToString(op.getDataType()[0]));
307
                }
308
                else {
309
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), lyr.getName());
310
                        if(lyr.getInfoString() != null)
311
                                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "Informacion"), lyr.getInfoString());
312
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "Valor_minimo_de_escala"),String.valueOf(lyr.getMinScale()));
313
                        propiedades += setHTMLBasicProperty(PluginServices.getText(this, "Valor_maximo_de_escala"),String.valueOf(lyr.getMaxScale()));
314
                }
315
                
316
                return setHTMLTable(cabecera + propiedades);
317
        }
318

    
319
        /**
320
         * M?todo que crea el c?digo HTML para la tabla de Coordenadas Geogr?ficas
321
         * dentro del panel de informaci?n de raster
322
         *
323
         * @return String con el c?digo HTML que corresponde con la tabla de
324
         *         Coordenadas Geogr?ficas
325
         */
326
        public String tablaCoord() {
327
                rowColor = true;
328
                String cabCoord = PluginServices.getText(this, "coor_geograficas");
329
                String propiedades = "";
330

    
331
                String cabecera = setHTMLTitleTable(cabCoord, 2);
332

    
333
                Extent ext = op.getFullRasterExtent();
334
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ul"), ext.getULX() + ", " + ext.getULY());
335
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "lr"), ext.getLRX() + ", " + ext.getLRY());
336
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ur"), ext.getURX() + ", " + ext.getURY());
337
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ll"), ext.getLLX() + ", " + ext.getLLY());
338

    
339
                double pixelSizeX = op.getAffineTransform().getScaleX();
340
                double pixelSizeY = op.getAffineTransform().getScaleY();
341
                double rotX = op.getAffineTransform().getShearX();
342
                double rotY = op.getAffineTransform().getShearY();
343

    
344
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixX"), String.valueOf(pixelSizeX));
345
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixY"), String.valueOf(pixelSizeY));
346
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "rotX"), String.valueOf(rotX));
347
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "rotY"), String.valueOf(rotY));
348

    
349
                return "<br>" + setHTMLTable(cabecera + propiedades);
350
        }
351

    
352
        /**
353
         * M?todo que crea la tabla de origen de datos dentro del panel
354
         * de Informaci?n.
355
         *
356
         * @return String con el c?digo HTML de la tabla.
357
         */
358
        public String tablaOrigen() {
359
                rowColor = true;
360
                String propiedades = "";
361
                String bandType = "";
362

    
363
                String cabOrig = PluginServices.getText(this, "origin");
364

    
365
                String cabecera = setHTMLTitleTable(cabOrig, 2);
366

    
367
                for(int j = 0; j < op.getBandCountFromDataset()[selectedDataSet] ; j++) {
368
                        bandType = RasterUtilities.typesToString(op.getDataType()[j]);
369

    
370
                        String data = "";
371
                        data += "Type=" + bandType;
372
                        data += ", ";
373
                        data += "ColorInterp=" + op.getColorInterpretation(j, selectedDataSet);
374
                        data += ", ";
375
                        data += "NoData=" + ((FLyrRasterSE) op).getNoDataValue();
376

    
377
                        propiedades += setHTMLBasicProperty("Band " + (j + 1), data);
378
                        
379
                        if (op instanceof FLyrRasterSE) {
380
                                FLyrRasterSE rasterSE = (FLyrRasterSE) op;
381
                                data = "";
382
                                try {
383
                                        int count = rasterSE.getDataSource().getDataset(selectedDataSet)[0].getOverviewCount(j);
384
                                        if (count > 0) {
385
                                                for (int i = 0; i < count; i++) {
386
                                                        if (!data.equals(""))
387
                                                                data += ", ";
388
                                        //                data += rasterSE.getDataSource().getDataset(selectedDataSet)[0].getOverviewWidth(j, i);
389
                                                        data += "x";
390
                                        //                data += rasterSE.getDataSource().getDataset(selectedDataSet)[0].getOverviewHeight(j, i);
391
                                                }
392
                                                propiedades += setHTMLBasicProperty("Overviews", data);
393
                                        }
394
                                } catch (BandAccessException e) {
395
                                        // No se obtiene el contador de overviews
396
                                } catch (RasterDriverException e) {
397
                                        // No se obtiene el contador de overviews
398
                                }
399
                        }
400
                }
401

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

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

    
416
                boolean datos = false;
417

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

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

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

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

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

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

    
443
        /**
444
         * M?todo para crear la tabla de informaci?n de 3D 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
                DatasetMetadata meta = null;
457
                boolean datos = false;
458

    
459
                String cabMeta = PluginServices.getText(this, "metadata");
460

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

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

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

    
474
                if(datos == false)
475
                        return "";
476

    
477
                return "<br>" + setHTMLTable(cabecera + propiedades);
478
        }
479

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

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

    
496
                        String nameFile = "";
497
                        getJComboBox().removeAllItems();
498
                        if(op!=null) {
499
                                for (int i = 0; i < op.getFileCount(); i++) {
500
                                        nameFile = op.getFileName()[i];
501
                                        nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1);
502
                                        getJComboBox().addItem(nameFile);
503
                                }
504
                                try {
505
                                        // Select previous item
506
                                        getJComboBox().setSelectedIndex(selectedDataSet);
507
                                } catch (IllegalArgumentException iae) {
508
                                        selectedDataSet = 0;
509
                                }
510
        
511
                                jComboBoxEvent = false;
512
                                refresh = true;
513
                        }
514
                }
515

    
516
                String html = "";
517
                if ((refresh) && (op.getFileCount() >= 1)) {
518
                        html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos());
519
                }
520
                else
521
                        html = setHTMLBody(tablaInfo());
522

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

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

    
535
                if (!(ref instanceof FLayer))
536
                        return;
537

    
538

    
539
                lyr = (FLayer) ref;
540
                if (lyr instanceof IRasterProperties) {
541
                        op = (IRasterProperties) lyr;
542
                        refresh();
543
                }
544
                        
545
        }
546

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

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

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

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