Changeset 4431 in josm for trunk/src/org
- Timestamp:
- 2011-09-17T10:59:32+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r4282 r4431 74 74 /** 75 75 * <p>Replies the projected east/north coordinates.</p> 76 * 76 * 77 77 * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates. 78 78 * Internally caches the projected coordinates.</p> … … 80 80 * <p><strong>Caveat:</strong> doesn't listen to projection changes. Clients must 81 81 * {@link #reproject() trigger a reprojection} or {@link #invalidateEastNorthCache() invalidate the internal cache}.</p> 82 * 82 * 83 83 * @return the east north coordinates or {@code null} 84 84 * @see #invalidateEastNorthCache() 85 * 85 * 86 86 */ 87 87 public final EastNorth getEastNorth() { … … 123 123 124 124 @Override 125 public Object getTemplateValue(String name) { 126 return attr.get(name); 125 public Object getTemplateValue(String name, boolean special) { 126 if (!special) 127 return attr.get(name); 128 else 129 return null; 127 130 } 128 131 -
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r4150 r4431 17 17 18 18 public abstract class AbstractPrimitive implements IPrimitive { 19 19 20 20 private static final AtomicLong idCounter = new AtomicLong(0); 21 21 … … 305 305 } 306 306 } 307 307 308 308 /** 309 309 * Marks this primitive as being modified. … … 373 373 return (flags & FLAG_VISIBLE) != 0; 374 374 } 375 375 376 376 /** 377 377 * Sets whether this primitive is visible, i.e. whether it is known on the server … … 414 414 return (flags & FLAG_INCOMPLETE) != 0; 415 415 } 416 416 417 417 protected String getFlagsAsString() { 418 418 StringBuilder builder = new StringBuilder(); … … 528 528 } 529 529 } 530 530 531 531 /** 532 532 * Remove the given key from the list … … 589 589 } 590 590 591 public final String getIgnoreCase(String key) { 592 String[] keys = this.keys; 593 if (key == null) 594 return null; 595 if (keys == null) 596 return null; 597 for (int i=0; i<keys.length;i+=2) { 598 if (keys[i].equalsIgnoreCase(key)) return keys[i+1]; 599 } 600 return null; 601 } 602 591 603 @Override 592 604 public final Collection<String> keySet() { … … 642 654 */ 643 655 abstract protected void keysChangedImpl(Map<String, String> originalKeys); 644 656 645 657 /** 646 658 * Replies the name of this primitive. The default implementation replies the value … … 680 692 return getName(); 681 693 } 682 683 /**684 * Replies the display name of a primitive formatted by <code>formatter</code>685 *686 * @return the display name687 */688 @Override689 public abstract String getDisplayName(NameFormatter formatter);690 694 691 695 } -
trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java
r4100 r4431 30 30 int getChangesetId(); 31 31 void setChangesetId(int changesetId); 32 32 33 33 void visit(PrimitiveVisitor visitor); 34 34 String getName(); 35 35 String getLocalName(); 36 String getDisplayName(NameFormatter formatter);37 36 38 37 } -
trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java
r4100 r4431 5 5 6 6 public interface NameFormatter { 7 String format( INode node);8 String format( IWay way);9 String format( IRelation relation);7 String format(Node node); 8 String format(Way way); 9 String format(Relation relation); 10 10 String format(Changeset changeset); 11 11 -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r4126 r4431 25 25 return lat != Double.NaN && lon != Double.NaN; 26 26 } 27 27 28 28 @Override 29 29 public LatLon getCoor() { … … 77 77 } 78 78 79 @Override80 public String getDisplayName(NameFormatter formatter) {81 return formatter.format(this);82 }83 79 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r4103 r4431 25 25 import org.openstreetmap.josm.tools.CheckParameterUtil; 26 26 import org.openstreetmap.josm.tools.Predicate; 27 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; 27 28 28 29 /** … … 36 37 * @author imi 37 38 */ 38 abstract public class OsmPrimitive extends AbstractPrimitive implements Comparable<OsmPrimitive> { 39 abstract public class OsmPrimitive extends AbstractPrimitive implements Comparable<OsmPrimitive>, TemplateEngineDataProvider { 40 private static final String SPECIAL_VALUE_ID = "id"; 41 private static final String SPECIAL_VALUE_LOCAL_NAME = "localname"; 42 39 43 40 44 /** … … 412 416 super.updateFlags(flag, value); 413 417 } 414 418 415 419 @Override 416 420 protected final void updateFlags(int flag, boolean value) { … … 621 625 622 626 String directionDefault = "oneway? | incline=* | aerialway=* | "+ 623 "waterway=stream | waterway=river | waterway=canal | waterway=drain | waterway=rapids | "+624 "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+625 "junction=roundabout";627 "waterway=stream | waterway=river | waterway=canal | waterway=drain | waterway=rapids | "+ 628 "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+ 629 "junction=roundabout"; 626 630 627 631 try { … … 700 704 * Keys handling 701 705 ------------*/ 702 706 703 707 @Override 704 708 public final void setKeys(Map<String, String> keys) { … … 710 714 } 711 715 } 712 716 713 717 @Override 714 718 public final void put(String key, String value) { … … 719 723 writeUnlock(locked); 720 724 } 721 } 722 725 } 726 723 727 @Override 724 728 public final void remove(String key) { … … 739 743 writeUnlock(locked); 740 744 } 741 } 742 745 } 746 743 747 @Override 744 748 protected final void keysChangedImpl(Map<String, String> originalKeys) { … … 857 861 /** 858 862 * <p>Visits {@code visitor} for all referrers.</p> 859 * 863 * 860 864 * @param visitor the visitor. Ignored, if null. 861 865 */ … … 889 893 if (referrers == null) return false; 890 894 checkDataset(); 891 if (referrers instanceof OsmPrimitive) {892 return n<=1 && referrers instanceof Way && ((OsmPrimitive)referrers).dataSet == dataSet;893 }else {894 int counter=0;895 for (OsmPrimitive o : (OsmPrimitive[])referrers) {896 if (dataSet == o.dataSet && o instanceof Way) {897 if (++counter >= n)898 return true;899 }900 }901 return false;895 if (referrers instanceof OsmPrimitive) 896 return n<=1 && referrers instanceof Way && ((OsmPrimitive)referrers).dataSet == dataSet; 897 else { 898 int counter=0; 899 for (OsmPrimitive o : (OsmPrimitive[])referrers) { 900 if (dataSet == o.dataSet && o instanceof Way) { 901 if (++counter >= n) 902 return true; 903 } 904 } 905 return false; 902 906 } 903 907 } … … 1002 1006 1003 1007 return 1004 isDeleted() == other.isDeleted()1005 && isModified() == other.isModified()1006 && timestamp == other.timestamp1007 && version == other.version1008 && isVisible() == other.isVisible()1009 && (user == null ? other.user==null : user==other.user)1010 && changesetId == other.changesetId;1008 isDeleted() == other.isDeleted() 1009 && isModified() == other.isModified() 1010 && timestamp == other.timestamp 1011 && version == other.version 1012 && isVisible() == other.isVisible() 1013 && (user == null ? other.user==null : user==other.user) 1014 && changesetId == other.changesetId; 1011 1015 } 1012 1016 … … 1101 1105 } 1102 1106 1107 /** 1108 * Replies the display name of a primitive formatted by <code>formatter</code> 1109 * 1110 * @return the display name 1111 */ 1112 public abstract String getDisplayName(NameFormatter formatter); 1113 1114 @Override 1115 public Collection<String> getTemplateKeys() { 1116 Collection<String> keySet = keySet(); 1117 List<String> result = new ArrayList<String>(keySet.size() + 2); 1118 result.add(SPECIAL_VALUE_ID); 1119 result.add(SPECIAL_VALUE_LOCAL_NAME); 1120 result.addAll(keySet); 1121 return result; 1122 } 1123 1124 @Override 1125 public Object getTemplateValue(String name, boolean special) { 1126 if (special) { 1127 String lc = name.toLowerCase(); 1128 if (SPECIAL_VALUE_ID.equals(lc)) 1129 return getId(); 1130 else if (SPECIAL_VALUE_LOCAL_NAME.equals(lc)) 1131 return getLocalName(); 1132 else 1133 return null; 1134 1135 } else 1136 return getIgnoreCase(name); 1137 } 1138 1139 @Override 1140 public boolean evaluateCondition(Match condition) { 1141 return condition.match(this); 1142 } 1143 1103 1144 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationData.java
r4100 r4431 62 62 return OsmPrimitiveType.RELATION; 63 63 } 64 65 @Override 64 65 @Override 66 66 public void visit(PrimitiveVisitor visitor) { 67 67 visitor.visit(this); 68 68 } 69 69 70 @Override71 public String getDisplayName(NameFormatter formatter) {72 return formatter.format(this);73 }74 75 70 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r4321 r4431 162 162 visitor.visit(this); 163 163 } 164 164 165 165 @Override public void visit(PrimitiveVisitor visitor) { 166 166 visitor.visit(this); … … 453 453 454 454 455 @Override456 455 public String getDisplayName(NameFormatter formatter) { 457 456 return formatter.format(this); -
trunk/src/org/openstreetmap/josm/data/osm/WayData.java
r4100 r4431 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 6 7 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; 7 8 … … 57 58 return OsmPrimitiveType.WAY; 58 59 } 59 60 @Override 60 61 @Override 61 62 public void visit(PrimitiveVisitor visitor) { 62 63 visitor.visit(this); 63 64 } 64 65 65 @Override66 public String getDisplayName(NameFormatter formatter) {67 return formatter.format(this);68 }69 70 66 } -
trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java
r4324 r4431 19 19 import org.openstreetmap.josm.data.coor.CoordinateFormat; 20 20 import org.openstreetmap.josm.data.osm.Changeset; 21 import org.openstreetmap.josm.data.osm.INode;22 21 import org.openstreetmap.josm.data.osm.IPrimitive; 23 22 import org.openstreetmap.josm.data.osm.IRelation; 24 import org.openstreetmap.josm.data.osm.IWay;25 23 import org.openstreetmap.josm.data.osm.NameFormatter; 26 24 import org.openstreetmap.josm.data.osm.Node; 27 import org.openstreetmap.josm.data.osm.OsmPrimitive;28 25 import org.openstreetmap.josm.data.osm.OsmUtils; 29 26 import org.openstreetmap.josm.data.osm.Relation; 30 import org.openstreetmap.josm.data.osm.RelationMember;31 27 import org.openstreetmap.josm.data.osm.Way; 32 28 import org.openstreetmap.josm.data.osm.history.HistoryNameFormatter; … … 35 31 import org.openstreetmap.josm.data.osm.history.HistoryRelation; 36 32 import org.openstreetmap.josm.data.osm.history.HistoryWay; 33 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 34 import org.openstreetmap.josm.tools.TaggingPresetNameTemplateList; 37 35 38 36 /** … … 57 55 return instance; 58 56 } 59 57 60 58 /** 61 59 * Registers a format hook. Adds the hook at the first position of the format hooks. … … 103 101 namingTagsForRelations = new ArrayList<String>( 104 102 Main.pref.getCollection("relation.nameOrder", Arrays.asList(DEFAULT_NAMING_TAGS_FOR_RELATIONS)) 105 );103 ); 106 104 } 107 105 return namingTagsForRelations; … … 116 114 * @return the decorated name 117 115 */ 118 protected String decorateNameWithId(Stringname, IPrimitive primitive) {119 if (Main.pref.getBoolean("osm-primitives.showid")) 120 if (Main.pref.getBoolean("osm-primitives.showid.new-primitives")) 121 return name + tr(" [id: {0}]", primitive.getUniqueId());122 else123 return name + tr(" [id: {0}]", primitive.getId());124 else125 return name;116 protected void decorateNameWithId(StringBuilder name, IPrimitive primitive) { 117 if (Main.pref.getBoolean("osm-primitives.showid")) { 118 if (Main.pref.getBoolean("osm-primitives.showid.new-primitives")) { 119 name.append(tr(" [id: {0}]", primitive.getUniqueId())); 120 } else { 121 name.append(tr(" [id: {0}]", primitive.getId())); 122 } 123 } 126 124 } 127 125 … … 132 130 * @return the name 133 131 */ 134 public String format( INode node) {135 String name = "";132 public String format(Node node) { 133 StringBuilder name = new StringBuilder(); 136 134 if (node.isIncomplete()) { 137 name = tr("incomplete"); 138 } else { 139 if (Main.pref.getBoolean("osm-primitives.localize-name", true)) { 140 name = node.getLocalName(); 135 name.append(tr("incomplete")); 136 } else { 137 TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(node); 138 if (preset == null) { 139 String n; 140 if (Main.pref.getBoolean("osm-primitives.localize-name", true)) { 141 n = node.getLocalName(); 142 } else { 143 n = node.getName(); 144 } 145 if(n == null) 146 { 147 String s; 148 if((s = node.get("addr:housename")) != null) { 149 /* I18n: name of house as parameter */ 150 n = tr("House {0}", s); 151 } 152 if(n == null && (s = node.get("addr:housenumber")) != null) { 153 String t = node.get("addr:street"); 154 if(t != null) { 155 /* I18n: house number, street as parameter, number should remain 156 before street for better visibility */ 157 n = tr("House number {0} at {1}", s, t); 158 } 159 else { 160 /* I18n: house number as parameter */ 161 n = tr("House number {0}", s); 162 } 163 } 164 } 165 166 if (n == null) { 167 n = node.isNew() ? tr("node") : ""+ node.getId(); 168 } 169 name.append(n); 141 170 } else { 142 name = node.getName(); 143 } 144 if(name == null) 145 { 146 String s; 147 if((s = node.get("addr:housename")) != null) { 148 /* I18n: name of house as parameter */ 149 name = tr("House {0}", s); 150 } 151 if(name == null && (s = node.get("addr:housenumber")) != null) { 152 String t = node.get("addr:street"); 153 if(t != null) { 154 /* I18n: house number, street as parameter, number should remain 155 before street for better visibility */ 156 name = tr("House number {0} at {1}", s, t); 157 } 158 else { 159 /* I18n: house number as parameter */ 160 name = tr("House number {0}", s); 161 } 162 } 163 } 164 165 if (name == null) { 166 name = node.isNew() ? tr("node") : ""+ node.getId(); 167 } 168 name += " \u200E(" + node.getCoor().latToString(CoordinateFormat.getDefaultFormat()) + ", " + node.getCoor().lonToString(CoordinateFormat.getDefaultFormat()) + ")"; 169 } 170 name = decorateNameWithId(name, node); 171 171 preset.nameTemplate.appendText(name, node); 172 } 173 name.append(" \u200E(").append(node.getCoor().latToString(CoordinateFormat.getDefaultFormat())).append(", ").append(node.getCoor().lonToString(CoordinateFormat.getDefaultFormat())).append(")"); 174 } 175 decorateNameWithId(name, node); 176 177 178 String result = name.toString(); 172 179 for (NameFormatterHook hook: formatHooks) { 173 String hookResult = hook.checkFormat(node, name);174 if (hookResult != null) {180 String hookResult = hook.checkFormat(node, result); 181 if (hookResult != null) 175 182 return hookResult; 176 } 177 } 178 179 return name; 183 } 184 185 return result; 180 186 } 181 187 … … 198 204 * @return the name 199 205 */ 200 public String format( IWay way) {201 String name = "";206 public String format(Way way) { 207 StringBuilder name = new StringBuilder(); 202 208 if (way.isIncomplete()) { 203 name = tr("incomplete"); 204 } else { 205 if (Main.pref.getBoolean("osm-primitives.localize-name", true)) { 206 name = way.getLocalName(); 209 name.append(tr("incomplete")); 210 } else { 211 TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(way); 212 if (preset == null) { 213 String n; 214 if (Main.pref.getBoolean("osm-primitives.localize-name", true)) { 215 n = way.getLocalName(); 216 } else { 217 n = way.getName(); 218 } 219 if (n == null) { 220 n = way.get("ref"); 221 } 222 if (n == null) { 223 n = 224 (way.get("highway") != null) ? tr("highway") : 225 (way.get("railway") != null) ? tr("railway") : 226 (way.get("waterway") != null) ? tr("waterway") : 227 (way.get("landuse") != null) ? tr("landuse") : null; 228 } 229 if(n == null) 230 { 231 String s; 232 if((s = way.get("addr:housename")) != null) { 233 /* I18n: name of house as parameter */ 234 n = tr("House {0}", s); 235 } 236 if(n == null && (s = way.get("addr:housenumber")) != null) { 237 String t = way.get("addr:street"); 238 if(t != null) { 239 /* I18n: house number, street as parameter, number should remain 240 before street for better visibility */ 241 n = tr("House number {0} at {1}", s, t); 242 } 243 else { 244 /* I18n: house number as parameter */ 245 n = tr("House number {0}", s); 246 } 247 } 248 } 249 if(n == null || n.length() == 0) { 250 n = String.valueOf(way.getId()); 251 } 252 253 name.append(n); 207 254 } else { 208 name = way.getName(); 209 } 210 if (name == null) { 211 name = way.get("ref"); 212 } 213 if (name == null) { 214 name = 215 (way.get("highway") != null) ? tr("highway") : 216 (way.get("railway") != null) ? tr("railway") : 217 (way.get("waterway") != null) ? tr("waterway") : 218 (way.get("landuse") != null) ? tr("landuse") : null; 219 } 220 if(name == null) 221 { 222 String s; 223 if((s = way.get("addr:housename")) != null) { 224 /* I18n: name of house as parameter */ 225 name = tr("House {0}", s); 226 } 227 if(name == null && (s = way.get("addr:housenumber")) != null) { 228 String t = way.get("addr:street"); 229 if(t != null) { 230 /* I18n: house number, street as parameter, number should remain 231 before street for better visibility */ 232 name = tr("House number {0} at {1}", s, t); 233 } 234 else { 235 /* I18n: house number as parameter */ 236 name = tr("House number {0}", s); 237 } 238 } 255 preset.nameTemplate.appendText(name, way); 239 256 } 240 257 … … 242 259 if (nodesNo > 1 && way.isClosed()) { 243 260 nodesNo--; 244 }245 if(name == null || name.length() == 0) {246 name = String.valueOf(way.getId());247 261 } 248 262 /* note: length == 0 should no longer happen, but leave the bracket code … … 250 264 /* I18n: count of nodes as parameter */ 251 265 String nodes = trn("{0} node", "{0} nodes", nodesNo, nodesNo); 252 name += (name.length() > 0) ? " ("+nodes+")" : nodes; 253 } 254 name = decorateNameWithId(name, way); 255 266 name.append(" (").append(nodes).append(")"); 267 } 268 decorateNameWithId(name, way); 269 270 String result = name.toString(); 256 271 for (NameFormatterHook hook: formatHooks) { 257 String hookResult = hook.checkFormat(way, name);258 if (hookResult != null) {272 String hookResult = hook.checkFormat(way, result); 273 if (hookResult != null) 259 274 return hookResult; 260 } 261 } 262 263 return name; 275 } 276 277 return result; 264 278 } 265 279 … … 282 296 * @return the name 283 297 */ 284 public String format( IRelation relation) {285 String name;298 public String format(Relation relation) { 299 StringBuilder name = new StringBuilder(); 286 300 if (relation.isIncomplete()) { 287 name = tr("incomplete"); 288 } else { 289 name = getRelationTypeName(relation); 301 name.append(tr("incomplete")); 302 } else { 303 TaggingPreset preset = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(relation); 304 305 formatRelationNameAndType(relation, name, preset); 306 307 int mbno = relation.getMembersCount(); 308 name.append(trn("{0} member", "{0} members", mbno, mbno)); 309 310 if (relation.hasIncompleteMembers()) { 311 name.append(", ").append(tr("incomplete")); 312 } 313 314 name.append(")"); 315 } 316 decorateNameWithId(name, relation); 317 318 String result = name.toString(); 319 for (NameFormatterHook hook: formatHooks) { 320 String hookResult = hook.checkFormat(relation, result); 321 if (hookResult != null) 322 return hookResult; 323 } 324 325 return result; 326 } 327 328 private void formatRelationNameAndType(Relation relation, StringBuilder result, TaggingPreset preset) { 329 if (preset == null) { 330 result.append(getRelationTypeName(relation)); 290 331 String relationName = getRelationName(relation); 291 332 if (relationName == null) { … … 294 335 relationName = "\"" + relationName + "\""; 295 336 } 296 name += " (" + relationName + ", "; 297 298 int mbno = relation.getMembersCount(); 299 name += trn("{0} member", "{0} members", mbno, mbno); 300 301 if (relation instanceof Relation) { 302 if (((Relation) relation).hasIncompleteMembers()) { 303 name += ", "+tr("incomplete"); 304 } 305 } 306 307 name += ")"; 308 } 309 name = decorateNameWithId(name, relation); 310 311 for (NameFormatterHook hook: formatHooks) { 312 String hookResult = hook.checkFormat(relation, name); 313 if (hookResult != null) { 314 return hookResult; 315 } 316 } 317 318 return name; 337 result.append(" (").append(relationName).append(", "); 338 } else { 339 preset.nameTemplate.appendText(result, relation); 340 result.append("("); 341 } 319 342 } 320 343 … … 322 345 @Override 323 346 public int compare(Relation r1, Relation r2) { 324 String type1 = getRelationTypeName(r1); 325 String type2 = getRelationTypeName(r2); 326 327 int comp = type1.compareTo(type2); 328 if (comp != 0) 329 return comp; 330 331 String name1 = getRelationName(r1); 332 String name2 = getRelationName(r2); 333 334 if (name1 == null && name2 == null) 335 return (r1.getUniqueId() > r2.getUniqueId())?1:-1; 336 else if (name1 == null) 337 return -1; 338 else if (name2 == null) 339 return 1; 340 else if (!name1.isEmpty() && !name2.isEmpty() && Character.isDigit(name1.charAt(0)) && Character.isDigit(name2.charAt(0))) { 341 //Compare numerically 342 String ln1 = getLeadingNumber(name1); 343 String ln2 = getLeadingNumber(name2); 344 345 comp = Long.valueOf(ln1).compareTo(Long.valueOf(ln2)); 346 if (comp != 0) 347 return comp; 348 349 // put 1 before 0001 350 comp = ln1.compareTo(ln2); 351 if (comp != 0) 352 return comp; 353 354 comp = name1.substring(ln1.length()).compareTo(name2.substring(ln2.length())); 347 //TODO This doesn't work correctly with formatHooks 348 349 TaggingPreset preset1 = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(r1); 350 TaggingPreset preset2 = TaggingPresetNameTemplateList.getInstance().findPresetTemplate(r2); 351 352 if (preset1 != null || preset2 != null) { 353 StringBuilder name1 = new StringBuilder(); 354 formatRelationNameAndType(r1, name1, preset1); 355 StringBuilder name2 = new StringBuilder(); 356 formatRelationNameAndType(r2, name2, preset2); 357 358 int comp = name1.toString().compareTo(name2.toString()); 355 359 if (comp != 0) 356 360 return comp; 357 361 } else { 358 comp = name1.compareToIgnoreCase(name2); 362 363 String type1 = getRelationTypeName(r1); 364 String type2 = getRelationTypeName(r2); 365 366 int comp = type1.compareTo(type2); 359 367 if (comp != 0) 360 368 return comp; 361 } 369 370 String name1 = getRelationName(r1); 371 String name2 = getRelationName(r2); 372 373 if (name1 == null && name2 == null) 374 return (r1.getUniqueId() > r2.getUniqueId())?1:-1; 375 else if (name1 == null) 376 return -1; 377 else if (name2 == null) 378 return 1; 379 else if (!name1.isEmpty() && !name2.isEmpty() && Character.isDigit(name1.charAt(0)) && Character.isDigit(name2.charAt(0))) { 380 //Compare numerically 381 String ln1 = getLeadingNumber(name1); 382 String ln2 = getLeadingNumber(name2); 383 384 comp = Long.valueOf(ln1).compareTo(Long.valueOf(ln2)); 385 if (comp != 0) 386 return comp; 387 388 // put 1 before 0001 389 comp = ln1.compareTo(ln2); 390 if (comp != 0) 391 return comp; 392 393 comp = name1.substring(ln1.length()).compareTo(name2.substring(ln2.length())); 394 if (comp != 0) 395 return comp; 396 } else { 397 comp = name1.compareToIgnoreCase(name2); 398 if (comp != 0) 399 return comp; 400 } 401 } 402 362 403 363 404 if (r1.getMembersCount() != r2.getMembersCount()) 364 405 return (r1.getMembersCount() > r2.getMembersCount())?1:-1; 365 406 366 comp = Boolean.valueOf(r1.hasIncompleteMembers()).compareTo(Boolean.valueOf(r2.hasIncompleteMembers()));407 int comp = Boolean.valueOf(r1.hasIncompleteMembers()).compareTo(Boolean.valueOf(r2.hasIncompleteMembers())); 367 408 if (comp != 0) 368 409 return comp; … … 408 449 name += "["+admin_level+"]"; 409 450 } 410 451 411 452 for (NameFormatterHook hook: formatHooks) { 412 453 String hookResult = hook.checkRelationTypeName(relation, name); 413 if (hookResult != null) {454 if (hookResult != null) 414 455 return hookResult; 415 }416 456 } 417 457 … … 562 602 (way.get("waterway") != null) ? tr("waterway") : 563 603 (way.get("landuse") != null) ? tr("landuse") : "" 564 );604 ); 565 605 } 566 606 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r4283 r4431 378 378 379 379 @Override 380 public List<String> getTemplateKeys() {381 List<String> result;380 public Collection<String> getTemplateKeys() { 381 Collection<String> result; 382 382 if (dataProvider != null) { 383 383 result = dataProvider.getTemplateKeys(); … … 401 401 402 402 @Override 403 public Object getTemplateValue(String name ) {403 public Object getTemplateValue(String name, boolean special) { 404 404 if (MARKER_FORMATTED_OFFSET.equals(name)) 405 405 return formatOffset(); … … 407 407 return offset; 408 408 else if (dataProvider != null) 409 return dataProvider.getTemplateValue(name );409 return dataProvider.getTemplateValue(name, special); 410 410 else 411 411 return null; -
trunk/src/org/openstreetmap/josm/gui/preferences/GPXSettingsPanel.java
r4287 r4431 33 33 private static final int WAYPOINT_LABEL_CUSTOM = 6; 34 34 private static final String[] LABEL_PATTERN_TEMPLATE = new String[] {Marker.LABEL_PATTERN_AUTO, Marker.LABEL_PATTERN_NAME, 35 Marker.LABEL_PATTERN_DESC, "{ *}", "?{ '{name}' | '{desc}' | '{formattedWaypointOffset}' }", ""};35 Marker.LABEL_PATTERN_DESC, "{special:everything}", "?{ '{name}' | '{desc}' | '{formattedWaypointOffset}' }", ""}; 36 36 private static final String[] LABEL_PATTERN_DESC = new String[] {tr("Auto"), /* gpx data field name */ trc("gpx_field", "Name"), 37 37 /* gpx data field name */ trc("gpx_field", "Desc(ription)"), tr("Everything"), tr("Name or offset"), tr("None"), tr("Custom")}; -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r4340 r4431 47 47 48 48 import org.openstreetmap.josm.Main; 49 import org.openstreetmap.josm.actions.search.SearchCompiler; 50 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 49 51 import org.openstreetmap.josm.command.ChangePropertyCommand; 50 52 import org.openstreetmap.josm.command.Command; … … 76 78 import org.openstreetmap.josm.tools.UrlLabel; 77 79 import org.openstreetmap.josm.tools.XmlObjectParser; 80 import org.openstreetmap.josm.tools.template_engine.ParseError; 81 import org.openstreetmap.josm.tools.template_engine.TemplateEntry; 82 import org.openstreetmap.josm.tools.template_engine.TemplateParser; 78 83 import org.xml.sax.SAXException; 79 84 … … 121 126 protected void initAutoCompletionField(AutoCompletingTextField field, String key) { 122 127 OsmDataLayer layer = Main.main.getEditLayer(); 123 if (layer == null) {128 if (layer == null) 124 129 return; 125 }126 130 AutoCompletionList list = new AutoCompletionList(); 127 131 Main.main.getEditLayer().data.getAutoCompletionManager().populateWithTagValues(list, key); … … 303 307 String v = (value instanceof JComboBox) 304 308 ? ((JComboBox) value).getEditor().getItem().toString() 305 : ((JTextField) value).getText(); 306 v = v.trim(); 307 308 if (!"false".equals(use_last_as_default)) { 309 lastValue.put(key, v); 310 } 311 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) { 312 return; 313 } 314 315 if (delete_if_empty && v.length() == 0) { 316 v = null; 317 } 318 changedTags.add(new Tag(key, v)); 309 : ((JTextField) value).getText(); 310 v = v.trim(); 311 312 if (!"false".equals(use_last_as_default)) { 313 lastValue.put(key, v); 314 } 315 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) 316 return; 317 318 if (delete_if_empty && v.length() == 0) { 319 v = null; 320 } 321 changedTags.add(new Tag(key, v)); 319 322 } 320 323 … … 491 494 e.display_value = (locale_display_values == null) 492 495 ? (values_context == null ? tr(fixPresetString(display_array[i])) 493 : trc(values_context, fixPresetString(display_array[i]))) : display_array[i];494 if (short_descriptions_array != null) {495 e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i]))496 : fixPresetString(short_descriptions_array[i]);497 }498 lhm.put(value_array[i], e);496 : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 497 if (short_descriptions_array != null) { 498 e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) 499 : fixPresetString(short_descriptions_array[i]); 500 } 501 lhm.put(value_array[i], e); 499 502 } 500 503 … … 544 547 // no change if same as before 545 548 if (originalValue == null) { 546 if (value.length() == 0) {549 if (value.length() == 0) 547 550 return; 548 } 549 } else if (value.equals(originalValue.toString())) { 551 } else if (value.equals(originalValue.toString())) 550 552 return; 551 }552 553 553 554 if (delete_if_empty && value.length() == 0) { … … 676 677 @Override 677 678 protected String getDisplayIfNull(String display) { 678 if (combo.isEditable()) {679 if (combo.isEditable()) 679 680 return combo.getEditor().getItem().toString(); 680 } else {681 else 681 682 return display; 682 }683 683 684 684 } … … 1008 1008 public EnumSet<PresetType> types; 1009 1009 public List<Item> data = new LinkedList<Item>(); 1010 public TemplateEntry nameTemplate; 1011 public Match nameTemplateFilter; 1010 1012 private static HashMap<String,String> lastValue = new HashMap<String,String>(); 1011 1013 … … 1088 1090 this.types = getType(types); 1089 1091 } 1092 1093 public void setName_template(String pattern) throws SAXException { 1094 try { 1095 this.nameTemplate = new TemplateParser(pattern).parse(); 1096 } catch (ParseError e) { 1097 System.err.println("Error while parsing " + pattern + ": " + e.getMessage()); 1098 throw new SAXException(e); 1099 } 1100 } 1101 1102 public void setName_template_filter(String filter) throws SAXException { 1103 try { 1104 this.nameTemplateFilter = SearchCompiler.compile(filter, false, false); 1105 } catch (org.openstreetmap.josm.actions.search.SearchCompiler.ParseError e) { 1106 System.err.println("Error while parsing" + filter + ": " + e.getMessage()); 1107 throw new SAXException(e); 1108 } 1109 } 1110 1090 1111 1091 1112 public static List<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException { … … 1199 1220 tr("Error"), 1200 1221 JOptionPane.ERROR_MESSAGE 1201 );1222 ); 1202 1223 } catch (SAXException e) { 1203 1224 System.err.println(e.getMessage()); … … 1209 1230 tr("Error"), 1210 1231 JOptionPane.ERROR_MESSAGE 1211 );1232 ); 1212 1233 } 1213 1234 zipIcons = null; -
trunk/src/org/openstreetmap/josm/tools/template_engine/TemplateEngineDataProvider.java
r4282 r4431 2 2 package org.openstreetmap.josm.tools.template_engine; 3 3 4 import java.util. List;4 import java.util.Collection; 5 5 6 6 import org.openstreetmap.josm.actions.search.SearchCompiler.Match; 7 7 8 8 public interface TemplateEngineDataProvider { 9 List<String> getTemplateKeys();10 Object getTemplateValue(String name );9 Collection<String> getTemplateKeys(); 10 Object getTemplateValue(String name, boolean special); 11 11 boolean evaluateCondition(Match condition); 12 12 } -
trunk/src/org/openstreetmap/josm/tools/template_engine/Variable.java
r4282 r4431 2 2 package org.openstreetmap.josm.tools.template_engine; 3 3 4 import java.util. List;4 import java.util.Collection; 5 5 6 6 7 7 public class Variable implements TemplateEntry { 8 8 9 private static final String SPECIAL_VARIABLE_PREFIX = "special:"; 10 private static final String SPECIAL_VALUE_EVERYTHING = "everything"; 11 12 9 13 private final String variableName; 14 private final boolean special; 10 15 11 16 public Variable(String variableName) { 12 this.variableName = variableName; 17 if (variableName.toLowerCase().startsWith(SPECIAL_VARIABLE_PREFIX)) { 18 this.variableName = variableName.substring(SPECIAL_VARIABLE_PREFIX.length()); 19 // special:special:key means that real key named special:key is needed, not special variable 20 this.special = !this.variableName.toLowerCase().startsWith(SPECIAL_VARIABLE_PREFIX); 21 } else { 22 this.variableName = variableName; 23 this.special = false; 24 } 13 25 } 14 26 15 27 @Override 16 28 public void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider) { 17 if ( "*".equals(variableName)) {18 List<String> keys = dataProvider.getTemplateKeys();29 if (special && SPECIAL_VALUE_EVERYTHING.equals(variableName)) { 30 Collection<String> keys = dataProvider.getTemplateKeys(); 19 31 boolean first = true; 20 32 for (String key: keys) { … … 24 36 first = false; 25 37 } 26 result.append(key).append("=").append(dataProvider.getTemplateValue(key ));38 result.append(key).append("=").append(dataProvider.getTemplateValue(key, false)); 27 39 } 28 40 } else { 29 Object value = dataProvider.getTemplateValue(variableName );41 Object value = dataProvider.getTemplateValue(variableName, special); 30 42 if (value != null) { 31 43 result.append(value); … … 36 48 @Override 37 49 public boolean isValid(TemplateEngineDataProvider dataProvider) { 38 if ( "*".equals(variableName))50 if (special && SPECIAL_VALUE_EVERYTHING.equals(variableName)) 39 51 return true; 40 52 else 41 return dataProvider.getTemplateValue(variableName ) != null;53 return dataProvider.getTemplateValue(variableName, special) != null; 42 54 } 43 55 … … 47 59 } 48 60 61 public boolean isSpecial() { 62 return special; 63 } 64 49 65 }
Note:
See TracChangeset
for help on using the changeset viewer.