Changeset 23189 in osm for applications/editors/josm/plugins/routes/src
- Timestamp:
- 2010-09-15T18:53:09+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/ConvertedWay.java
r17380 r23189 11 11 12 12 public class ConvertedWay { 13 14 public class WayEnd {15 private Node end;16 17 public WayEnd(Node end) {18 this.end = end;19 }20 21 @Override22 public boolean equals(Object o) {23 if (o instanceof WayEnd) {24 WayEnd otherEnd = (WayEnd)o;25 return end.equals(otherEnd.end) && routes.equals(otherEnd.getRoutes());26 } else {27 return false;28 }29 }30 31 @Override32 public int hashCode() {33 return end.hashCode() + routes.hashCode();34 }35 36 public BitSet getRoutes() {37 return routes;38 }39 40 public ConvertedWay getWay() {41 return ConvertedWay.this;42 }43 }44 45 private List<Node> nodes = new ArrayList<Node>();46 private BitSet routes;47 48 public ConvertedWay(BitSet routes, Way way) {49 this.routes = routes;50 nodes.addAll(way.getNodes());51 }52 53 public WayEnd getStart() {54 return new WayEnd(nodes.get(0));55 }56 57 public WayEnd getStop() {58 return new WayEnd(nodes.get(nodes.size() - 1));59 }60 61 /**62 * Connects way to this way. Other ways internal representation is destroyed!!!63 * @param way64 */65 public void connect(ConvertedWay way) {66 for (int i=0; i<2; i++) {67 if (way.nodes.get(0).equals(nodes.get(nodes.size() - 1))) {68 way.nodes.remove(0);69 nodes.addAll(way.nodes);70 return;71 }72 73 if (way.nodes.get(way.nodes.size() - 1).equals(nodes.get(0))) {74 nodes.remove(0);75 way.nodes.addAll(nodes);76 nodes = way.nodes;77 return;78 }79 Collections.reverse(nodes);80 }81 }82 13 83 public List<Node> getNodes() { 84 return nodes; 85 } 14 public class WayEnd { 15 private Node end; 86 16 87 public BitSet getRoutes() { 88 return routes; 89 } 17 public WayEnd(Node end) { 18 this.end = end; 19 } 20 21 @Override 22 public boolean equals(Object o) { 23 if (o instanceof WayEnd) { 24 WayEnd otherEnd = (WayEnd)o; 25 return end.equals(otherEnd.end) && routes.equals(otherEnd.getRoutes()); 26 } else { 27 return false; 28 } 29 } 30 31 @Override 32 public int hashCode() { 33 return end.hashCode() + routes.hashCode(); 34 } 35 36 public BitSet getRoutes() { 37 return routes; 38 } 39 40 public ConvertedWay getWay() { 41 return ConvertedWay.this; 42 } 43 } 44 45 private List<Node> nodes = new ArrayList<Node>(); 46 private BitSet routes; 47 48 public ConvertedWay(BitSet routes, Way way) { 49 this.routes = routes; 50 nodes.addAll(way.getNodes()); 51 } 52 53 public WayEnd getStart() { 54 return new WayEnd(nodes.get(0)); 55 } 56 57 public WayEnd getStop() { 58 return new WayEnd(nodes.get(nodes.size() - 1)); 59 } 60 61 /** 62 * Connects way to this way. Other ways internal representation is destroyed!!! 63 * @param way 64 */ 65 public void connect(ConvertedWay way) { 66 for (int i=0; i<2; i++) { 67 if (way.nodes.get(0).equals(nodes.get(nodes.size() - 1))) { 68 way.nodes.remove(0); 69 nodes.addAll(way.nodes); 70 return; 71 } 72 73 if (way.nodes.get(way.nodes.size() - 1).equals(nodes.get(0))) { 74 nodes.remove(0); 75 way.nodes.addAll(nodes); 76 nodes = way.nodes; 77 return; 78 } 79 Collections.reverse(nodes); 80 } 81 } 82 83 public List<Node> getNodes() { 84 return nodes; 85 } 86 87 public BitSet getRoutes() { 88 return routes; 89 } 90 90 91 91 -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/PathBuilder.java
r19532 r23189 14 14 public class PathBuilder { 15 15 16 17 16 private Map<Way, BitSet> wayRoutes = new HashMap<Way, BitSet>(); 17 private Collection<ConvertedWay> convertedWays; 18 18 19 19 public void addWay(Way way, RouteDefinition route) { 20 20 21 22 23 24 25 26 27 28 21 if (way.getNodesCount() >= 2) { 22 BitSet routes = wayRoutes.get(way); 23 if (routes == null) { 24 routes = new BitSet(); 25 wayRoutes.put(way, routes); 26 } 27 routes.set(route.getIndex()); 28 } 29 29 30 30 } 31 31 32 33 34 32 public Collection<ConvertedWay> getConvertedWays() { 33 if (convertedWays == null) { 34 Map<WayEnd, ConvertedWay> ways = new HashMap<WayEnd, ConvertedWay>(); 35 35 36 37 36 for (Entry<Way, BitSet> wayEntry:wayRoutes.entrySet()) { 37 ConvertedWay way = new ConvertedWay(wayEntry.getValue(), wayEntry.getKey()); 38 38 39 40 39 ConvertedWay wayBefore = ways.get(way.getStart()); 40 ConvertedWay wayAfter = ways.get(way.getStop()); 41 41 42 43 44 45 42 if (wayBefore != null) { 43 removeWay(ways, wayBefore); 44 way.connect(wayBefore); 45 } 46 46 47 48 49 50 47 if (wayAfter != null) { 48 removeWay(ways, wayAfter); 49 way.connect(wayAfter); 50 } 51 51 52 53 54 52 ways.put(way.getStart(), way); 53 ways.put(way.getStop(), way); 54 } 55 55 56 57 58 59 60 61 56 Set<ConvertedWay> uniqueWays = new HashSet<ConvertedWay>(); 57 uniqueWays.addAll(ways.values()); 58 convertedWays = uniqueWays; 59 } 60 return convertedWays; 61 } 62 62 63 64 65 66 63 private void removeWay(Map<WayEnd, ConvertedWay> map, ConvertedWay wayInMap) { 64 map.remove(wayInMap.getStart()); 65 map.remove(wayInMap.getStop()); 66 } 67 67 68 69 70 71 68 public void clear() { 69 convertedWays = null; 70 wayRoutes.clear(); 71 } 72 72 73 73 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RelationEditMode.java
r22046 r23189 21 21 22 22 public class RelationEditMode extends MapMode { 23 23 private static final long serialVersionUID = -7767329767438266289L; 24 24 25 25 private Way highlightedWay; 26 26 27 28 29 30 31 27 public RelationEditMode(MapFrame mapFrame) { 28 super(tr("Edit relation"), "node/autonode", tr("Edit relations"), 29 Shortcut.registerShortcut("mapmode:editRelation", tr("Mode: {0}", tr("Edit relation")), KeyEvent.VK_H, Shortcut.GROUP_EDIT), 30 mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 31 } 32 32 33 34 35 36 37 38 33 @Override 34 public void enterMode() { 35 super.enterMode(); 36 Main.map.mapView.addMouseListener(this); 37 Main.map.mapView.addMouseMotionListener(this); 38 } 39 39 40 41 42 43 44 45 40 @Override 41 public void exitMode() { 42 super.exitMode(); 43 Main.map.mapView.removeMouseListener(this); 44 Main.map.mapView.removeMouseMotionListener(this); 45 } 46 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 47 @Override 48 public void mouseMoved(MouseEvent e) { 49 Way nearestWay = Main.map.mapView.getNearestWay(e.getPoint(), OsmPrimitive.isUsablePredicate); 50 if (nearestWay != highlightedWay) { 51 if (highlightedWay != null) { 52 highlightedWay.setHighlighted(false); 53 } 54 if (nearestWay != null) { 55 nearestWay.setHighlighted(true); 56 } 57 highlightedWay = nearestWay; 58 Main.map.mapView.repaint(); 59 } 60 } 61 61 62 63 64 65 62 @Override 63 public void mouseClicked(MouseEvent e) { 64 if (Main.main.getCurrentDataSet() == null) 65 return; 66 66 67 68 67 Way way = Main.map.mapView.getNearestWay(e.getPoint(), OsmPrimitive.isUsablePredicate); 68 Collection<Relation> selectedRelations = Main.main.getCurrentDataSet().getSelectedRelations(); 69 69 70 70 if (way != null) { 71 71 72 73 74 72 if (selectedRelations.isEmpty()) { 73 JOptionPane.showMessageDialog(Main.parent, tr("No relation is selected")); 74 } 75 75 76 77 78 79 80 81 82 83 84 76 for (OsmPrimitive rel:selectedRelations) { 77 Relation r = (Relation)rel; 78 RelationMember foundMember = null; 79 for (RelationMember member:r.getMembers()) { 80 if (member.getMember() == way) { 81 foundMember = member; 82 break; 83 } 84 } 85 85 86 87 88 89 90 91 92 93 94 95 86 if (foundMember != null) { 87 Main.main.undoRedo.add(new RemoveRelationMemberCommand(r, new RelationMember("", way))); 88 } else { 89 Relation newRelation = new Relation(r); 90 newRelation.addMember(new RelationMember("", way)); 91 Main.main.undoRedo.add(new ChangeCommand(r, newRelation)); 92 } 93 } 94 } 95 } 96 96 97 97 -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteDefinition.java
r19338 r23189 10 10 public class RouteDefinition { 11 11 12 13 14 15 12 private final Color color; 13 private final String matchString; 14 private Match match; 15 private final int index; 16 16 17 18 19 20 21 22 23 24 25 26 27 17 public RouteDefinition(int index, Color color, String expression) { 18 this.color = color; 19 this.matchString = expression; 20 this.index = index; 21 try { 22 match = SearchCompiler.compile(expression, false, false); 23 } catch (ParseError e) { 24 match = new SearchCompiler.Never(); 25 e.printStackTrace(); 26 } 27 } 28 28 29 30 31 29 public boolean matches(OsmPrimitive primitive) { 30 return match.match(primitive); 31 } 32 32 33 34 35 33 public Color getColor() { 34 return color; 35 } 36 36 37 38 39 37 public int getIndex() { 38 return index; 39 } 40 40 41 42 43 44 41 @Override 42 public String toString() { 43 return color.toString() + " " + matchString; 44 } 45 45 46 46 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteLayer.java
r22549 r23189 33 33 public class RouteLayer extends Layer implements DataSetListenerAdapter.Listener { 34 34 35 36 37 38 35 private final PathPainter pathPainter; 36 private final PathBuilder pathBuilder = new PathBuilder(); 37 private final List<RouteDefinition> routes = new ArrayList<RouteDefinition>(); 38 private volatile boolean datasetChanged = true; 39 39 40 41 40 public RouteLayer(RoutesXMLLayer xmlLayer) { 41 super(xmlLayer.getName()); 42 42 43 44 45 46 47 48 49 50 51 52 53 43 int index = 0; 44 for (RoutesXMLRoute route:xmlLayer.getRoute()) { 45 if (route.isEnabled()) { 46 Color color = ColorHelper.html2color(route.getColor()); 47 if (color == null) { 48 color = Color.RED; 49 System.err.printf("Routes plugin - unable to convert color (%s)\n", route.getColor()); 50 } 51 routes.add(new RouteDefinition(index++, color, route.getPattern())); 52 } 53 } 54 54 55 56 57 58 59 55 if ("wide".equals(Main.pref.get("routes.painter"))) { 56 pathPainter = new WideLinePainter(this); 57 } else { 58 pathPainter = new NarrowLinePainter(this); 59 } 60 60 61 62 61 DatasetEventManager.getInstance().addDatasetListener(new DataSetListenerAdapter(this), FireMode.IMMEDIATELY); 62 } 63 63 64 65 66 67 64 @Override 65 public Icon getIcon() { 66 return ImageProvider.get("layer", "osmdata_small"); 67 } 68 68 69 70 71 72 69 @Override 70 public Object getInfoComponent() { 71 return null; 72 } 73 73 74 75 76 77 74 @Override 75 public Action[] getMenuEntries() { 76 return new Action[0]; 77 } 78 78 79 80 81 82 79 @Override 80 public String getToolTipText() { 81 return "Hiking routes"; 82 } 83 83 84 85 86 87 84 @Override 85 public boolean isMergable(Layer other) { 86 return false; 87 } 88 88 89 90 91 92 89 @Override 90 public void mergeFrom(Layer from) { 91 // Merging is not supported 92 } 93 93 94 95 96 97 98 99 100 101 94 private void addRelation(Relation relation, RouteDefinition route) { 95 for (RelationMember member:relation.getMembers()) { 96 if (member.getMember() instanceof Way) { 97 Way way = (Way)member.getMember(); 98 pathBuilder.addWay(way, route); 99 } 100 } 101 } 102 102 103 104 103 @Override 104 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 105 105 106 106 DataSet dataset = Main.main.getCurrentDataSet(); 107 107 108 109 110 108 if (dataset == null) { 109 return; 110 } 111 111 112 113 114 112 if (datasetChanged) { 113 datasetChanged = false; 114 pathBuilder.clear(); 115 115 116 117 118 119 120 121 122 116 for (Relation relation:dataset.getRelations()) { 117 for (RouteDefinition route:routes) { 118 if (route.matches(relation)) { 119 addRelation(relation, route); 120 } 121 } 122 } 123 123 124 125 126 127 128 129 130 131 124 for (Way way:dataset.getWays()) { 125 for (RouteDefinition route:routes) { 126 if (route.matches(way)) { 127 pathBuilder.addWay(way, route); 128 } 129 } 130 } 131 } 132 132 133 134 135 136 137 138 139 133 Stroke stroke = g.getStroke(); 134 Color color = g.getColor(); 135 for (ConvertedWay way:pathBuilder.getConvertedWays()) { 136 pathPainter.drawWay(way, mv, g); 137 } 138 g.setStroke(stroke); 139 g.setColor(color); 140 140 141 141 } 142 142 143 144 143 @Override 144 public void visitBoundingBox(BoundingXYVisitor v) { 145 145 146 146 } 147 147 148 149 150 148 public List<RouteDefinition> getRoutes() { 149 return routes; 150 } 151 151 152 153 154 152 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 153 datasetChanged = true; 154 } 155 155 156 156 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RoutesPlugin.java
r19473 r23189 26 26 27 27 public class RoutesPlugin extends Plugin implements LayerChangeListener { 28 28 29 29 private final List<RouteLayer> routeLayers = new ArrayList<RouteLayer>(); 30 30 private boolean isShown; 31 31 32 32 public RoutesPlugin(PluginInformation info) { 33 34 35 33 super(info); 34 MapView.addLayerChangeListener(this); 35 36 36 File routesFile = new File(getPluginDir() + File.separator + "routes.xml"); 37 37 if (!routesFile.exists()) { 38 38 System.out.println("File with route definitions doesn't exist, using default"); 39 39 40 40 try { 41 41 routesFile.getParentFile().mkdir(); 42 42 OutputStream outputStream = new FileOutputStream(routesFile); 43 43 InputStream inputStream = Routes.class.getResourceAsStream("routes.xml"); 44 45 byte[] b = new byte[512]; 46 int read; 47 while ((read = inputStream.read(b)) != -1) { 44 45 byte[] b = new byte[512]; 46 int read; 47 while ((read = inputStream.read(b)) != -1) { 48 48 outputStream.write(b, 0, read); 49 49 } 50 51 outputStream.close(); 50 51 outputStream.close(); 52 52 inputStream.close(); 53 53 54 54 } catch (IOException e) { 55 55 e.printStackTrace(); 56 56 } 57 57 } 58 58 59 59 try { 60 60 JAXBContext context = JAXBContext.newInstance( … … 64 64 new FileInputStream(getPluginDir() + File.separator + "routes.xml")); 65 65 for (RoutesXMLLayer layer:routes.getLayer()) { 66 67 68 66 if (layer.isEnabled()) { 67 routeLayers.add(new RouteLayer(layer)); 68 } 69 69 } 70 70 } catch (Exception e) { 71 71 e.printStackTrace(); 72 } 72 } 73 73 74 74 //new RelationEditMode(Main.map); … … 77 77 78 78 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 79 // TODO Auto-generated method stub 79 // TODO Auto-generated method stub 80 80 } 81 81 82 82 private void checkLayers() { 83 83 if (Main.map != null && Main.map.mapView != null) { … … 91 91 Main.main.addLayer(routeLayer); 92 92 } 93 } 93 } 94 94 }); 95 95 } 96 96 return; 97 } 97 } 98 98 } 99 99 if (isShown) { … … 104 104 Main.main.removeLayer(routeLayer); 105 105 } 106 } 106 } 107 107 }); 108 108 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/AbstractLinePainter.java
r22590 r23189 17 17 public abstract class AbstractLinePainter implements PathPainter { 18 18 19 20 21 22 23 24 25 26 27 28 29 30 31 19 // Following two method copied from http://blog.persistent.info/2004/03/java-lineline-intersections.html 20 protected boolean getLineLineIntersection(Line2D.Double l1, 21 Line2D.Double l2, 22 Point intersection) 23 { 24 double x1 = l1.getX1(), y1 = l1.getY1(), 25 x2 = l1.getX2(), y2 = l1.getY2(), 26 x3 = l2.getX1(), y3 = l2.getY1(), 27 x4 = l2.getX2(), y4 = l2.getY2(); 28 double dx1 = x2 - x1; 29 double dx2 = x4 - x3; 30 double dy1 = y2 - y1; 31 double dy2 = y4 - y3; 32 32 33 33 double ua = (dx2 * (y1 - y3) - dy2 * (x1 - x3)) / (dy2 * dx1 - dx2 * dy1); 34 34 35 36 37 38 39 40 41 42 35 if (Math.abs(dy2 * dx1 - dx2 * dy1) < 0.0001) { 36 intersection.x = (int)l1.x2; 37 intersection.y = (int)l1.y2; 38 return false; 39 } else { 40 intersection.x = (int)(x1 + ua * (x2 - x1)); 41 intersection.y = (int)(y1 + ua * (y2 - y1)); 42 } 43 43 44 45 44 return true; 45 } 46 46 47 48 49 50 47 protected double det(double a, double b, double c, double d) 48 { 49 return a * d - b * c; 50 } 51 51 52 53 54 52 protected Point shiftPoint(Point2D p1, Point2D p2, double shift) { 53 double dx = p2.getX() - p1.getX(); 54 double dy = p2.getY() - p1.getY(); 55 55 56 57 58 56 // Perpendicular vector 57 double ndx = -dy; 58 double ndy = dx; 59 59 60 61 62 63 60 // Normalize 61 double length = Math.sqrt(ndx * ndx + ndy * ndy); 62 ndx = ndx / length; 63 ndy = ndy / length; 64 64 65 66 65 return new Point((int)(p1.getX() + shift * ndx), (int)(p1.getY() + shift * ndy)); 66 } 67 67 68 69 70 68 protected Line2D.Double shiftLine(Point2D p1, Point2D p2, double shift) { 69 double dx = p2.getX() - p1.getX(); 70 double dy = p2.getY() - p1.getY(); 71 71 72 73 72 Point2D point1 = shiftPoint(p1, p2, shift); 73 Point2D point2 = new Point2D.Double(point1.getX() + dx, point1.getY() + dy); 74 74 75 76 77 75 return new Line2D.Double( 76 point1, point2); 77 } 78 78 79 79 protected GeneralPath getPath(Graphics2D g, MapView mapView, List<Node> nodes, double shift) { 80 80 81 81 GeneralPath path = new GeneralPath(); 82 82 83 84 85 83 if (nodes.size() < 2) { 84 return path; 85 } 86 86 87 88 89 90 87 Point p1 = null; 88 Point p2 = null; 89 Point p3 = null; 90 Point lastPoint = null; 91 91 92 93 92 for (Node n: nodes) { 93 Point p = mapView.getPoint(n); 94 94 95 96 97 98 99 100 101 95 if (!p.equals(p3)) { 96 p1 = p2; 97 p2 = p3; 98 p3 = p; 99 } else { 100 continue; 101 } 102 102 103 104 105 106 107 108 109 103 p = null; 104 if (p2 != null) { 105 if (p1 == null) { 106 p = shiftPoint(p2, p3, shift); 107 } else { 108 Line2D.Double line1 = shiftLine(p1, p2, shift); 109 Line2D.Double line2 = shiftLine(p2, p3, shift); 110 110 111 112 113 114 111 /*path.moveTo((float)line1.x1, (float)line1.y1); 112 path.lineTo((float)line1.x2, (float)line1.y2); 113 path.moveTo((float)line2.x1, (float)line2.y1); 114 path.lineTo((float)line2.x2, (float)line2.y2);*/ 115 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 116 p = new Point(); 117 if (!getLineLineIntersection(line1, line2, p)) { 118 p = null; 119 } else { 120 int dx = p.x - p2.x; 121 int dy = p.y - p2.y; 122 int distance = (int)Math.sqrt(dx * dx + dy * dy); 123 if (distance > 10) { 124 p.x = p2.x + dx / (distance / 10); 125 p.y = p2.y + dy / (distance / 10); 126 } 127 } 128 } 129 } 130 130 131 132 133 134 135 136 137 131 if (p != null && lastPoint != null) { 132 drawSegment(g, mapView, path, lastPoint, p); 133 } 134 if (p != null) { 135 lastPoint = p; 136 } 137 } 138 138 139 140 141 142 139 if (p2 != null && p3 != null && lastPoint != null) { 140 p3 = shiftPoint(p3, p2, -shift); 141 drawSegment(g, mapView, path, lastPoint, p3); 142 } 143 143 144 145 144 return path; 145 } 146 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 147 private void drawSegment(Graphics2D g, NavigatableComponent nc, GeneralPath path, Point p1, Point p2) { 148 boolean drawIt = false; 149 if (Main.isOpenjdk) { 150 /** 151 * Work around openjdk bug. It leads to drawing artefacts when zooming in a lot. (#4289, #4424) 152 * (It looks like int overflow when clipping.) We do custom clipping. 153 */ 154 Rectangle bounds = g.getClipBounds(); 155 bounds.grow(100, 100); // avoid arrow heads at the border 156 LineClip clip = new LineClip(); 157 drawIt = clip.cohenSutherland(p1.x, p1.y, p2.x, p2.y, bounds.x, bounds.y, bounds.x+bounds.width, bounds.y+bounds.height); 158 if (drawIt) { 159 p1 = clip.getP1(); 160 p2 = clip.getP2(); 161 } 162 } else { 163 drawIt = isSegmentVisible(nc, p1, p2); 164 } 165 if (drawIt) { 166 /* draw segment line */ 167 path.moveTo(p1.x, p1.y); 168 path.lineTo(p2.x, p2.y); 169 } 170 } 171 171 172 173 174 175 176 177 178 172 private boolean isSegmentVisible(NavigatableComponent nc, Point p1, Point p2) { 173 if ((p1.x < 0) && (p2.x < 0)) return false; 174 if ((p1.y < 0) && (p2.y < 0)) return false; 175 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false; 176 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false; 177 return true; 178 } 179 179 180 180 -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/NarrowLinePainter.java
r21174 r23189 14 14 public class NarrowLinePainter extends AbstractLinePainter { 15 15 16 17 16 private static final float LINE_WIDTH = 5; 17 private final RouteLayer layer; 18 18 19 20 21 19 public NarrowLinePainter(RouteLayer layer) { 20 this.layer = layer; 21 } 22 22 23 24 25 23 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g) { 24 List<Node> nodes = way.getNodes(); 25 BitSet routes = way.getRoutes(); 26 26 27 28 29 27 if (nodes.size() < 2) { 28 return; 29 } 30 30 31 32 33 34 35 31 //double totalWidth = LINE_WIDTH + (colors.size() - 1) * 4; 32 //double width = totalWidth / colors.size(); 33 //double shift = -totalWidth / 2 + width / 2; 34 double width = LINE_WIDTH; 35 double shift = - (LINE_WIDTH * routes.cardinality()) / 2 + width / 2; 36 36 37 37 for (int k=0; k<routes.length(); k++) { 38 38 39 40 41 39 if (!routes.get(k)) { 40 continue; 41 } 42 42 43 43 RouteDefinition route = layer.getRoutes().get(k); 44 44 45 46 45 g.setColor(route.getColor()); 46 g.setStroke(new BasicStroke((float) width)); 47 47 48 48 g.draw(getPath(g, mapView, nodes, shift)); 49 49 50 51 52 50 shift += width + 2; 51 } 52 } 53 53 54 54 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/PathPainter.java
r16428 r23189 7 7 8 8 public interface PathPainter { 9 10 9 10 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g); 11 11 12 12 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/WideLinePainter.java
r21174 r23189 15 15 public class WideLinePainter extends AbstractLinePainter { 16 16 17 18 17 private static final float LINE_WIDTH = 10; 18 private final RouteLayer layer; 19 19 20 21 22 20 public WideLinePainter(RouteLayer layer) { 21 this.layer = layer; 22 } 23 23 24 25 26 24 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g) { 25 List<Node> nodes = way.getNodes(); 26 BitSet routes = way.getRoutes(); 27 27 28 29 30 28 if (nodes.size() < 2) { 29 return; 30 } 31 31 32 33 34 32 double totalWidth = LINE_WIDTH + (routes.size() - 1) * 4; 33 double width = totalWidth / routes.cardinality(); 34 double shift = -totalWidth / 2 + width / 2; 35 35 36 36 for (int k=0; k<routes.length(); k++) { 37 37 38 39 40 38 if (!routes.get(k)) { 39 continue; 40 } 41 41 42 42 RouteDefinition route = layer.getRoutes().get(k); 43 43 44 45 46 44 Color color = route.getColor(); 45 g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); 46 g.setStroke(new BasicStroke((float) width)); 47 47 48 48 g.draw(getPath(g, mapView, nodes, shift)); 49 49 50 51 52 50 shift += width; 51 } 52 } 53 53 54 54 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/ObjectFactory.java
r16593 r23189 1 1 // 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 6 6 // 7 7 … … 13 13 14 14 /** 15 * This object contains factory methods for each 16 * Java content interface and Java element interface 17 * generated in the org.openstreetmap.josm.plugins.routes.xml package. 18 * <p>An ObjectFactory allows you to programatically 19 * construct new instances of the Java representation 20 * for XML content. The Java representation of XML 21 * content can consist of schema derived interfaces 22 * and classes representing the binding of schema 23 * type definitions, element declarations and model 24 * groups. Factory methods for each of these are 15 * This object contains factory methods for each 16 * Java content interface and Java element interface 17 * generated in the org.openstreetmap.josm.plugins.routes.xml package. 18 * <p>An ObjectFactory allows you to programatically 19 * construct new instances of the Java representation 20 * for XML content. The Java representation of XML 21 * content can consist of schema derived interfaces 22 * and classes representing the binding of schema 23 * type definitions, element declarations and model 24 * groups. Factory methods for each of these are 25 25 * provided in this class. 26 * 26 * 27 27 */ 28 28 @XmlRegistry … … 32 32 /** 33 33 * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.openstreetmap.josm.plugins.routes.xml 34 * 34 * 35 35 */ 36 36 public ObjectFactory() { … … 39 39 /** 40 40 * Create an instance of {@link RoutesXMLRoute } 41 * 41 * 42 42 */ 43 43 public RoutesXMLRoute createRoutesXMLRoute() { … … 47 47 /** 48 48 * Create an instance of {@link RoutesXMLLayer } 49 * 49 * 50 50 */ 51 51 public RoutesXMLLayer createRoutesXMLLayer() { … … 55 55 /** 56 56 * Create an instance of {@link Routes } 57 * 57 * 58 58 */ 59 59 public Routes createRoutes() { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/Routes.java
r16593 r23189 1 1 // 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 6 6 // 7 7 … … 19 19 /** 20 20 * <p>Java class for anonymous complex type. 21 * 21 * 22 22 * <p>The following schema fragment specifies the expected content contained within this class. 23 * 23 * 24 24 * <pre> 25 25 * <complexType> … … 33 33 * </complexType> 34 34 * </pre> 35 * 36 * 35 * 36 * 37 37 */ 38 38 @XmlAccessorType(XmlAccessType.FIELD) … … 47 47 /** 48 48 * Gets the value of the layer property. 49 * 49 * 50 50 * <p> 51 51 * This accessor method returns a reference to the live list, … … 53 53 * returned list will be present inside the JAXB object. 54 54 * This is why there is not a <CODE>set</CODE> method for the layer property. 55 * 55 * 56 56 * <p> 57 57 * For example, to add a new item, do as follows: … … 59 59 * getLayer().add(newItem); 60 60 * </pre> 61 * 62 * 61 * 62 * 63 63 * <p> 64 64 * Objects of the following type(s) are allowed in the list 65 65 * {@link RoutesXMLLayer } 66 * 67 * 66 * 67 * 68 68 */ 69 69 public List<RoutesXMLLayer> getLayer() { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/RoutesXMLLayer.java
r16593 r23189 1 1 // 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 6 6 // 7 7 … … 19 19 /** 20 20 * <p>Java class for layer complex type. 21 * 21 * 22 22 * <p>The following schema fragment specifies the expected content contained within this class. 23 * 23 * 24 24 * <pre> 25 25 * <complexType name="layer"> … … 35 35 * </complexType> 36 36 * </pre> 37 * 38 * 37 * 38 * 39 39 */ 40 40 @XmlAccessorType(XmlAccessType.FIELD) … … 52 52 /** 53 53 * Gets the value of the route property. 54 * 54 * 55 55 * <p> 56 56 * This accessor method returns a reference to the live list, … … 58 58 * returned list will be present inside the JAXB object. 59 59 * This is why there is not a <CODE>set</CODE> method for the route property. 60 * 60 * 61 61 * <p> 62 62 * For example, to add a new item, do as follows: … … 64 64 * getRoute().add(newItem); 65 65 * </pre> 66 * 67 * 66 * 67 * 68 68 * <p> 69 69 * Objects of the following type(s) are allowed in the list 70 70 * {@link RoutesXMLRoute } 71 * 72 * 71 * 72 * 73 73 */ 74 74 public List<RoutesXMLRoute> getRoute() { … … 81 81 /** 82 82 * Gets the value of the name property. 83 * 83 * 84 84 * @return 85 85 * possible object is 86 86 * {@link String } 87 * 87 * 88 88 */ 89 89 public String getName() { … … 93 93 /** 94 94 * Sets the value of the name property. 95 * 95 * 96 96 * @param value 97 97 * allowed object is 98 98 * {@link String } 99 * 99 * 100 100 */ 101 101 public void setName(String value) { … … 105 105 /** 106 106 * Gets the value of the enabled property. 107 * 107 * 108 108 * @return 109 109 * possible object is 110 110 * {@link Boolean } 111 * 111 * 112 112 */ 113 113 public boolean isEnabled() { … … 121 121 /** 122 122 * Sets the value of the enabled property. 123 * 123 * 124 124 * @param value 125 125 * allowed object is 126 126 * {@link Boolean } 127 * 127 * 128 128 */ 129 129 public void setEnabled(Boolean value) { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/RoutesXMLRoute.java
r16593 r23189 1 1 // 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 6 6 // 7 7 … … 18 18 /** 19 19 * <p>Java class for route complex type. 20 * 20 * 21 21 * <p>The following schema fragment specifies the expected content contained within this class. 22 * 22 * 23 23 * <pre> 24 24 * <complexType name="route"> … … 34 34 * </complexType> 35 35 * </pre> 36 * 37 * 36 * 37 * 38 38 */ 39 39 @XmlAccessorType(XmlAccessType.FIELD) … … 52 52 /** 53 53 * Gets the value of the pattern property. 54 * 54 * 55 55 * @return 56 56 * possible object is 57 57 * {@link String } 58 * 58 * 59 59 */ 60 60 public String getPattern() { … … 64 64 /** 65 65 * Sets the value of the pattern property. 66 * 66 * 67 67 * @param value 68 68 * allowed object is 69 69 * {@link String } 70 * 70 * 71 71 */ 72 72 public void setPattern(String value) { … … 76 76 /** 77 77 * Gets the value of the color property. 78 * 78 * 79 79 * @return 80 80 * possible object is 81 81 * {@link String } 82 * 82 * 83 83 */ 84 84 public String getColor() { … … 88 88 /** 89 89 * Sets the value of the color property. 90 * 90 * 91 91 * @param value 92 92 * allowed object is 93 93 * {@link String } 94 * 94 * 95 95 */ 96 96 public void setColor(String value) { … … 100 100 /** 101 101 * Gets the value of the enabled property. 102 * 102 * 103 103 * @return 104 104 * possible object is 105 105 * {@link Boolean } 106 * 106 * 107 107 */ 108 108 public boolean isEnabled() { … … 116 116 /** 117 117 * Sets the value of the enabled property. 118 * 118 * 119 119 * @param value 120 120 * allowed object is 121 121 * {@link Boolean } 122 * 122 * 123 123 */ 124 124 public void setEnabled(Boolean value) { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/package-info.java
r16593 r23189 1 1 // 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 2 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 3 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 4 // Any modifications to this file will be lost upon recompilation of the source schema. 5 // Generated on: 2009.07.19 at 03:50:48 odp. CEST 6 6 // 7 7
Note:
See TracChangeset
for help on using the changeset viewer.