Changeset 2659 in josm
- Timestamp:
- 2009-12-19T18:12:03+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r2603 r2659 11 11 import java.awt.Font; 12 12 import java.awt.FontMetrics; 13 import java.awt.Graphics2D;14 13 import java.awt.Image; 15 14 import java.awt.Point; … … 92 91 public ElemStyle getPrimitiveStyle(OsmPrimitive osm) { 93 92 if(!useStyleCache) 94 return ( styles != null) ? styles.get(osm) : null;95 96 97 98 99 100 101 102 93 return ((styles != null) ? styles.get(osm) : null); 94 95 if(osm.mappaintStyle == null && styles != null) { 96 osm.mappaintStyle = styles.get(osm); 97 if(osm instanceof Way) { 98 ((Way)osm).isMappaintArea = styles.isArea(osm); 99 } 100 } 101 return osm.mappaintStyle; 103 102 } 104 103 … … 255 254 width = l.width; 256 255 realWidth = l.realWidth; 257 dashed = l. dashed;256 dashed = l.getDashed(); 258 257 dashedColor = l.dashedColor; 259 258 } … … 292 291 293 292 /* draw overlays under the way */ 294 if(l != null && l.overlays != null) 295 { 296 for(LineElemStyle s : l.overlays) 297 { 298 if(!s.over) 299 { 293 if(l != null && l.overlays != null) { 294 for(LineElemStyle s : l.overlays) { 295 if(!s.over) { 300 296 lastN = null; 301 for(Node n : w.getNodes()) 302 { 303 if(lastN != null) 304 { 297 for(Node n : w.getNodes()) { 298 if(lastN != null) { 305 299 drawSeg(lastN, n, s.color != null && !data.isSelected(w) ? s.color : color, 306 false, s.getWidth(width), s. dashed, s.dashedColor);300 false, s.getWidth(width), s.getDashed(), s.dashedColor); 307 301 } 308 302 lastN = n; … … 338 332 { 339 333 drawSeg(lastN, n, s.color != null && !data.isSelected(w) ? s.color : color, 340 false, s.getWidth(width), s. dashed, s.dashedColor);334 false, s.getWidth(width), s.getDashed(), s.dashedColor); 341 335 } 342 336 lastN = n; … … 1156 1150 int w = icon.getIconWidth(), h=icon.getIconHeight(); 1157 1151 icon.paintIcon ( Main.map.mapView, g, p.x-w/2, p.y-h/2 ); 1158 if(showNames > dist) 1159 { 1152 if(showNames > dist && annotate) { 1160 1153 String name = getNodeName(n); 1161 if (name!=null && annotate) 1162 { 1154 if (name!=null) { 1163 1155 if (inactive || n.isDisabled()) { 1164 1156 g.setColor(inactiveColor); … … 1219 1211 protected void displaySegments(Color newColor, int newWidth, float newDash[], Color newDashedColor) { 1220 1212 if (currentPath != null) { 1221 Graphics2D g2d = (Graphics2D)g; 1222 g2d.setColor(inactive ? inactiveColor : currentColor); 1213 g.setColor(inactive ? inactiveColor : currentColor); 1223 1214 if (currentStroke == null && useStrokes > dist) { 1224 1215 if (currentDashed.length > 0) { 1225 try { 1226 g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashed,0)); 1227 } catch (IllegalArgumentException e) { 1228 g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 1229 } 1216 g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashed,0)); 1230 1217 } else { 1231 g 2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));1232 } 1233 } 1234 g 2d.draw(currentPath);1218 g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 1219 } 1220 } 1221 g.draw(currentPath); 1235 1222 1236 1223 if(currentDashedColor != null) { 1237 g 2d.setColor(currentDashedColor);1224 g.setColor(currentDashedColor); 1238 1225 if (currentStroke == null && useStrokes > dist) { 1239 1226 if (currentDashed.length > 0) { … … 1242 1229 currentDashedOffset[currentDashed.length-1] = currentDashed[0]; 1243 1230 float offset = currentDashedOffset[0]; 1244 try { 1245 g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashedOffset,offset)); 1246 } catch (IllegalArgumentException e) { 1247 g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 1248 } 1231 g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,currentDashedOffset,offset)); 1249 1232 } else { 1250 g 2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));1251 } 1252 } 1253 g 2d.draw(currentPath);1233 g.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 1234 } 1235 } 1236 g.draw(currentPath); 1254 1237 } 1255 1238 1256 1239 if(useStrokes > dist) { 1257 g 2d.setStroke(new BasicStroke(1));1240 g.setStroke(new BasicStroke(1)); 1258 1241 } 1259 1242 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r2578 r2659 8 8 import java.awt.BasicStroke; 9 9 import java.awt.Color; 10 import java.awt.Graphics;11 10 import java.awt.Graphics2D; 12 11 import java.awt.Point; … … 45 44 * The environment to paint to. 46 45 */ 47 protected Graphics g;46 protected Graphics2D g; 48 47 /** 49 48 * MapView to get screen coordinates. … … 90 89 protected GeneralPath currentPath = new GeneralPath(); 91 90 92 Rectangle bbox = new Rectangle();93 94 91 public void getColors() 95 92 { … … 124 121 getColors(); 125 122 126 ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,123 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 127 124 Main.pref.getBoolean("mappaint.use-antialiasing", false) ? 128 125 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); … … 386 383 } 387 384 388 ((Graphics2D) g).draw(relatedWayStroke.createStrokedShape(path));385 g.draw(relatedWayStroke.createStrokedShape(path)); 389 386 } 390 387 } … … 477 474 } 478 475 479 public void setGraphics(Graphics g) {476 public void setGraphics(Graphics2D g) { 480 477 this.g = g; 481 478 } … … 491 488 if (currentPath != null) { 492 489 g.setColor(currentColor); 493 ((Graphics2D) g).draw(currentPath);490 g.draw(currentPath); 494 491 currentPath = new GeneralPath(); 495 492 currentColor = newColor; -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java
r2626 r2659 14 14 public class ElemStyleHandler extends DefaultHandler 15 15 { 16 boolean inDoc, inRule, inCondition, in ElemStyle, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;16 boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin; 17 17 boolean hadLine, hadLineMod, hadIcon, hadArea; 18 18 ElemStyles styles; … … 44 44 public ElemStyleHandler(String name) { 45 45 styleName = name; 46 inDoc=inRule=inCondition=in ElemStyle=inLine=inIcon=inArea=false;46 inDoc=inRule=inCondition=inLine=inIcon=inArea=false; 47 47 rule.init(); 48 48 styles = MapPaintStyles.getStyles(); … … 105 105 line.realWidth=Integer.parseInt(atts.getValue(count)); 106 106 } else if (atts.getQName(count).equals("dashed")) { 107 try108 {107 float[] dashed; 108 try { 109 109 String[] parts = atts.getValue(count).split(","); 110 line.dashed = new float[parts.length];110 dashed = new float[parts.length]; 111 111 for (int i = 0; i < parts.length; i++) { 112 line.dashed[i] = (Integer.parseInt(parts[i]));112 dashed[i] = (Integer.parseInt(parts[i])); 113 113 } 114 114 } catch (NumberFormatException nfe) { 115 boolean dashed=Boolean.parseBoolean(atts.getValue(count)); 116 if(dashed) { 117 line.dashed = new float[]{9}; 118 } 119 } 115 boolean isDashed = Boolean.parseBoolean(atts.getValue(count)); 116 if(isDashed) { 117 dashed = new float[]{9}; 118 } else { 119 dashed = new float[0]; 120 } 121 } 122 line.setDashed(dashed); 120 123 } else if (atts.getQName(count).equals("dashedcolour")) { 121 124 line.dashedColor=convertColor(atts.getValue(count)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r1747 r2659 3 3 import java.awt.Color; 4 4 import java.util.Collection; 5 6 import org.openstreetmap.josm.tools.I18n; 5 7 6 8 public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle> … … 9 11 public int realWidth; //the real width of this line in meter 10 12 public Color color; 11 p ublicfloat[] dashed;13 private float[] dashed; 12 14 public Color dashedColor; 13 15 … … 49 51 this.overlays = overlays; 50 52 this.code = s.code; 51 for (LineElemStyle o : overlays) 53 for (LineElemStyle o : overlays) { 52 54 this.code += o.code; 55 } 53 56 } 54 57 … … 72 75 { 73 76 int res; 74 if(widthMode == WidthMode.ABSOLUTE) 77 if(widthMode == WidthMode.ABSOLUTE) { 75 78 res = width; 76 else if(widthMode == WidthMode.OFFSET)79 } else if(widthMode == WidthMode.OFFSET) { 77 80 res = ref + width; 78 else81 } else 79 82 { 80 if(width < 0) 83 if(width < 0) { 81 84 res = 0; 82 else85 } else { 83 86 res = ref*width/100; 87 } 84 88 } 85 89 return res <= 0 ? 1 : res; 86 90 } 87 91 88 public int compareTo(LineElemStyle s) 89 { 92 public int compareTo(LineElemStyle s) { 90 93 if(s.priority != priority) 91 94 return s.priority > priority ? 1 : -1; 92 if(!over && s.over) 93 return -1; 94 // we have no idea how to order other objects :-) 95 return 0; 95 if(!over && s.over) 96 return -1; 97 // we have no idea how to order other objects :-) 98 return 0; 99 } 100 101 public float[] getDashed() { 102 return dashed; 103 } 104 105 public void setDashed(float[] dashed) { 106 if (dashed.length == 0) { 107 this.dashed = dashed; 108 return; 109 } 110 111 boolean found = false; 112 for (int i=0; i<dashed.length; i++) { 113 if (dashed[i] > 0) { 114 found = true; 115 } 116 if (dashed[i] < 0) { 117 System.out.println(I18n.tr("Illegal dash pattern, values must be positive")); 118 } 119 } 120 if (found) { 121 this.dashed = dashed; 122 } else { 123 System.out.println(I18n.tr("Illegal dash pattern, at least one value must be > 0")); 124 } 96 125 } 97 126 }
Note:
See TracChangeset
for help on using the changeset viewer.