Changeset 5342 in josm for trunk/src/org
- Timestamp:
- 2012-07-15T14:59:10+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r5217 r5342 39 39 Color color = null; 40 40 41 IconReference iconRef = c.get( "fill-image", null, IconReference.class);41 IconReference iconRef = c.get(FILL_IMAGE, null, IconReference.class); 42 42 if (iconRef != null) { 43 43 fillImage = new MapImage(iconRef.iconName, iconRef.source); … … 54 54 } 55 55 } else { 56 color = c.get( "fill-color", null, Color.class);56 color = c.get(FILL_COLOR, null, Color.class); 57 57 if (color != null) { 58 58 int alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); … … 66 66 67 67 TextElement text = null; 68 Keyword textPos = c.get( "text-position", null, Keyword.class);68 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class); 69 69 if (textPos == null || Utils.equal(textPos.val, "center")) { 70 70 text = TextElement.create(c, PaintColors.AREA_TEXT.get(), true); -
trunk/src/org/openstreetmap/josm/gui/mappaint/BoxTextElemStyle.java
r5217 r5342 162 162 MultiCascade mc = new MultiCascade(); 163 163 Cascade c = mc.getOrCreateCascade("default"); 164 c.put( "text", Keyword.AUTO);164 c.put(TEXT, Keyword.AUTO); 165 165 Node n = new Node(); 166 166 n.put("name", "dummy"); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r5217 r5342 14 14 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction.RelativeFloat; 15 15 16 abstract public class ElemStyle {16 abstract public class ElemStyle implements StyleKeys { 17 17 18 18 public float major_z_index; … … 31 31 protected ElemStyle(Cascade c, float default_major_z_index) { 32 32 major_z_index = c.get("major-z-index", default_major_z_index, Float.class); 33 z_index = c.get( "z-index", 0f, Float.class);34 object_z_index = c.get( "object-z-index", 0f, Float.class);35 isModifier = c.get( "modifier", false, Boolean.class);33 z_index = c.get(Z_INDEX, 0f, Float.class); 34 object_z_index = c.get(OBJECT_Z_INDEX, 0f, Float.class); 35 isModifier = c.get(MODIFIER, false, Boolean.class); 36 36 } 37 37 -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r5217 r5342 22 22 MultiCascade mc = new MultiCascade(); 23 23 Cascade c = mc.getOrCreateCascade("default"); 24 c.put( "width", Keyword.DEFAULT);25 c.put( "color", color != null ? color : PaintColors.UNTAGGED.get());24 c.put(WIDTH, Keyword.DEFAULT); 25 c.put(COLOR, color != null ? color : PaintColors.UNTAGGED.get()); 26 26 if (isAreaEdge) { 27 c.put( "z-index", -3f);27 c.put(Z_INDEX, -3f); 28 28 } 29 29 return createLine(new Environment(null, mc, "default", null)); … … 99 99 case NORMAL: 100 100 { 101 Float widthOnDefault = getWidth(c_def, "width", null);102 width = getWidth(c, "width", widthOnDefault);101 Float widthOnDefault = getWidth(c_def, WIDTH, null); 102 width = getWidth(c, WIDTH, widthOnDefault); 103 103 break; 104 104 } 105 105 case CASING: 106 106 { 107 Float casingWidth = c.get(type.prefix + "width", null, Float.class, true);107 Float casingWidth = c.get(type.prefix + WIDTH, null, Float.class, true); 108 108 if (casingWidth == null) { 109 RelativeFloat rel_casingWidth = c.get(type.prefix + "width", null, RelativeFloat.class, true);109 RelativeFloat rel_casingWidth = c.get(type.prefix + WIDTH, null, RelativeFloat.class, true); 110 110 if (rel_casingWidth != null) { 111 111 casingWidth = rel_casingWidth.val / 2; … … 114 114 if (casingWidth == null) 115 115 return null; 116 Float widthOnDefault = getWidth(c_def, "width", null);117 width = getWidth(c, "width", widthOnDefault);116 Float widthOnDefault = getWidth(c_def, WIDTH, null); 117 width = getWidth(c, WIDTH, widthOnDefault); 118 118 if (width == null) { 119 119 width = 0f; … … 124 124 case LEFT_CASING: 125 125 case RIGHT_CASING: 126 width = getWidth(c, type.prefix + "width", null);126 width = getWidth(c, type.prefix + WIDTH, null); 127 127 break; 128 128 default: … … 132 132 return null; 133 133 134 float realWidth = c.get(type.prefix + "real_width", 0f, Float.class);134 float realWidth = c.get(type.prefix + REAL_WIDTH, 0f, Float.class); 135 135 if (realWidth > 0 && MapPaintSettings.INSTANCE.isUseRealWidth()) { 136 136 … … 149 149 } 150 150 151 Float offset = c.get( "offset", 0f, Float.class);151 Float offset = c.get(OFFSET, 0f, Float.class); 152 152 switch (type) { 153 153 case NORMAL: 154 154 break; 155 155 case CASING: 156 offset += c.get(type.prefix + "offset", 0f, Float.class);156 offset += c.get(type.prefix + OFFSET, 0f, Float.class); 157 157 break; 158 158 case LEFT_CASING: 159 159 case RIGHT_CASING: 160 160 { 161 Float baseWidthOnDefault = getWidth(c_def, "width", null);162 Float baseWidth = getWidth(c, "width", baseWidthOnDefault);161 Float baseWidthOnDefault = getWidth(c_def, WIDTH, null); 162 Float baseWidth = getWidth(c, WIDTH, baseWidthOnDefault); 163 163 if (baseWidth == null || baseWidth < 2f) { 164 164 baseWidth = 2f; 165 165 } 166 float casingOffset = c.get(type.prefix + "offset", 0f, Float.class);166 float casingOffset = c.get(type.prefix + OFFSET, 0f, Float.class); 167 167 casingOffset += baseWidth / 2 + width / 2; 168 168 /* flip sign for the right-casing-offset */ … … 175 175 } 176 176 177 Color color = c.get(type.prefix + "color", null, Color.class);177 Color color = c.get(type.prefix + COLOR, null, Color.class); 178 178 if (type == LineType.NORMAL && color == null) { 179 color = c.get( "fill-color", null, Color.class);179 color = c.get(FILL_COLOR, null, Color.class); 180 180 } 181 181 if (color == null) { … … 184 184 185 185 int alpha = 255; 186 Integer pAlpha = Utils.color_float2int(c.get( "opacity", null, Float.class));186 Integer pAlpha = Utils.color_float2int(c.get(OPACITY, null, Float.class)); 187 187 if (pAlpha != null) { 188 188 alpha = pAlpha; … … 190 190 color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 191 191 192 float[] dashes = c.get(type.prefix + "dashes", null, float[].class);192 float[] dashes = c.get(type.prefix + DASHES, null, float[].class); 193 193 if (dashes != null) { 194 194 boolean hasPositive = false; … … 206 206 } 207 207 } 208 float dashesOffset = c.get(type.prefix + "dashes-offset", 0f, Float.class);209 Color dashesBackground = c.get(type.prefix + "dashes-background-color", null, Color.class);208 float dashesOffset = c.get(type.prefix + DASHES_OFFSET, 0f, Float.class); 209 Color dashesBackground = c.get(type.prefix + DASHES_BACKGROUND_COLOR, null, Color.class); 210 210 if (dashesBackground != null) { 211 pAlpha = Utils.color_float2int(c.get(type.prefix + "dashes-background-opacity", null, Float.class));211 pAlpha = Utils.color_float2int(c.get(type.prefix + DASHES_BACKGROUND_OPACITY, null, Float.class)); 212 212 if (pAlpha != null) { 213 213 alpha = pAlpha; -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineTextElemStyle.java
r5219 r5342 20 20 Cascade c = env.mc.getCascade(env.layer); 21 21 22 Keyword textPos = c.get( "text-position", null, Keyword.class);22 Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class); 23 23 if (textPos != null && !Utils.equal(textPos.val, "line")) 24 24 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java
r3987 r5342 14 14 * StyleSources apply zoom level dependent properties. 15 15 */ 16 public class MultiCascade {16 public class MultiCascade implements StyleKeys { 17 17 18 18 private Map<String, Cascade> layers; … … 40 40 // be a modifier. Can be overridden in style definition. 41 41 if (!layer.equals("default") && !layer.equals("*")) { 42 c.put( "modifier", true);42 c.put(MODIFIER, true); 43 43 } 44 44 } … … 61 61 c = new Cascade(); 62 62 if (!layer.equals("default") && !layer.equals("*")) { 63 c.put( "modifier", true);63 c.put(MODIFIER, true); 64 64 } 65 65 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r5217 r5342 122 122 Cascade c_def = env.mc.getCascade("default"); 123 123 124 final IconReference iconRef = c.get( "icon-image", null, IconReference.class);124 final IconReference iconRef = c.get(ICON_IMAGE, null, IconReference.class); 125 125 if (iconRef == null) 126 126 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java
r4415 r5342 19 19 * 20 20 */ 21 public class TextElement {21 public class TextElement implements StyleKeys { 22 22 static public final LabelCompositionStrategy AUTO_LABEL_COMPOSITION_STRATEGY = new DeriveLabelFromNameTagsCompositionStrategy(); 23 23 … … 85 85 * from a tag value. 86 86 */ 87 TagKeyReference tkr = c.get( "text", null, TagKeyReference.class, true);87 TagKeyReference tkr = c.get(TEXT, null, TagKeyReference.class, true); 88 88 if (tkr != null) 89 89 return new TagLookupCompositionStrategy(tkr.key); … … 93 93 * a keyword 94 94 */ 95 Keyword keyword = c.get( "text", null, Keyword.class, true);95 Keyword keyword = c.get(TEXT, null, Keyword.class, true); 96 96 if (equal(keyword, Keyword.AUTO)) 97 97 return AUTO_LABEL_COMPOSITION_STRATEGY; … … 100 100 * Do we have a static text label? 101 101 */ 102 String text = c.get( "text", null, String.class, true);102 String text = c.get(TEXT, null, String.class, true); 103 103 if (text != null) 104 104 return new StaticLabelCompositionStrategy(text); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r4191 r5342 9 9 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 10 10 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 11 import org.openstreetmap.josm.gui.mappaint.StyleKeys; 11 12 12 abstract public class Instruction {13 abstract public class Instruction implements StyleKeys { 13 14 14 15 public abstract void execute(Environment env); … … 35 36 if (val instanceof Expression.LiteralExpression) { 36 37 Object litValue = ((Expression.LiteralExpression) val).evaluate(null); 37 if (key.equals( "text")) {38 if (key.equals(TEXT)) { 38 39 /* Special case for declaration 'text: ...' 39 40 * … … 72 73 value = val; 73 74 } 74 if (key.equals( "icon-image") || key.equals("fill-image") || key.equals("pattern-image")) {75 if (key.equals(ICON_IMAGE) || key.equals(FILL_IMAGE) || key.equals("pattern-image")) { 75 76 if (value instanceof String) { 76 77 value = new IconReference((String) value, env.source); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r5144 r5342 23 23 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 24 24 import org.openstreetmap.josm.gui.mappaint.Range; 25 import org.openstreetmap.josm.gui.mappaint.StyleKeys; 25 26 import org.openstreetmap.josm.gui.mappaint.StyleSource; 26 27 import org.openstreetmap.josm.gui.preferences.SourceEntry; … … 31 32 import org.xml.sax.SAXParseException; 32 33 33 public class XmlStyleSource extends StyleSource {34 public class XmlStyleSource extends StyleSource implements StyleKeys { 34 35 35 36 protected final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>(); … … 286 287 IconPrototype icon = getNode(osm, (useMinMaxScale ? scale : null), mc); 287 288 if (icon != null) { 288 def.put( "icon-image", icon.icon);289 def.put(ICON_IMAGE, icon.icon); 289 290 if (osm instanceof Node) { 290 291 if (icon.annotate != null) { 291 292 if (icon.annotate) { 292 def.put( "text", Keyword.AUTO);293 def.put(TEXT, Keyword.AUTO); 293 294 } else { 294 def.remove( "text");295 def.remove(TEXT); 295 296 } 296 297 } … … 301 302 get(osm, pretendWayIsClosed || !(osm instanceof Way) || ((Way) osm).isClosed(), p, (useMinMaxScale ? scale : null), mc); 302 303 if (p.line != null) { 303 def.put( "width", new Float(p.line.getWidth()));304 def.putOrClear( "real-width", p.line.realWidth != null ? new Float(p.line.realWidth) : null);305 def.putOrClear( "color", p.line.color);304 def.put(WIDTH, new Float(p.line.getWidth())); 305 def.putOrClear(REAL_WIDTH, p.line.realWidth != null ? new Float(p.line.realWidth) : null); 306 def.putOrClear(COLOR, p.line.color); 306 307 if (p.line.color != null) { 307 308 int alpha = p.line.color.getAlpha(); 308 309 if (alpha != 255) { 309 def.put( "opacity", Utils.color_int2float(alpha));310 def.put(OPACITY, Utils.color_int2float(alpha)); 310 311 } 311 312 } 312 def.putOrClear( "dashes", p.line.getDashed());313 def.putOrClear( "dashes-background-color", p.line.dashedColor);314 } 315 Float refWidth = def.get( "width", null, Float.class);313 def.putOrClear(DASHES, p.line.getDashed()); 314 def.putOrClear(DASHES_BACKGROUND_COLOR, p.line.dashedColor); 315 } 316 Float refWidth = def.get(WIDTH, null, Float.class); 316 317 if (refWidth != null && p.linemods != null) { 317 318 int numOver = 0, numUnder = 0; … … 325 326 String layer = String.format("over_%d", numOver); 326 327 c = mc.getOrCreateCascade(layer); 327 c.put( "object-z-index", new Float(numOver));328 c.put(OBJECT_Z_INDEX, new Float(numOver)); 328 329 ++numOver; 329 330 } else { 330 331 String layer = String.format("under_%d", numUnder); 331 332 c = mc.getOrCreateCascade(layer); 332 c.put( "object-z-index", new Float(-numUnder));333 c.put(OBJECT_Z_INDEX, new Float(-numUnder)); 333 334 ++numUnder; 334 335 } 335 c.put( "width", new Float(mod.getWidth(refWidth)));336 c.putOrClear( "color", mod.color);336 c.put(WIDTH, new Float(mod.getWidth(refWidth))); 337 c.putOrClear(COLOR, mod.color); 337 338 if (mod.color != null) { 338 339 int alpha = mod.color.getAlpha(); 339 340 if (alpha != 255) { 340 c.put( "opacity", Utils.color_int2float(alpha));341 c.put(OPACITY, Utils.color_int2float(alpha)); 341 342 } 342 343 } 343 c.putOrClear( "dashes", mod.getDashed());344 c.putOrClear( "dashes-background-color", mod.dashedColor);344 c.putOrClear(DASHES, mod.getDashed()); 345 c.putOrClear(DASHES_BACKGROUND_COLOR, mod.dashedColor); 345 346 } 346 347 } … … 353 354 } 354 355 if (p.area != null) { 355 def.putOrClear( "fill-color", p.area.color);356 def.putOrClear( "text-position", Keyword.CENTER);357 def.putOrClear( "text", Keyword.AUTO);358 def.remove( "fill-image");356 def.putOrClear(FILL_COLOR, p.area.color); 357 def.putOrClear(TEXT_POSITION, Keyword.CENTER); 358 def.putOrClear(TEXT, Keyword.AUTO); 359 def.remove(FILL_IMAGE); 359 360 } 360 361 }
Note:
See TracChangeset
for help on using the changeset viewer.