Changeset 17977 in josm
- Timestamp:
- 2021-07-10T17:48:58+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/TagInfoExtract.java
r17744 r17977 1 1 // License: GPL. For details, see LICENSE file. 2 3 2 import java.awt.Graphics2D; 4 3 import java.awt.image.BufferedImage; … … 249 248 } 250 249 } 251 252 250 } 253 251 … … 266 264 List<TagInfoTag> convertPresets(Iterable<TaggingPreset> presets, String descriptionPrefix, boolean addImages) { 267 265 final List<TagInfoTag> tags = new ArrayList<>(); 266 final Map<Tag, TagInfoTag> requiredTags = new LinkedHashMap<>(); 268 267 final Map<Tag, TagInfoTag> optionalTags = new LinkedHashMap<>(); 269 268 for (TaggingPreset preset : presets) { … … 278 277 Set<TagInfoTag.Type> types = TagInfoTag.Type.forPresetTypes(preset.types); 279 278 if (item.isKeyRequired()) { 280 tags.add(new TagInfoTag(descriptionPrefix + preset.getName(), item.key, value, types, 281 addImages && preset.iconName != null ? options.findImageUrl(preset.iconName) : null)); 279 fillTagsMap(requiredTags, item, value, preset.getName(), types, 280 descriptionPrefix + TagInfoTag.REQUIRED_FOR_COUNT + ": ", 281 addImages && preset.iconName != null ? options.findImageUrl(preset.iconName) : null); 282 282 } else if (Presets.class.equals(getClass())) { // not for ExternalPresets 283 optionalTags.compute(new Tag(item.key, value), (osmTag, tagInfoTag) -> { 284 if (tagInfoTag == null) { 285 String description = descriptionPrefix + TagInfoTag.OPTIONAL_FOR_COUNT + ": " + preset.getName(); 286 return new TagInfoTag(description, item.key, value, types, null); 287 } else { 288 tagInfoTag.descriptions.add(preset.getName()); 289 tagInfoTag.objectTypes.addAll(types); 290 return tagInfoTag; 291 } 292 }); 283 fillTagsMap(optionalTags, item, value, preset.getName(), types, 284 descriptionPrefix + TagInfoTag.OPTIONAL_FOR_COUNT + ": ", null); 293 285 } 294 286 } 295 287 }); 296 288 } 289 tags.addAll(requiredTags.values()); 297 290 tags.addAll(optionalTags.values()); 298 291 return tags; 292 } 293 294 private void fillTagsMap(Map<Tag, TagInfoTag> optionalTags, KeyedItem item, String value, String presetName, Set<TagInfoTag.Type> types, String descriptionPrefix, String iconUrl) { 295 optionalTags.compute(new Tag(item.key, value), (osmTag, tagInfoTag) -> { 296 if (tagInfoTag == null) { 297 return new TagInfoTag(descriptionPrefix + presetName, item.key, value, types, iconUrl); 298 } else { 299 tagInfoTag.descriptions.add(presetName); 300 tagInfoTag.objectTypes.addAll(types); 301 return tagInfoTag; 302 } 303 }); 299 304 } 300 305 … … 303 308 return values.isEmpty() || values.size() > 50 ? Collections.singleton(null) : values; 304 309 } 305 306 310 } 307 311 … … 328 332 Logging.warn(ex); 329 333 } 330 331 334 } 332 335 writeJson("JOSM user presets", "Tags supported by the user contributed presets in the OSM editor JOSM", tags); … … 491 494 return Optional.empty(); 492 495 } 493 494 496 } 495 497 … … 510 512 LineElement les = LineElement.createLine(env); 511 513 if (les != null) { 512 if (!generateImage) return Optional.of(""); 513 return Optional.of(createImage(les, "way", nc)); 514 return Optional.of(generateImage ? createImage(les, "way", nc) : ""); 514 515 } 515 516 return Optional.empty(); 516 517 } 517 518 518 } 519 519 … … 551 551 */ 552 552 private static class TagInfoTag { 553 static final String REQUIRED_FOR_COUNT = "Required for {count}"; 553 554 static final String OPTIONAL_FOR_COUNT = "Optional for {count}"; 554 555 final Collection<String> descriptions = new ArrayList<>(); … … 573 574 final int size = descriptions.size(); 574 575 object.add("description", String.join(", ", Utils.limit(descriptions, 8, "...")) 576 .replace(REQUIRED_FOR_COUNT, size > 3 ? "Required for " + size : "Required for") 575 577 .replace(OPTIONAL_FOR_COUNT, size > 3 ? "Optional for " + size : "Optional for")); 576 578 } … … 605 607 606 608 static Set<TagInfoTag.Type> forPresetTypes(Set<TaggingPresetType> types) { 607 if (types == null) { 608 return Collections.emptySet(); 609 } 610 return types.stream() 609 return types == null ? Collections.emptySet() : types.stream() 611 610 .map(Type::forPresetType) 612 611 .collect(Collectors.toCollection(() -> EnumSet.noneOf(Type.class)));
Note:
See TracChangeset
for help on using the changeset viewer.