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;
017
018    /** The context used for translating {@link #text} */
019    public String text_context;
020
021    /** The localized version of {@link #text} */
022    public String locale_text;
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    }
033
034    protected String fieldsToString() {
035        return (text != null ? "text=" + text + ", " : "")
036                + (text_context != null ? "text_context=" + text_context + ", " : "")
037                + (locale_text != null ? "locale_text=" + locale_text : "");
038    }
039
040    @Override
041    public String toString() {
042        return getClass().getSimpleName() + " [" + fieldsToString() + ']';
043    }
044}