001// License: GPL. See LICENSE file for details.
002package org.openstreetmap.josm.gui.preferences.advanced;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.GridBagLayout;
007
008import javax.swing.JComponent;
009import javax.swing.JLabel;
010import javax.swing.JPanel;
011
012import org.openstreetmap.josm.data.Preferences.StringSetting;
013import org.openstreetmap.josm.gui.ExtendedDialog;
014import org.openstreetmap.josm.gui.widgets.JosmTextField;
015import org.openstreetmap.josm.tools.GBC;
016
017/**
018 * Editor for String preference entries.
019 */
020public class StringEditor extends ExtendedDialog {
021
022    PrefEntry entry;
023    JosmTextField tvalue;
024
025    /**
026     * Constructs a new {@code StringEditor}.
027     * @param gui The parent component
028     */
029    public StringEditor(final JComponent gui, PrefEntry entry, StringSetting setting) {
030        super(gui, tr("Change string setting"), new String[] {tr("OK"), tr("Cancel")});
031        this.entry = entry;
032        setButtonIcons(new String[] {"ok.png", "cancel.png"});
033        setContent(build(setting.getValue() == null ? "" : setting.getValue()));
034    }
035
036    /**
037     * Returns the data.
038     * @return the preference data
039     */
040    public String getData() {
041        return tvalue.getText();
042    }
043
044    protected final JPanel build(String orig) {
045        JPanel p = new JPanel(new GridBagLayout());
046        p.add(new JLabel(tr("Key: {0}", entry.getKey())), GBC.eol().insets(0,0,5,0));
047
048        p.add(new JLabel(tr("Value: ")), GBC.std());
049        tvalue = new JosmTextField(orig, 50);
050        p.add(tvalue, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
051
052        return p;
053    }
054}