Revision 5273 branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/gui/wizards/WMSWizardData.java

View differences:

WMSWizardData.java
40 40
 */
41 41
package com.iver.cit.gvsig.gui.wizards;
42 42

  
43
import java.awt.Component;
44 43
import java.awt.geom.Rectangle2D;
45 44
import java.io.File;
46
import java.io.IOException;
47
import java.net.ConnectException;
48 45
import java.net.URL;
49 46
import java.util.ArrayList;
50 47
import java.util.Hashtable;
51
import java.util.NoSuchElementException;
52 48
import java.util.Vector;
53 49

  
54
import javax.swing.JOptionPane;
55

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

  
58 50
import com.iver.andami.PluginServices;
59 51
import com.iver.cit.gvsig.fmap.DriverException;
60
import com.iver.cit.gvsig.fmap.drivers.WMSListener;
61 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;
62 55
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
63 56

  
64 57

  
......
67 60
 *
68 61
 * @author Jaume Dominguez Faus
69 62
 */
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;
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;
108 112
		}
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() {
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() {
154 139
		return onlineResources;
155 140
	}
156

  
157
    public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
158
        return wms.getLayersExtent(layerNames, srs);
159
    }
160
    
141
	
142
	public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
143
		return wms.getLayersExtent(layerNames, srs);
144
	}
145
	
161 146
	public FMapWMSDriver getDriver() {
162 147
		return wms;
163 148
	}
164 149
	
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);
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();
194 162
			
195
		}
196
    }
197

  
198
	public void setWizardListener(WMSListener listener) {
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) {
199 182
		this.wizardListener = listener;		
200 183
	}
201 184
	
202 185
	public void cancelTransfer() {
203
		wms.cancel(FMapWMSDriver.GET_CAPABILITIES);
186
		wms.cancel(WMSOperations.GET_CAPABILITIES);
204 187
	}
205 188
}

Also available in: Unified diff