1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.properties;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.KeyEvent;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.LinkedList;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Map.Entry;
|
---|
11 | import java.util.function.IntFunction;
|
---|
12 | import java.util.function.Supplier;
|
---|
13 |
|
---|
14 | import javax.swing.JTable;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
17 | import org.openstreetmap.josm.data.osm.Tagged;
|
---|
18 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
19 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Copy the key and value of all the tags to clipboard.
|
---|
23 | * @since 13521
|
---|
24 | */
|
---|
25 | public class CopyAllKeyValueAction extends AbstractCopyAction {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Constructs a new {@code CopyAllKeyValueAction}.
|
---|
29 | * @param tagTable the tag table
|
---|
30 | * @param keyFn a function which returns the selected key for a given row index
|
---|
31 | * @param objectSp a supplier which returns the selected tagged object(s)
|
---|
32 | */
|
---|
33 | public CopyAllKeyValueAction(JTable tagTable, IntFunction<String> keyFn, Supplier<Collection<? extends Tagged>> objectSp) {
|
---|
34 | super(tagTable, keyFn, objectSp);
|
---|
35 | putValue(NAME, tr("Copy all Keys/Values"));
|
---|
36 | putValue(SHORT_DESCRIPTION, tr("Copy the key and value of all the tags to clipboard"));
|
---|
37 | Shortcut sc = Shortcut.registerShortcut("system:copytags", tr("Edit: {0}", tr("Copy Tags")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
|
---|
38 | MainApplication.registerActionShortcut(this, sc);
|
---|
39 | sc.setAccelerator(this);
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | protected Collection<String> getString(Tagged p, String key) {
|
---|
44 | List<String> r = new LinkedList<>();
|
---|
45 | for (Entry<String, String> kv : p.getKeys().entrySet()) {
|
---|
46 | r.add(new Tag(kv.getKey(), kv.getValue()).toString());
|
---|
47 | }
|
---|
48 | return r;
|
---|
49 | }
|
---|
50 | }
|
---|