Changeset 885 in josm
- Timestamp:
- 2008-08-28T22:07:04+02:00 (16 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r880 r885 48 48 49 49 protected boolean isZoomOk(ElemStyle e) { 50 if (!zoomLevelDisplay) /* show everything if the user wishes so */ 51 return true; 52 50 53 double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 51 54 52 /* show everything if the user wishes so */ 53 if (!zoomLevelDisplay) { 54 return true; 55 } 56 57 if (e == null) { 58 /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */ 59 if (circum < 1500) 60 return true; 61 return false; 62 } 55 if(e == null) /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */ 56 return (circum < 1500); 63 57 64 58 // formula to calculate a map scale: natural size / map size = scale … … 67 61 // so the exact "correcting value" below depends only on the screen size and resolution 68 62 // XXX - do we need a Preference setting for this (if things vary widely)? 69 /*System.out.println( 70 "Circum: " + circum + 71 " max: " + e.getMaxScale() + "(" + e.getMaxScale()/22 + ")" + 72 " min:" + e.getMinScale() + "(" + e.getMinScale()/22 + ")");*/ 73 if(circum>=e.getMaxScale() / 22 || circum<e.getMinScale() / 22) 74 return false; 75 return true; 63 return !(circum >= e.maxScale / 22 || circum < e.minScale / 22); 76 64 } 77 65 … … 83 71 */ 84 72 public void visit(Node n) { 85 ElemStyle nodeStyle = MapPaintStyles.getStyle(n); 86 if (nodeStyle!=null) { 87 if (nodeStyle instanceof IconElemStyle) { 88 if (isZoomOk(nodeStyle)) { 89 drawNode(n, ((IconElemStyle)nodeStyle).getIcon(), ((IconElemStyle)nodeStyle).doAnnotate()); 90 } 91 } else { 92 // throw some sort of exception 93 } 94 } else { 73 IconElemStyle nodeStyle = MapPaintStyles.getStyles().get(n); 74 if (nodeStyle != null && isZoomOk(nodeStyle)) 75 drawNode(n, nodeStyle.icon, nodeStyle.annotate); 76 else { 95 77 if (n.selected) 96 78 drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); … … 113 95 && (!showRelevantDirectionsOnly || w.hasDirectionKeys))); 114 96 115 Color colo ur = untaggedColor;116 Color areacolo ur = untaggedColor;97 Color color = untaggedColor; 98 Color areacolor = untaggedColor; 117 99 int width = defaultSegmentWidth; 118 100 int realWidth = 0; //the real width of the element in meters 119 101 boolean dashed = false; 120 102 boolean area = false; 121 ElemStyle wayStyle = MapPaintStyles.getStyle(w); 122 123 if(!isZoomOk(wayStyle)) {103 ElemStyle wayStyle = MapPaintStyles.getStyles().get(w); 104 105 if(!isZoomOk(wayStyle)) 124 106 return; 125 } 126 107 108 LineElemStyle l = null; 127 109 if(wayStyle!=null) 128 110 { 129 LineElemStyle l = null;130 111 if(wayStyle instanceof LineElemStyle) 131 {132 112 l = (LineElemStyle)wayStyle; 133 }134 113 else if (wayStyle instanceof AreaElemStyle) 135 114 { 136 areacolo ur = ((AreaElemStyle)wayStyle).colour;137 colo ur = areacolour;115 areacolor = ((AreaElemStyle)wayStyle).color; 116 color = areacolor; 138 117 l = ((AreaElemStyle)wayStyle).line; 139 118 area = true; … … 141 120 if(l != null) 142 121 { 143 colo ur = l.colour;122 color = l.color; 144 123 width = l.width; 145 124 realWidth = l.realWidth; … … 149 128 150 129 if (area && fillAreas) 151 drawWayAsArea(w, areacolour); 152 int orderNumber = 0; 153 154 Node lastN = null; 155 for (Node n : w.nodes) { 156 if (lastN == null) { 130 drawWayAsArea(w, areacolor); 131 if (realWidth > 0 && useRealWidth && !showDirection) 132 { 133 int tmpWidth = (int) (100 / (float) (circum / realWidth)); 134 if (tmpWidth > width) width = tmpWidth; 135 } 136 137 Node lastN; 138 if(l != null && l.overlays != null) 139 { 140 for(LineElemStyle s : l.overlays) 141 { 142 if(!s.over) 143 { 144 lastN = null; 145 for(Node n : w.nodes) 146 { 147 if(lastN != null) 148 drawSeg(lastN, n, s.color != null ? s.color : color, false, s.getWidth(width), s.dashed); 149 lastN = n; 150 } 151 } 152 } 153 } 154 155 lastN = null; 156 for(Node n : w.nodes) 157 { 158 if(lastN != null) 159 drawSeg(lastN, n, w.selected ? selectedColor : color, showDirection, width, dashed); 160 lastN = n; 161 } 162 163 if(l != null && l.overlays != null) 164 { 165 for(LineElemStyle s : l.overlays) 166 { 167 if(s.over) 168 { 169 lastN = null; 170 for(Node n : w.nodes) 171 { 172 if(lastN != null) 173 drawSeg(lastN, n, s.color != null ? s.color : color, false, s.getWidth(width), s.dashed); 174 lastN = n; 175 } 176 } 177 } 178 } 179 180 if(showOrderNumber) 181 { 182 int orderNumber = 0; 183 lastN = null; 184 for(Node n : w.nodes) 185 { 186 if(lastN != null) 187 { 188 orderNumber++; 189 drawOrderNumber(lastN, n, orderNumber); 190 } 157 191 lastN = n; 158 continue; 159 } 160 orderNumber++; 161 162 if (realWidth > 0 && useRealWidth && !showDirection) 163 { 164 int tmpWidth = (int) (100 / (float) (circum / realWidth)); 165 if (tmpWidth > width) width = tmpWidth; 166 } 167 drawSeg(lastN, n, w.selected ? selectedColor : colour, showDirection, width, dashed); 168 169 if (showOrderNumber) 170 drawOrderNumber(lastN, n, orderNumber); 171 172 lastN = n; 192 } 173 193 } 174 194 } … … 179 199 180 200 // This assumes that all segments are aligned in the same direction! 181 protected void drawWayAsArea(Way w, Color colo ur)201 protected void drawWayAsArea(Way w, Color color) 182 202 { 183 203 Polygon polygon = new Polygon(); … … 189 209 } 190 210 191 Color mycolor = w.selected ? selectedColor : colo ur;211 Color mycolor = w.selected ? selectedColor : color; 192 212 // set the opacity (alpha) level of the filled polygon 193 213 g.setColor(new Color( mycolor.getRed(), mycolor.getGreen(), mycolor.getBlue(), fillAlpha)); … … 299 319 300 320 for (final OsmPrimitive osm : data.ways) 301 if (!osm.incomplete && !osm.deleted && MapPaintStyles. isArea(osm))321 if (!osm.incomplete && !osm.deleted && MapPaintStyles.getStyles().isArea((Way)osm)) 302 322 osm.visit(this); 303 323 else if (!osm.deleted && !osm.incomplete) -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r874 r885 4 4 public class AreaElemStyle extends ElemStyle 5 5 { 6 public Color colo ur;6 public Color color; 7 7 public LineElemStyle line = null; 8 8 9 public AreaElemStyle (Color colour, long maxScale, long minScale) { 10 this.colour = colour; 9 public AreaElemStyle (AreaElemStyle a, long maxScale, long minScale) { 10 this.color = a.color; 11 this.priority = a.priority; 11 12 this.maxScale = maxScale; 12 13 this.minScale = minScale; … … 15 16 public AreaElemStyle(AreaElemStyle a, LineElemStyle l) 16 17 { 17 this.colour = a.colour; 18 this.color = a.color; 19 this.priority = a.priority; 18 20 this.maxScale = a.maxScale; 19 21 this.minScale = a.minScale; … … 21 23 } 22 24 23 @Override public String toString() { 24 return "AreaElemStyle: colour=" + colour; 25 public AreaElemStyle() { init(); } 26 27 public void init() 28 { 29 color = null; 30 priority = 0; 25 31 } 26 32 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r627 r885 4 4 { 5 5 // zoom range to display the feature 6 p rotectedlong minScale;7 p rotectedlong maxScale;6 public long minScale; 7 public long maxScale; 8 8 9 public long getMinScale() { 10 return minScale; 11 } 12 public long getMaxScale() { 13 return maxScale; 14 } 9 public int priority; 15 10 } 16 11 -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyleHandler.java
r874 r885 2 2 3 3 import java.awt.Color; 4 import java.awt.Toolkit;5 import java.io.File;6 import java.net.URL;7 8 import javax.swing.ImageIcon;9 4 10 5 import org.openstreetmap.josm.tools.ColorHelper; 11 import org.openstreetmap.josm.Main;12 6 import org.xml.sax.Attributes; 13 7 import org.xml.sax.helpers.DefaultHandler; 14 8 9 import org.openstreetmap.josm.Main; 10 15 11 public class ElemStyleHandler extends DefaultHandler 16 12 { 17 boolean inDoc, inRule, inCondition, inElemStyle, inLine, inIcon, inArea, inScaleMax, inScaleMin; 18 String curKey = null; 19 String curValue = null; 20 String curBoolean = null; 21 int curLineWidth = -1; 22 int curLineRealWidth = 0; 23 boolean curLineDashed = false; 24 Color curLineColour = null; 25 Color curAreaColour = null; 26 ImageIcon curIcon = null; 27 boolean curIconAnnotate = true; 28 long curScaleMax = 1000000000; 29 long curScaleMin = 0; 13 boolean inDoc, inRule, inCondition, inElemStyle, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin; 14 boolean hadLine, hadLineMod, hadIcon, hadArea; 15 ElemStyles styles; 16 RuleElem rule = new RuleElem(); 17 18 class RuleElem { 19 String key; 20 String value; 21 String boolValue; 22 long scaleMax; 23 long scaleMin; 24 LineElemStyle line = new LineElemStyle(); 25 LineElemStyle linemod = new LineElemStyle(); 26 AreaElemStyle area = new AreaElemStyle(); 27 IconElemStyle icon = new IconElemStyle(); 28 public void init() 29 { 30 key = value = boolValue = null; 31 scaleMax = 1000000000; 32 scaleMin = 0; 33 line.init(); 34 linemod.init(); 35 area.init(); 36 icon.init(); 37 } 38 }; 30 39 31 40 public ElemStyleHandler() { 32 41 inDoc=inRule=inCondition=inElemStyle=inLine=inIcon=inArea=false; 42 rule.init(); 43 styles = MapPaintStyles.getStyles(); 33 44 } 34 45 … … 54 65 } 55 66 56 @Override public void startElement(String uri,String name, String qName, 57 Attributes atts) {58 if (inDoc==true){59 if (qName.equals("rule")) {67 @Override public void startElement(String uri,String name, String qName, Attributes atts) { 68 if (inDoc==true) 69 { 70 if (qName.equals("rule")) 60 71 inRule=true; 61 } 62 else if (qName.equals("condition") && inRule) { 72 else if (qName.equals("scale_max")) 73 inScaleMax = true; 74 else if (qName.equals("scale_min")) 75 inScaleMin = true; 76 else if (qName.equals("condition") && inRule) 77 { 63 78 inCondition=true; 64 for (int count=0; count<atts.getLength(); count++) { 79 for (int count=0; count<atts.getLength(); count++) 80 { 65 81 if(atts.getQName(count).equals("k")) 82 rule.key = atts.getValue(count); 83 else if(atts.getQName(count).equals("v")) 84 rule.value = atts.getValue(count); 85 else if(atts.getQName(count).equals("b")) 86 rule.boolValue = atts.getValue(count); 87 } 88 } 89 else if (qName.equals("line")) 90 { 91 hadLine = inLine = true; 92 for (int count=0; count<atts.getLength(); count++) 93 { 94 if(atts.getQName(count).equals("width")) 95 rule.line.width = Integer.parseInt(atts.getValue(count)); 96 else if (atts.getQName(count).equals("colour")) 97 rule.line.color=convertColor(atts.getValue(count)); 98 else if (atts.getQName(count).equals("realwidth")) 99 rule.line.realWidth=Integer.parseInt(atts.getValue(count)); 100 else if (atts.getQName(count).equals("dashed")) 101 rule.line.dashed=Boolean.parseBoolean(atts.getValue(count)); 102 else if(atts.getQName(count).equals("priority")) 103 rule.line.priority = Integer.parseInt(atts.getValue(count)); 104 } 105 } 106 else if (qName.equals("linemod")) 107 { 108 hadLineMod = inLine = true; 109 for (int count=0; count<atts.getLength(); count++) 110 { 111 if(atts.getQName(count).equals("width")) 66 112 { 67 curKey = atts.getValue(count); 68 curBoolean = null; 69 curValue = null; 113 String val = atts.getValue(count); 114 if(val.startsWith("+")) 115 { 116 rule.line.width = Integer.parseInt(val.substring(1)); 117 rule.line.widthMode = LineElemStyle.WidthMode.OFFSET; 118 } 119 else if(val.startsWith("-")) 120 { 121 rule.line.width = Integer.parseInt(val); 122 rule.line.widthMode = LineElemStyle.WidthMode.OFFSET; 123 } 124 else if(val.endsWith("%")) 125 { 126 rule.line.width = Integer.parseInt(val.substring(0, val.length()-1)); 127 rule.line.widthMode = LineElemStyle.WidthMode.PERCENT; 128 } 129 else 130 rule.line.width = Integer.parseInt(val); 70 131 } 71 else if(atts.getQName(count).equals("v"))72 curValue = atts.getValue(count);73 else if(atts.getQName(count).equals("b"))74 curBoolean = atts.getValue(count);75 }76 } else if (qName.equals("line")) {77 inLine = true;78 for (int count=0; count<atts.getLength(); count++) {79 if(atts.getQName(count).equals("width"))80 curLineWidth = Integer.parseInt(atts.getValue(count));81 132 else if (atts.getQName(count).equals("colour")) 82 curLineColour=convertColor(atts.getValue(count));133 rule.line.color=convertColor(atts.getValue(count)); 83 134 else if (atts.getQName(count).equals("realwidth")) 84 curLineRealWidth=Integer.parseInt(atts.getValue(count));135 rule.line.realWidth=Integer.parseInt(atts.getValue(count)); 85 136 else if (atts.getQName(count).equals("dashed")) 86 curLineDashed=Boolean.parseBoolean(atts.getValue(count)); 87 } 88 } else if (qName.equals("scale_max")) { 89 inScaleMax = true; 90 } else if (qName.equals("scale_min")) { 91 inScaleMin = true; 92 } else if (qName.equals("icon")) { 93 inIcon = true; 94 for (int count=0; count<atts.getLength(); count++) { 95 if (atts.getQName(count).equals("src")) { 96 if(!MapPaintStyles.isInternal()) 97 { 98 String imageFile = MapPaintStyles.getImageDir()+atts.getValue(count); 99 File f = new File(imageFile); 100 if (f.exists()) { 101 //open icon from user directory 102 curIcon = new ImageIcon(imageFile); 103 continue; 104 } 105 } 106 try { 107 URL path = getClass().getResource(MapPaintStyles.getInternalImageDir()+atts.getValue(count)); 108 if (path == null) { 109 /* icon not found, using default */ 110 System.out.println("Mappaint: Icon " + atts.getValue(count) + " not found, using default icon"); 111 path = getClass().getResource(MapPaintStyles.getInternalImageDir()+"misc/no_icon.png"); 112 curIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(path)); 113 } else { 114 curIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(path)); 115 } 116 } 117 catch (Exception e){ 118 URL path = getClass().getResource(MapPaintStyles.getInternalImageDir()+"incomming/amenity.png"); 119 curIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(path)); 120 } 121 } else if (atts.getQName(count).equals("annotate")) { 122 curIconAnnotate = Boolean.parseBoolean (atts.getValue(count)); 123 } 137 rule.line.dashed=Boolean.parseBoolean(atts.getValue(count)); 138 else if(atts.getQName(count).equals("priority")) 139 rule.line.priority = Integer.parseInt(atts.getValue(count)); 140 else if(atts.getQName(count).equals("mode")) 141 rule.line.over = !atts.getValue(count).equals("under"); 142 } 143 } 144 else if (qName.equals("icon")) 145 { 146 hadIcon = inIcon = true; 147 for (int count=0; count<atts.getLength(); count++) 148 { 149 if (atts.getQName(count).equals("src")) 150 rule.icon.icon = MapPaintStyles.getIcon(atts.getValue(count)); 151 else if (atts.getQName(count).equals("annotate")) 152 rule.icon.annotate = Boolean.parseBoolean (atts.getValue(count)); 153 else if(atts.getQName(count).equals("priority")) 154 rule.icon.priority = Integer.parseInt(atts.getValue(count)); 124 155 } 125 156 } 126 157 else if (qName.equals("area")) 127 158 { 128 inArea = true; 159 hadArea = inArea = true; 129 160 for (int count=0; count<atts.getLength(); count++) 130 161 { 131 162 if (atts.getQName(count).equals("colour")) 132 curAreaColour=convertColor(atts.getValue(count)); 163 rule.area.color=convertColor(atts.getValue(count)); 164 else if(atts.getQName(count).equals("priority")) 165 rule.area.priority = Integer.parseInt(atts.getValue(count)); 133 166 } 134 167 } … … 138 171 @Override public void endElement(String uri,String name, String qName) 139 172 { 140 if (inRule && qName.equals("rule")) { 141 ElemStyle newStyle; 173 if (inRule && qName.equals("rule")) 174 { 175 if(hadLine) 176 styles.add(rule.key, rule.value, rule.boolValue, 177 new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin)); 178 if(hadLineMod) 179 styles.addModifier(rule.key, rule.value, rule.boolValue, 180 new LineElemStyle(rule.line, rule.scaleMax, rule.scaleMin)); 181 if(hadIcon) 182 styles.add(rule.key, rule.value, rule.boolValue, 183 new IconElemStyle(rule.icon, rule.scaleMax, rule.scaleMin)); 184 if(hadArea) 185 styles.add(rule.key, rule.value, rule.boolValue, 186 new AreaElemStyle(rule.area, rule.scaleMax, rule.scaleMin)); 142 187 inRule = false; 143 if (curLineWidth != -1) { 144 newStyle = new LineElemStyle(curLineWidth, curLineRealWidth, curLineColour, 145 curLineDashed, curScaleMax, curScaleMin); 146 MapPaintStyles.add(curKey, curValue, curBoolean, newStyle); 147 curLineWidth = -1; 148 curLineRealWidth= 0; 149 curLineDashed = false; 150 curLineColour = null; 151 } 152 153 if (curIcon != null) { 154 newStyle = new IconElemStyle(curIcon, curIconAnnotate, curScaleMax, curScaleMin); 155 MapPaintStyles.add(curKey, curValue, curBoolean, newStyle); 156 curIcon = null; 157 curIconAnnotate = true; 158 } 159 if (curAreaColour != null) { 160 newStyle = new AreaElemStyle (curAreaColour, curScaleMax, curScaleMin); 161 MapPaintStyles.add(curKey, curValue, curBoolean, newStyle); 162 curAreaColour = null; 163 } 164 curScaleMax = 1000000000; 165 curScaleMin = 0; 166 188 hadLine = hadLineMod = hadIcon = hadArea = false; 189 rule.init(); 167 190 } 168 191 else if (inCondition && qName.equals("condition")) … … 180 203 } 181 204 182 @Override public void characters(char ch[], int start, int length) { 183 if (inScaleMax == true) { 184 String content = new String(ch, start, length); 185 curScaleMax = Long.parseLong(content); 186 } 187 if (inScaleMin == true) { 188 String content = new String(ch, start, length); 189 curScaleMin = Long.parseLong(content); 190 } 205 @Override public void characters(char ch[], int start, int length) 206 { 207 if (inScaleMax == true) 208 rule.scaleMax = Long.parseLong(new String(ch, start, length)); 209 else if (inScaleMin == true) 210 rule.scaleMin = Long.parseLong(new String(ch, start, length)); 191 211 } 192 212 } 193 194 195 196 -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r874 r885 1 1 package org.openstreetmap.josm.gui.mappaint; 2 2 3 import java.util.Collections; 3 4 import java.util.HashMap; 5 import java.util.LinkedList; 6 import java.util.List; 4 7 import java.util.Iterator; 5 8 9 import org.openstreetmap.josm.data.osm.Node; 6 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 11 import org.openstreetmap.josm.data.osm.OsmUtils; 12 import org.openstreetmap.josm.data.osm.Way; 8 13 9 14 public class ElemStyles 10 15 { 11 private HashMap<String, ElemStyle> styles; 16 private HashMap<String, IconElemStyle> icons; 17 private HashMap<String, LineElemStyle> lines; 18 private HashMap<String, AreaElemStyle> areas; 19 private HashMap<String, LineElemStyle> modifiers; 12 20 13 21 public ElemStyles() 14 22 { 15 styles = new HashMap<String, ElemStyle>(); 23 icons = new HashMap<String, IconElemStyle>(); 24 lines = new HashMap<String, LineElemStyle>(); 25 modifiers = new HashMap<String, LineElemStyle>(); 26 areas = new HashMap<String, AreaElemStyle>(); 16 27 } 17 28 18 p ublic void add(String k, String v, String b, ElemStyle style)29 private String getKey(String k, String v, String b) 19 30 { 20 ElemStyle old_style; 21 String key; 22 23 /* unfortunately, there don't seem to be an efficient way to */ 24 /* find out, if a given OsmPrimitive is an area or not, */ 25 /* so distinguish only between way and node here - for now */ 26 if (style instanceof AreaElemStyle) 27 key = "w"; 28 else if (style instanceof LineElemStyle) 29 key = "w"; 30 else if (style instanceof IconElemStyle) 31 key = "n"; 31 if(v != null) 32 return "n" + k + "=" + v; 33 else if(b != null) 34 return "b" + k + "=" + OsmUtils.getNamedOsmBoolean(b); 32 35 else 33 key = ""; 34 35 if(v != null) 36 key += "n" + k + "=" + v; 37 else if(b != null) 38 key += "b" + k + "=" + OsmUtils.getNamedOsmBoolean(b); 39 else 40 key += "x" + k; 41 42 /* avoid duplicates - for now */ 43 old_style = styles.get(key); 44 if (old_style == null) { 45 /* new key/value, insert */ 46 styles.put(key, style); 47 } else { 48 if (style.getMaxScale() < old_style.getMaxScale()) { 49 /* existing larger scale key/value, replace */ 50 styles.remove(old_style); 51 styles.put(key, style); 52 } 53 } 36 return "x" + k; 54 37 } 55 38 56 public ElemStyle get(OsmPrimitive p, Boolean area)39 public void add(String k, String v, String b, LineElemStyle style) 57 40 { 58 if (p.keys!=null) { 59 String classname; 60 String kv = null; 41 lines.put(getKey(k,v,b), style); 42 } 61 43 62 if (p instanceof org.openstreetmap.josm.data.osm.Node) { 63 if(area) 64 return null; 65 classname = "n"; 66 } else { 67 classname = "w"; 68 } 69 Iterator<String> iterator = p.keys.keySet().iterator(); 70 while (iterator.hasNext()) 44 public void addModifier(String k, String v, String b, LineElemStyle style) 45 { 46 modifiers.put(getKey(k,v,b), style); 47 } 48 49 public void add(String k, String v, String b, AreaElemStyle style) 50 { 51 areas.put(getKey(k,v,b), style); 52 } 53 54 public void add(String k, String v, String b, IconElemStyle style) 55 { 56 icons.put(getKey(k,v,b), style); 57 } 58 59 public IconElemStyle get(Node n) 60 { 61 IconElemStyle ret = null; 62 if(n.keys != null) 63 { 64 Iterator<String> iterator = n.keys.keySet().iterator(); 65 while(iterator.hasNext()) 71 66 { 72 67 String key = iterator.next(); 73 ElemStyle style = null;74 kv = classname + "n" + key + "=" + p.keys.get(key);75 if (styles.containsKey(kv))68 String val = n.keys.get(key); 69 IconElemStyle style; 70 if((style = icons.get("n" + key + "=" + val)) != null) 76 71 { 77 style = styles.get(kv); 78 if(area == style instanceof AreaElemStyle) 79 return style; 72 if(ret == null || style.priority > ret.priority) 73 ret = style; 80 74 } 81 kv = classname + "b" + key + "=" + OsmUtils.getNamedOsmBoolean(p.keys.get(key)); 82 if (styles.containsKey(kv)) 75 if((style = icons.get("n" + key + "=" + OsmUtils.getNamedOsmBoolean(val))) != null) 83 76 { 84 style = styles.get(kv); 85 if(area == style instanceof AreaElemStyle) 86 return style; 77 if(ret == null || style.priority > ret.priority) 78 ret = style; 87 79 } 88 kv = classname + "x" + key; 89 if (styles.containsKey(kv)) 80 if((style = icons.get("x" + key)) != null) 90 81 { 91 style = styles.get(kv); 92 if(area == style instanceof AreaElemStyle) 93 return style; 82 if(ret == null || style.priority > ret.priority) 83 ret = style; 94 84 } 95 85 } 96 86 } 97 98 return null; 87 return ret; 99 88 } 100 89 101 public boolean isArea(OsmPrimitive p)90 public ElemStyle get(Way w) 102 91 { 103 return get(p, true) instanceof AreaElemStyle; 92 AreaElemStyle retArea = null; 93 LineElemStyle retLine = null; 94 List<LineElemStyle> over = new LinkedList<LineElemStyle>(); 95 if(w.keys != null) 96 { 97 Iterator<String> iterator = w.keys.keySet().iterator(); 98 while(iterator.hasNext()) 99 { 100 String key = iterator.next(); 101 String val = w.keys.get(key); 102 AreaElemStyle styleArea; 103 LineElemStyle styleLine; 104 String idx = "n" + key + "=" + val; 105 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 106 retArea = styleArea; 107 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 108 retLine = styleLine; 109 if((styleLine = modifiers.get(idx)) != null) 110 over.add(styleLine); 111 idx = "b" + key + "=" + OsmUtils.getNamedOsmBoolean(val); 112 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 113 retArea = styleArea; 114 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 115 retLine = styleLine; 116 if((styleLine = modifiers.get(idx)) != null) 117 over.add(styleLine); 118 idx = "x" + key; 119 if((styleArea = areas.get(idx)) != null && (retArea == null || styleArea.priority > retArea.priority)) 120 retArea = styleArea; 121 if((styleLine = lines.get(idx)) != null && (retLine == null || styleLine.priority > retLine.priority)) 122 retLine = styleLine; 123 if((styleLine = modifiers.get(idx)) != null) 124 over.add(styleLine); 125 } 126 } 127 if(over.size() != 0 && retLine != null) 128 { 129 Collections.sort(over); 130 retLine = new LineElemStyle(retLine, over); 131 } 132 if(retArea != null) 133 { 134 if(retLine != null) 135 return new AreaElemStyle(retArea, retLine); 136 else 137 return retArea; 138 } 139 return retLine; 140 } 141 142 public boolean isArea(Way w) 143 { 144 if(w.keys != null) 145 { 146 Iterator<String> iterator = w.keys.keySet().iterator(); 147 while(iterator.hasNext()) 148 { 149 String key = iterator.next(); 150 String val = w.keys.get(key); 151 if(areas.containsKey("n" + key + "=" + val) 152 || areas.containsKey("n" + key + "=" + OsmUtils.getNamedOsmBoolean(val)) 153 || areas.containsKey("x" + key)) 154 return true; 155 } 156 } 157 return false; 104 158 } 105 159 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/IconElemStyle.java
r627 r885 4 4 public class IconElemStyle extends ElemStyle 5 5 { 6 ImageIcon icon; 7 boolean annotate; 6 public ImageIcon icon; 7 public boolean annotate; 8 8 9 public IconElemStyle (ImageIcon icon, boolean annotate, long maxScale, long minScale) { 10 this.icon=icon; 11 this.annotate=annotate; 9 public IconElemStyle (IconElemStyle i, long maxScale, long minScale) { 10 this.icon = i.icon; 11 this.annotate = i.annotate; 12 this.priority = i.priority; 12 13 this.maxScale = maxScale; 13 14 this.minScale = minScale; 14 }15 16 public ImageIcon getIcon() {17 return icon;18 15 } 16 public IconElemStyle() { init(); } 19 17 20 public boolean doAnnotate() { 21 return annotate; 22 } 23 24 @Override public String toString() 18 public void init() 25 19 { 26 return "IconElemStyle: icon= " + icon + " annotate=" + annotate; 20 icon = null; 21 priority = 0; 22 annotate = true; 27 23 } 28 24 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r627 r885 1 1 package org.openstreetmap.josm.gui.mappaint; 2 2 3 import java.awt.Color; 4 import java.util.LinkedList; 5 import java.util.List; 3 6 4 public class LineElemStyle extends ElemStyle 7 public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle> 5 8 { 6 9 public int width; 7 public int realWidth = 0; //the real width of this line in meter8 public Color colo ur;9 public boolean dashed = false;10 public int realWidth; //the real width of this line in meter 11 public Color color; 12 public boolean dashed; 10 13 11 public LineElemStyle (int width, int realWidth, Color colour, boolean dashed, long maxScale, long minScale) { 12 this.width = width; 13 this.realWidth = realWidth; 14 this.colour = colour; 15 this.dashed = dashed; 14 public boolean over; 15 public enum WidthMode { ABSOLUTE, PERCENT, OFFSET }; 16 public WidthMode widthMode; 17 18 public List<LineElemStyle> overlays; 19 20 public LineElemStyle(LineElemStyle s, long maxScale, long minScale) { 21 this.width = s.width; 22 this.realWidth = s.realWidth; 23 this.color = s.color; 24 this.dashed = s.dashed; 25 this.over = s.over; 26 this.widthMode = s.widthMode; 27 28 this.priority = s.priority; 16 29 this.maxScale = maxScale; 17 30 this.minScale = minScale; 18 31 } 19 32 20 @Override public String toString() { 21 return "LineElemStyle: width= " + width + "realWidth= " + realWidth + " colour=" + colour + " dashed=" + dashed; 33 public LineElemStyle(LineElemStyle s, List<LineElemStyle> overlays) { 34 this.width = s.width; 35 this.realWidth = s.realWidth; 36 this.color = s.color; 37 this.dashed = s.dashed; 38 this.over = s.over; 39 this.widthMode = s.widthMode; 40 41 this.priority = s.priority; 42 this.maxScale = s.maxScale; 43 this.minScale = s.minScale; 44 45 this.overlays = overlays; 46 } 47 48 public LineElemStyle() { init(); } 49 50 public void init() 51 { 52 width = 1; 53 realWidth = 0; 54 dashed = false; 55 priority = 0; 56 color = null; 57 over = true; // only used for line modifications 58 widthMode = WidthMode.ABSOLUTE; 59 overlays = null; 60 }; 61 62 // get width for overlays 63 public int getWidth(int ref) 64 { 65 int res; 66 if(widthMode == WidthMode.ABSOLUTE) 67 res = width; 68 else if(widthMode == WidthMode.OFFSET) 69 res = ref + width; 70 else 71 { 72 if(width < 0) 73 res = 0; 74 else 75 res = ref*width/100; 76 } 77 return res <= 0 ? 1 : res; 78 } 79 80 public int compareTo(LineElemStyle s) 81 { 82 if(s.priority != priority) 83 return s.priority > priority ? 1 : -1; 84 if(!over && s.over) 85 return -1; 86 // we have no idea how to order other objects :-) 87 return 0; 22 88 } 23 89 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r874 r885 1 1 package org.openstreetmap.josm.gui.mappaint; 2 2 3 import java.awt.Toolkit; 3 4 import java.io.File; 4 5 import java.io.FileReader; … … 6 7 import java.util.HashMap; 7 8 import java.util.Iterator; 9 10 import javax.swing.ImageIcon; 8 11 9 12 import org.openstreetmap.josm.Main; … … 22 25 private static ElemStyles styles = new ElemStyles(); 23 26 24 public static String getStyleDir(){ 25 return styleDir; 27 public static ElemStyles getStyles() 28 { 29 return styles; 26 30 } 27 public static String getImageDir(){ 28 return imageDir; 29 } 30 public static String getInternalImageDir(){ 31 return internalImageDir; 32 } 33 public static Boolean isInternal(){ 34 return isInternal; 35 } 36 public static void add(String k, String v, String b, ElemStyle style) 31 32 public static ImageIcon getIcon(String name) 37 33 { 38 styles.add(k, v, b, style); 39 } 40 public static ElemStyle getStyle(OsmPrimitive osm) 41 { 42 ElemStyle s = styles.get(osm, true); 43 if(s != null) 34 try { 35 if(isInternal) 36 { 37 String imageFile = imageDir+name; 38 File f = new File(imageFile); 39 if(f.exists()) 40 { 41 //open icon from user directory 42 return new ImageIcon(imageFile); 43 } 44 } 45 URL path = Main.class.getResource(internalImageDir+name); 46 if(path == null) 47 { 48 System.out.println("Mappaint: Icon " + name + " not found, using default icon"); 49 path = Main.class.getResource(internalImageDir+"misc/no_icon.png"); 50 } 51 return new ImageIcon(Toolkit.getDefaultToolkit().createImage(path)); 52 } 53 catch (Exception e) 44 54 { 45 ElemStyle l = styles.get(osm, false); 46 if(l != null && l instanceof LineElemStyle) 47 { 48 s = new AreaElemStyle((AreaElemStyle)s, (LineElemStyle)l); 49 } 55 URL path = Main.class.getResource(internalImageDir+"incomming/amenity.png"); 56 return new ImageIcon(Toolkit.getDefaultToolkit().createImage(path)); 50 57 } 51 else52 s = styles.get(osm, false);53 return s;54 }55 public static boolean isArea(OsmPrimitive osm)56 {57 return styles.isArea(osm);58 58 } 59 59 60 60 public static void readFromPreferences() { 61 62 61 String styleName = Main.pref.get("mappaint.style", "standard"); 63 62 // fallback to standard name for internal case, as we only have one internal style 64 63 String internalStyleName = "standard"; 65 64 styleDir = Main.pref.get("mappaint.styledir", Main.pref.getPreferencesDir()+"plugins/mappaint/"+styleName+"/"); 66 String elemStylesFile = getStyleDir()+"elemstyles.xml";65 String elemStylesFile = styleDir+"elemstyles.xml"; 67 66 imageDir = styleDir+"icons/"; 68 67 internalImageDir = "/images/styles/"+internalStyleName+"/"; -
trunk/src/org/openstreetmap/josm/tools/ColorHelper.java
r627 r885 12 12 if (html.length() > 0 && html.charAt(0) == '#') 13 13 html = html.substring(1); 14 if (html.length() != 6) 14 else if (html.length() != 6 && html.length() != 8) 15 15 return null; 16 16 try { … … 18 18 Integer.parseInt(html.substring(0,2),16), 19 19 Integer.parseInt(html.substring(2,4),16), 20 Integer.parseInt(html.substring(4,6),16)); 20 Integer.parseInt(html.substring(4,6),16), 21 (html.length() == 8 ? Integer.parseInt(html.substring(6,8),16) : 255)); 21 22 } catch (NumberFormatException e) { 22 23 return null; -
trunk/styles/standard/elemstyles.xml
r879 r885 39 39 <rule> 40 40 <condition k="bridge" b="yes"/> 41 < !-- no line or area, as this is a highway=xy, railway=xy, .... -->41 <linemod mode="over" width="+4" colour="bridge#00008080" dashed="false"/> 42 42 <icon annotate="true" src="vehicle/viaduct.png"/> 43 43 <scale_min>1</scale_min> … … 53 53 <rule> 54 54 <condition k="bridge" v="viaduct"/> 55 < !-- no line or area, as this is a highway=xy, railway=xy, .... -->55 <linemod mode="over" width="+4" colour="bridge#00008080" dashed="false"/> 56 56 <icon annotate="true" src="vehicle/viaduct.png"/> 57 57 <scale_min>1</scale_min> … … 60 60 <rule> 61 61 <condition k="bridge" v="aqueduct"/> 62 < !-- no line or area, as this is a highway=xy, railway=xy, .... -->62 <linemod mode="over" width="+4" colour="bridge#00008080" dashed="false"/> 63 63 <icon annotate="true" src="nautical/aqueduct.png"/> 64 64 <scale_min>1</scale_min> … … 67 67 <rule> 68 68 <condition k="bridge" v="swing"/> 69 < !-- no line or area, as this is a highway=xy, railway=xy, .... -->69 <linemod mode="over" width="+4" colour="bridge#00008080" dashed="false"/> 70 70 <icon annotate="true" src="vehicle/viaduct.png"/> 71 71 <scale_min>1</scale_min> … … 74 74 <rule> 75 75 <condition k="tunnel" b="yes"/> 76 < !-- no line or area, as this is a highway=xy, railway=xy, .... -->76 <linemod mode="over" width="+4" colour="bridge#00008080" dashed="false"/> 77 77 <icon annotate="true" src="vehicle/tunnel.png"/> 78 78 <scale_min>1</scale_min> … … 886 886 <rule> 887 887 <condition k="railway" v="tram"/> 888 <line width="1" colour="rail#808080" dashed="true"/> 888 <!-- prefer way types over tram - draw tram as overlay in joined cases --> 889 <line width="1" colour="rail#808080" dashed="true" priority="-10000"/> 890 <linemod mode="over" width="1" colour="rail#808080" dashed="true"/> 889 891 <icon annotate="true" src="misc/deprecated.png"/> 890 892 <scale_min>1</scale_min>
Note:
See TracChangeset
for help on using the changeset viewer.