Changeset 3137 in josm for trunk/src/org


Ignore:
Timestamp:
2010-03-15T14:18:45+01:00 (14 years ago)
Author:
Gubaer
Message:

added a few utility methods

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java

    r3083 r3137  
    1111import java.util.Iterator;
    1212import java.util.List;
     13import java.util.Map;
    1314import java.util.Set;
    1415import java.util.Map.Entry;
     
    5455
    5556    /**
     57     * Creates a tag collection from a map of key/value-pairs. Replies
     58     * an empty tag collection if {@code tags} is null.
     59     *
     60     * @param tags  the key/value-pairs
     61     * @return the tag collection
     62     */
     63    public static TagCollection from(Map<String,String> tags) {
     64        TagCollection ret = new TagCollection();
     65        if (tags == null) return ret;
     66        for (Entry<String,String> entry: tags.entrySet()) {
     67            String key = entry.getKey() == null? "" : entry.getKey();
     68            String value = entry.getValue() == null ? "" : entry.getValue();
     69            ret.add(new Tag(key,value));
     70        }
     71        return ret;
     72    }
     73
     74    /**
    5675     * Creates a tag collection from the union of the tags managed by
    5776     * a collection of primitives. Replies an empty tag collection,
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r3083 r3137  
    2222import org.openstreetmap.josm.command.SequenceCommand;
    2323import org.openstreetmap.josm.data.osm.OsmPrimitive;
     24import org.openstreetmap.josm.data.osm.TagCollection;
    2425import org.openstreetmap.josm.data.osm.Tagged;
    2526
     
    331332
    332333    /**
     334     * Initializes the model with the tags in a tag collection. Removes
     335     * all tags if {@code tags} is null.
     336     *
     337     * @param tags the tags
     338     */
     339    public void initFromTags(TagCollection tags) {
     340        clear();
     341        if (tags == null){
     342            setDirty(false);
     343            return;
     344        }
     345        for (String key : tags.getKeys()) {
     346            String value = tags.getJoinedValues(key);
     347            add(key,value);
     348        }
     349        sort();
     350        // add an empty row
     351        TagModel tag = new TagModel();
     352        this.tags.add(tag);
     353        setDirty(false);
     354    }
     355
     356    /**
    333357     * applies the current state of the tag editor model to a primitive
    334358     *
     
    370394        applyToTags(tags);
    371395        return tags;
     396    }
     397
     398    /**
     399     * Replies the the tags in this tag editor model as {@see TagCollection}.
     400     *
     401     * @return the the tags in this tag editor model as {@see TagCollection}
     402     */
     403    public TagCollection getTagCollection() {
     404        return TagCollection.from(getTags());
    372405    }
    373406
Note: See TracChangeset for help on using the changeset viewer.