Revision: 4663
http://sourceforge.net/p/jump-pilot/code/4663
Author: bertazza
Date: 2015-12-23 16:26:41 +0000 (Wed, 23 Dec 2015)
Log Message:
-----------
Info feature tool: added a pane to show WMS info.
Modified Paths:
--------------
core/trunk/ChangeLog
core/trunk/src/com/vividsolutions/jump/workbench/ui/InfoFrame.java
core/trunk/src/com/vividsolutions/jump/workbench/ui/PrimaryInfoFrame.java
core/trunk/src/com/vividsolutions/jump/workbench/ui/TaskFrame.java
core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/FeatureInfoTool.java
core/trunk/src/com/vividsolutions/wms/AbstractParser.java
core/trunk/src/com/vividsolutions/wms/Capabilities.java
core/trunk/src/com/vividsolutions/wms/MapLayer.java
core/trunk/src/com/vividsolutions/wms/ParserWMS1_0.java
core/trunk/src/com/vividsolutions/wms/ParserWMS1_1.java
core/trunk/src/com/vividsolutions/wms/ParserWMS1_3.java
core/trunk/src/com/vividsolutions/wms/WMService.java
core/trunk/src/org/openjump/core/ui/plugin/queries/QueryDialog.java
Added Paths:
-----------
core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/clean.xsl
core/trunk/src/com/vividsolutions/wms/MapStyle.java
Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog 2015-12-23 15:39:50 UTC (rev 4662)
+++ core/trunk/ChangeLog 2015-12-23 16:26:41 UTC (rev 4663)
@@ -3,6 +3,8 @@
# 2. make sure that lines break at 80 chars for constricted display situations
#<-------------------------------- 80 chars
---------------------------------->#
+2015-12-23 bertazza
+ * Info feature tool: added a pane to show WMS info.
<----------------------------------------------- Changes.txt updated 'til here
2015-12-21 bertazza
Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/InfoFrame.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/InfoFrame.java
2015-12-23 15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/InfoFrame.java
2015-12-23 16:26:41 UTC (rev 4663)
@@ -61,6 +61,8 @@
import com.vividsolutions.jump.workbench.ui.images.IconLoader;
import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
import com.vividsolutions.jump.workbench.ui.plugin.ViewAttributesPlugIn;
+import java.io.IOException;
+import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
@@ -99,16 +101,18 @@
private GeometryInfoTab geometryInfoTab;
private JTabbedPane tabbedPane = new JTabbedPane();
private RasterInfoTab rasterInfoTab;
+ private WMSInfoTab wmsInfoTab;
private WorkbenchFrame workbenchFrame;
private static ImageIcon ICON = IconLoader.icon("information_16x16.png");
public InfoFrame(
WorkbenchContext workbenchContext,
LayerManagerProxy layerManagerProxy,
- final TaskFrame taskFrame) {
+ final TaskFrame taskFrame) throws IOException {
blackboard = PersistentBlackboardPlugIn.get(workbenchContext);
geometryInfoTab = new GeometryInfoTab(model, workbenchContext);
rasterInfoTab = new RasterInfoTab(null, null);
+ wmsInfoTab = new WMSInfoTab();
//Keep my own copy of LayerManager, because it will be nulled in
TaskFrame
//when TaskFrame closes (it may in fact already be closed, which is why
//a LayerManagerProxy must be passed in too). But I have to
@@ -150,6 +154,7 @@
tabbedPane.addTab("", IconLoader.icon("Table.gif"), attributeTab,
TABLE_VIEW);
tabbedPane.addTab("", IconLoader.icon("Paper.gif"), geometryInfoTab,
HTML_VIEW);
tabbedPane.addTab("R", null, rasterInfoTab, "Raster");
+ tabbedPane.addTab("WMS", null, wmsInfoTab, "WMS");
updateTitle(taskFrame.getTask().getName());
taskFrame.getTask().add(new Task.NameListener() {
public void taskNameChanged(String name) {
@@ -274,6 +279,10 @@
rasterInfoTab.setRasterValues(layerNames, cellValues);
}
+ public void setWmsInfo(String string) {
+ wmsInfoTab.setWmsInfoText(string);
+ }
+
@Override
public JFrame getFrame() {
// our frame has to be all proxies InfoFrame is
@@ -361,5 +370,32 @@
}
}
+
+ protected class WMSInfoTab extends JPanel {
+
+ private final JEditorPane jEditorPane;
+
+ public WMSInfoTab() throws IOException {
+
+ setLayout(new BorderLayout());
+
+ jEditorPane = new JEditorPane();
+ jEditorPane.setEditable(false);
+ JScrollPane jScrollPane = new JScrollPane(
+ jEditorPane,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+ this.add(jScrollPane);
+
+ }
+
+ public void setWmsInfoText(String wmsInfo) {
+
+ jEditorPane.setText(wmsInfo);
+
+ }
+
+ }
}
Modified:
core/trunk/src/com/vividsolutions/jump/workbench/ui/PrimaryInfoFrame.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/PrimaryInfoFrame.java
2015-12-23 15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/PrimaryInfoFrame.java
2015-12-23 16:26:41 UTC (rev 4663)
@@ -34,6 +34,7 @@
import com.vividsolutions.jump.workbench.WorkbenchContext;
import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
+import java.io.IOException;
/**
@@ -44,7 +45,7 @@
* positions InfoFrames differently depending on whether or not they are
primary.
*/
public class PrimaryInfoFrame extends InfoFrame {
- public PrimaryInfoFrame(WorkbenchContext workbenchContext,
LayerManagerProxy layerManagerProxy, TaskFrame taskFrame) {
+ public PrimaryInfoFrame(WorkbenchContext workbenchContext,
LayerManagerProxy layerManagerProxy, TaskFrame taskFrame) throws IOException {
super(workbenchContext, layerManagerProxy, taskFrame);
}
}
Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/TaskFrame.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/TaskFrame.java
2015-12-23 15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/TaskFrame.java
2015-12-23 16:26:41 UTC (rev 4663)
@@ -53,6 +53,7 @@
import com.vividsolutions.jump.workbench.ui.renderer.Renderer;
import com.vividsolutions.jump.workbench.ui.zoom.ZoomBar;
+import java.io.IOException;
public class TaskFrame extends JInternalFrame implements TaskFrameProxy,
CloneableInternalFrame, LayerViewPanelProxy, LayerNamePanelProxy,
@@ -223,7 +224,7 @@
return task.getLayerManager();
}
- public InfoFrame getInfoFrame() {
+ public InfoFrame getInfoFrame() throws IOException {
if (infoFrame == null || infoFrame.isClosed()) {
infoFrame = new PrimaryInfoFrame(workbenchContext, this, this);
}
Modified:
core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/FeatureInfoTool.java
===================================================================
---
core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/FeatureInfoTool.java
2015-12-23 15:39:50 UTC (rev 4662)
+++
core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/FeatureInfoTool.java
2015-12-23 16:26:41 UTC (rev 4663)
@@ -34,6 +34,7 @@
package com.vividsolutions.jump.workbench.ui.cursortool;
import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Envelope;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Image;
@@ -49,9 +50,27 @@
import com.vividsolutions.jump.workbench.model.FenceLayerFinder;
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.model.Layerable;
+import com.vividsolutions.jump.workbench.model.WMSLayer;
import com.vividsolutions.jump.workbench.ui.InfoFrame;
import com.vividsolutions.jump.workbench.ui.images.IconLoader;
+import com.vividsolutions.wms.WMService;
+import java.awt.geom.Point2D;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
import java.util.List;
+import javax.swing.JDialog;
+import javax.swing.JEditorPane;
+import javax.swing.JScrollPane;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import org.apache.commons.io.IOUtils;
import org.openjump.core.rasterimage.RasterImageLayer;
import
org.openjump.core.rasterimage.RasterImageLayer.RasterDataNotFoundException;
@@ -90,8 +109,79 @@
infoFrame.getModel().add(layer, features);
}
+ Coordinate coord =
getPanel().getViewport().toModelCoordinate(getViewSource());
+
+ // WMS
+ List<Layerable> wmsLay_l =
getWorkbench().getContext().getLayerManager().getLayerables(WMSLayer.class);
+ String response = "";
+ for(Layerable lay : wmsLay_l) {
+ WMSLayer wmsLayer = (WMSLayer) lay;
+
+ String featInfoUrl =
wmsLayer.getService().getCapabilities().getFeatureInfoURL();
+ String names = getWmsLayeNames(wmsLayer);
+
+ Point2D point = getPanel().getViewport().toViewPoint(coord);
+ Envelope bbox =
getPanel().getViewport().getEnvelopeInModelCoordinates();
+
+ if (featInfoUrl.contains("?")) {
+ featInfoUrl += "&";
+ } else {
+ featInfoUrl += "?";
+ }
+ String version = wmsLayer.getWmsVersion();
+ if (WMService.WMS_1_0_0.equals(version)) {
+ featInfoUrl += "REQUEST=feature_info&WMTVER=1.0.0";
+ } else if (WMService.WMS_1_1_0.equals(version) ||
+ WMService.WMS_1_1_1.equals(version) ||
+ WMService.WMS_1_3_0.equals(version)) {
+ featInfoUrl += "REQUEST=GetFeatureInfo&SERVICE=WMS&VERSION=" +
version;
+ }
+
+ featInfoUrl += "&QUERY_LAYERS=" + names + "&LAYERS=" + names;
+ if (WMService.WMS_1_3_0.equals(version)) {
+ featInfoUrl += "&CRS=" + wmsLayer.getSRS() +
+ "&I=" + (int) point.getX() +
+ "&J=" + (int) point.getY();
+ } else {
+ featInfoUrl += "&SRS=" + wmsLayer.getSRS() +
+ "&X=" + (int) point.getX() +
+ "&Y=" + (int) point.getY();
+ }
+
+ featInfoUrl += "&WIDTH=" + getPanel().getWidth() +
+ "&HEIGHT=" + getPanel().getHeight() +
+ "&BBOX=" + bbox.getMinX() + "," + bbox.getMinY() + "," +
bbox.getMaxX() + "," + bbox.getMaxY() +
+ "&STYLES=" +
+ "&FORMAT=" + wmsLayer.getFormat();
+
+ if (!WMService.WMS_1_0_0.equals(version)) {
+ try {
+ featInfoUrl += "&INFO_FORMAT=" +
wmsLayer.getService().getCapabilities().getInfoFormat();
+ } catch (IOException e) {
+ featInfoUrl += "&INFO_FORMAT=text/plain";
+ }
+ }
+
+ URL url = stripXhtmlTags(featInfoUrl);
+
+ String newLine = System.getProperty("line.separator");
+ response = response.concat("+
").concat(wmsLayer.getName()).concat(newLine);
+
+ String wmsResponse;
+ try {
+ wmsResponse = IOUtils.toString(url.openStream());
+ wmsResponse = cleanWmsResponse(wmsResponse);
+ } catch(Exception ex) {
+ wmsResponse = ex.toString();
+ wmsResponse = wmsResponse.concat(newLine);
+ }
+ response = response.concat(wmsResponse);
+ response = response.concat(newLine);
+
+ };
+ infoFrame.setWmsInfo(response);
+
// Raster data
- Coordinate coord =
getPanel().getViewport().toModelCoordinate(getViewSource());
List<Layerable> layerables_l =
getWorkbench().getContext().getLayerManager().getLayerables(RasterImageLayer.class);
String[] layerNames = new String[layerables_l.size()];
@@ -122,15 +212,78 @@
} catch(RasterDataNotFoundException ex) {
cellValues[l] = "???";
}
-
-
-
}
}
}
- infoFrame.setRasterValues(layerNames, cellValues);
-
+ infoFrame.setRasterValues(layerNames, cellValues);
infoFrame.surface();
}
+
+ private String getWmsLayeNames(WMSLayer selLayer) {
+ int i;
+ String names = "";
+ List<String> layerNames = selLayer.getLayerNames();
+ for (i=0; i< layerNames.size(); ++i) {
+ String name = (String) layerNames.get(i);
+ try {
+ name = URLEncoder.encode(name, "UTF-8");
+ } catch (Exception ignored) {
+ }
+ names += name;
+ if (i < layerNames.size() - 1) {
+ names += ",";
+ }
+ }
+
+ return names;
+ }
+
+ private URL stripXhtmlTags(String serverURL) throws Exception {
+
+ File tmpFile = File.createTempFile("wms", "q");
+ FileOutputStream cleanHtml = new FileOutputStream(tmpFile);
+ boolean resOk = true;
+ //String xsl =
(String)getClass().getResource("clean.xsl").getContent();
+ //System.out.println("Ecco l'xsl: "+xsl);
+ Transformer pulizia = TransformerFactory.newInstance().newTransformer(
+ new StreamSource(getClass().getResourceAsStream("clean.xsl")));
+ try {
+ pulizia.transform(new StreamSource(serverURL),
+ new StreamResult(cleanHtml));
+ } catch (Exception te) {
+ //System.out.println("XSLT Error: "+te.getMessage());
+ resOk = false;
+ } finally {
+ cleanHtml.close();
+ }
+ // [DR] gestione file vuoti
+ if (!resOk || !(new FileReader(tmpFile).ready())) {
+ /*
+ FileWriter noResponse = new FileWriter(tmpFile);
+ noResponse.write("<html><body><h2>Risultati interrogazione</h2>"+
+ "Il server non ha restituito alcun risultato.</body></html>");
+ noResponse.close();
+ */
+ //gestione risposte non html (testuali)
+ return new URL(serverURL);
+ }
+ return tmpFile.toURI().toURL();
+ }
+
+ private String cleanWmsResponse(String inputWms) {
+
+ String pattern = "GetFeatureInfo results:";
+ int index = inputWms.indexOf(pattern);
+ if(index != -1) {
+ int endIndex = index + pattern.length();
+ inputWms = inputWms.substring(endIndex);
+ if(inputWms.startsWith("\n\n")) {
+ inputWms = inputWms.replaceFirst("\n\n", "");
+ }
+ }
+
+ return inputWms;
+ }
+
}
Added: core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/clean.xsl
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/clean.xsl
(rev 0)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/cursortool/clean.xsl
2015-12-23 16:26:41 UTC (rev 4663)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ version="1.0">
+
+ <xsl:output method="html" version="3.2" />
+
+ <xsl:strip-space elements="*" />
+
+ <xsl:template match="/">
+ <xsl:if test="not(html)">
+ <html>
+ <head>
+ </head>
+ <body>
+ <xsl:apply-templates />
+ </body>
+ </html>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="*">
+ <xsl:choose>
+ <xsl:when test="local-name()='img'" />
+ <xsl:otherwise>
+ <xsl:element name="{local-name()}">
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:element>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="@*">
+ <xsl:attribute name="{local-name()}">
+ <xsl:value-of select="."/>
+ </xsl:attribute>
+ </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file
Modified: core/trunk/src/com/vividsolutions/wms/AbstractParser.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/AbstractParser.java 2015-12-23
15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/AbstractParser.java 2015-12-23
16:26:41 UTC (rev 4663)
@@ -39,7 +39,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -48,7 +47,6 @@
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -155,9 +153,31 @@
}
}
}
+
return formatList;
}
+ protected LinkedList<String> getInfoFormats(Document doc) {
+
+ // get the supported infoFormats
+ final Node formatNode = XMLTools.simpleXPath(doc, getRootPath() +
"/Capability/Request/GetMap");
+ NodeList nl = formatNode.getChildNodes();
+
+ final Node infoFormatNode = XMLTools.simpleXPath(doc,
"WMT_MS_Capabilities/Capability/Request/GetFeatureInfo");
+ LinkedList<String> infoFormatList = new LinkedList<String>();
+ if (infoFormatNode != null) {
+ nl = infoFormatNode.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node n = nl.item(i);
+ if (n.getNodeType() == Node.ELEMENT_NODE &&
"Format".equals(n.getNodeName())) {
+ infoFormatList.add(n.getFirstChild().getNodeValue());
+ }
+ }
+ }
+
+ return infoFormatList;
+
+ }
/**
* Traverses the DOM tree underneath the specified Node and generates
@@ -174,6 +194,7 @@
LinkedList<MapLayer> subLayers = new LinkedList<MapLayer>();
BoundingBox geographicBBox = null;
ArrayList<BoundingBox> boundingBoxList = new ArrayList<BoundingBox> (
);
+ List<MapStyle> styles = new ArrayList<MapStyle>();
NodeList nl = layerNode.getChildNodes();
@@ -199,6 +220,44 @@
boundingBoxList.add ( new BoundingBox("Geographics",
geographicBBox.getEnvelope()) );
} else if( n.getNodeName().equals( "Layer" ) ) {
subLayers.add( wmsLayerFromNode( n ) );
+ } else if (n.getNodeName().equals("Style")) { //$NON-NLS-1$
+ String styleName = ""; //$NON-NLS-1$
+ String titleName = ""; //$NON-NLS-1$
+ String legendFormat = ""; //$NON-NLS-1$
+ String url = ""; //$NON-NLS-1$
+ int h=0,w=0;
+ NodeList nodeStyle = n.getChildNodes();
+ for( int k = 0; k < nodeStyle.getLength(); k++ ) {
+ Node n1 = nodeStyle.item(k);
+ if (n1.getNodeName().equals("Name")) {
//$NON-NLS-1$
+ styleName = ((CharacterData)
n1.getFirstChild()).getData();
+ } else if (n1.getNodeName().equals("Title") &
n1.hasChildNodes()) { //$NON-NLS-1$
+ titleName = ((CharacterData)
n1.getFirstChild()).getData();
+ } else if (n1.getNodeName().equals("LegendURL")) {
//$NON-NLS-1$
+ try {
+
h=Integer.parseInt(n1.getAttributes().getNamedItem("height").getNodeValue());
+
w=Integer.parseInt(n1.getAttributes().getNamedItem("width").getNodeValue());
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception(e.toString());
+ }
+ NodeList nodelegend = n1.getChildNodes();
+ for( int k1 = 0; k1 < nodelegend.getLength();
k1++ ) {
+ Node n2 = nodelegend.item(k1);
+ if (n2.getNodeName().equals("Format")) {
//$NON-NLS-1$
+ legendFormat =
+ ((CharacterData)
n2.getFirstChild()).getData();
+ } else if
(n2.getNodeName().equals("OnlineResource")) { //$NON-NLS-1$
+ url =
+ n2.getAttributes()
+
.getNamedItem("xlink:href").getNodeValue(); //$NON-NLS-1$
+ }
+ }
+
+ }
+ }
+ styles.add(new MapStyle(styleName, titleName, url,
legendFormat,w,h));
}
}
} catch( Exception e ) {
@@ -208,7 +267,7 @@
}
// call the new constructor with boundingBoxList in MapLayer [uwe
dalluege]
- return new MapLayer(name, title, srsList, subLayers, geographicBBox,
boundingBoxList);
+ return new MapLayer(name, title, srsList, subLayers, geographicBBox,
boundingBoxList, styles);
}
protected void addSRSNode(Node n, List<String> srsList) throws Exception {
Modified: core/trunk/src/com/vividsolutions/wms/Capabilities.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/Capabilities.java 2015-12-23
15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/Capabilities.java 2015-12-23
16:26:41 UTC (rev 4663)
@@ -51,8 +51,9 @@
private String title;
private ArrayList mapFormats;
private WMService service;
- private String getMapURL, getFeatureInfoURL;
-
+ private String getMapURL, featureInfoURL;
+ private ArrayList infoFormats;
+
/**
* Creates a new WMS Capabilities object. Should generally only be used by
the Parser.
* @param service the WMService to which these Capabilites belong
@@ -60,19 +61,22 @@
* @param topLayer the top MapLayer of the entire layer tree
* @param mapFormats the Collection of supported formats
*/
- public Capabilities(WMService service, String title, MapLayer topLayer,
Collection mapFormats) {
+ public Capabilities(WMService service, String title, MapLayer topLayer,
+ Collection mapFormats, Collection infoFormats) {
this.service = service;
this.title = title;
this.topLayer = topLayer;
this.mapFormats = new ArrayList( mapFormats );
+ this.infoFormats = new ArrayList(infoFormats);
this.getMapURL = service.getServerUrl();
- this.getFeatureInfoURL = service.getServerUrl();
+ this.featureInfoURL = service.getServerUrl();
}
- public Capabilities(WMService service, String title, MapLayer topLayer,
Collection mapFormats, String getMapURL, String getFeatureInfoURL) {
- this(service, title, topLayer, mapFormats);
+ public Capabilities(WMService service, String title, MapLayer topLayer,
+ Collection mapFormats, Collection infoFormats, String getMapURL,
String featureInfoURL) {
+ this(service, title, topLayer, mapFormats, infoFormats);
this.getMapURL = getMapURL;
- this.getFeatureInfoURL = getFeatureInfoURL;
+ this.featureInfoURL = featureInfoURL;
}
/**
@@ -121,8 +125,8 @@
return getMapURL;
}
- public String getGetFeatureInfoURL() {
- return getFeatureInfoURL;
+ public String getFeatureInfoURL() {
+ return featureInfoURL;
}
public void setGetMapURL(String url) {
@@ -142,5 +146,16 @@
}
return formats;
}
+
+ public String getInfoFormat() {
+ String format = "text/plain";
+ if (!infoFormats.contains(format)) {
+ Iterator it = infoFormats.iterator();
+ if (it.hasNext()) {
+ format = (String) it.next();
+ }
+ }
+ return format;
+ }
}
Modified: core/trunk/src/com/vividsolutions/wms/MapLayer.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/MapLayer.java 2015-12-23 15:39:50 UTC
(rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/MapLayer.java 2015-12-23 16:26:41 UTC
(rev 4663)
@@ -63,10 +63,13 @@
// user modifiable members
private boolean enabled = false;
+ private List<MapStyle> styles;
+
/**
* Creates a new instance of MapLayer
*/
- public MapLayer(String name, String title, Collection srsList, Collection
subLayers, BoundingBox bbox) {
+ public MapLayer(String name, String title, Collection srsList,
+ Collection subLayers, BoundingBox bbox, List<MapStyle> styles) {
this.parent = null;
this.name = name;
this.title = title;
@@ -77,15 +80,17 @@
(it.next()).parent = this;
}
this.bbox = bbox;
+ setStyles(styles);
}
/**
* Creates a new instance of MapLayer with boundingBoxList [uwe dalluege]
*/
- public MapLayer ( String name, String title, Collection srsList,
Collection subLayers,
- BoundingBox bbox, ArrayList<BoundingBox> boundingBoxList ) {
- this ( name, title, srsList, subLayers, bbox );
- this.boundingBoxList = boundingBoxList;
+ public MapLayer
+ ( String name, String title, Collection srsList, Collection subLayers,
+ BoundingBox bbox, ArrayList boundingBoxList,List<MapStyle>
styles ) {
+ this ( name, title, srsList, subLayers, bbox,styles );
+ this.boundingBoxList = boundingBoxList;
}
@@ -297,8 +302,62 @@
if (parent != null) fullSRSList.addAll(parent.getFullSRSList());
return fullSRSList;
}
+
+ /**
+ * Sets the selected WMS layer style
+ *
+ * @param selectedStyle
+ */
+ public void setSelectedStyle( MapStyle selectedStyle ) {
+ for( Iterator<MapStyle> iter = styles.iterator(); iter.hasNext(); ) {
+ MapStyle element = iter.next();
+ element.setSelected(false, false);
+ }
+ selectedStyle.setSelected(true, false);
+ }
+
+ /**
+ * Gets the WMS layer style by name
+ *
+ * @param styleName
+ * @return
+ */
+ public MapStyle getStyle( String styleName ) {
+ for( Iterator<MapStyle> iter = styles.iterator(); iter.hasNext(); ) {
+ MapStyle element = iter.next();
+ if (element.getName().equals(styleName))
+ return element;
+ }
+ return null;
+ }
+
+ public List<MapStyle> getStyles() {
+ return styles;
+ }
+ /**
+ * @param sublayer
+ */
+ public void setSublayer(ArrayList sublayer) {
+ this.subLayers = sublayer;
+ }
+
/**
+ * @param newStyles
+ */
+ public void setStyles( List<MapStyle> newStyles ) {
+ this.styles = newStyles;
+ for( Iterator<MapStyle> iter = styles.iterator(); iter.hasNext(); ) {
+ MapStyle element = iter.next();
+ element.setLayer(this);
+ }
+
+ if (!styles.isEmpty()) {
+ styles.get(0).setSelected(true, true);
+ }
+ }
+
+ /**
* Returns a somewhat nicely-formatted string representing all of the
details of
* this layer and its sub-layers (recursively).
* @return a somewhat nicely-formatted string representing all of the
details of
Added: core/trunk/src/com/vividsolutions/wms/MapStyle.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/MapStyle.java
(rev 0)
+++ core/trunk/src/com/vividsolutions/wms/MapStyle.java 2015-12-23 16:26:41 UTC
(rev 4663)
@@ -0,0 +1,239 @@
+package com.vividsolutions.wms;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+
+import javax.imageio.ImageIO;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import org.apache.log4j.Logger;
+
+/*
+ * Estilo asociado a una capa. Se caracteriza por tener asociado un
+ * nombre, un estilo y una leyenda
+ * @author Marco Antonio Fuentelsaz P?rez
+ *
+ */
+public class MapStyle {
+
+ /** Log */
+ private final static Logger LOGGER = Logger.getLogger(MapStyle.class);
+
+ /** Nombre asociado al estilo */
+ private String name;
+
+ /** Titulo asociado al estilo */
+ private String title;
+
+ /** URL asociado a la leyenda */
+ private String urlLegend;
+
+ /** Formato asociado a la leyenda */
+ private String formatLegend;
+
+ /** */
+ private boolean selected;
+
+ /** Legend icon */
+ private Icon legendIcon;
+
+ /** */
+ private MapLayer layer;
+
+ /** Flag to indicate if the legend icon have been loaded or not */
+ private boolean loadedIcon;
+
+ private int width;
+ private int height;
+
+ /**
+ * @param name
+ * @param title
+ * @param urlLegend
+ * @param formatLegend
+ */
+ public MapStyle( String name, String title, String urlLegend, String
formatLegend ) {
+ this.name = name;
+ this.title = title;
+ setUrlLegend(urlLegend);
+ this.formatLegend = formatLegend;
+ this.selected = false;
+ }
+
+ public MapStyle( String name, String title, String urlLegend, String
formatLegend, int w, int h ) {
+ this.name = name;
+ this.title = title;
+ setUrlLegend(urlLegend);
+ this.formatLegend = formatLegend;
+ this.selected = false;
+ this.width = w;
+ this.height = h;
+ }
+
+ /**
+ * @return
+ */
+ public int getWidth() {
+ return width;
+ }
+ /**
+ * @return
+ */
+ public int getHeight() {
+ return height;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name
+ */
+ public void setName( String name ) {
+ this.name = name;
+ }
+
+ /**
+ * @return
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * @param title
+ */
+ public void setTitle( String title ) {
+ this.title = title;
+ }
+
+ /**
+ * @return
+ */
+ public String getUrlLegend() {
+ return urlLegend;
+ }
+
+ /**
+ * @param newURLLegend
+ */
+ public void setUrlLegend( String newURLLegend ) {
+ this.urlLegend = newURLLegend;
+ }
+
+ /**
+ * @return
+ */
+ public String getFormatLegend() {
+ return formatLegend;
+ }
+
+ /**
+ * @param formatLegend
+ */
+ public void setFormatLegend( String formatLegend ) {
+ this.formatLegend = formatLegend;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * Load the legend icon at first request, not before
+ *
+ * @return
+ */
+ public Icon getLegendIcon() {
+ if (!loadedIcon) {
+ loadIconFromLegendURL();
+ }
+ return legendIcon;
+ }
+
+ /**
+ * Loads the WMS style legend icon on request
+ */
+ private void loadIconFromLegendURL() {
+ URL selectedUrl = null;
+ try {
+ selectedUrl = new URL(urlLegend);
+ } catch (MalformedURLException e) {
+ LOGGER.error(e.getMessage());
+ }
+
+ if (selectedUrl != null) {
+ BufferedImage image;
+ try {
+ image = ImageIO.read(selectedUrl);
+ legendIcon = new ImageIcon(image);
+ loadedIcon = true;
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage());
+ }
+
+ } else {
+ loadedIcon = false;
+ }
+ }
+
+ /**
+ * @return
+ */
+ public boolean isSelected() {
+ return selected;
+ }
+
+ /**
+ * @param selected
+ * @param check
+ */
+ public void setSelected( boolean selected, boolean check ) {
+ if (check) {
+ if (this.selected && !selected && layer.getStyles().size() == 1)
+ return;
+ if (this.selected && !selected) {
+ for( Iterator<MapStyle> iter = layer.getStyles().iterator();
iter.hasNext(); ) {
+ MapStyle element = iter.next();
+ if (!element.equals(this))
+ element.setSelected(true, false);
+
+ }
+ }
+ }
+
+ this.selected = selected;
+ }
+
+ /**
+ *
+ */
+ public void fireStyleChanged() {
+ layer.setSelectedStyle(this);
+ }
+
+ @Override
+ public boolean equals( Object other ) {
+ if (other == this)
+ return true;
+ if (!(other instanceof MapStyle))
+ return false;
+ return getName().equals(((MapStyle) other).getName());
+ }
+
+ /**
+ * @param layer
+ */
+ public void setLayer( MapLayer layer ) {
+ this.layer = layer;
+ }
+}
Modified: core/trunk/src/com/vividsolutions/wms/ParserWMS1_0.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/ParserWMS1_0.java 2015-12-23
15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/ParserWMS1_0.java 2015-12-23
16:26:41 UTC (rev 4663)
@@ -78,11 +78,13 @@
}
+ @Override
protected Capabilities parseCapabilities(WMService service, Document doc)
throws IOException {
String title = getTitle(doc);
MapLayer topLayer = wmsLayerFromNode(XMLTools.simpleXPath(doc,
"WMT_MS_Capabilities/Capability/Layer"));
LinkedList<String> formatList = getFormatList(doc);
- return new Capabilities(service, title, topLayer, formatList);
+
+ return new Capabilities(service, title, topLayer, formatList,
getInfoFormats(doc));
}
@@ -90,4 +92,5 @@
return "SRS";
}
+
}
Modified: core/trunk/src/com/vividsolutions/wms/ParserWMS1_1.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/ParserWMS1_1.java 2015-12-23
15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/ParserWMS1_1.java 2015-12-23
16:26:41 UTC (rev 4663)
@@ -84,8 +84,8 @@
MapLayer topLayer = wmsLayerFromNode(XMLTools.simpleXPath(doc,
"WMT_MS_Capabilities/Capability/Layer"));
LinkedList<String> formatList = getFormatList(doc);
String getMapURL = getMapURL(doc);
- String getFeatureInfoURL = getFeatureInfoURL(doc);
- return new Capabilities(service, title, topLayer, formatList,
getMapURL, getFeatureInfoURL );
+ String featureInfoURL = getFeatureInfoURL(doc);
+ return new Capabilities(service, title, topLayer, formatList,
getInfoFormats(doc), getMapURL, featureInfoURL );
}
Modified: core/trunk/src/com/vividsolutions/wms/ParserWMS1_3.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/ParserWMS1_3.java 2015-12-23
15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/ParserWMS1_3.java 2015-12-23
16:26:41 UTC (rev 4663)
@@ -85,7 +85,7 @@
LinkedList<String> formatList = getFormatList(doc);
String getMapURL = getMapURL(doc);
String getFeatureInfoURL = getFeatureInfoURL(doc);
- return new Capabilities(service, title, topLayer, formatList,
getMapURL, getFeatureInfoURL );
+ return new Capabilities(service, title, topLayer, formatList,
getInfoFormats(doc), getMapURL, getFeatureInfoURL );
}
Modified: core/trunk/src/com/vividsolutions/wms/WMService.java
===================================================================
--- core/trunk/src/com/vividsolutions/wms/WMService.java 2015-12-23
15:39:50 UTC (rev 4662)
+++ core/trunk/src/com/vividsolutions/wms/WMService.java 2015-12-23
16:26:41 UTC (rev 4663)
@@ -215,16 +215,16 @@
* @return a MapRequest object which can be used to retrieve a map image
* from this service
*/
- public MapRequest createMapRequest() {
- // [UT] 04.02.2005 changed
- MapRequest mr = new MapRequest( this );
- mr.setVersion( this.wmsVersion );
- return mr;
- }
-
- public String getVersion(){
- return wmsVersion;
- }
+ public MapRequest createMapRequest() {
+ // [UT] 04.02.2005 changed
+ MapRequest mr = new MapRequest( this );
+ mr.setVersion( this.wmsVersion );
+ return mr;
+ }
+
+ public String getVersion(){
+ return wmsVersion;
+ }
//
// The WMService appends other parameters to the end of the URL
@@ -232,7 +232,7 @@
public static String legalize(String url) {
String fixedURL = url.trim();
- if (fixedURL.indexOf("?") == -1) {
+ if (!fixedURL.contains("?")) {
fixedURL = fixedURL + "?";
} else {
if (fixedURL.endsWith("?")) {
Modified: core/trunk/src/org/openjump/core/ui/plugin/queries/QueryDialog.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/queries/QueryDialog.java
2015-12-23 15:39:50 UTC (rev 4662)
+++ core/trunk/src/org/openjump/core/ui/plugin/queries/QueryDialog.java
2015-12-23 16:26:41 UTC (rev 4663)
@@ -22,6 +22,8 @@
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -901,9 +903,13 @@
// initialization for infoframe
InfoFrame info = null;
if(display.getState()) {
- info = new InfoFrame(context.getWorkbenchContext(),
- (LayerManagerProxy)context,
-
(TaskFrame)context.getWorkbenchFrame().getActiveInternalFrame());
+ try {
+ info = new InfoFrame(context.getWorkbenchContext(),
+ (LayerManagerProxy)context,
+
(TaskFrame)context.getWorkbenchFrame().getActiveInternalFrame());
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
}
// Loop on the requested layers
------------------------------------------------------------------------------
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel