svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / InfoPanel.java @ 13679
History | View | Annotate | Download (13.8 KB)
1 | 8026 | nacho | /*
|
---|---|---|---|
2 | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
||
3 | *
|
||
4 | * Copyright (C) 2004-5.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * cresques@gmail.com
|
||
23 | */
|
||
24 | package org.cresques.ui.raster; |
||
25 | |||
26 | import java.awt.GridBagConstraints; |
||
27 | import java.awt.GridBagLayout; |
||
28 | import java.awt.image.DataBuffer; |
||
29 | |||
30 | import javax.swing.JEditorPane; |
||
31 | import javax.swing.JPanel; |
||
32 | import javax.swing.JScrollPane; |
||
33 | |||
34 | import org.cresques.io.GeoRasterFile; |
||
35 | import org.cresques.io.datastruct.Metadata; |
||
36 | import org.cresques.ui.filter.FilterRasterDialogPanel; |
||
37 | |||
38 | /**
|
||
39 | *
|
||
40 | * @author Miguel Angel Querol Carratal? <querol_mig@gva.es>
|
||
41 | * Panel de informacion de la imagen r?ster de la que se muestran las propiedades
|
||
42 | *
|
||
43 | */
|
||
44 | 10645 | nacho | public class InfoPanel extends JPanel implements IResize{ |
45 | 8026 | nacho | |
46 | 10645 | nacho | |
47 | private int wComp = 445, hComp = 239; |
||
48 | private int wScroll = wComp - 5, hScroll = hComp - 9; |
||
49 | private int wEditor = wComp - 20, hEditor = hComp - 19; |
||
50 | |||
51 | 8026 | nacho | private final String bgColor0 = "\"#FEEDD6\""; // light salmon |
52 | private final String bgColor1 = "\"#EAEAEA\""; // light grey |
||
53 | private final String bgColor2 = "\"#F2FEFF\""; // light blue |
||
54 | private final String bgColor3 = "\"#FBFFE1\""; // light yellow |
||
55 | private JScrollPane jScrollPane = null; |
||
56 | public JEditorPane jEditorPane = null; |
||
57 | |||
58 | /**
|
||
59 | * Nombre del Panel
|
||
60 | */
|
||
61 | public String nom = "Info"; |
||
62 | |||
63 | /**
|
||
64 | * Dialogo padre que contiene a este
|
||
65 | */
|
||
66 | public FilterRasterDialogPanel parent = null; |
||
67 | |||
68 | /**
|
||
69 | * Matriz de tama?o Nx2 que contiene a las propiedades en forma propiedad/valor
|
||
70 | */
|
||
71 | public Object[][] props = null; |
||
72 | |||
73 | /**
|
||
74 | * Cabecera de las columnas del dialogo
|
||
75 | */
|
||
76 | public Object[] columnNames = { "Propiedad", "Valor" }; |
||
77 | |||
78 | /**
|
||
79 | * Cadenas de caracterres que corresponden con las cabeceras de las tablas
|
||
80 | * de informaci?n
|
||
81 | */
|
||
82 | public String cabInfo = null; |
||
83 | public String cabCoord = null; |
||
84 | public String cabProy = null; |
||
85 | public String cabOrig = null; |
||
86 | public String cabMeta = null; |
||
87 | /**
|
||
88 | * Vector de GeoRasterFiles para almacenar los archivos que forman
|
||
89 | * parte de la capa.
|
||
90 | */
|
||
91 | private GeoRasterFile[] files = null; |
||
92 | |||
93 | /**
|
||
94 | * Flags que indican que archivo corresponde a cada banda de color
|
||
95 | */
|
||
96 | private int redBand = -1; |
||
97 | private int greenBand = -1; |
||
98 | private int blueBand = -1; |
||
99 | |||
100 | |||
101 | |||
102 | /**
|
||
103 | * This is the default constructor
|
||
104 | */
|
||
105 | public InfoPanel(FilterRasterDialogPanel parent) {
|
||
106 | super();
|
||
107 | 10645 | nacho | this.files = parent.getGrf();
|
108 | 8026 | nacho | this.parent = parent;
|
109 | this.props = parent.props;
|
||
110 | initialize(); |
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * This method initializes this
|
||
115 | *
|
||
116 | * @return void
|
||
117 | */
|
||
118 | public void initialize() { |
||
119 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
120 | gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
||
121 | gridBagConstraints.gridx = 0;
|
||
122 | gridBagConstraints.gridy = 0;
|
||
123 | gridBagConstraints.weightx = 1.0;
|
||
124 | gridBagConstraints.weighty = 1.0;
|
||
125 | gridBagConstraints.insets = new java.awt.Insets(5,8,5,8); |
||
126 | this.setLayout(new GridBagLayout()); |
||
127 | 10645 | nacho | //this.setSize(wComp, hComp);
|
128 | //this.setPreferredSize(new java.awt.Dimension(wComp,hComp));
|
||
129 | 8026 | nacho | this.add(getJScrollPane(), gridBagConstraints);
|
130 | //refresh();
|
||
131 | 10645 | nacho | this.setComponentSize(wComp, hComp);
|
132 | 8026 | nacho | this.getJEditorPane().repaint();
|
133 | |||
134 | } |
||
135 | |||
136 | /**
|
||
137 | * This method initializes jScrollPane
|
||
138 | *
|
||
139 | * @return javax.swing.JScrollPane
|
||
140 | */
|
||
141 | private JScrollPane getJScrollPane() { |
||
142 | if (jScrollPane == null) { |
||
143 | jScrollPane = new JScrollPane(); |
||
144 | 10645 | nacho | //jScrollPane.setPreferredSize(new java.awt.Dimension(wScroll,hScroll));
|
145 | 8026 | nacho | jScrollPane.setViewportView(getJEditorPane()); |
146 | |||
147 | |||
148 | } |
||
149 | return jScrollPane;
|
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * This method initializes jEditorPane
|
||
154 | *
|
||
155 | * @return javax.swing.JEditorPane
|
||
156 | */
|
||
157 | private JEditorPane getJEditorPane() { |
||
158 | if (jEditorPane == null) { |
||
159 | jEditorPane = new JEditorPane(); |
||
160 | jEditorPane.setEditable(false);
|
||
161 | 10645 | nacho | //jEditorPane.setSize(new java.awt.Dimension(wEditor,hEditor));
|
162 | 8026 | nacho | |
163 | } |
||
164 | return jEditorPane;
|
||
165 | } |
||
166 | |||
167 | public void resetTable(){ |
||
168 | this.jEditorPane = null; |
||
169 | } |
||
170 | |||
171 | /**
|
||
172 | * Obtiene el nombre del panel.
|
||
173 | */
|
||
174 | public String getName(){ |
||
175 | return this.nom; |
||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * A?ade los GeoRasterFiles que forman parte de la capa
|
||
180 | * @param Vector de GeoRasterFiles que corresponde con los
|
||
181 | * archivos cargados.
|
||
182 | */
|
||
183 | public void addFiles(GeoRasterFile[] files){ |
||
184 | this.files = files;
|
||
185 | refresh(); |
||
186 | } |
||
187 | |||
188 | /**
|
||
189 | * Asigna el n?mero de l?nea del archivo que corresponde a cada bada de color
|
||
190 | * @param bandR N?mero de linea del archivo que corresponde a la banda roja
|
||
191 | * @param bandG N?mero de linea del archivo que corresponde a la banda verde
|
||
192 | * @param bandB N?mero de linea del archivo que corresponde a la banda azul
|
||
193 | */
|
||
194 | public void setBands(int bandR, int bandG, int bandB){ |
||
195 | this.redBand = bandR;
|
||
196 | this.greenBand = bandG;
|
||
197 | this.blueBand = bandB;
|
||
198 | refresh(); |
||
199 | } |
||
200 | |||
201 | |||
202 | /**
|
||
203 | * M?todo que crea el c?digo HTML para la tabla de informaci?n general
|
||
204 | * dentro del panel de informaci?n de raster
|
||
205 | * @return String con el c?figo HTML que corresponde con la tabla de informaci?n
|
||
206 | * general
|
||
207 | */
|
||
208 | public String tablaInfo(){ |
||
209 | String tablaInfo = null; |
||
210 | String propiedades=""; |
||
211 | String color = "\"#FEEDD6\""; |
||
212 | |||
213 | String cabecera =
|
||
214 | " <tr valign=\"top\">" +
|
||
215 | " <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"2\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabInfo+"</b></font></td>" + |
||
216 | " </tr>";
|
||
217 | |||
218 | for(int i = 0; i <= 5; i++){ |
||
219 | |||
220 | if ((i%2 == 0) || i == 0) color = bgColor0; |
||
221 | else color = bgColor1;
|
||
222 | |||
223 | //if(props[i][1] == null) props[i][1] = "";
|
||
224 | |||
225 | if(props.length > 1){ |
||
226 | String propiedad =
|
||
227 | " <tr valign=\"top\">" +
|
||
228 | " <td width=\"140\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\">"+props[i][0]+"</font></td>" + |
||
229 | " <td width=\"270\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+props[i][1]+"</font></td>" + |
||
230 | " </tr>";
|
||
231 | propiedades = propiedades + propiedad; |
||
232 | } |
||
233 | } |
||
234 | |||
235 | tablaInfo = "<table>" + cabecera + propiedades + "<tr></tr>" + "</table>"; |
||
236 | |||
237 | return tablaInfo;
|
||
238 | } |
||
239 | |||
240 | |||
241 | |||
242 | |||
243 | /**
|
||
244 | * M?todo que crea el c?digo HTML para la tabla de coordenadas geogr?ficas
|
||
245 | * dentro del panel de informaci?n de raster
|
||
246 | * @return String con el c?figo HTML que corresponde con la tabla de coordenadas
|
||
247 | * geogr?ficas.
|
||
248 | */
|
||
249 | public String tablaCoord(){ |
||
250 | String tablaCoord = null; |
||
251 | String propiedades = ""; |
||
252 | String color = "\"#FEEDD6\""; |
||
253 | |||
254 | if(props.length > 1){ |
||
255 | String cabecera =
|
||
256 | " <tr valign=\"top\">" +
|
||
257 | " <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"2\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabCoord+"</b></font></td>" + |
||
258 | " </tr>";
|
||
259 | |||
260 | for(int i = 7; i <= 12; i++){ |
||
261 | |||
262 | if ((i%2 == 1) || i == 7) color = bgColor0; |
||
263 | else color = bgColor1;
|
||
264 | |||
265 | if(props[i][1] == null) props[i][1] = ""; |
||
266 | |||
267 | if(props[i][0] != null){ |
||
268 | String propiedad =
|
||
269 | " <tr valign=\"top\">" +
|
||
270 | " <td width=\"140\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\">"+props[i][0]+"</font></td>" + |
||
271 | " <td width=\"270\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+props[i][1]+"</font></td>" + |
||
272 | " </tr>";
|
||
273 | propiedades = propiedades + propiedad; |
||
274 | } |
||
275 | } |
||
276 | tablaCoord = "<table>" + cabecera + propiedades + "<tr></tr>" + "</table>"; |
||
277 | |||
278 | return tablaCoord;
|
||
279 | } |
||
280 | return ""; |
||
281 | } |
||
282 | |||
283 | |||
284 | |||
285 | /**
|
||
286 | * M?todo que crea la tabla de origen de datos dentro del panel
|
||
287 | * de Informaci?n.
|
||
288 | * @param vector con todos los GeoRasterFiles que est?n dentro de la capa
|
||
289 | * @return String con el c?digo HTML de la tabla.
|
||
290 | */
|
||
291 | public String tablaOrigen(GeoRasterFile[] files){ |
||
292 | String tablaOrigen = null; |
||
293 | String propiedades = ""; |
||
294 | String color = "\"#FEEDD6\""; |
||
295 | String rBand = ""; |
||
296 | String gBand = ""; |
||
297 | String bBand = ""; |
||
298 | String bandType = ""; |
||
299 | int k = 0; |
||
300 | |||
301 | |||
302 | String cabecera =
|
||
303 | " <tr valign=\"top\">" +
|
||
304 | " <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabOrig+"</b></font></td>" + |
||
305 | " </tr>";
|
||
306 | |||
307 | for(int i = 0; i<files.length ; i++){ |
||
308 | String fName = files[i].getName();
|
||
309 | String propiedad =
|
||
310 | " <tr valign=\"top\">" +
|
||
311 | " <td width=\"417\" height=\"18\" bgcolor="+bgColor1+"align=\"left\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\">"+fName+"</font></td>" + |
||
312 | " </tr>";
|
||
313 | |||
314 | switch (files[i].getDataType()) {
|
||
315 | case DataBuffer.TYPE_BYTE: |
||
316 | bandType = "8U";
|
||
317 | break;
|
||
318 | case DataBuffer.TYPE_INT: |
||
319 | bandType = "32";
|
||
320 | break;
|
||
321 | case DataBuffer.TYPE_DOUBLE: |
||
322 | bandType = "64";
|
||
323 | break;
|
||
324 | case DataBuffer.TYPE_FLOAT: |
||
325 | bandType = "32";
|
||
326 | break;
|
||
327 | case DataBuffer.TYPE_SHORT: |
||
328 | bandType = "16";
|
||
329 | break;
|
||
330 | case DataBuffer.TYPE_USHORT: |
||
331 | bandType = "16U";
|
||
332 | break;
|
||
333 | case DataBuffer.TYPE_UNDEFINED: |
||
334 | bandType = "??";
|
||
335 | break;
|
||
336 | } |
||
337 | |||
338 | for(int j = 0; j < files[i].getBandCount() ; j++){ |
||
339 | if ((j%2 == 0) || j == 0) color = bgColor0; |
||
340 | else color = bgColor1;
|
||
341 | |||
342 | if(k == redBand) rBand = "R"; else rBand = ""; |
||
343 | if(k == greenBand) gBand = "G"; else gBand = ""; |
||
344 | if(k == blueBand) bBand = "B"; else bBand = ""; |
||
345 | |||
346 | String banda =
|
||
347 | " <tr valign=\"top\">" +
|
||
348 | " <td width=\"20\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"center\" colspan=\"1/2\"><font face=\"Arial\" size=\"3\" align=\"right\">"+rBand+"</font></td>" + |
||
349 | " <td width=\"20\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"center\" colspan=\"1/2\"><font face=\"Arial\" size=\"3\" align=\"right\">"+gBand+"</font></td>" + |
||
350 | " <td width=\"20\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"center\" colspan=\"1/2\"><font face=\"Arial\" size=\"3\" align=\"right\">"+bBand+"</font></td>" + |
||
351 | " <td width=\"357\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+"band "+(j+1)+"["+bandType+"]"+"</font></td>" + |
||
352 | " </tr>";
|
||
353 | propiedad = propiedad + banda; |
||
354 | k++; |
||
355 | } |
||
356 | propiedades = propiedades + propiedad; |
||
357 | } |
||
358 | |||
359 | tablaOrigen = "<table>" + cabecera + propiedades + "<tr></tr>" + "</table>"; |
||
360 | |||
361 | return tablaOrigen;
|
||
362 | } |
||
363 | |||
364 | |||
365 | /**
|
||
366 | * M?todo para crear la tabla de informaci?n de metadatos del raster en el
|
||
367 | * panel de informaci?n de propiedades de raster.
|
||
368 | * @param Vector con los georasterfiles cargados en la capa.
|
||
369 | * @return String con el c?digo HTML que genera la tabla.
|
||
370 | */
|
||
371 | public String tablaMetadatos(GeoRasterFile[] files){ |
||
372 | String tablaMetadatos = ""; |
||
373 | String propiedades = ""; |
||
374 | String[] metadatos = null; |
||
375 | String color = "\"#FEEDD6\""; |
||
376 | |||
377 | Metadata meta = null;
|
||
378 | boolean datos = false; |
||
379 | |||
380 | String cabecera =
|
||
381 | " <tr valign=\"top\">" +
|
||
382 | " <td width=\"417\" height=\"18\" bgcolor="+bgColor3+"align=\"center\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+cabMeta+"</b></font></td>" + |
||
383 | " </tr>";
|
||
384 | |||
385 | for (int i = 0 ; i < files.length ; i++){ |
||
386 | meta = files[i].getMetadata(); |
||
387 | if (meta != null){ |
||
388 | metadatos = meta.getMetadataString(); |
||
389 | String fichero =
|
||
390 | " <tr valign=\"top\">" +
|
||
391 | " <td width=\"417\" height=\"18\" bgcolor="+bgColor1+"align=\"left\" colspan=\"4\"><font face=\"Arial\" size=\"3\" align=\"right\">"+files[i].getName()+"</font></td>" + |
||
392 | " </tr>";
|
||
393 | propiedades = propiedades + fichero; |
||
394 | for(int j = 0 ; j<metadatos.length ; j++){ |
||
395 | 10645 | nacho | datos = true;
|
396 | 8026 | nacho | if ((j%2 == 0) || j == 0) color = bgColor0; |
397 | else color = bgColor1;
|
||
398 | int index = metadatos[j].indexOf("="); |
||
399 | |||
400 | String propiedad =
|
||
401 | " <tr valign=\"top\">" +
|
||
402 | " <td width=\"140\" height=\"18\" bgcolor=\"#D6D6D6\"align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\">"+metadatos[j].substring(0,index)+"</font></td>" + |
||
403 | " <td width=\"270\" height=\"18\" bgcolor="+color+"align=\"left\"><font face=\"Arial\" size=\"3\">"+metadatos[j].substring(index+1)+"</font></td>" + |
||
404 | " </tr>";
|
||
405 | propiedades = propiedades + propiedad; |
||
406 | } |
||
407 | } |
||
408 | } |
||
409 | |||
410 | tablaMetadatos = cabecera + propiedades; |
||
411 | if(datos == false) |
||
412 | return ""; |
||
413 | |||
414 | return tablaMetadatos;
|
||
415 | } |
||
416 | |||
417 | /**
|
||
418 | * M?todo que dibuja las tablas HTML del panel de informaci?n dentro de las
|
||
419 | * propiedades de r?ster. Se llama cada vez que se actualiza alg?n dato de las
|
||
420 | * tablas.
|
||
421 | *
|
||
422 | */
|
||
423 | public void refresh(){ |
||
424 | String html = null; |
||
425 | |||
426 | html = |
||
427 | "<html>"+
|
||
428 | this.tablaInfo()+
|
||
429 | this.tablaCoord();
|
||
430 | |||
431 | if(this.files != null){ |
||
432 | html = html + this.tablaOrigen(files) + this.tablaMetadatos(files) +"</html>"; |
||
433 | } |
||
434 | |||
435 | else
|
||
436 | html = html + "</html>";
|
||
437 | |||
438 | this.getJEditorPane().setContentType("text/html"); |
||
439 | this.getJEditorPane().setText(html);
|
||
440 | this.getJScrollPane().setAlignmentY(0); |
||
441 | } |
||
442 | |||
443 | 10645 | nacho | |
444 | public void setComponentSize(int w, int h){ |
||
445 | wComp = w; hComp = h; |
||
446 | wScroll = wComp - 5; hScroll = hComp - 9; |
||
447 | wEditor = wComp - 20; hEditor = hComp - 19; |
||
448 | 8026 | nacho | |
449 | 10645 | nacho | this.setSize(wComp, hComp);
|
450 | this.setPreferredSize(new java.awt.Dimension(wComp,hComp)); |
||
451 | jScrollPane.setPreferredSize(new java.awt.Dimension(wScroll,hScroll));
|
||
452 | jEditorPane.setSize(new java.awt.Dimension(wEditor,hEditor));
|
||
453 | |||
454 | 8026 | nacho | } |
455 | |||
456 | } |
||
457 |