* @return newly created entry or null if adding was cancelled
*/
public PrefEntry addPreference(final JComponent gui) {
JPanel p = new JPanel(new GridBagLayout());
p.add(new JLabel(tr("Key")), GBC.std().insets(0,0,5,0));
JosmTextField tkey = new JosmTextField("", 50);
p.add(tkey, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
p.add(new JLabel(tr("Select Setting Type:")), GBC.eol().insets(5,15,5,0));
JRadioButton rbString = new JRadioButton(tr("Simple"));
JRadioButton rbList = new JRadioButton(tr("List"));
JRadioButton rbListList = new JRadioButton(tr("List of lists"));
JRadioButton rbMapList = new JRadioButton(tr("List of maps"));
ButtonGroup group = new ButtonGroup();
group.add(rbString);
group.add(rbList);
group.add(rbListList);
group.add(rbMapList);
p.add(rbString, GBC.eol());
p.add(rbList, GBC.eol());
p.add(rbListList, GBC.eol());
p.add(rbMapList, GBC.eol());
rbString.setSelected(true);
ExtendedDialog dlg = new ExtendedDialog(gui, tr("Add setting"), new String[] {tr("OK"), tr("Cancel")});
dlg.setButtonIcons(new String[] {"ok.png", "cancel.png"});
dlg.setContent(p);
dlg.showDialog();
PrefEntry pe = null;
boolean ok = false;
if (dlg.getValue() == 1) {
if (rbString.isSelected()) {
StringSetting sSetting = new StringSetting(null);
pe = new PrefEntry(tkey.getText(), sSetting, sSetting, false);
StringEditor sEditor = new StringEditor(gui, pe, sSetting);
sEditor.showDialog();
if (sEditor.getValue() == 1) {
String data = sEditor.getData();
if (!Objects.equals(sSetting.getValue(), data)) {
pe.setValue(new StringSetting(data));
ok = true;
}
}
} else if (rbList.isSelected()) {
ListSetting lSetting = new ListSetting(null);
pe = new PrefEntry(tkey.getText(), lSetting, lSetting, false);
ListEditor lEditor = new ListEditor(gui, pe, lSetting);
lEditor.showDialog();
if (lEditor.getValue() == 1) {
List<String> data = lEditor.getData();
if (!lSetting.equalVal(data)) {
pe.setValue(new ListSetting(data));
ok = true;
}
}
} else if (rbListList.isSelected()) {
ListListSetting llSetting = new ListListSetting(null);
pe = new PrefEntry(tkey.getText(), llSetting, llSetting, false);
ListListEditor llEditor = new ListListEditor(gui, pe, llSetting);
llEditor.showDialog();
if (llEditor.getValue() == 1) {
List<List<String>> data = llEditor.getData();
if (!llSetting.equalVal(data)) {
pe.setValue(new ListListSetting(data));
ok = true;
}
}
} else if (rbMapList.isSelected()) {
MapListSetting mlSetting = new MapListSetting(null);
pe = new PrefEntry(tkey.getText(), mlSetting, mlSetting, false);
MapListEditor mlEditor = new MapListEditor(gui, pe, mlSetting);
mlEditor.showDialog();
if (mlEditor.getValue() == 1) {
List<Map<String, String>> data = mlEditor.getData();
if (!mlSetting.equalVal(data)) {