001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.tagging.presets.items; 003 004import java.util.List; 005 006import org.openstreetmap.josm.data.osm.Tag; 007import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 008 009/** 010 * A tagging preset item displaying a localizable text. 011 * @since 6190 012 */ 013public abstract class TextItem extends TaggingPresetItem { 014 015 /** The text to display */ 016 public String text; // NOSONAR 017 018 /** The context used for translating {@link #text} */ 019 public String text_context; // NOSONAR 020 021 /** The localized version of {@link #text} */ 022 public String locale_text; // NOSONAR 023 024 protected final void initializeLocaleText(String defaultText) { 025 if (locale_text == null) { 026 locale_text = getLocaleText(text, text_context, defaultText); 027 } 028 } 029 030 @Override 031 public void addCommands(List<Tag> changedTags) { 032 // Do nothing 033 } 034 035 protected String fieldsToString() { 036 return (text != null ? "text=" + text + ", " : "") 037 + (text_context != null ? "text_context=" + text_context + ", " : "") 038 + (locale_text != null ? "locale_text=" + locale_text : ""); 039 } 040 041 @Override 042 public String toString() { 043 return getClass().getSimpleName() + " [" + fieldsToString() + ']'; 044 } 045}