Ignore:
Timestamp:
2012-04-01T19:48:01+02:00 (12 years ago)
Author:
simon04
Message:

fix #5933 - tagging presets: allow to change the matching process (match=none|key|key!|keyvalue), remove delete_if_empty, default defaults to "", adapted comments in defaultpresets.xml, refactoring of the matching process (removes some duplicate code and some magical arithmetic)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java

    r4968 r5155  
    1111import java.util.Collection;
    1212import java.util.Collections;
    13 import java.util.Hashtable;
    1413import java.util.List;
    1514import java.util.Map;
     
    2423import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
    2524import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    26 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Check;
    27 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Combo;
    2825import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType;
    29 import org.openstreetmap.josm.gui.tagging.TaggingPreset.Text;
    3026import org.openstreetmap.josm.tools.GBC;
    3127
     
    8278    }
    8379
    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) {
    8581
    8682        removeAll();
    87         int total = nodes+ways+relations+closedways;
    88         if(total == 0) {
     83        if (types.isEmpty()) {
    8984            setVisible(false);
    9085            return;
    9186        }
    9287
    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            }
    11392
    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));
    14697        }
    14798
    148         if(getComponentCount() > 0) {
     99        if (getComponentCount() > 0) {
    149100            setVisible(true);
    150101            // This ensures the presets are exactly as high as needed.
     
    157108        }
    158109    }
    159 
    160110}
Note: See TracChangeset for help on using the changeset viewer.