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 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 |
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.Collections;
|
---|
9 | import java.util.function.IntFunction;
|
---|
10 | import java.util.function.Supplier;
|
---|
11 |
|
---|
12 | import javax.swing.JTable;
|
---|
13 | import javax.swing.event.PopupMenuEvent;
|
---|
14 | import javax.swing.event.PopupMenuListener;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
17 | import org.openstreetmap.josm.data.osm.Tagged;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Copy the key and value of the selected tag(s) to clipboard.
|
---|
21 | * @since 13521
|
---|
22 | */
|
---|
23 | public class CopyKeyValueAction extends AbstractCopyAction implements PopupMenuListener {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code CopyKeyValueAction}.
|
---|
27 | * @param tagTable the tag table
|
---|
28 | * @param keyFn a function which returns the selected key for a given row index
|
---|
29 | * @param objectSp a supplier which returns the selected tagged object(s)
|
---|
30 | */
|
---|
31 | public CopyKeyValueAction(JTable tagTable, IntFunction<String> keyFn, Supplier<Collection<? extends Tagged>> objectSp) {
|
---|
32 | super(tagTable, keyFn, objectSp);
|
---|
33 | setName(0);
|
---|
34 | putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag(s) to clipboard"));
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void setName(long n) {
|
---|
38 | putValue(NAME, trn("Copy selected {0} Key/Value", "Copy selected {0} Keys/Values", n, n));
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | protected Collection<String> getString(Tagged p, String key) {
|
---|
43 | String v = p.get(key);
|
---|
44 | return v == null ? null : Collections.singleton(new Tag(key, v).toString());
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
---|
49 | setName(valueStream().count());
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
---|
54 | // Do nothing
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void popupMenuCanceled(PopupMenuEvent e) {
|
---|
59 | // Do nothing
|
---|
60 | }
|
---|
61 | }
|
---|