source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/properties/CopyKeyValueAction.java@ 17032

Last change on this file since 17032 was 17032, checked in by Klumbumbus, 4 years ago

Add missing icons in Tags/Membership Dialog context menu, fix icons of HelpAction and SelectInRelationListAction

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.util.Collection;
8import java.util.Collections;
9import java.util.function.IntFunction;
10import java.util.function.Supplier;
11
12import javax.swing.JTable;
13import javax.swing.event.PopupMenuEvent;
14import javax.swing.event.PopupMenuListener;
15
16import org.openstreetmap.josm.data.osm.Tag;
17import org.openstreetmap.josm.data.osm.Tagged;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20/**
21 * Copy the key and value of the selected tag(s) to clipboard.
22 * @since 13521
23 */
24public class CopyKeyValueAction extends AbstractCopyAction implements PopupMenuListener {
25
26 /**
27 * Constructs a new {@code CopyKeyValueAction}.
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 CopyKeyValueAction(JTable tagTable, IntFunction<String> keyFn, Supplier<Collection<? extends Tagged>> objectSp) {
33 super(tagTable, keyFn, objectSp);
34 setName(0);
35 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tags to clipboard"));
36 new ImageProvider("copy").getResource().attachImageIcon(this, true);
37 }
38
39 private void setName(long n) {
40 putValue(NAME, trn("Copy selected {0} Key/Value", "Copy selected {0} Keys/Values", n, n));
41 }
42
43 @Override
44 protected Collection<String> getString(Tagged p, String key) {
45 String v = p.get(key);
46 return v == null ? null : Collections.singleton(new Tag(key, v).toString());
47 }
48
49 @Override
50 public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
51 setName(valueStream().count());
52 }
53
54 @Override
55 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
56 // Do nothing
57 }
58
59 @Override
60 public void popupMenuCanceled(PopupMenuEvent e) {
61 // Do nothing
62 }
63}
Note: See TracBrowser for help on using the repository browser.