Statistics
| Revision:

svn-gvsig-desktop / branches / MULTITHREADING_DEVELOPMENT / extensions / extWMS / src / com / iver / cit / gvsig / gui / wizards / WMSWizardData.java @ 5269

History | View | Annotate | Download (5.92 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.File;
46
import java.io.IOException;
47
import java.net.ConnectException;
48
import java.net.URL;
49
import java.util.ArrayList;
50
import java.util.Hashtable;
51
import java.util.NoSuchElementException;
52
import java.util.Vector;
53

    
54
import javax.swing.JOptionPane;
55

    
56
import org.gvsig.gui.beans.ProgressDialog;
57

    
58
import com.iver.andami.PluginServices;
59
import com.iver.cit.gvsig.fmap.DriverException;
60
import com.iver.cit.gvsig.fmap.drivers.WMSListener;
61
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
62
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
63

    
64

    
65
/**
66
 * Class holding the data shown at the wms wizards
67
 *
68
 * @author Jaume Dominguez Faus
69
 */
70
public class WMSWizardData { // should implemement any kind of wizard data interface?
71
    private String title;
72
    private String theAbstract;
73
    private WMSLayerNode layers;
74
    private String[] formats;
75
    private String serverVersion;
76
    private FMapWMSDriver wms = null;
77
    private Hashtable onlineResources = null;
78
    private EventListener listener = new EventListener();
79
    private WMSListener wizardListener;
80
    
81
    /**
82
     * @return Returns the serverVersion.
83
     */
84
    public String getServerVersion() {
85
        return serverVersion;
86
    }
87
    public String getHost(){
88
        return wms.getHost();
89
    }
90
    
91
   
92
    public void setHost(URL host, boolean override) throws DriverException{
93
        wms = new FMapWMSDriver(listener);
94
        try {
95
                wms.createClient(host);
96
                
97
                // Send a getCapabilities request;
98
                if (!wms.connect(override))
99
                        throw new DriverException(PluginServices.getText(this, "cant_connect") + host.toString());
100
        } catch (ConnectException e) {
101
                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"server_timeout"));
102
                        e.printStackTrace();
103
                        return;
104
                } catch (IOException e) {
105
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "cant_connect"));
106
                        e.printStackTrace();
107
                        return;
108
                }
109
    }
110
    
111
    /**
112
     * M?todo para saber los formatos que admite la aplicaci?n
113
     *
114
     * @param format cadena con el formato a validar
115
     *
116
     * @return true si soportamos dicho formato y false en
117
     * caso contrario
118
     */
119
    private boolean isValidFormat(String format) {
120
        if (format.equalsIgnoreCase("image/png") ||
121
                format.equalsIgnoreCase("image/jpg") ||
122
                format.equalsIgnoreCase("image/tiff") ||
123
                format.equalsIgnoreCase("image/jpeg") ||
124
                format.equalsIgnoreCase("image/tif") ||
125
                format.equalsIgnoreCase("image/gif")) {
126
            return true;
127
        }
128

    
129
        return false;
130
    }
131
    
132
    public String getAbstract() {
133
        return theAbstract;
134
    }
135

    
136
    public String[] getFormats() {
137
        return formats;
138
    }
139

    
140
    public WMSLayerNode getLayer() {
141
        return layers;
142
    }
143

    
144
    public String getTitle() {
145
        return title;
146
    }
147

    
148
    public String getServerType() {
149
            if (serverVersion==null) return "WMS";
150
        return "WMS "+serverVersion;
151
    }
152

    
153
    public Hashtable getOnlineResources() {
154
                return onlineResources;
155
        }
156

    
157
    public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
158
        return wms.getLayersExtent(layerNames, srs);
159
    }
160
    
161
        public FMapWMSDriver getDriver() {
162
                return wms;
163
        }
164
        
165
    public boolean isQueryable() {
166
            return wms.isQueryable();
167
    }
168
 
169
    private class EventListener implements WMSListener {
170
                public void getMap(int eventType, File mapFile, String message) { /* Nothing */ };
171
                public void getFeatureInfo(int eventType, String message) {/* Nothing*/        }
172

    
173
                public void getCapabilities(int eventType, String message) {
174
                        if(eventType == FMapWMSDriver.REQUEST_FINISHED) {
175
                                // Transfer complete -> initialize properties.
176
                                if (wms.getAbstract()  != null)
177
                                        theAbstract = wms.getAbstract();
178
                                        
179
                                Vector f = wms.getFormats(); 
180
                                ArrayList formatos = new ArrayList();
181
                                for (int i = 0; i < f.size(); i++) {
182
                                        if (isValidFormat((String)f.elementAt(i))) {
183
                                                formatos.add(f.elementAt(i));
184
                                        }
185
                                }
186
                                formats = (String[]) formatos.toArray(new String[0]);
187
                                serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion();
188
                                onlineResources = wms.getOnlineResources();
189
                                layers = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document
190
                        }        
191
                        if (wizardListener!=null)
192
                                // Notify WMSWizard that the data is ready.
193
                                wizardListener.getCapabilities(eventType, message);
194
                        
195
                }
196
    }
197

    
198
        public void setWizardListener(WMSListener listener) {
199
                this.wizardListener = listener;                
200
        }
201
        
202
        public void cancelTransfer() {
203
                wms.cancel(FMapWMSDriver.GET_CAPABILITIES);
204
        }
205
}