Changeset 3828 in osm for applications/editors/josm/plugins
- Timestamp:
- 2007-07-29T01:01:21+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/navigator/src/at/dallermassl/josm/plugin/navigator/NavigatorLayer.java
r3749 r3828 4 4 package at.dallermassl.josm.plugin.navigator; 5 5 6 import java.awt.BasicStroke; 7 import java.awt.Color; 6 8 import java.awt.Component; 7 9 import java.awt.Graphics; 10 import java.awt.Graphics2D; 8 11 import java.awt.Point; 12 import java.awt.Rectangle; 13 import java.awt.geom.Line2D; 9 14 import java.util.List; 10 15 … … 16 21 import org.openstreetmap.josm.gui.MapView; 17 22 import org.openstreetmap.josm.gui.layer.Layer; 23 import org.openstreetmap.josm.tools.ColorHelper; 18 24 import org.openstreetmap.josm.tools.ImageProvider; 19 25 … … 25 31 */ 26 32 public class NavigatorLayer extends Layer { 33 private static final String KEY_ROUTE_COLOR = "color.navigator.route"; 34 private static final String KEY_ROUTE_WIDTH = "navigator.route.width"; 35 private static final String KEY_ROUTE_SELECT = "navigator.route.select"; 36 protected static final double ARROW_PHI = Math.toRadians(20); 27 37 private NavigatorModel navigatorNodeModel; 28 38 private Icon startIcon; … … 137 147 endIcon.paintIcon(mv, g, screen.x, screen.y - endIcon.getIconHeight()); 138 148 } 139 140 List<Segment> path = navigatorNodeModel.getSegmentPath(); 141 if(path != null) { 142 synchronized(path) { 143 // TODO paint path 149 150 Main.pref.hasKey(KEY_ROUTE_COLOR); 151 String selectString = Main.pref.get(KEY_ROUTE_SELECT); 152 if(selectString.length() == 0) { 153 selectString = "true"; 154 Main.pref.put(KEY_ROUTE_SELECT, selectString); 155 } 156 157 if(Boolean.parseBoolean(selectString)) { 158 List<Segment> path = navigatorNodeModel.getSegmentPath(); 159 if(path != null) { 160 synchronized(path) { 161 Main.ds.setSelected(path); 162 // Main.map.mapView.repaint(); 163 } 144 164 } 145 165 } 146 } 166 167 String colorString = Main.pref.get(KEY_ROUTE_COLOR); 168 if(colorString.length() == 0) { 169 colorString = ColorHelper.color2html(Color.GREEN); 170 // FIXXME add after good color is found: Main.pref.put(KEY_ROUTE_COLOR, colorString); 171 } 172 Color color = ColorHelper.html2color(colorString); 173 174 String widthString = Main.pref.get(KEY_ROUTE_WIDTH); 175 if(widthString.length() == 0) { 176 widthString = "5"; 177 // FIXXME add after good width is found: Main.pref.put(KEY_ROUTE_WIDTH, widthString); 178 } 179 int width = Integer.parseInt(widthString); 180 181 List<SegmentEdge>edgePath = navigatorNodeModel.getEdgePath(); 182 if(edgePath != null) { 183 for(SegmentEdge edge : edgePath) { 184 drawSegmentEdge(g, mv, edge, color, width, true); 185 } 186 } 187 } 188 189 /** 190 * Draw a line with the given color. 191 */ 192 protected void drawSegmentEdge(Graphics g, MapView mv, SegmentEdge edge, Color col, int width, boolean showDirection) { 193 g.setColor(col); 194 Point from; 195 Point to; 196 if(!edge.isInverted()) { 197 from = mv.getPoint(edge.getSegment().from.eastNorth); 198 to = mv.getPoint(edge.getSegment().to.eastNorth); 199 } else { 200 from = mv.getPoint(edge.getSegment().to.eastNorth); 201 to = mv.getPoint(edge.getSegment().from.eastNorth); 202 } 203 204 Rectangle screen = g.getClipBounds(); 205 Line2D line = new Line2D.Double(from.x, from.y, to.x, to.y); 206 if (screen.contains(from.x, from.y, to.x, to.y) || screen.intersectsLine(line)) 207 { 208 Graphics2D g2d = (Graphics2D)g; 209 g2d.setStroke(new BasicStroke(width)); // thickness 210 g.drawLine(from.x, from.y, to.x, to.y); 211 if (showDirection) { 212 double t = Math.atan2(to.y-from.y, to.x-from.x) + Math.PI; 213 g.drawLine(to.x,to.y, (int)(to.x + 10*Math.cos(t-ARROW_PHI)), (int)(to.y + 10*Math.sin(t-ARROW_PHI))); 214 g.drawLine(to.x,to.y, (int)(to.x + 10*Math.cos(t+ARROW_PHI)), (int)(to.y + 10*Math.sin(t+ARROW_PHI))); 215 } 216 } 217 } 218 147 219 148 220 /*
Note:
See TracChangeset
for help on using the changeset viewer.