Changeset 2675 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
- Timestamp:
- 2009-12-23T21:22:35+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r2671 r2675 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.Color;9 8 import java.awt.Graphics2D; 10 9 import java.awt.Point; … … 13 12 import java.awt.geom.Point2D; 14 13 import java.util.ArrayList; 15 import java.util.Arrays;16 14 import java.util.Collection; 17 15 import java.util.Collections; … … 41 39 import org.openstreetmap.josm.gui.mappaint.LineElemStyle; 42 40 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 43 import org.openstreetmap.josm. tools.LanguageInfo;41 import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle; 44 42 45 43 public class MapPaintVisitor implements PaintVisitor { 46 44 47 protected Graphics2D g; 48 protected NavigatableComponent nc; 49 50 protected boolean useRealWidth; 51 protected boolean zoomLevelDisplay; 52 protected boolean drawMultipolygon; 53 protected boolean drawRestriction; 54 protected boolean leftHandTraffic; 55 protected int showNames; 56 protected int showIcons; 57 protected int useStrokes; 58 protected int fillAlpha; 59 protected Color untaggedColor; 60 protected Color textColor; 61 protected Color areaTextColor; 62 protected ElemStyles.StyleSet styles; 63 protected double circum; 64 protected double dist; 65 protected boolean useStyleCache; 45 private Graphics2D g; 46 private NavigatableComponent nc; 47 48 private boolean zoomLevelDisplay; 49 private boolean drawMultipolygon; 50 private boolean drawRestriction; 51 private boolean leftHandTraffic; 52 private ElemStyles.StyleSet styles; 53 private double circum; 54 private double dist; 55 private boolean useStyleCache; 66 56 private static int paintid = 0; 67 57 private EastNorth minEN; 68 58 private EastNorth maxEN; 69 59 private MapPainter painter; 70 protected Collection<String> regionalNameOrder; 71 72 public boolean inactive; 73 protected boolean fillSelectedNode; 74 protected boolean fillUnselectedNode; 75 protected int defaultSegmentWidth; 76 protected boolean showOrderNumber; 77 78 protected boolean showRelevantDirectionsOnly; 79 protected boolean showHeadArrowOnly; 80 protected boolean showDirectionArrow; 81 82 protected int selectedNodeRadius; 83 protected int selectedNodeSize; 84 protected int taggedNodeSize; 85 protected int taggedNodeRadius; 86 protected int unselectedNodeRadius; 87 protected int unselectedNodeSize; 88 89 protected Color selectedColor; 90 protected Color highlightColor; 91 protected Color inactiveColor; 92 protected Color nodeColor; 60 private MapPaintSettings paintSettings; 61 62 private boolean inactive; 93 63 94 64 protected boolean isZoomOk(ElemStyle e) { … … 112 82 } 113 83 } 84 85 if (osm.mappaintStyle == null && osm instanceof Node) { 86 osm.mappaintStyle = SimpleNodeElemStyle.INSTANCE; 87 } 88 114 89 return osm.mappaintStyle; 115 90 } … … 145 120 return; 146 121 147 IconElemStyle nodeStyle = (IconElemStyle)getPrimitiveStyle(n); 148 149 if (nodeStyle != null && isZoomOk(nodeStyle) && showIcons > dist) { 150 painter.drawNodeIcon(n, (inactive || n.isDisabled())?nodeStyle.getDisabledIcon():nodeStyle.icon, 151 nodeStyle.annotate, data.isSelected(n), getNodeName(n)); 152 } else { 153 if (isZoomOk(null)) { 154 if (n.highlighted) { 155 painter.drawNode(n, highlightColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode, 156 getNodeName(n)); 157 } else if (data.isSelected(n)) { 158 painter.drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode, 159 getNodeName(n)); 160 } else if (n.isTagged()) { 161 painter.drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode, 162 getNodeName(n)); 163 } else if (inactive || n.isDisabled()) { 164 painter.drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode, 165 getNodeName(n)); 166 } else { 167 painter.drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode, 168 getNodeName(n)); 169 } 170 } 122 ElemStyle nodeStyle = getPrimitiveStyle(n); 123 124 if (isZoomOk(nodeStyle)) { 125 nodeStyle.paintPrimitive(n, paintSettings, painter, n.isSelected()); 171 126 } 172 127 } … … 212 167 return; 213 168 214 if(wayStyle==null) 215 { 216 /* way without style */ 217 drawWay(w, null, untaggedColor, data.isSelected(w)); 218 } 219 else if(wayStyle instanceof LineElemStyle) 220 { 221 /* way with line style */ 222 drawWay(w, (LineElemStyle)wayStyle, untaggedColor, data.isSelected(w)); 223 } 224 else if (wayStyle instanceof AreaElemStyle) 225 { 169 if (wayStyle == null) { 170 wayStyle = LineElemStyle.UNTAGGED_WAY; 171 } 172 173 if(wayStyle instanceof LineElemStyle) { 174 wayStyle.paintPrimitive(w, paintSettings, painter, data.isSelected(w)); 175 } else if (wayStyle instanceof AreaElemStyle) { 226 176 AreaElemStyle areaStyle = (AreaElemStyle) wayStyle; 227 177 /* way with area style */ 228 178 if (fillAreas > dist) 229 179 { 230 painter.drawArea(getPolygon(w), (data.isSelected(w) ? selectedColor : areaStyle.color),getWayName(w));180 painter.drawArea(getPolygon(w), (data.isSelected(w) ? paintSettings.getSelectedColor() : areaStyle.color), painter.getWayName(w)); 231 181 if(!w.isClosed()) { 232 182 putError(w, tr("Area style way is not closed."), true); 233 183 } 234 184 } 235 drawWay(w, areaStyle.line, areaStyle.color, data.isSelected(w)); 236 } 237 } 238 239 public void drawWay(Way w, LineElemStyle l, Color color, boolean selected) { 240 /* show direction arrows, if draw.segment.relevant_directions_only is not set, 241 the way is tagged with a direction key 242 (even if the tag is negated as in oneway=false) or the way is selected */ 243 boolean showDirection = data.isSelected(w) || ((!useRealWidth) && (showDirectionArrow 244 && (!showRelevantDirectionsOnly || w.hasDirectionKeys()))); 245 /* head only takes over control if the option is true, 246 the direction should be shown at all and not only because it's selected */ 247 boolean showOnlyHeadArrowOnly = showDirection && !data.isSelected(w) && showHeadArrowOnly; 248 int width = defaultSegmentWidth; 249 int realWidth = 0; /* the real width of the element in meters */ 250 float dashed[] = new float[0]; 251 Color dashedColor = null; 252 Node lastN; 253 254 if(l != null) { 255 if (l.color != null) { 256 color = l.color; 257 } 258 width = l.width; 259 realWidth = l.realWidth; 260 dashed = l.getDashed(); 261 dashedColor = l.dashedColor; 262 } 263 if(selected) { 264 color = selectedColor; 265 } 266 if (realWidth > 0 && useRealWidth && !showDirection) { 267 268 /* if we have a "width" tag, try use it */ 269 /* (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) */ 270 String widthTag = w.get("width"); 271 if(widthTag == null) { 272 widthTag = w.get("est_width"); 273 } 274 if(widthTag != null) { 275 try { 276 realWidth = Integer.parseInt(widthTag); 277 } 278 catch(NumberFormatException nfe) { 279 } 280 } 281 282 int tmpWidth = (int) (100 / (float) (circum / realWidth)); 283 if (tmpWidth > width) { 284 width = tmpWidth; 285 } 286 } 287 288 if(w.highlighted) { 289 color = highlightColor; 290 } else if(data.isSelected(w)) { 291 color = selectedColor; 292 } else if(w.isDisabled()) { 293 color = inactiveColor; 294 } 295 296 /* draw overlays under the way */ 297 if(l != null && l.overlays != null) { 298 for(LineElemStyle s : l.overlays) { 299 if(!s.over) { 300 painter.drawWay(w, s.color != null && !data.isSelected(w) ? s.color : color, s.getWidth(width), 301 s.getDashed(), s.dashedColor, false, false); 302 } 303 } 304 } 305 306 /* draw the way */ 307 painter.drawWay(w, color, width, dashed, dashedColor, showDirection, showOnlyHeadArrowOnly); 308 309 /* draw overlays above the way */ 310 if(l != null && l.overlays != null) { 311 for(LineElemStyle s : l.overlays) { 312 if(s.over) { 313 painter.drawWay(w, s.color != null && !data.isSelected(w) ? s.color : color, s.getWidth(width), 314 s.getDashed(), s.dashedColor, false, false); 315 } 316 } 317 } 318 319 if(showOrderNumber) { 320 int orderNumber = 0; 321 lastN = null; 322 for(Node n : w.getNodes()) { 323 if(lastN != null) { 324 orderNumber++; 325 drawOrderNumber(lastN, n, orderNumber); 326 } 327 lastN = n; 328 } 185 areaStyle.getLineStyle().paintPrimitive(w, paintSettings, painter, data.isSelected(w)); 329 186 } 330 187 } … … 441 298 if(osm instanceof Way) 442 299 { 443 if(style instanceof AreaElemStyle) 444 { 300 if(style instanceof AreaElemStyle) { 445 301 Way way = (Way)osm; 446 302 AreaElemStyle areaStyle = (AreaElemStyle)style; 447 drawWay(way, areaStyle.line, selectedColor, true);303 areaStyle.getLineStyle().paintPrimitive(way, paintSettings, painter, true); 448 304 if(area) { 449 painter.drawArea(getPolygon(way), (areaselected ? selectedColor : areaStyle.color), getWayName(way)); 450 } 451 } 452 else 453 { 454 drawWay((Way)osm, (LineElemStyle)style, selectedColor, true); 305 painter.drawArea(getPolygon(way), (areaselected ? paintSettings.getSelectedColor() : areaStyle.color), painter.getWayName(way)); 306 } 307 } else { 308 style.paintPrimitive(osm, paintSettings, painter, true); 455 309 } 456 310 } 457 311 else if(osm instanceof Node) 458 312 { 459 if(style != null && isZoomOk(style)) { 460 painter.drawNodeIcon((Node)osm, ((IconElemStyle)style).icon, 461 ((IconElemStyle)style).annotate, true, getNodeName((Node)osm)); 462 } else if (isZoomOk(null)) { 463 painter.drawNode((Node)osm, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode, 464 getNodeName((Node)osm)); 313 if(isZoomOk(style)) { 314 style.paintPrimitive(osm, paintSettings, painter, true); 465 315 } 466 316 } … … 917 767 918 768 boolean selected = pd.selected || data.isSelected(pd.way) || data.isSelected(r); 919 painter.drawArea(p, selected ? selectedColor: areaStyle.color, null);769 painter.drawArea(p, selected ? paintSettings.getSelectedColor() : areaStyle.color, null); 920 770 visible = true; 921 771 } … … 934 784 || outer.size() == 0)) 935 785 { 936 drawWay(wInner, ((AreaElemStyle)wayStyle).line, 937 ((AreaElemStyle)wayStyle).color, data.isSelected(wInner) 938 || data.isSelected(r)); 786 ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wInner, paintSettings, painter, (data.isSelected(wInner) 787 || data.isSelected(r))); 939 788 } 940 789 wInner.mappaintDrawnCode = paintid; … … 968 817 if(zoomok) 969 818 { 970 drawWay(wOuter, ((AreaElemStyle)wayStyle).line, 971 ((AreaElemStyle)wayStyle).color, data.isSelected(wOuter) 972 || data.isSelected(r)); 819 ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wOuter, paintSettings, painter, (data.isSelected(wOuter) || data.isSelected(r))); 973 820 } 974 821 wOuter.mappaintDrawnCode = paintid; … … 1043 890 } 1044 891 return Math.abs(sum/2.0); 1045 }1046 1047 protected String getNodeName(Node n) {1048 if (showNames > dist) {1049 String name = null;1050 if (n.hasKeys()) {1051 for (String rn : regionalNameOrder) {1052 name = n.get(rn);1053 if (name != null) {1054 break;1055 }1056 }1057 }1058 return name;1059 } else1060 return null;1061 }1062 1063 protected String getWayName(Way w) {1064 if (showNames > dist) {1065 String name = null;1066 if (w.hasKeys()) {1067 for (String rn : regionalNameOrder) {1068 name = w.get(rn);1069 if (name != null) {1070 break;1071 }1072 }1073 }1074 return name;1075 } else1076 return null;1077 }1078 1079 public void getColors() {1080 selectedColor = PaintColors.SELECTED.get();1081 highlightColor = PaintColors.HIGHLIGHT.get();1082 inactiveColor = PaintColors.INACTIVE.get();1083 nodeColor = PaintColors.NODE.get();1084 untaggedColor = PaintColors.UNTAGGED.get();1085 textColor = PaintColors.TEXT.get();1086 areaTextColor = PaintColors.AREA_TEXT.get();1087 892 } 1088 893 … … 1113 918 useStyleCache = Main.pref.getBoolean("mappaint.cache", true); 1114 919 int fillAreas = Main.pref.getInteger("mappaint.fillareas", 10000000); 1115 fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));1116 showNames = Main.pref.getInteger("mappaint.shownames", 10000000);1117 showIcons = Main.pref.getInteger("mappaint.showicons", 10000000);1118 useStrokes = Main.pref.getInteger("mappaint.strokes", 10000000);1119 920 LatLon ll1 = nc.getLatLon(0, 0); 1120 921 LatLon ll2 = nc.getLatLon(100, 0); 1121 922 dist = ll1.greatCircleDistance(ll2); 1122 923 1123 getColors();1124 1125 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction", true);1126 showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only", true);1127 showHeadArrowOnly = Main.pref.getBoolean("draw.segment.head_only", false);1128 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number", false);1129 selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2;1130 selectedNodeSize = selectedNodeRadius * 2;1131 unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2;1132 unselectedNodeSize = unselectedNodeRadius * 2;1133 taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2;1134 taggedNodeSize = taggedNodeRadius * 2;1135 defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2);1136 fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true);1137 fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);1138 1139 useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth", false);1140 924 zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay", false); 1141 925 circum = Main.map.mapView.getDist100Pixel(); … … 1144 928 drawRestriction = Main.pref.getBoolean("mappaint.restriction", true); 1145 929 leftHandTraffic = Main.pref.getBoolean("mappaint.lefthandtraffic", false); 1146 String[] names = {"name:" + LanguageInfo.getJOSMLocaleCode(), "name", "int_name", "ref", "operator", "brand", "addr:housenumber"};1147 930 minEN = nc.getEastNorth(0, nc.getHeight() - 1); 1148 931 maxEN = nc.getEastNorth(nc.getWidth() - 1, 0); 1149 regionalNameOrder = Main.pref.getCollection("mappaint.nameOrder", Arrays.asList(names)); 1150 1151 this.painter = new MapPainter( g, inactive, nc, useStrokes > dist, virtual);932 933 this.paintSettings = MapPaintSettings.INSTANCE; 934 this.painter = new MapPainter(paintSettings, g, inactive, nc, virtual, dist, circum); 1152 935 1153 936 data.clearErrors(); … … 1235 1018 } 1236 1019 1237 /**1238 * Draw a number of the order of the two consecutive nodes within the1239 * parents way1240 */1241 protected void drawOrderNumber(Node n1, Node n2, int orderNumber) {1242 Point p1 = nc.getPoint(n1);1243 Point p2 = nc.getPoint(n2);1244 painter.drawOrderNumber(p1, p2, orderNumber);1245 }1246 1247 1020 public void putError(OsmPrimitive p, String text, boolean isError) 1248 1021 {
Note:
See TracChangeset
for help on using the changeset viewer.