Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / InfoPanel.java @ 12716

History | View | Annotate | Download (14.7 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
package org.gvsig.rastertools.properties.panels;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.event.ItemEvent;
23
import java.awt.event.ItemListener;
24
import java.awt.geom.Point2D;
25
import java.io.File;
26

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

    
31
import org.gvsig.raster.dataset.properties.DatasetMetadata;
32
import org.gvsig.raster.gui.properties.dialog.IRegistrablePanel;
33
import org.gvsig.raster.hierarchy.IRasterProperties;
34
import org.gvsig.raster.util.RasterUtilities;
35

    
36
import com.iver.andami.PluginServices;
37
import com.iver.cit.gvsig.fmap.layers.FLayer;
38
import com.iver.utiles.swing.JComboBox;
39

    
40
/**
41
 * Panel de informaci?n sobre raster. La informaci?n que aparece en este panel
42
 * es la siguiente:
43
 * <P>
44
 * Informaci?n b?sica sobre el dataset:
45
 * <UL>
46
 * <LI>Fichero/s que forman el dataset</LI>
47
 * <LI>Tama?o por fichero</LI>
48
 * <LI>Ancho y alto</LI>
49
 * <LI>Formato</LI>
50
 * <LI>Si tiene georreferenciaci?n o no</LI>
51
 * <LI>N?mero de bandas</LI>
52
 * <LI>Tipo de dato.</LI>
53
 * </UL>
54
 * </P>
55
 * <P>
56
 * Datos de georreferenciaci?n:
57
 * <UL>
58
 * <LI>Proyecci?n</LI>
59
 * <LI>Coordenadas UTM o geogr?ficas</LI>
60
 * <LI>Tama?o de pixel</LI>
61
 * </UL>
62
 * </P>
63
 * <P>
64
 * Bandas:
65
 * <UL>
66
 * <LI>Bandas de todos los datasets asociados con el tipo de dato de cada uno y
67
 * banda de visualizaci?n asignada (R, G o B)</LI>
68
 * <LI>Coordenadas UTM o geogr?ficas</LI>
69
 * <LI>Tama?o de pixel</LI>
70
 * </UL>
71
 * </P>
72
 * <P>
73
 * Metadatos
74
 * </P>
75
 *
76
 * @author Nacho Brodin (nachobrodin@gmail.com)
77
 *
78
 */
79

    
80
public class InfoPanel extends JPanel implements IRegistrablePanel { //, ComponentListener {
81

    
82
        final private static long serialVersionUID = 0;
83

    
84
        private final String bgColor0    = "\"#FEEDD6\""; // light salmon
85
        private final String bgColor1    = "\"#EAEAEA\""; // light grey
86
        // private final String bgColor2    = "\"#F2FEFF\""; // light blue
87
        private final String bgColor3    = "\"#FBFFE1\""; // light yellow
88
        private final String bgColor4    = "\"#D6D6D6\""; // Gris
89
        private final String bgColorBody = "\"#FFFFFF\""; // light yellow
90

    
91
/*
92
        private final String bgColor0    = "\"#e7e3e7\""; // light salmon
93
        private final String bgColor1    = "\"#e7e3e7\""; // light grey
94
        // private final String bgColor2    = "\"#e7e3e7\""; // light blue
95
        private final String bgColor3    = "\"#e7e3e7\""; // light yellow
96
        private final String bgColor4    = "\"#e7e3e7\""; // Gris
97
        private final String bgColorBody = "\"#e7e3e7\""; // light yellow
98
*/
99

    
100
        private JScrollPane jScrollPane = null;
101
        public JEditorPane jEditorPane = null;
102
        private JComboBox jComboBox = null;
103
        private int selectedDataSet = 0;
104

    
105
        private boolean jComboBoxEvent = false;
106

    
107
        /**
108
         * Identificador del Panel
109
         */
110
        public String id = "info";
111

    
112
        /**
113
         * Cabecera de las columnas del dialogo
114
         */
115
        public Object[] columnNames = { "Propiedad", "Valor" };
116

    
117
        private IRasterProperties op = null;
118

    
119
        /**
120
         * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
121
         * es impar.
122
         */
123
        private boolean rowColor = true;
124

    
125
        /**
126
         * This is the default constructor
127
         */
128
        public InfoPanel() {
129
                super();
130
                id = PluginServices.getText(this, id);
131
                initialize();
132
        }
133

    
134
        /**
135
         * This method initializes this
136
         *
137
         * @return void
138
         */
139
        public void initialize() {
140
                this.setLayout(new BorderLayout(5, 5));
141
                this.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
142
                this.add(getJScrollPane(), BorderLayout.CENTER);
143
                this.add(getJComboBox(), BorderLayout.SOUTH);
144
                this.getJEditorPane().repaint();
145

    
146
                getJComboBox().addItemListener(new ItemListener() {
147
                        public void itemStateChanged(ItemEvent e) {
148
                                refresh();
149
                        }
150
                });
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
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), op.getFileName()[selectedDataSet]);
291
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "size"), RasterUtilities.formatFileSize(op.getFileSize()[selectedDataSet]) + " ");
292
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ancho_alto"), op.getPxWidth() + " X " + op.getPxHeight());
293
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "formato"), op.getFileFormat());
294
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "georref"), op.isGeoreferenced() ? PluginServices.getText(this, "si") : PluginServices.getText(this, "no"));
295
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas"), new Integer(op.getBandCount()).toString());
296
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tipo_dato"), RasterUtilities.typesToString(op.getDataType()[0]));
297

    
298
                return setHTMLTable(cabecera + propiedades);
299
        }
300

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

    
313
                String cabecera = setHTMLTitleTable(cabCoord, 2);
314

    
315
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_left"), op.getAffineTransform().getTranslateX() + "");
316
                Point2D pt = new Point2D.Double(op.getPxWidth(), op.getPxHeight());
317
                op.getAffineTransform().transform(pt, pt);
318
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_down"), pt.getY() + "");
319
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_right"), pt.getX() + "");
320
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_up"), op.getAffineTransform().getTranslateY() + "");
321
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_center"), "(" + (op.getMinX()+op.getMaxX())/2 + ", " +  (op.getMinY()+op.getMaxY())/2 + ")");
322

    
323
                double pixelSizeX = op.getAffineTransform().getScaleX();
324
                double pixelSizeY = op.getAffineTransform().getScaleY();
325

    
326
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixX"), String.valueOf(pixelSizeX));
327
                propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixY"), String.valueOf(pixelSizeY));
328

    
329
                return "<br>" + setHTMLTable(cabecera + propiedades);
330
        }
331

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

    
343
                String cabOrig = PluginServices.getText(this, "origin");
344

    
345
                String cabecera = setHTMLTitleTable(cabOrig, 2);
346
                bandType = RasterUtilities.typesToString(op.getDataType()[selectedDataSet]);
347

    
348
                for(int j = 0; j < op.getBandCountFromDataset()[selectedDataSet] ; j++){
349
                        propiedades += setHTMLBasicProperty("Band " + (j + 1), "Type=" + bandType + ", ColorInterp=" + op.getColourInterpretation(j, selectedDataSet));
350
                }
351

    
352
                return "<br>" + setHTMLTable(cabecera + propiedades);
353
        }
354

    
355
        /**
356
         * M?todo para crear la tabla de proyecci?n del raster en el
357
         * panel de informaci?n de propiedades de raster.
358
         *
359
         * @return String con el c?digo HTML que genera la tabla de proyecci?n.
360
         */
361
        public String tablaProjection() {
362
                rowColor = true;
363
                String propiedades = "";
364
                String projection = null;
365

    
366
                boolean datos = false;
367

    
368
                String cabProjection = PluginServices.getText(this, "projection");
369

    
370
                String cabecera = setHTMLTitleTable(cabProjection, 1);
371

    
372
                projection = RasterUtilities.parserGdalProj(op.getWktProjection());
373
                if (projection != null){
374
                        datos = true;
375
                        propiedades += setHTMLBasicProperty(null, projection);
376
                }
377

    
378
                if (datos == false) return "";
379

    
380
                return "<br>" + setHTMLTable(cabecera + propiedades);
381
        }
382

    
383
        /**
384
         * M?todo para crear la tabla de informaci?n de metadatos del raster en el
385
         * panel de informaci?n de propiedades de raster.
386
         *
387
         * @param Vector
388
         *          con los georasterfiles cargados en la capa.
389
         * @return String con el c?digo HTML que genera la tabla.
390
         */
391
        public String tablaMetadatos() {
392
                rowColor = true;
393
                String propiedades = "";
394
                String[] metadatos = null;
395

    
396
                DatasetMetadata meta = null;
397
                boolean datos = false;
398

    
399
                String cabMeta = PluginServices.getText(this, "metadata");
400

    
401
                String cabecera = setHTMLTitleTable(cabMeta, 2);
402

    
403
                meta = op.getMetadata()[selectedDataSet];
404
                if (meta != null){
405
                        metadatos = meta.getMetadataString();
406
                        for(int j = 0 ; j<metadatos.length ; j++){
407
                                datos = true;
408
                                int index = metadatos[j].indexOf("=");
409

    
410
                                propiedades += setHTMLBasicProperty(metadatos[j].substring(0,index), metadatos[j].substring(index+1));
411
                        }
412
                }
413

    
414
                if(datos == false)
415
                        return "";
416

    
417
                return "<br>" + setHTMLTable(cabecera + propiedades);
418
        }
419

    
420
        /**
421
         * M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
422
         * propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las
423
         * tablas.
424
         *
425
         */
426
        public void refresh() {
427
                boolean refresh = false;
428
                if (!jComboBoxEvent) {
429
                        // Set flag to ensure that an infinite loop is not created
430
                        jComboBoxEvent = true;
431

    
432
                        selectedDataSet = getJComboBox().getSelectedIndex();
433
                        if (selectedDataSet < 0) selectedDataSet = 0;
434

    
435
                        String nameFile = "";
436
                        getJComboBox().removeAllItems();
437
                        for (int i = 0; i < op.getFileCount(); i++) {
438
                                nameFile = op.getFileName()[i];
439
                                nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1);
440
                                getJComboBox().addItem(nameFile);
441
                        }
442
                        try {
443
                                // Select previous item
444
                                getJComboBox().setSelectedIndex(selectedDataSet);
445
                        } catch (IllegalArgumentException iae) {
446
                                selectedDataSet = 0;
447
                        }
448

    
449
                        jComboBoxEvent = false;
450
                        refresh = true;
451
                }
452

    
453
                String html = "";
454
                if ((refresh) && (op.getFileCount() >= 1)) {
455
                        html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos());
456
                }
457

    
458
                this.getJEditorPane().setContentType("text/html");
459
                this.getJEditorPane().setText(html);
460
                this.getJEditorPane().setCaretPosition(0);
461
        }
462

    
463
        /*
464
         * (non-Javadoc)
465
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
466
         */
467
        public void setLayer(FLayer lyr) {
468
                if (lyr instanceof IRasterProperties) {
469
                        op = (IRasterProperties) lyr;
470
                        refresh();
471
                }
472
        }
473

    
474
        /*
475
         * (non-Javadoc)
476
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
477
         */
478
        public String getID() {
479
                return id;
480
        }
481

    
482
        /*
483
         * (non-Javadoc)
484
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
485
         */
486
        public void selectTab(String id) {
487
                if (this.id.equals(id))
488
                        refresh();
489
        }
490

    
491
        public void accept() {
492

    
493
        }
494

    
495
        public void apply() {
496

    
497
        }
498

    
499
        public void cancel() {
500

    
501
        }
502

    
503
        public void setComponentSize(int w, int h) {
504

    
505
        }
506
}