Statistics
| Revision:

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

History | View | Annotate | Download (5.05 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.geom.Rectangle2D;
44
import java.io.File;
45
import java.net.URL;
46
import java.util.ArrayList;
47
import java.util.Hashtable;
48
import java.util.Vector;
49

    
50
import com.iver.andami.PluginServices;
51
import com.iver.cit.gvsig.fmap.DriverException;
52
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
53
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory;
54
import com.iver.cit.gvsig.fmap.drivers.wms.WMSOperations;
55
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
56

    
57

    
58
/**
59
 * Class holding the data shown at the wms wizards
60
 *
61
 * @author Jaume Dominguez Faus
62
 */
63
public class WMSWizardData implements WMSOperations { 
64
        private String title;
65
        private String theAbstract;
66
        private WMSLayerNode layers;
67
        private String[] formats;
68
        private String serverVersion;
69
        private FMapWMSDriver wms = null;
70
        private Hashtable onlineResources = null;
71
        /**
72
         * The listener of the wizard that depends on this
73
         */
74
        private WMSOperations wizardListener;
75
        
76
        /**
77
         * @return Returns the serverVersion.
78
         */
79
        public String getServerVersion() {
80
                return serverVersion;
81
        }
82
        public String getHost(){
83
                return wms.getHost();
84
        }
85
        
86
        
87
        public void setHost(URL host, boolean override) throws DriverException{
88
                wms = FMapWMSDriverFactory.getDriverForHost(host);
89
                wms.addListener(this);
90
                // Send a getCapabilities request;
91
                if (!wms.connect(override))
92
                        throw new DriverException(PluginServices.getText(this, "cant_connect") + host.toString());
93
                
94
        }
95
        
96
        /**
97
         * M?todo para saber los formatos que admite la aplicaci?n
98
         *
99
         * @param format cadena con el formato a validar
100
         *
101
         * @return true si soportamos dicho formato y false en
102
         * caso contrario
103
         */
104
        private boolean isValidFormat(String format) {
105
                if (format.equalsIgnoreCase("image/png") ||
106
                                format.equalsIgnoreCase("image/jpg") ||
107
                                format.equalsIgnoreCase("image/tiff") ||
108
                                format.equalsIgnoreCase("image/jpeg") ||
109
                                format.equalsIgnoreCase("image/tif") ||
110
                                format.equalsIgnoreCase("image/gif")) {
111
                        return true;
112
                }
113
                
114
                return false;
115
        }
116
        
117
        public String getAbstract() {
118
                return theAbstract;
119
        }
120
        
121
        public String[] getFormats() {
122
                return formats;
123
        }
124
        
125
        public WMSLayerNode getLayer() {
126
                return layers;
127
        }
128
        
129
        public String getTitle() {
130
                return title;
131
        }
132
        
133
        public String getServerType() {
134
                if (serverVersion==null) return "WMS";
135
                return "WMS "+serverVersion;
136
        }
137
        
138
        public Hashtable getOnlineResources() {
139
                return onlineResources;
140
        }
141
        
142
        public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
143
                return wms.getLayersExtent(layerNames, srs);
144
        }
145
        
146
        public FMapWMSDriver getDriver() {
147
                return wms;
148
        }
149
        
150
        public boolean isQueryable() {
151
                return wms.isQueryable();
152
        }
153
        
154
        public void getMap(int eventType, File mapFile, String message) { /* Does not make sense in this context. */ };
155
        public void getFeatureInfo(int eventType, String message) { /* Does not make sense in this context. */ };
156
        
157
        public void getCapabilities(int eventType, String message) {
158
                if(eventType == WMSOperations.REQUEST_FINISHED) {
159
                        // Transfer complete -> initialize properties.
160
                        if (wms.getAbstract()  != null)
161
                                theAbstract = wms.getAbstract();
162
                        
163
                        Vector f = wms.getFormats(); 
164
                        ArrayList formatos = new ArrayList();
165
                        for (int i = 0; i < f.size(); i++) {
166
                                if (isValidFormat((String)f.elementAt(i))) {
167
                                        formatos.add(f.elementAt(i));
168
                                }
169
                        }
170
                        formats = (String[]) formatos.toArray(new String[0]);
171
                        serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion();
172
                        onlineResources = wms.getOnlineResources();
173
                        layers = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document
174
                }        
175
                if (wizardListener!=null)
176
                        // Notify WMSWizard that the data is ready.
177
                        wizardListener.getCapabilities(eventType, message);
178
                
179
        }
180
        
181
        public void setWizardListener(WMSOperations listener) {
182
                this.wizardListener = listener;                
183
        }
184
        
185
        public void cancelTransfer() {
186
                wms.cancel(WMSOperations.GET_CAPABILITIES);
187
        }
188
}