Changeset 2675 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
- Timestamp:
- 2009-12-23T21:22:35+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r2659 r2675 4 4 import java.util.Collection; 5 5 6 import org.openstreetmap.josm.data.osm.Node; 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.Way; 9 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 10 import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter; 11 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 6 12 import org.openstreetmap.josm.tools.I18n; 7 13 8 public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle> 9 { 10 public int width; 14 public class LineElemStyle extends ElemStyle implements Comparable<LineElemStyle> { 15 16 public static final LineElemStyle UNTAGGED_WAY; 17 18 static { 19 UNTAGGED_WAY = new LineElemStyle(); 20 UNTAGGED_WAY.color = PaintColors.UNTAGGED.get(); 21 } 22 23 private int width; 11 24 public int realWidth; //the real width of this line in meter 12 25 public Color color; … … 60 73 public void init() 61 74 { 62 width = 1; 75 width = -1; 63 76 realWidth = 0; 64 77 dashed = new float[0]; … … 124 137 } 125 138 } 139 140 @Override 141 public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected) { 142 Way w = (Way)primitive; 143 /* show direction arrows, if draw.segment.relevant_directions_only is not set, 144 the way is tagged with a direction key 145 (even if the tag is negated as in oneway=false) or the way is selected */ 146 boolean showDirection = selected || ((!paintSettings.isUseRealWidth()) && (paintSettings.isShowDirectionArrow() 147 && (!paintSettings.isShowRelevantDirectionsOnly() || w.hasDirectionKeys()))); 148 /* head only takes over control if the option is true, 149 the direction should be shown at all and not only because it's selected */ 150 boolean showOnlyHeadArrowOnly = showDirection && selected && paintSettings.isShowHeadArrowOnly(); 151 Node lastN; 152 153 Color myColor = color; 154 int myWidth = getWidth(); 155 156 if (realWidth > 0 && paintSettings.isUseRealWidth() && !showDirection) { 157 158 /* if we have a "width" tag, try use it */ 159 /* (this might be slow and could be improved by caching the value in the Way, on the other hand only used if "real width" is enabled) */ 160 String widthTag = w.get("width"); 161 if(widthTag == null) { 162 widthTag = w.get("est_width"); 163 } 164 if(widthTag != null) { 165 try { 166 realWidth = Integer.parseInt(widthTag); 167 } 168 catch(NumberFormatException nfe) { 169 } 170 } 171 172 myWidth = (int) (100 / (float) (painter.getCircum() / realWidth)); 173 if (myWidth < getWidth()) { 174 myWidth = getWidth(); 175 } 176 } 177 178 if(w.highlighted) { 179 myColor = paintSettings.getHighlightColor(); 180 } else if (selected) { 181 myColor = paintSettings.getSelectedColor(); 182 } else if(w.isDisabled()) { 183 myColor = paintSettings.getInactiveColor(); 184 } 185 186 /* draw overlays under the way */ 187 if(overlays != null) { 188 for(LineElemStyle s : overlays) { 189 if(!s.over) { 190 painter.drawWay(w, s.color != null && selected ? myColor: s.color, s.getWidth(myWidth), 191 s.getDashed(), s.dashedColor, false, false); 192 } 193 } 194 } 195 196 /* draw the way */ 197 painter.drawWay(w, myColor, myWidth, dashed, dashedColor, showDirection, showOnlyHeadArrowOnly); 198 199 /* draw overlays above the way */ 200 if(overlays != null) { 201 for(LineElemStyle s : overlays) { 202 if(s.over) { 203 painter.drawWay(w, s.color != null && selected ? myColor : s.color, s.getWidth(myWidth), 204 s.getDashed(), s.dashedColor, false, false); 205 } 206 } 207 } 208 209 if(paintSettings.isShowOrderNumber()) { 210 int orderNumber = 0; 211 lastN = null; 212 for(Node n : w.getNodes()) { 213 if(lastN != null) { 214 orderNumber++; 215 painter.drawOrderNumber(lastN, n, orderNumber); 216 } 217 lastN = n; 218 } 219 } 220 } 221 222 public int getWidth() { 223 if (width == -1) 224 return MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 225 return width; 226 } 227 228 public void setWidth(int width) { 229 this.width = width; 230 } 126 231 }
Note:
See TracChangeset
for help on using the changeset viewer.
