root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / InfoPanel.java @ 11117
History | View | Annotate | Download (14.7 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 | import java.awt.event.ItemEvent; |
||
23 | import java.awt.event.ItemListener; |
||
24 | import java.io.File; |
||
25 | |||
26 | import javax.swing.JEditorPane; |
||
27 | import javax.swing.JPanel; |
||
28 | import javax.swing.JScrollPane; |
||
29 | |||
30 | 10940 | nacho | import org.gvsig.raster.dataset.properties.DatasetMetadata; |
31 | 10740 | nacho | import org.gvsig.raster.shared.IRasterProperties; |
32 | 10940 | nacho | import org.gvsig.raster.util.RasterUtilities; |
33 | 10740 | nacho | import org.gvsig.rastertools.properties.dialog.IRegistrablePanel; |
34 | |||
35 | import com.iver.andami.PluginServices; |
||
36 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
37 | import com.iver.utiles.swing.JComboBox; |
||
38 | |||
39 | /**
|
||
40 | * Panel de informaci?n sobre raster. La informaci?n que aparece en este panel
|
||
41 | * es la siguiente:
|
||
42 | * <P>
|
||
43 | * Informaci?n b?sica sobre el dataset:
|
||
44 | * <UL>
|
||
45 | * <LI>Fichero/s que forman el dataset</LI>
|
||
46 | * <LI>Tama?o por fichero</LI>
|
||
47 | * <LI>Ancho y alto</LI>
|
||
48 | * <LI>Formato</LI>
|
||
49 | * <LI>Si tiene georreferenciaci?n o no</LI>
|
||
50 | * <LI>N?mero de bandas</LI>
|
||
51 | * <LI>Tipo de dato.</LI>
|
||
52 | * </UL>
|
||
53 | * </P>
|
||
54 | * <P>
|
||
55 | * Datos de georreferenciaci?n:
|
||
56 | * <UL>
|
||
57 | * <LI>Proyecci?n</LI>
|
||
58 | * <LI>Coordenadas UTM o geogr?ficas</LI>
|
||
59 | * <LI>Tama?o de pixel</LI>
|
||
60 | * </UL>
|
||
61 | * </P>
|
||
62 | * <P>
|
||
63 | * Bandas:
|
||
64 | * <UL>
|
||
65 | * <LI>Bandas de todos los datasets asociados con el tipo de dato de cada uno y
|
||
66 | * banda de visualizaci?n asignada (R, G o B)</LI>
|
||
67 | * <LI>Coordenadas UTM o geogr?ficas</LI>
|
||
68 | * <LI>Tama?o de pixel</LI>
|
||
69 | * </UL>
|
||
70 | * </P>
|
||
71 | * <P>
|
||
72 | * Metadatos
|
||
73 | * </P>
|
||
74 | *
|
||
75 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
76 | *
|
||
77 | */
|
||
78 | |||
79 | public class InfoPanel extends JPanel implements IRegistrablePanel { //, ComponentListener { |
||
80 | |||
81 | final private static long serialVersionUID = 0; |
||
82 | |||
83 | private final String bgColor0 = "\"#FEEDD6\""; // light salmon |
||
84 | private final String bgColor1 = "\"#EAEAEA\""; // light grey |
||
85 | // private final String bgColor2 = "\"#F2FEFF\""; // light blue
|
||
86 | private final String bgColor3 = "\"#FBFFE1\""; // light yellow |
||
87 | private final String bgColor4 = "\"#D6D6D6\""; // Gris |
||
88 | private final String bgColorBody = "\"#FFFFFF\""; // light yellow |
||
89 | |||
90 | /*
|
||
91 | private final String bgColor0 = "\"#e7e3e7\""; // light salmon
|
||
92 | private final String bgColor1 = "\"#e7e3e7\""; // light grey
|
||
93 | // private final String bgColor2 = "\"#e7e3e7\""; // light blue
|
||
94 | private final String bgColor3 = "\"#e7e3e7\""; // light yellow
|
||
95 | private final String bgColor4 = "\"#e7e3e7\""; // Gris
|
||
96 | private final String bgColorBody = "\"#e7e3e7\""; // light yellow
|
||
97 | */
|
||
98 | |||
99 | private JScrollPane jScrollPane = null; |
||
100 | public JEditorPane jEditorPane = null; |
||
101 | private JComboBox jComboBox = null; |
||
102 | private int selectedDataSet = 0; |
||
103 | |||
104 | private boolean jComboBoxEvent = false; |
||
105 | |||
106 | /**
|
||
107 | * Identificador del Panel
|
||
108 | */
|
||
109 | public String id = "info"; |
||
110 | |||
111 | /**
|
||
112 | * Cabecera de las columnas del dialogo
|
||
113 | */
|
||
114 | public Object[] columnNames = { "Propiedad", "Valor" }; |
||
115 | |||
116 | private IRasterProperties op = null; |
||
117 | |||
118 | /**
|
||
119 | * Booleano que est? a true cuando la fila a dibujar es par y a false cuando
|
||
120 | * es impar.
|
||
121 | */
|
||
122 | private boolean rowColor = true; |
||
123 | |||
124 | /**
|
||
125 | * This is the default constructor
|
||
126 | */
|
||
127 | public InfoPanel() {
|
||
128 | super();
|
||
129 | id = PluginServices.getText(this, id);
|
||
130 | initialize(); |
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * This method initializes this
|
||
135 | *
|
||
136 | * @return void
|
||
137 | */
|
||
138 | public void initialize() { |
||
139 | 11117 | bsanchez | this.setLayout(new BorderLayout(5, 5)); |
140 | this.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
||
141 | this.add(getJScrollPane(), BorderLayout.CENTER); |
||
142 | this.add(getJComboBox(), BorderLayout.SOUTH); |
||
143 | 10740 | nacho | this.getJEditorPane().repaint();
|
144 | |||
145 | getJComboBox().addItemListener(new ItemListener() { |
||
146 | public void itemStateChanged(ItemEvent e) { |
||
147 | refresh(); |
||
148 | } |
||
149 | }); |
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * This method initializes jScrollPane
|
||
154 | *
|
||
155 | * @return javax.swing.JScrollPane
|
||
156 | */
|
||
157 | private JScrollPane getJScrollPane() { |
||
158 | if (jScrollPane == null) { |
||
159 | jScrollPane = new JScrollPane(); |
||
160 | jScrollPane.setViewportView(getJEditorPane()); |
||
161 | } |
||
162 | return jScrollPane;
|
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | * This method initializes jComboBox
|
||
167 | *
|
||
168 | * @return javax.swing.JComboBox
|
||
169 | */
|
||
170 | private JComboBox getJComboBox() { |
||
171 | if (jComboBox == null) { |
||
172 | jComboBox = new JComboBox(); |
||
173 | } |
||
174 | return jComboBox;
|
||
175 | } |
||
176 | |||
177 | /**
|
||
178 | * This method initializes jEditorPane
|
||
179 | *
|
||
180 | * @return javax.swing.JEditorPane
|
||
181 | */
|
||
182 | private JEditorPane getJEditorPane() { |
||
183 | if (jEditorPane == null) { |
||
184 | jEditorPane = new JEditorPane(); |
||
185 | jEditorPane.setEditable(false);
|
||
186 | jEditorPane.setContentType("text/html");
|
||
187 | } |
||
188 | return jEditorPane;
|
||
189 | } |
||
190 | |||
191 | public void resetTable() { |
||
192 | this.jEditorPane = null; |
||
193 | } |
||
194 | |||
195 | /**
|
||
196 | * Controla la alternatividad de colores en la tabla.
|
||
197 | *
|
||
198 | * @return Cadena con el color de la fila siguiente.
|
||
199 | */
|
||
200 | private String getColor() { |
||
201 | String color = (rowColor ? bgColor0 : bgColor1);
|
||
202 | rowColor = !rowColor; |
||
203 | return color;
|
||
204 | } |
||
205 | |||
206 | /**
|
||
207 | * Obtiene una entrada de la tabla en formato HTML a partir de una propiedad,
|
||
208 | * un valor y un color.
|
||
209 | *
|
||
210 | * @param prop
|
||
211 | * Nombre de la propiedad
|
||
212 | * @param value
|
||
213 | * Valor
|
||
214 | * @param color
|
||
215 | * Color
|
||
216 | *
|
||
217 | * @return Entrada HTML de la tabla
|
||
218 | */
|
||
219 | private String setHTMLBasicProperty(String prop, String value) { |
||
220 | String content = "<tr valign=\"top\">"; |
||
221 | if (prop != null) |
||
222 | content += "<td bgcolor=" + bgColor4 + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + prop + ": </font></td>"; |
||
223 | content += "<td bgcolor=" + getColor() + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value + "</font></td>"; |
||
224 | content += "</tr>";
|
||
225 | |||
226 | return content;
|
||
227 | } |
||
228 | |||
229 | /**
|
||
230 | * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
|
||
231 | *
|
||
232 | * @param title
|
||
233 | * Nombre del titulo
|
||
234 | * @param colspan
|
||
235 | * Numero de celdas que ocupara el titulo
|
||
236 | *
|
||
237 | * @return Entrada HTML del titulo
|
||
238 | */
|
||
239 | private String setHTMLTitleTable(String title, int colspan) { |
||
240 | return
|
||
241 | "<tr valign=\"middle\" >" +
|
||
242 | "<td bgcolor=" + bgColor3 + " align=\"center\" colspan=\"" + colspan + "\"><font face=\"Arial\" size=\"3\"><b> " + title + "</b></font></td>" + |
||
243 | "</tr>";
|
||
244 | } |
||
245 | |||
246 | /**
|
||
247 | * Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
|
||
248 | *
|
||
249 | * @param content
|
||
250 | * Codigo HTML de las filas que componen la tabla.
|
||
251 | *
|
||
252 | * @return Entrada HTML de la tabla completa
|
||
253 | */
|
||
254 | private String setHTMLTable(String content) { |
||
255 | return "<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">" + content + "</table>"; |
||
256 | } |
||
257 | |||
258 | /**
|
||
259 | * Genera el HTML para todo el contenido.
|
||
260 | *
|
||
261 | * @param content
|
||
262 | * Codigo HTML que ira en el <body>...</body>.
|
||
263 | *
|
||
264 | * @return HTML completo
|
||
265 | */
|
||
266 | private String setHTMLBody(String content) { |
||
267 | String html = "<html>"; |
||
268 | html += "<body bgcolor=" + bgColorBody + " topmargin=\"0\" marginheight=\"0\">"; |
||
269 | html += content; |
||
270 | html += "</body>";
|
||
271 | html += "</html>";
|
||
272 | return html;
|
||
273 | } |
||
274 | |||
275 | /**
|
||
276 | * M?todo que crea el c?digo HTML para la tabla de informaci?n general dentro
|
||
277 | * del panel de informaci?n de raster
|
||
278 | *
|
||
279 | * @return String con el c?figo HTML que corresponde con la tabla de
|
||
280 | * informaci?n general
|
||
281 | */
|
||
282 | public String tablaInfo() { |
||
283 | rowColor = true;
|
||
284 | String cabInfo = PluginServices.getText(this, "general_info"); |
||
285 | String propiedades = ""; |
||
286 | |||
287 | String cabecera = setHTMLTitleTable(cabInfo, 2); |
||
288 | |||
289 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), op.getFileName()[selectedDataSet]); |
||
290 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "size"), RasterUtilities.formatFileSize(op.getFileSize()[selectedDataSet]) + " "); |
||
291 | 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 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas"), new Integer(op.getBandCount()).toString()); |
||
295 | 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 | *
|
||
304 | * @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 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_left"), op.getMinX() + ""); |
||
315 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_down"), op.getMinY() + ""); |
||
316 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_right"), op.getMaxX() + ""); |
||
317 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_up"), op.getMaxY() + ""); |
||
318 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_center"), "(" + (op.getMinX()+op.getMaxX())/2 + ", " + (op.getMinY()+op.getMaxY())/2 + ")"); |
||
319 | |||
320 | double tamRealX = op.getMaxX() - op.getMinX();
|
||
321 | double tamRealY = op.getMinY() - op.getMaxY();
|
||
322 | |||
323 | double tamX = Math.round((tamRealX / op.getPxWidth()) * 10000000); |
||
324 | double tamY = Math.round((tamRealY / op.getPxHeight()) * 10000000); |
||
325 | |||
326 | String tamPixX = String.valueOf(tamX / 10000000); |
||
327 | String tamPixY = String.valueOf(tamY / 10000000); |
||
328 | |||
329 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixX"), tamPixX); |
||
330 | propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixY"), tamPixY); |
||
331 | |||
332 | return "<br>" + setHTMLTable(cabecera + propiedades); |
||
333 | } |
||
334 | |||
335 | /**
|
||
336 | * M?todo que crea la tabla de origen de datos dentro del panel
|
||
337 | * de Informaci?n.
|
||
338 | *
|
||
339 | * @return String con el c?digo HTML de la tabla.
|
||
340 | */
|
||
341 | public String tablaOrigen() { |
||
342 | rowColor = true;
|
||
343 | String propiedades = ""; |
||
344 | String bandType = ""; |
||
345 | |||
346 | String cabOrig = PluginServices.getText(this, "origin"); |
||
347 | |||
348 | String cabecera = setHTMLTitleTable(cabOrig, 2); |
||
349 | bandType = RasterUtilities.typesToString(op.getDataType()[selectedDataSet]); |
||
350 | |||
351 | for(int j = 0; j < op.getBandCountFromDataset()[selectedDataSet] ; j++){ |
||
352 | propiedades += setHTMLBasicProperty("Band " + (j + 1), "Type=" + bandType + ", ColorInterp=" + op.getColourInterpretation(j, selectedDataSet)); |
||
353 | } |
||
354 | |||
355 | return "<br>" + setHTMLTable(cabecera + propiedades); |
||
356 | } |
||
357 | |||
358 | /**
|
||
359 | * M?todo para crear la tabla de proyecci?n del raster en el
|
||
360 | * panel de informaci?n de propiedades de raster.
|
||
361 | *
|
||
362 | * @return String con el c?digo HTML que genera la tabla de proyecci?n.
|
||
363 | */
|
||
364 | public String tablaProjection() { |
||
365 | rowColor = true;
|
||
366 | String propiedades = ""; |
||
367 | String projection = null; |
||
368 | |||
369 | boolean datos = false; |
||
370 | |||
371 | String cabProjection = PluginServices.getText(this, "projection"); |
||
372 | |||
373 | String cabecera = setHTMLTitleTable(cabProjection, 1); |
||
374 | |||
375 | projection = RasterUtilities.parserGdalProj(op.getStringProjection()); |
||
376 | if (projection != null){ |
||
377 | datos = true;
|
||
378 | propiedades += setHTMLBasicProperty(null, projection);
|
||
379 | } |
||
380 | |||
381 | if (datos == false) return ""; |
||
382 | |||
383 | return "<br>" + setHTMLTable(cabecera + propiedades); |
||
384 | } |
||
385 | |||
386 | /**
|
||
387 | * M?todo para crear la tabla de informaci?n de metadatos del raster en el
|
||
388 | * panel de informaci?n de propiedades de raster.
|
||
389 | *
|
||
390 | * @param Vector
|
||
391 | * con los georasterfiles cargados en la capa.
|
||
392 | * @return String con el c?digo HTML que genera la tabla.
|
||
393 | */
|
||
394 | public String tablaMetadatos() { |
||
395 | rowColor = true;
|
||
396 | String propiedades = ""; |
||
397 | String[] metadatos = null; |
||
398 | |||
399 | DatasetMetadata meta = null;
|
||
400 | boolean datos = false; |
||
401 | |||
402 | String cabMeta = PluginServices.getText(this, "metadata"); |
||
403 | |||
404 | String cabecera = setHTMLTitleTable(cabMeta, 2); |
||
405 | |||
406 | meta = op.getMetadata()[selectedDataSet]; |
||
407 | if (meta != null){ |
||
408 | metadatos = meta.getMetadataString(); |
||
409 | for(int j = 0 ; j<metadatos.length ; j++){ |
||
410 | datos = true;
|
||
411 | int index = metadatos[j].indexOf("="); |
||
412 | |||
413 | propiedades += setHTMLBasicProperty(metadatos[j].substring(0,index), metadatos[j].substring(index+1)); |
||
414 | } |
||
415 | } |
||
416 | |||
417 | if(datos == false) |
||
418 | return ""; |
||
419 | |||
420 | return "<br>" + setHTMLTable(cabecera + propiedades); |
||
421 | } |
||
422 | |||
423 | /**
|
||
424 | * M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
|
||
425 | * propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las
|
||
426 | * tablas.
|
||
427 | *
|
||
428 | */
|
||
429 | public void refresh() { |
||
430 | boolean refresh = false; |
||
431 | if (!jComboBoxEvent) {
|
||
432 | // Set flag to ensure that an infinite loop is not created
|
||
433 | jComboBoxEvent = true;
|
||
434 | |||
435 | selectedDataSet = getJComboBox().getSelectedIndex(); |
||
436 | if (selectedDataSet < 0) selectedDataSet = 0; |
||
437 | |||
438 | String nameFile = ""; |
||
439 | getJComboBox().removeAllItems(); |
||
440 | for (int i = 0; i < op.getFileCount(); i++) { |
||
441 | nameFile = op.getFileName()[i]; |
||
442 | nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1); |
||
443 | getJComboBox().addItem(nameFile); |
||
444 | } |
||
445 | try {
|
||
446 | // Select previous item
|
||
447 | getJComboBox().setSelectedIndex(selectedDataSet); |
||
448 | } catch (IllegalArgumentException iae) { |
||
449 | selectedDataSet = 0;
|
||
450 | } |
||
451 | |||
452 | jComboBoxEvent = false;
|
||
453 | refresh = true;
|
||
454 | } |
||
455 | |||
456 | String html = ""; |
||
457 | if ((refresh) && (op.getFileCount() >= 1)) { |
||
458 | html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos()); |
||
459 | } |
||
460 | |||
461 | this.getJEditorPane().setContentType("text/html"); |
||
462 | this.getJEditorPane().setText(html);
|
||
463 | 11117 | bsanchez | this.getJEditorPane().setCaretPosition(0); |
464 | 10740 | nacho | } |
465 | |||
466 | /*
|
||
467 | * (non-Javadoc)
|
||
468 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
||
469 | */
|
||
470 | public void setLayer(FLayer lyr) { |
||
471 | if (lyr instanceof IRasterProperties) { |
||
472 | op = (IRasterProperties) lyr; |
||
473 | refresh(); |
||
474 | } |
||
475 | } |
||
476 | |||
477 | /*
|
||
478 | * (non-Javadoc)
|
||
479 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
|
||
480 | */
|
||
481 | public String getID() { |
||
482 | return id;
|
||
483 | } |
||
484 | |||
485 | /*
|
||
486 | * (non-Javadoc)
|
||
487 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
||
488 | */
|
||
489 | public void selectTab(String id) { |
||
490 | if (this.id.equals(id)) |
||
491 | refresh(); |
||
492 | } |
||
493 | |||
494 | public void accept() { |
||
495 | |||
496 | } |
||
497 | |||
498 | public void apply() { |
||
499 | |||
500 | } |
||
501 | |||
502 | public void cancel() { |
||
503 | |||
504 | } |
||
505 | |||
506 | public void setComponentSize(int w, int h) { |
||
507 | |||
508 | } |
||
509 | } |