Changeset 3289 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2010-06-01T09:09:39+02:00 (14 years ago)
Author:
stoecker
Message:

added role support to presets

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.