001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.dialogs.properties; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.Collection; 007import java.util.Collections; 008import java.util.function.IntFunction; 009import java.util.function.Supplier; 010 011import javax.swing.JTable; 012 013import org.openstreetmap.josm.data.osm.Tagged; 014import org.openstreetmap.josm.tools.ImageProvider; 015 016/** 017 * Copy the value of the selected tag to clipboard. 018 * @since 13521 019 */ 020public class CopyValueAction extends AbstractCopyAction { 021 022 /** 023 * Constructs a new {@code CopyValueAction}. 024 * @param tagTable the tag table 025 * @param keyFn a function which returns the selected key for a given row index 026 * @param objectSp a supplier which returns the selected tagged object(s) 027 */ 028 public CopyValueAction(JTable tagTable, IntFunction<String> keyFn, Supplier<Collection<? extends Tagged>> objectSp) { 029 super(tagTable, keyFn, objectSp); 030 putValue(NAME, tr("Copy Value")); 031 putValue(SHORT_DESCRIPTION, tr("Copy the value of the selected tag to clipboard")); 032 new ImageProvider("copy").getResource().attachImageIcon(this, true); 033 } 034 035 @Override 036 protected Collection<String> getString(Tagged p, String key) { 037 String v = p.get(key); 038 return v == null ? null : Collections.singleton(v); 039 } 040}