Ticket #5933: 5933_v3.patch
File 5933_v3.patch, 28.9 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java index 3c63305..fe03b79 100644
a b import java.awt.event.MouseListener; 10 10 import java.awt.font.TextAttribute; 11 11 import java.util.Collection; 12 12 import java.util.Collections; 13 import java.util.Hashtable;14 13 import java.util.List; 15 14 import java.util.Map; 16 15 … … import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 22 import org.openstreetmap.josm.data.osm.Tag; 24 23 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 25 24 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 26 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Check;27 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Combo;28 25 import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType; 29 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Text;30 26 import org.openstreetmap.josm.tools.GBC; 31 27 32 28 public class PresetListPanel extends JPanel { … … public class PresetListPanel extends JPanel { 81 77 public void mouseReleased(MouseEvent arg0) {} 82 78 } 83 79 84 public void updatePresets( int nodes, int ways, int relations, int closedways, Map<String, Map<String, Integer>> valueCount, PresetHandler presetHandler){80 public void updatePresets(final Collection<PresetType> types, final Map<String, String> tags, PresetHandler presetHandler) { 85 81 86 82 removeAll(); 87 int total = nodes+ways+relations+closedways; 88 if(total == 0) { 83 if (types.isEmpty()) { 89 84 setVisible(false); 90 85 return; 91 86 } 92 87 93 for(TaggingPreset t : TaggingPresetPreference.taggingPresets) { 94 if( 95 ( t.types == null 96 || (relations > 0 && t.types.contains(PresetType.RELATION)) 97 || (nodes > 0 && t.types.contains(PresetType.NODE)) 98 || (ways+closedways > 0 && t.types.contains(PresetType.WAY)) 99 || (closedways > 0 && t.types.contains(PresetType.CLOSEDWAY)) 100 ) 101 && t.isShowable()) 102 { 103 int found = 0; 104 for(TaggingPreset.Item i : t.data) { 105 if(i instanceof TaggingPreset.Key) { 106 String val = ((TaggingPreset.Key)i).value; 107 String key = ((TaggingPreset.Key)i).key; 108 // we subtract 100 if not found and add 1 if found 109 found -= 100; 110 if(key == null || !valueCount.containsKey(key)) { 111 continue; 112 } 113 114 Map<String, Integer> v = valueCount.get(key); 115 if(v.size() == 1 && val != null && v.containsKey(val) && v.get(val) == total) { 116 found += 101; 117 } 118 } else { 119 String key = null; 120 if ((i instanceof Text) && ((Text)i).required) { 121 key = ((Text)i).key; 122 } else if ((i instanceof Combo) && ((Combo)i).required) { 123 key = ((Combo)i).key; 124 } else if ((i instanceof Check) && ((Check)i).required) { 125 key = ((Check)i).key; 126 } 127 if (key != null) { 128 if (valueCount.get(key) != null) { 129 found += 1; 130 } else { 131 found -= 100; 132 } 133 } 134 } 135 } 136 137 if(found <= 0) { 138 continue; 139 } 140 141 JLabel lbl = new JLabel(t.getName() + " …"); 142 lbl.setIcon((Icon) t.getValue(Action.SMALL_ICON)); 143 lbl.addMouseListener(new PresetLabelML(lbl, t, presetHandler)); 144 add(lbl, GBC.eol().fill(GBC.HORIZONTAL)); 88 for (TaggingPreset t : TaggingPresetPreference.taggingPresets) { 89 if (!t.matches(types, tags)) { 90 continue; 145 91 } 92 93 JLabel lbl = new JLabel(t.getName() + " …"); 94 lbl.setIcon((Icon) t.getValue(Action.SMALL_ICON)); 95 lbl.addMouseListener(new PresetLabelML(lbl, t, presetHandler)); 96 add(lbl, GBC.eol().fill(GBC.HORIZONTAL)); 146 97 } 147 98 148 if (getComponentCount() > 0) {99 if (getComponentCount() > 0) { 149 100 setVisible(true); 150 101 // This ensures the presets are exactly as high as needed. 151 102 int height = getComponentCount() * getComponent(0).getHeight(); … … public class PresetListPanel extends JPanel { 156 107 setVisible(false); 157 108 } 158 109 } 159 160 110 } -
src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java index 05a700e..5a9bca9 100644
a b import java.util.Arrays; 30 30 import java.util.Collection; 31 31 import java.util.Collections; 32 32 import java.util.Comparator; 33 import java.util.EnumSet; 33 34 import java.util.HashMap; 34 35 import java.util.HashSet; 35 36 import java.util.Iterator; … … import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask; 103 104 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 104 105 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 105 106 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 107 import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType; 106 108 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 107 109 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 108 110 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; … … public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi 260 262 Component c = super.getListCellRendererComponent(list, value, 261 263 index, isSelected, cellHasFocus); 262 264 if (c instanceof JLabel) { 263 String str = null; 264 str=((AutoCompletionListItem) value).getValue(); 265 if (valueCount.containsKey(objKey)){ 266 Map<String, Integer> m=valueCount.get(objKey); 265 String str = ((AutoCompletionListItem) value).getValue(); 266 if (valueCount.containsKey(objKey)) { 267 Map<String, Integer> m = valueCount.get(objKey); 267 268 if (m.containsKey(str)) { 268 str +="("+m.get(str)+")";269 c.setFont(c.getFont().deriveFont(Font.ITALIC +Font.BOLD));269 str = tr("{0} ({1})", str, m.get(str)); 270 c.setFont(c.getFont().deriveFont(Font.ITALIC + Font.BOLD)); 270 271 } 271 272 } 272 ((JLabel) c).setText(str);273 ((JLabel) c).setText(str); 273 274 } 274 275 return c; 275 276 } … … public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi 946 947 947 948 // re-load property data 948 949 propertyData.setRowCount(0); 949 int nodes = 0;950 int ways = 0;951 int relations = 0;952 int closedways = 0;953 950 954 Map<String, Integer> keyCount = new HashMap<String, Integer>(); 951 final Map<String, Integer> keyCount = new HashMap<String, Integer>(); 952 final Map<String, String> tags = new HashMap<String, String>(); 955 953 valueCount.clear(); 954 EnumSet<PresetType> types = EnumSet.noneOf(TaggingPreset.PresetType.class); 956 955 for (OsmPrimitive osm : newSelection) { 957 if(osm instanceof Node) { 958 ++nodes; 959 } else if(osm instanceof Relation) { 960 ++relations; 961 } else if(((Way)osm).isClosed()) { 962 ++closedways; 963 } else { 964 ++ways; 965 } 966 for (String key: osm.keySet()) { 956 types.add(PresetType.forPrimitive(osm)); 957 for (String key : osm.keySet()) { 967 958 String value = osm.get(key); 968 959 keyCount.put(key, keyCount.containsKey(key) ? keyCount.get(key) + 1 : 1); 969 960 if (valueCount.containsKey(key)) { 970 961 Map<String, Integer> v = valueCount.get(key); 971 v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1);962 v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1); 972 963 } else { 973 TreeMap<String, Integer> v = new TreeMap<String, Integer>();964 TreeMap<String, Integer> v = new TreeMap<String, Integer>(); 974 965 v.put(value, 1); 975 966 valueCount.put(key, v); 976 967 } 977 968 } 978 969 } 979 970 for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) { 980 int count =0;981 for (Entry<String, Integer> e1 : e.getValue().entrySet()) {982 count +=e1.getValue();971 int count = 0; 972 for (Entry<String, Integer> e1 : e.getValue().entrySet()) { 973 count += e1.getValue(); 983 974 } 984 975 if (count < newSelection.size()) { 985 e.getValue().put("", newSelection.size() -count);976 e.getValue().put("", newSelection.size() - count); 986 977 } 987 978 propertyData.addRow(new Object[]{e.getKey(), e.getValue()}); 979 tags.put(e.getKey(), e.getValue().size() == 1 980 ? e.getValue().keySet().iterator().next() : tr("<different>")); 988 981 } 989 982 990 983 membershipData.setRowCount(0); … … public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi 1025 1018 membershipData.addRow(new Object[]{r, roles.get(r)}); 1026 1019 } 1027 1020 1028 presets.updatePresets( nodes, ways, relations, closedways, valueCount, presetHandler);1021 presets.updatePresets(types, tags, presetHandler); 1029 1022 1030 1023 membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 1031 1024 membershipTable.setVisible(membershipData.getRowCount() > 0); -
src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
diff --git a/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java b/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java index 55fc577..65fbc8e 100644
a b import java.awt.BorderLayout; 5 5 import java.awt.GridBagConstraints; 6 6 import java.awt.GridBagLayout; 7 7 import java.awt.Insets; 8 import java.util.HashMap; 9 import java.util.Map; 10 import java.util.Map.Entry; 8 import java.util.EnumSet; 11 9 12 10 import javax.swing.BoxLayout; 13 11 import javax.swing.JButton; … … public class TagEditorPanel extends JPanel { 180 178 } 181 179 182 180 private void updatePresets() { 183 Map<String, Map<String, Integer>> valuesCount = new HashMap<String, Map<String,Integer>>(); 184 for (Entry<String, String> entry: model.getTags().entrySet()) { 185 Map<String, Integer> values = new HashMap<String, Integer>(); 186 values.put(entry.getValue(), 1); 187 valuesCount.put(entry.getKey(), values); 188 } 189 presetListPanel.updatePresets(0, 0, 1, 0, valuesCount, presetHandler); 181 presetListPanel.updatePresets( 182 EnumSet.of(TaggingPreset.PresetType.RELATION), 183 model.getTags(), presetHandler); 190 184 validate(); 191 185 } 192 186 } -
src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
diff --git a/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java index 5d23549..bd40aac 100644
a b public class TaggingPreset extends AbstractAction implements MapView.LayerChange 107 107 public String getName() { 108 108 return name().toLowerCase(); 109 109 } 110 111 public static PresetType forPrimitive(OsmPrimitive p) { 112 return forPrimitiveType(p.getDisplayType()); 113 } 114 115 public static PresetType forPrimitiveType(org.openstreetmap.josm.data.osm.OsmPrimitiveType type) { 116 switch (type) { 117 case NODE: 118 return NODE; 119 case WAY: 120 return WAY; 121 case CLOSEDWAY: 122 return CLOSEDWAY; 123 case RELATION: 124 return RELATION; 125 default: 126 throw new IllegalArgumentException(); 127 } 128 } 129 } 130 131 /** 132 * Enum denoting the way how a match (see {@link Item#matches}) is performed. 133 */ 134 private enum MatchType { 135 136 /** 137 * Neutral, i.e., o not consider this item for matching. 138 */ 139 NONE("none"), /** 140 * Positive if key matches, neutral otherwise. 141 */ 142 KEY("key"), 143 /** 144 * Positive if key matches, negative otherwise. 145 */ 146 KEY_REQUIRED("key!"), 147 /** 148 * Positive if key and value matches, negative otherwise. 149 */ 150 KEY_VALUE("keyvalue"); 151 private final String value; 152 153 private MatchType(String value) { 154 this.value = value; 155 } 156 157 public String getValue() { 158 return value; 159 } 160 161 public static MatchType ofString(String type) { 162 for (MatchType i : EnumSet.allOf(MatchType.class)) { 163 if (i.getValue().equals(type)) { 164 return i; 165 } 166 } 167 throw new IllegalArgumentException(type + " is not allowed"); 168 } 110 169 } 111 170 112 171 public static final int DIALOG_ANSWER_APPLY = 1; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 139 198 boolean requestFocusInWindow() { 140 199 return false; 141 200 } 201 202 /** 203 * Tests whether the tags match this item. 204 * @param tags the tags of an {@link OsmPrimitive} 205 * @return {@code true} if matches (positive), {@code null} if neutral, {@code false} if mismatches (negative). 206 */ 207 abstract Boolean matches(Map<String, String> tags); 142 208 } 143 209 144 210 public static class Usage { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 244 310 public String text; 245 311 public String locale_text; 246 312 public String text_context; 247 public String default_ ;313 public String default_ = ""; 248 314 public String originalValue; 249 315 public String use_last_as_default = "false"; 250 public boolean delete_if_empty = false; 251 public boolean required = false; 316 public String match = MatchType.NONE.getValue(); 252 317 253 318 private JComponent value; 254 319 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 315 380 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) 316 381 return; 317 382 318 if (delete_if_empty && v.length() == 0) {319 v = null;320 }321 383 changedTags.add(new Tag(key, v)); 322 384 } 323 385 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 325 387 boolean requestFocusInWindow() { 326 388 return value.requestFocusInWindow(); 327 389 } 390 391 @Override 392 Boolean matches(Map<String, String> tags) { 393 switch (MatchType.ofString(match)) { 394 case NONE: 395 return null; 396 case KEY: 397 return tags.containsKey(key) ? true : null; 398 case KEY_REQUIRED: 399 return tags.containsKey(key); 400 default: 401 throw new IllegalArgumentException("key_value matching not supported for <text>: " + text); 402 } 403 } 328 404 } 329 405 330 406 public static class Check extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 336 412 public String value_on = OsmUtils.trueval; 337 413 public String value_off = OsmUtils.falseval; 338 414 public boolean default_ = false; // only used for tagless objects 339 public boolean required = false;415 public String match = MatchType.NONE.getValue(); 340 416 341 417 private QuadStateCheckBox check; 342 418 private QuadStateCheckBox.State initialState; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 410 486 null)); 411 487 } 412 488 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} 489 490 @Override 491 Boolean matches(Map<String, String> tags) { 492 switch (MatchType.ofString(match)) { 493 case NONE: 494 return null; 495 case KEY: 496 return tags.containsKey(key) ? true : null; 497 case KEY_REQUIRED: 498 return tags.containsKey(key); 499 case KEY_VALUE: 500 return value_off.equals(tags.get(key)) || value_on.equals(tags.get(key)); 501 default: 502 throw new IllegalStateException(); 503 } 504 } 413 505 } 414 506 415 507 public static abstract class ComboMultiSelect extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 426 518 public String locale_short_descriptions; 427 519 public String default_; 428 520 public String delimiter = ";"; 429 public boolean delete_if_empty = false;430 521 public String use_last_as_default = "false"; 431 public boolean required = false;522 public String match = MatchType.NONE.getValue(); 432 523 433 524 protected List<String> short_description_list; 434 525 protected JComponent component; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 439 530 protected abstract Object getSelectedItem(); 440 531 protected abstract void addToPanelAnchor(JPanel p, String def, String[] display_array); 441 532 533 protected char getDelChar() { 534 return delimiter.isEmpty() ? ';' : delimiter.charAt(0); 535 } 536 442 537 @Override 443 538 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 444 539 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 446 541 usage = determineTextUsage(sel, key); 447 542 String def = default_; 448 543 449 char delChar = ';'; 450 if (!delimiter.isEmpty()) { 451 delChar = delimiter.charAt(0); 452 } 544 char delChar = getDelChar(); 453 545 454 546 String[] value_array = splitEscaped(delChar, values); 455 547 String[] display_array; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 551 643 } else if (value.equals(originalValue.toString())) 552 644 return; 553 645 554 if (delete_if_empty && value.length() == 0) {555 value = null;556 }557 646 if (!"false".equals(use_last_as_default)) { 558 647 lastValue.put(key, value); 559 648 } … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 607 696 } 608 697 }; 609 698 } 699 700 @Override 701 Boolean matches(Map<String, String> tags) { 702 switch (MatchType.ofString(match)) { 703 case NONE: 704 return null; 705 case KEY: 706 return tags.containsKey(key) ? true : null; 707 case KEY_REQUIRED: 708 return tags.containsKey(key); 709 case KEY_VALUE: 710 return tags.containsKey(key) 711 && Arrays.asList(splitEscaped(getDelChar(), values)).contains(tags.get(key)); 712 default: 713 throw new IllegalStateException(); 714 } 715 } 610 716 } 611 717 612 718 public static class Combo extends ComboMultiSelect { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 827 933 @Override 828 934 public void addCommands(List<Tag> changedTags) { 829 935 } 936 937 @Override 938 Boolean matches(Map<String, String> tags) { 939 return null; 940 } 830 941 } 831 942 832 943 public static class Link extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 861 972 @Override 862 973 public void addCommands(List<Tag> changedTags) { 863 974 } 975 976 @Override 977 Boolean matches(Map<String, String> tags) { 978 return null; 979 } 864 980 } 865 981 866 982 public static class Role { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 870 986 public String text_context; 871 987 public String locale_text; 872 988 873 public boolean required =false;989 public boolean required = false; 874 990 public long count = 0; 875 991 876 992 public void setType(String types) throws SAXException { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 955 1071 @Override 956 1072 public void addCommands(List<Tag> changedTags) { 957 1073 } 1074 1075 @Override 1076 Boolean matches(Map<String, String> tags) { 1077 return null; 1078 } 958 1079 } 959 1080 960 1081 public static class Optional extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 971 1092 @Override 972 1093 public void addCommands(List<Tag> changedTags) { 973 1094 } 1095 1096 @Override 1097 Boolean matches(Map<String, String> tags) { 1098 return null; 1099 } 974 1100 } 975 1101 976 1102 public static class Space extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 984 1110 @Override 985 1111 public void addCommands(List<Tag> changedTags) { 986 1112 } 1113 1114 @Override 1115 Boolean matches(Map<String, String> tags) { 1116 return null; 1117 } 987 1118 } 988 1119 989 1120 public static class Key extends Item { 990 1121 991 1122 public String key; 992 1123 public String value; 1124 public String match = MatchType.KEY_VALUE.getValue(); 993 1125 994 1126 @Override 995 1127 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 1000 1132 public void addCommands(List<Tag> changedTags) { 1001 1133 changedTags.add(new Tag(key, value)); 1002 1134 } 1135 1136 @Override 1137 Boolean matches(Map<String, String> tags) { 1138 switch (MatchType.ofString(match)) { 1139 case NONE: 1140 return null; 1141 case KEY: 1142 return tags.containsKey(key) ? true : null; 1143 case KEY_REQUIRED: 1144 return tags.containsKey(key); 1145 case KEY_VALUE: 1146 return value.equals(tags.get(key)); 1147 default: 1148 throw new IllegalStateException(); 1149 } 1150 } 1003 1151 } 1004 1152 1005 1153 /** … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 1485 1633 public String toString() { 1486 1634 return (types == null?"":types) + " " + name; 1487 1635 } 1636 1637 public boolean matches(Collection<PresetType> t, Map<String, String> tags) { 1638 if (!isShowable()) { 1639 return false; 1640 } else if (t != null && types != null && !types.containsAll(t)) { 1641 return false; 1642 } 1643 boolean atLeastOnePositiveMatch = false; 1644 for (Item item : data) { 1645 Boolean m = item.matches(tags); 1646 if (m != null && !m) { 1647 return false; 1648 } else if (m != null) { 1649 atLeastOnePositiveMatch = true; 1650 } 1651 } 1652 return atLeastOnePositiveMatch; 1653 } 1488 1654 } -
src/org/openstreetmap/josm/tools/TaggingPresetNameTemplateList.java
diff --git a/src/org/openstreetmap/josm/tools/TaggingPresetNameTemplateList.java b/src/org/openstreetmap/josm/tools/TaggingPresetNameTemplateList.java index 6792206..c9e252a 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.util.ArrayList; 4 import java.util.EnumSet; 5 import java.util.LinkedList; 5 6 import java.util.List; 6 7 7 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.Way;9 9 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 10 10 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 11 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Check;12 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Combo;13 11 import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType; 14 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Text;15 12 16 13 /** 17 14 * List of tagging presets with name templates, allows to find appropriate template based on existing primitive … … public class TaggingPresetNameTemplateList { 26 23 } 27 24 return instance; 28 25 } 29 30 private final List<TaggingPreset> presetsWithPattern = new ArrayList<TaggingPreset>(); 26 private final List<TaggingPreset> presetsWithPattern = new LinkedList<TaggingPreset>(); 31 27 32 28 private TaggingPresetNameTemplateList() { 33 29 if (TaggingPresetPreference.taggingPresets != null) { 34 for (TaggingPreset tp : TaggingPresetPreference.taggingPresets) {30 for (TaggingPreset tp : TaggingPresetPreference.taggingPresets) { 35 31 if (tp.nameTemplate != null) { 36 32 presetsWithPattern.add(tp); 37 33 } … … public class TaggingPresetNameTemplateList { 41 37 42 38 public TaggingPreset findPresetTemplate(OsmPrimitive primitive) { 43 39 44 PresetType presetType; 45 switch (primitive.getType()) { 46 case NODE: 47 presetType = PresetType.NODE; 48 break; 49 case WAY: 50 if (((Way) primitive).isClosed()) { 51 presetType = PresetType.CLOSEDWAY; 52 } else { 53 presetType = PresetType.WAY; 40 for (TaggingPreset t : presetsWithPattern) { 41 if (t.matches(EnumSet.of(PresetType.forPrimitive(primitive)), primitive.getKeys())) { 42 return t; 54 43 } 55 break;56 case RELATION:57 presetType = PresetType.RELATION;58 break;59 default:60 throw new AssertionError();61 44 } 62 63 for(TaggingPreset t : presetsWithPattern) {64 65 66 if ( t.types == null67 || t.types.contains(presetType)68 || (presetType == PresetType.CLOSEDWAY && t.types.contains(PresetType.WAY))) {69 int found = 0;70 71 if (t.nameTemplateFilter != null) {72 if (t.nameTemplateFilter.match(primitive))73 return t;74 else {75 continue;76 }77 }78 79 for(TaggingPreset.Item i : t.data) {80 if(i instanceof TaggingPreset.Key) {81 String val = ((TaggingPreset.Key)i).value;82 String key = ((TaggingPreset.Key)i).key;83 // we subtract 100 if not found and add 1 if found84 if (val != null && val.equals(primitive.get(key))) {85 found+=1;86 } else {87 found-=100;88 }89 } else {90 String key = null;91 if ((i instanceof Text) && ((Text)i).required) {92 key = ((Text)i).key;93 } else if ((i instanceof Combo) && ((Combo)i).required) {94 key = ((Combo)i).key;95 } else if ((i instanceof Check) && ((Check)i).required) {96 key = ((Check)i).key;97 }98 if (key != null) {99 if (primitive.get(key) != null) {100 found += 1;101 } else {102 found -= 100;103 }104 }105 }106 }107 108 if(found > 0)109 return t; // First matching preset wins110 }111 }112 113 45 return null; 114 115 46 } 116 117 118 47 }