001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.datatransfer.data;
003
004import java.awt.datatransfer.DataFlavor;
005import java.io.Serializable;
006import java.util.Collection;
007import java.util.Collections;
008import java.util.Map;
009
010import org.openstreetmap.josm.data.osm.TagMap;
011import org.openstreetmap.josm.data.osm.Tagged;
012
013/**
014 * This is a special transfer type that only transfers tag data.
015 * <p>
016 * It contains all tags contained in the selection that was copied. For conflicting tags, any of the values may be used.
017 * @author Michael Zangl
018 * @since 10604
019 */
020public class TagTransferData implements Serializable {
021
022    private static final long serialVersionUID = 1;
023
024    /**
025     * This is a data flavor added
026     */
027    public static final DataFlavor FLAVOR = new DataFlavor(TagTransferData.class, "OSM Tags");
028
029    private final TagMap tags = new TagMap();
030
031    /**
032     * Creates a new {@link TagTransferData} object for the given objects.
033     * @param tagged The tags to transfer.
034     */
035    public TagTransferData(Collection<? extends Tagged> tagged) {
036        for (Tagged t : tagged) {
037            tags.putAll(t.getKeys());
038        }
039    }
040
041    /**
042     * Create a new {@link TagTransferData} object with the given tags.
043     * @param tags The tags.
044     * @since 10637
045     */
046    public TagTransferData(Map<String, String> tags) {
047        this.tags.putAll(tags);
048    }
049
050    /**
051     * Gets all tags contained in this data.
052     * @return The tags.
053     */
054    public Map<String, String> getTags() {
055        return Collections.unmodifiableMap(tags);
056    }
057}