Changeset 3289 in josm


Ignore:
Timestamp:
Jun 1, 2010 9:09:39 AM (3 years ago)
Author:
stoecker
Message:

added role support to presets

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r3279 r3289  
    4848  value_off: the value to set when unchecked (default is 'no') 
    4949 
     50role: type to specify possible roles in relations 
     51  key: the role name used in relation 
     52  text: fixed label to display 
     53  requisite: "optional" or "required" (default is optional) 
     54  count: how often can the role occur (if not given unlimited number is assumed) 
     55  type: the data types - way,node,relation,closedway (separated by comma) 
     56 
    5057For external files the <annotations> should have following elements: 
    5158- author           the author of the preset 
     
    31793186    </group> <!-- Landuse --> 
    31803187  </group> 
    3181 <!-- FIXME: element role not yet supported! --> 
    31823188    <group name="Relations" icon="presets/relations.png"> 
    31833189        <item name="Multipolygon" icon="presets/empty.png" type="relation"> 
     
    31933199                <role key="outer" text="outer segment" requisite="required" type="way" /> 
    31943200                <role key="inner" text="inner segment" requisite="optional" type="way" /> 
     3201            </roles> 
     3202        </item> 
     3203        <item name="Boundary" icon="presets/empty.png" type="relation"> 
     3204            <link href="http://wiki.openstreetmap.org/wiki/Relation:boundary" 
     3205                  de.href="http://wiki.openstreetmap.org/wiki/DE:Relation:boundary" 
     3206                  es.href="http://wiki.openstreetmap.org/wiki/ES:Relation:boundary" 
     3207                  fr.href="http://wiki.openstreetmap.org/wiki/FR:Relation:boundary" /> 
     3208            <label text="Edit Boundary" /> 
     3209            <key key="type" value="boundary" /> 
     3210            <text key="name" text="Name" default="" delete_if_empty="true" /> 
     3211            <optional> 
     3212                <combo key="boundary" text="Boundary type" values="administrative,national,civil,political" default="" delete_if_empty="true" /> 
     3213                <combo key="admin_level" text="Administrative level" values="1,2,3,4,5,6,7,8,9,10" default="" delete_if_empty="true" /> 
     3214            </optional> 
     3215            <roles> 
     3216                <role key="outer" text="outer segment" requisite="required" type="way" /> 
     3217                <role key="inner" text="inner segment" requisite="optional" type="way" /> 
     3218                <role key="subarea" text="Sub area" requisite="optional" type="relation" /> 
     3219                <role key="admin_centre" text="Administration centre" requisite="optional" type="node" /> 
    31953220            </roles> 
    31963221        </item> 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r3225 r3289  
    310310                } 
    311311        ); 
     312        tfRole.setText(Main.pref.get("relation.editor.generic.lastrole", "")); 
    312313        p3.add(tfRole); 
    313314        SetRoleAction setRoleAction = new SetRoleAction(); 
     
    11671168 
    11681169        public void run() { 
     1170            Main.pref.put("relation.editor.generic.lastrole", tfRole.getText()); 
    11691171            if (getRelation() == null) { 
    11701172                applyNewRelation(); 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r3279 r3289  
    486486    } 
    487487 
     488    public static class Role { 
     489        public List<String> types; 
     490        public String key; 
     491        public String text; 
     492        public String text_context; 
     493        public String locale_text; 
     494 
     495        public boolean required=false; 
     496        public long count = 0; 
     497 
     498        public void setType(String types) throws SAXException { 
     499            this.types = TaggingPreset.getType(types); 
     500        } 
     501 
     502        public void setRequisite(String str) throws SAXException { 
     503            if("required".equals(str)) 
     504                required = true; 
     505            else if(!"optional".equals(str)) 
     506                throw new SAXException(tr("Unknown requisite: {0}", str)); 
     507        } 
     508 
     509        /* return either argument, the highest possible value or the lowest 
     510           allowed value */ 
     511        public long getValidCount(long c) 
     512        { 
     513            if(count > 0 && !required) 
     514                return c != 0 ? count : 0; 
     515            else if(count > 0) 
     516                return count; 
     517            else if(!required) 
     518                return c != 0  ? c : 0; 
     519            else 
     520                return c != 0  ? c : 1; 
     521        } 
     522        public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     523            String cstring; 
     524            if(count > 0 && !required) 
     525                cstring = "0,"+String.valueOf(count); 
     526            else if(count > 0) 
     527                cstring = String.valueOf(count); 
     528            else if(!required) 
     529                cstring = "0-..."; 
     530            else 
     531                cstring = "1-..."; 
     532            if(locale_text == null) { 
     533                if (text != null) { 
     534                    if(text_context != null) { 
     535                        locale_text = trc(text_context, text); 
     536                    } else { 
     537                        locale_text = tr(text); 
     538                    } 
     539                } 
     540            } 
     541            p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 
     542            p.add(new JLabel(key), GBC.std().insets(0,0,10,0)); 
     543            p.add(new JLabel(cstring), types == null ? GBC.eol() : GBC.std().insets(0,0,10,0)); 
     544            if(types != null){ 
     545                JPanel pp = new JPanel(); 
     546                for(String t : types) 
     547                    pp.add(new JLabel(ImageProvider.get("Mf_" + t))); 
     548                p.add(pp, GBC.eol()); 
     549            } 
     550            return true; 
     551        } 
     552    } 
     553 
     554    public static class Roles extends Item { 
     555        public List<Role> roles = new LinkedList<Role>(); 
     556        @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 
     557            p.add(new JLabel(" "), GBC.eol()); // space 
     558            if(roles.size() > 0) 
     559            { 
     560                JPanel proles = new JPanel(new GridBagLayout()); 
     561                proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0,0,10,0)); 
     562                proles.add(new JLabel(tr("role")), GBC.std().insets(0,0,10,0)); 
     563                proles.add(new JLabel(tr("count")), GBC.std().insets(0,0,10,0)); 
     564                proles.add(new JLabel(tr("elements")), GBC.eol()); 
     565                for (Role i : roles) 
     566                    i.addToPanel(proles, sel); 
     567                p.add(proles, GBC.eol()); 
     568            } 
     569            return false; 
     570        } 
     571        @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 
     572    } 
     573 
    488574    public static class Optional extends Item { 
    489575        // TODO: Draw a box around optional stuff 
     
    581667     */ 
    582668    private static Collection<String> allowedtypes = Arrays.asList(new String[] 
    583                                                                               {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 
    584     public void setType(String types) throws SAXException { 
    585         this.types = Arrays.asList(types.split(",")); 
    586         for (String type : this.types) { 
     669    {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 
     670 
     671    static public List<String> getType(String types) throws SAXException { 
     672        List<String> t = Arrays.asList(types.split(",")); 
     673        for (String type : t) { 
    587674            if(!allowedtypes.contains(type)) 
    588675                throw new SAXException(tr("Unknown type: {0}", type)); 
    589676        } 
     677        return t; 
     678    } 
     679 
     680    public void setType(String types) throws SAXException { 
     681        this.types = getType(types); 
    590682    } 
    591683 
     
    598690        parser.map("link", Link.class); 
    599691        parser.mapOnStart("optional", Optional.class); 
     692        parser.mapOnStart("roles", Roles.class); 
     693        parser.map("role", Role.class); 
    600694        parser.map("check", Check.class); 
    601695        parser.map("combo", Combo.class); 
     
    605699        LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 
    606700        TaggingPresetMenu lastmenu = null; 
     701        Roles lastrole = null; 
    607702        parser.start(in); 
    608703        while(parser.hasNext()) { 
     
    621716 
    622717                } 
     718                lastrole = null; 
    623719            } else if (o instanceof TaggingPresetSeparator) { 
    624720                TaggingPresetSeparator tp = (TaggingPresetSeparator) o; 
    625721                tp.group = lastmenu; 
    626722                all.add(tp); 
     723                lastrole = null; 
    627724            } else if (o instanceof TaggingPreset) { 
    628725                TaggingPreset tp = (TaggingPreset) o; 
     
    631728                all.add(tp); 
    632729                Main.toolbar.register(tp); 
     730                lastrole = null; 
    633731            } else { 
    634                 if(all.size() != 0) 
    635                     all.getLast().data.add((Item)o); 
     732                if(all.size() != 0) { 
     733                    if(o instanceof Roles) { 
     734                        all.getLast().data.add((Item)o); 
     735                        lastrole = (Roles) o; 
     736                    } 
     737                    else if(o instanceof Role) { 
     738                        if(lastrole == null) 
     739                            throw new SAXException(tr("Preset role element without parent")); 
     740                        lastrole.roles.add((Role) o); 
     741                    } 
     742                    else { 
     743                        all.getLast().data.add((Item)o); 
     744                        lastrole = null; 
     745                    } 
     746                } 
    636747                else 
    637748                    throw new SAXException(tr("Preset sub element without parent")); 
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java

    r3214 r3289  
    7575     * use getRoleCache() accessor 
    7676     */ 
    77     protected  Set<String> roleCache; 
     77    protected Set<String> roleCache; 
     78    /** 
     79     * the same as roleCache but for the preset roles 
     80     * can be accessed directly 
     81     */ 
     82    protected static Set<String> presetRoleCache = new HashSet<String>(); 
    7883 
    7984    public AutoCompletionManager(DataSet ds) { 
     
    179184                        presetTagCache.put(tt.key, tt.default_); 
    180185                    } 
     186                } else if (item instanceof TaggingPreset.Roles) { 
     187                    TaggingPreset.Roles r = (TaggingPreset.Roles) item; 
     188                    for (TaggingPreset.Role i : r.roles) { 
     189                        if (i.key != null) 
     190                            presetRoleCache.add(i.key); 
     191                    } 
    181192                } 
    182193            } 
     
    228239     */ 
    229240    public void populateWithMemberRoles(AutoCompletionList list) { 
     241        list.add(presetRoleCache, AutoCompletionItemPritority.IS_IN_STANDARD); 
    230242        list.add(getRoleCache(), AutoCompletionItemPritority.IS_IN_DATASET); 
    231243    } 
Note: See TracChangeset for help on using the changeset viewer.