Changeset 5155 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java
- Timestamp:
- 2012-04-01T19:48:01+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java
r4968 r5155 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; … … 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 … … 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 } 88 for (TaggingPreset t : TaggingPresetPreference.taggingPresets) { 89 if (!t.matches(types, tags)) { 90 continue; 91 } 113 92 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)); 145 } 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. … … 157 108 } 158 109 } 159 160 110 }
Note:
See TracChangeset
for help on using the changeset viewer.