Changeset 36085 in osm for applications/editors/josm
- Timestamp:
- 2023-05-26T16:46:48+02:00 (18 months ago)
- Location:
- applications/editors/josm/plugins/routing
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routing/build.xml
r35978 r36085 12 12 <property name="plugin.icon" value="images/preferences/routing.png"/> 13 13 <property name="plugin.link" value="https://wiki.openstreetmap.org/index.php/JOSM/Plugins/Routing"/> 14 <property name="plugin.requires" value="log4j"/>15 14 16 15 <!-- -
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraph.java
r34187 r36085 5 5 import java.util.Arrays; 6 6 import java.util.Collection; 7 import java.util.Collections; 7 8 import java.util.List; 8 9 import java.util.Map; 9 10 10 import org.apache.log4j.Logger;11 11 import org.jgrapht.Graph; 12 12 import org.jgrapht.alg.BellmanFordShortestPath; … … 21 21 import com.innovant.josm.plugin.routing.RoutingLayer; 22 22 import com.innovant.josm.plugin.routing.RoutingModel; 23 import org.openstreetmap.josm.gui.layer.Layer; 24 import org.openstreetmap.josm.tools.Logging; 23 25 24 26 /** … … 61 63 private final DataSet data; 62 64 63 /** 64 * Logger. 65 */ 66 static Logger logger = Logger.getLogger(RoutingGraph.class); 67 68 private static Collection<String> excludedHighwayValues = Arrays.asList(new String[]{ 69 "bus_stop", "traffic_signals", "street_lamp", "stop", "construction", 70 "platform", "give_way", "proposed", "milestone", "speed_camera", "abandoned" 71 }); 65 private static final Collection<String> excludedHighwayValues = Arrays.asList("bus_stop", "traffic_signals", "street_lamp", "stop", 66 "construction", "platform", "give_way", "proposed", "milestone", "speed_camera", "abandoned"); 72 67 73 68 /** … … 84 79 // private WeightedMultigraph<Node, OsmEdge> graph; 85 80 private Graph<Node, OsmEdge> graph; 86 private RoutingGraphDelegator rgDelegator = null; 87 81 private RoutingGraphDelegator rgDelegator; 88 82 89 83 /** … … 94 88 } 95 89 90 @SuppressWarnings("squid:S2234") 96 91 private void addEdgeBidirectional(Way way, Node from, Node to) { 97 92 addEdge(way, from, to); … … 99 94 } 100 95 96 @SuppressWarnings("squid:S2234") 101 97 private void addEdgeReverseOneway(Way way, Node from, Node to) { 102 98 addEdge(way, to, from); … … 114 110 /** 115 111 * Default Constructor. 112 * @param data The data to use for the graph 116 113 */ 117 114 public RoutingGraph(DataSet data) { … … 123 120 routingProfile.setOnewayUse(true); // Don't ignore oneways by default 124 121 this.setWaySpeeds(routingProfile.getWaySpeeds()); 125 logger.debug("Created RoutingGraph");122 Logging.trace("Created RoutingGraph"); 126 123 } 127 124 … … 130 127 */ 131 128 public void createGraph() { 132 133 logger.debug("Creating Graph..."); 129 Logging.trace("Creating Graph..."); 134 130 graph = new DirectedWeightedMultigraph<>(OsmEdge.class); 135 131 rgDelegator = new RoutingGraphDelegator(graph); … … 140 136 // skip way if not suitable for routing. 141 137 if (way == null || way.isDeleted() || !this.isvalidWay(way) 142 || way.getNodes ().size() < 1) continue;138 || way.getNodesCount() == 0) continue; 143 139 144 140 // INIT … … 146 142 Node to = null; 147 143 List<Node> nodes = way.getNodes(); 148 int nodes _count = nodes.size();144 int nodesCount = nodes.size(); 149 145 150 146 /* … … 166 162 */ 167 163 168 String oneway _val = way.get("oneway"); /* get (oneway=?) tag for this way. */169 String junction _val = way.get("junction"); /* get (junction=?) tag for this way. */164 String onewayVal = way.get("oneway"); /* get (oneway=?) tag for this way. */ 165 String junctionVal = way.get("junction"); /* get (junction=?) tag for this way. */ 170 166 171 167 from = nodes.get(0); /* 1st node A */ 172 168 graph.addVertex(from); /* add vertex A */ 173 169 174 for (int i = 1; i < nodes _count; i++) { /* loop from B until E */170 for (int i = 1; i < nodesCount; i++) { /* loop from B until E */ 175 171 176 172 to = nodes.get(i); /* 2nd node B */ … … 185 181 addEdgeBidirectional(way, from, to); 186 182 187 } else if (oneway _val == null && junction_val == "roundabout") {183 } else if (onewayVal == null && "roundabout".equals(junctionVal)) { 188 184 //Case (roundabout): oneway=implicit yes 189 185 addEdgeNormalOneway(way, from, to); 190 186 191 } else if (oneway _val == null || oneway_val == "false" || oneway_val == "no" || oneway_val == "0") {187 } else if (onewayVal == null || Arrays.asList("false", "no", "0").contains(onewayVal)) { 192 188 //Case (bi-way): oneway=false OR oneway=unset OR oneway=0 OR oneway=no 193 189 addEdgeBidirectional(way, from, to); 194 190 195 } else if ( oneway_val == "-1") {191 } else if ("-1".equals(onewayVal)) { 196 192 //Case (oneway reverse): oneway=-1 197 193 addEdgeReverseOneway(way, from, to); 198 194 199 } else if ( oneway_val == "1" || oneway_val == "yes" || oneway_val == "true") {195 } else if (Arrays.asList("1", "yes", "true").contains(onewayVal)) { 200 196 //Case (oneway normal): oneway=yes OR 1 OR true 201 197 addEdgeNormalOneway(way, from, to); … … 209 205 } // end of looping thru ways 210 206 211 logger.debug("End Create Graph");212 logger.debug("Vertex: "+graph.vertexSet().size());213 logger.debug("Edges: "+graph.edgeSet().size());207 Logging.trace("End Create Graph"); 208 Logging.trace("Vertex: {0}", graph.vertexSet().size()); 209 Logging.trace("Edges: {0}", graph.edgeSet().size()); 214 210 } 215 211 … … 229 225 double weight = getWeight(way, length); 230 226 setWeight(edge, length); 231 logger.debug("edge for way " + way.getId() 232 + "(from node " + from.getId() + " to node " 233 + to.getId() + ") has weight: " + weight); 227 Logging.trace("edge for way {0} (from node {1} to node {2}) has weight: {3}", way.getId(), from.getId(), to.getId(), weight); 234 228 ((DirectedWeightedMultigraph<Node, OsmEdge>) graph).setEdgeWeight(edge, weight); 235 229 } … … 240 234 * in routing. 241 235 * 242 * @param way236 * @param osmedge 243 237 * the way. 244 238 */ … … 273 267 if (this.waySpeeds.containsKey(way.get("highway"))) 274 268 speed = this.waySpeeds.get(way.get("highway")); 275 logger.debug("Speed="+speed);269 Logging.trace("Speed={0}", speed); 276 270 break; 277 271 default: … … 315 309 Graph<Node, OsmEdge> g; 316 310 double totalWeight = 0; 317 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 311 final Layer editLayer = MainApplication.getLayerManager().getEditLayer(); 312 final RoutingLayer layer = MainApplication.getLayerManager().getLayersOfType(RoutingLayer.class) 313 .stream().filter(rLayer -> rLayer.getDataLayer() == editLayer).findFirst().orElse(null); 314 if (layer == null) { 315 return Collections.emptyList(); 316 } 318 317 RoutingModel routingModel = layer.getRoutingModel(); 319 318 320 319 if (graph == null || routingModel.getOnewayChanged()) 321 320 this.createGraph(); 322 logger.debug("apply algorithm between nodes ");321 Logging.trace("apply algorithm between nodes "); 323 322 324 323 for (Node node : nodes) { 325 logger.debug(node.getId());324 Logging.trace(Long.toString(node.getId())); 326 325 } 327 logger.debug("-----------------------------------");326 Logging.trace("-----------------------------------"); 328 327 329 328 // Assign the graph to g … … 332 331 switch (algorithm) { 333 332 case ROUTING_ALG_DIJKSTRA: 334 logger.debug("Using Dijkstra algorithm");333 Logging.trace("Using Dijkstra algorithm"); 335 334 DijkstraShortestPath<Node, OsmEdge> routingk = null; 336 335 for (int index = 1; index < nodes.size(); ++index) { … … 338 337 .get(index - 1), nodes.get(index)); 339 338 if (routingk.getPathEdgeList() == null) { 340 logger.debug("no path found!");339 Logging.trace("no path found!"); 341 340 break; 342 341 } … … 346 345 break; 347 346 case ROUTING_ALG_BELLMANFORD: 348 logger.debug("Using Bellman Ford algorithm");347 Logging.trace("Using Bellman Ford algorithm"); 349 348 for (int index = 1; index < nodes.size(); ++index) { 350 349 path = BellmanFordShortestPath.findPathBetween(rgDelegator, nodes 351 350 .get(index - 1), nodes.get(index)); 352 if (path == null ) {353 logger.debug("no path found!");354 return null;351 if (path == null || path.isEmpty()) { 352 Logging.trace("no path found!"); 353 return Collections.emptyList(); 355 354 } 356 355 } 357 356 break; 358 357 default: 359 logger.debug("Wrong algorithm");358 Logging.trace("Wrong algorithm"); 360 359 break; 361 360 } 362 361 363 logger.debug("shortest path found: " + path + "\nweight: " 364 + totalWeight); 362 Logging.trace("shortest path found: {0}\nweight: {1}", path, totalWeight); 365 363 return path; 366 364 } … … 389 387 * @param routeType the routeType to set 390 388 */ 391 public void setTypeRoute(RouteType route type) {392 this.routeType = route type;393 this.rgDelegator.setRouteType(route type);389 public void setTypeRoute(RouteType routeType) { 390 this.routeType = routeType; 391 this.rgDelegator.setRouteType(routeType); 394 392 } 395 393 -
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraphDelegator.java
r32768 r36085 2 2 package com.innovant.josm.jrt.core; 3 3 4 import org.apache.log4j.Logger;5 4 import org.jgrapht.Graph; 6 5 import org.jgrapht.graph.GraphDelegator; … … 15 14 */ 16 15 public class RoutingGraphDelegator extends GraphDelegator<Node, OsmEdge> { 17 18 /**19 * Logger.20 */21 static Logger logger = Logger.getLogger(RoutingGraphDelegator.class);22 23 16 /** 24 17 * -
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingProfile.java
r34554 r36085 5 5 import java.util.Map; 6 6 7 import org.apache.log4j.Logger;8 7 import org.openstreetmap.josm.data.Preferences; 9 8 import org.openstreetmap.josm.tools.Logging; 10 9 11 10 /** … … 30 29 */ 31 30 public class RoutingProfile { 32 /**33 * logger34 */35 static Logger logger = Logger.getLogger(RoutingProfile.class);36 31 /** 37 32 * True if oneway is used for routing (i.e. for cars). … … 74 69 */ 75 70 public RoutingProfile(String name) { 76 logger.debug("Init RoutingProfile with name: "+name);71 Logging.trace("Init RoutingProfile with name: {0}", name); 77 72 this.name = name; 78 73 waySpeeds = new HashMap<>(); 79 74 Map<String, String> prefs = Preferences.main().getAllPrefix("routing.profile."+name+".speed"); 80 for ( String key:prefs.keySet()) {81 waySpeeds.put(( key.split("\\.")[4]), Double.valueOf(prefs.get(key)));75 for (Map.Entry<String, String> entry : prefs.entrySet()) { 76 waySpeeds.put((entry.getKey().split("\\.")[4]), Double.valueOf(entry.getValue())); 82 77 } 83 for ( String key:waySpeeds.keySet()) {84 logger.debug(key+ "-- speed: "+waySpeeds.get(key));78 for (Map.Entry<String, Double> entry : waySpeeds.entrySet()) { 79 Logging.trace("{0}-- speed: {1}", entry.getKey(), entry.getValue()); 85 80 } 86 logger.debug("End init RoutingProfile with name: "+name);81 Logging.trace("End init RoutingProfile with name: {0}", name); 87 82 } 88 83 -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java
r34554 r36085 20 20 import javax.swing.Icon; 21 21 22 import org.apache.log4j.Logger;23 22 import org.openstreetmap.josm.actions.RenameLayerAction; 24 23 import org.openstreetmap.josm.data.Bounds; … … 39 38 40 39 import com.innovant.josm.jrt.osm.OsmEdge; 41 40 import org.openstreetmap.josm.tools.Logging; 42 41 43 42 /** … … 54 53 KEY_ROUTE_SELECT("routing.route.select"); 55 54 56 p ublicfinal String key;55 private final String key; 57 56 PreferencesKeys(String key) { 58 57 this.key = key; … … 65 64 66 65 /** 67 * Logger68 */69 static Logger logger = Logger.getLogger(RoutingLayer.class);70 71 /**72 66 * Constant 73 67 */ … … 77 71 * Routing Model 78 72 */ 79 private RoutingModel routingModel;73 private final RoutingModel routingModel; 80 74 81 75 /** 82 76 * Start, Middle and End icons 83 77 */ 84 private Icon startIcon, middleIcon, endIcon; 78 private final Icon startIcon; 79 private final Icon middleIcon; 80 private final Icon endIcon; 85 81 86 82 /** 87 83 * Associated OSM layer 88 84 */ 89 private OsmDataLayer dataLayer;85 private final OsmDataLayer dataLayer; 90 86 91 87 /** 92 88 * Default constructor 93 89 * @param name Layer name. 90 * @param dataLayer The datalayer to use for routing 94 91 */ 95 92 public RoutingLayer(String name, OsmDataLayer dataLayer) { 96 93 super(name); 97 logger.debug("Creating Routing Layer...");98 if (startIcon == null)startIcon = ImageProvider.get("routing", "startflag");99 if (middleIcon == null)middleIcon = ImageProvider.get("routing", "middleflag");100 if (endIcon == null)endIcon = ImageProvider.get("routing", "endflag");94 Logging.trace("Creating Routing Layer..."); 95 this.startIcon = ImageProvider.get("routing", "startflag"); 96 this.middleIcon = ImageProvider.get("routing", "middleflag"); 97 this.endIcon = ImageProvider.get("routing", "endflag"); 101 98 this.dataLayer = dataLayer; 102 99 this.routingModel = new RoutingModel(dataLayer.data); 103 logger.debug("Routing Layer created."); 104 100 Logging.trace("Routing Layer created."); 105 101 106 102 this.routingModel.routingGraph.createGraph(); /* construct the graph right after we we create the layer */ … … 138 134 if (n.isDeleted() || n.isIncomplete()) continue; 139 135 140 Point P = MainApplication.getMap().mapView.getPoint(n); 141 double dist = p.distance(P); 142 if (dist < snapDistance) { 143 if ((nearest == null) || (dist < minDist)) { 144 nearest = n; 145 minDist = dist; 146 } 136 Point point = MainApplication.getMap().mapView.getPoint(n); 137 double dist = p.distance(point); 138 if (dist < snapDistance && ((nearest == null) || (dist < minDist))) { 139 nearest = n; 140 minDist = dist; 147 141 } 148 142 } … … 153 147 @Override 154 148 public Icon getIcon() { 155 Icon icon = ImageProvider.get("layer", "routing_small"); 156 return icon; 149 return ImageProvider.get("layer", "routing_small"); 157 150 } 158 151 159 152 @Override 160 153 public Object getInfoComponent() { 161 String info ="<html>"154 return "<html>" 162 155 + "<body>" 163 156 +"Graph Vertex: "+this.routingModel.routingGraph.getVertexCount()+"<br/>" … … 165 158 + "</body>" 166 159 + "</html>"; 167 return info;168 160 } 169 161 … … 183 175 @Override 184 176 public String getToolTipText() { 185 String tooltip =this.routingModel.routingGraph.getVertexCount() + " vertices, "177 return this.routingModel.routingGraph.getVertexCount() + " vertices, " 186 178 + this.routingModel.routingGraph.getEdgeCount() + " edges"; 187 return tooltip;188 179 } 189 180 … … 208 199 Color color; 209 200 if (isActiveLayer) { 210 color = new NamedColorProperty(PreferencesKeys.KEY_ACTIVE_ROUTE_COLOR. key, Color.RED).get();201 color = new NamedColorProperty(PreferencesKeys.KEY_ACTIVE_ROUTE_COLOR.getKey(), Color.RED).get(); 211 202 } else { 212 color = new NamedColorProperty(PreferencesKeys.KEY_INACTIVE_ROUTE_COLOR. key, Color.decode("#dd2222")).get();203 color = new NamedColorProperty(PreferencesKeys.KEY_INACTIVE_ROUTE_COLOR.getKey(), Color.decode("#dd2222")).get(); 213 204 } 214 205 215 206 // Get path stroke width from preferences 216 String widthString = Config.getPref().get(PreferencesKeys.KEY_ROUTE_WIDTH. key);207 String widthString = Config.getPref().get(PreferencesKeys.KEY_ROUTE_WIDTH.getKey()); 217 208 if (widthString.length() == 0) { 218 209 widthString = "2"; /* I think 2 is better */ … … 223 214 224 215 // draw our graph 225 if (isActiveLayer) { 226 if (routingModel != null) { 227 if (routingModel.routingGraph != null && routingModel.routingGraph.getGraph() != null) { 228 Set<OsmEdge> graphEdges = routingModel.routingGraph.getGraph().edgeSet(); 229 if (!graphEdges.isEmpty()) { 230 Color color2 = ColorHelper.html2color("#00ff00"); /* just green for now */ 231 OsmEdge firstedge = (OsmEdge) graphEdges.toArray()[0]; 232 Point from = mv.getPoint(firstedge.fromEastNorth()); 233 g.drawRect(from.x-4, from.y+4, from.x+4, from.y-4); 234 for (OsmEdge edge : graphEdges) { 235 drawGraph(g, mv, edge, color2, width); 236 } 237 } 216 if (isActiveLayer && routingModel.routingGraph != null && routingModel.routingGraph.getGraph() != null) { 217 Set<OsmEdge> graphEdges = routingModel.routingGraph.getGraph().edgeSet(); 218 if (!graphEdges.isEmpty()) { 219 Color color2 = ColorHelper.html2color("#00ff00"); /* just green for now */ 220 OsmEdge firstedge = (OsmEdge) graphEdges.toArray()[0]; 221 Point from = mv.getPoint(firstedge.fromEastNorth()); 222 g.drawRect(from.x - 4, from.y + 4, from.x + 4, from.y - 4); 223 for (OsmEdge edge : graphEdges) { 224 drawGraph(g, mv, edge, color2, width); 238 225 } 239 226 } … … 241 228 242 229 243 if (nodes == null || nodes. size() == 0) return;230 if (nodes == null || nodes.isEmpty()) return; 244 231 245 232 // Paint routing path … … 289 276 * Draw a line with the given color. 290 277 */ 291 private void drawEdge(Graphics g, MapView mv, OsmEdge edge, Color col, int width,278 private static void drawEdge(Graphics g, MapView mv, OsmEdge edge, Color col, int width, 292 279 boolean showDirection) { 293 280 g.setColor(col); … … 310 297 } 311 298 312 private void drawGraph(Graphics g, MapView mv, OsmEdge edge, Color col, int width) {299 private static void drawGraph(Graphics g, MapView mv, OsmEdge edge, Color col, int width) { 313 300 g.setColor(col); 314 301 Point from; -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingModel.java
r32768 r36085 5 5 import java.util.List; 6 6 7 import org.apache.log4j.Logger;8 7 import org.openstreetmap.josm.data.osm.DataSet; 9 8 import org.openstreetmap.josm.data.osm.Node; … … 12 11 import com.innovant.josm.jrt.core.RoutingGraph.Algorithm; 13 12 import com.innovant.josm.jrt.osm.OsmEdge; 14 13 import org.openstreetmap.josm.tools.Logging; 15 14 16 15 /** … … 21 20 */ 22 21 public class RoutingModel { 23 24 /**25 * Logger26 */27 static Logger logger = Logger.getLogger(RoutingModel.class);28 29 22 /** 30 23 * Graph to calculate route 31 24 */ 32 public RoutingGraph routingGraph = null;25 public final RoutingGraph routingGraph; 33 26 34 27 /** 35 28 * List of nodes that the route has to traverse 36 29 */ 37 private List<Node> nodes = null;30 private List<Node> nodes; 38 31 39 private List<OsmEdge> path = null;32 private List<OsmEdge> path; 40 33 41 34 /** 42 35 * Flag to advise about changes in the selected nodes. 43 36 */ 44 private boolean changeNodes = false;37 private boolean changeNodes; 45 38 46 39 /** 47 40 * Flag to advise about changes in ways. 48 41 */ 49 private boolean changeOneway = false;42 private boolean changeOneway; 50 43 51 44 /** 52 45 * Default Constructor. 46 * @param data The data to use for the routing graph 53 47 */ 54 48 public RoutingModel(DataSet data) { 55 49 nodes = new ArrayList<>(); 56 System.out.println("gr " + data);50 Logging.trace("gr " + data); 57 51 routingGraph = new RoutingGraph(data); 58 52 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingPlugin.java
r33794 r36085 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File;7 6 import java.util.ArrayList; 8 7 9 import org.apache.log4j.Logger; 10 import org.apache.log4j.xml.DOMConfigurator; 8 import com.innovant.josm.plugin.routing.actions.AddRouteNodeAction; 9 import com.innovant.josm.plugin.routing.actions.MoveRouteNodeAction; 10 import com.innovant.josm.plugin.routing.actions.RemoveRouteNodeAction; 11 import com.innovant.josm.plugin.routing.gui.RoutingDialog; 12 import com.innovant.josm.plugin.routing.gui.RoutingMenu; 13 import com.innovant.josm.plugin.routing.gui.RoutingPreferenceDialog; 11 14 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 12 15 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter; … … 27 30 import org.openstreetmap.josm.tools.Logging; 28 31 29 import com.innovant.josm.plugin.routing.actions.AddRouteNodeAction;30 import com.innovant.josm.plugin.routing.actions.MoveRouteNodeAction;31 import com.innovant.josm.plugin.routing.actions.RemoveRouteNodeAction;32 import com.innovant.josm.plugin.routing.gui.RoutingDialog;33 import com.innovant.josm.plugin.routing.gui.RoutingMenu;34 import com.innovant.josm.plugin.routing.gui.RoutingPreferenceDialog;35 36 32 /** 37 33 * The main class of the routing plugin … … 43 39 */ 44 40 public class RoutingPlugin extends Plugin implements LayerChangeListener, DataSetListenerAdapter.Listener { 45 /**46 * Logger47 */48 static Logger logger = Logger.getLogger(RoutingPlugin.class);49 41 50 42 /** … … 116 108 datasetAdapter = new DataSetListenerAdapter(this); 117 109 plugin = this; // Assign reference to the plugin class 118 File log4jConfigFile = new java.io.File("log4j.xml"); 119 if (log4jConfigFile.exists()) { 120 DOMConfigurator.configure(log4jConfigFile.getPath()); 121 } else { 122 System.err.println("Routing plugin warning: log4j configuration not found"); 123 } 124 logger.debug("Loading routing plugin..."); 110 Logging.trace("Loading routing plugin..."); 125 111 preferenceSettings = new RoutingPreferenceDialog(); 126 112 // Initialize layers list … … 131 117 MainApplication.getLayerManager().addLayerChangeListener(this); 132 118 DatasetEventManager.getInstance().addDatasetListener(datasetAdapter, FireMode.IN_EDT_CONSOLIDATED); 133 logger.debug("Finished loading plugin");119 Logging.trace("Finished loading plugin"); 134 120 } 135 121 … … 178 164 // Enable menu 179 165 menu.enableStartItem(); 180 newFrame.addToggleDialog(routingDialog = new RoutingDialog()); 166 routingDialog = new RoutingDialog(); 167 newFrame.addToggleDialog(routingDialog); 181 168 } else { 182 169 addRouteNodeAction = null; … … 218 205 // Set layer on top and select layer, also refresh toggleDialog to reflect selection 219 206 MainApplication.getMap().mapView.moveLayer(newLayer, 0); 220 logger.debug("Added routing layer.");207 Logging.trace("Added routing layer."); 221 208 } 222 209 } … … 232 219 menu.disableRestOfItems(); 233 220 layers.remove(oldLayer); 234 logger.debug("Removed routing layer.");221 Logging.trace("Removed routing layer."); 235 222 } else if (oldLayer instanceof OsmDataLayer) { 236 223 // Remove all associated routing layers … … 238 225 // FIXME: can't remove associated routing layers without triggering exceptions in some cases 239 226 RoutingLayer[] layersArray = layers.toArray(new RoutingLayer[0]); 240 for ( int i = 0; i < layersArray.length; i++) {241 if ( layersArray[i].getDataLayer().equals(oldLayer)) {227 for (RoutingLayer routingLayer : layersArray) { 228 if (routingLayer.getDataLayer().equals(oldLayer)) { 242 229 try { 243 230 // Remove layer 244 MainApplication.getLayerManager().removeLayer( layersArray[i]);231 MainApplication.getLayerManager().removeLayer(routingLayer); 245 232 } catch (IllegalArgumentException e) { 246 233 Logging.error(e); -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/AddRouteNodeAction.java
r33794 r36085 6 6 import java.awt.event.MouseEvent; 7 7 8 import org.apache.log4j.Logger;9 8 import org.openstreetmap.josm.actions.mapmode.MapMode; 10 9 import org.openstreetmap.josm.data.osm.Node; … … 15 14 import com.innovant.josm.plugin.routing.RoutingLayer; 16 15 import com.innovant.josm.plugin.routing.RoutingPlugin; 16 import org.openstreetmap.josm.tools.Logging; 17 17 18 18 /** … … 24 24 */ 25 25 public class AddRouteNodeAction extends MapMode { 26 27 /**28 * Logger.29 */30 static Logger logger = Logger.getLogger(AddRouteNodeAction.class);31 32 26 /** 33 27 * Constructor 34 * @param mapFrame map frame35 28 */ 36 29 public AddRouteNodeAction() { … … 60 53 node = layer.getNearestHighwayNode(e.getPoint()); 61 54 if (node == null) { 62 logger.debug("no selected node");55 Logging.trace("no selected node"); 63 56 return; 64 57 } 65 logger.debug("selected node " +node);58 Logging.trace("selected node {0}", node); 66 59 layer.getRoutingModel().addNode(node); 67 60 RoutingPlugin.getInstance().getRoutingDialog().addNode(node); -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/MoveRouteNodeAction.java
r33794 r36085 8 8 import java.util.List; 9 9 10 import org.apache.log4j.Logger;11 10 import org.openstreetmap.josm.actions.mapmode.MapMode; 12 11 import org.openstreetmap.josm.data.osm.Node; … … 19 18 import com.innovant.josm.plugin.routing.RoutingPlugin; 20 19 import com.innovant.josm.plugin.routing.gui.RoutingDialog; 20 import org.openstreetmap.josm.tools.Logging; 21 21 22 22 /** … … 35 35 36 36 /** 37 * Logger.38 */39 static Logger logger = Logger.getLogger(RoutingLayer.class);40 41 /**42 37 * Index of dragged node 43 38 */ … … 46 41 /** 47 42 * Constructor 48 * @param mapFrame map frame49 43 */ 50 44 public MoveRouteNodeAction() { … … 67 61 @Override public void mousePressed(MouseEvent e) { 68 62 // If left button is pressed 69 if (e.getButton() == MouseEvent.BUTTON1) { 70 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 71 requestFocusInMapView(); 72 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 73 RoutingModel routingModel = layer.getRoutingModel(); 74 // Search for the nearest node in the list 75 List<Node> nl = routingModel.getSelectedNodes(); 76 index = -1; 77 double dmax = DRAG_SQR_RADIUS; // maximum distance, in pixels 78 for (int i = 0; i < nl.size(); i++) { 79 Node node = nl.get(i); 80 double d = MainApplication.getMap().mapView.getPoint(node).distanceSq(e.getPoint()); 81 if (d < dmax) { 82 dmax = d; 83 index = i; 84 } 63 if (e.getButton() == MouseEvent.BUTTON1 && MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 64 requestFocusInMapView(); 65 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 66 RoutingModel routingModel = layer.getRoutingModel(); 67 // Search for the nearest node in the list 68 List<Node> nl = routingModel.getSelectedNodes(); 69 index = -1; 70 double dmax = DRAG_SQR_RADIUS; // maximum distance, in pixels 71 for (int i = 0; i < nl.size(); i++) { 72 Node node = nl.get(i); 73 double d = MainApplication.getMap().mapView.getPoint(node).distanceSq(e.getPoint()); 74 if (d < dmax) { 75 dmax = d; 76 index = i; 85 77 } 86 if (index >= 0)87 logger.debug("Moved from node " + nl.get(index));88 78 } 79 if (index >= 0) 80 Logging.trace("Moved from node {0}", nl.get(index)); 89 81 } 90 82 } … … 109 101 node = layer.getNearestHighwayNode(point); 110 102 if (node == null) { 111 logger.debug("Didn't found a close node to move to.");103 Logging.trace("Didn't found a close node to move to."); 112 104 return; 113 105 } 114 logger.debug("Moved to node " +node);106 Logging.trace("Moved to node {0}", node); 115 107 routingModel.removeNode(index); 116 108 routingDialog.removeNode(index); -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/RemoveRouteNodeAction.java
r33794 r36085 7 7 import java.util.List; 8 8 9 import org.apache.log4j.Logger;10 9 import org.openstreetmap.josm.actions.mapmode.MapMode; 11 10 import org.openstreetmap.josm.data.osm.Node; … … 17 16 import com.innovant.josm.plugin.routing.RoutingModel; 18 17 import com.innovant.josm.plugin.routing.RoutingPlugin; 18 import org.openstreetmap.josm.tools.Logging; 19 19 20 20 /** … … 31 31 */ 32 32 private static final int REMOVE_SQR_RADIUS = 100; 33 34 /**35 * Logger.36 */37 static Logger logger = Logger.getLogger(RoutingLayer.class);38 33 39 34 public RemoveRouteNodeAction() { … … 56 51 @Override public void mouseClicked(MouseEvent e) { 57 52 // If left button is clicked 58 if (e.getButton() == MouseEvent.BUTTON1) { 59 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 60 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 61 RoutingModel routingModel = layer.getRoutingModel(); 62 // Search for the nearest node in the list 63 List<Node> nl = routingModel.getSelectedNodes(); 64 int index = -1; 65 double dmax = REMOVE_SQR_RADIUS; // maximum distance, in pixels 66 for (int i = 0; i < nl.size(); i++) { 67 Node node = nl.get(i); 68 double d = MainApplication.getMap().mapView.getPoint(node).distanceSq(e.getPoint()); 69 if (d < dmax) { 70 dmax = d; 71 index = i; 72 } 53 if (e.getButton() == MouseEvent.BUTTON1 && MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 54 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 55 RoutingModel routingModel = layer.getRoutingModel(); 56 // Search for the nearest node in the list 57 List<Node> nl = routingModel.getSelectedNodes(); 58 int index = -1; 59 double dmax = REMOVE_SQR_RADIUS; // maximum distance, in pixels 60 for (int i = 0; i < nl.size(); i++) { 61 Node node = nl.get(i); 62 double d = MainApplication.getMap().mapView.getPoint(node).distanceSq(e.getPoint()); 63 if (d < dmax) { 64 dmax = d; 65 index = i; 73 66 } 74 // If found a close node, remove it and recalculate route75 if (index >= 0) {76 // Remove node77 logger.debug("Removing node " + nl.get(index));78 routingModel.removeNode(index);79 RoutingPlugin.getInstance().getRoutingDialog().removeNode(index);80 MainApplication.getMap().repaint();81 } else {82 logger.debug("Can't find a node to remove.");83 }67 } 68 // If found a close node, remove it and recalculate route 69 if (index >= 0) { 70 // Remove node 71 Logging.trace("Removing node {0}", nl.get(index)); 72 routingModel.removeNode(index); 73 RoutingPlugin.getInstance().getRoutingDialog().removeNode(index); 74 MainApplication.getMap().repaint(); 75 } else { 76 Logging.trace("Can't find a node to remove."); 84 77 } 85 78 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingDialog.java
r33794 r36085 18 18 import com.innovant.josm.plugin.routing.RoutingLayer; 19 19 import com.innovant.josm.plugin.routing.RoutingModel; 20 21 20 22 21 /** -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java
r33794 r36085 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.event.ActionEvent;8 import java.awt.event.ActionListener;9 7 import java.awt.event.ItemEvent; 10 import java.awt.event.ItemListener;11 8 import java.awt.event.KeyEvent; 12 9 … … 17 14 import javax.swing.JRadioButtonMenuItem; 18 15 19 import org.openstreetmap.josm.gui.MainApplication;20 import org.openstreetmap.josm.gui.MainMenu;21 22 16 import com.innovant.josm.jrt.core.RoutingGraph.RouteType; 23 17 import com.innovant.josm.plugin.routing.RoutingLayer; 24 18 import com.innovant.josm.plugin.routing.RoutingModel; 25 19 import com.innovant.josm.plugin.routing.RoutingPlugin; 20 import org.openstreetmap.josm.gui.MainApplication; 21 import org.openstreetmap.josm.gui.MainMenu; 26 22 27 23 /** … … 51 47 52 48 startMI = new JMenuItem(tr("Add routing layer")); 53 startMI.addActionListener(new ActionListener() { 54 @Override 55 public void actionPerformed(ActionEvent e) { 56 RoutingPlugin.getInstance().addLayer(); 57 } 58 }); 49 startMI.addActionListener(e -> RoutingPlugin.getInstance().addLayer()); 59 50 menu.add(startMI); 60 51 … … 66 57 JRadioButtonMenuItem rshorter = new JRadioButtonMenuItem(tr("Shortest")); 67 58 rshorter.setSelected(true); 68 rshorter.addItemListener(new ItemListener() { 69 @Override 70 public void itemStateChanged(ItemEvent e) { 71 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 72 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 73 RoutingModel routingModel = layer.getRoutingModel(); 74 if (e.getStateChange() == ItemEvent.SELECTED) { 75 routingModel.routingGraph.setTypeRoute(RouteType.SHORTEST); 76 } else { 77 routingModel.routingGraph.setTypeRoute(RouteType.FASTEST); 78 } 79 // routingModel.routingGraph.resetGraph(); 80 // routingModel.routingGraph.createGraph(); 81 //TODO: Change this way 82 //FIXME: do not change node but recalculate routing. 83 routingModel.setNodesChanged(); 84 MainApplication.getMap().repaint(); 59 rshorter.addItemListener(e -> { 60 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 61 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 62 RoutingModel routingModel = layer.getRoutingModel(); 63 if (e.getStateChange() == ItemEvent.SELECTED) { 64 routingModel.routingGraph.setTypeRoute(RouteType.SHORTEST); 65 } else { 66 routingModel.routingGraph.setTypeRoute(RouteType.FASTEST); 85 67 } 68 // routingModel.routingGraph.resetGraph(); 69 // routingModel.routingGraph.createGraph(); 70 //TODO: Change this way 71 //FIXME: do not change node but recalculate routing. 72 routingModel.setNodesChanged(); 73 MainApplication.getMap().repaint(); 86 74 } 87 88 75 }); 89 76 … … 96 83 criteriaM.addSeparator(); 97 84 JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(tr("Ignore oneways")); 98 cbmi.addItemListener(new ItemListener() { 99 @Override 100 public void itemStateChanged(ItemEvent e) { 101 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 102 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 103 RoutingModel routingModel = layer.getRoutingModel(); 104 if (e.getStateChange() == ItemEvent.SELECTED) 105 routingModel.routingGraph.getRoutingProfile().setOnewayUse(false); 106 else 107 routingModel.routingGraph.getRoutingProfile().setOnewayUse(true); 108 routingModel.setNodesChanged(); 109 routingModel.setOnewayChanged(); 110 MainApplication.getMap().repaint(); 111 } 85 cbmi.addItemListener(e -> { 86 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 87 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 88 RoutingModel routingModel = layer.getRoutingModel(); 89 routingModel.routingGraph.getRoutingProfile().setOnewayUse(e.getStateChange() != ItemEvent.SELECTED); 90 routingModel.setNodesChanged(); 91 routingModel.setOnewayChanged(); 92 MainApplication.getMap().repaint(); 112 93 } 113 94 }); … … 117 98 menu.addSeparator(); 118 99 reverseMI = new JMenuItem(tr("Reverse route")); 119 reverseMI.addActionListener(new ActionListener() { 120 @Override 121 public void actionPerformed(ActionEvent e) { 122 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 123 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 124 RoutingModel routingModel = layer.getRoutingModel(); 125 routingModel.reverseNodes(); 126 MainApplication.getMap().repaint(); 127 } 100 reverseMI.addActionListener(e -> { 101 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 102 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 103 RoutingModel routingModel = layer.getRoutingModel(); 104 routingModel.reverseNodes(); 105 MainApplication.getMap().repaint(); 128 106 } 129 107 }); … … 131 109 132 110 clearMI = new JMenuItem(tr("Clear route")); 133 clearMI.addActionListener(new ActionListener() { 134 @Override 135 public void actionPerformed(ActionEvent e) { 136 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 137 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 138 RoutingModel routingModel = layer.getRoutingModel(); 139 // Reset routing nodes and paths 140 routingModel.reset(); 141 RoutingPlugin.getInstance().getRoutingDialog().clearNodes(); 142 MainApplication.getMap().repaint(); 143 } 111 clearMI.addActionListener(e -> { 112 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 113 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 114 RoutingModel routingModel = layer.getRoutingModel(); 115 // Reset routing nodes and paths 116 routingModel.reset(); 117 RoutingPlugin.getInstance().getRoutingDialog().clearNodes(); 118 MainApplication.getMap().repaint(); 144 119 } 145 120 }); … … 147 122 148 123 regraphMI = new JMenuItem(tr("Reconstruct Graph")); 149 regraphMI.addActionListener(new ActionListener() { 150 @Override 151 public void actionPerformed(ActionEvent e) { 152 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 153 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 154 RoutingModel routingModel = layer.getRoutingModel(); 155 routingModel.routingGraph.resetGraph(); 156 routingModel.routingGraph.createGraph(); 157 } 124 regraphMI.addActionListener(e -> { 125 if (MainApplication.getLayerManager().getActiveLayer() instanceof RoutingLayer) { 126 RoutingLayer layer = (RoutingLayer) MainApplication.getLayerManager().getActiveLayer(); 127 RoutingModel routingModel = layer.getRoutingModel(); 128 routingModel.routingGraph.resetGraph(); 129 routingModel.routingGraph.createGraph(); 158 130 } 159 131 }); -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingPreferenceDialog.java
r34554 r36085 7 7 import java.awt.Dimension; 8 8 import java.awt.GridBagLayout; 9 import java.awt.event.ActionEvent;10 import java.awt.event.ActionListener;11 9 import java.awt.event.MouseAdapter; 12 10 import java.awt.event.MouseEvent; … … 26 24 import javax.swing.table.DefaultTableModel; 27 25 28 import org.apache.log4j.Logger;26 import com.innovant.josm.jrt.osm.OsmWayTypes; 29 27 import org.openstreetmap.josm.data.Preferences; 30 28 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; … … 32 30 import org.openstreetmap.josm.spi.preferences.Config; 33 31 import org.openstreetmap.josm.tools.GBC; 34 35 import com.innovant.josm.jrt.osm.OsmWayTypes; 32 import org.openstreetmap.josm.tools.Logging; 36 33 37 34 public class RoutingPreferenceDialog extends DefaultTabPreferenceSetting { 38 35 39 /**40 * Logger41 */42 static Logger logger = Logger.getLogger(RoutingPreferenceDialog.class);43 36 44 37 private Map<String, String> orig; … … 81 74 p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL)); 82 75 p.add(add, GBC.std().insets(0, 5, 0, 0)); 83 add.addActionListener(new ActionListener() { 84 @Override 85 public void actionPerformed(ActionEvent e) { 86 JPanel p = new JPanel(new GridBagLayout()); 87 p.add(new JLabel(tr("Weight")), GBC.std().insets(0, 0, 5, 0)); 88 JComboBox<String> key = new JComboBox<>(); 89 for (OsmWayTypes pk : OsmWayTypes.values()) { 90 key.addItem(pk.getTag()); 91 } 92 JTextField value = new JTextField(10); 93 p.add(key, GBC.eop().insets(5, 0, 0, 0).fill(GBC.HORIZONTAL)); 94 p.add(new JLabel(tr("Value")), GBC.std().insets(0, 0, 5, 0)); 95 p.add(value, GBC.eol().insets(5, 0, 0, 0).fill(GBC.HORIZONTAL)); 96 int answer = JOptionPane.showConfirmDialog(gui, p, 97 tr("Enter weight values"), 98 JOptionPane.OK_CANCEL_OPTION); 99 if (answer == JOptionPane.OK_OPTION) { 100 model 101 .addRow(new String[] { 102 key.getSelectedItem().toString(), 103 value.getText() }); 104 } 76 add.addActionListener(e -> { 77 JPanel p1 = new JPanel(new GridBagLayout()); 78 p1.add(new JLabel(tr("Weight")), GBC.std().insets(0, 0, 5, 0)); 79 JComboBox<String> key = new JComboBox<>(); 80 for (OsmWayTypes pk : OsmWayTypes.values()) { 81 key.addItem(pk.getTag()); 82 } 83 JTextField value = new JTextField(10); 84 p1.add(key, GBC.eop().insets(5, 0, 0, 0).fill(GBC.HORIZONTAL)); 85 p1.add(new JLabel(tr("Value")), GBC.std().insets(0, 0, 5, 0)); 86 p1.add(value, GBC.eol().insets(5, 0, 0, 0).fill(GBC.HORIZONTAL)); 87 int answer = JOptionPane.showConfirmDialog(gui, p1, 88 tr("Enter weight values"), 89 JOptionPane.OK_CANCEL_OPTION); 90 if (answer == JOptionPane.OK_OPTION) { 91 model 92 .addRow(new String[] { 93 key.getSelectedItem().toString(), 94 value.getText() }); 105 95 } 106 96 }); … … 108 98 JButton delete = new JButton(tr("Delete")); 109 99 p.add(delete, GBC.std().insets(0, 5, 0, 0)); 110 delete.addActionListener(new ActionListener() { 111 @Override 112 public void actionPerformed(ActionEvent e) { 113 if (list.getSelectedRow() == -1) 114 JOptionPane.showMessageDialog(gui, 115 tr("Please select the row to delete.")); 116 else { 117 Integer i; 118 while ((i = list.getSelectedRow()) != -1) { 119 model.removeRow(i); 120 } 100 delete.addActionListener(e -> { 101 if (list.getSelectedRow() == -1) 102 JOptionPane.showMessageDialog(gui, 103 tr("Please select the row to delete.")); 104 else { 105 int i; 106 while ((i = list.getSelectedRow()) != -1) { 107 model.removeRow(i); 121 108 } 122 109 } … … 125 112 JButton edit = new JButton(tr("Edit")); 126 113 p.add(edit, GBC.std().insets(5, 5, 5, 0)); 127 edit.addActionListener(new ActionListener() { 128 @Override 129 public void actionPerformed(ActionEvent e) { 130 edit(gui, list); 131 } 132 }); 114 edit.addActionListener(e -> edit(gui, list)); 133 115 134 JTabbedPane Opciones = new JTabbedPane();135 Opciones.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);116 JTabbedPane options = new JTabbedPane(); 117 options.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); 136 118 137 Opciones.addTab("Profile", null, p, null);138 // Opciones.addTab("Preferences", new JPanel());119 options.addTab("Profile", null, p, null); 120 // options.addTab("Preferences", new JPanel()); 139 121 140 122 list.addMouseListener(new MouseAdapter() { … … 145 127 }); 146 128 147 principal.add( Opciones, GBC.eol().fill(GBC.BOTH));129 principal.add(options, GBC.eol().fill(GBC.BOTH)); 148 130 149 131 } … … 184 166 readPreferences(); 185 167 // Put these values in the model 186 for ( String tag : orig.keySet()) {187 model.addRow(new String[] { tag, orig.get(tag)});168 for (Map.Entry<String, String> entry : orig.entrySet()) { 169 model.addRow(new String[] {entry.getKey(), entry.getValue()}); 188 170 } 189 171 } … … 192 174 orig = Preferences.main().getAllPrefix("routing.profile.default.speed"); 193 175 if (orig.size() == 0) { // defaults 194 logger.debug("Loading Default Preferences.");176 Logging.trace("Loading Default Preferences."); 195 177 for (OsmWayTypes owt : OsmWayTypes.values()) { 196 178 Config.getPref().putInt("routing.profile.default.speed." … … 198 180 } 199 181 orig = Preferences.main().getAllPrefix("routing.profile.default.speed"); 200 } else logger.debug("Default preferences already exist.");182 } else Logging.trace("Default preferences already exist."); 201 183 } 202 184 /*
Note:
See TracChangeset
for help on using the changeset viewer.