- Timestamp:
- 2012-04-16T22:53:07+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
r4968 r5196 46 46 47 47 @Override 48 public void initialize() throws Exception{48 public void initialize() { 49 49 initializePresets(); 50 50 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r4968 r5196 155 155 156 156 @Override 157 public void initialize() throws Exception {157 public void initialize() throws IOException { 158 158 initializeData(); 159 159 initializePresets(); … … 286 286 * Reads the presets data. 287 287 * 288 * @throws Exception289 288 */ 290 public static void initializePresets() throws Exception{289 public static void initializePresets() { 291 290 292 291 if (!Main.pref.getBoolean(PREF_CHECK_VALUES, true)) … … 308 307 } 309 308 for (TaggingPreset p : presets) { 310 for(TaggingPreset.Item i : p.data) { 311 if (i instanceof TaggingPreset.Combo) { 312 TaggingPreset.Combo combo = (TaggingPreset.Combo) i; 313 if (combo.values != null) { 314 for(String value : combo.values.split(",")) { 315 presetsValueData.put(combo.key, value); 316 } 317 } 318 } else if (i instanceof TaggingPreset.Key) { 319 TaggingPreset.Key k = (TaggingPreset.Key) i; 320 presetsValueData.put(k.key, k.value); 321 } else if (i instanceof TaggingPreset.Text) { 322 TaggingPreset.Text k = (TaggingPreset.Text) i; 323 presetsValueData.putVoid(k.key); 324 } else if (i instanceof TaggingPreset.Check) { 325 TaggingPreset.Check k = (TaggingPreset.Check) i; 326 presetsValueData.put(k.key, "yes"); 327 presetsValueData.put(k.key, "no"); 309 for (TaggingPreset.Item i : p.data) { 310 if (i instanceof TaggingPreset.KeyedItem) { 311 TaggingPreset.KeyedItem ky = (TaggingPreset.KeyedItem) i; 312 presetsValueData.putAll(ky.key, ky.getValues()); 328 313 } 329 314 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r5181 r5196 23 23 import java.util.Arrays; 24 24 import java.util.Collection; 25 import java.util.Collections; 25 26 import java.util.EnumSet; 26 27 import java.util.HashMap; … … 210 211 * @return {@code true} if matches (positive), {@code null} if neutral, {@code false} if mismatches (negative). 211 212 */ 212 abstract Boolean matches(Map<String, String> tags); 213 Boolean matches(Map<String, String> tags) { 214 return null; 215 } 216 } 217 218 public static abstract class KeyedItem extends Item { 219 220 public String key; 221 public String text; 222 public String text_context; 223 public String match = getDefaultMatch().getValue(); 224 225 public abstract MatchType getDefaultMatch(); 226 public abstract Collection<String> getValues(); 227 228 @Override 229 Boolean matches(Map<String, String> tags) { 230 switch (MatchType.ofString(match)) { 231 case NONE: 232 return null; 233 case KEY: 234 return tags.containsKey(key) ? true : null; 235 case KEY_REQUIRED: 236 return tags.containsKey(key); 237 case KEY_VALUE: 238 return tags.containsKey(key) && (getValues().contains(tags.get(key))); 239 default: 240 throw new IllegalStateException(); 241 } 242 } 243 213 244 } 214 245 … … 325 356 } 326 357 327 public static class Text extends Item { 328 329 public String key; 330 public String text; 358 public static class Text extends KeyedItem { 359 331 360 public String locale_text; 332 public String text_context;333 361 public String default_; 334 362 public String originalValue; 335 363 public String use_last_as_default = "false"; 336 public String match = MatchType.NONE.getValue();337 364 338 365 private JComponent value; … … 410 437 411 438 @Override 412 Boolean matches(Map<String, String> tags) { 413 switch (MatchType.ofString(match)) { 414 case NONE: 415 return null; 416 case KEY: 417 return tags.containsKey(key) ? true : null; 418 case KEY_REQUIRED: 419 return tags.containsKey(key); 420 default: 421 throw new IllegalArgumentException("key_value matching not supported for <text>: " + text); 422 } 423 } 424 } 425 426 public static class Check extends Item { 427 428 public String key; 429 public String text; 430 public String text_context; 439 public MatchType getDefaultMatch() { 440 return MatchType.NONE; 441 } 442 443 @Override 444 public Collection<String> getValues() { 445 if (default_ == null || default_.isEmpty()) { 446 return Collections.emptyList(); 447 } 448 return Collections.singleton(default_); 449 } 450 } 451 452 public static class Check extends KeyedItem { 453 431 454 public String locale_text; 432 455 public String value_on = OsmUtils.trueval; 433 456 public String value_off = OsmUtils.falseval; 434 457 public boolean default_ = false; // only used for tagless objects 435 public String match = MatchType.NONE.getValue();436 458 437 459 private QuadStateCheckBox check; … … 509 531 510 532 @Override 511 Boolean matches(Map<String, String> tags) { 512 switch (MatchType.ofString(match)) { 513 case NONE: 514 return null; 515 case KEY: 516 return tags.containsKey(key) ? true : null; 517 case KEY_REQUIRED: 518 return tags.containsKey(key); 519 case KEY_VALUE: 520 return value_off.equals(tags.get(key)) || value_on.equals(tags.get(key)); 521 default: 522 throw new IllegalStateException(); 523 } 524 } 525 } 526 527 public static abstract class ComboMultiSelect extends Item { 528 529 public String key; 530 public String text; 531 public String text_context; 533 public MatchType getDefaultMatch() { 534 return MatchType.NONE; 535 } 536 537 @Override 538 public Collection<String> getValues() { 539 return Arrays.asList(value_on, value_off); 540 } 541 } 542 543 public static abstract class ComboMultiSelect extends KeyedItem { 544 532 545 public String locale_text; 533 546 public String values; … … 540 553 public String delimiter = ";"; 541 554 public String use_last_as_default = "false"; 542 public String match = MatchType.NONE.getValue();543 555 544 556 protected JComponent component; 545 557 protected Map<String, PresetListEntry> lhm = new LinkedHashMap<String, PresetListEntry>(); 558 private boolean initialized = false; 546 559 protected Usage usage; 547 560 protected Object originalValue; 548 561 549 562 protected abstract Object getSelectedItem(); 550 protected abstract void addToPanelAnchor(JPanel p, String def , String[] display_array);563 protected abstract void addToPanelAnchor(JPanel p, String def); 551 564 552 565 protected char getDelChar() { … … 555 568 556 569 @Override 570 public Collection<String> getValues() { 571 initListEntries(); 572 return lhm.keySet(); 573 } 574 575 public Collection<String> getDisplayValues() { 576 initListEntries(); 577 return Utils.transform(lhm.values(), new Utils.Function<PresetListEntry, String>() { 578 579 @Override 580 public String apply(PresetListEntry x) { 581 return x.getDisplayValue(true); 582 } 583 }); 584 } 585 586 @Override 557 587 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 588 589 initListEntries(); 558 590 559 591 // find out if our key is already used in the selection. 560 592 usage = determineTextUsage(sel, key); 561 562 String[] display_array; 563 if (lhm.isEmpty()) { 564 display_array = initListEntriesFromAttributes(); 593 if (!usage.hasUniqueValue() && !usage.unused()) { 594 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 595 } 596 597 p.add(new JLabel(tr("{0}:", locale_text)), GBC.std().insets(0, 0, 10, 0)); 598 addToPanelAnchor(p, default_); 599 600 return true; 601 602 } 603 604 private void initListEntries() { 605 if (initialized) { 606 lhm.remove(DIFFERENT); // possibly added in #addToPanel 607 return; 608 } else if (lhm.isEmpty()) { 609 initListEntriesFromAttributes(); 565 610 } else { 566 611 if (values != null) { … … 579 624 key, text, "short_descriptions", "list_entry")); 580 625 } 581 display_array = new String[lhm.values().size()];582 int i = 0;583 626 for (PresetListEntry e : lhm.values()) { 584 627 if (e.value_context == null) { 585 628 e.value_context = values_context; 586 629 } 587 display_array[i++] = e.getDisplayValue(true); 588 } 589 } 590 630 } 631 } 591 632 if (locale_text == null) { 592 633 locale_text = trc(text_context, fixPresetString(text)); 593 634 } 594 p.add(new JLabel(tr("{0}:", locale_text)), GBC.std().insets(0, 0, 10, 0)); 595 596 addToPanelAnchor(p, default_, display_array); 597 598 return true; 599 635 initialized = true; 600 636 } 601 637 … … 621 657 } 622 658 623 if (!usage.hasUniqueValue() && !usage.unused()) {624 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT));625 }626 659 for (int i = 0; i < value_array.length; i++) { 627 660 final PresetListEntry e = new PresetListEntry(value_array[i]); … … 637 670 display_array[i] = e.getDisplayValue(true); 638 671 } 639 640 // as addToPanel may be called several times, set String to null to avoid "Ignoring * attribute as * elements are given"641 values = null;642 display_values = null;643 locale_display_values = null;644 short_descriptions = null;645 locale_short_descriptions = null;646 672 647 673 return display_array; … … 744 770 745 771 @Override 746 Boolean matches(Map<String, String> tags) { 747 switch (MatchType.ofString(match)) { 748 case NONE: 749 return null; 750 case KEY: 751 return tags.containsKey(key) ? true : null; 752 case KEY_REQUIRED: 753 return tags.containsKey(key); 754 case KEY_VALUE: 755 return tags.containsKey(key) 756 && Arrays.asList(splitEscaped(getDelChar(), values)).contains(tags.get(key)); 757 default: 758 throw new IllegalStateException(); 759 } 772 public MatchType getDefaultMatch() { 773 return MatchType.NONE; 760 774 } 761 775 } … … 771 785 772 786 @Override 773 protected void addToPanelAnchor(JPanel p, String def , String[] display_array) {787 protected void addToPanelAnchor(JPanel p, String def) { 774 788 if (!usage.unused()) { 775 789 for (String s : usage.values) { … … 791 805 AutoCompletingTextField tf = new AutoCompletingTextField(); 792 806 initAutoCompletionField(tf, key); 793 tf.getAutoCompletionList().add( Arrays.asList(display_array), AutoCompletionItemPritority.IS_IN_STANDARD);807 tf.getAutoCompletionList().add(getDisplayValues(), AutoCompletionItemPritority.IS_IN_STANDARD); 794 808 combo.setEditor(tf); 795 809 … … 861 875 } 862 876 setSelectedIndices(Arrays.copyOf(intParts, j)); 863 // check if we have ac utally managed to represent the full877 // check if we have actually managed to represent the full 864 878 // value with our presets. if not, cop out; we will not offer 865 879 // a selection list that threatens to ruin the value. … … 887 901 888 902 @Override 889 protected void addToPanelAnchor(JPanel p, String def , String[] display_array) {903 protected void addToPanelAnchor(JPanel p, String def) { 890 904 list = new ConcatenatingJList(delimiter, lhm.values().toArray()); 891 905 component = list; … … 979 993 public void addCommands(List<Tag> changedTags) { 980 994 } 981 982 @Override983 Boolean matches(Map<String, String> tags) {984 return null;985 }986 995 } 987 996 … … 1017 1026 @Override 1018 1027 public void addCommands(List<Tag> changedTags) { 1019 }1020 1021 @Override1022 Boolean matches(Map<String, String> tags) {1023 return null;1024 1028 } 1025 1029 } … … 1117 1121 public void addCommands(List<Tag> changedTags) { 1118 1122 } 1119 1120 @Override1121 Boolean matches(Map<String, String> tags) {1122 return null;1123 }1124 1123 } 1125 1124 … … 1138 1137 public void addCommands(List<Tag> changedTags) { 1139 1138 } 1140 1141 @Override1142 Boolean matches(Map<String, String> tags) {1143 return null;1144 }1145 1139 } 1146 1140 … … 1156 1150 public void addCommands(List<Tag> changedTags) { 1157 1151 } 1158 1159 @Override 1160 Boolean matches(Map<String, String> tags) { 1161 return null; 1162 } 1163 } 1164 1165 public static class Key extends Item { 1166 1167 public String key; 1152 } 1153 1154 public static class Key extends KeyedItem { 1155 1168 1156 public String value; 1169 public String match = MatchType.KEY_VALUE.getValue();1170 1157 1171 1158 @Override … … 1180 1167 1181 1168 @Override 1182 Boolean matches(Map<String, String> tags) { 1183 switch (MatchType.ofString(match)) { 1184 case NONE: 1185 return null; 1186 case KEY: 1187 return tags.containsKey(key) ? true : null; 1188 case KEY_REQUIRED: 1189 return tags.containsKey(key); 1190 case KEY_VALUE: 1191 return value.equals(tags.get(key)); 1192 default: 1193 throw new IllegalStateException(); 1194 } 1169 public MatchType getDefaultMatch() { 1170 return MatchType.KEY_VALUE; 1171 } 1172 1173 @Override 1174 public Collection<String> getValues() { 1175 return Collections.singleton(value); 1195 1176 } 1196 1177 } … … 1615 1596 /** 1616 1597 * Removes all unsuitable OsmPrimitives from the given list 1617 * @param participants List of possib ile OsmPrimitives to tag1598 * @param participants List of possible OsmPrimitives to tag 1618 1599 * @return Cleaned list with suitable OsmPrimitives only 1619 1600 */ -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSearchDialog.java
r5170 r5196 45 45 import org.openstreetmap.josm.gui.ExtendedDialog; 46 46 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 47 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Check;48 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Combo;49 47 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Item; 50 48 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Key; … … 52 50 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Role; 53 51 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Roles; 54 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Text;55 52 56 53 public class TaggingPresetSearchDialog extends ExtendedDialog implements SelectionChangedListener { … … 122 119 } 123 120 for (Item item: preset.data) { 124 if (item instanceof Check) { 125 tags.add(((Check)item).key.toLowerCase()); 126 } else if (item instanceof Combo) { 121 if (item instanceof TaggingPreset.KeyedItem) { 122 tags.add(((TaggingPreset.KeyedItem) item).key); 127 123 // Should combo values also be added? 128 tags.add(((Combo)item).key); 129 } else if (item instanceof Key) { 130 tags.add(((Key) item).key); 131 String value = ((Key) item).value; 132 if (value != null) { 133 tags.add(value); 134 } 135 } else if (item instanceof Text) { 136 tags.add(((Text) item).key); 124 if (item instanceof Key && ((Key) item).value != null) { 125 tags.add(((Key) item).value); 126 } 137 127 } else if (item instanceof Roles) { 138 for (Role role : ((Roles) item).roles) {128 for (Role role : ((Roles) item).roles) { 139 129 tags.add(role.key); 140 130 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r4869 r5196 149 149 for (final TaggingPreset p : presets) { 150 150 for (TaggingPreset.Item item : p.data) { 151 if (item instanceof TaggingPreset. Check) {152 TaggingPreset. Check ch = (TaggingPreset.Check) item;153 if ( ch.key == null) {151 if (item instanceof TaggingPreset.KeyedItem) { 152 TaggingPreset.KeyedItem ki = (TaggingPreset.KeyedItem) item; 153 if (ki.key == null) { 154 154 continue; 155 155 } 156 presetTagCache.put(ch.key, OsmUtils.falseval); 157 presetTagCache.put(ch.key, OsmUtils.trueval); 158 } else if (item instanceof TaggingPreset.Combo) { 159 TaggingPreset.Combo co = (TaggingPreset.Combo) item; 160 if (co.key == null || co.values == null) { 161 continue; 162 } 163 for (String value : co.values.split(",")) { 164 presetTagCache.put(co.key, value); 165 } 166 } else if (item instanceof TaggingPreset.Key) { 167 TaggingPreset.Key ky = (TaggingPreset.Key) item; 168 if (ky.key == null || ky.value == null) { 169 continue; 170 } 171 presetTagCache.put(ky.key, ky.value); 172 } else if (item instanceof TaggingPreset.Text) { 173 TaggingPreset.Text tt = (TaggingPreset.Text) item; 174 if (tt.key == null) { 175 continue; 176 } 177 presetTagCache.putVoid(tt.key); 178 if (tt.default_ != null && !tt.default_.equals("")) { 179 presetTagCache.put(tt.key, tt.default_); 180 } 156 presetTagCache.putAll(ki.key, ki.getValues()); 181 157 } else if (item instanceof TaggingPreset.Roles) { 182 158 TaggingPreset.Roles r = (TaggingPreset.Roles) item; … … 266 242 * 267 243 * @param list the list to populate 268 * @param key the tag keys244 * @param keys the tag keys 269 245 */ 270 246 public void populateWithTagValues(AutoCompletionList list, List<String> keys) {
Note:
See TracChangeset
for help on using the changeset viewer.