Changeset 33532 in osm for applications/editors/josm/plugins/routes
- Timestamp:
- 2017-08-26T02:18:43+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/routes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routes/build.xml
r32826 r33532 2 2 <project name="routes" default="dist" basedir="."> 3 3 <property name="commit.message" value="Changed the constructor signature of the plugin main class"/> 4 <property name="plugin.main.version" value="1 0827"/>4 <property name="plugin.main.version" value="12662"/> 5 5 <property name="josm" location="../../core/dist/josm-custom.jar"/> 6 6 <property name="plugin.dist.dir" value="../../dist"/> -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteDefinition.java
r31586 r33532 3 3 import java.awt.Color; 4 4 5 import org.openstreetmap.josm.actions.search.SearchCompiler;6 import org.openstreetmap.josm.actions.search.SearchCompiler.Match;7 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;8 5 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 import org.openstreetmap.josm.data.osm.search.SearchParseError; 7 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 8 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 9 9 10 10 public class RouteDefinition { … … 21 21 try { 22 22 match = SearchCompiler.compile(expression); 23 } catch ( ParseError e) {23 } catch (SearchParseError e) { 24 24 match = new SearchCompiler.Never(); 25 25 e.printStackTrace(); -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteLayer.java
r33290 r33532 21 21 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 22 22 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 23 import org.openstreetmap.josm.gui.MainApplication; 23 24 import org.openstreetmap.josm.gui.MapView; 24 25 import org.openstreetmap.josm.gui.layer.Layer; … … 33 34 public class RouteLayer extends Layer implements DataSetListenerAdapter.Listener { 34 35 35 36 37 38 36 private final PathPainter pathPainter; 37 private final PathBuilder pathBuilder = new PathBuilder(); 38 private final List<RouteDefinition> routes = new ArrayList<>(); 39 private volatile boolean datasetChanged = true; 39 40 40 41 41 public RouteLayer(RoutesXMLLayer xmlLayer) { 42 super(xmlLayer.getName()); 42 43 43 44 45 46 47 48 49 50 51 52 53 44 int index = 0; 45 for (RoutesXMLRoute route:xmlLayer.getRoute()) { 46 if (route.isEnabled()) { 47 Color color = ColorHelper.html2color(route.getColor()); 48 if (color == null) { 49 color = Color.RED; 50 System.err.printf("Routes plugin - unable to convert color (%s)\n", route.getColor()); 51 } 52 routes.add(new RouteDefinition(index++, color, route.getPattern())); 53 } 54 } 54 55 55 56 57 58 59 56 if ("wide".equals(Main.pref.get("routes.painter"))) { 57 pathPainter = new WideLinePainter(this); 58 } else { 59 pathPainter = new NarrowLinePainter(this); 60 } 60 61 61 62 62 DatasetEventManager.getInstance().addDatasetListener(new DataSetListenerAdapter(this), FireMode.IMMEDIATELY); 63 } 63 64 64 65 66 67 65 @Override 66 public Icon getIcon() { 67 return ImageProvider.get("layer", "osmdata_small"); 68 } 68 69 69 70 71 72 70 @Override 71 public Object getInfoComponent() { 72 return null; 73 } 73 74 74 75 76 77 75 @Override 76 public Action[] getMenuEntries() { 77 return new Action[0]; 78 } 78 79 79 80 81 82 80 @Override 81 public String getToolTipText() { 82 return "Hiking routes"; 83 } 83 84 84 85 86 87 85 @Override 86 public boolean isMergable(Layer other) { 87 return false; 88 } 88 89 89 90 91 92 90 @Override 91 public void mergeFrom(Layer from) { 92 // Merging is not supported 93 } 93 94 94 95 96 97 98 99 100 101 95 private void addRelation(Relation relation, RouteDefinition route) { 96 for (RelationMember member:relation.getMembers()) { 97 if (member.getMember() instanceof Way) { 98 Way way = (Way)member.getMember(); 99 pathBuilder.addWay(way, route); 100 } 101 } 102 } 102 103 103 104 104 @Override 105 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 105 106 106 DataSet dataset = Main.getLayerManager().getEditDataSet();107 DataSet dataset = MainApplication.getLayerManager().getEditDataSet(); 107 108 108 109 110 109 if (dataset == null) { 110 return; 111 } 111 112 112 113 114 113 if (datasetChanged) { 114 datasetChanged = false; 115 pathBuilder.clear(); 115 116 116 117 118 119 120 121 122 117 for (Relation relation:dataset.getRelations()) { 118 for (RouteDefinition route:routes) { 119 if (route.matches(relation)) { 120 addRelation(relation, route); 121 } 122 } 123 } 123 124 124 125 126 127 128 129 130 131 125 for (Way way:dataset.getWays()) { 126 for (RouteDefinition route:routes) { 127 if (route.matches(way)) { 128 pathBuilder.addWay(way, route); 129 } 130 } 131 } 132 } 132 133 133 134 135 136 137 138 139 134 Stroke stroke = g.getStroke(); 135 Color color = g.getColor(); 136 for (ConvertedWay way:pathBuilder.getConvertedWays()) { 137 pathPainter.drawWay(way, mv, g); 138 } 139 g.setStroke(stroke); 140 g.setColor(color); 140 141 141 142 } 142 143 143 144 144 @Override 145 public void visitBoundingBox(BoundingXYVisitor v) { 145 146 146 147 } 147 148 148 149 150 149 public List<RouteDefinition> getRoutes() { 150 return routes; 151 } 151 152 152 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 153 datasetChanged = true; 154 } 153 @Override 154 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 155 datasetChanged = true; 156 } 155 157 156 157 158 159 158 @Override 159 public synchronized void destroy() { 160 /* layer is reused, don't destroy it at all */ 161 } 160 162 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RoutesPlugin.java
r33292 r33532 14 14 import javax.xml.bind.Unmarshaller; 15 15 16 import org.openstreetmap.josm. Main;16 import org.openstreetmap.josm.gui.MainApplication; 17 17 import org.openstreetmap.josm.gui.layer.Layer; 18 18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 25 25 import org.openstreetmap.josm.plugins.routes.xml.Routes; 26 26 import org.openstreetmap.josm.plugins.routes.xml.RoutesXMLLayer; 27 import org.openstreetmap.josm.tools.Logging; 27 28 28 29 public class RoutesPlugin extends Plugin implements LayerChangeListener { 29 30 30 31 private final List<RouteLayer> routeLayers = new ArrayList<>(); 31 32 32 33 34 Main.getLayerManager().addLayerChangeListener(this);33 public RoutesPlugin(PluginInformation info) { 34 super(info); 35 MainApplication.getLayerManager().addLayerChangeListener(this); 35 36 36 37 38 Main.info("File with route definitions doesn't exist, using default");37 File routesFile = new File(getPluginDir() + File.separator + "routes.xml"); 38 if (!routesFile.exists()) { 39 Logging.info("File with route definitions doesn't exist, using default"); 39 40 40 41 42 43 44 45 46 47 48 49 50 51 52 53 Main.error(e);54 55 41 try { 42 routesFile.getParentFile().mkdir(); 43 try ( 44 OutputStream outputStream = new FileOutputStream(routesFile); 45 InputStream inputStream = Routes.class.getResourceAsStream("routes.xml"); 46 ) { 47 byte[] b = new byte[512]; 48 int read; 49 while ((read = inputStream.read(b)) != -1) { 50 outputStream.write(b, 0, read); 51 } 52 } 53 } catch (IOException e) { 54 Logging.error(e); 55 } 56 } 56 57 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 58 try { 59 JAXBContext context = JAXBContext.newInstance( 60 Routes.class.getPackage().getName(), Routes.class.getClassLoader()); 61 Unmarshaller unmarshaller = context.createUnmarshaller(); 62 Routes routes = (Routes)unmarshaller.unmarshal( 63 new FileInputStream(getPluginDir() + File.separator + "routes.xml")); 64 for (RoutesXMLLayer layer:routes.getLayer()) { 65 if (layer.isEnabled()) { 66 routeLayers.add(new RouteLayer(layer)); 67 } 68 } 69 } catch (Exception e) { 70 e.printStackTrace(); 71 } 72 } 72 73 73 74 75 74 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 75 // Do nothing 76 } 76 77 77 78 79 80 81 82 83 84 85 86 87 88 89 78 @Override 79 public void layerAdded(LayerAddEvent e) { 80 Layer layer = e.getAddedLayer(); 81 if (layer instanceof OsmDataLayer) { 82 for (RouteLayer routeLayer : routeLayers) { 83 if (!e.getSource().containsLayer(routeLayer)) { 84 SwingUtilities.invokeLater(() -> { 85 e.getSource().addLayer(routeLayer); 86 }); 87 } 88 } 89 } 90 } 90 91 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 92 @Override 93 public void layerRemoving(LayerRemoveEvent e) { 94 for (Layer layer : e.getSource().getLayers()) { 95 if (layer instanceof OsmDataLayer) { 96 return; /* at least one OSM layer left, do nothing */ 97 } 98 } 99 if(!e.isLastLayer()) { 100 SwingUtilities.invokeLater(() -> { 101 for (RouteLayer routeLayer : routeLayers) { 102 if (e.getSource().containsLayer(routeLayer)) { 103 e.getSource().removeLayer(routeLayer); 104 } 105 } 106 }); 107 } 108 } 108 109 109 110 111 112 110 @Override 111 public void layerOrderChanged(LayerOrderChangeEvent e) { 112 // Do nothing 113 } 113 114 }
Note:
See TracChangeset
for help on using the changeset viewer.