Ticket #5933: 5933.patch
File 5933.patch, 28.3 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 15bcc62..f8edcfd 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 6fc18f2..d2ac05a 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.getType()); 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; 316 @Deprecated 317 public boolean delete_if_empty = true; 318 @Deprecated 251 319 public boolean required = false; 320 public String match = MatchType.NONE.getValue(); 252 321 253 322 private JComponent value; 254 323 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 325 394 boolean requestFocusInWindow() { 326 395 return value.requestFocusInWindow(); 327 396 } 397 398 @Override 399 Boolean matches(Map<String, String> tags) { 400 switch (MatchType.ofString(match)) { 401 case NONE: 402 return null; 403 case KEY: 404 return tags.containsKey(key) ? true : null; 405 case KEY_REQUIRED: 406 return tags.containsKey(key); 407 default: 408 throw new IllegalArgumentException("key_value matching not supported for <text>: " + text); 409 } 410 } 328 411 } 329 412 330 413 public static class Check extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 336 419 public String value_on = OsmUtils.trueval; 337 420 public String value_off = OsmUtils.falseval; 338 421 public boolean default_ = false; // only used for tagless objects 422 @Deprecated 339 423 public boolean required = false; 424 public String match = MatchType.NONE.getValue(); 340 425 341 426 private QuadStateCheckBox check; 342 427 private QuadStateCheckBox.State initialState; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 410 495 null)); 411 496 } 412 497 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} 498 499 @Override 500 Boolean matches(Map<String, String> tags) { 501 switch (MatchType.ofString(match)) { 502 case NONE: 503 return null; 504 case KEY: 505 return tags.containsKey(key) ? true : null; 506 case KEY_REQUIRED: 507 return tags.containsKey(key); 508 case KEY_VALUE: 509 return value_off.equals(tags.get(key)) || value_on.equals(tags.get(key)); 510 default: 511 throw new IllegalStateException(); 512 } 513 } 413 514 } 414 515 415 516 public static abstract class ComboMultiSelect extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 426 527 public String locale_short_descriptions; 427 528 public String default_; 428 529 public String delimiter = ";"; 429 public boolean delete_if_empty = false; 530 @Deprecated 531 public boolean delete_if_empty = true; 430 532 public String use_last_as_default = "false"; 533 @Deprecated 431 534 public boolean required = false; 535 public String match = MatchType.NONE.getValue(); 432 536 433 537 protected List<String> short_description_list; 434 538 protected JComponent component; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 439 543 protected abstract Object getSelectedItem(); 440 544 protected abstract void addToPanelAnchor(JPanel p, String def, String[] display_array); 441 545 546 protected char getDelChar() { 547 return delimiter.isEmpty() ? ';' : delimiter.charAt(0); 548 } 549 442 550 @Override 443 551 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 444 552 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 446 554 usage = determineTextUsage(sel, key); 447 555 String def = default_; 448 556 449 char delChar = ';'; 450 if (!delimiter.isEmpty()) { 451 delChar = delimiter.charAt(0); 452 } 557 char delChar = getDelChar(); 453 558 454 559 String[] value_array = splitEscaped(delChar, values); 455 560 String[] display_array; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 607 712 } 608 713 }; 609 714 } 715 716 @Override 717 Boolean matches(Map<String, String> tags) { 718 switch (MatchType.ofString(match)) { 719 case NONE: 720 return null; 721 case KEY: 722 return tags.containsKey(key) ? true : null; 723 case KEY_REQUIRED: 724 return tags.containsKey(key); 725 case KEY_VALUE: 726 return tags.containsKey(key) 727 && Arrays.asList(splitEscaped(getDelChar(), values)).contains(tags.get(key)); 728 default: 729 throw new IllegalStateException(); 730 } 731 } 610 732 } 611 733 612 734 public static class Combo extends ComboMultiSelect { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 827 949 @Override 828 950 public void addCommands(List<Tag> changedTags) { 829 951 } 952 953 @Override 954 Boolean matches(Map<String, String> tags) { 955 return null; 956 } 830 957 } 831 958 832 959 public static class Link extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 861 988 @Override 862 989 public void addCommands(List<Tag> changedTags) { 863 990 } 991 992 @Override 993 Boolean matches(Map<String, String> tags) { 994 return null; 995 } 864 996 } 865 997 866 998 public static class Role { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 870 1002 public String text_context; 871 1003 public String locale_text; 872 1004 873 public boolean required =false;1005 public boolean required = false; 874 1006 public long count = 0; 875 1007 876 1008 public void setType(String types) throws SAXException { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 955 1087 @Override 956 1088 public void addCommands(List<Tag> changedTags) { 957 1089 } 1090 1091 @Override 1092 Boolean matches(Map<String, String> tags) { 1093 return null; 1094 } 958 1095 } 959 1096 960 1097 public static class Optional extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 971 1108 @Override 972 1109 public void addCommands(List<Tag> changedTags) { 973 1110 } 1111 1112 @Override 1113 Boolean matches(Map<String, String> tags) { 1114 return null; 1115 } 974 1116 } 975 1117 976 1118 public static class Space extends Item { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 984 1126 @Override 985 1127 public void addCommands(List<Tag> changedTags) { 986 1128 } 1129 1130 @Override 1131 Boolean matches(Map<String, String> tags) { 1132 return null; 1133 } 987 1134 } 988 1135 989 1136 public static class Key extends Item { 990 1137 991 1138 public String key; 992 1139 public String value; 1140 public String match = MatchType.KEY_VALUE.getValue(); 993 1141 994 1142 @Override 995 1143 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 1000 1148 public void addCommands(List<Tag> changedTags) { 1001 1149 changedTags.add(new Tag(key, value)); 1002 1150 } 1151 1152 @Override 1153 Boolean matches(Map<String, String> tags) { 1154 switch (MatchType.ofString(match)) { 1155 case NONE: 1156 return null; 1157 case KEY: 1158 return tags.containsKey(key) ? true : null; 1159 case KEY_REQUIRED: 1160 return tags.containsKey(key); 1161 case KEY_VALUE: 1162 return value.equals(tags.get(key)); 1163 default: 1164 throw new IllegalStateException(); 1165 } 1166 } 1003 1167 } 1004 1168 1005 1169 /** … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 1485 1649 public String toString() { 1486 1650 return (types == null?"":types) + " " + name; 1487 1651 } 1652 1653 public boolean matches(Collection<PresetType> t, Map<String, String> tags) { 1654 if (!isShowable()) { 1655 return false; 1656 } 1657 if (t != null && !types.containsAll(t)) { 1658 return false; 1659 } 1660 boolean atLeastOnePositiveMatch = false; 1661 for (Item item : data) { 1662 Boolean m = item.matches(tags); 1663 if (m != null && !m) { 1664 return false; 1665 } else if (m != null) { 1666 atLeastOnePositiveMatch = true; 1667 } 1668 } 1669 return atLeastOnePositiveMatch; 1670 } 1488 1671 } -
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 }