Changeset 6896 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-03-02T16:23:58+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r6310 r6896 184 184 } 185 185 186 int alpha = 255;186 int alpha = color.getAlpha(); 187 187 Integer pAlpha = Utils.color_float2int(c.get(type.prefix + OPACITY, null, Float.class)); 188 188 if (pAlpha != null) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r6889 r6896 21 21 import org.openstreetmap.josm.tools.Utils; 22 22 23 /** 24 * A mappaint style (abstract class). 25 * 26 * Handles everything from parsing the style definition to application 27 * of the style to an osm primitive. 28 */ 23 29 public abstract class StyleSource extends SourceEntry { 24 30 … … 44 50 } 45 51 52 /** 53 * Apply style to osm primitive. 54 * 55 * Adds properties to a MultiCascade. All active {@link StyleSource}s add 56 * their properties on after the other. At a later stage, concrete painting 57 * primitives (lines, icons, text, ...) are derived from the MultiCascade. 58 * @param mc the current MultiCascade, empty for the first StyleSource 59 * @param osm the primitive 60 * @param scale the map scale 61 * @param multipolyOuterWay support for a very old multipolygon tagging style 62 * where you add the tags both to the outer and the inner way. 63 * However, independent inner way style is also possible. 64 * @param pretendWayIsClosed For styles that require the way to be closed, 65 * we pretend it is. This is useful for generating area styles from the (segmented) 66 * outer ways of a multipolygon. 67 */ 46 68 public abstract void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed); 47 69 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r6883 r6896 731 731 return result; 732 732 } 733 734 @Override 735 public String toString() { 736 StringBuilder b = new StringBuilder("ParameterFunction~"); 737 b.append(m.getName()).append("("); 738 for (int i = 0; i < args.size(); ++i) { 739 if (i > 0) b.append(","); 740 b.append(expectedParameterTypes[i]); 741 b.append(" ").append(args.get(i)); 742 } 743 b.append(')'); 744 return b.toString(); 745 } 746 733 747 } 734 748 … … 780 794 return result; 781 795 } 796 @Override 797 public String toString() { 798 StringBuilder b = new StringBuilder("ArrayFunction~"); 799 b.append(m.getName()).append("("); 800 for (int i = 0; i < args.size(); ++i) { 801 if (i > 0) b.append(","); 802 b.append(arrayComponentType); 803 b.append(" ").append(args.get(i)); 804 } 805 b.append(')'); 806 return b.toString(); 807 } 808 782 809 } 783 810 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r6883 r6896 85 85 @Override 86 86 public String toString() { 87 return key + ':' + (val instanceof float[] ? Arrays.toString((float[]) val): val) + ';';87 return key + ": " + (val instanceof float[] ? Arrays.toString((float[]) val) : val instanceof String ? "String<"+val+">" : val) + ';'; 88 88 } 89 89 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6830 r6896 41 41 42 42 <DEFAULT> 43 TOKEN [IGNORE_CASE]: 44 { 45 /* Special keywords in some contexts, ordinary identifiers in other contexts. 46 Don't use the javacc token contexts (except DEFAULT and COMMENT) because 47 they complicate error handling. Instead simply add a parsing rule <code>ident()</code> 48 that parses the IDENT token and in addition all the keyword tokens. */ 49 < AND: "and" > 50 | < SET: "set" > 51 | < NOT: "not" > 52 | < MEDIA: "@media" > 53 } 54 55 <DEFAULT> 43 56 TOKEN: 44 57 { 45 < SET: ("set" | "SET") > 46 | < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* > 58 < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* > 47 59 | < UINT: ["1"-"9"] ( ["0"-"9"] )* > 48 60 | < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? > … … 122 134 * 'val' can be a literal, or an expression like "prop(width, default) + 0.8". 123 135 * 136 * @media { ... } queries are supported, following http://www.w3.org/TR/css3-mediaqueries/#syntax 137 * 138 * media_query 139 * ___________________________|_______________________________ 140 * | | 141 * @media all and (min-josm-version: 7789) and (max-josm-version: 7790), all and (user-agent: xyz) { ... } 142 * |______________________| 143 * | 144 * media_expression 124 145 */ 125 146 … … 166 187 } 167 188 189 String ident(): 190 { 191 Token t; 192 String s; 193 } 194 { 195 ( t=<IDENT> | t=<SET> | t=<NOT> | t=<AND> ) { return t.image; } 196 } 197 168 198 String string_or_ident() : 169 199 { … … 172 202 } 173 203 { 174 t=<IDENT> { return t.image; } | s=string() { return s; }204 ( s=ident() | s=string() ) { return s; } 175 205 } 176 206 … … 229 259 { 230 260 MapCSSRule r; 231 Token com = null;232 261 } 233 262 { 234 263 { this.sheet = sheet; } 235 264 w() 265 rules(true) ( media() w() rules(true) )* 266 <EOF> 267 } 268 269 void media(): 270 { 271 boolean pass = false; 272 boolean q; 273 boolean empty = true; 274 } 275 { 276 <MEDIA> w() 277 ( q=media_query() { pass = pass || q; empty = false; } 278 ( <COMMA> w() q=media_query() { pass = pass || q; } )* 279 )? 280 <LBRACE> w() 281 rules(empty || pass) 282 <RBRACE> 283 } 284 285 boolean media_query(): 286 { 287 Token t; 288 String mediatype = "all"; 289 boolean pass = true; 290 boolean invert = false; 291 boolean e; 292 } 293 { 294 ( <NOT> { invert = true; } w() )? 295 ( 296 t=<IDENT> { mediatype = t.image.toLowerCase(); } w() 297 ( <AND> w() e=media_expression() { pass = pass && e; } w() )* 298 | 299 e=media_expression() { pass = pass && e; } w() 300 ( <AND> w() e=media_expression() { pass = pass && e; } w() )* 301 ) 302 { 303 if (!"all".equals(mediatype)) { 304 pass = false; 305 } 306 return invert ? (!pass) : pass; 307 } 308 } 309 310 boolean media_expression(): 311 { 312 Token t; 313 String feature; 314 Object val = null; 315 } 316 { 317 <LPAR> w() t=<IDENT> { feature = t.image; } w() ( <COLON> w() val=literal() )? <RPAR> 318 { return this.sheet.evalMediaExpression(feature, val); } 319 } 320 321 void rules(boolean add): 322 { 323 MapCSSRule r; 324 } 325 { 236 326 ( 237 327 try { 238 r=rule() { if (r != null) { sheet.rules.add(r); } } w()328 r=rule() { if (add && r != null) { sheet.rules.add(r); } } w() 239 329 } catch (MapCSSException mex) { 240 330 error_skipto(RBRACE, mex); … … 245 335 } 246 336 )* 247 <EOF>248 337 } 249 338 … … 345 434 String tag_key() : 346 435 { 347 String s ;436 String s, s2; 348 437 Token t; 349 438 } … … 351 440 s=string() { return s; } 352 441 | 353 t=<IDENT> { s = t.image; } ( <COLON> t=<IDENT> { s += ':' + t.image; } )* { return s; }442 s=ident() ( <COLON> s2=ident() { s += ':' + s2; } )* { return s; } 354 443 } 355 444 … … 435 524 Condition class_or_pseudoclass(Context context) : 436 525 { 437 Token t;526 String s; 438 527 boolean not = false; 439 528 boolean pseudo; … … 446 535 <COLON> { pseudo = true; } 447 536 ) 448 t=<IDENT>537 s=ident() 449 538 { return pseudo 450 ? Condition.createPseudoClassCondition( t.image, not, context)451 : Condition.createClassCondition( t.image, not, context); }539 ? Condition.createPseudoClassCondition(s, not, context) 540 : Condition.createClassCondition(s, not, context); } 452 541 } 453 542 454 543 String subpart() : 455 544 { 456 Token t;545 String s; 457 546 } 458 547 { 459 548 <DCOLON> 460 ( t=<IDENT> | t=<STAR> ) 461 { return t.image; } 549 ( s=ident() { return s; } | <STAR> { return "*"; } ) 462 550 } 463 551 … … 573 661 } 574 662 { 575 tmp=<IDENT> { name = tmp.image; }w()663 name=ident() w() 576 664 <LPAR> w() 577 665 ( -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r6868 r6896 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.Version; 18 19 import org.openstreetmap.josm.data.osm.Node; 19 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 213 214 } 214 215 216 public boolean evalMediaExpression(String feature, Object val) { 217 if ("user-agent".equals(feature)) { 218 String s = Cascade.convertTo(val, String.class); 219 if ("josm".equals(s)) return true; 220 } 221 if ("min-josm-version".equals(feature)) { 222 Float v = Cascade.convertTo(val, Float.class); 223 if (v != null) return Math.round(v) <= Version.getInstance().getVersion(); 224 } 225 if ("max-josm-version".equals(feature)) { 226 Float v = Cascade.convertTo(val, Float.class); 227 if (v != null) return Math.round(v) >= Version.getInstance().getVersion(); 228 } 229 return false; 230 } 231 215 232 @Override 216 233 public String toString() {
Note:
See TracChangeset
for help on using the changeset viewer.