| 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.function.IntFunction;
|
|---|
| 9 | import java.util.function.Supplier;
|
|---|
| 10 | import java.util.stream.Collectors;
|
|---|
| 11 |
|
|---|
| 12 | import javax.swing.JTable;
|
|---|
| 13 |
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.Tag;
|
|---|
| 15 | import org.openstreetmap.josm.data.osm.Tagged;
|
|---|
| 16 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 17 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 18 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 19 |
|
|---|
| 20 | /**
|
|---|
| 21 | * Copy the key and value of all the tags to clipboard.
|
|---|
| 22 | * @since 13521
|
|---|
| 23 | */
|
|---|
| 24 | public class CopyAllKeyValueAction extends AbstractCopyAction {
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * Constructs a new {@code CopyAllKeyValueAction}.
|
|---|
| 28 | * @param tagTable the tag table
|
|---|
| 29 | * @param keyFn a function which returns the selected key for a given row index
|
|---|
| 30 | * @param objectSp a supplier which returns the selected tagged object(s)
|
|---|
| 31 | */
|
|---|
| 32 | public CopyAllKeyValueAction(JTable tagTable, IntFunction<String> keyFn, Supplier<Collection<? extends Tagged>> objectSp) {
|
|---|
| 33 | super(tagTable, keyFn, objectSp);
|
|---|
| 34 | putValue(NAME, tr("Copy all Keys/Values"));
|
|---|
| 35 | putValue(SHORT_DESCRIPTION, tr("Copy the key and value of all the tags to clipboard"));
|
|---|
| 36 | new ImageProvider("copy").getResource().attachImageIcon(this, true);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * Registers this action shortcut
|
|---|
| 41 | * @return this instance, for easy chaining
|
|---|
| 42 | */
|
|---|
| 43 | CopyAllKeyValueAction registerShortcut() {
|
|---|
| 44 | Shortcut sc = Shortcut.registerShortcut("system:copytags", tr("Edit: {0}", tr("Copy Tags")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
|
|---|
| 45 | MainApplication.registerActionShortcut(this, sc);
|
|---|
| 46 | sc.setAccelerator(this);
|
|---|
| 47 | return this;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | @Override
|
|---|
| 51 | protected Collection<String> getString(Tagged p, String key) {
|
|---|
| 52 | return p.getKeys().entrySet().stream()
|
|---|
| 53 | .map(kv -> new Tag(kv.getKey(), kv.getValue()).toString())
|
|---|
| 54 | .collect(Collectors.toList());
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|