Changeset 4423 in osm for applications/editors/josm
- Timestamp:
- 2007-09-03T00:23:03+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mappaint/src/mappaint/MapPaintVisitor.java
r3621 r4423 10 10 import java.awt.Point; 11 11 import java.awt.Polygon; 12 import java.awt.Stroke; 13 import java.awt.geom.GeneralPath; 12 14 13 15 import javax.swing.ImageIcon; … … 21 23 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 22 24 23 import java.awt.event.MouseEvent;24 25 26 25 /** 27 26 * A visitor that paints the OSM components in a map-like style. … … 30 29 public class MapPaintVisitor extends SimplePaintVisitor { 31 30 31 protected boolean useRealWidth; 32 protected boolean zoomLevelDisplay; 33 protected boolean fillAreas; 34 protected Color untaggedColor; 35 protected Color textColor; 36 protected boolean currentDashed = false; 37 protected int currentWidth = 0; 38 protected Stroke currentStroke = null; 39 protected static final Font orderFont = new Font("Helvetica", Font.PLAIN, 8); 40 32 41 protected boolean isZoomOk(ElemStyle e) { 33 42 double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 34 43 35 44 /* show everything, if the user wishes so */ 36 if(! Main.pref.getBoolean("mappaint.zoomLevelDisplay",false)) {45 if(!zoomLevelDisplay) { 37 46 return true; 38 47 } … … 81 90 } 82 91 } else { 83 drawNode(n, n.selected ? getPreferencesColor("selected", 84 Color.YELLOW) 85 : getPreferencesColor("node", Color.RED)); 92 drawNode(n, n.selected ? selectedColor : nodeColor); 86 93 } 87 94 } … … 95 102 ElemStyle segmentStyle = MapPaintPlugin.elemStyles.getStyle(ls); 96 103 if(isZoomOk(segmentStyle)) { 97 drawSegment(ls, getPreferencesColor("untagged",Color.GRAY),Main.pref.getBoolean("draw.segment.direction"));104 drawSegment(ls, untaggedColor, showDirectionArrow); 98 105 } 99 106 } … … 106 113 @Override public void visit(Way w) { 107 114 double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 108 boolean showDirection = Main.pref.getBoolean("draw.segment.direction");109 if ( Main.pref.getBoolean("mappaint.useRealWidth",false)&& showDirection && !w.selected) showDirection = false;110 Color colour = getPreferencesColor("untagged",Color.GRAY);115 boolean showDirection = showDirectionArrow ; 116 if (useRealWidth && showDirection && !w.selected) showDirection = false; 117 Color colour = untaggedColor; 111 118 int width = 2; 112 119 int realWidth = 0; //the real width of the element in meters … … 134 141 } 135 142 } 136 boolean fillAreas = Main.pref.getBoolean("mappaint.fillareas", true);137 143 138 144 if (area && fillAreas) … … 144 150 if (area && fillAreas) 145 151 //Draw segments in a different colour so direction arrows show against the fill 146 drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW) : getPreferencesColor("untagged",Color.GRAY),showDirection, width,true);152 drawSegment(ls, w.selected ? selectedColor : untaggedColor, showDirection, width,true); 147 153 else 148 154 if (area) 149 drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW) : colour,showDirection, width,true);155 drawSegment(ls, w.selected ? selectedColor : colour, showDirection, width,true); 150 156 else 151 if (realWidth > 0 && Main.pref.getBoolean("mappaint.useRealWidth",false)&& !showDirection){157 if (realWidth > 0 && useRealWidth && !showDirection){ 152 158 int tmpWidth = (int) (100 / (float) (circum / realWidth)); 153 159 if (tmpWidth > width) width = tmpWidth; 154 160 } 155 161 156 drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.YELLOW): colour,showDirection, width,dashed);157 if (!ls.incomplete && Main.pref.getBoolean("draw.segment.order_number"))162 drawSegment(ls, w.selected ? selectedColor : colour,showDirection, width,dashed); 163 if (!ls.incomplete && showOrderNumber) 158 164 { 159 165 try 160 166 { 161 g.setColor(w.selected ? getPreferencesColor("selected", Color.YELLOW): colour);167 g.setColor(w.selected ? selectedColor : colour); 162 168 drawOrderNumber(ls, orderNumber); 163 169 } … … 187 193 188 194 g.setColor( w.selected ? 189 getPreferencesColor("selected", Color.YELLOW): colour);195 selectedColor : colour); 190 196 191 197 g.fillPolygon(polygon); … … 201 207 if (name!=null && annotate) 202 208 { 203 g.setColor( getPreferencesColor ("text", Color.WHITE));209 g.setColor(textColor); 204 210 Font defaultFont = g.getFont(); 205 g.setFont ( new Font("Helvetica", Font.PLAIN, 8));211 g.setFont (orderFont); 206 212 g.drawString (name, p.x+w/2+2, p.y+h/2+2); 207 213 g.setFont(defaultFont); … … 209 215 if (n.selected) 210 216 { 211 g.setColor ( getPreferencesColor("selected", Color.YELLOW));217 g.setColor ( selectedColor ); 212 218 g.drawRect (p.x-w/2-2,p.y-w/2-2, w+4, h+4); 213 219 } … … 219 225 // Altered - now specify width 220 226 @Override protected void drawSegment(Segment ls, Color col,boolean showDirection) { 221 if ( Main.pref.getBoolean("mappaint.useRealWidth",false)&& showDirection && !ls.selected) showDirection = false;227 if (useRealWidth && showDirection && !ls.selected) showDirection = false; 222 228 drawSegment(ls,col,showDirection,1,false); 223 229 } … … 231 237 if (ls.incomplete) 232 238 return; 239 if (ls.selected) { 240 col = selectedColor; 241 } 242 drawSeg(ls, col, showDirection, width, dashed); 243 } 244 245 private void drawSeg(Segment ls, Color col,boolean showDirection, int width,boolean dashed) { 246 if (col != currentColor || width != currentWidth || dashed != currentDashed) { 247 displaySegments(col, width, dashed); 248 } 233 249 Point p1 = nc.getPoint(ls.from.eastNorth); 234 250 Point p2 = nc.getPoint(ls.to.eastNorth); … … 239 255 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return ; 240 256 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return ; 241 Graphics2D g2d = (Graphics2D)g; 242 if (ls.selected) 243 col = getPreferencesColor("selected", Color.YELLOW); 244 g.setColor(col); 257 //if (ls.selected) 258 // col = selectedColor; 259 //g.setColor(col); 245 260 //g.setWidth(width); 246 if (dashed) 247 g2d.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {9},0)); 248 else 249 g2d.setStroke(new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 250 251 g.drawLine(p1.x, p1.y, p2.x, p2.y); 261 //if (dashed) 262 // g2d.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {9},0)); 263 //else 264 // g2d.setStroke(new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 265 266 //g.drawLine(p1.x, p1.y, p2.x, p2.y); 267 currrentPath.moveTo(p1.x, p1.y); 268 currrentPath.lineTo(p2.x, p2.y); 252 269 253 270 if (showDirection) { 254 271 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 255 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 256 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 257 } 258 g2d.setStroke(new BasicStroke(1)); 259 260 } 261 272 //g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 273 //g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 274 currrentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 275 currrentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 276 currrentPath.lineTo(p2.x, p2.y); 277 } 278 //g2d.setStroke(new BasicStroke(1)); 279 280 } 281 282 protected void displaySegments() { 283 displaySegments(null, 0, false); 284 } 285 286 protected void displaySegments(Color newColor, int newWidth, boolean newDash) { 287 288 if (currrentPath != null) { 289 Graphics2D g2d = (Graphics2D)g; 290 g2d.setColor(currentColor); 291 if (currentStroke == null) { 292 if (currentDashed) 293 g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {9},0)); 294 else 295 g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 296 } 297 g2d.draw(currrentPath); 298 g2d.setStroke(new BasicStroke(1)); 299 300 currrentPath = new GeneralPath(); 301 currentColor = newColor; 302 currentWidth = newWidth; 303 currentDashed = newDash; 304 currentStroke = null; 305 } 306 } 262 307 263 308 /** … … 279 324 // Shows areas before non-areas 280 325 public void visitAll(DataSet data) { 326 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY); 327 selectedColor = getPreferencesColor("selected", Color.YELLOW); 328 nodeColor = getPreferencesColor("node", Color.RED); 329 segmentColor = getPreferencesColor("segment", darkgreen); 330 dfltWayColor = getPreferencesColor("way", darkblue); 331 incompleteColor = getPreferencesColor("incomplete way", darkerblue); 332 backgroundColor = getPreferencesColor("background", Color.BLACK); 333 untaggedColor = getPreferencesColor("untagged",Color.GRAY); 334 textColor = getPreferencesColor ("text", Color.WHITE); 335 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction"); 336 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number"); 337 useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false); 338 zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false); 339 fillAreas = Main.pref.getBoolean("mappaint.fillareas", true); 281 340 282 341 Collection<Way> noAreaWays = new LinkedList<Way>(); … … 308 367 osm.visit(this); 309 368 } 369 displaySegments(); 310 370 } 311 371 }
Note:
See TracChangeset
for help on using the changeset viewer.