svn-gvsig-desktop / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / gui / ShowResultsDialog.java @ 2771
History | View | Annotate | Download (10.6 KB)
1 |
/*
|
---|---|
2 |
* Created on 28-may-2005
|
3 |
*/
|
4 |
package es.gva.cit.gvsig.catalogClient.gui; |
5 |
|
6 |
import java.awt.geom.Point2D; |
7 |
import java.awt.geom.Rectangle2D; |
8 |
import java.io.IOException; |
9 |
import java.net.URL; |
10 |
import java.util.ArrayList; |
11 |
import java.util.StringTokenizer; |
12 |
|
13 |
import org.w3c.dom.Node; |
14 |
|
15 |
|
16 |
import com.iver.andami.PluginServices; |
17 |
import com.iver.andami.ui.mdiManager.View; |
18 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
19 |
import com.iver.cit.gvsig.fmap.DriverException; |
20 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
21 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
22 |
import com.iver.cit.gvsig.fmap.layers.FLyrText; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
25 |
import com.iver.cit.gvsig.fmap.services.OGCWCSService; |
26 |
import com.iver.cit.gvsig.fmap.services.OGCWMSService; |
27 |
import com.iver.cit.gvsig.gui.wcs.Parametro; |
28 |
|
29 |
import es.gva.cit.catalogClient.CatalogClient; |
30 |
import es.gva.cit.catalogClient.parsers.Resource; |
31 |
import es.gva.cit.catalogClient.ui.ShowResultsDialogPanel; |
32 |
import es.uji.lsi.wcs.client.ServerOutOfOrderException; |
33 |
|
34 |
/**
|
35 |
* @author luisw
|
36 |
*/
|
37 |
public class ShowResultsDialog extends ShowResultsDialogPanel |
38 |
implements View { |
39 |
|
40 |
/**
|
41 |
* @param nodes
|
42 |
* @param client
|
43 |
* @param query
|
44 |
* @param currentRecord
|
45 |
*/
|
46 |
public ShowResultsDialog(CatalogClient client, Node[] nodes, int currentRecord) { |
47 |
super(client, nodes, currentRecord);
|
48 |
|
49 |
/* getDescriptionButton().addActionListener(new java.awt.event.ActionListener() {
|
50 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
51 |
descriptionButtonActionPerformed();
|
52 |
}
|
53 |
});
|
54 |
getMapButton().addActionListener(new java.awt.event.ActionListener() {
|
55 |
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
56 |
mapButtonActionPerformed();
|
57 |
}
|
58 |
});*/
|
59 |
} |
60 |
|
61 |
public void descriptionButtonActionPerformed() { |
62 |
closeJDialog(); |
63 |
ShowTreeDialog dialog = new ShowTreeDialog(nodes[getCurrentNode()]);
|
64 |
dialog.setBounds(0, 0, 800, 775); |
65 |
dialog.setName(PluginServices.getText(this, "catalog_tree")+":"); |
66 |
dialog.setVisible(true);
|
67 |
PluginServices.getMDIManager().addView(dialog); |
68 |
} |
69 |
|
70 |
public void mapButtonActionPerformed() { |
71 |
loadWMS(null,null,null); |
72 |
|
73 |
Resource[] resources = ppalPanel.getTags().getResources();
|
74 |
for (int i = 0 ; i < resources.length ; i++){ |
75 |
String protocol = resources[i].getProtocol();
|
76 |
String link = resources[i].getLinkage();
|
77 |
String srs = resources[i].getSrs();
|
78 |
String layer = resources[i].getName();
|
79 |
|
80 |
if ((protocol == null) || (link == null)) |
81 |
return;
|
82 |
|
83 |
System.out.println("******************************************"); |
84 |
System.out.println("PROTOCOLO: " + resources[i].getProtocol()); |
85 |
System.out.println("LINK: " + resources[i].getLinkage()); |
86 |
System.out.println("RECURSO: " + resources[i].getName()); |
87 |
System.out.println("COORDENADAS: " + resources[i].getSrs()); |
88 |
|
89 |
if (protocol.toLowerCase().indexOf("ogc:wcs") >= 0) |
90 |
cargaWCS(link); |
91 |
|
92 |
if (protocol.toLowerCase().indexOf("ogc:wms") >= 0) |
93 |
loadWMS(link,layer,formatSRS(srs)); |
94 |
|
95 |
/*
|
96 |
if (protocol.toLowerCase().indexOf("www:link") >= 0){
|
97 |
Browser.init();
|
98 |
try {
|
99 |
Browser.displayURL(resources[0].getLinkage());
|
100 |
} catch (IOException e1) {
|
101 |
// TODO Auto-generated catch block
|
102 |
e1.printStackTrace();
|
103 |
}
|
104 |
}*/
|
105 |
} |
106 |
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* There are coordenates names that contain extra characters
|
111 |
* @param srs
|
112 |
* The String retreived
|
113 |
* @return
|
114 |
* The coordenates system
|
115 |
*/
|
116 |
public String formatSRS(String srs){ |
117 |
StringTokenizer sti = new StringTokenizer(srs); |
118 |
String aux;
|
119 |
|
120 |
while(sti.hasMoreTokens()){
|
121 |
aux = sti.nextToken(); |
122 |
if (aux.toUpperCase().indexOf("EPGS") >= 0) |
123 |
return aux;
|
124 |
} |
125 |
|
126 |
return srs;
|
127 |
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* enlace con Wizards.
|
132 |
* La estrategia para integrar una capa desde un cat?logo, conociendo
|
133 |
* solo su nombre (en caso de que est? metadatada por separado, junto con los
|
134 |
* atributos que necesitase) ser?a la siguiente:
|
135 |
* <li> Hacer un getcapabilities del server para obtener el boundaries y algunos
|
136 |
* otros datos necesarios.
|
137 |
* <li> Rellenar todos los campos a un valor por defecto (al primero de ellos,
|
138 |
* por ejemplo), o bien en caso de campos m?ltiples sacar el cuadro de
|
139 |
* di?logo correspondiente.
|
140 |
* <li> A?adirla a la vista.
|
141 |
* Esta estrategia requiere (o al menos hace casi indispensable) de la capacidad
|
142 |
* de modificar las caracter?sticas de la conexi?n desde dentro de la vista.<br>
|
143 |
* <br>
|
144 |
* Para el WMS los campos minimos para poder a?adir a una capa son 5:
|
145 |
* <li>"host": url del servidor
|
146 |
* <li>"layerQuery" nombre de la capa
|
147 |
* <li>"fullExtent" bordes de la capa (tama?o m?ximo)
|
148 |
* <li>"format" formato de imagen que manda el servidor
|
149 |
* <li>"srs" sistema de coordenadas (proyecci?n)
|
150 |
* <li>"name" nombre que tendr? la capa en la vista (Opcional)
|
151 |
*/
|
152 |
public void pruebasMapa() { |
153 |
{ // WCS
|
154 |
String host = "http://hypnos.cbs.umn.edu/cgi-bin/mapserv43d?"+ |
155 |
"map=/data/wcs/demo.map";
|
156 |
String basicParam = "request=GetCapabilities"+ |
157 |
"service=WCS&version=1.0.0&service=WCS&version=1.0.0";
|
158 |
String request = "request=GetCoverage"; |
159 |
String time = "2002-001"; |
160 |
String bands = "1,2,3"; |
161 |
String coverage = "modis"; |
162 |
String crs = "EPSG:26915"; |
163 |
String format = "FORMAT=GEOTIFF_INT16"; |
164 |
String bBox = "BBOX=159707.0,4597900.0,1400210.0,5501400.0"; |
165 |
String sz = "RESY=3691.973214285714&RESX=3691.973214285714"; |
166 |
try {
|
167 |
addLayerToView(createWCSLayer(host, crs, coverage, time)); |
168 |
} catch (IOException e) { |
169 |
// TODO Auto-generated catch block
|
170 |
e.printStackTrace(); |
171 |
} catch (DriverException e) {
|
172 |
// TODO Auto-generated catch block
|
173 |
e.printStackTrace(); |
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
/**
|
179 |
* This function loads a WMS resource
|
180 |
* @param host
|
181 |
* URL where the server is located
|
182 |
* @param layer
|
183 |
* Layer name
|
184 |
* @param crs
|
185 |
* Coordenates System
|
186 |
*/
|
187 |
|
188 |
public void loadWMS(String host, String layer, String crs) { |
189 |
try {
|
190 |
addLayerToView(createWMSLayer(host, layer, crs)); |
191 |
} catch (IOException e) { |
192 |
// TODO Auto-generated catch block
|
193 |
e.printStackTrace(); |
194 |
} catch (ServerOutOfOrderException e) {
|
195 |
// TODO Auto-generated catch block
|
196 |
e.printStackTrace(); |
197 |
} |
198 |
} |
199 |
|
200 |
public void cargaWCS(String host, String attrib, String crs) { |
201 |
int pos = attrib.indexOf("&"); |
202 |
String cover = ""; |
203 |
String time = ""; |
204 |
if ( pos >= 0) { |
205 |
cover = attrib.substring(0, pos-1); |
206 |
time = attrib.substring(pos+6);
|
207 |
} else
|
208 |
cover = attrib; |
209 |
try {
|
210 |
addLayerToView(createWCSLayer(host, crs, cover, time)); |
211 |
} catch (IOException e) { |
212 |
// TODO Auto-generated catch block
|
213 |
e.printStackTrace(); |
214 |
} catch (DriverException e) {
|
215 |
// TODO Auto-generated catch block
|
216 |
e.printStackTrace(); |
217 |
} |
218 |
} |
219 |
|
220 |
public void cargaWCS(String link) { |
221 |
try {
|
222 |
addLayerToView(createWCSLayer(link)); |
223 |
} catch (IOException e) { |
224 |
// TODO Auto-generated catch block
|
225 |
e.printStackTrace(); |
226 |
} catch (DriverException e) {
|
227 |
// TODO Auto-generated catch block
|
228 |
e.printStackTrace(); |
229 |
} |
230 |
} |
231 |
/*
|
232 |
* Hay que dotar a los 'host' de persistencia en el getcapabilities,
|
233 |
* para que incorporar las capas sea m?s r?pido (en tiempo y en c?digo).
|
234 |
*/
|
235 |
private FLayer createWMSLayer(String host, String layer,String crs) throws IOException, ServerOutOfOrderException { |
236 |
System.out.println("Cargando capa WMS: " + host + "&LAYER=" + layer + "&SRS=" + crs); |
237 |
FLyrWMS lyr = null;
|
238 |
lyr = new FLyrWMS();
|
239 |
lyr.setHost(new URL("http://gruposigp2/cgi-bin/wms")); |
240 |
lyr.setSRS("EPSG:23030");
|
241 |
lyr.setFormat("image/jpg");
|
242 |
lyr.setName("embalses");
|
243 |
lyr.setLayerQuery("embalses");
|
244 |
|
245 |
lyr.setLayerText(new FLyrText(new ArrayList())); |
246 |
|
247 |
return lyr;
|
248 |
} |
249 |
|
250 |
private FLayer createWCSLayer(String link) throws IOException, DriverException { |
251 |
System.out.println("Cargando capa WCS: " + link); |
252 |
FLyrWCS lyr = null;
|
253 |
lyr = new FLyrWCS();
|
254 |
String host = link.substring(0,link.indexOf('?')); |
255 |
String query = link.substring(link.indexOf('?')+1); |
256 |
lyr.setHost(host); |
257 |
lyr.initFromQueryString(query); |
258 |
return lyr;
|
259 |
} |
260 |
|
261 |
/*
|
262 |
* Hay que dotar a los 'host' de persistencia en el getcapabilities,
|
263 |
* para que incorporar las capas sea m?s r?pido (en tiempo y en c?digo).
|
264 |
*/
|
265 |
private FLayer createWCSLayer(String host, String crs, |
266 |
String coverage, String time) throws IOException, DriverException { |
267 |
FLyrWCS lyr = null;
|
268 |
lyr = new FLyrWCS();
|
269 |
lyr.setHost(host); |
270 |
lyr.setSRS(crs); |
271 |
lyr.setCoverageName(coverage); |
272 |
lyr.setTime("TIME="+time);
|
273 |
OGCWCSService service = (OGCWCSService) lyr.getWCSAdaptor().getDriver(); |
274 |
service.connect(); |
275 |
if (true) { |
276 |
lyr.setLabel( service.getLabel(coverage) ); |
277 |
lyr.setName( lyr.getLabel() ); |
278 |
lyr.setFullExtent ( service.getFullExtent(coverage, crs) ); |
279 |
lyr.setFormat( (String) service.getFormats(coverage).get(0) ); |
280 |
Parametro param = (Parametro) service.getParameters(coverage).get(0);
|
281 |
lyr.setParameter( param.getName()+"="+(String)param.getLista_valores_simples().get(0) ); |
282 |
lyr.setMaxResolution ( service.getMaxResolution(coverage) ); |
283 |
} |
284 |
if (false) { |
285 |
lyr.setLabel( "North Central US MODIS Images for 2002" );
|
286 |
lyr.setName( lyr.getLabel() ); |
287 |
Rectangle2D bBox = new Rectangle2D.Double(); |
288 |
bBox.setFrameFromDiagonal(159707.0,4597900.0,1400210.0,5501400.0); |
289 |
|
290 |
lyr.setFullExtent ( bBox ); |
291 |
lyr.setFormat( "GEOTIFF_16BIT" );
|
292 |
lyr.setParameter( "bands=1,2,3" );
|
293 |
lyr.setMaxResolution ( new Point2D.Double(500D, 500D) ); |
294 |
} |
295 |
// Creo que esto es redundante. La capa ya tiene todos los datos para poder
|
296 |
// montarlo
|
297 |
/*lyr.getWCSAdaptor().setCoverageQuery("COVERAGE="+coverage+"&CRS="+crs+
|
298 |
"&BBOX=159707.0,4597900.0,1400210.0,5501400.0&"+
|
299 |
"TIME="+lyr.getTime()+"&"+lyr.getParameter()+
|
300 |
"&RESX=1790.047619047619&RESY=1790.047619047619&"+
|
301 |
"FORMAT="+lyr.getFormat());*/
|
302 |
return lyr;
|
303 |
} |
304 |
|
305 |
private void addLayerToView(FLayer lyr) { |
306 |
com.iver.cit.gvsig.gui.View theView = |
307 |
(com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
308 |
//IProjection proj = theView.getProjection();
|
309 |
|
310 |
//FLayer lyr = createOvcLayer(mapServer, proj);
|
311 |
//lyr.setName(mapServer.getName());
|
312 |
|
313 |
if (lyr != null) { |
314 |
try {
|
315 |
lyr.load(); |
316 |
} catch (DriverIOException e) {
|
317 |
;//throw new XMLException(e);
|
318 |
} |
319 |
|
320 |
lyr.setVisible(true);
|
321 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
322 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
323 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
324 |
} |
325 |
} |
326 |
|
327 |
/**
|
328 |
* Cierra el Dialog
|
329 |
*/
|
330 |
public void closeJDialog() { |
331 |
this.hide();
|
332 |
PluginServices.getMDIManager().closeView(ShowResultsDialog.this); |
333 |
} |
334 |
|
335 |
/* (non-Javadoc)
|
336 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
337 |
*/
|
338 |
public ViewInfo getViewInfo() {
|
339 |
ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODALDIALOG);
|
340 |
m_viewinfo.setTitle(getName()); |
341 |
return m_viewinfo;
|
342 |
} |
343 |
} |