Changeset 3967 in josm
- Timestamp:
- 2011-03-09T16:01:54+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3888 r3967 78 78 79 79 TextElement text = null; 80 StringtextPos = c.get("text-position", null,String.class);81 if (textPos == null || Utils.equal(textPos, "center")) { 80 Keyword textPos = c.get("text-position", null, Keyword.class); 81 if (textPos == null || Utils.equal(textPos.val, "center")) { 82 82 text = TextElement.create(c, PaintColors.AREA_TEXT.get()); 83 83 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r3904 r3967 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint; 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 3 5 4 6 import java.awt.Color; … … 54 56 } 55 57 58 public void put(String key, Object val) { 59 prop.put(key, val); 60 } 61 62 public void putOrClear(String key, Object val) { 63 if (val != null) { 64 prop.put(key, val); 65 } else { 66 prop.remove(key); 67 } 68 } 69 70 public void remove(String key) { 71 prop.remove(key); 72 } 73 56 74 @SuppressWarnings("unchecked") 57 75 public static <T> T convertTo(Object o, Class<T> klass) { … … 81 99 return (T) toColor(o); 82 100 83 if (klass == String.class) 101 if (klass == String.class) { 102 if (o instanceof Keyword) 103 return (T) ((Keyword) o).val; 104 84 105 return (T) o.toString(); 106 } 85 107 86 108 return null; … … 107 129 if (o instanceof Boolean) 108 130 return (Boolean) o; 109 if (o instanceof String) {110 String s = ( String) o;111 if ( "true".equals(o) || "yes".equals(o))131 if (o instanceof Keyword) { 132 String s = ((Keyword) o).val; 133 if (equal(s, "true") || equal(s, "yes")) 112 134 return true; 113 if ("false" .equals(o) || "no".equals(o))135 if (equal(s, "false") || equal(s, "no")) 114 136 return false; 115 137 } … … 138 160 } 139 161 140 publicstatic Color toColor(Object o) {162 private static Color toColor(Object o) { 141 163 if (o instanceof Color) 142 164 return (Color) o; 143 if (o instanceof String) 144 return CSSColors.get((String) o); 145 return null; 146 } 147 148 public void put(String key, Object val) { 149 prop.put(key, val); 150 } 151 152 public void putOrClear(String key, Object val) { 153 if (val != null) { 154 prop.put(key, val); 155 } else { 156 prop.remove(key); 157 } 158 } 159 160 public void remove(String key) { 161 prop.remove(key); 165 if (o instanceof Keyword) 166 return CSSColors.get(((Keyword) o).val); 167 return null; 162 168 } 163 169 -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3903 r3967 33 33 public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member); 34 34 35 /** 36 * Get a property value of type Width 37 * @param c the cascade 38 * @param key property key for the width value 39 * @param relativeTo reference width. Only needed, when relative width syntax 40 * is used, e.g. "+4". 41 */ 35 42 protected static Float getWidth(Cascade c, String key, Float relativeTo) { 36 43 Float width = c.get(key, null, Float.class, true); … … 39 46 return width; 40 47 } else { 41 String width_key= c.get(key, null,String.class, true);42 if (equal(width _key, "thinnest"))48 Keyword widthKW = c.get(key, null, Keyword.class, true); 49 if (equal(widthKW, Keyword.THINNEST)) 43 50 return 0f; 44 else if(equal(width_key, "default"))51 if (equal(widthKW, Keyword.DEFAULT)) 45 52 return (float) MapPaintSettings.INSTANCE.getDefaultSegmentWidth(); 46 elseif (relativeTo != null) {53 if (relativeTo != null) { 47 54 RelativeFloat width_rel = c.get(key, null, RelativeFloat.class, true); 48 55 if (width_rel != null) … … 57 64 float size = c.get("font-size", (float) Main.pref.getInteger("mappaint.fontsize", 8), Float.class); 58 65 int weight = Font.PLAIN; 59 StringweightStr= c.get("font-wheight", null,String.class);60 if (equal(weight Str, "bold")) {66 Keyword weightKW = c.get("font-wheight", null, Keyword.class); 67 if (weightKW != null && equal(weightKW, "bold")) { 61 68 weight = Font.BOLD; 62 69 } 63 70 int style = Font.PLAIN; 64 String styleStr= c.get("font-style", null,String.class);65 if (equal(style Str, "italic")) {71 Keyword styleKW = c.get("font-style", null, Keyword.class); 72 if (styleKW != null && equal(styleKW.val, "italic")) { 66 73 style = Font.ITALIC; 67 74 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3907 r3967 21 21 MultiCascade mc = new MultiCascade(); 22 22 Cascade c = mc.getOrCreateCascade("default"); 23 c.put("width", "default");23 c.put("width", Keyword.DEFAULT); 24 24 c.put("color", color != null ? color : PaintColors.UNTAGGED.get()); 25 25 return createLine(new Environment(null, mc, "default", null)); … … 103 103 104 104 int alpha = 255; 105 Integer pAlpha = Utils.color_float2int(c.get("opacity", null, float.class));105 Integer pAlpha = Utils.color_float2int(c.get("opacity", null, Float.class)); 106 106 if (pAlpha != null) { 107 107 alpha = pAlpha; … … 136 136 } 137 137 138 int cap; 139 String capStr = c.get(prefix + "linecap", null, String.class); 140 if (equal(capStr, "none")) { 141 cap = BasicStroke.CAP_BUTT; 142 } else if (equal(capStr, "round")) { 143 cap = BasicStroke.CAP_ROUND; 144 } else if (equal(capStr, "square")) { 145 cap = BasicStroke.CAP_SQUARE; 146 } else { 138 Integer cap = null; 139 Keyword capKW = c.get(prefix + "linecap", null, Keyword.class); 140 if (capKW != null) { 141 if (equal(capKW.val, "none")) { 142 cap = BasicStroke.CAP_BUTT; 143 } else if (equal(capKW.val, "round")) { 144 cap = BasicStroke.CAP_ROUND; 145 } else if (equal(capKW.val, "square")) { 146 cap = BasicStroke.CAP_SQUARE; 147 } 148 } 149 if (cap == null) { 147 150 cap = dashes != null ? BasicStroke.CAP_BUTT : BasicStroke.CAP_ROUND; 148 151 } 149 152 150 int join; 151 String joinStr = c.get(prefix + "linejoin", null, String.class); 152 if (equal(joinStr, "round")) { 153 join = BasicStroke.JOIN_ROUND; 154 } else if (equal(joinStr, "miter")) { 155 join = BasicStroke.JOIN_MITER; 156 } else if (equal(joinStr, "bevel")) { 157 join = BasicStroke.JOIN_BEVEL; 158 } else { 153 Integer join = null; 154 Keyword joinKW = c.get(prefix + "linejoin", null, Keyword.class); 155 if (joinKW != null) { 156 if (equal(joinKW.val, "round")) { 157 join = BasicStroke.JOIN_ROUND; 158 } else if (equal(joinKW.val, "miter")) { 159 join = BasicStroke.JOIN_MITER; 160 } else if (equal(joinKW.val, "bevel")) { 161 join = BasicStroke.JOIN_BEVEL; 162 } 163 } 164 if (join == null) { 159 165 join = BasicStroke.JOIN_ROUND; 160 166 } … … 177 183 TextElement text = null; 178 184 if (!casing) { 179 StringtextPos = c.get("text-position", null,String.class);180 if (textPos == null || equal(textPos, "line")) { 185 Keyword textPos = c.get("text-position", null, Keyword.class); 186 if (textPos == null || equal(textPos.val, "line")) { 181 187 text = TextElement.create(c, PaintColors.TEXT.get()); 182 188 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3930 r3967 55 55 @Override 56 56 public String toString() { 57 return "IconReference{" + "iconName=" + iconName + " source=" + source.getDisplayString() +'}';57 return "IconReference{" + "iconName='" + iconName + "' source='" + source.getDisplayString() + "'}"; 58 58 } 59 59 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3903 r3967 121 121 122 122 } 123 123 124 124 public static final NodeElemStyle SIMPLE_NODE_ELEMSTYLE; 125 125 static { … … 171 171 if (te != null) { 172 172 HorizontalTextAlignment hAlign = HorizontalTextAlignment.RIGHT; 173 StringhAlignStr= c.get("text-anchor-horizontal",null, String.class);174 if (equal(hAlign Str, "left")) {173 Keyword hAlignKW = c.get("text-anchor-horizontal", Keyword.RIGHT, Keyword.class); 174 if (equal(hAlignKW.val, "left")) { 175 175 hAlign = HorizontalTextAlignment.LEFT; 176 } else if (equal(hAlign Str, "center")) {176 } else if (equal(hAlignKW.val, "center")) { 177 177 hAlign = HorizontalTextAlignment.CENTER; 178 } else if (equal(hAlign Str, "right")) {178 } else if (equal(hAlignKW.val, "right")) { 179 179 hAlign = HorizontalTextAlignment.RIGHT; 180 180 } 181 181 VerticalTextAlignment vAlign = VerticalTextAlignment.BOTTOM; 182 String vAlignStr = c.get("text-anchor-vertical", null, String.class);182 String vAlignStr = c.get("text-anchor-vertical", Keyword.BOTTOM, Keyword.class).val; 183 183 if (equal(vAlignStr, "above")) { 184 184 vAlign = VerticalTextAlignment.ABOVE; … … 203 203 204 204 SymbolShape shape; 205 String shapeStr = c.get("symbol-shape", null, String.class); 206 if (equal(shapeStr, "square")) { 205 Keyword shapeKW = c.get("symbol-shape", null, Keyword.class); 206 if (shapeKW == null) 207 return null; 208 if (equal(shapeKW, "square")) { 207 209 shape = SymbolShape.SQUARE; 208 } else if (equal(shape Str, "circle")) {210 } else if (equal(shapeKW, "circle")) { 209 211 shape = SymbolShape.CIRCLE; 210 212 } else -
trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java
r3899 r3967 12 12 13 13 public class TextElement { 14 // textKey == null means automatic generation of text string, otherwise 15 // the corresponding tag value is used 14 16 public String textKey; 15 17 public Font font; … … 29 31 30 32 public static TextElement create(Cascade c, Color defTextColor) { 31 String textStr = c.get("text", null, String.class);32 if (textStr == null)33 return null;34 33 35 34 String textKey = null; 36 if (!"auto".equalsIgnoreCase(textStr)) { 37 textKey = textStr; 38 } 35 Keyword textKW = c.get("text", null, Keyword.class, true); 36 if (textKW == null) { 37 textKey = c.get("text", null, String.class); 38 if (textKey == null) 39 return null; 40 } else if (!textKW.val.equals("auto")) 41 return null; 39 42 40 43 Font font = ElemStyle.getFont(c); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.java
r3912 r3967 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm.gui.mappaint.Keyword; 8 9 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 9 10 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; … … 1039 1040 1040 1041 final public Object literal() throws ParseException { 1041 Objectval;1042 String val; 1042 1043 Token t; 1043 1044 float f; 1044 1045 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { 1045 1046 case IDENT: 1047 t = jj_consume_token(IDENT); 1048 {if (true) return new Keyword(t.image);} 1049 break; 1046 1050 case STRING: 1047 val = string _or_ident();1048 1051 val = string(); 1052 {if (true) return val;} 1049 1053 break; 1050 1054 case PLUS: … … 1167 1171 } 1168 1172 1169 private boolean jj_3R_41() {1170 if (jj_scan_token(DOLLAR)) return true;1171 if (jj_scan_token(EQUAL)) return true;1172 return false;1173 }1174 1175 1173 private boolean jj_3R_40() { 1176 1174 if (jj_scan_token(CARET)) return true; … … 1273 1271 } 1274 1272 1273 private boolean jj_3R_85() { 1274 if (jj_scan_token(HEXCOLOR)) return true; 1275 return false; 1276 } 1277 1275 1278 private boolean jj_3R_27() { 1276 1279 if (jj_3R_50()) return true; … … 1279 1282 1280 1283 private boolean jj_3R_84() { 1281 if (jj_ scan_token(HEXCOLOR)) return true;1284 if (jj_3R_28()) return true; 1282 1285 return false; 1283 1286 } 1284 1287 1285 1288 private boolean jj_3R_83() { 1289 if (jj_scan_token(PLUS)) return true; 1286 1290 if (jj_3R_28()) return true; 1287 1291 return false; … … 1304 1308 1305 1309 private boolean jj_3R_82() { 1306 if (jj_scan_token(PLUS)) return true; 1307 if (jj_3R_28()) return true; 1310 if (jj_3R_54()) return true; 1308 1311 return false; 1309 1312 } 1310 1313 1311 1314 private boolean jj_3R_81() { 1312 if (jj_ 3R_56()) return true;1315 if (jj_scan_token(IDENT)) return true; 1313 1316 return false; 1314 1317 } … … 1323 1326 if (jj_3R_83()) { 1324 1327 jj_scanpos = xsp; 1325 if (jj_3R_84()) return true; 1328 if (jj_3R_84()) { 1329 jj_scanpos = xsp; 1330 if (jj_3R_85()) return true; 1331 } 1326 1332 } 1327 1333 } … … 1361 1367 } 1362 1368 1363 private boolean jj_3R_8 5() {1369 private boolean jj_3R_86() { 1364 1370 if (jj_scan_token(COMMA)) return true; 1365 1371 if (jj_3R_18()) return true; … … 1383 1389 while (true) { 1384 1390 xsp = jj_scanpos; 1385 if (jj_3R_8 5()) { jj_scanpos = xsp; break; }1391 if (jj_3R_86()) { jj_scanpos = xsp; break; } 1386 1392 } 1387 1393 return false; … … 1850 1856 private boolean jj_3R_42() { 1851 1857 if (jj_scan_token(STAR)) return true; 1858 if (jj_scan_token(EQUAL)) return true; 1859 return false; 1860 } 1861 1862 private boolean jj_3R_41() { 1863 if (jj_scan_token(DOLLAR)) return true; 1852 1864 if (jj_scan_token(EQUAL)) return true; 1853 1865 return false; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.jj
r3912 r3967 11 11 import java.util.List; 12 12 13 import org.openstreetmap.josm.gui.mappaint.Keyword; 13 14 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 14 15 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; … … 523 524 Object literal() : 524 525 { 525 Objectval;526 String val; 526 527 Token t; 527 528 float f; 528 529 } 529 530 { 530 val=string_or_ident() { return val; } 531 t=<IDENT> { return new Keyword(t.image); } 532 | 533 val=string() { return val; } 531 534 | 532 535 <PLUS> f=ufloat() { return new Instruction.RelativeFloat(f); } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParserTokenManager.java
r3902 r3967 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import org.openstreetmap.josm.gui.mappaint.Keyword; 6 7 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 7 8 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3894 r3967 20 20 import org.openstreetmap.josm.data.osm.Way; 21 21 import org.openstreetmap.josm.gui.mappaint.Cascade; 22 import org.openstreetmap.josm.gui.mappaint.Keyword; 22 23 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 23 24 import org.openstreetmap.josm.gui.mappaint.Range; … … 288 289 if (icon.annotate != null) { 289 290 if (icon.annotate) { 290 def.put("text", "auto");291 def.put("text", Keyword.AUTO); 291 292 } else { 292 293 def.remove("text"); … … 352 353 if (p.area != null) { 353 354 def.putOrClear("fill-color", p.area.color); 354 def.putOrClear("text-position", "center");355 def.putOrClear("text", "auto");355 def.putOrClear("text-position", Keyword.CENTER); 356 def.putOrClear("text", Keyword.AUTO); 356 357 def.remove("fill-image"); 357 358 }
Note:
See TracChangeset
for help on using the changeset viewer.