diff --git a/.classpath b/.classpath
index 5aed12b..bb0e7eb 100644
--- a/.classpath
+++ b/.classpath
@@ -17,7 +17,7 @@
-
+
diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java
index d52bdfe..b2df8c6 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPreferences.java
@@ -1,3 +1,4 @@
+// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai;
import static org.openstreetmap.josm.tools.I18n.tr;
diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIURLPreferenceTable.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIURLPreferenceTable.java
index 6a73c25..2653788 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIURLPreferenceTable.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIURLPreferenceTable.java
@@ -4,15 +4,12 @@ package org.openstreetmap.josm.plugins.mapwithai;
import static org.openstreetmap.josm.tools.I18n.tr;
import java.awt.Component;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import java.util.TreeMap;
import java.util.stream.Collectors;
@@ -20,30 +17,19 @@ import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
-import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.JComponent;
-import javax.swing.JLabel;
import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
-import org.openstreetmap.josm.gui.ExtendedDialog;
-import org.openstreetmap.josm.gui.preferences.advanced.ListEditor;
-import org.openstreetmap.josm.gui.preferences.advanced.ListListEditor;
import org.openstreetmap.josm.gui.preferences.advanced.MapListEditor;
import org.openstreetmap.josm.gui.preferences.advanced.PrefEntry;
-import org.openstreetmap.josm.gui.preferences.advanced.StringEditor;
import org.openstreetmap.josm.gui.widgets.JosmTextField;
import org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation.DataUrl;
-import org.openstreetmap.josm.spi.preferences.ListListSetting;
-import org.openstreetmap.josm.spi.preferences.ListSetting;
import org.openstreetmap.josm.spi.preferences.MapListSetting;
import org.openstreetmap.josm.spi.preferences.Setting;
import org.openstreetmap.josm.spi.preferences.StringSetting;
-import org.openstreetmap.josm.tools.GBC;
/**
* Component for editing list of preferences as a table.
@@ -136,10 +122,6 @@ public class MapWithAIURLPreferenceTable extends JTable {
if (editor != null) {
editor.requestFocus();
}
- } else if (stg instanceof ListSetting) {
- ok = doEditList(gui, (PrefEntry) e, (ListSetting) stg);
- } else if (stg instanceof ListListSetting) {
- ok = doEditListList(gui, (PrefEntry) e, (ListListSetting) stg);
} else if (stg instanceof MapListSetting) {
PrefEntry pref = e instanceof PrefEntry ? (PrefEntry) e : new PrefEntry("Parameters", stg, stg, false);
ok = doEditMapList(gui, pref, (MapListSetting) stg);
@@ -154,7 +136,15 @@ public class MapWithAIURLPreferenceTable extends JTable {
return ok;
}
- private static Map objectify(Map map) {
+ /**
+ * Convert a map of Map<String, String> to a map of Map<String,
+ * Object>
+ *
+ * @param map The map of strings to strings to convert (e.g., "1"->int 1, "true"
+ * -> boolean true, etc)
+ * @return A converted map
+ */
+ public static Map objectify(Map map) {
Map returnMap = new TreeMap<>();
for (Entry entry : map.entrySet()) {
Object obj = null;
@@ -176,32 +166,6 @@ public class MapWithAIURLPreferenceTable extends JTable {
return returnMap;
}
- private static boolean doEditList(final JComponent gui, final PrefEntry e, ListSetting lSetting) {
- ListEditor lEditor = new ListEditor(gui, e, lSetting);
- lEditor.showDialog();
- if (lEditor.getValue() == 1) {
- List data = lEditor.getData();
- if (!lSetting.equalVal(data)) {
- e.setValue(new ListSetting(data));
- return true;
- }
- }
- return false;
- }
-
- private static boolean doEditListList(final JComponent gui, final PrefEntry e, ListListSetting llSetting) {
- ListListEditor llEditor = new ListListEditor(gui, e, llSetting);
- llEditor.showDialog();
- if (llEditor.getValue() == 1) {
- List> data = llEditor.getData();
- if (!llSetting.equalVal(data)) {
- e.setValue(new ListListSetting(data));
- return true;
- }
- }
- return false;
- }
-
private static boolean doEditMapList(final JComponent gui, final PrefEntry e, MapListSetting mlSetting) {
MapListEditor mlEditor = new MapListEditor(gui, e, mlSetting);
mlEditor.showDialog();
@@ -215,139 +179,6 @@ public class MapWithAIURLPreferenceTable extends JTable {
return false;
}
- /**
- * Add new preference to the table
- * @param gui - parent component for asking dialogs
- * @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(GridBagConstraints.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);
-
- PrefEntry pe = null;
- boolean ok = false;
- if (askAddSetting(gui, p)) {
- if (rbString.isSelected()) {
- StringSetting sSetting = new StringSetting(null);
- pe = new PrefEntry(tkey.getText(), sSetting, sSetting, false);
- ok = doAddSimple(gui, pe, sSetting);
- } else if (rbList.isSelected()) {
- ListSetting lSetting = new ListSetting(null);
- pe = new PrefEntry(tkey.getText(), lSetting, lSetting, false);
- ok = doAddList(gui, pe, lSetting);
- } else if (rbListList.isSelected()) {
- ListListSetting llSetting = new ListListSetting(null);
- pe = new PrefEntry(tkey.getText(), llSetting, llSetting, false);
- ok = doAddListList(gui, pe, llSetting);
- } else if (rbMapList.isSelected()) {
- MapListSetting mlSetting = new MapListSetting(null);
- pe = new PrefEntry(tkey.getText(), mlSetting, mlSetting, false);
- ok = doAddMapList(gui, pe, mlSetting);
- }
- }
- return ok ? pe : null;
- }
-
- private static boolean askAddSetting(JComponent gui, JPanel p) {
- return new ExtendedDialog(gui, tr("Add setting"), tr("OK"), tr("Cancel"))
- .setContent(p).setButtonIcons("ok", "cancel").showDialog().getValue() == 1;
- }
-
- private static boolean doAddSimple(final JComponent gui, PrefEntry pe, StringSetting sSetting) {
- 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));
- return true;
- }
- }
- return false;
- }
-
- private static boolean doAddList(final JComponent gui, PrefEntry pe, ListSetting lSetting) {
- ListEditor lEditor = new ListEditor(gui, pe, lSetting);
- lEditor.showDialog();
- if (lEditor.getValue() == 1) {
- List data = lEditor.getData();
- if (!lSetting.equalVal(data)) {
- pe.setValue(new ListSetting(data));
- return true;
- }
- }
- return false;
- }
-
- private static boolean doAddListList(final JComponent gui, PrefEntry pe, ListListSetting llSetting) {
- ListListEditor llEditor = new ListListEditor(gui, pe, llSetting);
- llEditor.showDialog();
- if (llEditor.getValue() == 1) {
- List> data = llEditor.getData();
- if (!llSetting.equalVal(data)) {
- pe.setValue(new ListListSetting(data));
- return true;
- }
- }
- return false;
- }
-
- private static boolean doAddMapList(final JComponent gui, PrefEntry pe, MapListSetting mlSetting) {
- MapListEditor mlEditor = new MapListEditor(gui, pe, mlSetting);
- mlEditor.showDialog();
- if (mlEditor.getValue() == 1) {
- List