[tiled] r580 - in branches/bjorn: . src/tiled/core src/tiled/io src/tiled/io/xml src/tiled/mapeditor src/tiled/mapeditor/dialogs src/tiled/mapeditor/plugin src/tiled/mapeditor/resources src/tiled/mapeditor/selection src/tiled/mapeditor/undo src/tiled/mapeditor/util src/tiled/mapeditor/widget src/tiled/util src/tiled/view

svn@biggeruniverse.com svn at biggeruniverse.com
Sat Feb 11 18:50:46 PST 2006


Author: bjorn
Date: 2006-02-11 20:50:45 -0600 (Sat, 11 Feb 2006)
New Revision: 580

Modified:
   branches/bjorn/CHANGES
   branches/bjorn/src/tiled/core/LayerLockedException.java
   branches/bjorn/src/tiled/io/MapHelper.java
   branches/bjorn/src/tiled/io/xml/XMLMapWriter.java
   branches/bjorn/src/tiled/io/xml/XMLWriter.java
   branches/bjorn/src/tiled/mapeditor/MapEditor.java
   branches/bjorn/src/tiled/mapeditor/Resources.java
   branches/bjorn/src/tiled/mapeditor/dialogs/BrushDialog.java
   branches/bjorn/src/tiled/mapeditor/dialogs/ConfigurationDialog.java
   branches/bjorn/src/tiled/mapeditor/dialogs/NewMapDialog.java
   branches/bjorn/src/tiled/mapeditor/plugin/PluginClassLoader.java
   branches/bjorn/src/tiled/mapeditor/resources/gui.properties
   branches/bjorn/src/tiled/mapeditor/selection/SelectionLayer.java
   branches/bjorn/src/tiled/mapeditor/undo/UndoStack.java
   branches/bjorn/src/tiled/mapeditor/util/LayerTableModel.java
   branches/bjorn/src/tiled/mapeditor/util/TiledFileFilter.java
   branches/bjorn/src/tiled/mapeditor/widget/TileButton.java
   branches/bjorn/src/tiled/util/TiledConfiguration.java
   branches/bjorn/src/tiled/view/MapView.java
Log:
Rewrote TiledConfiguration, which is now a helper class on top of Preferences instead of a custom preferences handler.

Modified: branches/bjorn/CHANGES
===================================================================
--- branches/bjorn/CHANGES	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/CHANGES	2006-02-12 02:50:45 UTC (rev 580)
@@ -1,13 +1,19 @@
-0.5.2 - TBD (+ means planned change)
+0.5.2 - TBD
 
+* Made a start with internationalization
+* Rewrote configuration based on the Preferences class, no more tiled.conf
+* Fixed a bug when exporting a tileset with an external image
+* Fixed two cases of hanging when using the fill tool
+* Fixed loading of layer visibility attribute
+
+Planned changes
 + Added the Shifted view, which emulates several tiling configurations
 + Added "stamp" tool
 + Added ability to select multiple layers from layer table
 + Added the ability to merge tile images when layers are merged
 + Fixed memory problems when loading several maps with many tilesets in a row
-* Fixed a bug when exporting a tileset with an external image
-* Fixed two cases of hanging when using the fill tool
-* Fixed loading of layer visibility attribute
++ Fixed NullPointerException when saving without specifying an extention
++ Localizations to Dutch and German
 
 0.5.1 - June 15th, 2005
 

Modified: branches/bjorn/src/tiled/core/LayerLockedException.java
===================================================================
--- branches/bjorn/src/tiled/core/LayerLockedException.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/core/LayerLockedException.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -1,3 +1,15 @@
+/*
+ *  Tiled Map Editor, (c) 2004-2006
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  Adam Turk <aturk at biggeruniverse.com>
+ *  Bjorn Lindeijer <b.lindeijer at xs4all.nl>
+ */
+
 package tiled.core;
 
 /**

Modified: branches/bjorn/src/tiled/io/MapHelper.java
===================================================================
--- branches/bjorn/src/tiled/io/MapHelper.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/io/MapHelper.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -15,6 +15,7 @@
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.Stack;
+import java.util.prefs.Preferences;
 
 import javax.swing.JOptionPane;
 
@@ -214,11 +215,11 @@
      *          had for the user
      */
     private static void reportPluginMessages(Stack s) {
-        // TODO: maybe have a nice dialog with a scrollbar, in case there are a
-        // lot of messages...
-        TiledConfiguration config = TiledConfiguration.getInstance();
+        // TODO: maybe have a nice dialog with a scrollbar, in case there are
+        // a lot of messages...
+        Preferences prefs = TiledConfiguration.node("io");
 
-        if (config.keyHasValue("tiled.report.io", 1)) {
+        if (prefs.getBoolean("reportWarnings", false)) {
             if (!s.isEmpty()) {
                 Iterator itr = s.iterator();
                 StringBuffer warnings = new StringBuffer();

Modified: branches/bjorn/src/tiled/io/xml/XMLMapWriter.java
===================================================================
--- branches/bjorn/src/tiled/io/xml/XMLMapWriter.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/io/xml/XMLMapWriter.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -21,6 +21,7 @@
 import java.util.Properties;
 import java.util.Stack;
 import java.util.Vector;
+import java.util.prefs.Preferences;
 import java.util.zip.GZIPOutputStream;
 
 import tiled.core.*;
@@ -33,6 +34,8 @@
  */
 public class XMLMapWriter implements MapWriter
 {
+    private static final int LAST_BYTE = 0x000000FF;
+
     /**
      * Saves a map to an XML file.
      *
@@ -99,7 +102,7 @@
         writer.flush();
     }
 
-    private void writeMap(Map map, XMLWriter w, String wp) throws IOException {
+    private static void writeMap(Map map, XMLWriter w, String wp) throws IOException {
         try {
             w.startElement("map");
 
@@ -118,10 +121,10 @@
                     w.writeAttribute("orientation", "shifted"); break;
             }
 
-            w.writeAttribute("width", "" + map.getWidth());
-            w.writeAttribute("height", "" + map.getHeight());
-            w.writeAttribute("tilewidth", "" + map.getTileWidth());
-            w.writeAttribute("tileheight", "" + map.getTileHeight());
+            w.writeAttribute("width", map.getWidth());
+            w.writeAttribute("height", map.getHeight());
+            w.writeAttribute("tilewidth", map.getTileWidth());
+            w.writeAttribute("tileheight", map.getTileHeight());
 
             Properties props = map.getProperties();
             for (Enumeration keys = props.keys(); keys.hasMoreElements();) {
@@ -158,7 +161,7 @@
      * degenerate case where the tileset is not stored in an external file,
      * writes the contents of the tileset instead.
      */
-    private void writeTilesetReference(TileSet set, XMLWriter w, String wp)
+    private static void writeTilesetReference(TileSet set, XMLWriter w, String wp)
         throws IOException {
 
         try {
@@ -169,7 +172,7 @@
             } else {
                 w.startElement("tileset");
                 try {
-                    w.writeAttribute("firstgid", "" + set.getFirstGid());
+                    w.writeAttribute("firstgid", set.getFirstGid());
                     w.writeAttribute("source", source.substring(
                                 source.lastIndexOf(File.separatorChar) + 1));
                     if (set.getBaseDir() != null) {
@@ -184,7 +187,7 @@
         } 
     }
 
-    private void writeTileset(TileSet set, XMLWriter w, String wp)
+    private static void writeTileset(TileSet set, XMLWriter w, String wp)
         throws IOException {
 
         try {
@@ -197,11 +200,11 @@
                 w.writeAttribute("name", name);
             }
 
-            w.writeAttribute("firstgid", "" + set.getFirstGid());
+            w.writeAttribute("firstgid", set.getFirstGid());
 
             if (tilebmpFile != null) {
-                w.writeAttribute("tilewidth", "" + set.getTileWidth());
-                w.writeAttribute("tileheight", "" + set.getTileHeight());
+                w.writeAttribute("tilewidth", set.getTileWidth());
+                w.writeAttribute("tileheight", set.getTileHeight());
                 //w.writeAttribute("spacing", "0");
             }
 
@@ -221,9 +224,12 @@
                 w.endElement();
             } else {
                 // Embedded tileset
+                Preferences prefs = TiledConfiguration.node("saving");
 
-                TiledConfiguration conf = TiledConfiguration.getInstance();
-                if (conf.keyHasValue("tmx.save.tileSetImages", "1")) {
+                boolean embedImages = prefs.getBoolean("embedImages", true);
+                boolean tileSetImages = prefs.getBoolean("tileSetImages", false);
+
+                if (tileSetImages) {
                     Enumeration ids = set.getImageIds();
                     while (ids.hasMoreElements()) {
                         String id = (String)ids.nextElement();
@@ -238,16 +244,15 @@
                         w.endElement();
                         w.endElement();
                     }
-                } else if (conf.keyHasValue("tmx.save.embedImages", "0")) {
-                    String imgSource = conf.getValue(
-                            "tmx.save.tileImagePrefix") + "set.png";
+                } else if (!embedImages) {
+                    String imgSource =
+                            prefs.get("tileImagePrefix", "tile") + "set.png";
                     
                     w.startElement("image");
                     w.writeAttribute("source", imgSource);
                     
-                    String tilesetFilename = (wp.substring(0,
-                            wp.lastIndexOf(File.separatorChar) + 1)
-                            + imgSource);
+                    String tilesetFilename = wp.substring(0,
+                            wp.lastIndexOf(File.separatorChar) + 1) + imgSource;
                     FileOutputStream fw = new FileOutputStream(new File(
                                 tilesetFilename));
                     //byte[] data = ImageHelper.imageToPNG(setImage);
@@ -262,7 +267,7 @@
                     Iterator tileIterator = set.iterator();
                     boolean needWrite = false;
 
-                    if (conf.keyHasValue("tmx.save.embedImages", "1")) {
+                    if (embedImages) {
                         needWrite = true;
                     } else {
                         while (tileIterator.hasNext()) {
@@ -292,7 +297,7 @@
         }
     }
 
-    private void writeObjectGroup(ObjectGroup o, XMLWriter w)
+    private static void writeObjectGroup(ObjectGroup o, XMLWriter w)
         throws IOException
     {
         Iterator itr = o.getObjects();
@@ -306,15 +311,15 @@
      * first global ids for the tilesets are determined, in order for the right
      * gids to be written to the layer data.
      */
-    private void writeMapLayer(MapLayer l, XMLWriter w) throws IOException {
+    private static void writeMapLayer(MapLayer l, XMLWriter w) throws IOException {
         try {
-            TiledConfiguration conf = TiledConfiguration.getInstance();
-            boolean encodeLayerData = conf.keyHasValue(
-                    "tmx.save.encodeLayerData", "1");
-            boolean compressLayerData = conf.keyHasValue(
-                    "tmx.save.layerCompression", "1") && encodeLayerData;
+            Preferences prefs = TiledConfiguration.node("saving");
+            boolean encodeLayerData =
+                    prefs.getBoolean("encodeLayerData", true);
+            boolean compressLayerData =
+                    prefs.getBoolean("layerCompression", true) &&
+                            encodeLayerData;
 
-
             Rectangle bounds = l.getBounds();
 
             if (l.getClass() == SelectionLayer.class) {
@@ -326,20 +331,20 @@
             }
 
             w.writeAttribute("name", l.getName());
-            w.writeAttribute("width", "" + bounds.width);
-            w.writeAttribute("height", "" + bounds.height);
+            w.writeAttribute("width", bounds.width);
+            w.writeAttribute("height", bounds.height);
             if (bounds.x != 0) {
-                w.writeAttribute("xoffset", "" + bounds.x);
+                w.writeAttribute("xoffset", bounds.x);
             }
             if (bounds.y != 0) {
-                w.writeAttribute("yoffset", "" + bounds.y);
+                w.writeAttribute("yoffset", bounds.y);
             }
 
             if (!l.isVisible()) {
                 w.writeAttribute("visible", "0");
             }
             if (l.getOpacity() < 1.0f) {
-                w.writeAttribute("opacity", "" + l.getOpacity());
+                w.writeAttribute("opacity", l.getOpacity());
             }
 
             Properties props = l.getProperties();
@@ -377,10 +382,10 @@
                                 gid = tile.getGid();
                             }
 
-                            out.write((gid      ) & 0x000000FF);
-                            out.write((gid >>  8) & 0x000000FF);
-                            out.write((gid >> 16) & 0x000000FF);
-                            out.write((gid >> 24) & 0x000000FF);
+                            out.write(gid       & LAST_BYTE);
+                            out.write(gid >> 8  & LAST_BYTE);
+                            out.write(gid >> 16 & LAST_BYTE);
+                            out.write(gid >> 24 & LAST_BYTE);
                         }
                     }
 
@@ -400,7 +405,7 @@
                             }
 
                             w.startElement("tile");
-                            w.writeAttribute("gid", ""+gid);
+                            w.writeAttribute("gid", gid);
                             w.endElement();
                         }
                     }
@@ -413,13 +418,13 @@
         }
     }
 
-    private void writeTile(Tile tile, XMLWriter w) throws IOException {
+    private static void writeTile(Tile tile, XMLWriter w) throws IOException {
         try {
             w.startElement("tile");
 
             int tileId = tile.getId();
 
-            w.writeAttribute("id", "" + tileId);
+            w.writeAttribute("id", tileId);
 
             //if (groundHeight != getHeight()) {
             //    w.writeAttribute("groundheight", "" + groundHeight);
@@ -436,13 +441,14 @@
 
             Image tileImage = tile.getImage();
 
-            TiledConfiguration conf = TiledConfiguration.getInstance();
+            Preferences prefs = TiledConfiguration.node("saving");
 
+            boolean embedImages = prefs.getBoolean("embedImages", true);
+            boolean tileSetImages = prefs.getBoolean("tileSetImages", false);
+
             // Write encoded data
-            if (tileImage != null && !conf.keyHasValue(
-                        "tmx.save.tileSetImages", "1")) {
-                if (conf.keyHasValue("tmx.save.embedImages", "1")
-                        && conf.keyHasValue("tmx.save.tileSetImages", "0")) {
+            if (tileImage != null && !tileSetImages) {
+                if (embedImages && !tileSetImages) {
                     w.startElement("image");
                     w.writeAttribute("format", "png");
                     w.startElement("data");
@@ -451,25 +457,24 @@
                                     ImageHelper.imageToPNG(tileImage))));
                     w.endElement();
                     w.endElement();
-                } else if(conf.keyHasValue("tmx.save.tileSetImages", "1")) {
+                } else if (tileSetImages) {
                     w.startElement("image");
-                    w.writeAttribute("id", "" + tile.getImageId());
+                    w.writeAttribute("id", tile.getImageId());
                     int orientation = tile.getImageOrientation();
                     int rotation;
                     boolean flipped =
-                        (orientation & 1) == ((orientation & 2) >> 1);
+                            (orientation & 1) == (orientation & 2) >> 1;
                     if ((orientation & 4) == 4) {
-                        rotation = ((orientation & 1) == 1) ? 270 : 90;
+                        rotation = (orientation & 1) == 1 ? 270 : 90;
                     } else {
-                        rotation = ((orientation & 2) == 2) ? 180 : 0;
+                        rotation = (orientation & 2) == 2 ? 180 : 0;
                     }
-                    if (rotation != 0) w.writeAttribute("rotation",
-                            "" + rotation);
+                    if (rotation != 0) w.writeAttribute("rotation", rotation);
                     if (flipped) w.writeAttribute("flipped", "true");
                     w.endElement();
                 } else {
-                    String prefix = conf.getValue("tmx.save.tileImagePrefix");
-                    String filename = conf.getValue("tmx.save.maplocation") +
+                    String prefix = prefs.get("tileImagePrefix", "tile");
+                    String filename = prefs.get("maplocation", "") +
                         prefix + tileId + ".png";
                     w.startElement("image");
                     w.writeAttribute("source", prefix + tileId + ".png");
@@ -488,14 +493,14 @@
         }
     }
 
-    private void writeObject(MapObject m, ObjectGroup o, XMLWriter w)
+    private static void writeObject(MapObject m, ObjectGroup o, XMLWriter w)
         throws IOException
     {
         try {
             Rectangle b = o.getBounds();
             w.startElement("object");
-            w.writeAttribute("x", "" + (m.getX() + b.x));
-            w.writeAttribute("y", "" + (m.getY() + b.y));
+            w.writeAttribute("x", m.getX() + b.x);
+            w.writeAttribute("y", m.getY() + b.y);
             w.writeAttribute("type", m.getType());
             if (m.getSource() != null) {
                 w.writeAttribute("source", m.getSource());
@@ -581,7 +586,7 @@
                 // Assumes: \ does not occur in filenames
                 relPath = relPath.replace('\\', '/');
             }
-        } catch (Exception e) {
+        } catch (IOException e) {
         }
 
         return relPath;

Modified: branches/bjorn/src/tiled/io/xml/XMLWriter.java
===================================================================
--- branches/bjorn/src/tiled/io/xml/XMLWriter.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/io/xml/XMLWriter.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -17,7 +17,6 @@
 import java.io.IOException;
 import java.util.Stack;
 
-
 /**
  * A simple helper class to write an XML file, based on
  * http://www.xmlsoft.org/html/libxml-xmlwriter.html
@@ -32,8 +31,8 @@
     private final Writer w;
     
     private final Stack openElements;
-    private boolean bStartTagOpen = false;
-    private boolean bDocumentOpen = false;
+    private boolean bStartTagOpen;
+    private boolean bDocumentOpen;
 
 
     public XMLWriter(Writer writer) {
@@ -44,7 +43,7 @@
 
     public void setIndent(boolean bIndent) {
         this.bIndent = bIndent;
-        newLine = ((bIndent) ? "\n" : "");
+        newLine = bIndent ? "\n" : "";
     }
 
     public void setIndentString(String indentString) {
@@ -82,7 +81,7 @@
 
     public void endDocument() throws IOException {
         // End all open elements.
-        while (openElements.size() > 0) {
+        while (!openElements.isEmpty()) {
             endElement();
         }
     }
@@ -100,7 +99,7 @@
         }
 
         // Set document closed when last element is closed
-        if (openElements.size() == 0) {
+        if (openElements.isEmpty()) {
             bDocumentOpen = false;
         }
     }
@@ -117,6 +116,16 @@
         }
     }
 
+    public void writeAttribute(String name, int content)
+        throws IOException, XMLWriterException {
+        writeAttribute(name, String.valueOf(content));
+    }
+
+    public void writeAttribute(String name, float content)
+        throws IOException, XMLWriterException {
+        writeAttribute(name, String.valueOf(content));
+    }
+
     public void writeCDATA(String content) throws IOException {
         if (bStartTagOpen) {
             w.write(">" + newLine);

Modified: branches/bjorn/src/tiled/mapeditor/MapEditor.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/MapEditor.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/MapEditor.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -20,6 +20,7 @@
 import java.io.*;
 import java.util.Stack;
 import java.util.Vector;
+import java.util.prefs.Preferences;
 
 import javax.imageio.ImageIO;
 import javax.swing.*;
@@ -41,7 +42,6 @@
 import tiled.io.MapReader;
 import tiled.io.MapWriter;
 
-
 /**
  * The main class for the Tiled Map Editor.
  *
@@ -80,9 +80,8 @@
     private final UndoableEditSupport undoSupport;
     private final MapEventAdapter mapEventAdapter;
     private final PluginClassLoader pluginLoader;
-    private final TiledConfiguration configuration;
+    private final Preferences prefs = TiledConfiguration.root();
 
-
     int currentPointerState;
     Tile currentTile;
     int currentLayer = -1;
@@ -140,9 +139,6 @@
     final Action selectAllAction, inverseAction, cancelSelectionAction;
 
     public MapEditor() {
-        // Get instance of configuration
-        configuration = TiledConfiguration.getInstance();
-
         /*
         try {
             Image imgPaintCursor = Resources.getImage("cursor-pencil.png");
@@ -164,8 +160,7 @@
 
         cursorHighlight = new SelectionLayer(1, 1);
         cursorHighlight.select(0, 0);
-        cursorHighlight.setVisible(configuration.keyHasValue(
-                    "tiled.cursorhighlight", 1));
+        cursorHighlight.setVisible(prefs.getBoolean("cursorhighlight", true));
 
         mapEventAdapter = new MapEventAdapter();
 
@@ -223,7 +218,7 @@
                 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
         mapScrollPane.setBorder(null);
 
-        createToolbox();
+        createToolBar();
         createData();
         createStatusBar();
 
@@ -241,11 +236,6 @@
 
     private void exit() {
         if (checkSave()) {
-            try {
-                configuration.write("tiled.conf");
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
             System.exit(0);
         }
     }
@@ -408,8 +398,7 @@
         gridMenuItem.setAccelerator(KeyStroke.getKeyStroke("control G"));
 
         cursorMenuItem = new JCheckBoxMenuItem("Highlight Cursor");
-        cursorMenuItem.setSelected(configuration.keyHasValue(
-                    "tiled.cursorhighlight", 1));
+        cursorMenuItem.setSelected(prefs.getBoolean("cursorhighlight", true));
         cursorMenuItem.addActionListener(this);
         cursorMenuItem.setToolTipText(
                 "Toggle highlighting on-map cursor position");
@@ -457,10 +446,9 @@
     }
 
     /**
-     * Creates the left hand main toolbox
-     *
+     * Creates the tool bar.
      */
-    private void createToolbox() {
+    private void createToolBar() {
         Icon iconMove = Resources.getIcon("gimp-tool-move-22.png");
         Icon iconPaint = Resources.getIcon("gimp-tool-pencil-22.png");
         Icon iconErase = Resources.getIcon("gimp-tool-eraser-22.png");
@@ -1049,7 +1037,7 @@
     }
 
     private void updateCursorHighlight(Point tile) {
-        if (configuration.keyHasValue("tiled.cursorhighlight", 1)) {
+        if (prefs.getBoolean("cursorhighlight", true)) {
             Rectangle redraw = cursorHighlight.getBounds();
 
             if (redraw.x != tile.x || redraw.y != tile.y) {
@@ -1205,8 +1193,7 @@
             mapView.toggleMode(MapView.PF_COORDINATES);
             mapView.repaint();
         } else if (command.equals("Highlight Cursor")) {
-            configuration.addConfigPair("tiled.cursorhighlight",
-                    Integer.toString(cursorMenuItem.isSelected() ? 1 : 0));
+            prefs.putBoolean("cursorhighlight", cursorMenuItem.isSelected());
             cursorHighlight.setVisible(cursorMenuItem.isSelected());
         } else if (command.equals("Resize")) {
             ResizeDialog rd = new ResizeDialog(appFrame, this);
@@ -1224,11 +1211,10 @@
                 new PluginDialog(appFrame, pluginLoader);
             pluginDialog.setVisible(true);
         } else if (command.startsWith("_open")) {
-            try {
-                loadMap(configuration.getValue(
-                            "tiled.recent." + command.substring(5)));
-            } catch (Exception e) {
-                e.printStackTrace();
+            Preferences recentFiles = prefs.node("recent");
+            String file = recentFiles.get("file" + command.substring(5), "");
+            if (file.length() > 0) {
+                loadMap(file);
             }
         } else if (command.equals("Preferences...")) {
             ConfigurationDialog d = new ConfigurationDialog(appFrame);
@@ -1861,12 +1847,8 @@
     }
 
     private void openMap() {
-        String startLocation = "";
-
         // Start at the location of the most recently loaded map file
-        if (configuration.hasOption("tiled.recent.1")) {
-            startLocation = configuration.getValue("tiled.recent.1");
-        }
+        String startLocation = prefs.node("recent").get("file0", "");
 
         JFileChooser ch = new JFileChooser(startLocation);
 
@@ -1910,47 +1892,24 @@
         return null;
     }
 
-    private void updateRecent(String mapFile) {
-        Vector recent = new Vector();
-        try {
-            recent.add(configuration.getValue("tiled.recent.1"));
-            recent.add(configuration.getValue("tiled.recent.2"));
-            recent.add(configuration.getValue("tiled.recent.3"));
-            recent.add(configuration.getValue("tiled.recent.4"));
-        } catch (Exception e) {
+    private void updateRecent(String filename) {
+        // If a filename is given, add it to the recent files
+        if (filename != null) {
+            TiledConfiguration.addToRecentFiles(filename);
         }
 
-        // If a map file is given, add it to the recent list
-        if (mapFile != null) {
-            // Remove any existing entry that is the same
-            for (int i = 0; i < recent.size(); i++) {
-                String filename = (String)recent.get(i);
-                if (filename!=null&&filename.equals(mapFile)) {
-                    recent.remove(i);
-                    i--;
-                }
-            }
+        java.util.List files = TiledConfiguration.getRecentFiles();
 
-            recent.add(0, mapFile);
-
-            if (recent.size() > 4) {
-                recent.setSize(4);
-            }
-        }
-
         recentMenu.removeAll();
 
-        for (int i = 0; i < recent.size(); i++) {
-            String file = (String)recent.get(i);
-            if (file != null) {
-                String name =
-                    file.substring(file.lastIndexOf(File.separatorChar) + 1);
+        for (int i = 0; i < files.size(); i++) {
+            String path = (String) files.get(i);
+            String name =
+                path.substring(path.lastIndexOf(File.separatorChar) + 1);
 
-                configuration.addConfigPair("tiled.recent." + (i + 1), file);
-                JMenuItem recentOption = createMenuItem(name, null, null);
-                recentOption.setActionCommand("_open" + (i + 1));
-                recentMenu.add(recentOption);
-            }
+            JMenuItem recentOption = createMenuItem(name, null, null);
+            recentOption.setActionCommand("_open" + i);
+            recentMenu.add(recentOption);
         }
     }
 

Modified: branches/bjorn/src/tiled/mapeditor/Resources.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/Resources.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/Resources.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -25,7 +25,7 @@
  *
  * @version $Id$
  */
-public class Resources {
+public final class Resources {
     // The resource bundle used by this class
     private static final ResourceBundle resourceBundle =
             ResourceBundle.getBundle(

Modified: branches/bjorn/src/tiled/mapeditor/dialogs/BrushDialog.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/dialogs/BrushDialog.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/dialogs/BrushDialog.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -19,6 +19,7 @@
 import java.awt.event.ItemListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.prefs.Preferences;
 import javax.swing.*;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
@@ -37,6 +38,7 @@
 import tiled.mapeditor.widget.MiniMapViewer;
 import tiled.mapeditor.widget.VerticalStaticJPanel;
 import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
 import tiled.util.TiledConfiguration;
 
 /**
@@ -54,12 +56,11 @@
     private JSlider sRandomAmount;
     private JButton bOk, bApply, bCancel;
     private BrushBrowser brushes;
-    private MiniMapViewer mmv;
 
     public BrushDialog(MapEditor editor, JFrame parent,
                        AbstractBrush currentBrush)
     {
-        super(parent, "Brush Options", false);
+        super(parent, Resources.getString("dialog.brush.title"), false);
         myBrush = currentBrush;
         this.editor = editor;
 
@@ -144,14 +145,14 @@
     private JPanel createCustomPanel() {
         JPanel customPanel = new JPanel();
 
-        mmv = new MiniMapViewer();
+        MiniMapViewer mmv = new MiniMapViewer();
         if (myBrush instanceof CustomBrush) {
             //mmv.setView(((CustomBrush)myBrush));
         }
 
         JScrollPane miniSp = new JScrollPane();
         miniSp.getViewport().setView(mmv);
-        miniSp.setPreferredSize(new Dimension(100,100));
+        miniSp.setPreferredSize(new Dimension(100, 100));
         JButton bCreate = new JButton("Create...");
         bCreate.addActionListener(this);
         //TODO: create functionality is not available yet
@@ -313,13 +314,9 @@
     }
 
     private void openMap() throws Exception {
-        String startLocation = "";
-        TiledConfiguration configuration = TiledConfiguration.getInstance();
-
         // Start at the location of the most recently loaded map file
-        if (configuration.hasOption("tiled.recent.1")) {
-            startLocation = configuration.getValue("tiled.recent.1");
-        }
+        Preferences prefs = TiledConfiguration.node("recent");
+        String startLocation = prefs.get("file0", "");
 
         JFileChooser ch = new JFileChooser(startLocation);
 
@@ -329,7 +326,7 @@
                 ch.addChoosableFileFilter(new TiledFileFilter(
                             readers[i].getFilter(), readers[i].getName()));
             }
-        } catch (Throwable e) {
+        } catch (Exception e) {
             JOptionPane.showMessageDialog(this,
                     "Error while loading plugins: " + e.getMessage(),
                     "Error while loading map",

Modified: branches/bjorn/src/tiled/mapeditor/dialogs/ConfigurationDialog.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/dialogs/ConfigurationDialog.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/dialogs/ConfigurationDialog.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -13,33 +13,37 @@
 package tiled.mapeditor.dialogs;
 
 import java.awt.*;
-import java.awt.event.*;
-
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.prefs.Preferences;
 import javax.swing.*;
-import javax.swing.event.ChangeListener;
 import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 
-import tiled.util.TiledConfiguration;
 import tiled.mapeditor.widget.IntegerSpinner;
 import tiled.mapeditor.widget.VerticalStaticJPanel;
+import tiled.util.TiledConfiguration;
 
-
-public class ConfigurationDialog extends JDialog implements ActionListener,
-       ChangeListener, ItemListener
+/**
+ * @version $Id$
+ */
+public class ConfigurationDialog extends JDialog
 {
-    private JButton bOk, bApply, bCancel;
-    private JPanel layerOps, generalOps, tilesetOps, gridOps;
     private IntegerSpinner undoDepth, gridOpacity;
     private JCheckBox cbBinaryEncode, cbCompressLayerData, cbEmbedImages;
     private JCheckBox cbReportIOWarnings;
     private JRadioButton rbEmbedInTiles, rbEmbedInSet;
     private JCheckBox cbGridAA;
-    private JColorChooser gridColor;
-    private final TiledConfiguration configuration;
+    //private JColorChooser gridColor;
 
+    private final Preferences prefs = TiledConfiguration.root();
+    private final Preferences savingPrefs = prefs.node("saving");
+    private final Preferences ioPrefs = prefs.node("io");
+
     public ConfigurationDialog(JFrame parent) {
         super(parent, "Preferences", true);
-        configuration = TiledConfiguration.getInstance();
         init();
         setLocationRelativeTo(parent);
     }
@@ -60,39 +64,11 @@
         cbGridAA = new JCheckBox("Antialiasing");
         gridOpacity = new IntegerSpinner(0, 0, 255);
         //gridColor = new JColorChooser();
-        cbBinaryEncode.addItemListener(this);
-        cbCompressLayerData.addItemListener(this);
-        cbEmbedImages.addItemListener(this);
-        cbReportIOWarnings.addItemListener(this);
-        cbGridAA.addItemListener(this);
-        undoDepth.addChangeListener(this);
-        gridOpacity.addChangeListener(this);
-        //gridColor.addChangeListener(this);
 
-        cbBinaryEncode.setActionCommand("tmx.save.encodeLayerData");
-        cbCompressLayerData.setActionCommand("tmx.save.layerCompression");
-        //cbEmbedImages.setActionCommand("tmx.save.embedImages");
-        cbReportIOWarnings.setActionCommand("tiled.report.io");
+        // Set up the layout
 
-        rbEmbedInTiles.setActionCommand("tmx.save.embedImages");
-        rbEmbedInTiles.setEnabled(false);
-        rbEmbedInSet.setActionCommand("tmx.save.tileSetImages");
-        rbEmbedInSet.setEnabled(false);
-        undoDepth.setName("tiled.undo.depth");
-        cbGridAA.setActionCommand("tiled.grid.antialias");
-        gridOpacity.setName("tiled.grid.opacity");
-        //gridColor.setName("tiled.grid.color");
-
-        bOk = new JButton("OK");
-        bApply = new JButton("Apply");
-        bCancel = new JButton("Cancel");
-        bOk.addActionListener(this);
-        bApply.addActionListener(this);
-        bCancel.addActionListener(this);
-        bApply.setEnabled(false);
-
         /* LAYER OPTIONS */
-        layerOps = new VerticalStaticJPanel();
+        JPanel layerOps = new VerticalStaticJPanel();
         layerOps.setLayout(new GridBagLayout());
         layerOps.setBorder(BorderFactory.createCompoundBorder(
                     BorderFactory.createTitledBorder("Layer Options"),
@@ -108,7 +84,7 @@
         layerOps.add(cbCompressLayerData, c);
 
         /* GENERAL OPTIONS */
-        generalOps = new VerticalStaticJPanel();
+        JPanel generalOps = new VerticalStaticJPanel();
         generalOps.setLayout(new GridBagLayout());
         generalOps.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
         c = new GridBagConstraints();
@@ -123,7 +99,7 @@
         generalOps.add(cbReportIOWarnings, c);
 
         /* TILESET OPTIONS */
-        tilesetOps = new VerticalStaticJPanel();
+        JPanel tilesetOps = new VerticalStaticJPanel();
         tilesetOps.setLayout(new GridBagLayout());
         tilesetOps.setBorder(BorderFactory.createCompoundBorder(
                     BorderFactory.createTitledBorder("Tileset Options"),
@@ -138,7 +114,7 @@
         tilesetOps.add(rbEmbedInSet, c);
 
         /* GRID OPTIONS */
-        gridOps = new VerticalStaticJPanel();
+        JPanel gridOps = new VerticalStaticJPanel();
         gridOps.setLayout(new GridBagLayout());
         gridOps.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
         c = new GridBagConstraints();
@@ -153,17 +129,19 @@
         //c.gridx = 1;
         //gridOps.add(gridColor, c);
 
+        JButton bClose = new JButton("Close");
+        bClose.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                dispose();
+            }
+        });
+
         /* BUTTONS PANEL */
         JPanel buttons = new VerticalStaticJPanel();
         buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
         buttons.add(Box.createGlue());
-        buttons.add(bOk);
-        buttons.add(Box.createRigidArea(new Dimension(5, 0)));
-        buttons.add(bApply);
-        buttons.add(Box.createRigidArea(new Dimension(5, 0)));
-        buttons.add(bCancel);
+        buttons.add(bClose);
 
-
         JPanel saving = new JPanel();
         saving.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
         saving.setLayout(new BoxLayout(saving, BoxLayout.Y_AXIS));
@@ -196,111 +174,103 @@
         mainPanel.add(buttons);
 
         getContentPane().add(mainPanel);
-        getRootPane().setDefaultButton(bOk);
+        getRootPane().setDefaultButton(bClose);
         pack();
-    }
 
-    public void configure() {
-        updateFromConf();
-        setVisible(true);
-    }
+        // Associate listeners with the configuration widgets
 
-    private void updateFromConf() {
-        undoDepth.setValue(configuration.getIntValue(undoDepth.getName(), 30));
-        gridOpacity.setValue(
-                configuration.getIntValue(gridOpacity.getName(), 255));
+        cbBinaryEncode.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent itemEvent) {
+                final boolean selected = cbBinaryEncode.isSelected();
+                savingPrefs.putBoolean("encodeLayerData", selected);
+                cbCompressLayerData.setEnabled(selected);
+            }
+        });
 
-        if (configuration.keyHasValue("tmx.save.embedImages", "1")) {
-            cbEmbedImages.setSelected(true);
-            rbEmbedInTiles.setSelected(true);
-        }
+        cbCompressLayerData.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent itemEvent) {
+                savingPrefs.putBoolean("layerCompression",
+                        cbCompressLayerData.isSelected());
+            }
+        });
 
-        // Handle checkboxes
-        updateFromConf(layerOps);
-        updateFromConf(generalOps);
-        updateFromConf(tilesetOps);
-        updateFromConf(gridOps);
+        cbEmbedImages.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent itemEvent) {
+                final boolean embed = cbEmbedImages.isSelected();
+                savingPrefs.putBoolean("embedImages", embed);
+                rbEmbedInTiles.setSelected(embed && rbEmbedInTiles.isSelected());
+                rbEmbedInTiles.setEnabled(embed);
+                rbEmbedInSet.setSelected(embed && rbEmbedInSet.isSelected());
+                rbEmbedInSet.setEnabled(embed);
+            }
+        });
 
-        cbCompressLayerData.setEnabled(cbBinaryEncode.isSelected());
+        cbReportIOWarnings.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent itemEvent) {
+                ioPrefs.putBoolean("reportWarnings",
+                        cbReportIOWarnings.isSelected());
+            }
+        });
 
-        bApply.setEnabled(false);
-    }
+        cbGridAA.addItemListener(new ItemListener() {
+            public void itemStateChanged(ItemEvent itemEvent) {
+                prefs.putBoolean("gridAntialias", cbGridAA.isSelected());
+            }
+        });
 
-    private void updateFromConf(Container container) {
-        for (int i = 0; i < container.getComponentCount(); i++) {
-            Component c = container.getComponent(i);
-            try {
-                AbstractButton b = (AbstractButton)c;
-                if (b.getClass().equals(JCheckBox.class)) {
-                    if (configuration.keyHasValue(b.getActionCommand(), "1")) {
-                        b.setSelected(true);
-                    }
-                }
-            } catch (ClassCastException e) {
+        undoDepth.addChangeListener(new ChangeListener() {
+            public void stateChanged(ChangeEvent changeEvent) {
+                prefs.putInt("undoDepth", undoDepth.intValue());
             }
-        }
-    }
+        });
 
-    private void processOptions() {
-        configuration.addConfigPair(
-                undoDepth.getName(), "" + undoDepth.intValue());
-        configuration.addConfigPair(
-                gridOpacity.getName(), "" + gridOpacity.intValue());
+        gridOpacity.addChangeListener(new ChangeListener() {
+            public void stateChanged(ChangeEvent changeEvent) {
+                prefs.putInt("gridOpacity", gridOpacity.intValue());
+            }
+        });
 
-        // Handle checkboxes
-        processOptions(layerOps);
-        processOptions(generalOps);
-        processOptions(tilesetOps);
-        processOptions(gridOps);
+        //gridColor.addChangeListener(...);
 
-        bApply.setEnabled(false);
-    }
+        rbEmbedInTiles.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                savingPrefs.putBoolean("embedImages",
+                        rbEmbedInTiles.isSelected());
+            }
+        });
 
-    private void processOptions(Container container) {
-        for (int i = 0; i < container.getComponentCount(); i++) {
-            Component c = container.getComponent(i);
-            try {
-                AbstractButton b = (AbstractButton)c;
-                if (b.getClass().equals(JCheckBox.class)) {
-                    configuration.addConfigPair(
-                            b.getActionCommand(), b.isSelected() ? "1" : "0");
-                }
-            } catch (ClassCastException e) {
+        rbEmbedInSet.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent actionEvent) {
+                savingPrefs.putBoolean("tileSetImages",
+                        rbEmbedInSet.isSelected());
             }
-        }
-    }
+        });
 
-    public void actionPerformed(ActionEvent event) {
-        Object source = event.getSource();
+        rbEmbedInTiles.setEnabled(false);
+        rbEmbedInSet.setEnabled(false);
 
-        if (source == bOk) {
-            processOptions();
-            dispose();
-        } else if (source == bCancel) {
-            dispose();
-        } else if (source == bApply) {
-            processOptions();
-        }
+        //gridColor.setName("tiled.grid.color");
     }
 
-    public void stateChanged(ChangeEvent event) {
-        bApply.setEnabled(true);
+    public void configure() {
+        updateFromConfiguration();
+        setVisible(true);
     }
 
-    public void itemStateChanged(ItemEvent event) {
-        Object source = event.getItemSelectable();
+    private void updateFromConfiguration() {
+        undoDepth.setValue(prefs.getInt("undoDepth", 30));
+        gridOpacity.setValue(prefs.getInt("gridOpacity", 255));
 
-        if (source == cbBinaryEncode) {
-            cbCompressLayerData.setEnabled(cbBinaryEncode.isSelected());
-        } else if (source == cbEmbedImages) {
-            rbEmbedInTiles.setSelected(
-                    cbEmbedImages.isSelected() && rbEmbedInTiles.isSelected());
-            rbEmbedInTiles.setEnabled(cbEmbedImages.isSelected());
-            rbEmbedInSet.setSelected(
-                    cbEmbedImages.isSelected() && rbEmbedInSet.isSelected());
-            rbEmbedInSet.setEnabled(cbEmbedImages.isSelected());
+        if (savingPrefs.getBoolean("embedImages", true)) {
+            cbEmbedImages.setSelected(true);
+            rbEmbedInTiles.setSelected(true);
         }
 
-        bApply.setEnabled(true);
+        cbBinaryEncode.setSelected(savingPrefs.getBoolean("encodeLayerData", true));
+        cbCompressLayerData.setSelected(savingPrefs.getBoolean("layerCompression", true));
+        cbGridAA.setSelected(savingPrefs.getBoolean("gridAntialias", true));
+        cbReportIOWarnings.setSelected(ioPrefs.getBoolean("reportWarnings", false));
+
+        cbCompressLayerData.setEnabled(cbBinaryEncode.isSelected());
     }
 }

Modified: branches/bjorn/src/tiled/mapeditor/dialogs/NewMapDialog.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/dialogs/NewMapDialog.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/dialogs/NewMapDialog.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -12,15 +12,23 @@
 
 package tiled.mapeditor.dialogs;
 
-import java.awt.*;
-import java.awt.event.*;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.prefs.Preferences;
 import javax.swing.*;
 
-import tiled.core.*;
-import tiled.util.TiledConfiguration;
+import tiled.core.Map;
 import tiled.mapeditor.widget.IntegerSpinner;
 import tiled.mapeditor.widget.VerticalStaticJPanel;
+import tiled.util.TiledConfiguration;
 
+/**
+ * @version $Id$
+ */
 public class NewMapDialog extends JDialog implements ActionListener
 {
     private Map newMap;
@@ -28,6 +36,8 @@
     private IntegerSpinner tileWidth, tileHeight;
     private JComboBox mapTypeChooser;
 
+    private final Preferences prefs = TiledConfiguration.node("dialog/newmap");
+
     public NewMapDialog(JFrame parent) {
         super(parent, "New Map", true);
         init();
@@ -39,11 +49,10 @@
     private void init() {
         // Load dialog defaults
 
-        TiledConfiguration conf = TiledConfiguration.getInstance();
-        int defaultMapWidth = conf.getIntValue("tiled.newmapdialog.mapwidth", 64);
-        int defaultMapHeight = conf.getIntValue("tiled.newmapdialog.mapheight", 64);
-        int defaultTileWidth = conf.getIntValue("tiled.newmapdialog.tilewidth", 35);
-        int defaultTileHeight = conf.getIntValue("tiled.newmapdialog.tileheight", 35);
+        int defaultMapWidth = prefs.getInt("mapWidth", 64);
+        int defaultMapHeight = prefs.getInt("mapHeight", 64);
+        int defaultTileWidth = prefs.getInt("tileWidth", 35);
+        int defaultTileHeight = prefs.getInt("tileHeight", 35);
 
         // Create the primitives
 
@@ -179,13 +188,10 @@
 
             // Save dialog options
 
-            TiledConfiguration conf = TiledConfiguration.getInstance();
-            conf.addConfigPair("tiled.newmapdialog.mapwidth", Integer.toString(mapWidth.intValue()));
-            conf.addConfigPair("tiled.newmapdialog.mapheight", Integer.toString(mapHeight.intValue()));
-            conf.addConfigPair("tiled.newmapdialog.tilewidth", Integer.toString(tileWidth.intValue()));
-            conf.addConfigPair("tiled.newmapdialog.tileheight", Integer.toString(tileHeight.intValue()));
-
-            conf.flush();
+            prefs.putInt("mapWidth", mapWidth.intValue());
+            prefs.putInt("mapHeight", mapHeight.intValue());
+            prefs.putInt("tileWidth", tileWidth.intValue());
+            prefs.putInt("tileHeight", tileHeight.intValue());
         }
         dispose();
     }

Modified: branches/bjorn/src/tiled/mapeditor/plugin/PluginClassLoader.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/plugin/PluginClassLoader.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/plugin/PluginClassLoader.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -23,7 +23,6 @@
 import java.util.Vector;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
-
 import javax.swing.JFrame;
 import javax.swing.ProgressMonitor;
 
@@ -32,7 +31,9 @@
 import tiled.io.PluggableMapIO;
 import tiled.util.TiledConfiguration;
 
-
+/**
+ * @version $Id$
+ */
 public final class PluginClassLoader extends URLClassLoader
 {
     private Vector plugins;
@@ -58,7 +59,7 @@
         writerFormats = new Hashtable();
     }
 
-    public static PluginClassLoader getInstance() {
+    public static synchronized PluginClassLoader getInstance() {
         if (instance == null) {
             instance = new PluginClassLoader();
         }
@@ -70,8 +71,7 @@
         ProgressMonitor monitor;
 
         if (base == null) {
-            baseURL = TiledConfiguration.getInstance().getValue(
-                    "tiled.plugins.dir");
+            baseURL = TiledConfiguration.root().get("pluginsDir", "plugins");
         }
 
         File dir = new File(baseURL);
@@ -99,7 +99,7 @@
         monitor.setMillisToPopup(0);
         monitor.setMillisToDecideToPopup(0);
 
-        for (int i = 0, j = 0; i < files.length; i++) {
+        for (int i = 0; i < files.length; i++) {
             String aPath = files[i].getAbsolutePath();
             String aName =
                 aPath.substring(aPath.lastIndexOf(File.separatorChar) + 1);
@@ -246,7 +246,7 @@
         return false;
     }
 
-    private boolean isReader(Class c) throws Exception {
+    private static boolean isReader(Class c) throws Exception {
         return doesImplement(c, "tiled.io.MapReader");
     }
 

Modified: branches/bjorn/src/tiled/mapeditor/resources/gui.properties
===================================================================
--- branches/bjorn/src/tiled/mapeditor/resources/gui.properties	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/resources/gui.properties	2006-02-12 02:50:45 UTC (rev 580)
@@ -1,4 +1,5 @@
 action.tileset.remove.error.title=Error while removing tileset
 action.tileset.remove.error.layer-locked.message=A layer containing tiles used by this tileset is locked,\n\
   it needs to be unlocked before the tileset can be completely removed.
+dialog.brush.title=Brush Options
 general.file.exists.message=The file already exists. Do you wish to overwrite it?
\ No newline at end of file

Modified: branches/bjorn/src/tiled/mapeditor/selection/SelectionLayer.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/selection/SelectionLayer.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/selection/SelectionLayer.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -12,16 +12,20 @@
 
 package tiled.mapeditor.selection;
 
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Rectangle;
 import java.awt.geom.Area;
 import java.awt.geom.Rectangle2D;
+import java.util.prefs.Preferences;
 
-import tiled.core.*;
+import tiled.core.Tile;
+import tiled.core.TileLayer;
 import tiled.util.TiledConfiguration;
 
-
 /**
  * A layer used to keep track of a selected area.
+ *
+ * @version $Id$
  */
 public class SelectionLayer extends TileLayer
 {
@@ -30,7 +34,6 @@
     private Area selection;
 
     public SelectionLayer() {
-        super();
         init();
     }
 
@@ -40,11 +43,10 @@
     }
 
     private void init() {
-        TiledConfiguration conf = TiledConfiguration.getInstance();
+        Preferences prefs = TiledConfiguration.root();
         try {
-            highlightColor = Color.decode(
-                    conf.getValue("tiled.selection.color"));
-        } catch (Throwable e) {
+            highlightColor = Color.decode(prefs.get("selectionColor", ""));
+        } catch (NumberFormatException e) {
             highlightColor = Color.blue;
         }
 
@@ -55,7 +57,7 @@
     /**
      * Returns the selected area.
      * 
-     * @return
+     * @return the selected area
      */
     public Area getSelectedArea() {
         return selection;

Modified: branches/bjorn/src/tiled/mapeditor/undo/UndoStack.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/undo/UndoStack.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/undo/UndoStack.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -13,22 +13,24 @@
 package tiled.mapeditor.undo;
 
 import java.util.Iterator;
-import javax.swing.undo.*;
+import javax.swing.undo.UndoManager;
+import javax.swing.undo.UndoableEdit;
 
 import tiled.util.TiledConfiguration;
 
-
+/**
+ * @version $Id$
+ */
 public class UndoStack extends UndoManager
 {
     UndoableEdit savedAt;
 
     public UndoStack() {
-        setLimit(TiledConfiguration.getInstance().getIntValue(
-                    "tmx.undo.depth", 30));
+        setLimit(TiledConfiguration.root().getInt("undoDepth", 30));
     }
 
     public boolean isAllSaved() {
-        return (editToBeUndone() == savedAt);
+        return editToBeUndone() == savedAt;
     }
 
     public void commitSave() {

Modified: branches/bjorn/src/tiled/mapeditor/util/LayerTableModel.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/util/LayerTableModel.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/util/LayerTableModel.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -46,7 +46,7 @@
             /*
             for (int j = 0; j < map.getTotalLayers(); j++) {
                 if (map.getLayer(j).getClass() == SelectionLayer.class) {
-                    if (TiledConfiguration.keyHasValue("tiled.layer.showselection", "1")) {
+                    if (TiledConfiguration.root().getBoolean("layer.showselection", true)) {
                         totalLayers++;
                     }
                 } else {

Modified: branches/bjorn/src/tiled/mapeditor/util/TiledFileFilter.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/util/TiledFileFilter.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/util/TiledFileFilter.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -54,9 +54,9 @@
     public TiledFileFilter(String filter, String desc) {
     	exts = new LinkedList();
     	this.desc = desc;
-    	String [] ext = filter.split(",");
-    	for(int i=0;i<ext.length;i++) {
-    		exts.add(ext[i].substring(ext[i].indexOf('.')+1));
+    	String[] ext = filter.split(",");
+    	for (int i = 0; i < ext.length; i++) {
+    		exts.add(ext[i].substring(ext[i].indexOf('.') + 1));
     	}
     }
     

Modified: branches/bjorn/src/tiled/mapeditor/widget/TileButton.java
===================================================================
--- branches/bjorn/src/tiled/mapeditor/widget/TileButton.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/mapeditor/widget/TileButton.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -30,26 +30,26 @@
     private boolean maintainAspect;
     private EventListenerList tileSelectionListeners;
 
-    public TileButton( Tile t, Dimension d ) {
+    public TileButton(Tile t, Dimension d) {
         setMargin(new Insets(0, 0, 0, 0));
         size = d;
         maintainAspect = false;
-        setTile( t );
+        setTile(t);
     }
 
-    public TileButton( Dimension d ) {
-        this( null, d );
+    public TileButton(Dimension d) {
+        this(null, d);
     }
 
-    public TileButton( Tile t ) {
-        this( t, null );
+    public TileButton(Tile t) {
+        this(t, null);
     }
 
-    public TileButton( ) {
-        this( null, null );
+    public TileButton() {
+        this(null, null);
     }
 
-    public void setTile( Tile t ) {
+    public void setTile(Tile t) {
         tile = t;
         ImageIcon icon = null;
         Insets i = getInsets();
@@ -123,11 +123,11 @@
     }
     */
 
-    public void setMaintainAspect( boolean v ) {
+    public void setMaintainAspect(boolean v) {
         maintainAspect = v;
     }
 
-    public boolean isAspectMaintained( ) {
+    public boolean isAspectMaintained() {
         return maintainAspect;
     }
 
@@ -135,27 +135,27 @@
      * Adds a tile selection listener. The listener will be notified when the
      * tile shown by the tile button changes.
      */
-    public void addTileSelectionListener( TileSelectionListener l ) {
-        tileSelectionListeners.add( TileSelectionListener.class, l );
+    public void addTileSelectionListener(TileSelectionListener l) {
+        tileSelectionListeners.add(TileSelectionListener.class, l);
     }
 
     /**
      * Removes a tile selection listener.
      */
-    public void removeTileSelectionListener( TileSelectionListener l ) {
-        tileSelectionListeners.remove( TileSelectionListener.class, l );
+    public void removeTileSelectionListener(TileSelectionListener l) {
+        tileSelectionListeners.remove(TileSelectionListener.class, l);
     }
 
     /**
      * Notifies all registered tile selection listeners about a newly selected
      * tile.
      */
-    protected void fireActionPerformed( TileSelectionEvent e ) {
-        Object[] listeners = tileSelectionListeners.getListenerList( );
+    protected void fireActionPerformed(TileSelectionEvent e) {
+        Object[] listeners = tileSelectionListeners.getListenerList();
 
-        for( int i = listeners.length - 2; i >= 0; i -= 2 ) {
-            if( listeners[i] == TileSelectionListener.class ) {
-                ((TileSelectionListener)listeners[i + 1]).tileSelected( e );
+        for (int i = listeners.length - 2; i >= 0; i -= 2) {
+            if (listeners[i] == TileSelectionListener.class) {
+                ((TileSelectionListener)listeners[i + 1]).tileSelected(e);
             }
         }
     }

Modified: branches/bjorn/src/tiled/util/TiledConfiguration.java
===================================================================
--- branches/bjorn/src/tiled/util/TiledConfiguration.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/util/TiledConfiguration.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -12,240 +12,96 @@
 
 package tiled.util;
 
-import java.util.*;
-import java.io.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.prefs.Preferences;
 
-
 /**
- * A singleton class handling configuration options.
+ * This class provides access to nodes in the user tiled preferences tree. In
+ * addition it provides a number of related convenience methods.
+ *
+ * @version $Id$
  */
 public final class TiledConfiguration
 {
-    private static TiledConfiguration instance = null;
-    private Properties settings;
-    private boolean changed;
+    public static final int RECENT_FILE_COUNT = 8;
 
+    private static final Preferences prefs = Preferences.userRoot().node("tiled");
+
+    // Prevent instanciation
     private TiledConfiguration() {
-        settings = new Properties();
-        populateDefaults();
-        try {
-            parse("tiled.conf");
-        } catch (Exception e) {
-            System.out.println("Warning: could not load configuration file.");
-        }
-        changed = false;
     }
 
     /**
-     * Returns the tiled configuration class instance. Will create a new
-     * instance when it hasn't been created yet.
-     * 
-     * @return a reference to the singleton
-     */
-    public static TiledConfiguration getInstance() {
-        if (instance == null) {
-            instance = new TiledConfiguration();
-        }
-        return instance;
-    }
-
-    /**
-     * Reads config settings from the given file.
+     * Returns the node with the given path name relative from the root of
+     * Tiled configuration.
      *
-     * @param filename path of file to read configuration from
-     * @throws FileNotFoundException
-     * @throws IOException
+     * @param pathName the path name relative from the root
+     * @return the requested preferences node
      */
-    public void parse(String filename)
-        throws FileNotFoundException, IOException
-    {
-        parse(new BufferedReader(new FileReader(filename)));
+    public static Preferences node(String pathName) {
+        return prefs.node(pathName);
     }
 
     /**
-     * Reads config settings from the given buffered reader.
-     * 
-     * @param br a @link{BufferedReader} opened on the config file
-     * @throws IOException
-     */
-    public void parse(BufferedReader br) throws IOException {
-        String line;
-        while ((line = br.readLine()) != null) {
-            // Make sure it isn't a comment
-            if (!line.trim().startsWith("#") && line.trim().length() > 0){
-                String[] keyValue = line.split("[ ]*=[ ]*");
-                if (keyValue.length > 1) {
-                    addConfigPair(keyValue[0], keyValue[1]);
-                }
-            }
-        }
-    }
-
-    /**
-     * Returns wether the option is available in the config file.
+     * Returns the root node for Tiled configuration.
      *
-     * @param name the name of the option to check for
-     * @return <code>true</code> if the option has a non-<code>null</code>
-     *         value, <code>false</code> otherwise
+     * @return the root node for Tiled configuration
      */
-    public boolean hasOption(String name) {
-        return (settings.get(name) != null);
+    public static Preferences root() {
+        return prefs;
     }
 
     /**
-     * Returns the value of the given option.
+     * Adds the given filename to the top of the recent file list. It also
+     * makes sure it does not occur further down the list.
      *
-     * @param option
-     * @return String The value of the specified option as a String
+     * @param mapFile the absolute path of the file to add, must not be
+     *                <code>null</code>
      */
-    public String getValue(String option) {
-         return (String)settings.get(option);
-    }
+    public static void addToRecentFiles(String mapFile) {
+        assert mapFile != null;
 
-    /**
-     * Returns the integer value of the given option, or the given default
-     * when the option doesn't exist.
-     * 
-     * @param option
-     * @param def
-     * @return int The value of the specified option as an <code>int</code>
-     */
-    public int getIntValue(String option, int def) {
-        String str = getValue(option);
-        if (str != null) {
-            return Integer.parseInt(str);
-        } else {
-            return def;
+        // Get the existing recent file list
+        List recent = getRecentFiles();
+
+        // Remove all existing occurences of the file
+        Iterator iterator = recent.iterator();
+        while (iterator.hasNext()) {
+            String filename = (String) iterator.next();
+            if (filename.equals(mapFile)) {
+                iterator.remove();
+            }
         }
-    }
 
-    /**
-     * Returns wether a certain option equals a certain string, ignoring case.
-     */
-    public boolean keyHasValue(String option, String comp) {
-        String check = getValue(option);
-        return (check != null && check.equalsIgnoreCase(comp));
-    }
+        // Add the given map file to the top
+        recent.add(0, mapFile);
 
-    /**
-     * Returns wether a certain option equals a certain integer.
-     */
-    public boolean keyHasValue(String option, int comp) {
-        return (hasOption(option) && getIntValue(option, 0) == comp);
-    }
-
-    /**
-     * Adds a config pair to the configuration.
-     */
-    public void addConfigPair(String key, String value) {
-        String prev = (String)settings.get(key);
-        if (prev == null || !prev.equals(value)) {
-            settings.put(key, value);
-            changed = true;
+        // Store the new recent file listing
+        Preferences recentNode = prefs.node("recent");
+        for (int i = 0; i < RECENT_FILE_COUNT && i < recent.size(); i++)
+        {
+            String recentFile = (String) recent.get(i);
+            recentNode.put("file" + i, recentFile);
         }
     }
 
     /**
-     * Removes a config pair from the configuration.
-     */
-    public void remove(String key) {
-        settings.remove(key);
-    }
-
-    /**
-     * Writes the current configuration to a file. Preserves comments and
-     * unknown options.
+     * Returns the list of recently used files.
      *
-     * @param filename the file to write the configuration to
+     * @return the list of recently used files
      */
-    public void write(String filename) throws IOException, Exception {
-        BufferedWriter bw;
-        Vector inputLines = new Vector();
-        HashMap availableKeys = new HashMap();
-        String line;
-
-        try {
-            BufferedReader br = new BufferedReader(new FileReader(filename));
-            while ((line = br.readLine()) != null) {
-                inputLines.add(line);
+    public static List getRecentFiles() {
+        List recent = new ArrayList(RECENT_FILE_COUNT);
+        Preferences recentNode = prefs.node("recent");
+        for (int i = 0; i < RECENT_FILE_COUNT; i++)
+        {
+            String recentFile = recentNode.get("file" + i, "");
+            if (recentFile.length() > 0) {
+                recent.add(recentFile);
             }
-
-            br.close();
-        } catch (IOException ioe) {
-            // Although it's nice, it's not necessary to have a config file in
-            // existence when we go to write the config
         }
-
-        bw = new BufferedWriter(new FileWriter(filename));
-
-        // Iterate through all existing lines in the file
-        Iterator lineItr = inputLines.iterator();
-        while (lineItr.hasNext()) {
-            line = (String)lineItr.next();
-            // Make sure it isn't a comment
-            if (!line.trim().startsWith("#") && line.trim().length() > 0) {
-                String[] keyValue = line.split("[ ]*=[ ]*");
-                availableKeys.put(keyValue[0], "Tiled is cool");
-                if (hasOption(keyValue[0])) {
-                    bw.write(keyValue[0] + " = " + getValue(keyValue[0]));
-                    bw.newLine();
-                } else {
-                    bw.write(line);
-                    bw.newLine();
-                }
-            } else {
-                bw.write(line);
-                bw.newLine();
-            }
-        }
-
-        // Iterate through configuration options, saving the options that were
-        // not yet in the file already.
-        Iterator keyItr = settings.keySet().iterator();
-        while (keyItr.hasNext()) {
-            String key = (String)keyItr.next();
-            if (!availableKeys.containsKey(key) && settings.get(key) != null) {
-                bw.write(key + " = " + settings.get(key));
-                bw.newLine();
-            }
-        }
-
-        bw.close();
+        return recent;
     }
-
-    /**
-     * Sets the default values for pertinent properties.
-     */
-    public void populateDefaults() {
-        addConfigPair("tmx.save.embedImages", "1");
-        addConfigPair("tmx.save.tileImagePrefix", "tile");
-        addConfigPair("tmx.save.layerCompression", "1");
-        addConfigPair("tmx.save.encodeLayerData", "1");
-        addConfigPair("tmx.save.tileSetImages", "0");
-        addConfigPair("tmx.save.embedtileSetImages", "0");
-        addConfigPair("tiled.report.io", "0");
-        addConfigPair("tiled.undo.depth", "30");
-        addConfigPair("tiled.selection.color", "0x0000FF");
-        addConfigPair("tiled.background.color", "0x404040");
-        addConfigPair("tiled.cursorhighlight", "1");
-        addConfigPair("tiled.grid.color", "0x000000");
-        addConfigPair("tiled.grid.antialias", "1");
-        addConfigPair("tiled.grid.opacity", "255");
-        addConfigPair("tiled.plugins.dir", "plugins");
-
-        // defaults for new map dialog...
-        addConfigPair("tiled.newmapdialog.mapwidth", "64");
-        addConfigPair("tiled.newmapdialog.mapheight", "64");
-        addConfigPair("tiled.newmapdialog.tilewidth", "35");
-        addConfigPair("tiled.newmapdialog.tileheight", "35");
-    }
-
-    /**
-     * Writes current the configuration to <code>tiled.conf</code>. Silently ignores any exception.
-     */
-    public void flush () {
-        try { write("tiled.conf"); }
-        catch (IOException ex) {}
-        catch (Exception ex) {}
-    }
 }

Modified: branches/bjorn/src/tiled/view/MapView.java
===================================================================
--- branches/bjorn/src/tiled/view/MapView.java	2006-02-11 16:35:31 UTC (rev 579)
+++ branches/bjorn/src/tiled/view/MapView.java	2006-02-12 02:50:45 UTC (rev 580)
@@ -15,6 +15,7 @@
 import java.awt.*;
 //import java.awt.geom.PathIterator;
 import java.util.Iterator;
+import java.util.prefs.Preferences;
 import javax.swing.Scrollable;
 import javax.swing.JPanel;
 
@@ -46,7 +47,9 @@
     };
 
     private SmoothZoomer smoothZoomer;
+
     private static final Color DEFAULT_BACKGROUND_COLOR = new Color(64, 64, 64);
+    private static final Color DEFAULT_GRID_COLOR = Color.black;
 
 
     public MapView(Map m) {
@@ -191,7 +194,7 @@
      */
     public void paintComponent(Graphics g) {
         Graphics2D g2d = (Graphics2D)g.create();
-        TiledConfiguration conf = TiledConfiguration.getInstance();
+        Preferences prefs = TiledConfiguration.root();
 
         double currentZoom = zoom;
         Iterator li = myMap.getLayers();
@@ -202,7 +205,7 @@
 
         // Do an initial fill with the background color
         try {
-            String colorString = conf.getValue("tiled.background.color");
+            String colorString = prefs.get("backgroundColor", "");
             g2d.setColor(Color.decode(colorString));
         } catch (NumberFormatException e) {
             g2d.setColor(DEFAULT_BACKGROUND_COLOR);
@@ -251,15 +254,15 @@
 
         // Grid color (also used for coordinates)
         try {
-            String colorString = conf.getValue("tiled.grid.color");
+            String colorString = prefs.get("gridColor", "");
             g2d.setColor(Color.decode(colorString));
         } catch (NumberFormatException e) {
-            g2d.setColor(Color.black);
+            g2d.setColor(DEFAULT_GRID_COLOR);
         }
 
         if (getMode(PF_GRIDMODE)) {
             // Grid opacity
-            int opacity = conf.getIntValue("tiled.grid.opacity", 255);
+            int opacity = prefs.getInt("gridOpacity", 255);
             if (opacity < 255) {
                 g2d.setComposite(AlphaComposite.getInstance(
                             AlphaComposite.SRC_ATOP, (float)opacity / 255.0f));
@@ -268,7 +271,7 @@
             }
 
             // Configure grid antialiasing
-            if (conf.keyHasValue("tiled.grid.antialias", 1)) {
+            if (prefs.getBoolean("gridAntialias", true)) {
                 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);
             } else {




More information about the tiled-commit mailing list