Revision 9843

View differences:

org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/buildNumber.properties
1
#Sat Oct 05 19:11:11 CEST 2019
2
buildNumber=141
0 3

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
    <id>gvsig-plugin-package</id>
3
    <formats>
4
        <format>zip</format>
5
    </formats>
6
    <baseDirectory>${project.artifactId}</baseDirectory>
7
    <includeBaseDirectory>true</includeBaseDirectory>
8
    <files>
9
        <file>
10
            <source>target/${project.artifactId}-${project.version}.jar</source>
11
            <outputDirectory>lib</outputDirectory>
12
        </file>
13
        <file>
14
            <source>target/package.info</source>
15
        </file>
16
    </files>
17

  
18
    <fileSets>
19
        <fileSet>
20
            <directory>src/main/resources-plugin</directory>
21
            <outputDirectory>.</outputDirectory>
22
        </fileSet>
23
    </fileSets>
24

  
25

  
26
    <dependencySets>
27
        <dependencySet>
28
            <useProjectArtifact>false</useProjectArtifact>
29
            <useTransitiveDependencies>false</useTransitiveDependencies>
30
            <outputDirectory>lib</outputDirectory>
31
            <includes> 
32
                <include>org.gvsig:org.gvsig.raster.wms.remoteclient:jar</include>
33
                <include>org.gvsig:org.gvsig.raster.wms.io:jar</include>
34
            </includes>
35
        </dependencySet>
36
    </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/infobypoint/BrowserControl.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * Created on 18-oct-2004
26
 *
27
 * TODO To change the template for this generated file go to
28
 * Window - Preferences - Java - Code Generation - Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.raster.wms.app.wmsclient.infobypoint;
71
import java.io.IOException;
72
import java.util.ArrayList;
73
import java.util.List;
74

  
75
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
77

  
78
 
79
/**
80
* <p>A simple, static class to display a URL in the system browser.<br></p>
81
*
82
* <p>Under <b>Unix</b> systems, it will open one of the browser set through the
83
* <b>setBrowserCommand(String)</b>. The argument of this method
84
* must be a fully qualified command or one of the commands returned
85
* by <b>getSupportedBrowsers()</b>.<br>By default, the browser is Firefox,
86
* which is included in the list of supported browsers.<br></p>
87
*
88
* <p>Under <b>Windows</b>, this will bring up the default browser under windows,
89
* usually either Netscape or Microsoft IE.  The default browser is
90
* determined by the OS so no config is necessary.<br>This has been tested under Windows 95/98/NT/XP.</p>
91
* <p>Notice that <b>you must include</b> the url type -- either "http://" or  "file://".</p>
92
*
93
* <p>Under <b>Mac</b>, the usability of this class is pending of test. So probably it does not work</p>
94
* Examples:
95
* BrowserControl.displayURL("http://www.javaworld.com")
96
* BrowserControl.displayURL("file://c:\\docs\\index.html")
97
* BrowserContorl.displayURL("file:///user/joe/index.html");
98
*
99
* @author jaume dominguez faus - jaume.dominguez@iver.es
100
*/
101
public class BrowserControl
102
{
103
	private static Logger logger = LoggerFactory.getLogger(BrowserControl.class.getName());
104
	 // Used to identify the windows platform.
105
    private static final String WIN_ID = "Windows";
106
    // The default system browser under windows.
107
    private static final String WIN_PATH = "rundll32";
108
    // The flag to display a url.
109
    private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
110
    
111
	public static final String OPERA = "Opera";
112
	public static final String NETSCAPE = "Netscape";
113
	public static final String MOZILLA = "Mozilla";
114
	public static final String GALEON = "Galeon";
115
	public static final String EPIPHANY = "Epiphany";
116
	public static final String FIREFOX = "Firefox";
117
	public static final String CHROME = "google-chrome";
118
	public static final String KONQUEROR = "Konqueror";
119
	private String browserCommand = null;
120
	private List<String> supportedBrowsers;
121
	//public Preferences fPrefs = Preferences.userRoot().node( "gvsig.wcs-wizard" );
122
	
123
	public BrowserControl() {
124
		browserCommand = FIREFOX;//fPrefs.get("DefaultBrowser", FIREFOX);
125
	}
126
	
127
	private boolean throwBrowser(String browser, String url) {
128
		String url1 = url.replace("'", "\'");
129
		String url2 = "'" + url.replace("'", "\'") + "'";
130
		int exitCode = -1;
131
		String cmd = null;
132
		Process p = null;
133
		
134
		try {
135
			cmd = browser.toLowerCase() + " " + url1;
136
			logger.info("Trying..." + cmd);
137
			p = exec(cmd);
138
			exitCode = p.waitFor();
139
		} catch (IOException e) {
140
			exitCode = -1;
141
		} catch (InterruptedException e) {
142
			logger.info("Error bringing up browser, cmd='" + cmd + "'");
143
		}
144
		
145
		try {
146
			if (exitCode != 0) {
147
				cmd = browser.toLowerCase() + " "  + url2;
148
				logger.info("Trying..." + cmd);
149
				p = exec(cmd);
150
				exitCode = p.waitFor();
151
			}
152
		} catch (IOException e) {
153
			exitCode = -1;
154
		} catch(InterruptedException x) {
155
			logger.info("Error bringing up browser, cmd='" + cmd + "'");
156
		} 
157
		
158
		if(exitCode != 0)
159
			return false;
160
		return true;
161
	}
162

  
163
    /**
164
     * Display a file in the system browser.  If you want to display a
165
     * file, you must include the absolute path name.
166
     *
167
     * @param url the file's url (the url must start with either "http://" or  "file://").
168
     */
169
    public void displayURL(String url) {
170
        boolean windows = isWindowsPlatform();
171
        String cmd = null;
172
        try {
173
        	if (windows) {
174
        		// cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
175
        		cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
176
        		Runtime.getRuntime().exec(cmd);
177
        	} else {
178
        		if(throwBrowser(browserCommand, url)) {
179
        			return;
180
        		} else {
181
        			int i = 0;
182
        			boolean throwed = false;
183
        			while(i < getSupportedBrowsers().size() && ! throwed) {
184
        				throwed = throwBrowser(getSupportedBrowsers().get(i), url);
185
        				i++;
186
        			}
187
        		}
188
        	}
189
        } catch(IOException x) {
190
            // couldn't exec browser
191
        	logger.warn("Could not invoke browser, command=" + cmd);
192
        	logger.info("Caught: " + x);
193
        }
194

  
195
    }
196
    
197
    private Process exec(String cmd) throws IOException {
198
    	logger.info(cmd);
199
		return Runtime.getRuntime().exec(cmd);
200
    }
201

  
202
    /**
203
     * Try to determine whether this application is running under Windows
204
     * or some other platform by examing the "os.name" property.
205
     *
206
     * @return true if this application is running under a Windows OS
207
     */
208
    public static boolean isWindowsPlatform()
209
    {
210
        String os = System.getProperty("os.name");
211
        if ( os != null && os.startsWith(WIN_ID))
212
            return true;
213
        else
214
            return false;
215
    }
216

  
217

  
218
    
219
    /**
220
     * Returns a list of supported browsers.
221
     * @return
222
     */
223
    public List<String> getSupportedBrowsers() {
224
    	if (supportedBrowsers == null) {
225
    		supportedBrowsers = new ArrayList<String>();
226
    		supportedBrowsers.add(CHROME);
227
    		supportedBrowsers.add(FIREFOX);
228
    		supportedBrowsers.add(KONQUEROR);
229
    		supportedBrowsers.add(EPIPHANY);
230
    		supportedBrowsers.add(MOZILLA);
231
    		supportedBrowsers.add(NETSCAPE);
232
    		supportedBrowsers.add(OPERA);
233
    	}
234
    	return supportedBrowsers;
235
    }
236
}
0 237

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/infobypoint/InfoByWMSPointExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.wms.app.wmsclient.infobypoint;
23

  
24
import java.awt.Component;
25
import java.util.Observable;
26
import java.util.Observer;
27

  
28
import javax.swing.JOptionPane;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.PluginsLocator;
32
import org.gvsig.andami.actioninfo.ActionInfoManager;
33
import org.gvsig.andami.plugins.Extension;
34
import org.gvsig.andami.ui.mdiManager.IWindow;
35
import org.gvsig.app.project.documents.view.ViewDocument;
36
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
37
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior;
42
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
43
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
44
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
45
import org.gvsig.raster.fmap.layers.FLyrRaster;
46
import org.gvsig.raster.swing.RasterSwingLibrary;
47
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel;
48
import org.gvsig.raster.wms.app.wmsclient.infobypoint.viewtool.InfoByPixelPointViewTool;
49
import org.gvsig.raster.wms.app.wmsclient.infobypoint.viewtool.PixelInspectorViewTool;
50
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
51

  
52
/**
53
 * Plugin for the information by point of a raster layer
54
 * @author Nacho Brodin (nachobrodin@gmail.com)
55
 */
56
public class InfoByWMSPointExtension extends Extension  {
57
	private InfoByPixelPointViewTool     lastTool      = null;
58
	public static Behavior               oldBehavior   = null;
59

  
60
	public void execute(String actionCommand) {
61
		if(actionCommand.compareTo("INFO_BY_PIXEL") == 0) {
62
			MapControl mapCtrl = getMapControl();
63
			StatusBarListener sbl = new StatusBarListener(mapCtrl);
64
			
65
			IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
66
			for (int i = 0; i < wList.length; i++) {
67
				if(wList[i] instanceof MainInfoByPointDialog) {
68
					JOptionPane.showMessageDialog(
69
							(Component)wList[i], 
70
							PluginServices.getText(this, "open_window"), 
71
							PluginServices.getText(this, "Information"), 
72
							JOptionPane.INFORMATION_MESSAGE);
73
					mapCtrl.addBehavior("infoByRasterPoint", 
74
							new Behavior[]{new PointBehavior(lastTool),
75
							new MouseMovementBehavior(sbl)});
76
					mapCtrl.setTool("infoByRasterPoint");
77
					return;
78
				}
79
			}
80
			MainInfoByPointDialog dialog = new MainInfoByPointDialog();
81
			InfoByPointDataModel model = dialog.getInfoByPointDataModel();
82
			((Observable)model).addObserver((Observer)dialog.getMainPanel());
83
			
84
			lastTool = new InfoByPixelPointViewTool(mapCtrl, model, dialog);
85
			mapCtrl.addBehavior("infoByRasterPoint", 
86
					new Behavior[]{new PointBehavior(lastTool),
87
					new MouseMovementBehavior(sbl)});
88
			mapCtrl.setTool("infoByRasterPoint");
89
			oldBehavior = CompoundBehavior.getAllControlsBehavior();
90
			CompoundBehavior.setAllControlsBehavior(new PixelInspectorViewTool(mapCtrl, model, dialog.getPixelInspector()));
91
			
92
			model.notifyObservers();
93
			PluginServices.getMDIManager().addWindow(dialog);
94
		}
95
	}
96
	
97
	private MapControl getMapControl() {
98
		IWindow theView = PluginServices.getMDIManager().getActiveWindow();
99
		if(!(theView instanceof AbstractViewPanel)) {
100
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "window_not_valid"));
101
			return null;
102
		}
103
		return ((AbstractViewPanel)theView).getMapControl();
104
	}
105
	
106
	@SuppressWarnings("deprecation")
107
	public boolean isEnabled() {
108
		org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
109
		if (f == null)
110
			return false;
111
		if (f instanceof AbstractViewPanel) {
112
			AbstractViewPanel vista = (AbstractViewPanel) f;
113
			ViewDocument model = vista.getModel();
114
			MapContext mapa = model.getMapContext();
115
			FLayers layers = mapa.getLayers();
116
                        for (Object layer : layers.getActives()) {
117
                             if (layer instanceof FLyrWMS) {
118
                                    return true;
119
                            }
120
                        }
121
                }
122
		return false;
123
        }
124
	
125
	public boolean isVisible() {
126
		return isEnabled();
127
	}
128

  
129
	public void initialize() {
130
	}
131
	
132
	@Override
133
	public void postInitialize() {
134
		super.postInitialize();
135
		try {
136
			ActionInfoManager manager = PluginsLocator.getActionInfoManager();
137
			manager.redirect("layer-info-by-raster-point", "layer-info-by-wms-point");
138
		} catch (IllegalArgumentException e) {
139
			RasterSwingLibrary.messageBoxError("infobypoint_not_available", null);
140
		}
141
	}
142
}
0 143

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/infobypoint/MainInfoByPointDialog.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.wms.app.wmsclient.infobypoint;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.awt.Dimension;
27
import java.util.HashMap;
28

  
29
import javax.swing.ImageIcon;
30
import javax.swing.JEditorPane;
31
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
33
import javax.swing.event.HyperlinkEvent;
34
import javax.swing.event.HyperlinkListener;
35
import javax.swing.text.Document;
36
import javax.swing.text.html.HTMLEditorKit;
37
import javax.swing.text.html.StyleSheet;
38
import javax.swing.tree.DefaultMutableTreeNode;
39
import javax.swing.tree.DefaultTreeModel;
40
import javax.swing.tree.TreePath;
41

  
42
import org.gvsig.andami.IconThemeHelper;
43
import org.gvsig.andami.PluginServices;
44
import org.gvsig.andami.ui.mdiManager.IWindow;
45
import org.gvsig.andami.ui.mdiManager.WindowInfo;
46
import org.gvsig.app.project.documents.view.info.gui.XMLItem;
47
import org.gvsig.fmap.mapcontext.layers.FLayer;
48
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior;
49
import org.gvsig.raster.swing.RasterSwingLocator;
50
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel;
51
import org.gvsig.raster.swing.infobypoint.MainInfoByPointPanel;
52
import org.gvsig.raster.swing.pixelinspector.PixelInspector;
53
import org.gvsig.utils.xmlViewer.TextXMLContent;
54
import org.gvsig.utils.xmlViewer.XMLContent;
55
import org.gvsig.utils.xmlViewer.XMLViewer;
56
import org.slf4j.LoggerFactory;
57
import org.xml.sax.Attributes;
58
import org.xml.sax.ContentHandler;
59
import org.xml.sax.Locator;
60
import org.xml.sax.SAXException;
61

  
62
/**
63
 * Dialog for the information by point of a raster layer
64
 * @author Nacho Brodin (nachobrodin@gmail.com)
65
 */
66
public class MainInfoByPointDialog extends JPanel implements IWindow, HyperlinkListener {
67
	private static final long               serialVersionUID   = 1L;
68
	private MainInfoByPointPanel            mainPanel          = null;
69
	private JScrollPane                     scroll             = null;
70
	private JPanel                          wmsInfo            = null;
71
	private JEditorPane                     jeditor            = null;
72
	private XMLViewer                       dlgXML             = null;
73
	private XMLItem                         item               = null;
74
	private XMLContent                      xmlContent         = null;
75

  
76
	public class StringXMLItem extends TextXMLContent implements XMLItem {
77
		FLayer layer;
78

  
79
		public StringXMLItem(String text, FLayer lyr) {
80
			super(text);
81
			this.layer = lyr;
82
		}
83

  
84
		public FLayer getLayer(){
85
			return this.layer;
86
		}
87

  
88
		public void parse(ContentHandler handler) throws SAXException {
89
			setContentHandler(new FilterContentHandler(handler));
90
			parse();
91
		}
92

  
93
		private class FilterContentHandler implements ContentHandler {
94

  
95
			private ContentHandler handler;
96

  
97
			public FilterContentHandler(ContentHandler handler) {
98
				this.handler = handler;
99
			}
100

  
101
			public void setDocumentLocator(Locator arg0) {
102
			}
103

  
104
			public void startDocument() throws SAXException {
105
			}
106

  
107
			public void endDocument() throws SAXException {
108
			}
109

  
110
			public void startPrefixMapping(String arg0, String arg1)
111
					throws SAXException {
112
			}
113

  
114
			public void endPrefixMapping(String arg0) throws SAXException {
115
			}
116

  
117
			public void startElement(String arg0, String arg1, String arg2,
118
					Attributes arg3) throws SAXException {
119
				handler.startElement(arg0, arg1, arg2, arg3);
120
			}
121

  
122
			public void endElement(String arg0, String arg1, String arg2)
123
					throws SAXException {
124
				handler.endElement(arg0, arg1, arg2);
125
			}
126

  
127
			public void characters(char[] arg0, int arg1, int arg2)
128
					throws SAXException {
129
				handler.characters(arg0, arg1, arg2);
130
			}
131

  
132
			public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
133
					throws SAXException {
134
			}
135

  
136
			public void processingInstruction(String arg0, String arg1)
137
					throws SAXException {
138
			}
139

  
140
			public void skippedEntity(String arg0) throws SAXException {
141
			}
142
		}
143
	}
144

  
145
	public MainInfoByPointDialog() {
146
		setLayout(new BorderLayout());
147
		add((Component)getMainPanel(), BorderLayout.WEST);
148
		add((Component)getWMSInfoPanel(), BorderLayout.CENTER);
149
	}
150

  
151
	public MainInfoByPointPanel getMainPanel() {
152
		if(mainPanel == null) {
153
			HashMap<String, String> translations = new HashMap<String, String>();
154
			translations.put("info", PluginServices.getText(this, "info"));
155
			translations.put("view", PluginServices.getText(this, "view"));
156
			translations.put("layer_list", PluginServices.getText(this, "layer_list"));
157
			translations.put("band_values", PluginServices.getText(this, "band_values"));
158
			translations.put("pixel_point", PluginServices.getText(this, "pixel_point"));
159
			translations.put("view_point", PluginServices.getText(this, "view_point"));
160
			translations.put("world_point", PluginServices.getText(this, "world_point"));
161
			translations.put("bands", PluginServices.getText(this, "bands"));
162
			translations.put("colors", PluginServices.getText(this, "colors"));
163
			translations.put("coords", PluginServices.getText(this, "coords"));
164
			translations.put("lat", PluginServices.getText(this, "lat"));
165
			translations.put("long", PluginServices.getText(this, "long"));
166
			translations.put("red", PluginServices.getText(this, "red"));
167
			translations.put("green", PluginServices.getText(this, "green"));
168
			translations.put("blue", PluginServices.getText(this, "blue"));
169
			HashMap<String, ImageIcon> icons = new HashMap<String, ImageIcon>();
170
			icons.put("forward-icon", IconThemeHelper.getImageIcon("forward-icon"));
171
			icons.put("backward-icon", IconThemeHelper.getImageIcon("backward-icon"));
172
			mainPanel = RasterSwingLocator.getSwingManager().createInfoByPointPanel(
173
					translations, icons, null);
174
			((JPanel)mainPanel).setPreferredSize(new Dimension(230, 0));
175
		}
176
		return mainPanel;
177
	}
178

  
179
	private JPanel getWMSInfoPanel() {
180
		if(wmsInfo == null) {
181
			wmsInfo = new JPanel();
182
			wmsInfo.setLayout(new BorderLayout());
183
			jeditor = new JEditorPane();
184
			scroll = new JScrollPane(jeditor);
185
			jeditor.addHyperlinkListener(this);
186
			jeditor.setEditable(false);
187
			wmsInfo.add(scroll, BorderLayout.CENTER);
188
		}
189
		return wmsInfo;
190
	}
191

  
192
	private JPanel getWMSXMLInfoPanel(String text) throws SAXException {
193
		if(wmsInfo == null) {
194
			wmsInfo = new JPanel();
195
			wmsInfo.setLayout(new BorderLayout());
196
			dlgXML = new XMLViewer();
197
			scroll = new JScrollPane(dlgXML);
198
			item = new StringXMLItem(text, null);
199
			xmlContent = new XMLContent() {
200
				private ContentHandler handler;
201

  
202
				public void setContentHandler(ContentHandler arg0) {
203
					handler = arg0;
204
				}
205

  
206
				public void parse() throws SAXException {
207
					handler.startDocument();
208
					item.parse( handler);
209
					handler.endDocument();
210
				}
211
			};
212
			dlgXML.setNamesColumn(new String[0]);
213
			dlgXML.setModel(xmlContent);
214
			dlgXML.getXmlTree().setRootVisible(false);
215
			DefaultTreeModel treeModel = (DefaultTreeModel)dlgXML.getXmlTree().getModel();
216
			DefaultMutableTreeNode root = (DefaultMutableTreeNode) dlgXML.getXmlTree().getModel().getRoot();
217
			DefaultMutableTreeNode n = root.getFirstLeaf();
218
			TreePath path = new TreePath(treeModel.getPathToRoot(n));
219
			dlgXML.getXmlTree().expandPath(path);
220
			//dlgXML.getXmlTree().setSelectionPath(path);
221

  
222
			wmsInfo.add(scroll, BorderLayout.CENTER);
223
		}
224
		return wmsInfo;
225
	}
226

  
227
	public void setWMSInfoText(String text, String type) {
228
		if(type.equals("text/html")) {
229
			if(jeditor == null) {
230
				wmsInfo = null;
231
				dlgXML = null;
232
				remove(1);
233
				add((Component)getWMSInfoPanel(), BorderLayout.CENTER);
234
			}
235
			HTMLEditorKit kit = new HTMLEditorKit();
236
			jeditor.setEditorKit(kit);
237

  
238
			text = removeLabelBlock(text, "style");
239
			text = removeLabelBlock(text, "meta");
240

  
241
			StyleSheet s = kit.getStyleSheet();
242
			s.addRule("body {font-family:verdana; margin: 15px; }");
243
			s.addRule("caption {background-color:#FBFFE1;font-style:normal;color:black}");
244
			s.addRule("th {background-color:#D6D6D6;color:white;}");
245
			s.addRule("td {background-color:#FEEDD6;color:black;}");
246
			Document doc = kit.createDefaultDocument();
247
			jeditor.setDocument(doc);
248
			jeditor.setContentType(type);
249
			jeditor.setText(text);
250
		} else if(type.equals("text/xml")) {
251
			try {
252
				if(dlgXML == null) {
253
					wmsInfo = null;
254
					jeditor = null;
255
					remove(1);
256
					add((Component)getWMSXMLInfoPanel(text), BorderLayout.CENTER);
257
				} else {
258
					item = new StringXMLItem(text, null);
259
					dlgXML.setModel(xmlContent);
260
				}
261
			} catch (SAXException e) {
262
				LoggerFactory.getLogger(MainInfoByPointDialog.class).debug("", e);
263
			}
264
		} else { //if(type.equals("text/plain")) {
265
            if(jeditor == null) {
266
                wmsInfo = null;
267
                dlgXML = null;
268
                remove(1);
269
                add((Component)getWMSInfoPanel(), BorderLayout.CENTER);
270
            }
271
            jeditor.setText(text);
272
		}
273
	}
274

  
275
	/**
276
	 * Removes a label from the text
277
	 * @param text
278
	 * @param label
279
	 * @return
280
	 */
281
	private String removeLabelBlock(String text, String label) {
282
		if(text.contains("<" + label) && text.contains("/" + label + ">")) {
283
			int initIndex = text.indexOf("<" + label);
284
			int endIndex = text.indexOf("/" + label + ">");
285
			return text.substring(0, initIndex) + text.substring(endIndex + 7, text.length());
286
		}
287
		return text;
288
	}
289

  
290
	public WindowInfo getWindowInfo() {
291
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
292
		m_viewinfo.setTitle(PluginServices.getText(this, "WMS InfoByPoint"));
293
		m_viewinfo.setHeight(380);
294
		m_viewinfo.setWidth(700);
295
		return m_viewinfo;
296
	}
297

  
298
	public void windowClosed() {
299
		CompoundBehavior.setAllControlsBehavior(InfoByWMSPointExtension.oldBehavior);
300
	}
301

  
302
	public Object getWindowProfile() {
303
		return WindowInfo.PROPERTIES_PROFILE;
304
	}
305

  
306
	public InfoByPointDataModel getInfoByPointDataModel() {
307
		return getMainPanel().getInfoByPointDataModel();
308
	}
309

  
310
	public PixelInspector getPixelInspector() {
311
		return getMainPanel().getPixelInspectorPanel();
312
	}
313

  
314
	public void hyperlinkUpdate(HyperlinkEvent e) {
315
		if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
316
			new BrowserControl().displayURL(e.getURL().toString());
317
		}
318
	}
319
}
0 320

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/infobypoint/viewtool/InfoByPixelPointViewTool.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.wms.app.wmsclient.infobypoint.viewtool;
23

  
24
import java.awt.Image;
25
import java.awt.Point;
26
import java.awt.geom.Point2D;
27
import java.awt.image.BufferedImage;
28
import java.util.ArrayList;
29
import java.util.List;
30
import java.util.logging.Level;
31
import java.util.logging.Logger;
32

  
33
import org.gvsig.andami.IconThemeHelper;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.coverage.RasterManager;
36
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
37
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
38
import org.gvsig.fmap.dal.coverage.util.ColorConversion;
39
import org.gvsig.fmap.dal.exception.DataException;
40
import org.gvsig.fmap.mapcontext.ViewPort;
41
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
42
import org.gvsig.fmap.mapcontext.layers.FLayer;
43
import org.gvsig.fmap.mapcontext.layers.FLayers;
44
import org.gvsig.fmap.mapcontrol.MapControl;
45
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
46
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
47
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
48
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel;
49
import org.gvsig.raster.wms.app.wmsclient.infobypoint.MainInfoByPointDialog;
50
import org.gvsig.raster.wms.app.wmsclient.layer.DynObjectSetWMSInfo;
51
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
52
import org.gvsig.tools.exception.BaseException;
53
import org.gvsig.tools.visitor.VisitCanceledException;
54
import org.gvsig.tools.visitor.Visitor;
55

  
56
/**
57
 * Extensi?n de la clase SelectImageListenerImple de FMap. Esta clase permite
58
 * capturar el evento de la selecci?n de un punto RGB sobre la vista
59
 *
60
 * 22/02/2008
61
 * @author Nacho Brodin (nachobrodin@gmail.com)
62
 */
63
public class InfoByPixelPointViewTool implements PointListener {
64
	private RasterManager            rManager            = RasterLocator.getManager();
65
	private InfoByPointDataModel     model               = null;
66
	private ColorConversion          conv                = null;
67
	private ViewPort                 viewPort            = null;
68
	private FLayers                  layers              = null;
69
	private List<String>             list                = null;
70
	private MainInfoByPointDialog    dialog              = null;
71

  
72
	/**
73
	 * Reference to the <code>MapControl</code> object that uses.
74
	 */
75
	protected MapControl mapCtrl;
76

  
77
	/**
78
	 * World equivalent coordinates of the point 2D
79
	 */
80
	protected Point2D wcPoint = null;
81

  
82
	/**
83
	 * Contructor
84
	 * @param mapCtrl
85
	 */
86
	public InfoByPixelPointViewTool(
87
			MapControl mapCtrl,
88
			InfoByPointDataModel model,
89
			MainInfoByPointDialog dialog) {
90
		this.mapCtrl = mapCtrl;
91
		this.model = model;
92
		this.dialog = dialog;
93
		conv = rManager.getColorConversion();
94
		viewPort = mapCtrl.getViewPort();
95
		layers = mapCtrl.getMapContext().getLayers();
96
		list = new ArrayList<String>();
97
	}
98

  
99
	@SuppressWarnings("deprecation")
100
	public void point(PointEvent event) {
101
		Point2D point2D = event.getPoint();
102

  
103
		BufferedImage image = mapCtrl.getImage();
104
		int value = image.getRGB((int) point2D.getX(), (int) point2D.getY());
105
		int r = (value >> 16) & 0xff;
106
		int g = (value >> 8) & 0xff;
107
		int b = value & 0xff;
108

  
109
		double[] cmyk = conv.RGBtoCMYK(r & 0xff, g & 0xff, b & 0xff, 1D);
110

  
111
		double[] hsl = conv.RGBtoHSL(r & 0xff, g & 0xff, b & 0xff);
112
		hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
113
		hsl[2] = (int) (hsl[2] * 255. + 0.5);
114
		hsl[1] = (int) (hsl[1] * 255. + 0.5);
115

  
116
		Point2D mapPoint = viewPort.toMapPoint(point2D);
117

  
118
		model.setARGB(r, g, b);
119
		model.setCMYK(cmyk);
120
		model.setHSL(hsl[0], hsl[1], hsl[2]);
121
		model.setViewPoint(point2D.getX(), point2D.getY());
122
		model.setWorldPoint(mapPoint.getX(), mapPoint.getY());
123

  
124
		//Raster dependent
125

  
126
		list.clear();
127
		FLyrWMS selected = null;
128
              
129
                for (FLayer lyr : layers.getVisibles()) {
130
			if(lyr instanceof FLyrWMS) {
131
				FLyrWMS raster = (FLyrWMS)lyr;
132
				if(raster.isInside(mapPoint)) {
133
					list.add(raster.getName());
134
					if(raster.isActive())
135
						selected = raster;
136
				}
137
			}
138
		}
139

  
140
		if(selected != null) {
141
			Point2D rasterPoint = selected.getDataStore().worldToRaster(mapPoint);
142
			model.setNumberOfBands(selected.getDataStore().getBandCount());
143
			model.setBandValues(getBandValues(selected.getDataStore(), rasterPoint));
144
			model.setPixelPoint(rasterPoint.getX(), rasterPoint.getY());
145

  
146
			Point p = new Point();
147
			p.setLocation(point2D.getX(), point2D.getY());
148
			try {
149
			    DynObjectSetWMSInfo dos = (DynObjectSetWMSInfo)selected.getInfo(p, 0D, null, true);
150
			    String txt = dos.getInfoElement();
151
			    if(dos.getTypeInfo().compareTo("text/plain") == 0)
152
			        dialog.setWMSInfoText(txt, dos.getTypeInfo());
153
			    else if(dos.getTypeInfo().compareTo("text/html") == 0) {
154
			        int beginIndex = txt.indexOf("<html");
155
			        if(beginIndex > 0)
156
			            txt = txt.substring(beginIndex, txt.length());
157
			        dialog.setWMSInfoText(txt, "text/html");
158
			    } else if(dos.getTypeInfo().endsWith("vnd.ogc.gml") || dos.getTypeInfo().compareTo("text/xml") == 0) {
159
			        dialog.setWMSInfoText(txt, "text/xml");
160
			    }else
161
			        dialog.setWMSInfoText(txt, "text/html");
162

  
163
			} catch (LoadLayerException e) {
164
			    e.printStackTrace();
165
			} catch (DataException e) {
166
			    e.printStackTrace();
167
			}
168
		} else {
169
			list.clear();
170
			list.add("...");
171
			model.setNumberOfBands(0);
172
			model.setBandValues(new double[]{Double.NaN});
173
			model.setPixelPoint(-1, -1);
174
		}
175
		model.setLayerList(list);
176

  
177
		model.notifyObservers();
178
	}
179

  
180
	/**
181
	 * Loads the values of a pixel point
182
	 * @param dataStore
183
	 * @param pxPoint
184
	 * @return
185
	 */
186
	private double[] getBandValues(RasterDataStore dataStore, Point2D pxPoint) {
187
		double[] res = new double[dataStore.getBandCount()];
188
		int pos = 0;
189
		try {
190
			if(dataStore.getDataType()[0] >= 0 && dataStore.getDataType()[0] <= 3) {
191
				for(int i = 0; i < dataStore.getBandCount(); i++) {
192
					int val = ((Integer)dataStore.getData((int)pxPoint.getX(), (int)pxPoint.getY(), i)).intValue();
193
					if(dataStore.getDataType()[0] == Buffer.TYPE_BYTE)
194
						res[pos] = (val & 0x000000ff);
195
					else
196
						res[pos] = val;
197
					pos ++;
198
				}
199
			}
200

  
201
			if(dataStore.getDataType()[0] == 4) {
202
				for(int i = 0; i < dataStore.getBandCount(); i++) {
203
					res[pos] = ((Float)dataStore.getData((int)pxPoint.getX(), (int)pxPoint.getY(), i)).doubleValue() ;
204
					pos ++;
205
				}
206
			}
207
			if(dataStore.getDataType()[0] == 5) {
208
				for(int i = 0; i < dataStore.getBandCount(); i++) {
209
					res[pos] = ((Double)dataStore.getData((int)pxPoint.getX(), (int)pxPoint.getY(), i)).doubleValue();
210
					pos ++;
211
				}
212
			}
213
			return res;
214
		} catch (Exception e) {
215
			for (int i = 0; i < dataStore.getBandCount(); i++) {
216
				res[i] = Double.NaN;
217
			}
218
		}
219
		return res;
220
	}
221

  
222
	public void pointDoubleClick(PointEvent event) throws BehaviorException {
223
	}
224

  
225
	public boolean cancelDrawing() {
226
		return true;
227
	}
228

  
229
	public Image getImageCursor() {
230
		return IconThemeHelper.getImage("zoom-pixel-cursor");
231
	}
232
}
0 233

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/infobypoint/viewtool/PixelInspectorViewTool.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.wms.app.wmsclient.infobypoint.viewtool;
23

  
24
import java.awt.event.MouseEvent;
25
import java.awt.geom.Point2D;
26
import java.awt.image.BufferedImage;
27

  
28
import org.gvsig.fmap.dal.coverage.RasterLocator;
29
import org.gvsig.fmap.dal.coverage.RasterManager;
30
import org.gvsig.fmap.dal.coverage.util.ColorConversion;
31
import org.gvsig.fmap.mapcontext.ViewPort;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontrol.MapControl;
34
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
35
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
36
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
37
import org.gvsig.raster.fmap.layers.FLyrRaster;
38
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel;
39
import org.gvsig.raster.swing.pixelinspector.PixelInspector;
40

  
41

  
42
/**
43
 * Behavior to be added to the MapControl. With this behavior will be
44
 * possible to manage the mouse event on the view 
45
 * 
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class PixelInspectorViewTool extends Behavior {
49
	private RasterManager            rManager            = RasterLocator.getManager();
50
	private InfoByPointDataModel     model               = null;
51
	private ColorConversion          conv                = null;
52
	private ViewPort                 viewPort            = null;
53
	private MapControl               mapCtrl             = null;
54
	private PixelInspector           observer            = null;
55
	
56
	/**
57
	 * Constructor. Asigna el dialogo
58
	 * @param dialog
59
	 */
60
	public PixelInspectorViewTool(MapControl mapCtrl, InfoByPointDataModel model, PixelInspector observer) {
61
		this.mapCtrl = mapCtrl;
62
		this.model = model;
63
		this.observer = observer;
64
		conv = rManager.getColorConversion();
65
		viewPort = mapCtrl.getViewPort();
66
	}
67
	
68
	public FLyrRaster getLayer(Point2D p) {
69
		FLyrRaster raster = null;
70
		for (int i = mapCtrl.getMapContext().getLayers().getLayersCount() - 1; i >= 0; i--) {
71
			FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i);
72
			if(lyr instanceof FLyrRaster) {
73
				raster = (FLyrRaster)lyr;
74
				if(raster.isInside(p))
75
					return raster;
76
			}
77
		}
78
		return null;
79
	}
80
	
81
	/*
82
	 *  (non-Javadoc)
83
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.IBehavior#getListener()
84
	 */
85
	public ToolListener getListener() {
86
		return null;
87
	}
88
	
89
	/*
90
	 *  (non-Javadoc)
91
	 * @see com.iver.cit.gvsig.fmap.tools.Behavior.IBehavior#mouseMoved(java.awt.event.MouseEvent)
92
	 */
93
	@SuppressWarnings("deprecation")
94
	public void mouseMoved(MouseEvent e) throws BehaviorException {
95
		Point2D point2D = new Point2D.Double(e.getX(), e.getY());
96
		BufferedImage image = mapCtrl.getImage();
97
		
98
		//Actualiza los datos del panel
99
		if(e.getX() >= image.getWidth() || e.getY() >= image.getHeight())
100
			return;
101
		int value = image.getRGB((int) point2D.getX(), (int) point2D.getY());
102
		int r = (value >> 16) & 0xff;
103
		int g = (value >> 8) & 0xff;
104
		int b = value & 0xff;
105
		
106
		double[] cmyk = conv.RGBtoCMYK(r & 0xff, g & 0xff, b & 0xff, 1D);
107
		
108
		double[] hsl = conv.RGBtoHSL(r & 0xff, g & 0xff, b & 0xff);
109
		hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
110
		hsl[2] = (int) (hsl[2] * 255. + 0.5);
111
		hsl[1] = (int) (hsl[1] * 255. + 0.5);
112
		
113
		Point2D mapPoint = viewPort.toMapPoint(point2D);
114
		
115
		model.setARGB(r, g, b);
116
		model.setCMYK(cmyk);
117
		model.setHSL(hsl[0], hsl[1], hsl[2]);
118
		model.setViewPoint(point2D.getX(), point2D.getY());
119
		model.setWorldPoint(mapPoint.getX(), mapPoint.getY());
120
		
121
		//Raster dependent
122
		FLyrRaster raster = getLayer(mapPoint);
123
		if(raster != null && raster.getDataStore() != null) {
124
			Point2D rasterPoint = raster.getDataStore().worldToRaster(mapPoint);
125
			model.setNumberOfBands(raster.getDataStore().getBandCount());
126
			model.setPixelPoint(rasterPoint.getX(), rasterPoint.getY());
127
		} /*else {
128
			model.setNumberOfBands(0);
129
			model.setBandValues(new double[]{Double.NaN});
130
			model.setPixelPoint(-1, -1);
131
		}*/
132
		
133
		model.notifyObservers();
134
		
135
		//Actualiza el inspector
136
		observer.setClear(false);
137
		observer.setDataBuffer(image);
138
		int pX = ((observer.getWidth() / observer.getScale()) >> 1) - e.getX();
139
		int pY = ((observer.getHeight() / observer.getScale()) >> 1) - e.getY();
140
		observer.setViewCoordinates((int)e.getPoint().getX(), (int)e.getPoint().getY());
141
		observer.setPosX(pX);
142
		observer.setPosY(pY);
143
		observer.repaint();
144
	}
145

  
146
}
0 147

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/WMSClientExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wms.app.wmsclient;
24

  
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.app.extension.AddLayer;
28
import org.gvsig.raster.wms.app.wmsclient.gui.toc.WMSPropsTocMenuEntry;
29
import org.gvsig.raster.wms.app.wmsclient.gui.wizard.WMSWizard;
30
import org.gvsig.raster.wms.app.wmsclient.layer.DynObjectSetWMSInfo;
31
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.extensionpoint.ExtensionPoint;
34

  
35

  
36
/**
37
 * Extension for adding WMS support to gvSIG.
38
 *
39
 * @author jaume dominguez faus - jaume.dominguez@iver.es
40
 */
41
public class WMSClientExtension extends Extension {
42

  
43
    public void initialize() {
44
    	
45
    	// Adds an entry to the TOC's floating menu to those layers defined in this extension
46
		ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add(
47
				"View_TocActions");
48

  
49
		exPoint.append("WMSProperties", "", new WMSPropsTocMenuEntry());
50

  
51
        // Adds a new tab to the "add layer" wizard for WMS layer creation
52
    	AddLayer.addWizard(WMSWizard.class);
53

  
54
    	ToolsLocator.getExtensionPointManager().add("CatalogLayers").append(
55
				"OGC:WMS", "", FLyrWMS.class);
56
    	initilizeIcons();
57
    	DynObjectSetWMSInfo.registerDynClass();
58
    }
59
    
60
	public void postInitialize() {
61
		FLyrWMS.registerPersistent();
62
	}
63

  
64
    public void execute(String actionCommand) {
65
    	// no commands, no code.
66
    }
67

  
68
    public boolean isEnabled() {
69
    	// may return whatever
70
        return false;
71
    }
72

  
73
    public boolean isVisible() {
74
    	// may return whatever
75
        return false;
76
    }
77

  
78
    void initilizeIcons(){
79
		IconThemeHelper.registerIcon(null, "aplication-preferences-uparrow", this);
80
		IconThemeHelper.registerIcon(null, "aplication-preferences-downarrow", this);
81
		IconThemeHelper.registerIcon(null, "icon-layer-wms", this);
82
    }
83
}
0 84

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.86/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/gui/dialog/WMSPropsDialog.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wms.app.wmsclient.gui.dialog;
24

  
25
import java.awt.Dimension;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Vector;
31

  
32
import javax.swing.JButton;
33
import javax.swing.JDialog;
34
import javax.swing.JOptionPane;
35
import javax.swing.JPanel;
36
import javax.swing.tree.TreePath;
37

  
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.ui.mdiManager.IWindow;
40
import org.gvsig.andami.ui.mdiManager.WindowInfo;
41
import org.gvsig.app.gui.wizards.WizardListener;
42
import org.gvsig.app.gui.wizards.WizardListenerSupport;
43
import org.gvsig.fmap.dal.coverage.exception.ConnectException;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.mapcontext.MapContext;
46
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException;
47
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException;
48
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
49
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
50
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException;
51
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException;
52
import org.gvsig.fmap.mapcontext.exceptions.TypeLayerException;
53
import org.gvsig.fmap.mapcontext.exceptions.URLLayerException;
54
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException;
55
import org.gvsig.fmap.mapcontext.layers.FLayer;
56
import org.gvsig.fmap.mapcontext.layers.FLayers;
57
import org.gvsig.fmap.mapcontrol.MapControl;
58
import org.gvsig.raster.fmap.layers.FLyrRaster;
59
import org.gvsig.raster.swing.RasterSwingLibrary;
60
import org.gvsig.raster.util.CancelTaskImpl;
61
import org.gvsig.raster.wms.app.wmsclient.gui.panel.WMSParamsPanel;
62
import org.gvsig.raster.wms.app.wmsclient.gui.wizard.LayerTreeModel;
63
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
64
import org.gvsig.raster.wms.io.RemoteWMSStyle;
65
import org.gvsig.raster.wms.io.WMSLayerNode;
66
import org.gvsig.raster.wms.io.WMSServerExplorer;
67
import org.slf4j.Logger;
68
import org.slf4j.LoggerFactory;
69

  
70

  
71
/**
72
 * The TOC WMS properties panel container.
73
 *
74
 * @author jaume - 
75
 *
76
 */
77
public class WMSPropsDialog extends JPanel implements IWindow {
78

  
79
	private static final long         serialVersionUID    = 1L;
80
	private Logger                   logger              = LoggerFactory.getLogger(WMSPropsDialog.class);
81
	JDialog                           dlg                 = null;  
82
	private JPanel                    buttonsPanel        = null;
83
	private FLyrRaster                fLayer              = null;
84
	boolean                           applied             = false;;
85
	private WindowInfo                m_ViewInfo          = null;
86

  
87
	private JButton                   btnApply            = null;
88
	private JButton                   btnOk               = null;
89
	private JButton                   btnCancel           = null;
90
	private WMSParamsPanel            wmsParamsTabbedPane;
91
    private CommandListener           m_actionListener;
92
    private WMSServerExplorer         explorer            = null;
93

  
94
    public WMSPropsDialog(FLayer layer) {
95
		super();
96
		if(layer instanceof FLyrRaster)
97
			initialize((FLyrRaster)layer);
98
	}
99

  
100

  
101
	private void initialize(FLyrRaster layer) {
102
		setLayout(null);
103

  
104
        setFLayer(layer);
105
        wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties());
106
        wmsParamsTabbedPane.addWizardListener(new WizardListener(){
107
			public void wizardStateChanged(boolean finishable) {
108
				getBtnOk().setEnabled(finishable);
109
				getBtnApply().setEnabled(finishable);
110
			}
111

  
112
			public void error(Exception e) {
113
			}
114

  
115
        })  ;
116
        wmsParamsTabbedPane.disableDisagregatedLayers();
117
        this.add(wmsParamsTabbedPane);
118
        this.add(getButtonsPanel(), null);
119

  
120
	}
121

  
122

  
123
	public void setFLayer(FLyrRaster f) {
124
		fLayer = f;
125
	}
126

  
127
	/**
128
	 * With getParamsPanel we have access to the map config TabbedPane.
129
	 * If this panel doesn't exist yet (which can occur when an existing project is
130
	 * recovered) it is been automatically constructed by connecting to the server,
131
	 * reloading the necessary data, filling up the content and setting the selected
132
	 * values that were selected when the projet was saved.
133
	 *
134
	 *
135
	 * Since a connection to the server is needed when rebuiliding the panel, this
136
	 * causes a delay for the panel's showing up or a nullPointer error if there is
137
	 * no path to the server.
138
	 *
139
	 *
140
	 * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
141
	 * del mapa. Si este panel todav?a no existe (como puede ser cuando
142
	 * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
143
	 * al servidor, recuperando los datos necesarios, rellenando el contenido y
144
	 * dejando seleccionados los valores que estaban seleccionados cuando se
145
	 * guarda el proyecto.
146
	 *
147
	 *
148
	 * Como para reconstruirse requiere una conexi?n con el servidor esto causa
149
	 * un retardo en la aparici?n en el toc o un error de nullPointer si no
150
	 * hay conexi?n hasta el servidor.
151
	 *
152
	 *
153
	 * @return WMSParamsPanel
154
	 */
155
	@SuppressWarnings({ "unchecked" })
156
	public WMSParamsPanel getParamsPanel(HashMap info) {
157
	    if (info != null) {
158
	    	try {
159
	    		if(explorer == null) {
160
					explorer = ((FLyrWMS)fLayer).getExplorer();
161
					
162
					try {
163
			    		explorer.connect(new CancelTaskImpl(), true);
164
					} catch (ConnectException e) {
165
						RasterSwingLibrary.messageBoxError("The connection cannot be established", this, e);
166
						return null;
167
					} 
168
	    		}
169
	    	} catch (Exception e) {
170
	    		explorer = null;
171
	    		JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
172
	    	}
173
	    	try {
174
	        	
175
                // name
176
	            WMSParamsPanel toc = new WMSParamsPanel();
177
	            toc.setLayerName((String)info.get("name"));
178
	            toc.setWizardData(explorer);
179

  
180
	            toc.setVisible(true);
181
	            toc.setListenerSupport(new WizardListenerSupport());
182

  
183
	            WMSLayerNode[] selectedLayers = (WMSLayerNode[]) ((Vector) info.get("selectedLayers")).toArray(new WMSLayerNode[0]);
184
	            for (int i = 0; i < selectedLayers.length; i++) {
185
	            	toc.getJustTreeLayer().clearSelection();
186
	            	//  Se a?ade a la lista de layers seleccionados
187
	            	TreePath path = new TreePath(((LayerTreeModel)toc.getJustTreeLayer()
188
	            						.getModel()).getNodeByName(selectedLayers[i].getName()));
189
	            	toc.getJustTreeLayer().addSelectionPath(path);
190
	            	toc.addLayer();
191
                }
192

  
193
                // srs
194
                String srs = (String) info.get("srs");
195
                int index = toc.getSRSIndex( srs );
196
	            if (index != -1) {
197
					toc.getLstSRSs().setSelectedIndex(index);
198
				}
199

  
200
                // format
201
	            String format = (String) info.get("format");
202
	            index = toc.getFormatIndex(format);
203
	            if (index != -1) {
204
					toc.getLstFormats().setSelectedIndex(index);
205
				}
206
	            
207
	            //info format
208
	            String infoFormat = (String) info.get("infoformat");
209
	            index = toc.getInfoFormatIndex(infoFormat);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff