Changeset 4007 in josm for trunk/src/org
- Timestamp:
- 2011-03-27T13:41:58+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/LabelCompositionStrategy.java
r3987 r4007 48 48 static public class StaticLabelCompositionStrategy extends LabelCompositionStrategy { 49 49 private String defaultLabel; 50 50 51 public StaticLabelCompositionStrategy(String defaultLabel){ 51 52 this.defaultLabel = defaultLabel; -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3967 r4007 21 21 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 22 22 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 23 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration; 23 24 import org.openstreetmap.josm.gui.preferences.SourceEntry; 24 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration;25 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 26 import org.openstreetmap.josm.io.MirroredInputStream; … … 42 42 return styles; 43 43 } 44 44 45 /** 46 * Value holder for a reference to a tag name. A style instruction 47 * <pre> 48 * text: a_tag_name; 49 * </pre> 50 * results in a tag reference for the tag <tt>a_tag_name</tt> in the 51 * style cascade. 52 */ 53 public static class TagKeyReference { 54 public final String key; 55 public TagKeyReference(String key){ 56 this.key = key; 57 } 58 59 @Override 60 public String toString() { 61 return "TagKeyReference{" + "key='" + key + "'}"; 62 } 63 } 64 45 65 public static class IconReference { 46 66 47 public String iconName;48 public StyleSource source;67 public final String iconName; 68 public final StyleSource source; 49 69 50 70 public IconReference(String iconName, StyleSource source) { … … 59 79 } 60 80 61 public static ImageIcon getIcon(IconReference ref, boolean sanitize) 62 { 81 public static ImageIcon getIcon(IconReference ref, boolean sanitize) { 63 82 String namespace = ref.source.getPrefName(); 64 83 ImageIcon i = ImageProvider.getIfAvailable(getIconSourceDirs(ref.source), "mappaint."+namespace, null, ref.iconName, ref.source.zipIcons, sanitize); … … 112 131 dirs.add("resource://images/styles/"); 113 132 } 114 133 115 134 return dirs; 116 135 } … … 130 149 source.loadStyleSource(); 131 150 } 132 151 133 152 fireMapPaintSylesUpdated(); 134 153 } … … 139 158 in = new MirroredInputStream(entry.url); 140 159 InputStream zip = in.getZipEntry("xml", "style"); 141 if (zip != null) {160 if (zip != null) 142 161 return new XmlStyleSource(entry); 143 }144 162 zip = in.getZipEntry("mapcss", "style"); 145 if (zip != null) {163 if (zip != null) 146 164 return new MapCSSStyleSource(entry); 147 } 148 if (entry.url.toLowerCase().endsWith(".mapcss")) { 165 if (entry.url.toLowerCase().endsWith(".mapcss")) 149 166 return new MapCSSStyleSource(entry); 150 } 151 if (entry.url.toLowerCase().endsWith(".xml")) { 167 if (entry.url.toLowerCase().endsWith(".xml")) 152 168 return new XmlStyleSource(entry); 153 }else {169 else { 154 170 InputStreamReader reader = new InputStreamReader(in); 155 171 WHILE: while (true) { … … 272 288 Arrays.sort(selSorted); 273 289 274 if (i < 0) {// Up290 if (i < 0) // Up 275 291 return selSorted[0] >= -i; 276 } else 277 if (i > 0) { // Down 292 else if (i > 0) // Down 278 293 return selSorted[selSorted.length-1] <= styles.getStyleSources().size() - 1 - i; 279 }else294 else 280 295 return true; 281 296 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/TextElement.java
r4003 r4007 9 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 10 import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.DeriveLabelFromNameTagsCompositionStrategy; 11 import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.StaticLabelCompositionStrategy; 11 12 import org.openstreetmap.josm.gui.mappaint.LabelCompositionStrategy.TagLookupCompositionStrategy; 13 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.TagKeyReference; 12 14 import org.openstreetmap.josm.tools.CheckParameterUtil; 13 15 import org.openstreetmap.josm.tools.Utils; … … 81 83 */ 82 84 protected static LabelCompositionStrategy buildLabelCompositionStrategy(Cascade c, boolean defaultAnnotate){ 83 Keyword textKW = c.get("text", null, Keyword.class, true); 84 if (textKW == null) { 85 String textKey = c.get("text", null, String.class); 86 if (textKey == null) 87 return defaultAnnotate ? AUTO_LABEL_COMPOSITION_STRATEGY : null; 88 return new TagLookupCompositionStrategy(textKey); 89 } else if (textKW.val.equals("auto")) 85 /* 86 * If the cascade includes a TagKeyReference we will lookup the rendered label 87 * from a tag value. 88 */ 89 TagKeyReference tkr = c.get("text", null, TagKeyReference.class, true); 90 if (tkr != null) 91 return new TagLookupCompositionStrategy(tkr.key); 92 93 /* 94 * Check whether the label composition strategy is given by 95 * a keyword 96 */ 97 Keyword keyword = c.get("text", null, Keyword.class, true); 98 if (equal(keyword, Keyword.AUTO)) 90 99 return AUTO_LABEL_COMPOSITION_STRATEGY; 91 else 92 return new TagLookupCompositionStrategy(textKW.val); 100 101 /* 102 * Do we have a static text label? 103 */ 104 String text = c.get("text", null, String.class, true); 105 if (text != null) 106 return new StaticLabelCompositionStrategy(text); 107 return defaultAnnotate ? AUTO_LABEL_COMPOSITION_STRATEGY : null; 93 108 } 94 109 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Expression.java
r3980 r4007 16 16 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 17 17 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Relation; 18 20 import org.openstreetmap.josm.gui.mappaint.Cascade; 19 21 import org.openstreetmap.josm.gui.mappaint.Environment; 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 20 23 import org.openstreetmap.josm.tools.Utils; 21 24 22 25 public interface Expression { 23 24 26 public Object evaluate(Environment env); 25 27 … … 27 29 Object literal; 28 30 29 public LiteralExpression(Object lit) { 30 this.literal = lit; 31 public LiteralExpression(Object literal) { 32 CheckParameterUtil.ensureParameterNotNull(literal); 33 this.literal = literal; 31 34 } 32 35 … … 38 41 @Override 39 42 public String toString() { 40 if (literal == null)41 return "Lit{<null>}";42 43 if (literal instanceof float[]) 43 44 return Arrays.toString((float[]) literal); … … 47 48 48 49 public static class FunctionExpression implements Expression { 50 //static Logger logger = Logger.getLogger(FunctionExpression.class.getName()); 51 49 52 String name; 50 53 List<Expression> args; … … 73 76 if (args.length == 0) 74 77 return 0f; 75 if (args.length == 1) { // unary minus78 if (args.length == 1) 76 79 return -args[0]; 77 }78 80 float res = args[0]; 79 81 for (int i=1; i<args.length; ++i) { … … 160 162 } 161 163 162 public String get_tag_value(String key) {164 public String tag(String key) { 163 165 return env.osm.get(key); 166 } 167 168 // FIXME: respect parent selector chain 169 public String parent_tag(String key) { 170 for (Relation parent: OsmPrimitive.getFilteredList(env.osm.getReferrers(), Relation.class)) { 171 String value = parent.get(key); 172 if (value != null) return value; 173 } 174 return null; 164 175 } 165 176 … … 286 297 } 287 298 for (Method m : allMethods) { 288 if (!m.getName().equals(name)) 299 if (!m.getName().equals(name)) { 289 300 continue; 301 } 290 302 Class<?>[] expectedParameterTypes = m.getParameterTypes(); 291 303 Object[] convertedArgs = new Object[expectedParameterTypes.length]; … … 304 316 convertedArgs[0] = arrayArg; 305 317 } else { 306 if (args.size() != expectedParameterTypes.length) 318 if (args.size() != expectedParameterTypes.length) { 307 319 continue; 320 } 308 321 for (int i=0; i<args.size(); ++i) { 309 322 convertedArgs[i] = Cascade.convertTo(args.get(i).evaluate(env), expectedParameterTypes[i]); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Instruction.java
r4006 r4007 4 4 import java.util.Arrays; 5 5 6 import org.openstreetmap.josm.gui.mappaint.Cascade; 6 7 import org.openstreetmap.josm.gui.mappaint.Environment; 8 import org.openstreetmap.josm.gui.mappaint.Keyword; 9 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 7 10 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 8 11 … … 12 15 13 16 public static class RelativeFloat { 14 public f loat val;17 public final float val; 15 18 16 19 public RelativeFloat(float val) { … … 25 28 26 29 public static class AssignmentInstruction extends Instruction { 27 String key; 28 Object val; 30 //static private final Logger logger = Logger.getLogger(AssignmentInstruction.class.getName()); 31 public final String key; 32 public final Object val; 29 33 30 34 public AssignmentInstruction(String key, Object val) { 31 35 this.key = key; 32 36 if (val instanceof Expression.LiteralExpression) { 33 this.val = ((Expression.LiteralExpression) val).evaluate(null); 37 Object litValue = ((Expression.LiteralExpression) val).evaluate(null); 38 if (key.equals("text")) { 39 /* Special case for declaration 'text: ...' 40 * 41 * - Treat the value 'auto' as keyword. 42 * - Treat any other literal value 'litval' as as reference to tag with key 'litval' 43 * 44 * - Accept function expressions as is. This allows for 45 * tag(a_tag_name) value of a tag 46 * eval("a static text") a static text 47 * parent_tag(a_tag_name) value of a tag of a parent relation 48 */ 49 if (litValue.equals(Keyword.AUTO)) { 50 this.val = Keyword.AUTO; 51 } else { 52 String s = Cascade.convertTo(litValue, String.class); 53 if (s != null) { 54 this.val = new MapPaintStyles.TagKeyReference(s); 55 } else { 56 this.val = litValue; 57 } 58 } 59 } else { 60 this.val = litValue; 61 } 34 62 } else { 35 63 this.val = val; … … 39 67 @Override 40 68 public void execute(Environment env) { 41 Object value = (val instanceof Expression) ? ((Expression) val).evaluate(env) : val; 69 Object value = null; 70 if (val instanceof Expression) { 71 value = ((Expression) val).evaluate(env); 72 } else { 73 value = val; 74 } 42 75 if (key.equals("icon-image") || key.equals("fill-image") || key.equals("pattern-image")) { 43 76 if (value instanceof String) {
Note:
See TracChangeset
for help on using the changeset viewer.