Index: trunk/src/org/openstreetmap/josm/data/Preferences.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 3525)
+++ trunk/src/org/openstreetmap/josm/data/Preferences.java	(revision 3527)
@@ -84,46 +84,4 @@
     }
 
-    /**
-     * Class holding one bookmarkentry.
-     * @author imi
-     */
-    public static class Bookmark implements Comparable<Bookmark> {
-        private String name;
-        private Bounds area;
-
-        public Bookmark() {
-            area = null;
-            name = null;
-        }
-
-        public Bookmark(Bounds area) {
-            this.area = area;
-        }
-
-        @Override public String toString() {
-            return name;
-        }
-
-        public int compareTo(Bookmark b) {
-            return name.toLowerCase().compareTo(b.name.toLowerCase());
-        }
-
-        public Bounds getArea() {
-            return area;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public void setName(String name) {
-            this.name = name;
-        }
-
-        public void setArea(Bounds area) {
-            this.area = area;
-        }
-    }
-
     public interface ColorKey {
         String getColorName();
@@ -275,4 +233,13 @@
                     all.put(e.getKey(), e.getValue());
                 }
+        return all;
+    }
+
+    synchronized private Map<String, String> getAllPrefixDefault(final String prefix) {
+        final Map<String,String> all = new TreeMap<String,String>();
+        for (final Entry<String,String> e : defaults.entrySet())
+            if (e.getKey().startsWith(prefix)) {
+                all.put(e.getKey(), e.getValue());
+            }
         return all;
     }
@@ -531,63 +498,4 @@
     }
 
-    /* TODO: Bookmarks should be stored in preferences */
-    public File getBookmarksFile() {
-        return new File(getPreferencesDir(),"bookmarks");
-    }
-
-    public Collection<Bookmark> loadBookmarks() throws IOException {
-        File bookmarkFile = getBookmarksFile();
-        if (!bookmarkFile.exists()) {
-            bookmarkFile.createNewFile();
-        }
-        BufferedReader in = new BufferedReader(new InputStreamReader(
-                new FileInputStream(bookmarkFile), "utf-8"));
-
-        LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
-        for (String line = in.readLine(); line != null; line = in.readLine()) {
-            // FIXME: legacy code using ',' sign, should be \u001e only
-            Matcher m = Pattern.compile("^(.+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)$").matcher(line);
-            if (!m.matches() || m.groupCount() != 5) {
-                System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark file ''{1}''",line, bookmarkFile.toString()));
-                continue;
-            }
-            Bookmark b = new Bookmark();
-            b.setName(m.group(1));
-            double[] values= new double[4];
-            for (int i = 0; i < 4; ++i) {
-                try {
-                    values[i] = Double.parseDouble(m.group(i+2));
-                } catch(NumberFormatException e) {
-                    System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark file ''{2}''",m.group(i+2),line, bookmarkFile.toString()));
-                    continue;
-                }
-            }
-            b.setArea(new Bounds(values));
-            bookmarks.add(b);
-        }
-        in.close();
-        Collections.sort(bookmarks);
-        return bookmarks;
-    }
-
-    public void saveBookmarks(Collection<Bookmark> bookmarks) throws IOException {
-        File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks");
-        if (!bookmarkFile.exists()) {
-            bookmarkFile.createNewFile();
-        }
-        PrintWriter out = new PrintWriter(new OutputStreamWriter(
-                new FileOutputStream(bookmarkFile), "utf-8"));
-        for (Bookmark b : bookmarks) {
-            out.print(b.getName()+ "\u001e");
-            Bounds area = b.getArea();
-            out.print(area.getMin().lat() +"\u001e");
-            out.print(area.getMin().lon() +"\u001e");
-            out.print(area.getMax().lat() +"\u001e");
-            out.print(area.getMax().lon());
-            out.println();
-        }
-        out.close();
-    }
-
     /**
      * Convenience method for accessing colour preferences.
@@ -702,16 +610,5 @@
         String s = get(key);
         if(def != null)
-        {
-            String d = null;
-            for(String a : def)
-            {
-                if(d != null) {
-                    d += "\u001e" + a;
-                } else {
-                    d = a;
-                }
-            }
-            putDefault(key, d);
-        }
+            putCollectionDefault(key, def);
         if(s != null && s.length() != 0)
             return Arrays.asList(s.split("\u001e"));
@@ -738,4 +635,56 @@
         return put(key, s);
     }
+    synchronized private void putCollectionDefault(String key, Collection<String> val) {
+        String s = null;
+        if(val != null)
+        {
+            for(String a : val)
+            {
+                if(s != null) {
+                    s += "\u001e" + a;
+                } else {
+                    s = a;
+                }
+            }
+        }
+        putDefault(key, s);
+    }
+    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;
+    }
+    synchronized public boolean putArray(String key, Collection<Collection<String>> val) {
+        boolean res = true;
+        for(String k : getAllPrefix(key + ".").keySet())
+            put(k, null);
+        if(val != null) {
+            String s = null;
+            int num = 0;
+            for(Collection<String> c : val) {
+                if(!putCollection(key+"."+num++, c))
+                    res = false;
+            }
+        }
+        return res;
+    }
 
     /**
Index: trunk/src/org/openstreetmap/josm/gui/BookmarkList.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/BookmarkList.java	(revision 3525)
+++ trunk/src/org/openstreetmap/josm/gui/BookmarkList.java	(revision 3527)
@@ -6,6 +6,18 @@
 import java.awt.Component;
 import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.swing.DefaultListModel;
@@ -19,6 +31,4 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.Preferences;
-import org.openstreetmap.josm.data.Preferences.Bookmark;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -30,4 +40,55 @@
 
     /**
+     * Class holding one bookmarkentry.
+     * @author imi
+     */
+    public static class Bookmark implements Comparable<Bookmark> {
+        private String name;
+        private Bounds area;
+
+        public Bookmark(Collection<String> list) throws NumberFormatException, IllegalArgumentException {
+            ArrayList<String> array = new ArrayList<String>(list);
+            if(array.size() < 5)
+                throw new IllegalArgumentException(tr("Wrong number of arguments for bookmark"));
+            name = array.get(0);
+            area = new Bounds(Double.parseDouble(array.get(1)), Double.parseDouble(array.get(2)),
+                              Double.parseDouble(array.get(3)), Double.parseDouble(array.get(4)));
+        }
+
+        public Bookmark() {
+            area = null;
+            name = null;
+        }
+
+        public Bookmark(Bounds area) {
+            this.area = area;
+        }
+
+        @Override public String toString() {
+            return name;
+        }
+
+        public int compareTo(Bookmark b) {
+            return name.toLowerCase().compareTo(b.name.toLowerCase());
+        }
+
+        public Bounds getArea() {
+            return area;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public void setArea(Bounds area) {
+            this.area = area;
+        }
+    }
+
+    /**
      * Create a bookmark list as well as the Buttons add and remove.
      */
@@ -45,19 +106,70 @@
         DefaultListModel model = (DefaultListModel)getModel();
         model.removeAllElements();
-        try {
-            for (Preferences.Bookmark b : Main.pref.loadBookmarks()) {
+        Collection<Collection<String>> args = Main.pref.getArray("bookmarks", null);
+        if(args != null) {
+            LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
+            for(Collection<String> entry : args) {
+                try {
+                    bookmarks.add(new Bookmark(entry));
+                }
+                catch(Exception e) {
+                    System.err.println(tr("Error reading bookmark entry: %s", e.getMessage()));
+                }
+            }
+            Collections.sort(bookmarks);
+            for (Bookmark b : bookmarks) {
                 model.addElement(b);
             }
-        } catch (IOException e) {
-            e.printStackTrace();
-            JOptionPane.showMessageDialog(
-                    Main.parent,
-                    tr("<html>Could not read bookmarks from<br>''{0}''<br>Error was: {1}</html>",
-                            Main.pref.getBookmarksFile(),
-                            e.getMessage()
-                    ),
-                    tr("Error"),
-                    JOptionPane.ERROR_MESSAGE
-            );
+        }
+        else if(!Main.applet) { /* FIXME: remove else clause after spring 2011 */
+            File bookmarkFile = new File(Main.pref.getPreferencesDir(),"bookmarks");
+            try {
+                LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
+                if (bookmarkFile.exists()) {
+                    System.out.println("Try loading obsolete bookmarks file");
+                    BufferedReader in = new BufferedReader(new InputStreamReader(
+                            new FileInputStream(bookmarkFile), "utf-8"));
+
+                    for (String line = in.readLine(); line != null; line = in.readLine()) {
+                        Matcher m = Pattern.compile("^(.+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)$").matcher(line);
+                        if (!m.matches() || m.groupCount() != 5) {
+                            System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark file ''{1}''",line, bookmarkFile.toString()));
+                            continue;
+                        }
+                        Bookmark b = new Bookmark();
+                        b.setName(m.group(1));
+                        double[] values= new double[4];
+                        for (int i = 0; i < 4; ++i) {
+                            try {
+                                values[i] = Double.parseDouble(m.group(i+2));
+                            } catch(NumberFormatException e) {
+                                System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark file ''{2}''",m.group(i+2),line, bookmarkFile.toString()));
+                                continue;
+                            }
+                        }
+                        b.setArea(new Bounds(values));
+                        bookmarks.add(b);
+                    }
+                    in.close();
+                    Collections.sort(bookmarks);
+                    for (Bookmark b : bookmarks) {
+                        model.addElement(b);
+                    }
+                    save();
+                    System.out.println("Removing obsolete bookmarks file");
+                    bookmarkFile.delete();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+                JOptionPane.showMessageDialog(
+                        Main.parent,
+                        tr("<html>Could not read bookmarks from<br>''{0}''<br>Error was: {1}</html>",
+                                bookmarkFile.toString(),
+                                e.getMessage()
+                        ),
+                        tr("Error"),
+                        JOptionPane.ERROR_MESSAGE
+                );
+            }
         }
     }
@@ -67,18 +179,17 @@
      */
     public void save() {
-        try {
-            Collection<Preferences.Bookmark> bookmarks = new LinkedList<Preferences.Bookmark>();
-            for (Object o : ((DefaultListModel)getModel()).toArray()) {
-                bookmarks.add((Preferences.Bookmark)o);
-            }
-            Main.pref.saveBookmarks(bookmarks);
-        } catch (IOException e) {
-            JOptionPane.showMessageDialog(
-                    Main.parent,
-                    tr("<html>Could not write bookmark.<br>{0}</html>", e.getMessage()),
-                    tr("Error"),
-                    JOptionPane.ERROR_MESSAGE
-            );
-        }
+        LinkedList<Collection<String>> coll = new LinkedList<Collection<String>>();
+        for (Object o : ((DefaultListModel)getModel()).toArray()) {
+            String[] array = new String[5];
+            Bookmark b = (Bookmark)o;
+            array[0] = b.getName();
+            Bounds area = b.getArea();
+            array[1] = String.valueOf(area.getMin().lat());
+            array[2] = String.valueOf(area.getMin().lon());
+            array[3] = String.valueOf(area.getMax().lat());
+            array[4] = String.valueOf(area.getMax().lon());
+            coll.add(Arrays.asList(array));
+        }
+        Main.pref.putArray("bookmarks", coll);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java	(revision 3525)
+++ trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java	(revision 3527)
@@ -25,7 +25,7 @@
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.Preferences;
-import org.openstreetmap.josm.data.Preferences.Bookmark;
 import org.openstreetmap.josm.data.coor.CoordinateFormat;
 import org.openstreetmap.josm.gui.BookmarkList;
+import org.openstreetmap.josm.gui.BookmarkList.Bookmark;
 import org.openstreetmap.josm.gui.JMultilineLabel;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -114,5 +114,5 @@
         bookmarks.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
             public void valueChanged(ListSelectionEvent e) {
-                Preferences.Bookmark b = (Preferences.Bookmark)bookmarks.getSelectedValue();
+                Bookmark b = (Bookmark)bookmarks.getSelectedValue();
                 if (b != null) {
                     gui.boundingBoxChanged(b.getArea(),BookmarkSelection.this);
