Revision 3316

View differences:

org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.wms</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.8</version>
7
	<name>${project.artifactId}</name>
8
	<description>wms client</description>
9
	<inceptionYear>2011</inceptionYear>
10
	
11
	<parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.desktop</artifactId>
14
      <version>2.0.90</version>
15
  </parent>
16

  
17
        <properties>
18
            <!-- El plugin versions:use-latest-versions falla con scope import -->
19
            <!-- asi que toca usar el versions:update-properties que si que funciona -->
20
            <org.gvsig.raster.version>2.2.11</org.gvsig.raster.version>
21
        </properties>
22
    
23
    <repositories>
24
      <repository>
25
        <id>gvsig-public-http-repository</id>
26
        <name>gvSIG maven public HTTP repository</name>
27
        <url>http://devel.gvsig.org/m2repo/j2se</url>
28
        <releases>
29
          <enabled>true</enabled>
30
          <updatePolicy>daily</updatePolicy>
31
          <checksumPolicy>warn</checksumPolicy>
32
        </releases>
33
        <snapshots>
34
          <enabled>true</enabled>
35
          <updatePolicy>daily</updatePolicy>
36
          <checksumPolicy>warn</checksumPolicy>
37
        </snapshots>
38
      </repository>
39
    </repositories>
40
    
41
    <scm>
42
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8</connection>
43
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8</developerConnection>
44
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8</url>
45
    </scm>
46
    
47
    <build>
48
        <plugins>
49
            <plugin>
50
                <groupId>org.apache.maven.plugins</groupId>
51
                <artifactId>maven-release-plugin</artifactId>
52
                <configuration>
53
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.wms/tags/</tagBase>
54
                    <goals>deploy</goals>
55
                </configuration>
56
            </plugin>
57
        </plugins>
58
    </build>
59
    
60
    <dependencyManagement>
61
		<dependencies>
62
                        <dependency>
63
                                <groupId>org.gvsig</groupId>
64
                                <artifactId>org.gvsig.raster</artifactId>
65
                                <version>${org.gvsig.raster.version}</version>
66
                                <type>pom</type>
67
                                <scope>import</scope>
68
                        </dependency>
69

  
70
			<dependency>
71
				<groupId>org.gvsig</groupId>
72
				<artifactId>org.gvsig.raster.wms.io</artifactId>
73
				<version>2.2.8</version>
74
			</dependency>
75
			<dependency>
76
				<groupId>org.gvsig</groupId>
77
				<artifactId>org.gvsig.raster.wms.remoteclient</artifactId>
78
				<version>2.2.8</version>
79
			</dependency>
80
			<dependency>
81
				<groupId>org.gvsig</groupId>
82
				<artifactId>org.gvsig.raster.wms.app.wmsclient</artifactId>
83
				<version>2.2.8</version>
84
			</dependency>
85

  
86
		</dependencies>
87
	</dependencyManagement>
88

  
89
	<modules>
90
		<module>org.gvsig.raster.wms.remoteclient</module>
91
		<module>org.gvsig.raster.wms.io</module>
92
		<module>org.gvsig.raster.wms.app.wmsclient</module>
93
	</modules>
94
</project>
95

  
0 96

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/org.gvsig.raster.wms.app.wmsclient/buildNumber.properties
1
#Thu Apr 02 16:04:28 CEST 2015
2
buildNumber=62
0 3

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/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.8/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/exception/WMSDriverExceptionType.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.exception;
23

  
24
import org.gvsig.remoteclient.wms.WMSStatus;
25
import org.gvsig.utils.ExceptionDescription;
26

  
27

  
28
public class WMSDriverExceptionType extends ExceptionDescription {
29

  
30
	WMSStatus status;
31
	
32
	public WMSDriverExceptionType(){
33
		super(65, "Error al acceder a un servicio WMS");
34
		
35
	}
36
	
37
	public String getHtmlErrorMessage() {
38
		String message = "<p><b>Error en una petici?n a servidor WMS</b></p>";
39
		message += "Informaci?n adicional:<br>";
40
		message += "Direcci?n: " + status.getOnlineResource();
41
		message += "<br> Formato: "+status.getFormat();
42
		return message;
43
	}
44

  
45
	public WMSStatus getWmsStatus() {
46
		return status;
47
	}
48

  
49
	public void setWmsStatus(WMSStatus wmsStatus) {
50
		this.status = wmsStatus;
51
	}
52

  
53

  
54
}
55

  
0 56

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/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

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

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

  
72
	/**
73
	 * World equivalent coordinates of the point 2D 
74
	 */
75
	protected Point2D wcPoint = null;
76
	
77
	/**
78
	 * Contructor
79
	 * @param mapCtrl
80
	 */
81
	public InfoByPixelPointViewTool(
82
			MapControl mapCtrl, 
83
			InfoByPointDataModel model,
84
			MainInfoByPointDialog dialog) {
85
		this.mapCtrl = mapCtrl;
86
		this.model = model;
87
		this.dialog = dialog;
88
		conv = rManager.getColorConversion();
89
		viewPort = mapCtrl.getViewPort();
90
		layers = mapCtrl.getMapContext().getLayers();
91
		list = new ArrayList<String>();
92
	}
93

  
94
	@SuppressWarnings("deprecation")
95
	public void point(PointEvent event) {
96
		Point2D point2D = event.getPoint();
97

  
98
		BufferedImage image = mapCtrl.getImage();
99
		int value = image.getRGB((int) point2D.getX(), (int) point2D.getY());
100
		int r = (value >> 16) & 0xff;
101
		int g = (value >> 8) & 0xff;
102
		int b = value & 0xff;
103
		
104
		double[] cmyk = conv.RGBtoCMYK(r & 0xff, g & 0xff, b & 0xff, 1D);
105
		
106
		double[] hsl = conv.RGBtoHSL(r & 0xff, g & 0xff, b & 0xff);
107
		hsl[0] = (int)(255.0 * hsl[0] / 360.0 + 0.5);
108
		hsl[2] = (int) (hsl[2] * 255. + 0.5);
109
		hsl[1] = (int) (hsl[1] * 255. + 0.5);
110
		
111
		Point2D mapPoint = viewPort.toMapPoint(point2D);
112
		
113
		model.setARGB(r, g, b);
114
		model.setCMYK(cmyk);
115
		model.setHSL(hsl[0], hsl[1], hsl[2]);
116
		model.setViewPoint(point2D.getX(), point2D.getY());
117
		model.setWorldPoint(mapPoint.getX(), mapPoint.getY());
118
		
119
		//Raster dependent
120
		
121
		list.clear();
122
		FLyrWMS selected = null;
123
		for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
124
			FLayer lyr = layers.getLayer(i);
125
			if(lyr instanceof FLyrWMS) {
126
				FLyrWMS raster = (FLyrWMS)lyr;
127
				if(raster.isInside(mapPoint)) {
128
					list.add(raster.getName());
129
					if(raster.isActive())
130
						selected = raster;
131
				}
132
			}
133
		}
134
		
135
		if(selected != null) {
136
			Point2D rasterPoint = selected.getDataStore().worldToRaster(mapPoint);
137
			model.setNumberOfBands(selected.getDataStore().getBandCount());
138
			model.setBandValues(getBandValues(selected.getDataStore(), rasterPoint));
139
			model.setPixelPoint(rasterPoint.getX(), rasterPoint.getY());
140
		} else {
141
			list.clear();
142
			list.add("...");
143
			model.setNumberOfBands(0);
144
			model.setBandValues(new double[]{Double.NaN});
145
			model.setPixelPoint(-1, -1);
146
		}
147
		model.setLayerList(list);
148
		
149
		Point p = new Point();
150
		p.setLocation(point2D.getX(), point2D.getY());
151
		try {
152
			DynObjectSetWMSInfo dos = (DynObjectSetWMSInfo)selected.getInfo(p, 0D, null, true);
153
			String txt = dos.getInfoElement();
154
			if(dos.getTypeInfo().compareTo("text/plain") == 0)
155
				dialog.setWMSInfoText(txt, dos.getTypeInfo());
156
			else if(dos.getTypeInfo().compareTo("text/html") == 0) {
157
				int beginIndex = txt.indexOf("<html");
158
				if(beginIndex > 0)
159
					txt = txt.substring(beginIndex, txt.length());
160
				dialog.setWMSInfoText(txt, "text/html");
161
			} else if(dos.getTypeInfo().endsWith("vnd.ogc.gml") || dos.getTypeInfo().compareTo("text/xml") == 0) {
162
				dialog.setWMSInfoText(txt, "text/xml");
163
			}else
164
				dialog.setWMSInfoText(txt, "text/html");
165
				
166
		} catch (LoadLayerException e) {
167
			e.printStackTrace();
168
		} catch (DataException e) {
169
			e.printStackTrace();
170
		}
171
		model.notifyObservers();
172
	}
173
	
174
	/**
175
	 * Loads the values of a pixel point
176
	 * @param dataStore
177
	 * @param pxPoint
178
	 * @return
179
	 */
180
	private double[] getBandValues(RasterDataStore dataStore, Point2D pxPoint) {
181
		double[] res = new double[dataStore.getBandCount()];
182
		int pos = 0;
183
		try {
184
			if(dataStore.getDataType()[0] >= 0 && dataStore.getDataType()[0] <= 3) {
185
				for(int i = 0; i < dataStore.getBandCount(); i++) {
186
					int val = ((Integer)dataStore.getData((int)pxPoint.getX(), (int)pxPoint.getY(), i)).intValue();
187
					if(dataStore.getDataType()[0] == Buffer.TYPE_BYTE)
188
						res[pos] = (val & 0x000000ff);
189
					else
190
						res[pos] = val;
191
					pos ++;
192
				}
193
			}
194

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

  
216
	public void pointDoubleClick(PointEvent event) throws BehaviorException {
217
	}
218

  
219
	public boolean cancelDrawing() {
220
		return true;
221
	}
222

  
223
	public Image getImageCursor() {
224
		return IconThemeHelper.getImage("zoom-pixel-cursor");
225
	}
226
}
0 227

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/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.8/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.8/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 (int i = 0; i < layers.getLayersCount(); i++)
117
				if (layers.getLayer(i) instanceof FLyrWMS) {
118
					FLyrRaster lyr = (FLyrRaster)layers.getLayer(i);
119
					if(lyr.isActive())
120
						return true;
121
				}
122
		}
123
		return false;
124
	}
125
	
126
	public boolean isVisible() {
127
		return isEnabled();
128
	}
129

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

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/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
		}
265
	}
266
	
267
	/**
268
	 * Removes a label from the text
269
	 * @param text
270
	 * @param label
271
	 * @return
272
	 */
273
	private String removeLabelBlock(String text, String label) {
274
		if(text.contains("<" + label) && text.contains("/" + label + ">")) {
275
			int initIndex = text.indexOf("<" + label);
276
			int endIndex = text.indexOf("/" + label + ">");
277
			return text.substring(0, initIndex) + text.substring(endIndex + 7, text.length());
278
		}
279
		return text;
280
	}
281
	
282
	public WindowInfo getWindowInfo() {
283
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE);
284
		m_viewinfo.setTitle(PluginServices.getText(this, "WMS InfoByPoint"));
285
		m_viewinfo.setHeight(380);
286
		m_viewinfo.setWidth(700);
287
		return m_viewinfo;
288
	}
289
	
290
	public void windowClosed() {
291
		CompoundBehavior.setAllControlsBehavior(InfoByWMSPointExtension.oldBehavior);
292
	}
293
	
294
	public Object getWindowProfile() {
295
		return WindowInfo.PROPERTIES_PROFILE;
296
	}
297

  
298
	public InfoByPointDataModel getInfoByPointDataModel() {
299
		return getMainPanel().getInfoByPointDataModel();
300
	}
301
	
302
	public PixelInspector getPixelInspector() {
303
		return getMainPanel().getPixelInspectorPanel();
304
	}
305

  
306
	public void hyperlinkUpdate(HyperlinkEvent e) {
307
		if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
308
			new BrowserControl().displayURL(e.getURL().toString());
309
		}
310
	}
311
}
0 312

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.8/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.8/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;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff