Index: trunk/src/org/openstreetmap/josm/data/Preferences.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 3530)
+++ trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 3531)
@@ -601,13 +601,10 @@
     synchronized private void putCollectionDefault(String key, Collection<String> val) {
         String s = null;
-        if(val != null)
+        for(String a : val)
         {
-            for(String a : val)
-            {
-                if(s != null) {
-                    s += "\u001e" + a;
-                } else {
-                    s = a;
-                }
+            if(s != null) {
+                s += "\u001e" + a;
+            } else {
+                s = a;
             }
         }
@@ -616,31 +613,18 @@
     synchronized public Collection<Collection<String>> getArray(String key,
     Collection<Collection<String>> def) {
-        if(def != null) {
-            for(String k : getAllPrefixDefault(key + ".").keySet())
-                put(k, null);
-            int num = 0;
-            for(Collection<String> c : def)
-                putCollectionDefault(key+"."+num++, c);
-        }
-        String s = get(key+".0");
-        if(s != null && s.length() != 0)
-        {
-            Collection<Collection<String>> col = new LinkedList<Collection<String>>();
-            for(int num = 0; ; ++num) {
-                Collection<String> c = getCollection(key+"."+num, null);
-                if(c == null)
-                    break;
-                col.add(c);
-            }
-            return col;
-        }
-        return def;
+        if(def != null)
+            putArrayDefault(key, def);
+        key += ".";
+        int num = 0;
+        Collection<Collection<String>> col = new LinkedList<Collection<String>>();
+        while(properties.containsKey(key+num))
+            col.add(getCollection(key+num++, null));
+        return num == 0 && def != null ? def : col;
     }
     synchronized public boolean putArray(String key, Collection<Collection<String>> val) {
         boolean res = true;
+        key += ".";
         Collection<String> keys = getAllPrefix(key).keySet();
-        key += ".";
         if(val != null) {
-            String s = null;
             int num = 0;
             for(Collection<String> c : val) {
@@ -661,4 +645,22 @@
     }
 
+    synchronized private void putArrayDefault(String key, Collection<Collection<String>> val) {
+        key += ".";
+        Collection<String> keys = getAllPrefixDefault(key).keySet();
+        int num = 0;
+        for(Collection<String> c : val) {
+            keys.remove(key+num);
+            putCollectionDefault(key+num++, c);
+        }
+        int l = key.length();
+        for(String k : keys) {
+            try {
+              Integer.valueOf(k.substring(l));
+              defaults.remove(k);
+            } catch(Exception e) {
+            }
+        }
+    }
+
     /**
      * Updates system properties with the current values in the preferences.
Index: trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java	(revision 3530)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java	(revision 3531)
@@ -216,4 +216,29 @@
     }
 
+    private void removePreference(final PreferenceTabbedPane gui, final JTable list) {
+        if (list.getSelectedRowCount() == 0) {
+            JOptionPane.showMessageDialog(
+                    gui,
+                    tr("Please select the row to delete."),
+                    tr("Warning"),
+                    JOptionPane.WARNING_MESSAGE
+            );
+            return;
+        }
+        for(int row: list.getSelectedRows()) {
+            data.put((String) model.getValueAt(row, 0), "");
+            model.setValueAt("", row, 1);
+        }
+    }
+
+    private void addPreference(final PreferenceTabbedPane gui) {
+        String s[] = showEditDialog(gui, tr("Enter a new key/value pair"),
+            null, null);
+        if(s != null && !s[0].isEmpty() && !s[1].isEmpty()) {
+            data.put(s[0], s[1]);
+            dataToModel();
+        }
+    }
+
     private void editPreference(final PreferenceTabbedPane gui, final JTable list) {
         if (list.getSelectedRowCount() != 1) {
@@ -226,53 +251,38 @@
             return;
         }
-        String v = (String) JOptionPane.showInputDialog(
-                Main.parent,
-                tr("New value for {0}", model.getValueAt(list.getSelectedRow(), 0)),
-                tr("New value"),
-                JOptionPane.QUESTION_MESSAGE,
-                null,
-                null,
-                model.getValueAt(list.getSelectedRow(), 1)
-        );
-        if (v != null) {
-            data.put((String) model.getValueAt(list.getSelectedRow(), 0), v);
-            model.setValueAt(v, list.getSelectedRow(), 1);
-        }
-    }
-
-    private void removePreference(final PreferenceTabbedPane gui, final JTable list) {
-        if (list.getSelectedRowCount() == 0) {
-            JOptionPane.showMessageDialog(
-                    gui,
-                    tr("Please select the row to delete."),
-                    tr("Warning"),
-                    JOptionPane.WARNING_MESSAGE
-            );
-            return;
-        }
-        for(int row: list.getSelectedRows()) {
-            data.put((String) model.getValueAt(row, 0), "");
-            model.setValueAt("", row, 1);
-        }
-    }
-
-    private void addPreference(final PreferenceTabbedPane gui) {
+        String key = (String)model.getValueAt(list.getSelectedRow(), 0);
+        String value = data.get(key);
+        if(value.isEmpty())
+            value = defaults.get(key);
+        String s[] = showEditDialog(gui, tr("Change a key/value pair"),
+            key, value);
+        if(s != null && !s[0].isEmpty()) {
+            data.put(s[0], s[1]);
+            if(!s[0].equals(key))
+                data.put(key,"");
+            dataToModel();
+        }
+    }
+
+    private String[] showEditDialog(final PreferenceTabbedPane gui, String title,
+    String key, String value) {
         JPanel p = new JPanel(new GridBagLayout());
         p.add(new JLabel(tr("Key")), GBC.std().insets(0,0,5,0));
-        JTextField key = new JTextField(10);
-        JTextField value = new JTextField(10);
-        p.add(key, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
+        JTextField tkey = new JTextField(key, 50);
+        JTextField tvalue = new JTextField(value, 50);
+        p.add(tkey, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
         p.add(new JLabel(tr("Value")), GBC.std().insets(0,0,5,0));
-        p.add(value, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL));
+        /* TODO: Split value at "\u001e" and present a table with automatic added lines */
+        p.add(tvalue, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL));
         int answer = JOptionPane.showConfirmDialog(
                 gui, p,
-                tr("Enter a new key/value pair"),
+                title,
                 JOptionPane.OK_CANCEL_OPTION,
                 JOptionPane.PLAIN_MESSAGE
         );
-        if (answer == JOptionPane.OK_OPTION) {
-            data.put(key.getText(), value.getText());
-            model.addRow(new String[]{key.getText(), value.getText()});
-        }
+        if(answer == JOptionPane.OK_OPTION) {
+            return new String[]{tkey.getText(), tvalue.getText()};
+        }
+        return null;
     }
 }
