Changeset 3591 in osm for applications/editors/josm
- Timestamp:
- 2007-07-15T03:44:47+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/mappaint/src/mappaint
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mappaint/src/mappaint/ElemStyleHandler.java
r3590 r3591 15 15 public class ElemStyleHandler extends DefaultHandler 16 16 { 17 boolean inDoc, inRule, inCondition, inElemStyle, inLine, inIcon, inArea ;18 ElemStyle curLineStyle=null;19 ElemStyle curIconStyle=null;20 ElemStyle curAreaStyle=null;21 ElemStyles styles;22 String curKey, curValue;23 int curWidth = 1, curRealWidth = 0;24 int curMinZoom;25 ImageIcon curIcon ;26 Color curColour;27 boolean curAnnotate;17 boolean inDoc, inRule, inCondition, inElemStyle, inLine, inIcon, inArea, inScaleMax; 18 ElemStyles styles = null; 19 String curKey = null; 20 String curValue = null; 21 int curLineWidth = 1; 22 int curLineRealWidth = 0; 23 Color curLineColour = null; 24 Color curAreaColour = null; 25 ImageIcon curIcon = null; 26 boolean curIconAnnotate = true; 27 int curScaleMax = 1000000000; 28 28 29 29 public ElemStyleHandler( ) … … 81 81 { 82 82 if(atts.getQName(count).equals("width")) 83 cur Width = Integer.parseInt(atts.getValue(count));83 curLineWidth = Integer.parseInt(atts.getValue(count)); 84 84 else if (atts.getQName(count).equals("colour")) 85 cur Colour=ColorHelper.html2color(atts.getValue(count));85 curLineColour=ColorHelper.html2color(atts.getValue(count)); 86 86 else if (atts.getQName(count).equals("realwidth")) 87 cur RealWidth=Integer.parseInt(atts.getValue(count));87 curLineRealWidth=Integer.parseInt(atts.getValue(count)); 88 88 } 89 89 } 90 else if (qName.equals(" zoom"))90 else if (qName.equals("scale_max")) 91 91 { 92 curMinZoom = 0; 93 for(int count=0; count<atts.getLength(); count++) 94 { 95 if(atts.getQName(count).equals("min")) 96 curMinZoom = Integer.parseInt(atts.getValue(count)); 97 } 98 } 92 inScaleMax = true; 93 } 99 94 else if (qName.equals("icon")) 100 95 { … … 120 115 } 121 116 } else if (atts.getQName(count).equals("annotate")) 122 cur Annotate = Boolean.parseBoolean117 curIconAnnotate = Boolean.parseBoolean 123 118 (atts.getValue(count)); 124 119 } … … 130 125 { 131 126 if (atts.getQName(count).equals("colour")) 132 cur Colour=ColorHelper.html2color(atts.getValue(count));127 curAreaColour=ColorHelper.html2color(atts.getValue(count)); 133 128 } 134 129 } … … 136 131 } 137 132 138 139 133 @Override public void endElement(String uri,String name, String qName) 140 134 { 141 135 if(inRule && qName.equals("rule")) 142 136 { 137 ElemStyle newStyle; 143 138 inRule = false; 144 if(curLine Style != null)139 if(curLineWidth != -1) 145 140 { 146 styles.add (curKey, curValue, curLineStyle); 147 curLineStyle = null; 141 newStyle = new LineElemStyle(curLineWidth, curLineRealWidth, curLineColour, 142 curScaleMax); 143 styles.add (curKey, curValue, newStyle); 144 curLineWidth = 1; 145 curLineRealWidth= 0; 146 curLineColour = null; 148 147 } 149 if(curIcon Style!= null)148 if(curIcon != null) 150 149 { 151 styles.add (curKey, curValue, curIconStyle); 152 curIconStyle = null; 150 newStyle = new IconElemStyle(curIcon,curIconAnnotate,curScaleMax); 151 styles.add (curKey, curValue, newStyle); 152 curIcon = null; 153 curIconAnnotate = true; 153 154 } 154 if(curArea Style!= null)155 if(curAreaColour != null) 155 156 { 156 styles.add (curKey, curValue, curAreaStyle); 157 curAreaStyle = null; 157 newStyle = new AreaElemStyle (curAreaColour,curScaleMax); 158 styles.add (curKey, curValue, newStyle); 159 curAreaColour = null; 158 160 } 161 curScaleMax = 1000000000; 162 159 163 } 160 164 else if (inCondition && qName.equals("condition")) 161 165 inCondition = false; 162 166 else if (inLine && qName.equals("line")) 163 {164 167 inLine = false; 165 curLineStyle = new LineElemStyle(curWidth,curRealWidth, curColour,166 curMinZoom);167 curWidth=1;168 curRealWidth = 0;169 }170 168 else if (inIcon && qName.equals("icon")) 171 {172 169 inIcon = false; 173 curIconStyle = new IconElemStyle(curIcon,curAnnotate,curMinZoom);174 }175 170 else if (inArea && qName.equals("area")) 176 {177 171 inArea = false; 178 curAreaStyle = new AreaElemStyle (curColour,curMinZoom); 179 } 180 172 else if (qName.equals("scale_max")) 173 { 174 inScaleMax = false; 175 } 181 176 } 182 177 183 178 @Override public void characters(char ch[], int start, int length) 184 179 { 180 if( inScaleMax == true) { 181 String content = new String(ch, start, length); 182 183 curScaleMax = Integer.parseInt(content); 184 } 185 185 } 186 186 } -
applications/editors/josm/plugins/mappaint/src/mappaint/MapPaintVisitor.java
r2853 r3591 30 30 public class MapPaintVisitor extends SimplePaintVisitor { 31 31 32 protected boolean isZoomOk(ElemStyle e) { 33 double circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 34 35 /* show everything, if the user wishes so */ 36 if(!Main.pref.getBoolean("mappaint.zoomLevelDisplay",false)) { 37 return true; 38 } 39 40 if(e == null) { 41 /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */ 42 if(circum < 1500) { 43 return true; 44 } else { 45 return false; 46 } 47 } 48 49 if(circum>=e.getMinZoom() / 70) { 50 return false; 51 } else { 52 return true; 53 } 54 } 55 32 56 /** 33 57 * Draw a small rectangle. … … 39 63 @Override public void visit(Node n) { 40 64 ElemStyle nodeStyle = MapPaintPlugin.elemStyles.getStyle(n); 41 if(nodeStyle!=null && Main.map.mapView.zoom()>=nodeStyle.getMinZoom()){65 if(nodeStyle!=null){ 42 66 if(nodeStyle instanceof IconElemStyle) { 43 drawNode(n, ((IconElemStyle)nodeStyle).getIcon()); 67 if(isZoomOk(nodeStyle)) { 68 drawNode(n, ((IconElemStyle)nodeStyle).getIcon()); 69 } 44 70 } else { 45 71 // throw some sort of exception … … 58 84 */ 59 85 @Override public void visit(Segment ls) { 86 ElemStyle segmentStyle = MapPaintPlugin.elemStyles.getStyle(ls); 87 if(isZoomOk(segmentStyle)) { 60 88 drawSegment(ls, getPreferencesColor("untagged",Color.GRAY),Main.pref.getBoolean("draw.segment.direction")); 89 } 61 90 } 62 91 … … 75 104 boolean area=false; 76 105 ElemStyle wayStyle = MapPaintPlugin.elemStyles.getStyle(w); 106 107 if(!isZoomOk(wayStyle)) { 108 return; 109 } 110 77 111 if(wayStyle!=null) 78 112 { … … 188 222 Point p1 = nc.getPoint(ls.from.eastNorth); 189 223 Point p2 = nc.getPoint(ls.to.eastNorth); 190 224 191 225 // checking if this segment is visible 192 226 if ((p1.x < 0) && (p2.x < 0)) return ; … … 223 257 */ 224 258 @Override public void drawNode(Node n, Color color) { 225 Point p = nc.getPoint(n.eastNorth); 226 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 227 g.setColor(color); 228 g.drawRect(p.x-1, p.y-1, 2, 2); 259 if(isZoomOk(null)) { 260 Point p = nc.getPoint(n.eastNorth); 261 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 262 g.setColor(color); 263 g.drawRect(p.x-1, p.y-1, 2, 2); 264 } 229 265 } 230 266
Note:
See TracChangeset
for help on using the changeset viewer.