Changeset 5212 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-05-06T08:09:19+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r5206 r5212 37 37 38 38 private BasicStroke dashesLine; 39 40 protected enum LineType { 41 NORMAL(""), 42 CASING("casing-"), 43 LEFT_CASING("left-casing-"), 44 RIGHT_CASING("right-casing"); 45 46 public String prefix; 47 48 LineType(String prefix) { 49 this.prefix = prefix; 50 } 51 } 39 52 40 53 protected LineElemStyle(Cascade c, BasicStroke line, Color color, BasicStroke dashesLine, Color dashesBackground, float offset, float realWidth) { … … 49 62 50 63 public static LineElemStyle createLine(Environment env) { 51 return createImpl(env, "");64 return createImpl(env, LineType.NORMAL); 52 65 } 53 66 54 67 public static LineElemStyle createLeftCasing(Environment env) { 55 LineElemStyle leftCasing = createImpl(env, "left-casing-");68 LineElemStyle leftCasing = createImpl(env, LineType.LEFT_CASING); 56 69 if (leftCasing != null) { 57 70 leftCasing.z_index += -90; … … 62 75 63 76 public static LineElemStyle createRightCasing(Environment env) { 64 LineElemStyle rightCasing = createImpl(env, "right-casing-");77 LineElemStyle rightCasing = createImpl(env, LineType.RIGHT_CASING); 65 78 if (rightCasing != null) { 66 79 rightCasing.z_index += -90; … … 71 84 72 85 public static LineElemStyle createCasing(Environment env) { 73 LineElemStyle casing = createImpl(env, "casing-");86 LineElemStyle casing = createImpl(env, LineType.CASING); 74 87 if (casing != null) { 75 88 casing.z_index += -100; … … 79 92 } 80 93 81 private static LineElemStyle createImpl(Environment env, String prefix) {94 private static LineElemStyle createImpl(Environment env, LineType type) { 82 95 Cascade c = env.mc.getCascade(env.layer); 83 96 Cascade c_def = env.mc.getCascade("default"); 84 85 97 Float widthOnDefault = getWidth(c_def, "width", null); 86 98 Float width = getWidth(c, "width", widthOnDefault); 87 if ( !prefix.isEmpty()) {88 width = getWidth(c, prefix + "width", width);99 if (type != LineType.NORMAL) { 100 width = getWidth(c, type.prefix + "width", width); 89 101 } 90 102 if (width == null) 91 103 return null; 92 104 93 float realWidth = c.get( prefix + "real-width", 0f, Float.class);105 float realWidth = c.get(type.prefix + "real_width", 0f, Float.class); 94 106 if (realWidth > 0 && MapPaintSettings.INSTANCE.isUseRealWidth()) { 95 107 … … 113 125 offset = 0f; 114 126 } 115 if ( !prefix.isEmpty()) {116 Float base_width = getWidth(c, "width", widthOnDefault);127 if (type != LineType.NORMAL) { 128 /* pre-calculate an offset */ 117 129 Float base_offset = offset; 118 if ( base_width == null || base_width < 2f) {119 base_width = 2f;120 }121 /* pre-calculate an offset */122 if (prefix.startsWith("left") || prefix.startsWith("right")) {130 if (type == LineType.LEFT_CASING || type == LineType.RIGHT_CASING) { 131 Float base_width = getWidth(c, "width", widthOnDefault); 132 if (base_width == null || base_width < 2f) { 133 base_width = 2f; 134 } 123 135 offset = base_width/2 + width/2; 124 136 } else { … … 126 138 } 127 139 /* overwrites (e.g. "4") or adjusts (e.g. "+4") a prefixed -offset */ 128 if (getWidth(c, prefix + "offset", offset) != null) {129 offset = getWidth(c, prefix + "offset", offset);140 if (getWidth(c, type.prefix + "offset", offset) != null) { 141 offset = getWidth(c, type.prefix + "offset", offset); 130 142 } 131 143 /* flip sign for the right-casing-offset */ 132 if ( prefix.startsWith("right")) {144 if (type == LineType.RIGHT_CASING) { 133 145 offset *= -1f; 134 146 } … … 137 149 } 138 150 139 Color color = c.get( prefix + "color", null, Color.class);140 if ( prefix.isEmpty()&& color == null) {151 Color color = c.get(type.prefix + "color", null, Color.class); 152 if (type == LineType.NORMAL && color == null) { 141 153 color = c.get("fill-color", null, Color.class); 142 154 } … … 152 164 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 153 165 154 float[] dashes = c.get( prefix + "dashes", null, float[].class);166 float[] dashes = c.get(type.prefix + "dashes", null, float[].class); 155 167 if (dashes != null) { 156 168 boolean hasPositive = false; … … 168 180 } 169 181 } 170 float dashesOffset = c.get( prefix + "dashes-offset", 0f, Float.class);171 Color dashesBackground = c.get( prefix + "dashes-background-color", null, Color.class);182 float dashesOffset = c.get(type.prefix + "dashes-offset", 0f, Float.class); 183 Color dashesBackground = c.get(type.prefix + "dashes-background-color", null, Color.class); 172 184 if (dashesBackground != null) { 173 pAlpha = Utils.color_float2int(c.get( prefix + "dashes-background-opacity", null, Float.class));185 pAlpha = Utils.color_float2int(c.get(type.prefix + "dashes-background-opacity", null, Float.class)); 174 186 if (pAlpha != null) { 175 187 alpha = pAlpha; … … 180 192 181 193 Integer cap = null; 182 Keyword capKW = c.get( prefix + "linecap", null, Keyword.class);194 Keyword capKW = c.get(type.prefix + "linecap", null, Keyword.class); 183 195 if (capKW != null) { 184 196 if (equal(capKW.val, "none")) { … … 195 207 196 208 Integer join = null; 197 Keyword joinKW = c.get( prefix + "linejoin", null, Keyword.class);209 Keyword joinKW = c.get(type.prefix + "linejoin", null, Keyword.class); 198 210 if (joinKW != null) { 199 211 if (equal(joinKW.val, "round")) { … … 209 221 } 210 222 211 float miterlimit = c.get( prefix + "miterlimit", 10f, Float.class);223 float miterlimit = c.get(type.prefix + "miterlimit", 10f, Float.class); 212 224 if (miterlimit < 1f) { 213 225 miterlimit = 10f; … … 235 247 boolean showOrientation = !isModifier && (selected || paintSettings.isShowDirectionArrow()) && !paintSettings.isUseRealWidth(); 236 248 boolean showOneway = !isModifier && !selected && 237 !paintSettings.isUseRealWidth() &&238 paintSettings.isShowOnewayArrow() && w.hasDirectionKeys();249 !paintSettings.isUseRealWidth() && 250 paintSettings.isShowOnewayArrow() && w.hasDirectionKeys(); 239 251 boolean onewayReversed = w.reversedDirection(); 240 252 /* head only takes over control if the option is true,
Note:
See TracChangeset
for help on using the changeset viewer.