aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHallvard Traetteberg2012-04-19 18:08:24 (EDT)
committerHallvard Traetteberg2012-04-19 18:08:24 (EDT)
commit891010c774f84b0fe082e1a3f03d36df5d92ef4b (patch)
treefcf4338514324e0bdac57aae66320061458e4e97
parent3637783b355d5be3b3204e73e0b7970ad1e88cf3 (diff)
downloadorg.eclipse.nebula-891010c774f84b0fe082e1a3f03d36df5d92ef4b.zip
org.eclipse.nebula-891010c774f84b0fe082e1a3f03d36df5d92ef4b.tar.gz
org.eclipse.nebula-891010c774f84b0fe082e1a3f03d36df5d92ef4b.tar.bz2
Changes corresponding to attachment 214012
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/README.txt59
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/GeoMap.java22
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/AbstractPage.java4
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/PageContainer.java2
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/ResultsPage.java20
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/SearchPage.java58
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/TitleControl.java21
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/action.gifbin216 -> 0 bytes
-rw-r--r--widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/world.pngbin15230 -> 0 bytes
9 files changed, 95 insertions, 91 deletions
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/README.txt b/widgets/geomap/org.eclipse.nebula.widgets.geomap/README.txt
new file mode 100644
index 0000000..ebd38d3
--- /dev/null
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/README.txt
@@ -0,0 +1,59 @@
+SWT MapWidget
+=============
+
+
+
+Java based browsing of openstreetmap tiles (or the like). This is a EPL licensed SWT-Widget meant for reuse. A single file is enough to bring mapping to your Eclipse, swt, jface, RCP application. Sourcecode is provided as is and without warranty.
+Only requirement is SWT so you don't need the full eclipse rcp stack.
+
+- This project contains 2 things:
+
+1. MapWidget is the standalone SWT Control that can show a map from
+ any tile-server.
+2. MapBrowser is the example showcase for the MapWidget.
+
+Note that data is loaded from external servers
+ http://gazetteer.openstreetmap.org/,
+ http://tile.openstreetmap.org/ and
+ http://tah.openstreetmap.org.
+
+The MapWidget is just a very simple Java Viewer for the data provided by the above servers.
+Please check and comply to their usage-policies. Their data originates again from openstreetmap.org,
+which is a free source of data. However using the above tile-servers is subject to their
+usage policies. You can set up your own tileserver by following the instructions on
+openstreetmap.org.
+
+You can trivally supply your own TileServer by creating an instance of the class
+MapWidget.TileServer. If you have a local-dataset (eg for offline access) you can return
+local file Urls from your tileserver. You can also change the rather simple code to allow
+for some other more direct look-up, if going through an URL seems inappropriate for your
+particular scenario.
+
+If you see error messages saying that tileservers cannot be reached this can be caused by either
+a complete lack of an internet connection (in which case you are out of luck) or by a restricted
+connection where you are forced to use a http(s) proxy-server.
+The later is often the case in companies which do not allow unrestricted access to the internet.
+In this case you need to set the system properties httpProxy.host and maybe also httpProxy.port
+via -D command line options. For https these properties are named https.proxyHost and https.proxyPort.
+You can also set these properties programmatically from java. An excellent in depth explanation can
+be found at http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html.
+
+
+
+- Developer info
+
+The entire viewer runs using standard jdk version 1.6 or newer. Sourcecode can be found below. Only dependency is SWT.
+
+ Sourceforge project page: http://sourceforge.net/projects/mappanel/
+
+
+
+- Epilog
+
+Acknowledgments for feedback, testing, fixing, suggestions go to:
+ Everyone at openstreetmap.org, Ricky Clarkson, Werner de Bruijn.
+
+
+
+Contact author: stepan.rutz AT gmx.de . Feedback etc is more than welcome.
+
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/GeoMap.java b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/GeoMap.java
index dfcfdb6..c72b452 100644
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/GeoMap.java
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/GeoMap.java
@@ -10,16 +10,14 @@
*******************************************************************************/
package org.eclipse.nebula.widgets.geomap;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.InputStream;
import java.net.URL;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
@@ -32,7 +30,6 @@ import java.util.logging.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
-import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseEvent;
@@ -48,13 +45,9 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-
/**
* MapPanel display tiles from openstreetmap as is. This simple minimal viewer supports zoom around mouse-click center and has a simple api.
@@ -96,17 +89,6 @@ import org.eclipse.swt.widgets.Shell;
*/
public class GeoMap extends Canvas {
- /*
- wait icon
- credits to: RaminusFalcon
- obtained from: http://commons.wikimedia.org/wiki/File:GreenHourglass_up.svg
-
- world icon
- credits to: Zeus
- http://commons.wikimedia.org/wiki/File:Gartoon-fs-ftp.png
- */
-
-
private static final Logger log = Logger.getLogger(GeoMap.class.getName());
public static final class TileServer {
@@ -389,7 +371,7 @@ public class GeoMap extends Canvas {
"\r\n" +
"Web/Source: <a href=\"http://mappanel.sourceforge.net\">http://mappanel.sourceforge.net</a>\r\n" +
"Written by stepan.rutz. Contact <a href=\"mailto:stepan.rutz@gmx.de?subject=SWT%20MapWidget\">stepan.rutz@gmx.de</a>\r\n\r\n" +
- "Tileserver and Namefinder are part of Openstreetmap.org or associated projects.\r\n";
+ "Tileserver and Nominationserver are accessed online and are part of Openstreetmap.org and not of this software.\r\n";
//"MapPanel gets all its data the openstreetmap servers.\r\n\r\n" +
//"Please support the effort at <a href=\"http://www.openstreetmap.org\">http://www.openstreetmap.org/</a>.\r\n";
//"Please keep in mind this application is just a alternative renderer for swt.\r\n";
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/AbstractPage.java b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/AbstractPage.java
index a6ecfcd..d611b92 100644
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/AbstractPage.java
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/AbstractPage.java
@@ -43,8 +43,6 @@ public abstract class AbstractPage implements Page {
private PageContainer container;
private Composite composite;
- private Image actionImage;
-
protected PageContainer getContainer() {
return container;
@@ -63,7 +61,6 @@ public abstract class AbstractPage implements Page {
AbstractPage.this.widgetDisposed(e);
}
});
- actionImage = new Image(composite.getDisplay(), getClass().getResourceAsStream("resources/action.gif"));
composite.setLayout(new GridLayout(2, false));
container.adapt(composite);
@@ -114,7 +111,6 @@ public abstract class AbstractPage implements Page {
Label titleImage = new Label(wrap, SWT.WRAP);
container.adapt(titleImage);
- titleImage.setImage(actionImage);
Link link = new Link(wrap, SWT.NONE);
container.adapt(link);
link.setText(text);
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/PageContainer.java b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/PageContainer.java
index e98003e..d58191e 100644
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/PageContainer.java
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/PageContainer.java
@@ -53,7 +53,7 @@ public class PageContainer extends Composite {
stackLayout = new StackLayout();
- TitleControl title = new TitleControl(this);
+ TitleControl title = new TitleControl(this, null);
adapt(title);
title.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
title.setText("SWT MapWidget");
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/ResultsPage.java b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/ResultsPage.java
index cc6f6b0..066c646 100644
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/ResultsPage.java
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/ResultsPage.java
@@ -76,11 +76,10 @@ public class ResultsPage extends AbstractPage implements Page {
String shortName = result.getName();
shortName = shortName.replaceAll("\\s(.*)$", "");
- String linkBody = shortName + " [" + result.getCategory() + "]";
+ String linkBody = shortName;
+ if (result.getType() != null && result.getType().length() > 0)
+ linkBody += " [" + result.getType() + "]";
- String description = result.getDescription();
- description = description.replaceAll("\\[.*?\\]", "");
-
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, linkBody);
}
@@ -122,10 +121,13 @@ public class ResultsPage extends AbstractPage implements Page {
int index = table.indexOf(item);
if (index >= 0 && index < results.length) {
SearchResult result = results[index];
- String description = result.getDescription();
- description = description.replaceAll("\\[.*?\\]", "");
- description = description.replaceAll("<.*?>", "");
- descriptionText.setText(description);
+ String name = result.getName();
+ name = name.replaceAll("\\[.*?\\]", "");
+ name = name.replaceAll("<.*?>", "");
+ if (result.getCategory() != null)
+ name += " " + result.getCategory();
+ descriptionText.setText(name);
+
descriptionText.getParent().layout();
}
}
@@ -141,7 +143,7 @@ public class ResultsPage extends AbstractPage implements Page {
if (index >= 0 && index < results.length) {
SearchResult result = results[index];
GeoMap mapWidget = mapBrowser.getMapWidget();
- mapWidget.setZoom(result.getZoom() < 1 || result.getZoom() > mapWidget.getTileServer().getMaxZoom() ? 8 : result.getZoom());
+// mapWidget.setZoom(result.getZoom() < 1 || result.getZoom() > mapWidget.getTileServer().getMaxZoom() ? 8 : result.getZoom());
Point position = mapWidget.computePosition(new PointD(result.getLon(), result.getLat()));
mapWidget.setCenterPosition(position);
mapWidget.redraw();
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/SearchPage.java b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/SearchPage.java
index 71cbd3e..7665408 100644
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/SearchPage.java
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/SearchPage.java
@@ -39,7 +39,7 @@ import org.xml.sax.helpers.DefaultHandler;
/**
- * A {link {@link Page} that allows searching use the OSM namefinder facility.
+ * A {link {@link Page} that allows searching use the OSM Nominatim tool.
* The OSM namefinder has its own usage policies. Please check them out before
* you use it.
*
@@ -56,8 +56,6 @@ public class SearchPage extends AbstractPage implements Page {
private String name;
private String category;
private String info;
- private int zoom;
- private String description = "";
public SearchResult() {
}
@@ -97,23 +95,11 @@ public class SearchPage extends AbstractPage implements Page {
public void setInfo(String info) {
this.info = info;
}
- public int getZoom() {
- return zoom;
- }
- public void setZoom(int zoom) {
- this.zoom = zoom;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
+
public String toString() {
return "SearchResult [category=" + category + ", info=" + info + ", lat=" + lat + ", lon=" + lon
- + ", name=" + name + ", type=" + type + ", zoom=" + zoom + ", description=" + description + "]";
+ + ", name=" + name + ", type=" + type + "]";
}
-
}
private final GeoMapBrowser mapBrowser;
@@ -249,51 +235,28 @@ public class SearchPage extends AbstractPage implements Page {
private void doSearchInternal(final String newSearch) {
results.clear();
try {
- String args = URLEncoder.encode(newSearch, "UTF-8");
+ String args = URLEncoder.encode(newSearch.trim(), "UTF-8");
String path = GeoMap.NAMEFINDER_URL + "?format=xml&q=" + args;
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.newSAXParser().parse(path, new DefaultHandler() {
- private final ArrayList<String> pathStack = new ArrayList<String>();
-// private final ArrayList<SearchResult> namedStack = new ArrayList<SearchResult>();
private StringBuilder chars;
public void startElement(String uri, String localName, String qName, Attributes attributes) {
- pathStack.add(qName);
- String path = getPath();
- if ("place".equals(qName)) {
+ if ("place".equals(qName)) {
SearchResult result = new SearchResult();
result.setType(attributes.getValue("type"));
result.setLat(tryDouble(attributes.getValue("lat")));
result.setLon(tryDouble(attributes.getValue("lon")));
result.setName(attributes.getValue("display_name"));
- result.setCategory(attributes.getValue("category"));
- result.setInfo(attributes.getValue("info"));
- result.setZoom(tryInteger(attributes.getValue("zoom")));
-// namedStack.add(result);
- if (pathStack.size() == 2)
- results.add(result);
-// } else if ("description".equals(qName)) {
-// chars = new StringBuilder();
+ results.add(result);
}
}
public void endElement(String uri, String localName, String qName) throws SAXException {
-// if ("place".equals(qName)) {
-// pathStack.remove(pathStack.size() - 1);
-// } else if ("description".equals(qName)) {
-// namedStack.get(namedStack.size() - 1).setDescription(chars.toString());
-// }
- pathStack.remove(pathStack.size() - 1);
}
public void characters(char[] ch, int start, int length) throws SAXException {
- if(chars != null)
+ if (chars != null)
chars.append(ch, start, length);
}
- private String getPath() {
- StringBuilder sb = new StringBuilder();
- for (String p : pathStack)
- sb.append("/").append(p);
- return sb.toString();
- }
private double tryDouble(String s) {
try {
return Double.valueOf(s);
@@ -301,13 +264,6 @@ public class SearchPage extends AbstractPage implements Page {
return 0d;
}
}
- private int tryInteger(String s) {
- try {
- return Integer.valueOf(s);
- } catch (Exception e) {
- return 0;
- }
- }
});
} catch (Exception e) {
log.log(Level.SEVERE, "failed to search for \"" + newSearch + "\"", e);
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/TitleControl.java b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/TitleControl.java
index 27927f9..286cb85 100644
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/TitleControl.java
+++ b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/TitleControl.java
@@ -43,7 +43,7 @@ public class TitleControl extends Canvas {
private String text = "";
private Point size = new Point(1, 1);
- public TitleControl(Composite parent) {
+ public TitleControl(Composite parent, Image image) {
super(parent, SWT.DOUBLE_BUFFERED);
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
@@ -61,7 +61,8 @@ public class TitleControl extends Canvas {
gradient2Color = new Color(getDisplay(), 205, 224, 244);
bottomLineColor = new Color(getDisplay(), 200, 195, 216);
writingColor = new Color(getDisplay(), 60, 60, 60);
- image = new Image(getDisplay(), getClass().getResourceAsStream("resources/world.png"));
+ this.image = image;
+
measureSize("M");
}
@@ -70,7 +71,11 @@ public class TitleControl extends Canvas {
try {
gc.setFont(font);
size = gc.stringExtent(s);
- size.y = Math.max(image.getBounds().height + 1, size.y);
+ if (image != null) {
+ size.y = Math.max(image.getBounds().height + 1, size.y);
+ } else {
+ size.y += 16;
+ }
size.y += TOP_SPACE;
} finally {
gc.dispose();
@@ -83,7 +88,8 @@ public class TitleControl extends Canvas {
gradient2Color.dispose();
bottomLineColor.dispose();
writingColor.dispose();
- image.dispose();
+ if (image != null)
+ image.dispose();
}
private void onPaint(PaintEvent e) {
@@ -97,8 +103,11 @@ public class TitleControl extends Canvas {
gc.fillGradientRectangle(0, 0, w, h - 1, true);
- Rectangle imgsize = image.getBounds();
- gc.drawImage(image, 12, 0);
+ Rectangle imgsize = new Rectangle(0, 0, 0, 0);
+ if (image != null) {
+ imgsize = image.getBounds();
+ gc.drawImage(image, 12, 0);
+ }
gc.setForeground(bottomLineColor);
gc.drawLine(0, h - 1, w, h - 1);
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/action.gif b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/action.gif
deleted file mode 100644
index e3a7cc7..0000000
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/action.gif
+++ /dev/null
Binary files differ
diff --git a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/world.png b/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/world.png
deleted file mode 100644
index 269e7ef..0000000
--- a/widgets/geomap/org.eclipse.nebula.widgets.geomap/src/org/eclipse/nebula/widgets/geomap/internal/resources/world.png
+++ /dev/null
Binary files differ