1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.datatransfer.data;
|
---|
3 |
|
---|
4 | import java.awt.datatransfer.DataFlavor;
|
---|
5 | import java.io.Serializable;
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.Collections;
|
---|
8 | import java.util.Map;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.osm.TagMap;
|
---|
11 | import org.openstreetmap.josm.data.osm.Tagged;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * This is a special transfer type that only transfers tag data.
|
---|
15 | * <p>
|
---|
16 | * It contains all tags contained in the selection that was copied. For conflicting tags, any of the values may be used.
|
---|
17 | * @author Michael Zangl
|
---|
18 | * @since 10604
|
---|
19 | */
|
---|
20 | public class TagTransferData implements Serializable {
|
---|
21 |
|
---|
22 | private static final long serialVersionUID = 1;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * This is a data flavor added
|
---|
26 | */
|
---|
27 | public static final DataFlavor FLAVOR = new DataFlavor(TagTransferData.class, "OSM Tags");
|
---|
28 |
|
---|
29 | private final TagMap tags = new TagMap();
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Creates a new {@link TagTransferData} object for the given objects.
|
---|
33 | * @param tagged The tags to transfer.
|
---|
34 | */
|
---|
35 | public TagTransferData(Collection<? extends Tagged> tagged) {
|
---|
36 | for (Tagged t : tagged) {
|
---|
37 | tags.putAll(t.getKeys());
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Create a new {@link TagTransferData} object with the given tags.
|
---|
43 | * @param tags The tags.
|
---|
44 | * @since 10637
|
---|
45 | */
|
---|
46 | public TagTransferData(Map<String, String> tags) {
|
---|
47 | this.tags.putAll(tags);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Gets all tags contained in this data.
|
---|
52 | * @return The tags.
|
---|
53 | */
|
---|
54 | public Map<String, String> getTags() {
|
---|
55 | return Collections.unmodifiableMap(tags);
|
---|
56 | }
|
---|
57 | }
|
---|