Changeset 3803 in josm
- Timestamp:
- 2011-01-22T19:27:33+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r3800 r3803 34 34 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 35 35 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 36 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 36 37 import org.openstreetmap.josm.gui.mappaint.IconElemStyle; 37 38 import org.openstreetmap.josm.gui.mappaint.LineElemStyle; 38 39 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 39 40 import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle; 40 import org.openstreetmap.josm.gui.mappaint.StyleSource;41 41 42 42 public class MapPaintVisitor implements PaintVisitor { … … 49 49 private boolean drawRestriction; 50 50 private boolean leftHandTraffic; 51 private StyleSourcestyles;51 private ElemStyles styles; 52 52 private double circum; 53 53 private double dist; … … 535 535 zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay", false); 536 536 circum = nc.getDist100Pixel(); 537 styles = MapPaintStyles.getStyles() .getStyleSet();537 styles = MapPaintStyles.getStyles(); 538 538 drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon", true); 539 539 drawRestriction = Main.pref.getBoolean("mappaint.restriction", true); -
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r3799 r3803 24 24 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 25 25 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 26 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 26 27 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 27 import org.openstreetmap.josm.gui.mappaint.StyleSource;28 28 29 29 public class MultipolygonTest extends Test { … … 41 41 protected static final int NO_STYLE_POLYGON = 1611; 42 42 43 private static StyleSourcestyles;43 private static ElemStyles styles; 44 44 45 45 private final List<List<Node>> nonClosedWays = new ArrayList<List<Node>>(); … … 52 52 @Override 53 53 public void initialize() throws Exception { 54 styles = MapPaintStyles.getStyles() .getStyleSet();54 styles = MapPaintStyles.getStyles(); 55 55 } 56 56 -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3719 r3803 45 45 } 46 46 47 public ElemStyle getLineStyle() {47 public LineElemStyle getLineStyle() { 48 48 return line; 49 49 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java
r3719 r3803 15 15 public class ElemStyleHandler extends DefaultHandler 16 16 { 17 boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;18 boolean hadLine, hadLineMod, hadIcon, hadArea;19 ElemStyles styles;20 String styleName; 21 RuleElem rule = new RuleElem();17 private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin; 18 private boolean hadLine, hadLineMod, hadIcon, hadArea; 19 private RuleElem rule = new RuleElem(); 20 21 StyleSource style; 22 22 23 23 static class RuleElem { … … 43 43 } 44 44 45 public ElemStyleHandler(St ring name) {46 styleName = name;45 public ElemStyleHandler(StyleSource style) { 46 this.style = style; 47 47 inDoc=inRule=inCondition=inLine=inIcon=inArea=false; 48 48 rule.init(); 49 styles = MapPaintStyles.getStyles();50 49 } 51 50 … … 54 53 int i = colString.indexOf("#"); 55 54 Color ret; 56 if (i < 0) {57 ret = Main.pref.getColor("mappaint."+style Name+"."+colString, Color.red);55 if (i < 0) { 56 ret = Main.pref.getColor("mappaint."+style.getPrefName()+"."+colString, Color.red); 58 57 } else if(i == 0) { 59 58 ret = ColorHelper.html2color(colString); 60 59 } else { 61 ret = Main.pref.getColor("mappaint."+style Name+"."+colString.substring(0,i),60 ret = Main.pref.getColor("mappaint."+style.getPrefName()+"."+colString.substring(0,i), 62 61 ColorHelper.html2color(colString.substring(i))); 63 62 } … … 74 73 75 74 private void error(String message) { 76 System.out.println(style Name+ " (" + rule.rule.key + "=" + rule.rule.value + "): " + message);75 System.out.println(style.getDisplayString() + " (" + rule.rule.key + "=" + rule.rule.value + "): " + message); 77 76 } 78 77 … … 141 140 } else if (qName.equals("rules")) 142 141 { 143 if(styleName == null) 144 { 145 String n = atts.getValue("name"); 146 if(n == null) { 147 n = "standard"; 148 } 149 styleName = n; 142 if (style.name == null) { 143 style.name = atts.getValue("name"); 144 } 145 if (style.shortdescription == null) { 146 style.shortdescription = atts.getValue("shortdescription"); 150 147 } 151 148 } … … 203 200 { 204 201 if (atts.getQName(count).equals("src")) { 205 ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), style Name);202 ImageIcon icon = MapPaintStyles.getIcon(atts.getValue(count), style.getPrefName()); 206 203 hadIcon = (icon != null); 207 204 rule.icon.icon = icon; … … 242 239 if(hadLine) 243 240 { 244 style s.add(styleName,rule.rule, rule.rules,241 style.add(rule.rule, rule.rules, 245 242 new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin)); 246 243 } 247 244 if(hadLineMod) 248 245 { 249 style s.addModifier(styleName,rule.rule, rule.rules,246 style.addModifier(rule.rule, rule.rules, 250 247 new LineElemStyle(rule.linemod, rule.scaleMax, rule.scaleMin)); 251 248 } 252 249 if(hadIcon) 253 250 { 254 style s.add(styleName,rule.rule, rule.rules,251 style.add(rule.rule, rule.rules, 255 252 new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin)); 256 253 } 257 254 if(hadArea) 258 255 { 259 style s.add(styleName,rule.rule, rule.rules,256 style.add(rule.rule, rule.rules, 260 257 new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin)); 261 258 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3799 r3803 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 6 import java.util.ArrayList; 4 7 import java.util.Collection; 5 import java.util.Collections; 6 import java.util.HashMap; 7 import java.util.Iterator; 8 import java.util.LinkedList; 8 import java.util.HashSet; 9 9 import java.util.List; 10 import java.util.Set; 10 11 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.data.osm.Node; 13 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.OsmUtils;15 15 import org.openstreetmap.josm.data.osm.Way; 16 import org.openstreetmap.josm.tools.FilteredCollection; 17 import org.openstreetmap.josm.tools.Predicate; 16 18 17 public class ElemStyles 18 { 19 HashMap<String, StyleSource> styleSet; 19 public class ElemStyles { 20 private List<StyleSource> styleSources; 21 20 22 public ElemStyles() 21 23 { 22 styleS et = new HashMap<String,StyleSource>();24 styleSources = new ArrayList<StyleSource>(); 23 25 } 24 26 25 public void add(String name, Rule r, Collection<Rule> rules, LineElemStyle style) 26 { 27 if(rules != null) 28 { 29 style.rules = rules; 30 getStyleSet(name, true).linesList.add(style); 31 } 32 else 33 { 34 String key = r.getKey(); 35 style.code = key; 36 getStyleSet(name, true).lines.put(key, style); 27 public void add(StyleSource style) { 28 styleSources.add(style); 29 } 30 31 public Collection<StyleSource> getStyleSources() { 32 return new FilteredCollection<StyleSource>(styleSources, new Predicate<StyleSource>() { 33 34 String name = Main.pref.get("mappaint.style", "standard"); 35 36 @Override 37 public boolean evaluate(StyleSource s) { 38 return equal(s.getPrefName(), name); 39 } 40 41 }); 42 } 43 44 public ElemStyle get(OsmPrimitive osm) { 45 return get(osm, false); 46 } 47 48 public ElemStyle get(OsmPrimitive osm, boolean forceArea) { 49 if (!osm.hasKeys()) 50 return null; 51 52 if (osm instanceof Node) { 53 IconElemStyle icon = null; 54 for (StyleSource s : getStyleSources()) { 55 icon = s.getNode(osm, icon); 56 } 57 return icon; 58 } else { 59 boolean noclosed; 60 if (forceArea) { 61 noclosed = false; 62 } else { 63 noclosed = osm instanceof Way && !((Way) osm).isClosed(); 64 } 65 AreaElemStyle area = null; 66 LineElemStyle line = null; 67 ElemStyle result = null; 68 for (StyleSource s : getStyleSources()) { 69 result = s.get(osm, noclosed, area, line); 70 if (result instanceof LineElemStyle) { 71 area = null; 72 line = (LineElemStyle) result; 73 } else if (result instanceof AreaElemStyle) { 74 area = (AreaElemStyle) result; 75 if (area.getLineStyle() != null) { 76 line = area.getLineStyle(); 77 } 78 } else if (result != null) 79 throw new AssertionError(); 80 } 81 return result; 37 82 } 38 83 } 39 84 40 public void addModifier(String name, Rule r, Collection<Rule> rules, LineElemStyle style) 41 { 42 if(rules != null) 43 { 44 style.rules = rules; 45 getStyleSet(name, true).modifiersList.add(style); 85 public boolean hasAreas() { 86 for (StyleSource s : getStyleSources()) { 87 if (s.hasAreas()) 88 return true; 46 89 } 47 else 48 { 49 String key = r.getKey(); 50 style.code = key; 51 getStyleSet(name, true).modifiers.put(key, style); 52 } 90 return false; 53 91 } 54 92 55 public void add(String name, Rule r, Collection<Rule> rules, AreaElemStyle style) 56 { 57 if(rules != null) 58 { 59 style.rules = rules; 60 getStyleSet(name, true).areasList.add(style); 93 public boolean isArea(OsmPrimitive osm) { 94 for (StyleSource s : getStyleSources()) { 95 if (s.isArea(osm)) 96 return true; 61 97 } 62 else 63 { 64 String key = r.getKey(); 65 style.code = key; 66 getStyleSet(name, true).areas.put(key, style); 67 } 98 return false; 68 99 } 69 100 70 public void add(String name, Rule r, Collection<Rule> rules, IconElemStyle style) 71 { 72 if(rules != null) 73 { 74 style.rules = rules; 75 getStyleSet(name, true).iconsList.add(style); 101 public ElemStyle getArea(Way osm) { 102 if (osm.hasKeys()) { 103 /* force area mode also for unclosed ways */ 104 ElemStyle style = get(osm, true); 105 if (style != null && style instanceof AreaElemStyle) { 106 return style; 107 } 76 108 } 77 else 78 { 79 String key = r.getKey(); 80 style.code = key; 81 getStyleSet(name, true).icons.put(key, style); 82 } 109 return null; 83 110 } 84 111 85 private StyleSource getStyleSet(String name, boolean create) 86 { 87 if(name == null) { 88 name = Main.pref.get("mappaint.style", "standard"); 89 } 90 91 StyleSource s = styleSet.get(name); 92 if(create && s == null) 93 { 94 s = new StyleSource(); 95 styleSet.put(name, s); 96 } 97 return s; 112 public IconElemStyle getIcon(OsmPrimitive osm) { 113 return osm.hasKeys() ? (IconElemStyle) get(osm) : null; 98 114 } 99 115 100 /* called from class users, never return null */101 public StyleSource getStyleSet()102 {103 return getStyleSet(null, true);104 }105 106 public Collection<String> getStyleNames()107 {108 return styleSet.keySet();116 public Collection<String> getStyleNames() { 117 Set<String> names = new HashSet<String>(); 118 names.add("standard"); 119 for (StyleSource s : styleSources) { 120 if (s.name != null) { 121 names.add(s.name); 122 } 123 } 124 return names; 109 125 } 110 126 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3796 r3803 76 76 77 77 for (SourceEntry entry : sourceEntries) { 78 StyleSource style = new StyleSource(entry); 78 79 try { 79 XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler( entry.name));80 XmlObjectParser parser = new XmlObjectParser(new ElemStyleHandler(style)); 80 81 MirroredInputStream in = new MirroredInputStream(entry.url); 81 82 InputStream zip = in.getZipEntry("xml","style"); … … 95 96 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString())); 96 97 e.printStackTrace(); 98 style.hasError = true; 97 99 } catch(SAXParseException e) { 98 100 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", entry.url, e.getLineNumber(), e.getColumnNumber(), e.getMessage())); 99 101 e.printStackTrace(); 102 style.hasError = true; 100 103 } catch(SAXException e) { 101 104 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", entry.url, e.getMessage())); 102 105 e.printStackTrace(); 106 style.hasError = true; 103 107 } 108 styles.add(style); 104 109 } 105 110 iconDirs = null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r3799 r3803 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.Collection; 4 5 import java.util.Collections; 5 6 import java.util.HashMap; … … 7 8 import java.util.LinkedList; 8 9 import java.util.List; 10 import java.util.regex.Matcher; 11 import java.util.regex.Pattern; 9 12 import org.openstreetmap.josm.data.osm.Node; 10 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 14 import org.openstreetmap.josm.data.osm.OsmUtils; 12 15 import org.openstreetmap.josm.data.osm.Way; 13 14 public class StyleSource { 15 16 public HashMap<String, IconElemStyle> icons; 17 public HashMap<String, LineElemStyle> lines; 18 public HashMap<String, AreaElemStyle> areas; 19 public HashMap<String, LineElemStyle> modifiers; 20 public LinkedList<IconElemStyle> iconsList; 21 public LinkedList<LineElemStyle> linesList; 22 public LinkedList<AreaElemStyle> areasList; 23 public LinkedList<LineElemStyle> modifiersList; 24 25 public StyleSource() { 26 icons = new HashMap<String, IconElemStyle>(); 27 lines = new HashMap<String, LineElemStyle>(); 28 modifiers = new HashMap<String, LineElemStyle>(); 29 areas = new HashMap<String, AreaElemStyle>(); 30 iconsList = new LinkedList<IconElemStyle>(); 31 linesList = new LinkedList<LineElemStyle>(); 32 modifiersList = new LinkedList<LineElemStyle>(); 33 areasList = new LinkedList<AreaElemStyle>(); 34 } 35 36 private IconElemStyle getNode(OsmPrimitive primitive) { 37 IconElemStyle ret = null; 16 import org.openstreetmap.josm.gui.preferences.SourceEntry; 17 18 public class StyleSource extends SourceEntry { 19 20 public final HashMap<String, IconElemStyle> icons = new HashMap<String, IconElemStyle>(); 21 public final HashMap<String, LineElemStyle> lines = new HashMap<String, LineElemStyle>(); 22 public final HashMap<String, LineElemStyle> modifiers = new HashMap<String, LineElemStyle>(); 23 public final HashMap<String, AreaElemStyle> areas = new HashMap<String, AreaElemStyle>(); 24 public final LinkedList<IconElemStyle> iconsList = new LinkedList<IconElemStyle>(); 25 public final LinkedList<LineElemStyle> linesList = new LinkedList<LineElemStyle>(); 26 public final LinkedList<LineElemStyle> modifiersList = new LinkedList<LineElemStyle>(); 27 public final LinkedList<AreaElemStyle> areasList = new LinkedList<AreaElemStyle>(); 28 29 public boolean hasError = false; 30 31 public StyleSource(String url, String name, String shortdescription) { 32 super(url, name, shortdescription, true); 33 } 34 35 public StyleSource(SourceEntry entry) { 36 super(entry.url, entry.name, entry.shortdescription, entry.active); 37 } 38 39 public IconElemStyle getNode(OsmPrimitive primitive, IconElemStyle icon) { 38 40 for (String key : primitive.keySet()) { 39 41 String val = primitive.get(key); 40 42 IconElemStyle style; 41 43 if ((style = icons.get("n" + key + "=" + val)) != null) { 42 if ( ret == null || style.priority > ret.priority) {43 ret= style;44 if (icon == null || style.priority > icon.priority) { 45 icon = style; 44 46 } 45 47 } 46 48 if ((style = icons.get("b" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) { 47 if ( ret == null || style.priority > ret.priority) {48 ret= style;49 if (icon == null || style.priority > icon.priority) { 50 icon = style; 49 51 } 50 52 } 51 53 if ((style = icons.get("x" + key)) != null) { 52 if ( ret == null || style.priority > ret.priority) {53 ret= style;54 if (icon == null || style.priority > icon.priority) { 55 icon = style; 54 56 } 55 57 } 56 58 } 57 59 for (IconElemStyle s : iconsList) { 58 if ((ret == null || s.priority > ret.priority) && s.check(primitive)) { 59 ret = s; 60 } 61 } 62 return ret; 63 } 64 65 private ElemStyle get(OsmPrimitive primitive, boolean noclosed) { 66 AreaElemStyle retArea = null; 67 LineElemStyle retLine = null; 68 String linestring = null; 69 HashMap<String, LineElemStyle> over = new HashMap<String, LineElemStyle>(); 60 if ((icon == null || s.priority > icon.priority) && s.check(primitive)) { 61 icon = s; 62 } 63 } 64 return icon; 65 } 66 67 public ElemStyle get(OsmPrimitive primitive, boolean noclosed, AreaElemStyle area, LineElemStyle line) { 68 String lineIdx = null; 69 HashMap<String, LineElemStyle> overlayMap = new HashMap<String, LineElemStyle>(); 70 70 for (String key : primitive.keySet()) { 71 71 String val = primitive.get(key); … … 73 73 LineElemStyle styleLine; 74 74 String idx = "n" + key + "=" + val; 75 if ((styleArea = areas.get(idx)) != null && ( retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {76 retArea = styleArea;77 } 78 if ((styleLine = lines.get(idx)) != null && ( retLine == null || styleLine.priority > retLine.priority)) {79 retLine = styleLine;80 line string= idx;75 if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) { 76 area = styleArea; 77 } 78 if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) { 79 line = styleLine; 80 lineIdx = idx; 81 81 } 82 82 if ((styleLine = modifiers.get(idx)) != null) { 83 over .put(idx, styleLine);83 overlayMap.put(idx, styleLine); 84 84 } 85 85 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 86 if ((styleArea = areas.get(idx)) != null && ( retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {87 retArea = styleArea;88 } 89 if ((styleLine = lines.get(idx)) != null && ( retLine == null || styleLine.priority > retLine.priority)) {90 retLine = styleLine;91 line string= idx;86 if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) { 87 area = styleArea; 88 } 89 if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) { 90 line = styleLine; 91 lineIdx = idx; 92 92 } 93 93 if ((styleLine = modifiers.get(idx)) != null) { 94 over .put(idx, styleLine);94 overlayMap.put(idx, styleLine); 95 95 } 96 96 idx = "x" + key; 97 if ((styleArea = areas.get(idx)) != null && ( retArea == null || styleArea.priority > retArea.priority) && (!noclosed || !styleArea.closed)) {98 retArea = styleArea;99 } 100 if ((styleLine = lines.get(idx)) != null && ( retLine == null || styleLine.priority > retLine.priority)) {101 retLine = styleLine;102 line string= idx;97 if ((styleArea = areas.get(idx)) != null && (area == null || styleArea.priority > area.priority) && (!noclosed || !styleArea.closed)) { 98 area = styleArea; 99 } 100 if ((styleLine = lines.get(idx)) != null && (line == null || styleLine.priority > line.priority)) { 101 line = styleLine; 102 lineIdx = idx; 103 103 } 104 104 if ((styleLine = modifiers.get(idx)) != null) { 105 over .put(idx, styleLine);105 overlayMap.put(idx, styleLine); 106 106 } 107 107 } 108 108 for (AreaElemStyle s : areasList) { 109 if (( retArea == null || s.priority > retArea.priority) && (!noclosed || !s.closed) && s.check(primitive)) {110 retArea = s;109 if ((area == null || s.priority > area.priority) && (!noclosed || !s.closed) && s.check(primitive)) { 110 area = s; 111 111 } 112 112 } 113 113 for (LineElemStyle s : linesList) { 114 if (( retLine == null || s.priority > retLine.priority) && s.check(primitive)) {115 retLine = s;114 if ((line == null || s.priority > line.priority) && s.check(primitive)) { 115 line = s; 116 116 } 117 117 } 118 118 for (LineElemStyle s : modifiersList) { 119 119 if (s.check(primitive)) { 120 over.put(s.getCode(), s); 121 } 122 } 123 over.remove(linestring); 124 if (over.size() != 0 && retLine != null) { 125 List<LineElemStyle> s = new LinkedList<LineElemStyle>(over.values()); 126 Collections.sort(s); 127 retLine = new LineElemStyle(retLine, s); 128 } 129 if (retArea != null) { 130 if (retLine != null) { 131 return new AreaElemStyle(retArea, retLine); 120 overlayMap.put(s.getCode(), s); 121 } 122 } 123 overlayMap.remove(lineIdx); // do not use overlay if linestyle is from the same rule (example: railway=tram) 124 if (!overlayMap.isEmpty() && line != null) { 125 List<LineElemStyle> tmp = new LinkedList<LineElemStyle>(); 126 if (line.overlays != null) { 127 tmp.addAll(line.overlays); 128 } 129 tmp.addAll(overlayMap.values()); 130 Collections.sort(tmp); 131 line = new LineElemStyle(line, tmp); 132 } 133 if (area != null) { 134 if (line != null) { 135 return new AreaElemStyle(area, line); 132 136 } else { 133 return retArea; 134 } 135 } 136 return retLine; 137 } 138 139 public ElemStyle get(OsmPrimitive osm) { 140 return (!osm.hasKeys()) ? null : ((osm instanceof Node) ? getNode(osm) : get(osm, osm instanceof Way && !((Way) osm).isClosed())); 141 } 142 143 public ElemStyle getArea(Way osm) { 144 if (osm.hasKeys()) { 145 /* force area mode also for unclosed ways */ 146 ElemStyle style = get(osm, false); 147 if (style != null && style instanceof AreaElemStyle) { 148 return style; 149 } 150 } 151 return null; 152 } 153 154 public IconElemStyle getIcon(OsmPrimitive osm) { 155 return osm.hasKeys() ? getNode(osm) : null; 137 return area; 138 } 139 } 140 return line; 156 141 } 157 142 … … 186 171 return areas.size() > 0; 187 172 } 173 174 public void add(Rule r, Collection<Rule> rules, LineElemStyle style) { 175 if(rules != null) 176 { 177 style.rules = rules; 178 linesList.add(style); 179 } 180 else { 181 String key = r.getKey(); 182 style.code = key; 183 lines.put(key, style); 184 } 185 } 186 187 public void addModifier(Rule r, Collection<Rule> rules, LineElemStyle style) { 188 if(rules != null) 189 { 190 style.rules = rules; 191 modifiersList.add(style); 192 } 193 else 194 { 195 String key = r.getKey(); 196 style.code = key; 197 modifiers.put(key, style); 198 } 199 } 200 201 public void add(Rule r, Collection<Rule> rules, AreaElemStyle style) { 202 if(rules != null) 203 { 204 style.rules = rules; 205 areasList.add(style); 206 } 207 else 208 { 209 String key = r.getKey(); 210 style.code = key; 211 areas.put(key, style); 212 } 213 } 214 215 public void add(Rule r, Collection<Rule> rules, IconElemStyle style) { 216 if(rules != null) 217 { 218 style.rules = rules; 219 iconsList.add(style); 220 } 221 else 222 { 223 String key = r.getKey(); 224 style.code = key; 225 icons.put(key, style); 226 } 227 } 228 229 /** 230 * the name / identifier that should be used to save custom color values 231 * and similar stuff to the preference file 232 * @return the identifier; never null. Usually the result is "standard" 233 */ 234 public String getPrefName() { 235 return name == null ? "standard" : name; 236 } 237 238 /** 239 * String to show in menus and error messages. 240 * @return Usually the shortdescription, but can be the file name 241 * if no shortdescription is available. 242 */ 243 public String getDisplayString() { 244 if (shortdescription != null) 245 return shortdescription; 246 /** 247 * extract file part from url, e.g.: 248 * http://www.test.com/file.xml?format=text --> file.xml 249 */ 250 Pattern p = Pattern.compile("([^/\\\\]*?)([?].*)?$"); 251 Matcher m = p.matcher(url); 252 if (m.find()) { 253 return m.group(1); 254 } else { 255 System.err.println("Warning: Unexpected URL format: "+url); 256 return url; 257 } 258 } 188 259 }
Note: See TracChangeset
for help on using the changeset viewer.