svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / wizards / WMSWizardData.java @ 5449
History | View | Annotate | Download (5.12 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.wizards; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
import java.io.IOException; |
46 |
import java.net.ConnectException; |
47 |
import java.net.URL; |
48 |
import java.util.ArrayList; |
49 |
import java.util.Hashtable; |
50 |
import java.util.Vector; |
51 |
|
52 |
import javax.swing.JOptionPane; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.cit.gvsig.fmap.DriverException; |
56 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
57 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory; |
58 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
59 |
|
60 |
|
61 |
/**
|
62 |
* Class holding the data shown at the wms wizards
|
63 |
*
|
64 |
* @author Jaume Dominguez Faus
|
65 |
*/
|
66 |
public class WMSWizardData { // should implemement any kind of wizard data interface? |
67 |
private String title; |
68 |
private String theAbstract; |
69 |
private WMSLayerNode layer;
|
70 |
private String[] formats; |
71 |
private String serverVersion; |
72 |
private FMapWMSDriver wms = null; |
73 |
private Hashtable onlineResources = null; |
74 |
|
75 |
/**
|
76 |
* @return Returns the serverVersion.
|
77 |
*/
|
78 |
public String getServerVersion() { |
79 |
return serverVersion;
|
80 |
} |
81 |
public String getHost(){ |
82 |
return wms.getHost();
|
83 |
} |
84 |
|
85 |
public void setHost(URL host, boolean override) throws DriverException{ |
86 |
try {
|
87 |
wms = FMapWMSDriverFactory.getFMapDriverForURL(host); |
88 |
|
89 |
// Send a getCapabilities request;
|
90 |
if (!wms.connect(override, null)) |
91 |
throw new DriverException(PluginServices.getText(this, "cant_connect") + host.toString()); |
92 |
} catch (ConnectException e) { |
93 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"server_timeout")); |
94 |
e.printStackTrace(); |
95 |
return;
|
96 |
} catch (IOException e) { |
97 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "cant_connect")); |
98 |
e.printStackTrace(); |
99 |
return;
|
100 |
} |
101 |
if (wms.getAbstract() != null) |
102 |
theAbstract = wms.getAbstract(); |
103 |
|
104 |
|
105 |
|
106 |
Vector f = wms.getFormats();
|
107 |
ArrayList formatos = new ArrayList(); |
108 |
for (int i = 0; i < f.size(); i++) { |
109 |
if (isValidFormat((String)f.elementAt(i))) { |
110 |
formatos.add(f.elementAt(i)); |
111 |
} |
112 |
} |
113 |
formats = (String[]) formatos.toArray(new String[0]); |
114 |
serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion(); |
115 |
onlineResources = wms.getOnlineResources(); |
116 |
layer = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* M?todo para saber los formatos que admite la aplicaci?n
|
121 |
*
|
122 |
* @param format cadena con el formato a validar
|
123 |
*
|
124 |
* @return true si soportamos dicho formato y false en
|
125 |
* caso contrario
|
126 |
*/
|
127 |
private boolean isValidFormat(String format) { |
128 |
if (format.equalsIgnoreCase("image/png") || |
129 |
format.equalsIgnoreCase("image/jpg") ||
|
130 |
format.equalsIgnoreCase("image/tiff") ||
|
131 |
format.equalsIgnoreCase("image/jpeg") ||
|
132 |
format.equalsIgnoreCase("image/tif") ||
|
133 |
format.equalsIgnoreCase("image/gif")) {
|
134 |
return true; |
135 |
} |
136 |
|
137 |
return false; |
138 |
} |
139 |
|
140 |
public String getAbstract() { |
141 |
return theAbstract;
|
142 |
} |
143 |
|
144 |
public String[] getFormats() { |
145 |
return formats;
|
146 |
} |
147 |
|
148 |
public WMSLayerNode getLayer() {
|
149 |
return layer;
|
150 |
} |
151 |
|
152 |
public String getTitle() { |
153 |
return title;
|
154 |
} |
155 |
|
156 |
public String getServerType() { |
157 |
if (serverVersion==null) return "WMS"; |
158 |
return "WMS "+serverVersion; |
159 |
} |
160 |
|
161 |
public Hashtable getOnlineResources() { |
162 |
return onlineResources;
|
163 |
} |
164 |
|
165 |
public Rectangle2D getBoundingBox(String[] layerNames, String srs) { |
166 |
return wms.getLayersExtent(layerNames, srs);
|
167 |
} |
168 |
|
169 |
public FMapWMSDriver getDriver() {
|
170 |
return wms;
|
171 |
} |
172 |
|
173 |
public boolean isQueryable() { |
174 |
return wms.isQueryable();
|
175 |
} |
176 |
|
177 |
} |