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