Changeset 4074 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-05-05T20:49:14+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r4000 r4074 17 17 import java.util.Locale; 18 18 import java.util.Map; 19 import java.util.Map.Entry; 19 20 import java.util.Set; 20 import java.util.Map.Entry;21 21 import java.util.concurrent.atomic.AtomicLong; 22 22 … … 1302 1302 } 1303 1303 } 1304 1305 1304 return result; 1305 } 1306 1307 /** 1308 * <p>Visits {@code visitor} for all referrers.</p> 1309 * 1310 * @param visitor the visitor. Ignored, if null. 1311 */ 1312 public void visitReferrers(Visitor visitor){ 1313 if (visitor == null) return; 1314 if (this.referrers == null) 1315 return; 1316 else if (this.referrers instanceof OsmPrimitive) { 1317 OsmPrimitive ref = (OsmPrimitive) this.referrers; 1318 if (ref.dataSet == dataSet) { 1319 ref.visit(visitor); 1320 } 1321 } else if (this.referrers instanceof OsmPrimitive[]) { 1322 OsmPrimitive[] refs = (OsmPrimitive[]) this.referrers; 1323 for (OsmPrimitive ref: refs) { 1324 if (ref.dataSet == dataSet) { 1325 ref.visit(visitor); 1326 } 1327 } 1328 } 1306 1329 } 1307 1330 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r4040 r4074 6 6 import java.util.ArrayList; 7 7 import java.util.Collections; 8 import java.util.Comparator;9 8 import java.util.List; 10 9 … … 24 23 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 25 24 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 26 import org.openstreetmap.josm.tools.Pair;27 25 28 26 public class MapPaintVisitor implements PaintVisitor { -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r4055 r4074 84 84 private Pair<StyleList, Range> getImpl(OsmPrimitive osm, double scale, NavigatableComponent nc) { 85 85 if (osm instanceof Node) 86 {87 86 return generateStyles(osm, scale, null, false); 88 }89 87 else if (osm instanceof Way) 90 88 { … … 235 233 236 234 for (Entry<String, Cascade> e : mc.getLayers()) { 237 if ("*".equals(e.getKey())) 235 if ("*".equals(e.getKey())) { 238 236 continue; 237 } 239 238 env.layer = e.getKey(); 240 239 Cascade c = e.getValue(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java
r4007 r4074 114 114 * @param c the style properties 115 115 * @param defaultTextColor the default text color. Must not be null. 116 * @param defaultAnnotate true, if a text label shall be rendered by default, even if the style sheet 117 * doesn't include respective style declarations 116 118 * @return the text element or null, if the style properties don't include 117 119 * properties for text rendering … … 212 214 final TextElement other = (TextElement) obj; 213 215 return equal(labelCompositionStrategy, other.labelCompositionStrategy) && 214 215 216 217 218 219 216 equal(font, other.font) && 217 xOffset == other.xOffset && 218 yOffset == other.yOffset && 219 equal(color, other.color) && 220 equal(haloRadius, other.haloRadius) && 221 equal(haloColor, other.haloColor); 220 222 } 221 223 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSRule.java
r3876 r4074 4 4 import java.util.List; 5 5 6 import org.openstreetmap.josm.gui.mappaint.Environment; 6 7 import org.openstreetmap.josm.tools.Utils; 7 8 … … 16 17 } 17 18 19 /** 20 * <p>Executes the instructions against the environment {@code env}</p> 21 * 22 * @param env the environment 23 */ 24 public void execute(Environment env) { 25 for (Instruction i : declaration) { 26 i.execute(env); 27 } 28 } 29 18 30 @Override 19 31 public String toString() { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r4069 r4074 134 134 if ((s instanceof GeneralSelector)) { 135 135 GeneralSelector gs = (GeneralSelector) s; 136 if (gs.base.equals(type)) { 137 for (Condition cnd : gs.conds) { 138 if (!cnd.applies(env)) 139 continue NEXT_RULE; 136 if (gs.getBase().equals(type)) { 137 if (!gs.matchesConditions(env)) { 138 continue NEXT_RULE; 140 139 } 141 for (Instruction i : r.declaration) { 142 i.execute(env); 143 } 140 r.execute(env); 144 141 } 145 142 } … … 179 176 continue; 180 177 } 181 for (Instruction i : r.declaration) { 182 i.execute(env); 183 } 178 r.execute(env); 184 179 } 185 180 } 186 181 env.layer = sub; 187 for (Instruction i : r.declaration) { 188 i.execute(env); 189 } 182 r.execute(env); 190 183 } 191 184 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r4069 r4074 10 10 import org.openstreetmap.josm.data.osm.RelationMember; 11 11 import org.openstreetmap.josm.data.osm.Way; 12 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 12 13 import org.openstreetmap.josm.gui.mappaint.Environment; 13 14 import org.openstreetmap.josm.gui.mappaint.Range; … … 67 68 } 68 69 70 /** 71 * <p>Finds the first referrer matching {@link #left}</p> 72 * 73 * <p>The visitor works on an environment and it saves the matching 74 * referrer in {@code e.parent} and its relative position in the 75 * list referrers "child list" in {@code e.index}.</p> 76 * 77 * <p>If after execution {@code e.parent} is null, no matching 78 * referrer was found.</p> 79 * 80 */ 81 private class MatchingReferrerFinder extends AbstractVisitor{ 82 private Environment e; 83 84 /** 85 * Constructor 86 * @param e the environment against which we match 87 */ 88 public MatchingReferrerFinder(Environment e){ 89 this.e = e; 90 } 91 92 @Override 93 public void visit(Node n) { 94 // node should never be a referrer 95 throw new AssertionError(); 96 } 97 98 @Override 99 public void visit(Way w) { 100 /* 101 * If e.parent is already set to the first matching referrer. We skip any following 102 * referrer injected into the visitor. 103 */ 104 if (e.parent != null) return; 105 106 if (!left.matches(e.withPrimitive(w))) 107 return; 108 for (int i=0; i<w.getNodesCount(); i++) { 109 Node n = w.getNode(i); 110 if (n.equals(e.osm)) { 111 if (link.matches(e.withParent(w).withIndex(i).withLinkContext())) { 112 e.parent = w; 113 e.index = i; 114 return; 115 } 116 } 117 } 118 } 119 120 @Override 121 public void visit(Relation r) { 122 /* 123 * If e.parent is already set to the first matching referrer. We skip any following 124 * referrer injected into the visitor. 125 */ 126 if (e.parent != null) return; 127 128 if (!left.matches(e.withPrimitive(r))) 129 return; 130 for (int i=0; i < r.getMembersCount(); i++) { 131 RelationMember m = r.getMember(i); 132 if (m.getMember().equals(e.osm)) { 133 if (link.matches(e.withParent(r).withIndex(i).withLinkContext())) { 134 e.parent = r; 135 e.index = i; 136 return; 137 } 138 } 139 } 140 } 141 } 142 69 143 @Override 70 144 public boolean matches(Environment e) { … … 73 147 74 148 if (!parentSelector) { 75 for (OsmPrimitive ref : e.osm.getReferrers()) { 76 if (!left.matches(e.withPrimitive(ref))) 77 continue; 78 if (ref instanceof Way) { 79 List<Node> wayNodes = ((Way) ref).getNodes(); 80 for (int i=0; i<wayNodes.size(); i++) { 81 if (wayNodes.get(i).equals(e.osm)) { 82 if (link.matches(e.withParent(ref).withIndex(i).withLinkContext())) { 83 e.parent = ref; 84 e.index = i; 85 return true; 86 } 87 } 88 } 89 } else if (ref instanceof Relation) { 90 List<RelationMember> members = ((Relation) ref).getMembers(); 91 for (int i=0; i<members.size(); i++) { 92 RelationMember m = members.get(i); 93 if (m.getMember().equals(e.osm)) { 94 if (link.matches(e.withParent(ref).withIndex(i).withLinkContext())) { 95 e.parent = ref; 96 e.index = i; 97 return true; 98 } 99 } 100 } 101 } 102 } 149 MatchingReferrerFinder collector = new MatchingReferrerFinder(e); 150 e.osm.visitReferrers(collector); 151 if (e.parent != null) 152 return true; 103 153 } else { 104 154 if (e.osm instanceof Way) { … … 181 231 182 232 public static class GeneralSelector implements Selector { 183 p ublicString base;233 private String base; 184 234 public Range range; 185 pr otectedList<Condition> conds;235 private List<Condition> conds; 186 236 private String subpart; 187 237 … … 198 248 range = new Range(); 199 249 } 200 this.conds = conds; 250 if (conds == null || conds.isEmpty()) { 251 this.conds = null; 252 } else { 253 this.conds = conds; 254 } 201 255 this.subpart = subpart; 202 256 } … … 211 265 } 212 266 213 @Override 214 public boolean matches(Environment e) { 215 if (!baseApplies(e.osm)) 216 return false; 267 public boolean matchesBase(Environment e){ 268 if (base.equals("*")) 269 return true; 270 if (base.equals("area")) { 271 if (e.osm instanceof Way) 272 return true; 273 if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon()) 274 return true; 275 } 276 if (base.equals(OsmPrimitiveType.from(e.osm).getAPIName())) 277 return true; 278 return false; 279 } 280 281 public boolean matchesConditions(Environment e){ 282 if (conds == null) return true; 217 283 for (Condition c : conds) { 218 284 if (!c.applies(e)) … … 222 288 } 223 289 224 private boolean baseApplies(OsmPrimitive osm) { 225 if (base.equals("*")) 226 return true; 227 if (base.equals("area")) { 228 if (osm instanceof Way) 229 return true; 230 if (osm instanceof Relation && ((Relation) osm).isMultipolygon()) 231 return true; 232 } 233 if (base.equals(OsmPrimitiveType.from(osm).getAPIName())) 234 return true; 235 return false; 290 @Override 291 public boolean matches(Environment e) { 292 if (!matchesBase(e)) return false; 293 return matchesConditions(e); 294 } 295 296 public String getBase() { 297 return base; 236 298 } 237 299
Note:
See TracChangeset
for help on using the changeset viewer.