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; 007import javax.swing.JComponent; 008 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 017public class StringEditor extends ExtendedDialog { 018 019 PrefEntry entry; 020 JosmTextField tvalue; 021 022 public StringEditor(final JComponent gui, PrefEntry entry, StringSetting setting) { 023 super(gui, tr("Change string setting"), new String[] {tr("OK"), tr("Cancel")}); 024 this.entry = entry; 025 setButtonIcons(new String[] {"ok.png", "cancel.png"}); 026 setContent(build(setting.getValue() == null ? "" : setting.getValue())); 027 } 028 029 public String getData() { 030 return tvalue.getText(); 031 } 032 033 protected JPanel build(String orig) { 034 JPanel p = new JPanel(new GridBagLayout()); 035 p.add(new JLabel(tr("Key: {0}", entry.getKey())), GBC.eol().insets(0,0,5,0)); 036 037 p.add(new JLabel(tr("Value: ")), GBC.std()); 038 tvalue = new JosmTextField(orig, 50); 039 p.add(tvalue, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL)); 040 041 return p; 042 } 043}