Statistics
| Revision:

root / branches / MULTITHREADING_DEVELOPMENT / extensions / extWMS / src / com / iver / cit / gvsig / gui / wizards / WMSWizardData.java @ 5393

History | View | Annotate | Download (5.14 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, WMSOperations wizardListener) throws DriverException{
88
                wms = FMapWMSDriverFactory.getDriverForHost(host);
89
                this.wizardListener = wizardListener;
90
                wms.setWizardDataListener(this);
91
                // Send a getCapabilities request;
92
                if (!wms.connect(override))
93
                        throw new DriverException(PluginServices.getText(this, "cant_connect") + host.toString());
94
                
95
        }
96
        
97
        /**
98
         * M?todo para saber los formatos que admite la aplicaci?n
99
         *
100
         * @param format cadena con el formato a validar
101
         *
102
         * @return true si soportamos dicho formato y false en
103
         * caso contrario
104
         */
105
        private boolean isValidFormat(String format) {
106
                if (format.equalsIgnoreCase("image/png") ||
107
                                format.equalsIgnoreCase("image/jpg") ||
108
                                format.equalsIgnoreCase("image/tiff") ||
109
                                format.equalsIgnoreCase("image/jpeg") ||
110
                                format.equalsIgnoreCase("image/tif") ||
111
                                format.equalsIgnoreCase("image/gif")) {
112
                        return true;
113
                }
114
                
115
                return false;
116
        }
117
        
118
        public String getAbstract() {
119
                return theAbstract;
120
        }
121
        
122
        public String[] getFormats() {
123
                return formats;
124
        }
125
        
126
        public WMSLayerNode getLayer() {
127
                return layers;
128
        }
129
        
130
        public String getTitle() {
131
                return title;
132
        }
133
        
134
        public String getServerType() {
135
                if (serverVersion==null) return "WMS";
136
                return "WMS "+serverVersion;
137
        }
138
        
139
        public Hashtable getOnlineResources() {
140
                return onlineResources;
141
        }
142
        
143
        public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
144
                return wms.getLayersExtent(layerNames, srs);
145
        }
146
        
147
        public FMapWMSDriver getDriver() {
148
                return wms;
149
        }
150
        
151
        public boolean isQueryable() {
152
                return wms.isQueryable();
153
        }
154
        
155
        public void getMap(int eventType, File mapFile, String message) { /* Does not make sense in this context. */ };
156
        public void getFeatureInfo(int eventType, String message) { /* Does not make sense in this context. */ };
157
        
158
        public void getCapabilities(int eventType, String message) {
159
                if(eventType == WMSOperations.REQUEST_FINISHED) {
160
                        // Transfer complete -> initialize properties.
161
                        if (wms.getAbstract()  != null)
162
                                theAbstract = wms.getAbstract();
163
                        
164
                        Vector f = wms.getFormats(); 
165
                        ArrayList formatos = new ArrayList();
166
                        for (int i = 0; i < f.size(); i++) {
167
                                if (isValidFormat((String)f.elementAt(i))) {
168
                                        formatos.add(f.elementAt(i));
169
                                }
170
                        }
171
                        formats = (String[]) formatos.toArray(new String[0]);
172
                        serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion();
173
                        onlineResources = wms.getOnlineResources();
174
                        layers = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document
175
                        
176
                }        
177
                if (wizardListener!=null) {
178
                        // Notify WMSWizard that the data is ready.
179
                        wizardListener.getCapabilities(eventType, message);
180
                }
181
                
182
        }
183
        
184
        public void setWizardListener(WMSOperations listener) {
185
                this.wizardListener = listener;                
186
        }
187
        
188
        public void cancelTransfer() {
189
                wms.cancel(WMSOperations.GET_CAPABILITIES);
190
        }
191
}