Changeset 34477 in osm
- Timestamp:
- 2018-08-15T13:48:45+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/routes
- Files:
-
- 9 added
- 7 deleted
- 13 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routes
- Property svn:ignore
-
old new 1 1 build 2 3 2 bin 3 javadoc
-
- Property svn:ignore
-
applications/editors/josm/plugins/routes/.classpath
r32680 r34477 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="src" path="resources"/> 4 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 5 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> -
applications/editors/josm/plugins/routes/.project
r32286 r34477 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/routes/build.xml
r34038 r34477 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <project name="routes" default="dist" basedir="."> 3 <!-- enter the SVN commit message --> 3 4 <property name="commit.message" value="Changed the constructor signature of the plugin main class"/> 4 <property name="plugin.main.version" value="13007"/> 5 <property name="josm" location="../../core/dist/josm-custom.jar"/> 6 <property name="plugin.dist.dir" value="../../dist"/> 7 <property name="plugin.build.dir" value="build"/> 8 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 9 <property name="ant.build.javac.target" value="1.8"/> 10 <target name="init"> 11 <mkdir dir="${plugin.build.dir}"/> 12 </target> 13 <target name="compile" depends="init"> 14 <echo message="creating ${plugin.jar}"/> 15 <javac srcdir="src" debug="true" destdir="${plugin.build.dir}" includeantruntime="false"> 16 <compilerarg value="-Xlint:deprecation"/> 17 <compilerarg value="-Xlint:unchecked"/> 18 <classpath> 19 <pathelement location="${josm}"/> 20 <fileset dir="lib"> 21 <include name="**/*.jar"/> 22 </fileset> 23 </classpath> 24 </javac> 25 <copy file="src/org/openstreetmap/josm/plugins/routes/xml/routes.xml" todir="${plugin.build.dir}/org/openstreetmap/josm/plugins/routes/xml"/> 26 <copy file="src/org/openstreetmap/josm/plugins/routes/xml/routes.xsd" todir="${plugin.build.dir}/org/openstreetmap/josm/plugins/routes/xml"/> 27 </target> 28 <target name="dist" depends="compile,revision"> 29 <copy todir="${plugin.build.dir}/data"> 30 <fileset dir="data"/> 31 </copy> 32 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifestencoding="UTF-8"> 33 <manifest> 34 <attribute name="Author" value="Jiri Klement"/> 35 <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.routes.RoutesPlugin"/> 36 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 37 <attribute name="Plugin-Description" value="Renders routes (bus, hiking trails, bicycle routes, ..). Route types must be defined in routes.xml file in plugin directory"/> 38 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> 39 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 40 </manifest> 41 </jar> 42 </target> 43 <target name="test"/> 44 <target name="checkstyle"/> 45 <target name="spotbugs"/> 46 <target name="javadoc"/> 47 <target name="revision"> 48 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 49 <env key="LANG" value="C"/> 50 <arg value="info"/> 51 <arg value="--xml"/> 52 <arg value="."/> 53 </exec> 54 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/> 55 <delete file="REVISION"/> 56 </target> 57 <target name="clean"> 58 <delete dir="${plugin.build.dir}"/> 59 <delete file="${plugin.jar}"/> 60 </target> 61 <target name="install" depends="dist"> 62 <property environment="env"/> 63 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 64 <and> 65 <os family="windows"/> 66 </and> 67 </condition> 68 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 69 </target> 70 <!-- 71 ************************** Publishing the plugin *********************************** 72 --> 73 <!-- 74 ** extracts the JOSM release for the JOSM version in ../core and saves it in the 75 ** property ${coreversion.info.entry.revision} 76 ** 77 --> 78 <target name="core-info"> 79 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 80 <env key="LANG" value="C"/> 81 <arg value="info"/> 82 <arg value="--xml"/> 83 <arg value="../../core"/> 84 </exec> 85 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/> 86 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 87 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> 88 <delete file="core.info.xml"/> 89 </target> 90 <!-- 91 ** commits the source tree for this plugin 92 --> 93 <target name="commit-current"> 94 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 95 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 96 <env key="LANG" value="C"/> 97 <arg value="commit"/> 98 <arg value="-m '${commit.message}'"/> 99 <arg value="."/> 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="14153"/> 7 8 <!-- Configure these properties (replace "..." accordingly). 9 See https://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins 10 --> 11 <property name="plugin.author" value="Jiri Klement"/> 12 <property name="plugin.class" value="org.openstreetmap.josm.plugins.routes.RoutesPlugin"/> 13 <property name="plugin.description" value="Renders routes (bus, hiking trails, bicycle routes, ..). Route types must be defined in routes.xml file in plugin directory"/> 14 <!--<property name="plugin.icon" value="..."/>--> 15 <!--<property name="plugin.link" value="..."/>--> 16 <!--<property name="plugin.early" value="..."/>--> 17 <property name="plugin.requires" value="jaxb"/> 18 <!--<property name="plugin.stage" value="..."/>--> 19 20 <!-- ** include targets that all plugins have in common ** --> 21 <import file="../build-common.xml"/> 22 23 <target name="pre-compile" depends="-jaxb_linux, -jaxb_windows" unless="jaxb.notRequired"> 24 <exec executable="${xjc}" failonerror="true"> 25 <arg value="-d"/> 26 <arg value="src"/> 27 <arg value="-p"/> 28 <arg value="org.openstreetmap.josm.plugins.routes.xml"/> 29 <arg value="-encoding"/> 30 <arg value="UTF-8"/> 31 <arg value="resources/org/openstreetmap/josm/plugins/routes/xml/routes.xsd"/> 100 32 </exec> 101 33 </target> 102 <!--103 ** updates (svn up) the source tree for this plugin104 -->105 <target name="update-current">106 <echo>Updating plugin source ...</echo>107 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">108 <env key="LANG" value="C"/>109 <arg value="up"/>110 <arg value="."/>111 </exec>112 <echo>Updating ${plugin.jar} ...</echo>113 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">114 <env key="LANG" value="C"/>115 <arg value="up"/>116 <arg value="../dist/${plugin.jar}"/>117 </exec>118 </target>119 <!--120 ** commits the plugin.jar121 -->122 <target name="commit-dist">123 <echo>124 ***** Properties of published ${plugin.jar} *****125 Commit message : '${commit.message}'126 Plugin-Mainversion: ${plugin.main.version}127 JOSM build version: ${coreversion.info.entry.revision}128 Plugin-Version : ${version.entry.commit.revision}129 ***** / Properties of published ${plugin.jar} *****130 34 131 Now commiting ${plugin.jar} ...132 </echo>133 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">134 <env key="LANG" value="C"/>135 <arg value="-m '${commit.message}'"/>136 <arg value="commit"/>137 <arg value="${plugin.jar}"/>138 </exec>139 </target>140 <!-- ** make sure svn is present as a command line tool ** -->141 <target name="ensure-svn-present">142 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">143 <env key="LANG" value="C"/>144 <arg value="--version"/>145 </exec>146 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">147 <!-- return code not set at all? Most likely svn isn't installed -->148 <condition>149 <not>150 <isset property="svn.exit.code"/>151 </not>152 </condition>153 </fail>154 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">155 <!-- error code from SVN? Most likely svn is not what we are looking on this system -->156 <condition>157 <isfailure code="${svn.exit.code}"/>158 </condition>159 </fail>160 </target>161 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">162 </target>163 35 </project> -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/ConvertedWay.java
r30737 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 8 9 import org.openstreetmap.josm.data.osm.Node; 9 10 import org.openstreetmap.josm.data.osm.Way; 10 11 11 12 12 public class ConvertedWay { … … 22 22 public boolean equals(Object o) { 23 23 if (o instanceof WayEnd) { 24 WayEnd otherEnd = (WayEnd) o;24 WayEnd otherEnd = (WayEnd) o; 25 25 return end.equals(otherEnd.end) && routes.equals(otherEnd.getRoutes()); 26 26 } else { … … 61 61 /** 62 62 * Connects way to this way. Other ways internal representation is destroyed!!! 63 * @param way 63 * @param way way 64 64 */ 65 65 public void connect(ConvertedWay way) { 66 for (int i =0; i<2; i++) {66 for (int i = 0; i < 2; i++) { 67 67 if (way.nodes.get(0).equals(nodes.get(nodes.size() - 1))) { 68 68 way.nodes.remove(0); … … 88 88 return routes; 89 89 } 90 91 92 90 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/PathBuilder.java
r30737 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 6 7 import java.util.HashSet; 7 8 import java.util.Map; 9 import java.util.Map.Entry; 8 10 import java.util.Set; 9 import java.util.Map.Entry;10 11 11 12 import org.openstreetmap.josm.data.osm.Way; -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteDefinition.java
r33532 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 4 5 5 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 import org.openstreetmap.josm.data.osm.search.SearchParseError;7 7 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 8 8 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 9 import org.openstreetmap.josm.data.osm.search.SearchParseError; 9 10 10 11 public class RouteDefinition { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteLayer.java
r33532 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 10 11 import javax.swing.Icon; 11 12 12 import org.openstreetmap.josm.Main;13 13 import org.openstreetmap.josm.data.Bounds; 14 14 import org.openstreetmap.josm.data.osm.DataSet; … … 29 29 import org.openstreetmap.josm.plugins.routes.xml.RoutesXMLLayer; 30 30 import org.openstreetmap.josm.plugins.routes.xml.RoutesXMLRoute; 31 import org.openstreetmap.josm.spi.preferences.Config; 31 32 import org.openstreetmap.josm.tools.ColorHelper; 32 33 import org.openstreetmap.josm.tools.ImageProvider; … … 34 35 public class RouteLayer extends Layer implements DataSetListenerAdapter.Listener { 35 36 36 37 38 39 37 private final PathPainter pathPainter; 38 private final PathBuilder pathBuilder = new PathBuilder(); 39 private final List<RouteDefinition> routes = new ArrayList<>(); 40 private volatile boolean datasetChanged = true; 40 41 41 42 42 public RouteLayer(RoutesXMLLayer xmlLayer) { 43 super(xmlLayer.getName()); 43 44 44 45 46 47 48 49 50 51 52 53 54 45 int index = 0; 46 for (RoutesXMLRoute route:xmlLayer.getRoute()) { 47 if (route.isEnabled()) { 48 Color color = ColorHelper.html2color(route.getColor()); 49 if (color == null) { 50 color = Color.RED; 51 System.err.printf("Routes plugin - unable to convert color (%s)\n", route.getColor()); 52 } 53 routes.add(new RouteDefinition(index++, color, route.getPattern())); 54 } 55 } 55 56 56 if ("wide".equals(Main.pref.get("routes.painter"))) {57 58 59 60 57 if ("wide".equals(Config.getPref().get("routes.painter"))) { 58 pathPainter = new WideLinePainter(this); 59 } else { 60 pathPainter = new NarrowLinePainter(this); 61 } 61 62 62 63 63 DatasetEventManager.getInstance().addDatasetListener(new DataSetListenerAdapter(this), FireMode.IMMEDIATELY); 64 } 64 65 65 66 67 68 66 @Override 67 public Icon getIcon() { 68 return ImageProvider.get("layer", "osmdata_small"); 69 } 69 70 70 71 72 73 71 @Override 72 public Object getInfoComponent() { 73 return null; 74 } 74 75 75 76 77 78 76 @Override 77 public Action[] getMenuEntries() { 78 return new Action[0]; 79 } 79 80 80 81 82 83 81 @Override 82 public String getToolTipText() { 83 return "Hiking routes"; 84 } 84 85 85 86 87 88 86 @Override 87 public boolean isMergable(Layer other) { 88 return false; 89 } 89 90 90 91 92 93 91 @Override 92 public void mergeFrom(Layer from) { 93 // Merging is not supported 94 } 94 95 95 96 97 98 Way way = (Way)member.getMember();99 100 101 102 96 private void addRelation(Relation relation, RouteDefinition route) { 97 for (RelationMember member:relation.getMembers()) { 98 if (member.getMember() instanceof Way) { 99 Way way = (Way) member.getMember(); 100 pathBuilder.addWay(way, route); 101 } 102 } 103 } 103 104 104 105 105 @Override 106 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 106 107 107 108 DataSet dataset = MainApplication.getLayerManager().getEditDataSet(); 108 109 109 110 111 110 if (dataset == null) { 111 return; 112 } 112 113 113 114 115 114 if (datasetChanged) { 115 datasetChanged = false; 116 pathBuilder.clear(); 116 117 117 118 119 120 121 122 123 118 for (Relation relation:dataset.getRelations()) { 119 for (RouteDefinition route:routes) { 120 if (route.matches(relation)) { 121 addRelation(relation, route); 122 } 123 } 124 } 124 125 125 126 127 128 129 130 131 132 126 for (Way way:dataset.getWays()) { 127 for (RouteDefinition route:routes) { 128 if (route.matches(way)) { 129 pathBuilder.addWay(way, route); 130 } 131 } 132 } 133 } 133 134 134 135 Color color= g.getColor();136 137 138 139 140 135 Stroke stroke = g.getStroke(); 136 Color color = g.getColor(); 137 for (ConvertedWay way:pathBuilder.getConvertedWays()) { 138 pathPainter.drawWay(way, mv, g); 139 } 140 g.setStroke(stroke); 141 g.setColor(color); 141 142 142 143 } 143 144 144 145 145 @Override 146 public void visitBoundingBox(BoundingXYVisitor v) { 146 147 147 148 } 148 149 149 150 151 150 public List<RouteDefinition> getRoutes() { 151 return routes; 152 } 152 153 153 154 155 156 154 @Override 155 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 156 datasetChanged = true; 157 } 157 158 158 159 160 161 159 @Override 160 public synchronized void destroy() { 161 /* layer is reused, don't destroy it at all */ 162 } 162 163 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RoutesPlugin.java
r33896 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 61 62 Routes.class.getPackage().getName(), Routes.class.getClassLoader()); 62 63 Unmarshaller unmarshaller = context.createUnmarshaller(); 63 Routes routes = (Routes) unmarshaller.unmarshal(64 Routes routes = (Routes) unmarshaller.unmarshal( 64 65 new FileInputStream(getPluginDirs().getUserDataDirectory(false) + File.separator + "routes.xml")); 65 66 for (RoutesXMLLayer layer:routes.getLayer()) { … … 69 70 } 70 71 } catch (Exception e) { 71 e.printStackTrace();72 Logging.error(e); 72 73 } 73 74 } … … 97 98 public void layerRemoving(LayerRemoveEvent e) { 98 99 for (Layer layer : e.getSource().getLayers()) { 99 if (layer instanceof OsmDataLayer) 100 if (layer instanceof OsmDataLayer) { 100 101 return; /* at least one OSM layer left, do nothing */ 101 102 } 102 103 } 103 if (!e.isLastLayer()) {104 if (!e.isLastLayer()) { 104 105 SwingUtilities.invokeLater(() -> { 105 106 for (RouteLayer routeLayer : routeLayers) { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/AbstractLinePainter.java
r32842 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 17 18 protected boolean getLineLineIntersection(Line2D.Double l1, 18 19 Line2D.Double l2, 19 Point intersection) 20 { 20 Point intersection) { 21 21 double x1 = l1.getX1(), y1 = l1.getY1(), 22 x2 = l1.getX2(), y2 = l1.getY2(),23 x3 = l2.getX1(), y3 = l2.getY1(),24 x4 = l2.getX2(), y4 = l2.getY2();22 x2 = l1.getX2(), y2 = l1.getY2(), 23 x3 = l2.getX1(), y3 = l2.getY1(), 24 x4 = l2.getX2(), y4 = l2.getY2(); 25 25 double dx1 = x2 - x1; 26 26 double dx2 = x4 - x3; … … 31 31 32 32 if (Math.abs(dy2 * dx1 - dx2 * dy1) < 0.0001) { 33 intersection.x = (int) l1.x2;34 intersection.y = (int) l1.y2;33 intersection.x = (int) l1.x2; 34 intersection.y = (int) l1.y2; 35 35 return false; 36 36 } else { 37 intersection.x = (int) (x1 + ua * (x2 - x1));38 intersection.y = (int) (y1 + ua * (y2 - y1));37 intersection.x = (int) (x1 + ua * (x2 - x1)); 38 intersection.y = (int) (y1 + ua * (y2 - y1)); 39 39 } 40 40 … … 42 42 } 43 43 44 protected double det(double a, double b, double c, double d) 45 { 44 protected double det(double a, double b, double c, double d) { 46 45 return a * d - b * c; 47 46 } … … 60 59 ndy = ndy / length; 61 60 62 return new Point((int) (p1.getX() + shift * ndx), (int)(p1.getY() + shift * ndy));61 return new Point((int) (p1.getX() + shift * ndx), (int) (p1.getY() + shift * ndy)); 63 62 } 64 63 … … 117 116 int dx = p.x - p2.x; 118 117 int dy = p.y - p2.y; 119 int distance = (int) Math.sqrt(dx * dx + dy * dy);118 int distance = (int) Math.sqrt(dx * dx + dy * dy); 120 119 if (distance > 10) { 121 120 p.x = p2.x + dx / (distance / 10); -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/NarrowLinePainter.java
r23189 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 21 22 } 22 23 24 @Override 23 25 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g) { 24 26 List<Node> nodes = way.getNodes(); … … 33 35 //double shift = -totalWidth / 2 + width / 2; 34 36 double width = LINE_WIDTH; 35 double shift = - 37 double shift = -(LINE_WIDTH * routes.cardinality()) / 2 + width / 2; 36 38 37 for (int k =0; k<routes.length(); k++) {39 for (int k = 0; k < routes.length(); k++) { 38 40 39 41 if (!routes.get(k)) { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/PathPainter.java
r23189 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 8 9 public interface PathPainter { 9 10 10 publicvoid drawWay(ConvertedWay way, MapView mapView, Graphics2D g);11 void drawWay(ConvertedWay way, MapView mapView, Graphics2D g); 11 12 12 13 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/WideLinePainter.java
r23189 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 22 23 } 23 24 25 @Override 24 26 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g) { 25 27 List<Node> nodes = way.getNodes(); … … 34 36 double shift = -totalWidth / 2 + width / 2; 35 37 36 for (int k =0; k<routes.length(); k++) {38 for (int k = 0; k < routes.length(); k++) { 37 39 38 40 if (!routes.get(k)) {
Note:
See TracChangeset
for help on using the changeset viewer.