Changeset 3388 in josm


Ignore:
Timestamp:
Jul 27, 2010 8:06:29 PM (3 years ago)
Author:
jttt
Message:

Add tagging preset search dialog

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r3385 r3388  
    8585import org.openstreetmap.josm.actions.search.SearchAction; 
    8686import org.openstreetmap.josm.gui.layer.Layer; 
     87import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction; 
    8788import org.openstreetmap.josm.tools.Shortcut; 
    8889/** 
     
    183184    public final JumpToAction jumpToAct = new JumpToAction(); 
    184185 
     186    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); 
     187 
    185188 
    186189    /** 
     
    289292        } 
    290293 
     294        add(presetsMenu, presetSearchAction); 
     295 
    291296        add(toolsMenu, splitWay); 
    292297        add(toolsMenu, combineWay); 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r3327 r3388  
    22package org.openstreetmap.josm.gui.tagging; 
    33 
    4 import static org.openstreetmap.josm.tools.I18n.marktr; 
    54import static org.openstreetmap.josm.tools.I18n.tr; 
    65import static org.openstreetmap.josm.tools.I18n.trc; 
     
    2120import java.util.Arrays; 
    2221import java.util.Collection; 
     22import java.util.EnumSet; 
    2323import java.util.HashMap; 
    2424import java.util.LinkedHashMap; 
     
    7070 */ 
    7171public class TaggingPreset extends AbstractAction implements MapView.LayerChangeListener { 
     72 
     73    public enum PresetType { 
     74        NODE("Mf_node"), WAY("Mf_way"), RELATION("Mf_relation"), CLOSEDWAY("Mf_closedway"); 
     75 
     76        private final String iconName; 
     77 
     78        PresetType(String iconName) { 
     79            this.iconName = iconName; 
     80        } 
     81 
     82        public String getIconName() { 
     83            return iconName; 
     84        } 
     85 
     86        public String getName() { 
     87            return name().toLowerCase(); 
     88        } 
     89 
     90    } 
    7291 
    7392    public TaggingPresetMenu group = null; 
     
    487506 
    488507    public static class Role { 
    489         public List<String> types; 
     508        public EnumSet<PresetType> types; 
    490509        public String key; 
    491510        public String text; 
     
    545564            if(types != null){ 
    546565                JPanel pp = new JPanel(); 
    547                 for(String t : types) { 
    548                     pp.add(new JLabel(ImageProvider.get("Mf_" + t))); 
     566                for(PresetType t : types) { 
     567                    pp.add(new JLabel(ImageProvider.get(t.getIconName()))); 
    549568                } 
    550569                p.add(pp, GBC.eol()); 
     
    607626     * The types as preparsed collection. 
    608627     */ 
    609     public List<String> types; 
     628    public EnumSet<PresetType> types; 
    610629    public List<Item> data = new LinkedList<Item>(); 
    611630    private static HashMap<String,String> lastValue = new HashMap<String,String>(); 
     
    669688     * Called from the XML parser to set the types this preset affects 
    670689     */ 
    671     private static Collection<String> allowedtypes = Arrays.asList(new String[] 
    672                                                                               {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 
    673  
    674     static public List<String> getType(String types) throws SAXException { 
    675         List<String> t = Arrays.asList(types.split(",")); 
    676         for (String type : t) { 
    677             if(!allowedtypes.contains(type)) 
     690 
     691    static public EnumSet<PresetType> getType(String types) throws SAXException { 
     692        EnumSet<PresetType> result = EnumSet.noneOf(PresetType.class); 
     693        for (String type : Arrays.asList(types.split(","))) { 
     694            try { 
     695                PresetType presetType = PresetType.valueOf(type.toUpperCase()); 
     696                result.add(presetType); 
     697            } catch (IllegalArgumentException e) { 
    678698                throw new SAXException(tr("Unknown type: {0}", type)); 
    679         } 
    680         return t; 
     699            } 
     700        } 
     701        return result; 
    681702    } 
    682703 
     
    833854        if(types != null){ 
    834855            JPanel pp = new JPanel(); 
    835             for(String t : types){ 
    836                 JLabel la = new JLabel(ImageProvider.get("Mf_" + t)); 
    837                 la.setToolTipText(tr("Elements of type {0} are supported.", tr(t))); 
     856            for(PresetType t : types){ 
     857                JLabel la = new JLabel(ImageProvider.get(t.getIconName())); 
     858                la.setToolTipText(tr("Elements of type {0} are supported.", tr(t.getName()))); 
    838859                pp.add(la); 
    839860            } 
     
    953974                if(osm instanceof Relation) 
    954975                { 
    955                     if(!types.contains("relation")) { 
     976                    if(!types.contains(PresetType.RELATION)) { 
    956977                        continue; 
    957978                    } 
     
    959980                else if(osm instanceof Node) 
    960981                { 
    961                     if(!types.contains("node")) { 
     982                    if(!types.contains(PresetType.NODE)) { 
    962983                        continue; 
    963984                    } 
     
    965986                else if(osm instanceof Way) 
    966987                { 
    967                     if(!types.contains("way") && 
    968                             !(types.contains("closedway") && ((Way)osm).isClosed())) { 
     988                    if(!types.contains(PresetType.WAY) && 
     989                            !(types.contains(PresetType.CLOSEDWAY) && ((Way)osm).isClosed())) { 
    969990                        continue; 
    970991                    } 
Note: See TracChangeset for help on using the changeset viewer.