001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.tagging.presets.items; 003 004import java.util.Collection; 005import java.util.Collections; 006import java.util.List; 007 008import javax.swing.JPanel; 009 010import org.openstreetmap.josm.data.osm.Tag; 011import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 012 013/** 014 * Invisible type allowing to hardcode an OSM key/value from the preset definition. 015 */ 016public class Key extends KeyedItem { 017 018 /** The hardcoded value for key */ 019 public String value; // NOSONAR 020 021 @Override 022 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) { 023 return false; 024 } 025 026 @Override 027 public void addCommands(List<Tag> changedTags) { 028 changedTags.add(asTag()); 029 } 030 031 /** 032 * Returns the {@link Tag} set by this item 033 * @return the tag 034 */ 035 public Tag asTag() { 036 return new Tag(key, value); 037 } 038 039 @Override 040 public MatchType getDefaultMatch() { 041 return MatchType.KEY_VALUE_REQUIRED; 042 } 043 044 @Override 045 public Collection<String> getValues() { 046 return Collections.singleton(value); 047 } 048 049 @Override 050 public String toString() { 051 return "Key [key=" + key + ", value=" + value + ", text=" + text 052 + ", text_context=" + text_context + ", match=" + match 053 + ']'; 054 } 055}