root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / InfoPanel.java @ 10940
History | View | Annotate | Download (15.1 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.GridBagConstraints; |
23 |
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.JPanel; |
29 |
import javax.swing.JScrollPane; |
30 |
|
31 |
import org.gvsig.raster.dataset.properties.DatasetMetadata; |
32 |
import org.gvsig.raster.shared.IRasterProperties; |
33 |
import org.gvsig.raster.util.RasterUtilities; |
34 |
import org.gvsig.rastertools.properties.dialog.IRegistrablePanel; |
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 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
141 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
142 |
gridBagConstraints.gridx = 0;
|
143 |
gridBagConstraints.gridy = 0;
|
144 |
gridBagConstraints.weightx = 1.0;
|
145 |
gridBagConstraints.weighty = 1.0;
|
146 |
gridBagConstraints.insets = new java.awt.Insets(5, 8, 5, 8); |
147 |
// this.setLayout(new GridBagLayout());
|
148 |
this.setLayout(new BorderLayout()); |
149 |
this.add(getJComboBox(), BorderLayout.NORTH); |
150 |
this.add(getJScrollPane(), BorderLayout.CENTER/* gridBagConstraints */); |
151 |
// this.addComponentListener(this);
|
152 |
this.getJEditorPane().repaint();
|
153 |
|
154 |
getJComboBox().addItemListener(new ItemListener() { |
155 |
public void itemStateChanged(ItemEvent e) { |
156 |
refresh(); |
157 |
} |
158 |
}); |
159 |
} |
160 |
|
161 |
/**
|
162 |
* This method initializes jScrollPane
|
163 |
*
|
164 |
* @return javax.swing.JScrollPane
|
165 |
*/
|
166 |
private JScrollPane getJScrollPane() { |
167 |
if (jScrollPane == null) { |
168 |
jScrollPane = new JScrollPane(); |
169 |
jScrollPane.setViewportView(getJEditorPane()); |
170 |
} |
171 |
return jScrollPane;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* This method initializes jComboBox
|
176 |
*
|
177 |
* @return javax.swing.JComboBox
|
178 |
*/
|
179 |
private JComboBox getJComboBox() { |
180 |
if (jComboBox == null) { |
181 |
jComboBox = new JComboBox(); |
182 |
} |
183 |
return jComboBox;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* This method initializes jEditorPane
|
188 |
*
|
189 |
* @return javax.swing.JEditorPane
|
190 |
*/
|
191 |
private JEditorPane getJEditorPane() { |
192 |
if (jEditorPane == null) { |
193 |
jEditorPane = new JEditorPane(); |
194 |
jEditorPane.setEditable(false);
|
195 |
jEditorPane.setContentType("text/html");
|
196 |
} |
197 |
return jEditorPane;
|
198 |
} |
199 |
|
200 |
public void resetTable() { |
201 |
this.jEditorPane = null; |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Controla la alternatividad de colores en la tabla.
|
206 |
*
|
207 |
* @return Cadena con el color de la fila siguiente.
|
208 |
*/
|
209 |
private String getColor() { |
210 |
String color = (rowColor ? bgColor0 : bgColor1);
|
211 |
rowColor = !rowColor; |
212 |
return color;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Obtiene una entrada de la tabla en formato HTML a partir de una propiedad,
|
217 |
* un valor y un color.
|
218 |
*
|
219 |
* @param prop
|
220 |
* Nombre de la propiedad
|
221 |
* @param value
|
222 |
* Valor
|
223 |
* @param color
|
224 |
* Color
|
225 |
*
|
226 |
* @return Entrada HTML de la tabla
|
227 |
*/
|
228 |
private String setHTMLBasicProperty(String prop, String value) { |
229 |
String content = "<tr valign=\"top\">"; |
230 |
if (prop != null) |
231 |
content += "<td bgcolor=" + bgColor4 + "align=\"right\" width=\"140\"><font face=\"Arial\" size=\"3\">" + prop + ": </font></td>"; |
232 |
content += "<td bgcolor=" + getColor() + "align=\"left\"><font face=\"Arial\" size=\"3\">" + value + "</font></td>"; |
233 |
content += "</tr>";
|
234 |
|
235 |
return content;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
|
240 |
*
|
241 |
* @param title
|
242 |
* Nombre del titulo
|
243 |
* @param colspan
|
244 |
* Numero de celdas que ocupara el titulo
|
245 |
*
|
246 |
* @return Entrada HTML del titulo
|
247 |
*/
|
248 |
private String setHTMLTitleTable(String title, int colspan) { |
249 |
return
|
250 |
"<tr valign=\"middle\" >" +
|
251 |
"<td bgcolor=" + bgColor3 + " align=\"center\" colspan=\"" + colspan + "\"><font face=\"Arial\" size=\"3\"><b> " + title + "</b></font></td>" + |
252 |
"</tr>";
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* Obtiene una cabecera de tabla en formato HTML a partir de un titulo.
|
257 |
*
|
258 |
* @param content
|
259 |
* Codigo HTML de las filas que componen la tabla.
|
260 |
*
|
261 |
* @return Entrada HTML de la tabla completa
|
262 |
*/
|
263 |
private String setHTMLTable(String content) { |
264 |
return "<table cellpadding=\"0\" cellspacing=\"0\" align=\"center\" width=\"100%\">" + content + "</table>"; |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Genera el HTML para todo el contenido.
|
269 |
*
|
270 |
* @param content
|
271 |
* Codigo HTML que ira en el <body>...</body>.
|
272 |
*
|
273 |
* @return HTML completo
|
274 |
*/
|
275 |
private String setHTMLBody(String content) { |
276 |
String html = "<html>"; |
277 |
html += "<body bgcolor=" + bgColorBody + " topmargin=\"0\" marginheight=\"0\">"; |
278 |
html += content; |
279 |
html += "</body>";
|
280 |
html += "</html>";
|
281 |
return html;
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* M?todo que crea el c?digo HTML para la tabla de informaci?n general dentro
|
286 |
* del panel de informaci?n de raster
|
287 |
*
|
288 |
* @return String con el c?figo HTML que corresponde con la tabla de
|
289 |
* informaci?n general
|
290 |
*/
|
291 |
public String tablaInfo() { |
292 |
rowColor = true;
|
293 |
String cabInfo = PluginServices.getText(this, "general_info"); |
294 |
String propiedades = ""; |
295 |
|
296 |
String cabecera = setHTMLTitleTable(cabInfo, 2); |
297 |
|
298 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "archivo"), op.getFileName()[selectedDataSet]); |
299 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "size"), RasterUtilities.formatFileSize(op.getFileSize()[selectedDataSet]) + " "); |
300 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "ancho_alto"), op.getPxWidth() + " X " + op.getPxHeight()); |
301 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "formato"), op.getFileFormat()); |
302 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "georref"), op.isGeoreferenced() ? PluginServices.getText(this, "si") : PluginServices.getText(this, "no")); |
303 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "nbandas"), new Integer(op.getBandCount()).toString()); |
304 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tipo_dato"), RasterUtilities.typesToString(op.getDataType()[0])); |
305 |
|
306 |
return setHTMLTable(cabecera + propiedades);
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* M?todo que crea el c?digo HTML para la tabla de Coordenadas Geogr?ficas
|
311 |
* dentro del panel de informaci?n de raster
|
312 |
*
|
313 |
* @return String con el c?figo HTML que corresponde con la tabla de
|
314 |
* Coordenadas Geogr?ficas
|
315 |
*/
|
316 |
public String tablaCoord() { |
317 |
rowColor = true;
|
318 |
String cabCoord = PluginServices.getText(this, "coor_geograficas"); |
319 |
String propiedades = ""; |
320 |
|
321 |
String cabecera = setHTMLTitleTable(cabCoord, 2); |
322 |
|
323 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_left"), op.getMinX() + ""); |
324 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_down"), op.getMinY() + ""); |
325 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_right"), op.getMaxX() + ""); |
326 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_up"), op.getMaxY() + ""); |
327 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "coor_center"), "(" + (op.getMinX()+op.getMaxX())/2 + ", " + (op.getMinY()+op.getMaxY())/2 + ")"); |
328 |
|
329 |
double tamRealX = op.getMaxX() - op.getMinX();
|
330 |
double tamRealY = op.getMinY() - op.getMaxY();
|
331 |
|
332 |
double tamX = Math.round((tamRealX / op.getPxWidth()) * 10000000); |
333 |
double tamY = Math.round((tamRealY / op.getPxHeight()) * 10000000); |
334 |
|
335 |
String tamPixX = String.valueOf(tamX / 10000000); |
336 |
String tamPixY = String.valueOf(tamY / 10000000); |
337 |
|
338 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixX"), tamPixX); |
339 |
propiedades += setHTMLBasicProperty(PluginServices.getText(this, "tamPixY"), tamPixY); |
340 |
|
341 |
return "<br>" + setHTMLTable(cabecera + propiedades); |
342 |
} |
343 |
|
344 |
/**
|
345 |
* M?todo que crea la tabla de origen de datos dentro del panel
|
346 |
* de Informaci?n.
|
347 |
*
|
348 |
* @return String con el c?digo HTML de la tabla.
|
349 |
*/
|
350 |
public String tablaOrigen() { |
351 |
rowColor = true;
|
352 |
String propiedades = ""; |
353 |
String bandType = ""; |
354 |
|
355 |
String cabOrig = PluginServices.getText(this, "origin"); |
356 |
|
357 |
String cabecera = setHTMLTitleTable(cabOrig, 2); |
358 |
bandType = RasterUtilities.typesToString(op.getDataType()[selectedDataSet]); |
359 |
|
360 |
for(int j = 0; j < op.getBandCountFromDataset()[selectedDataSet] ; j++){ |
361 |
propiedades += setHTMLBasicProperty("Band " + (j + 1), "Type=" + bandType + ", ColorInterp=" + op.getColourInterpretation(j, selectedDataSet)); |
362 |
} |
363 |
|
364 |
return "<br>" + setHTMLTable(cabecera + propiedades); |
365 |
} |
366 |
|
367 |
/**
|
368 |
* M?todo para crear la tabla de proyecci?n del raster en el
|
369 |
* panel de informaci?n de propiedades de raster.
|
370 |
*
|
371 |
* @return String con el c?digo HTML que genera la tabla de proyecci?n.
|
372 |
*/
|
373 |
public String tablaProjection() { |
374 |
rowColor = true;
|
375 |
String propiedades = ""; |
376 |
String projection = null; |
377 |
|
378 |
boolean datos = false; |
379 |
|
380 |
String cabProjection = PluginServices.getText(this, "projection"); |
381 |
|
382 |
String cabecera = setHTMLTitleTable(cabProjection, 1); |
383 |
|
384 |
projection = RasterUtilities.parserGdalProj(op.getStringProjection()); |
385 |
if (projection != null){ |
386 |
datos = true;
|
387 |
propiedades += setHTMLBasicProperty(null, projection);
|
388 |
} |
389 |
|
390 |
if (datos == false) return ""; |
391 |
|
392 |
return "<br>" + setHTMLTable(cabecera + propiedades); |
393 |
} |
394 |
|
395 |
/**
|
396 |
* M?todo para crear la tabla de informaci?n de metadatos del raster en el
|
397 |
* panel de informaci?n de propiedades de raster.
|
398 |
*
|
399 |
* @param Vector
|
400 |
* con los georasterfiles cargados en la capa.
|
401 |
* @return String con el c?digo HTML que genera la tabla.
|
402 |
*/
|
403 |
public String tablaMetadatos() { |
404 |
rowColor = true;
|
405 |
String propiedades = ""; |
406 |
String[] metadatos = null; |
407 |
|
408 |
DatasetMetadata meta = null;
|
409 |
boolean datos = false; |
410 |
|
411 |
String cabMeta = PluginServices.getText(this, "metadata"); |
412 |
|
413 |
String cabecera = setHTMLTitleTable(cabMeta, 2); |
414 |
|
415 |
meta = op.getMetadata()[selectedDataSet]; |
416 |
if (meta != null){ |
417 |
metadatos = meta.getMetadataString(); |
418 |
for(int j = 0 ; j<metadatos.length ; j++){ |
419 |
datos = true;
|
420 |
int index = metadatos[j].indexOf("="); |
421 |
|
422 |
propiedades += setHTMLBasicProperty(metadatos[j].substring(0,index), metadatos[j].substring(index+1)); |
423 |
} |
424 |
} |
425 |
|
426 |
if(datos == false) |
427 |
return ""; |
428 |
|
429 |
return "<br>" + setHTMLTable(cabecera + propiedades); |
430 |
} |
431 |
|
432 |
/**
|
433 |
* M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
|
434 |
* propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las
|
435 |
* tablas.
|
436 |
*
|
437 |
*/
|
438 |
public void refresh() { |
439 |
boolean refresh = false; |
440 |
if (!jComboBoxEvent) {
|
441 |
// Set flag to ensure that an infinite loop is not created
|
442 |
jComboBoxEvent = true;
|
443 |
|
444 |
selectedDataSet = getJComboBox().getSelectedIndex(); |
445 |
if (selectedDataSet < 0) selectedDataSet = 0; |
446 |
|
447 |
String nameFile = ""; |
448 |
getJComboBox().removeAllItems(); |
449 |
for (int i = 0; i < op.getFileCount(); i++) { |
450 |
nameFile = op.getFileName()[i]; |
451 |
nameFile = nameFile.substring(nameFile.lastIndexOf(File.separator) + 1); |
452 |
getJComboBox().addItem(nameFile); |
453 |
} |
454 |
try {
|
455 |
// Select previous item
|
456 |
getJComboBox().setSelectedIndex(selectedDataSet); |
457 |
} catch (IllegalArgumentException iae) { |
458 |
selectedDataSet = 0;
|
459 |
} |
460 |
|
461 |
jComboBoxEvent = false;
|
462 |
refresh = true;
|
463 |
} |
464 |
|
465 |
String html = ""; |
466 |
if ((refresh) && (op.getFileCount() >= 1)) { |
467 |
html = setHTMLBody(tablaInfo() + tablaCoord() + tablaOrigen() + tablaProjection() + tablaMetadatos()); |
468 |
} |
469 |
|
470 |
this.getJEditorPane().setContentType("text/html"); |
471 |
this.getJEditorPane().setText(html);
|
472 |
} |
473 |
|
474 |
/*
|
475 |
* (non-Javadoc)
|
476 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
477 |
*/
|
478 |
public void setLayer(FLayer lyr) { |
479 |
if (lyr instanceof IRasterProperties) { |
480 |
op = (IRasterProperties) lyr; |
481 |
refresh(); |
482 |
} |
483 |
} |
484 |
|
485 |
/*
|
486 |
* (non-Javadoc)
|
487 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
|
488 |
*/
|
489 |
public String getID() { |
490 |
return id;
|
491 |
} |
492 |
|
493 |
/*
|
494 |
* (non-Javadoc)
|
495 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
496 |
*/
|
497 |
public void selectTab(String id) { |
498 |
if (this.id.equals(id)) |
499 |
refresh(); |
500 |
} |
501 |
|
502 |
public void accept() { |
503 |
|
504 |
} |
505 |
|
506 |
public void apply() { |
507 |
|
508 |
} |
509 |
|
510 |
public void cancel() { |
511 |
|
512 |
} |
513 |
|
514 |
public void setComponentSize(int w, int h) { |
515 |
|
516 |
} |
517 |
} |