- Timestamp:
- 2011-02-06T10:19:47+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3859 r3860 100 100 } 101 101 102 public void drawWay(Way way, Color color, float width, float dashed[], float dashesOffset, Color dashedColor, boolean showDirection,102 public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, boolean showDirection, 103 103 boolean reversedDirection, boolean showHeadArrowOnly) { 104 104 … … 156 156 lastPoint = p; 157 157 } 158 displaySegments(path, arrows, color, width, dashed, dashesOffset, dashedColor);159 } 160 161 private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, float width, float dashed[], float dashesOffset, Color dashedColor) {158 displaySegments(path, arrows, color, line, dashes, dashedColor); 159 } 160 161 private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) { 162 162 g.setColor(inactive ? inactiveColor : color); 163 163 if (useStrokes) { 164 if (dashed != null && dashed.length > 0) { 165 g.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,dashed,dashesOffset)); 166 } else { 167 g.setStroke(new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 168 } 164 g.setStroke(line); 169 165 } 170 166 g.draw(path); 171 167 g.draw(arrows); 172 168 173 if(!inactive && useStrokes && dashe dColor!= null) {169 if(!inactive && useStrokes && dashes != null) { 174 170 g.setColor(dashedColor); 175 if (dashed != null && dashed.length > 0) { 176 float[] dashedOffset = new float[dashed.length]; 177 System.arraycopy(dashed, 0, dashedOffset, 1, dashed.length - 1); 178 dashedOffset[0] = dashed[dashed.length-1]; 179 float offset = dashedOffset[0] + dashesOffset; 180 g.setStroke(new BasicStroke(width,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,dashedOffset, offset)); 181 } else { 182 g.setStroke(new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND)); 183 } 171 g.setStroke(dashes); 184 172 g.draw(path); 185 173 g.draw(arrows); -
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r3858 r3860 19 19 protected Map<String, Object> prop = new HashMap<String, Object>(); 20 20 21 public <T> T get(String key, T def, Class<T> klass) { 22 return get(key, def, klass, false); 23 } 24 21 25 /** 22 26 * Get value for the given key … … 24 28 * @param def default value, can be null 25 29 * @param klass the same as T 30 * @param suppressWarnings show or don't show a warning when some value is 31 * found, but cannot be converted to the requested type 26 32 * @return if a value with class klass has been mapped to key, returns this 27 33 * value, def otherwise 28 34 */ 29 public <T> T get(String key, T def, Class<T> klass ) {35 public <T> T get(String key, T def, Class<T> klass, boolean suppressWarnings) { 30 36 if (def != null && !klass.isInstance(def)) 31 37 throw new IllegalArgumentException(); … … 35 41 T res = convertTo(o, klass); 36 42 if (res == null) { 37 System.err.println(String.format("Warning: unable to convert property %s to type %s: found %s of type %s!", key, klass, o, o.getClass())); 43 if (!suppressWarnings) { 44 System.err.println(String.format("Warning: unable to convert property %s to type %s: found %s of type %s!", key, klass, o, o.getClass())); 45 } 38 46 return def; 39 47 } else -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3855 r3860 193 193 List<ElemStyle> sl = new ArrayList<ElemStyle>(); 194 194 MultiCascade mc = new MultiCascade(); 195 Environment env = new Environment(osm, mc, null, null); 195 196 196 197 for (StyleSource s : styleSources) { … … 203 204 if ("*".equals(e.getKey())) 204 205 continue; 206 env.layer = e.getKey(); 205 207 Cascade c = e.getValue(); 206 208 if (osm instanceof Way) { 207 209 addIfNotNull(sl, AreaElemStyle.create(c)); 208 addIfNotNull(sl, LineElemStyle.createLine( c));209 addIfNotNull(sl, LineElemStyle.createCasing( c));210 addIfNotNull(sl, LineElemStyle.createLine(env)); 211 addIfNotNull(sl, LineElemStyle.createCasing(env)); 210 212 } else if (osm instanceof Node) { 211 213 addIfNotNull(sl, NodeElemStyle.create(c)); … … 213 215 if (((Relation)osm).isMultipolygon()) { 214 216 addIfNotNull(sl, AreaElemStyle.create(c)); 215 addIfNotNull(sl, LineElemStyle.createLine( c));216 addIfNotNull(sl, LineElemStyle.createCasing( c));217 addIfNotNull(sl, LineElemStyle.createLine(env)); 218 addIfNotNull(sl, LineElemStyle.createCasing(env)); 217 219 } else if ("restriction".equals(osm.get("type"))) { 218 220 addIfNotNull(sl, NodeElemStyle.create(c)); -
trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
r3858 r3860 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.mappaint .mapcss;2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 9 9 public class Environment { 10 10 11 OsmPrimitive osm;12 MultiCascade mc;13 String layer;14 StyleSource source;11 public OsmPrimitive osm; 12 public MultiCascade mc; 13 public String layer; 14 public StyleSource source; 15 15 16 16 public Environment(OsmPrimitive osm, MultiCascade mc, String layer, StyleSource source) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3859 r3860 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 6 import java.awt.BasicStroke; 4 7 import java.awt.Color; 5 8 import java.util.Arrays; … … 11 14 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 12 15 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 16 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat; 13 17 import org.openstreetmap.josm.tools.Utils; 14 18 … … 16 20 17 21 public static LineElemStyle createSimpleLineStyle(Color color) { 18 return new LineElemStyle(Cascade.EMPTY_CASCADE, -1f, 0f, color != null ? color : PaintColors.UNTAGGED.get(), null, 0f, null); 22 Cascade c = new Cascade(); 23 c.put("width", -1f); 24 c.put("color", color != null ? color : PaintColors.UNTAGGED.get()); 25 MultiCascade mc = new MultiCascade(); 26 mc.put("default", c); 27 return createLine(new Environment(null, mc, "default", null)); 19 28 } 20 29 public static final LineElemStyle UNTAGGED_WAY = createSimpleLineStyle(null); 21 30 22 private float width;23 31 public float realWidth; // the real width of this line in meter 24 32 public Color color; 25 private float[] dashed; 26 private float dashesOffset; 27 public Color dashedColor; 28 29 protected LineElemStyle(Cascade c, float width, float realWidth, Color color, float[] dashed, float dashesOffset, Color dashedColor) { 33 public Color dashesBackground; 34 35 private BasicStroke line; 36 private BasicStroke dashesLine; 37 38 protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float realWidth) { 30 39 super(c); 31 setWidth(width); 40 this.line = line; 41 this.color = color; 42 this.dashesLine = dashesLine; 43 this.dashesBackground = dashesBackground; 32 44 this.realWidth = realWidth; 33 this.color = color; 34 this.dashed = dashed; 35 this.dashesOffset = dashesOffset; 36 this.dashedColor = dashedColor; 37 } 38 39 public static LineElemStyle createLine(Cascade c) { 40 return createImpl(c, ""); 41 } 42 43 public static LineElemStyle createCasing(Cascade c) { 44 LineElemStyle casing = createImpl(c, "casing-"); 45 } 46 47 public static LineElemStyle createLine(Environment env) { 48 return createImpl(env, ""); 49 } 50 51 public static LineElemStyle createCasing(Environment env) { 52 LineElemStyle casing = createImpl(env, "casing-"); 45 53 if (casing != null) { 46 54 casing.object_z_index = -1; … … 49 57 } 50 58 51 private static LineElemStyle createImpl(Cascade c, String prefix) { 52 Float width = c.get(prefix + "width", null, Float.class); 53 if (width == null) 54 return null; 59 private static LineElemStyle createImpl(Environment env, String prefix) { 60 Cascade c = env.getCascade(); 61 Float width = c.get(prefix + "width", null, Float.class, true); 62 if (width != null) { 63 if (width == -1f) { 64 width = (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 65 } 66 if (width <= 0) 67 return null; 68 } else { 69 String width_key = c.get(prefix + "width", null, String.class, true); 70 if (equal(width_key, "thinnest")) { 71 width = 0f; 72 } else if (! equal(env.layer, "default")) { 73 RelativeFloat width_rel = c.get(prefix + "width", null, RelativeFloat.class, true); 74 if (width_rel != null) { 75 width = env.mc.getCascade("default").get("width", 0f, Float.class) + width_rel.val; 76 } else 77 return null; 78 } else 79 return null; 80 } 55 81 56 82 float realWidth = c.get(prefix + "real-width", 0f, Float.class); 83 if (realWidth > 0 && MapPaintSettings.INSTANCE.isUseRealWidth()) { 84 85 /* if we have a "width" tag, try use it */ 86 String widthTag = env.osm.get("width"); 87 if(widthTag == null) { 88 widthTag = env.osm.get("est_width"); 89 } 90 if(widthTag != null) { 91 try { 92 realWidth = new Float(Integer.parseInt(widthTag)); 93 } 94 catch(NumberFormatException nfe) { 95 } 96 } 97 } 98 57 99 Color color = c.get(prefix + "color", null, Color.class); 58 100 if (color == null) { … … 82 124 } 83 125 } 84 if (!hasPositive ) {126 if (!hasPositive || dashes.length == 0) { 85 127 dashes = null; 86 128 } … … 97 139 } 98 140 99 return new LineElemStyle(c, width, realWidth, color, dashes, dashesOffset, dashesBackground); 141 int cap; 142 String capStr = c.get(prefix + "linecap", null, String.class); 143 if (equal(capStr, "none")) { 144 cap = BasicStroke.CAP_BUTT; 145 } else if (equal(capStr, "round")) { 146 cap = BasicStroke.CAP_ROUND; 147 } else if (equal(capStr, "square")) { 148 cap = BasicStroke.CAP_SQUARE; 149 } else { 150 cap = dashes != null ? BasicStroke.CAP_BUTT : BasicStroke.CAP_ROUND; 151 } 152 153 int join; 154 String joinStr = c.get(prefix + "linejoin", null, String.class); 155 if (equal(joinStr, "round")) { 156 join = BasicStroke.JOIN_ROUND; 157 } else if (equal(joinStr, "miter")) { 158 join = BasicStroke.JOIN_MITER; 159 } else if (equal(joinStr, "bevel")) { 160 join = BasicStroke.JOIN_BEVEL; 161 } else { 162 join = BasicStroke.JOIN_ROUND; 163 } 164 165 float miterlimit = c.get(prefix + "miterlimit", 10f, Float.class); 166 167 BasicStroke line = new BasicStroke(width, cap, join, miterlimit, dashes, dashesOffset); 168 BasicStroke dashesLine = null; 169 170 if (dashes != null && dashesBackground != null) { 171 float[] dashes2 = new float[dashes.length]; 172 System.arraycopy(dashes, 0, dashes2, 1, dashes.length - 1); 173 dashes2[0] = dashes[dashes.length-1]; 174 dashesLine = new BasicStroke(width, cap, join, miterlimit, dashes2, dashes2[0] + dashesOffset); 175 } 176 177 return new LineElemStyle(c, line, color, dashesLine, dashesBackground, realWidth); 100 178 } 101 179 … … 114 192 Node lastN; 115 193 116 Color myDashedColor = dashedColor; 117 float myWidth = getWidth(); 118 194 Color myDashedColor = dashesBackground; 195 BasicStroke myLine = line, myDashLine = dashesLine; 119 196 if (realWidth > 0 && paintSettings.isUseRealWidth() && !showDirection) { 120 121 /* if we have a "width" tag, try use it */ 122 /* (this might be slow and could be improved by caching the value in the Way, on the other hand only used if "real width" is enabled) */ 123 String widthTag = w.get("width"); 124 if(widthTag == null) { 125 widthTag = w.get("est_width"); 126 } 127 if(widthTag != null) { 128 try { 129 realWidth = new Float(Integer.parseInt(widthTag)); 130 } 131 catch(NumberFormatException nfe) { 132 } 133 } 134 135 myWidth = (int) (100 / (float) (painter.getCircum() / realWidth)); 136 if (myWidth < getWidth()) { 137 myWidth = getWidth(); 197 float myWidth = (int) (100 / (float) (painter.getCircum() / realWidth)); 198 if (myWidth < line.getLineWidth()) { 199 myWidth = line.getLineWidth(); 200 } 201 myLine = new BasicStroke(myWidth, line.getEndCap(), line.getLineJoin(), 202 line.getMiterLimit(), line.getDashArray(), line.getDashPhase()); 203 if (dashesLine != null) { 204 myDashLine = new BasicStroke(myWidth, dashesLine.getEndCap(), dashesLine.getLineJoin(), 205 dashesLine.getMiterLimit(), dashesLine.getDashArray(), dashesLine.getDashPhase()); 138 206 } 139 207 } … … 151 219 } 152 220 153 painter.drawWay(w, markColor != null ? markColor : color, myWidth, dashed, 154 dashesOffset, myDashedColor, showDirection, 221 painter.drawWay(w, markColor != null ? markColor : color, myLine, myDashLine, myDashedColor, showDirection, 155 222 selected ? false : reversedDirection, showOnlyHeadArrowOnly); 156 223 … … 168 235 } 169 236 170 public float getWidth() {171 if (width == -1f)172 return MapPaintSettings.INSTANCE.getDefaultSegmentWidth();173 return width;174 }175 176 public void setWidth(float width) {177 this.width = width;178 }179 180 237 @Override 181 238 public boolean equals(Object obj) { … … 185 242 return false; 186 243 final LineElemStyle other = (LineElemStyle) obj; 187 return width == other.width && 188 realWidth == other.realWidth && 189 Utils.equal(color, other.color) && 190 Arrays.equals(dashed, other.dashed) && 191 dashesOffset == other.dashesOffset && 192 Utils.equal(dashedColor, other.dashedColor); 244 return equal(line, other.line) && 245 equal(color, other.color) && 246 equal(dashesLine, other.dashesLine) && 247 equal(dashesBackground, other.dashesBackground) && 248 realWidth == other.realWidth; 193 249 } 194 250 … … 196 252 public int hashCode() { 197 253 int hash = super.hashCode(); 198 hash = 29 * hash + Float.floatToIntBits(width); 254 hash = 29 * hash + line.hashCode(); 255 hash = 29 * hash + color.hashCode(); 256 hash = 29 * hash + (dashesLine != null ? dashesLine.hashCode() : 0); 257 hash = 29 * hash + (dashesBackground != null ? dashesBackground.hashCode() : 0); 199 258 hash = 29 * hash + Float.floatToIntBits(realWidth); 200 hash = 29 * hash + color.hashCode();201 hash = 29 * hash + Arrays.hashCode(dashed);202 hash = 29 * hash + Float.floatToIntBits(dashesOffset);203 hash = 29 * hash + (dashedColor != null ? dashedColor.hashCode() : 0);204 259 return hash; 205 260 } … … 207 262 @Override 208 263 public String toString() { 209 return "LineElemStyle{" + super.toString() + "width=" + width +264 return "LineElemStyle{" + super.toString() + "width=" + line.getLineWidth() + 210 265 " realWidth=" + realWidth + " color=" + Utils.toString(color) + 211 " dashed=" + Arrays.toString( dashed) +212 ( dashesOffset == 0f ? "" : " dashesOffses=" + dashesOffset) +213 " dashedColor=" + Utils.toString(dashe dColor) + '}';266 " dashed=" + Arrays.toString(line.getDashArray()) + 267 (line.getDashPhase() == 0f ? "" : " dashesOffses=" + line.getDashPhase()) + 268 " dashedColor=" + Utils.toString(dashesBackground) + '}'; 214 269 } 215 270 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r3856 r3860 4 4 import org.openstreetmap.josm.data.osm.Relation; 5 5 import org.openstreetmap.josm.data.osm.Way; 6 import org.openstreetmap.josm.gui.mappaint.Environment; 6 7 import org.openstreetmap.josm.tools.Utils; 7 8 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
r3856 r3860 15 15 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError; 16 16 import org.openstreetmap.josm.gui.mappaint.Cascade; 17 import org.openstreetmap.josm.gui.mappaint.Environment; 17 18 import org.openstreetmap.josm.tools.Utils; 18 19 … … 137 138 } 138 139 return c.containsKey(key); 140 } 141 142 public String get_tag_value(String key) { 143 return env.osm.get(key); 144 } 145 146 public boolean has_tag_key(String key) { 147 return env.osm.hasKey(key); 139 148 } 140 149 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r3858 r3860 4 4 import java.util.Arrays; 5 5 6 import org.openstreetmap.josm.gui.mappaint.Environment; 6 7 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 7 8 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r3858 r3860 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.gui.mappaint.Cascade; 15 import org.openstreetmap.josm.gui.mappaint.Environment; 15 16 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 16 17 import org.openstreetmap.josm.gui.mappaint.Range; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r3856 r3860 8 8 import org.openstreetmap.josm.data.osm.Relation; 9 9 import org.openstreetmap.josm.data.osm.Way; 10 import org.openstreetmap.josm.gui.mappaint.Environment; 10 11 import org.openstreetmap.josm.gui.mappaint.Range; 11 12 import org.openstreetmap.josm.tools.Pair;
Note:
See TracChangeset
for help on using the changeset viewer.