Changeset 3824 in josm for trunk/src/org
- Timestamp:
- 2011-01-27T21:18:27+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r3731 r3824 26 26 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError; 27 27 import org.openstreetmap.josm.data.osm.visitor.Visitor; 28 import org.openstreetmap.josm.gui.mappaint. ElemStyle;28 import org.openstreetmap.josm.gui.mappaint.StyleCache; 29 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 30 30 import org.openstreetmap.josm.tools.Predicate; … … 299 299 * MAPPAINT 300 300 *--------*/ 301 public ElemStyle mappaintStyle = null;301 public StyleCache mappaintStyle = null; 302 302 public int mappaintDrawnCode = 0; 303 303 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r3822 r3824 1 / * License: GPL. Copyright 2007 by Immanuel Scholz and others */1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data.osm.visitor.paint; 3 4 /* To enable debugging or profiling remove the double / signs */5 3 6 4 import java.awt.Graphics2D; … … 38 36 import org.openstreetmap.josm.gui.mappaint.LineElemStyle; 39 37 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 40 import org.openstreetmap.josm.gui.mappaint.S impleNodeElemStyle;38 import org.openstreetmap.josm.gui.mappaint.StyleCache; 41 39 42 40 public class MapPaintVisitor implements PaintVisitor { … … 70 68 } 71 69 72 public ElemStyle getPrimitiveStyle(OsmPrimitive osm, boolean nodefault) {70 public StyleCache getPrimitiveStyle(OsmPrimitive osm, boolean nodefault) { 73 71 if(osm.mappaintStyle == null) 74 72 { … … 79 77 } 80 78 } 81 if (osm.mappaintStyle == null) {79 if (osm.mappaintStyle.equals(StyleCache.EMPTY_STYLECACHE)) { 82 80 if(osm instanceof Node) 83 osm.mappaintStyle = S impleNodeElemStyle.INSTANCE;81 osm.mappaintStyle = StyleCache.SIMPLE_NODE_STYLECACHE;// SimpleNodeElemStyle.INSTANCE; 84 82 else if (osm instanceof Way) 85 osm.mappaintStyle = LineElemStyle.UNTAGGED_WAY;86 } 87 } 88 if (nodefault && osm.mappaintStyle == LineElemStyle.UNTAGGED_WAY)89 return null;83 osm.mappaintStyle = StyleCache.UNTAGGED_WAY_STYLECACHE;//LineElemStyle.UNTAGGED_WAY; 84 } 85 } 86 if (nodefault && osm.mappaintStyle.equals(StyleCache.UNTAGGED_WAY_STYLECACHE)) 87 return StyleCache.EMPTY_STYLECACHE; 90 88 return osm.mappaintStyle; 91 89 } 92 90 93 91 public IconElemStyle getPrimitiveNodeStyle(OsmPrimitive osm) { 94 if(osm.mappaintStyle == null && styles != null) 95 osm.mappaintStyle = styles.getIcon(osm); 96 97 return (IconElemStyle)osm.mappaintStyle; 92 if(osm.mappaintStyle == null && styles != null) { 93 IconElemStyle icon = styles.getIcon(osm); 94 osm.mappaintStyle = StyleCache.create(icon); 95 return icon; 96 } 97 for (ElemStyle s : osm.mappaintStyle.getStyles()) { 98 if (s instanceof IconElemStyle) 99 return (IconElemStyle) s; 100 } 101 return null; 98 102 } 99 103 … … 115 119 return; 116 120 117 ElemStyle nodeStyle = getPrimitiveStyle(n, false); 118 119 if (isZoomOk(nodeStyle)) { 120 nodeStyle.paintPrimitive(n, paintSettings, painter, data.isSelected(n), 121 false); 121 StyleCache sc = getPrimitiveStyle(n, false); 122 123 for (ElemStyle s : sc.getStyles()) { 124 if (isZoomOk(s)) { 125 s.paintPrimitive(n, paintSettings, painter, data.isSelected(n), false); 126 } 127 122 128 } 123 129 } … … 158 164 return; 159 165 160 ElemStyle wayStyle = getPrimitiveStyle(w, false); 161 162 if(!isZoomOk(wayStyle)) 163 return; 164 165 if(wayStyle instanceof LineElemStyle) { 166 wayStyle.paintPrimitive(w, paintSettings, painter, data.isSelected(w), false); 167 } else if (wayStyle instanceof AreaElemStyle) { 168 AreaElemStyle areaStyle = (AreaElemStyle) wayStyle; 169 /* way with area style */ 170 if (fillAreas > dist) 171 { 172 areaStyle.paintPrimitive(w, paintSettings, painter, data.isSelected(w), false); 173 } 174 areaStyle.getLineStyle().paintPrimitive(w, paintSettings, painter, data.isSelected(w), false); 166 StyleCache sc = getPrimitiveStyle(w, false); 167 for (ElemStyle s : sc.getStyles()) { 168 if(!isZoomOk(s)) 169 return; 170 if (fillAreas > dist || !(s instanceof AreaElemStyle)) { 171 s.paintPrimitive(w, paintSettings, painter, data.isSelected(w), false); 172 } 175 173 } 176 174 } … … 369 367 multipolygon.load(r); 370 368 371 ElemStyle wayStyle = getPrimitiveStyle(r, false); 369 AreaElemStyle areaStyle = null; 370 LineElemStyle lineStyle = null; 371 for (ElemStyle s : getPrimitiveStyle(r, false).getStyles()) { 372 if (s instanceof AreaElemStyle) { 373 areaStyle = (AreaElemStyle) s; 374 } else if (s instanceof LineElemStyle) { 375 lineStyle = (LineElemStyle) s; 376 } 377 } 372 378 373 379 boolean disabled = r.isDisabled(); 374 380 // If area style was not found for relation then use style of ways 375 if(styles != null && !(wayStyle instanceof AreaElemStyle)) {381 if(styles != null && areaStyle == null) { 376 382 for (Way w : multipolygon.getOuterWays()) { 377 wayStyle = styles.getArea(w); 383 for (ElemStyle s : styles.getArea(w).getStyles()) { 384 if (s instanceof AreaElemStyle) { 385 areaStyle = (AreaElemStyle) s; 386 } else if (s instanceof LineElemStyle) { 387 lineStyle = (LineElemStyle) s; 388 } 389 } 378 390 disabled = disabled || w.isDisabled(); 379 if( wayStyle != null) {391 if(areaStyle != null) { 380 392 break; 381 393 } … … 383 395 } 384 396 385 if ( wayStyle instanceof AreaElemStyle) {386 boolean zoomok = isZoomOk( wayStyle);397 if (areaStyle != null) { 398 boolean zoomok = isZoomOk(areaStyle); 387 399 boolean visible = false; 388 400 … … 390 402 391 403 if(zoomok && !disabled && !multipolygon.getOuterWays().isEmpty()) { 392 AreaElemStyle areaStyle = (AreaElemStyle)wayStyle;393 404 for (PolyData pd : multipolygon.getCombinedPolygons()) { 394 405 Polygon p = pd.get(); … … 399 410 boolean selected = pd.selected || data.isSelected(r); 400 411 painter.drawArea(p, selected ? paintSettings.getRelationSelectedColor() 401 : areaStyle.color, painter.getAreaName(r));412 : areaStyle.color, painter.getAreaName(r)); 402 413 visible = true; 403 414 } … … 407 418 return drawn; 408 419 for (Way wInner : multipolygon.getInnerWays()) { 409 ElemStyle innerStyle = getPrimitiveStyle(wInner, true); 410 if(innerStyle == null) { 420 StyleCache inner = getPrimitiveStyle(wInner, true); 421 AreaElemStyle innerArea = null; 422 for (ElemStyle s : inner.getStyles()) { 423 if (s instanceof AreaElemStyle) { 424 innerArea = (AreaElemStyle) s; 425 break; 426 } 427 } 428 429 if(inner.getStyles().isEmpty()) { 411 430 if (data.isSelected(wInner) || disabled) 412 431 continue; 413 432 if(zoomok && (wInner.mappaintDrawnCode != paintid || multipolygon.getOuterWays().isEmpty())) { 414 ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wInner, paintSettings,415 painter, (data.isSelected(wInner) || data.isSelected(r)), false);433 lineStyle.paintPrimitive(wInner, paintSettings, 434 painter, (data.isSelected(wInner) || data.isSelected(r)), false); 416 435 } 417 436 wInner.mappaintDrawnCode = paintid; 418 437 } 419 else 420 { 421 if(wayStyle.equals(innerStyle)) 422 { 438 else { 439 if(areaStyle.equals(innerArea)) { 423 440 wInner.mappaintDrawnAreaCode = paintid; 424 if(!data.isSelected(wInner))425 {441 442 if(!data.isSelected(wInner)) { 426 443 wInner.mappaintDrawnCode = paintid; 427 444 drawWay(wInner, 0); … … 431 448 } 432 449 for (Way wOuter : multipolygon.getOuterWays()) { 433 ElemStyle outerStyle = getPrimitiveStyle(wOuter, true); 434 if(outerStyle == null) { 450 StyleCache outer = getPrimitiveStyle(wOuter, true); 451 boolean hasOuterArea = false; 452 for (ElemStyle s : outer.getStyles()) { 453 if (s instanceof AreaElemStyle) { 454 hasOuterArea = true; 455 break; 456 } 457 } 458 459 if (outer.getStyles().isEmpty()) { 435 460 // Selected ways are drawn at the very end 436 461 if (data.isSelected(wOuter)) 437 462 continue; 438 463 if(zoomok) { 439 ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wOuter, paintSettings, painter,440 (data.isSelected(wOuter) || data.isSelected(r)), r.isSelected());464 lineStyle.paintPrimitive(wOuter, paintSettings, painter, 465 (data.isSelected(wOuter) || data.isSelected(r)), r.isSelected()); 441 466 } 442 467 wOuter.mappaintDrawnCode = paintid; 443 } else if (outerStyle instanceof AreaElemStyle) {468 } else if (hasOuterArea) { 444 469 wOuter.mappaintDrawnAreaCode = paintid; 445 470 if(!data.isSelected(wOuter)) { … … 512 537 /* Shows areas before non-areas */ 513 538 public void visitAll(final DataSet data, boolean virtual, Bounds bounds) { 539 //long start = System.currentTimeMillis(); 514 540 BBox bbox = new BBox(bounds); 515 541 this.data = data; … … 616 642 OsmPrimitive osm = m.getMember(); 617 643 if(osm.isDrawable()) { 618 ElemStyle style= getPrimitiveStyle(m.getMember(), false);644 StyleCache sc = getPrimitiveStyle(m.getMember(), false); 619 645 if(osm instanceof Way) 620 646 { 621 if(style instanceof AreaElemStyle) {622 ((AreaElemStyle)style).getLineStyle().paintPrimitive(osm, paintSettings, painter, true, true);623 } else {624 style.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true);647 for (ElemStyle s : sc.getStyles()) { 648 if (!(s instanceof AreaElemStyle)) { 649 s.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true); 650 } 625 651 } 626 652 } 627 653 else if(osm instanceof Node) 628 654 { 629 if(isZoomOk(style)) { 630 style.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true); 655 for (ElemStyle s : sc.getStyles()) { 656 if (isZoomOk(s)) { 657 s.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true); 658 } 631 659 } 632 660 } … … 648 676 649 677 painter.drawVirtualNodes(data.searchWays(bbox)); 678 //System.err.println("PAINTING TOOK "+(System.currentTimeMillis() - start)); 650 679 } 651 680 -
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r3803 r3824 26 26 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 27 27 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 28 import org.openstreetmap.josm.gui.mappaint.StyleCache; 29 import org.openstreetmap.josm.gui.mappaint.xml.AreaPrototype; 28 30 29 31 public class MultipolygonTest extends Test { … … 53 55 public void initialize() throws Exception { 54 56 styles = MapPaintStyles.getStyles(); 55 57 } 56 58 57 59 private List<List<Node>> joinWays(Collection<Way> ways) { … … 113 115 public void visit(Way w) { 114 116 if (styles != null && !w.isClosed()) { 115 ElemStyle e = styles.getArea(w);116 if (e instanceof AreaElemStyle && !((AreaElemStyle)e).closed) {117 AreaPrototype e = styles.getAreaProto(w); 118 if (e != null && ! e.closed) { 117 119 errors.add( new TestError(this, Severity.WARNING, tr("Area style way is not closed"), NOT_CLOSED, w)); 118 120 } … … 140 142 List<List<Node>> innerWays = joinWays(polygon.getInnerWays()); // Side effect - sets nonClosedWays 141 143 List<List<Node>> outerWays = joinWays(polygon.getOuterWays()); 142 143 144 if (styles != null) { 144 ElemStyle wayStyle = styles.get(r); 145 145 StyleCache sc = styles.get(r); 146 147 AreaElemStyle area = null; 148 for (ElemStyle s : sc.getStyles()) { 149 if (s instanceof AreaElemStyle) { 150 area = (AreaElemStyle) s; 151 break; 152 } 153 } 146 154 // If area style was not found for relation then use style of ways 147 if ( !(wayStyle instanceof AreaElemStyle)) {155 if (area == null) { 148 156 errors.add( new TestError(this, Severity.OTHER, tr("No style in multipolygon relation"), 149 157 NO_STYLE_POLYGON, r)); 150 158 for (Way w : polygon.getOuterWays()) { 151 wayStyle = styles.getArea(w); 152 if(wayStyle != null) { 159 160 for (ElemStyle s : styles.getArea(w).getStyles()) { 161 if (s instanceof AreaElemStyle) { 162 area = (AreaElemStyle) s; 163 break; 164 } 165 } 166 if (area != null) { 153 167 break; 154 168 } … … 156 170 } 157 171 158 if ( wayStyle instanceof AreaElemStyle) {172 if (area != null) { 159 173 for (Way wInner : polygon.getInnerWays()) { 160 ElemStyle innerStyle = styles.get(wInner); 161 if (wayStyle != null && wayStyle.equals(innerStyle)) { 174 AreaElemStyle areaInner = null; 175 for (ElemStyle s : styles.get(wInner).getStyles()) { 176 if (s instanceof AreaElemStyle) { 177 areaInner = (AreaElemStyle) s; 178 break; 179 } 180 } 181 182 if (areaInner != null && area.equals(areaInner)) { 162 183 List<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); 163 184 l.add(r); … … 168 189 } 169 190 for (Way wOuter : polygon.getOuterWays()) { 170 ElemStyle outerStyle = styles.get(wOuter); 171 if (outerStyle instanceof AreaElemStyle && !wayStyle.equals(outerStyle)) { 191 AreaElemStyle areaOuter = null; 192 for (ElemStyle s : styles.get(wOuter).getStyles()) { 193 if (s instanceof AreaElemStyle) { 194 areaOuter = (AreaElemStyle) s; 195 break; 196 } 197 } 198 if (areaOuter != null && !area.equals(areaOuter)) { 172 199 List<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); 173 200 l.add(r); -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3822 r3824 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.awt.Color; 4 5 5 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 import org.openstreetmap.josm.data.osm.Relation;7 7 import org.openstreetmap.josm.data.osm.Way; 8 8 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 9 9 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 10 import org.openstreetmap.josm.tools.Utils; 10 11 11 12 public class AreaElemStyle extends ElemStyle 12 13 { 13 14 public Color color; 14 public boolean closed;15 private LineElemStyle line;16 15 17 public AreaElemStyle (AreaElemStyle a, long maxScale, long minScale) { 18 this.color = a.color; 19 this.closed = a.closed; 20 this.priority = a.priority; 21 this.maxScale = maxScale; 22 this.minScale = minScale; 23 this.conditions = a.conditions; 24 this.line = new LineElemStyle(); 25 this.line.color = a.color; 26 } 27 28 public AreaElemStyle(AreaElemStyle a, LineElemStyle l) 29 { 30 this.color = a.color; 31 this.closed = a.closed; 32 this.priority = a.priority; 33 this.maxScale = a.maxScale; 34 this.minScale = a.minScale; 35 this.conditions = a.conditions; 36 this.line = l; 37 this.code = a.code; 38 } 39 40 public AreaElemStyle() { init(); } 41 42 public void init() 43 { 44 closed = false; 45 color = null; 46 priority = 0; 47 } 48 49 public LineElemStyle getLineStyle() { 50 return line; 16 public AreaElemStyle(long minScale, long maxScale, Color color) { 17 super(minScale, maxScale); 18 this.color = color; 51 19 } 52 20 … … 60 28 } 61 29 } 30 31 @Override 32 public boolean equals(Object obj) { 33 if (obj == null || getClass() != obj.getClass()) 34 return false; 35 if (!super.equals(obj)) 36 return false; 37 return Utils.equal(color, ((AreaElemStyle) obj).color); 38 } 39 40 @Override 41 public int hashCode() { 42 return color.hashCode(); 43 } 44 45 @Override 46 public String toString() { 47 return "AreaElemStyle{" + "color=" + color + '}'; 48 } 62 49 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3805 r3824 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.Collection;5 6 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 import org.openstreetmap.josm.data.osm.OsmUtils;8 5 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 9 6 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 10 import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition;11 7 12 8 abstract public class ElemStyle { … … 15 11 public long maxScale; 16 12 17 public int priority; 18 public String code; 19 Collection<XmlCondition> conditions = null; 13 public ElemStyle(long minScale, long maxScale) { 14 this.minScale = minScale; 15 this.maxScale = maxScale; 16 } 20 17 21 18 @Override 22 19 public boolean equals(Object o) { 23 return (o instanceof ElemStyle) && (((ElemStyle) o).getCode().equals(getCode())); 20 if (!(o instanceof ElemStyle)) 21 return false; 22 ElemStyle s = (ElemStyle) o; 23 return minScale == s.minScale && maxScale == s.maxScale; 24 24 } 25 25 … … 29 29 } 30 30 31 public String getCode() {32 if (code == null) {33 code = "";34 if (conditions != null) {35 for (XmlCondition c: conditions) {36 code += c.toCode();37 }38 }39 }40 return code;41 }42 public boolean check(OsmPrimitive primitive)43 {44 if(conditions == null)45 return true;46 for(XmlCondition c : conditions)47 {48 String k = primitive.get(c.key);49 String bv = OsmUtils.getNamedOsmBoolean(c.boolValue);50 if(k == null || (c.value != null && !k.equals(c.value))51 || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))52 return false;53 }54 return true;55 }56 57 31 public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member); 58 32 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3817 r3824 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.Collections; 9 import java.util.Comparator; 8 10 import java.util.HashSet; 9 11 import java.util.List; … … 14 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.gui.mappaint.xml.AreaPrototype; 19 import org.openstreetmap.josm.gui.mappaint.xml.IconPrototype; 20 import org.openstreetmap.josm.gui.mappaint.xml.LinePrototype; 21 import org.openstreetmap.josm.gui.mappaint.xml.LinemodPrototype; 22 import org.openstreetmap.josm.gui.mappaint.xml.Prototype; 16 23 import org.openstreetmap.josm.tools.FilteredCollection; 17 24 import org.openstreetmap.josm.tools.Predicate; … … 42 49 } 43 50 44 public ElemStyle get(OsmPrimitive osm) { 45 return (!osm.hasKeys()) ? null : ((osm instanceof Node) ? getNode(osm) : get(osm, false)); 51 public static class WayPrototypesRecord { 52 LinePrototype line; 53 List<LinemodPrototype> linemods; 54 AreaPrototype area; 55 56 public List<ElemStyle> createStyles() { 57 List<ElemStyle> ret = new ArrayList<ElemStyle>(); 58 if (area != null) { 59 ret.add(area.createStyle()); 60 } 61 if (line != null) { 62 ret.add(line.createStyle()); 63 } else { 64 if (area != null) { 65 ret.add(LineElemStyle.createSimpleLineStyle(area.color)); 66 } else { 67 ret.add(LineElemStyle.UNTAGGED_WAY); 68 } 69 } 70 71 if (linemods != null) { 72 for (LinemodPrototype p : linemods) { 73 LineElemStyle s = p.createStyle(line.getWidth()); 74 if (p.over) { 75 ret.add(s); 76 } else { 77 ret.add(0, s); 78 } 79 } 80 } 81 return ret; 82 } 46 83 } 47 84 48 public ElemStyle getNode(OsmPrimitive osm) { 49 IconElemStyle icon = null; 85 public StyleCache get(OsmPrimitive osm) { 86 if (osm instanceof Node) { 87 IconPrototype icon = getNode(osm); 88 if (icon == null) 89 return StyleCache.EMPTY_STYLECACHE; 90 return StyleCache.create(icon.createStyle()); 91 } else { 92 WayPrototypesRecord p = get(osm, false); 93 return StyleCache.create(p.createStyles()); 94 } 95 } 96 97 public IconPrototype getNode(OsmPrimitive osm) { 98 IconPrototype icon = null; 50 99 for (StyleSource s : getStyleSources()) { 51 100 icon = s.getNode(osm, icon); … … 54 103 } 55 104 56 public ElemStyle get(OsmPrimitive osm, boolean forceArea) { 57 if (!osm.hasKeys()) 58 return null; 59 AreaElemStyle area = null; 60 LineElemStyle line = null; 61 ElemStyle result = null; 105 private WayPrototypesRecord get(OsmPrimitive osm, boolean forceArea) { 106 WayPrototypesRecord p = new WayPrototypesRecord(); 62 107 for (StyleSource s : getStyleSources()) { 63 result = s.get(osm, forceArea || !(osm instanceof Way) || ((Way) osm).isClosed(), area, line); 64 if (result instanceof LineElemStyle) { 65 area = null; 66 line = (LineElemStyle) result; 67 } else if (result instanceof AreaElemStyle) { 68 area = (AreaElemStyle) result; 69 if (area.getLineStyle() != null) { 70 line = area.getLineStyle(); 71 } 72 } else if (result != null) 73 throw new AssertionError(); 108 s.get(osm, forceArea || !(osm instanceof Way) || ((Way) osm).isClosed(), p); 74 109 } 75 return result;110 return p; 76 111 } 77 112 … … 92 127 } 93 128 94 public ElemStyle getArea(Way osm) {129 public StyleCache getArea(Way osm) { 95 130 if (osm.hasKeys()) { 96 131 /* force area mode also for unclosed ways */ 97 ElemStyle style = get(osm, true); 98 if (style != null && style instanceof AreaElemStyle) { 99 return style; 100 } 132 WayPrototypesRecord p = get(osm, true); 133 if (p.area != null) 134 return StyleCache.create(p.createStyles()); 135 } 136 return StyleCache.EMPTY_STYLECACHE; 137 } 138 139 public AreaPrototype getAreaProto(Way osm) { 140 if (osm.hasKeys()) { 141 /* force area mode also for unclosed ways */ 142 WayPrototypesRecord p = get(osm, true); 143 if (p.area != null) 144 return p.area; 101 145 } 102 146 return null; … … 104 148 105 149 public IconElemStyle getIcon(OsmPrimitive osm) { 106 return osm.hasKeys() ? (IconElemStyle) getNode(osm) : null; 150 if (!osm.hasKeys()) 151 return null; 152 NodeElemStyle icon = getNode(osm).createStyle(); 153 if (icon instanceof IconElemStyle) { 154 return (IconElemStyle) icon; 155 } 156 return null; 107 157 } 108 158 -
trunk/src/org/openstreetmap/josm/gui/mappaint/IconElemStyle.java
r3805 r3824 10 10 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 11 11 12 public class IconElemStyle extends ElemStyle 13 { 12 public class IconElemStyle extends NodeElemStyle { 14 13 public ImageIcon icon; 15 14 private ImageIcon disabledIcon; 16 public boolean annotate;17 15 18 public IconElemStyle (IconElemStyle i, long maxScale, long minScale) { 19 this.icon = i.icon; 20 this.annotate = i.annotate; 21 this.priority = i.priority; 22 this.maxScale = maxScale; 23 this.minScale = minScale; 24 this.conditions = i.conditions; 25 } 26 public IconElemStyle() { init(); } 27 28 public void init() { 29 icon = null; 30 priority = 0; 31 annotate = true; 16 public IconElemStyle(long minScale, long maxScale, ImageIcon icon) { 17 super(minScale, maxScale); 18 this.icon = icon; 32 19 } 33 20 … … 39 26 return disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(icon.getImage())); 40 27 } 28 41 29 @Override 42 30 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings settings, MapPainter painter, boolean selected, boolean member) { 43 31 if (painter.isShowIcons()) { 44 32 Node n = (Node) primitive; 45 String name = painter.isShowNames() && annotate?painter.getNodeName(n):null; 46 painter.drawNodeIcon(n, (painter.isInactive() || n.isDisabled())?getDisabledIcon():icon, selected, member, name); 33 painter.drawNodeIcon(n, (painter.isInactive() || n.isDisabled())?getDisabledIcon():icon, selected, member, getName(n, painter)); 47 34 } else { 48 35 SimpleNodeElemStyle.INSTANCE.paintPrimitive(primitive, settings, painter, selected, member); … … 50 37 51 38 } 39 40 @Override 41 public boolean equals(Object obj) { 42 if (obj == null || getClass() != obj.getClass()) 43 return false; 44 if (!super.equals(obj)) 45 return false; 46 47 final IconElemStyle other = (IconElemStyle) obj; 48 // we should get the same image object due to caching 49 return this.icon.getImage() == other.icon.getImage(); 50 } 51 52 @Override 53 public int hashCode() { 54 return icon.getImage().hashCode(); 55 } 56 57 @Override 58 public String toString() { 59 return "IconElemStyle{" + "icon=" + icon + '}'; 60 } 52 61 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3805 r3824 3 3 4 4 import java.awt.Color; 5 import java.util. Collection;5 import java.util.Arrays; 6 6 7 7 import org.openstreetmap.josm.data.osm.Node; … … 11 11 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 12 12 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 13 import org.openstreetmap.josm.tools. I18n;13 import org.openstreetmap.josm.tools.Utils; 14 14 15 public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle>{15 public class LineElemStyle extends ElemStyle { 16 16 17 17 public static final LineElemStyle UNTAGGED_WAY; 18 18 19 19 static { 20 UNTAGGED_WAY = new LineElemStyle(); 20 UNTAGGED_WAY = new LineElemStyle(0, Long.MAX_VALUE, -1, 0, PaintColors.UNTAGGED.get(), new float[0], null); 21 } 22 23 public static LineElemStyle createSimpleLineStyle(Color color) { 24 return new LineElemStyle(0, Long.MAX_VALUE, -1, 0, color, new float[0], null); 21 25 } 22 26 … … 27 31 public Color dashedColor; 28 32 29 public boolean over; 30 public enum WidthMode { ABSOLUTE, PERCENT, OFFSET } 31 public WidthMode widthMode; 32 33 public Collection<LineElemStyle> overlays; 34 35 public LineElemStyle(LineElemStyle s, long maxScale, long minScale) { 36 this.width = s.width; 37 this.realWidth = s.realWidth; 38 this.color = s.color; 39 this.dashed = s.dashed; 40 this.dashedColor = s.dashedColor; 41 this.over = s.over; 42 this.widthMode = s.widthMode; 43 44 this.priority = s.priority; 45 this.maxScale = maxScale; 46 this.minScale = minScale; 47 this.conditions = s.conditions; 48 } 49 50 public LineElemStyle(LineElemStyle s, Collection<LineElemStyle> overlays) { 51 this.width = s.width; 52 this.realWidth = s.realWidth; 53 this.color = s.color; 54 this.dashed = s.dashed; 55 this.dashedColor = s.dashedColor; 56 this.over = s.over; 57 this.widthMode = s.widthMode; 58 59 this.priority = s.priority; 60 this.maxScale = s.maxScale; 61 this.minScale = s.minScale; 62 this.conditions = s.conditions; 63 64 this.overlays = overlays; 65 this.code = s.code; 66 for (LineElemStyle o : overlays) { 67 this.code += o.code; 68 } 69 } 70 71 public LineElemStyle() { init(); } 72 73 public void init() 74 { 75 width = -1; 76 realWidth = 0; 77 dashed = new float[0]; 78 dashedColor = null; 79 priority = 0; 80 color = PaintColors.UNTAGGED.get(); 81 over = true; // only used for line modifications 82 widthMode = WidthMode.ABSOLUTE; 83 overlays = null; 84 } 85 86 // get width for overlays 87 public int getWidth(int ref) 88 { 89 int res; 90 if(widthMode == WidthMode.ABSOLUTE) { 91 res = width; 92 } else if(widthMode == WidthMode.OFFSET) { 93 res = ref + width; 94 } else 95 { 96 if(width < 0) { 97 res = 0; 98 } else { 99 res = ref*width/100; 100 } 101 } 102 return res <= 0 ? 1 : res; 103 } 104 105 public int compareTo(LineElemStyle s) { 106 if(s.priority != priority) 107 return s.priority > priority ? 1 : -1; 108 if(!over && s.over) 109 return -1; 110 // we have no idea how to order other objects :-) 111 return 0; 112 } 113 114 public float[] getDashed() { 115 return dashed; 116 } 117 118 public void setDashed(float[] dashed) { 119 if (dashed.length == 0) { 120 this.dashed = dashed; 121 return; 122 } 123 124 boolean found = false; 125 for (int i=0; i<dashed.length; i++) { 126 if (dashed[i] > 0) { 127 found = true; 128 } 129 if (dashed[i] < 0) { 130 System.out.println(I18n.tr("Illegal dash pattern, values must be positive")); 131 } 132 } 133 if (found) { 134 this.dashed = dashed; 135 } else { 136 System.out.println(I18n.tr("Illegal dash pattern, at least one value must be > 0")); 137 } 33 public LineElemStyle(long minScale, long maxScale, int width, int realWidth, Color color, float[] dashed, Color dashedColor) { 34 super(minScale, maxScale); 35 setWidth(width); 36 this.realWidth = realWidth; 37 this.color = color; 38 this.dashed = dashed; 39 this.dashedColor = dashedColor; 138 40 } 139 41 … … 189 91 } 190 92 191 /* draw overlays under the way */192 if(overlays != null) {193 for(LineElemStyle s : overlays) {194 if(!s.over) {195 painter.drawWay(w,196 markColor != null ?197 (s.color != null ? new Color(markColor.getRed(), markColor.getGreen(), markColor.getBlue(), s.color.getAlpha()) : markColor) :198 s.color,199 s.getWidth(myWidth),200 s.getDashed(),201 w.isDisabled() ? paintSettings.getInactiveColor() : s.dashedColor,202 false, false, false);203 }204 }205 }206 207 /* draw the way */208 93 painter.drawWay(w, markColor != null ? markColor : color, myWidth, dashed, myDashedColor, showDirection, 209 94 selected ? false : reversedDirection, showOnlyHeadArrowOnly); 210 211 /* draw overlays above the way */212 if(overlays != null) {213 for(LineElemStyle s : overlays) {214 if(s.over) {215 painter.drawWay(w,216 markColor != null ?217 (s.color != null ? new Color(markColor.getRed(), markColor.getGreen(), markColor.getBlue(), s.color.getAlpha()) : markColor) :218 s.color,219 s.getWidth(myWidth),220 s.getDashed(),221 s.dashedColor,222 false, false, false);223 }224 }225 }226 95 227 96 if(paintSettings.isShowOrderNumber()) { … … 247 116 this.width = width; 248 117 } 118 119 @Override 120 public boolean equals(Object obj) { 121 if (obj == null || getClass() != obj.getClass()) 122 return false; 123 if (!super.equals(obj)) 124 return false; 125 final LineElemStyle other = (LineElemStyle) obj; 126 return width == other.width && 127 realWidth == other.realWidth && 128 Utils.equal(color, other.color) && 129 Arrays.equals(dashed, other.dashed) && 130 Utils.equal(dashedColor, other.dashedColor); 131 } 132 133 @Override 134 public int hashCode() { 135 int hash = 3; 136 hash = 29 * hash + this.width; 137 hash = 29 * hash + this.realWidth; 138 hash = 29 * hash + this.color.hashCode(); 139 hash = 29 * hash + Arrays.hashCode(this.dashed); 140 hash = 29 * hash + (this.dashedColor != null ? this.dashedColor.hashCode() : 0); 141 return hash; 142 } 143 144 @Override 145 public String toString() { 146 return "LineElemStyle{" + "width=" + width + " realWidth=" + realWidth + " color=" + color + " dashed=" + Arrays.toString(dashed) + " dashedColor=" + dashedColor + '}'; 147 } 249 148 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/SimpleNodeElemStyle.java
r3804 r3824 8 8 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 9 9 10 public class SimpleNodeElemStyle extends ElemStyle {10 public class SimpleNodeElemStyle extends NodeElemStyle { 11 11 12 12 public static final SimpleNodeElemStyle INSTANCE = new SimpleNodeElemStyle(); 13 13 14 14 private SimpleNodeElemStyle() { 15 minScale = 0;16 maxScale = 1500;15 super(0, Long.MAX_VALUE); 16 annotate = true; 17 17 } 18 18 19 private static finalint max(int a, int b, int c, int d) {19 private static int max(int a, int b, int c, int d) { 20 20 return Math.max(Math.max(a, b), Math.max(c, d)); 21 21 } … … 25 25 boolean selected, boolean member) { 26 26 Node n = (Node)primitive; 27 String name = painter.isShowNames()?painter.getNodeName(n):null;28 29 27 30 28 if (n.isHighlighted()) { 31 painter.drawNode(n, settings.getHighlightColor(), settings.getSelectedNodeSize(), settings.isFillSelectedNode(), name);29 painter.drawNode(n, settings.getHighlightColor(), settings.getSelectedNodeSize(), settings.isFillSelectedNode(), getName(n, painter)); 32 30 } else { 33 31 … … 65 63 settings.isFillUnselectedNode(); 66 64 67 painter.drawNode(n, color, size, fill, name);65 painter.drawNode(n, color, size, fill, getName(n, painter)); 68 66 } 69 67 } 70 71 68 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r3817 r3824 15 15 import org.openstreetmap.josm.data.osm.OsmUtils; 16 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.gui.mappaint.ElemStyles.WayPrototypesRecord; 18 import org.openstreetmap.josm.gui.mappaint.xml.AreaPrototype; 19 import org.openstreetmap.josm.gui.mappaint.xml.IconPrototype; 20 import org.openstreetmap.josm.gui.mappaint.xml.LinePrototype; 21 import org.openstreetmap.josm.gui.mappaint.xml.LinemodPrototype; 22 import org.openstreetmap.josm.gui.mappaint.xml.Prototype; 17 23 import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition; 18 24 import org.openstreetmap.josm.gui.preferences.SourceEntry; … … 20 26 public class StyleSource extends SourceEntry { 21 27 22 public final HashMap<String, Icon ElemStyle> icons = new HashMap<String, IconElemStyle>();23 public final HashMap<String, Line ElemStyle> lines = new HashMap<String, LineElemStyle>();24 public final HashMap<String, Line ElemStyle> modifiers = new HashMap<String, LineElemStyle>();25 public final HashMap<String, Area ElemStyle> areas = new HashMap<String, AreaElemStyle>();26 public final LinkedList<Icon ElemStyle> iconsList = new LinkedList<IconElemStyle>();27 public final LinkedList<Line ElemStyle> linesList = new LinkedList<LineElemStyle>();28 public final LinkedList<Line ElemStyle> modifiersList = new LinkedList<LineElemStyle>();29 public final LinkedList<Area ElemStyle> areasList = new LinkedList<AreaElemStyle>();28 public final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>(); 29 public final HashMap<String, LinePrototype> lines = new HashMap<String, LinePrototype>(); 30 public final HashMap<String, LinemodPrototype> modifiers = new HashMap<String, LinemodPrototype>(); 31 public final HashMap<String, AreaPrototype> areas = new HashMap<String, AreaPrototype>(); 32 public final LinkedList<IconPrototype> iconsList = new LinkedList<IconPrototype>(); 33 public final LinkedList<LinePrototype> linesList = new LinkedList<LinePrototype>(); 34 public final LinkedList<LinemodPrototype> modifiersList = new LinkedList<LinemodPrototype>(); 35 public final LinkedList<AreaPrototype> areasList = new LinkedList<AreaPrototype>(); 30 36 31 37 public boolean hasError = false; … … 39 45 } 40 46 41 public Icon ElemStyle getNode(OsmPrimitive primitive, IconElemStyle icon) {47 public IconPrototype getNode(OsmPrimitive primitive, IconPrototype icon) { 42 48 for (String key : primitive.keySet()) { 43 49 String val = primitive.get(key); 44 Icon ElemStyle style;50 IconPrototype style; 45 51 if ((style = icons.get("n" + key + "=" + val)) != null) { 46 52 if (icon == null || style.priority >= icon.priority) { … … 59 65 } 60 66 } 61 for (Icon ElemStyle s : iconsList) {67 for (IconPrototype s : iconsList) { 62 68 if ((icon == null || s.priority >= icon.priority) && s.check(primitive)) { 63 69 icon = s; … … 72 78 * multipolygon relations. 73 79 */ 74 public ElemStyle get(OsmPrimitive primitive, boolean closed, AreaElemStyle area, LineElemStyle line) {80 public void get(OsmPrimitive primitive, boolean closed, WayPrototypesRecord p) { 75 81 String lineIdx = null; 76 HashMap<String, Line ElemStyle> overlayMap = new HashMap<String, LineElemStyle>();82 HashMap<String, LinemodPrototype> overlayMap = new HashMap<String, LinemodPrototype>(); 77 83 for (String key : primitive.keySet()) { 78 84 String val = primitive.get(key); 79 AreaElemStyle styleArea; 80 LineElemStyle styleLine; 85 AreaPrototype styleArea; 86 LinePrototype styleLine; 87 LinemodPrototype styleLinemod; 81 88 String idx = "n" + key + "=" + val; 82 if ((styleArea = areas.get(idx)) != null && ( area == null || styleArea.priority >=area.priority) && (closed || !styleArea.closed)) {83 area = styleArea;84 } 85 if ((styleLine = lines.get(idx)) != null && ( line == null || styleLine.priority >=line.priority)) {86 line = styleLine;89 if ((styleArea = areas.get(idx)) != null && (p.area == null || styleArea.priority >= p.area.priority) && (closed || !styleArea.closed)) { 90 p.area = styleArea; 91 } 92 if ((styleLine = lines.get(idx)) != null && (p.line == null || styleLine.priority >= p.line.priority)) { 93 p.line = styleLine; 87 94 lineIdx = idx; 88 95 } 89 if ((styleLine = modifiers.get(idx)) != null) {90 overlayMap.put(idx, styleLine );96 if ((styleLinemod = modifiers.get(idx)) != null) { 97 overlayMap.put(idx, styleLinemod); 91 98 } 92 99 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 93 if ((styleArea = areas.get(idx)) != null && ( area == null || styleArea.priority >=area.priority) && (closed || !styleArea.closed)) {94 area = styleArea;95 } 96 if ((styleLine = lines.get(idx)) != null && ( line == null || styleLine.priority >=line.priority)) {97 line = styleLine;100 if ((styleArea = areas.get(idx)) != null && (p.area == null || styleArea.priority >= p.area.priority) && (closed || !styleArea.closed)) { 101 p.area = styleArea; 102 } 103 if ((styleLine = lines.get(idx)) != null && (p.line == null || styleLine.priority >= p.line.priority)) { 104 p.line = styleLine; 98 105 lineIdx = idx; 99 106 } 100 if ((styleLine = modifiers.get(idx)) != null) {101 overlayMap.put(idx, styleLine );107 if ((styleLinemod = modifiers.get(idx)) != null) { 108 overlayMap.put(idx, styleLinemod); 102 109 } 103 110 idx = "x" + key; 104 if ((styleArea = areas.get(idx)) != null && ( area == null || styleArea.priority >=area.priority) && (closed || !styleArea.closed)) {105 area = styleArea;106 } 107 if ((styleLine = lines.get(idx)) != null && ( line == null || styleLine.priority >=line.priority)) {108 line = styleLine;111 if ((styleArea = areas.get(idx)) != null && (p.area == null || styleArea.priority >= p.area.priority) && (closed || !styleArea.closed)) { 112 p.area = styleArea; 113 } 114 if ((styleLine = lines.get(idx)) != null && (p.line == null || styleLine.priority >= p.line.priority)) { 115 p.line = styleLine; 109 116 lineIdx = idx; 110 117 } 111 if ((styleLine = modifiers.get(idx)) != null) {112 overlayMap.put(idx, styleLine );113 } 114 } 115 for (Area ElemStyle s : areasList) {116 if (( area == null || s.priority >=area.priority) && (closed || !s.closed) && s.check(primitive)) {117 area = s;118 } 119 } 120 for (Line ElemStyle s : linesList) {121 if (( line == null || s.priority >=line.priority) && s.check(primitive)) {122 line = s;123 } 124 } 125 for (Line ElemStyle s : modifiersList) {118 if ((styleLinemod = modifiers.get(idx)) != null) { 119 overlayMap.put(idx, styleLinemod); 120 } 121 } 122 for (AreaPrototype s : areasList) { 123 if ((p.area == null || s.priority >= p.area.priority) && (closed || !s.closed) && s.check(primitive)) { 124 p.area = s; 125 } 126 } 127 for (LinePrototype s : linesList) { 128 if ((p.line == null || s.priority >= p.line.priority) && s.check(primitive)) { 129 p.line = s; 130 } 131 } 132 for (LinemodPrototype s : modifiersList) { 126 133 if (s.check(primitive)) { 127 134 overlayMap.put(s.getCode(), s); … … 129 136 } 130 137 overlayMap.remove(lineIdx); // do not use overlay if linestyle is from the same rule (example: railway=tram) 131 if (!overlayMap.isEmpty() && line != null) {132 List<Line ElemStyle> tmp = new LinkedList<LineElemStyle>();133 if ( line.overlays != null) {134 tmp.addAll( line.overlays);138 if (!overlayMap.isEmpty() && p.line != null) { 139 List<LinemodPrototype> tmp = new LinkedList<LinemodPrototype>(); 140 if (p.linemods != null) { 141 tmp.addAll(p.linemods); 135 142 } 136 143 tmp.addAll(overlayMap.values()); 137 144 Collections.sort(tmp); 138 line = new LineElemStyle(line, tmp); 139 } 140 if (area != null) { 141 if (line != null) { 142 return new AreaElemStyle(area, line); 143 } else { 144 return area; 145 } 146 } 147 return line; 145 p.linemods = tmp; 146 } 148 147 } 149 148 … … 155 154 String key = iterator.next(); 156 155 String val = o.get(key); 157 Area ElemStyle s = areas.get("n" + key + "=" + val);156 AreaPrototype s = areas.get("n" + key + "=" + val); 158 157 if (s == null || (s.closed && noclosed)) { 159 158 s = areas.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val)); … … 166 165 } 167 166 } 168 for (Area ElemStyle s : areasList) {167 for (AreaPrototype s : areasList) { 169 168 if (!(s.closed && noclosed) && s.check(o)) { 170 169 return true; … … 179 178 } 180 179 181 public void add(XmlCondition c, Collection<XmlCondition> conditions, LineElemStyle style) { 182 if(conditions != null) 183 { 184 style.conditions = conditions; 185 linesList.add(style); 186 } 187 else { 188 String key = c.getKey(); 189 style.code = key; 190 lines.put(key, style); 191 } 192 } 193 194 public void addModifier(XmlCondition c, Collection<XmlCondition> conditions, LineElemStyle style) { 195 if(conditions != null) 196 { 197 style.conditions = conditions; 198 modifiersList.add(style); 199 } 200 else 201 { 202 String key = c.getKey(); 203 style.code = key; 204 modifiers.put(key, style); 205 } 206 } 207 208 public void add(XmlCondition c, Collection<XmlCondition> conditions, AreaElemStyle style) { 209 if(conditions != null) 210 { 211 style.conditions = conditions; 212 areasList.add(style); 213 } 214 else 215 { 216 String key = c.getKey(); 217 style.code = key; 218 areas.put(key, style); 219 } 220 } 221 222 public void add(XmlCondition c, Collection<XmlCondition> conditions, IconElemStyle style) { 223 if(conditions != null) 224 { 225 style.conditions = conditions; 226 iconsList.add(style); 227 } 228 else 229 { 230 String key = c.getKey(); 231 style.code = key; 232 icons.put(key, style); 233 } 234 } 180 public void add(XmlCondition c, Collection<XmlCondition> conditions, Prototype prot) { 181 if(conditions != null) 182 { 183 prot.conditions = conditions; 184 if (prot instanceof IconPrototype) { 185 iconsList.add((IconPrototype) prot); 186 } else if (prot instanceof LinemodPrototype) { 187 modifiersList.add((LinemodPrototype) prot); 188 } else if (prot instanceof LinePrototype) { 189 linesList.add((LinePrototype) prot); 190 } else if (prot instanceof AreaPrototype) { 191 areasList.add((AreaPrototype) prot); 192 } else 193 throw new RuntimeException(); 194 } 195 else { 196 String key = c.getKey(); 197 prot.code = key; 198 if (prot instanceof IconPrototype) { 199 icons.put(key, (IconPrototype) prot); 200 } else if (prot instanceof LinemodPrototype) { 201 modifiers.put(key, (LinemodPrototype) prot); 202 } else if (prot instanceof LinePrototype) { 203 lines.put(key, (LinePrototype) prot); 204 } else if (prot instanceof AreaPrototype) { 205 areas.put(key, (AreaPrototype) prot); 206 } else 207 throw new RuntimeException(); 208 } 209 } 235 210 236 211 /** -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java
r3805 r3824 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;12 import org.openstreetmap.josm.gui.mappaint.IconElemStyle;13 import org.openstreetmap.josm.gui.mappaint.LineElemStyle;14 11 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 15 12 import org.openstreetmap.josm.gui.mappaint.StyleSource; … … 31 28 long scaleMax; 32 29 long scaleMin; 33 Line ElemStyle line = new LineElemStyle();34 Line ElemStyle linemod = new LineElemStyle();35 Area ElemStyle area = new AreaElemStyle();36 Icon ElemStyle icon = new IconElemStyle();30 LinePrototype line = new LinePrototype(); 31 LinemodPrototype linemod = new LinemodPrototype(); 32 AreaPrototype area = new AreaPrototype(); 33 IconPrototype icon = new IconPrototype(); 37 34 public void init() 38 35 { … … 81 78 } 82 79 83 private void startElementLine(String qName, Attributes atts, Line ElemStyle line) {80 private void startElementLine(String qName, Attributes atts, LinePrototype line) { 84 81 for (int count=0; count<atts.getLength(); count++) 85 82 { … … 87 84 { 88 85 String val = atts.getValue(count); 89 if(val.startsWith("+")) 90 { 91 line.setWidth(Integer.parseInt(val.substring(1))); 92 line.widthMode = LineElemStyle.WidthMode.OFFSET; 93 } 94 else if(val.startsWith("-")) 95 { 96 line.setWidth(Integer.parseInt(val)); 97 line.widthMode = LineElemStyle.WidthMode.OFFSET; 98 } 99 else if(val.endsWith("%")) 100 { 101 line.setWidth(Integer.parseInt(val.substring(0, val.length()-1))); 102 line.widthMode = LineElemStyle.WidthMode.PERCENT; 103 } else { 86 if (! (val.startsWith("+") || val.startsWith("-") || val.endsWith("%"))) { 104 87 line.setWidth(Integer.parseInt(val)); 105 88 } … … 130 113 } else if(atts.getQName(count).equals("priority")) { 131 114 line.priority = Integer.parseInt(atts.getValue(count)); 115 } else if (!(atts.getQName(count).equals("mode") && line instanceof LinemodPrototype)){ 116 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!"); 117 } 118 } 119 } 120 121 private void startElementLinemod(String qName, Attributes atts, LinemodPrototype line) { 122 startElementLine(qName, atts, line); 123 for (int count=0; count<atts.getLength(); count++) 124 { 125 if(atts.getQName(count).equals("width")) 126 { 127 String val = atts.getValue(count); 128 if(val.startsWith("+")) 129 { 130 line.setWidth(Integer.parseInt(val.substring(1))); 131 line.widthMode = LinemodPrototype.WidthMode.OFFSET; 132 } 133 else if(val.startsWith("-")) 134 { 135 line.setWidth(Integer.parseInt(val)); 136 line.widthMode = LinemodPrototype.WidthMode.OFFSET; 137 } 138 else if(val.endsWith("%")) 139 { 140 line.setWidth(Integer.parseInt(val.substring(0, val.length()-1))); 141 line.widthMode = LinemodPrototype.WidthMode.PERCENT; 142 } else { 143 line.setWidth(Integer.parseInt(val)); 144 } 132 145 } else if(atts.getQName(count).equals("mode")) { 133 146 line.over = !atts.getValue(count).equals("under"); 134 } else {135 error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");136 147 } 137 148 } … … 189 200 hadLine = inLine = true; 190 201 startElementLine(qName, atts, rule.line); 191 if(rule.line.widthMode != LineElemStyle.WidthMode.ABSOLUTE) {192 error("Relative widths are not possible for normal lines");193 rule.line.widthMode = LineElemStyle.WidthMode.ABSOLUTE;194 }195 202 } 196 203 else if (qName.equals("linemod")) 197 204 { 198 205 hadLineMod = inLineMod = true; 199 startElementLine (qName, atts, rule.linemod);206 startElementLinemod(qName, atts, rule.linemod); 200 207 } 201 208 else if (qName.equals("icon")) … … 245 252 { 246 253 style.add(rule.cond, rule.conditions, 247 new Line ElemStyle(rule.line, rule.scaleMax, rule.scaleMin));254 new LinePrototype(rule.line, rule.scaleMax, rule.scaleMin)); 248 255 } 249 256 if(hadLineMod) 250 257 { 251 style.add Modifier(rule.cond, rule.conditions,252 new Line ElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin));258 style.add(rule.cond, rule.conditions, 259 new LinemodPrototype(rule.linemod, rule.scaleMax, rule.scaleMin)); 253 260 } 254 261 if(hadIcon) 255 262 { 256 263 style.add(rule.cond, rule.conditions, 257 new Icon ElemStyle(rule.icon, rule.scaleMax, rule.scaleMin));264 new IconPrototype(rule.icon, rule.scaleMax, rule.scaleMin)); 258 265 } 259 266 if(hadArea) 260 267 { 261 268 style.add(rule.cond, rule.conditions, 262 new Area ElemStyle(rule.area, rule.scaleMax, rule.scaleMin));269 new AreaPrototype(rule.area, rule.scaleMax, rule.scaleMin)); 263 270 } 264 271 inRule = false;
Note:
See TracChangeset
for help on using the changeset viewer.