[tiled] r700 - in trunk: . plugins/json/src/org/json plugins/mappy/src/tiled/plugins/mappy src/tiled/core src/tiled/io src/tiled/io/xml src/tiled/mapeditor src/tiled/mapeditor/actions src/tiled/mapeditor/animation src/tiled/mapeditor/dialogs src/tiled/mapeditor/plugin src/tiled/mapeditor/resources src/tiled/mapeditor/util src/tiled/mapeditor/widget src/tiled/view

svn at biggeruniverse.com svn at biggeruniverse.com
Sat Oct 7 14:37:02 PDT 2006


Author: bjorn
Date: 2006-10-07 16:37:01 -0500 (Sat, 07 Oct 2006)
New Revision: 700

Added:
   trunk/src/tiled/mapeditor/util/ConfirmableFileFilter.java
   trunk/src/tiled/mapeditor/util/ConfirmingFileChooser.java
Removed:
   trunk/src/tiled/view/ObliqueMapView.java
Modified:
   trunk/CHANGES
   trunk/TODO
   trunk/plugins/json/src/org/json/JSONArray.java
   trunk/plugins/json/src/org/json/JSONObject.java
   trunk/plugins/json/src/org/json/JSONTokener.java
   trunk/plugins/mappy/src/tiled/plugins/mappy/MappyMapWriter.java
   trunk/src/tiled/core/Map.java
   trunk/src/tiled/core/Sprite.java
   trunk/src/tiled/core/TileSet.java
   trunk/src/tiled/io/PluginLogger.java
   trunk/src/tiled/io/xml/XMLMapTransformer.java
   trunk/src/tiled/io/xml/XMLMapWriter.java
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/actions/SaveAsAction.java
   trunk/src/tiled/mapeditor/animation/AnimationDialog.java
   trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java
   trunk/src/tiled/mapeditor/dialogs/ImageColorDialog.java
   trunk/src/tiled/mapeditor/dialogs/NewMapDialog.java
   trunk/src/tiled/mapeditor/plugin/PluginClassLoader.java
   trunk/src/tiled/mapeditor/resources/gui.properties
   trunk/src/tiled/mapeditor/util/TiledFileFilter.java
   trunk/src/tiled/mapeditor/util/TilesetTableModel.java
   trunk/src/tiled/mapeditor/widget/ImageViewPanel.java
   trunk/src/tiled/view/MapView.java
Log:
Added import/export of configuration after generalizing ConfirmingFileChooser
together with ConfirmableFileFilter. Also removed skeleton of ObliqueMapView
that has been unimplemented ever since this project started and currently not
planned to be implemented, and did some code cleanups.


Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/CHANGES	2006-10-07 21:37:01 UTC (rev 700)
@@ -2,10 +2,12 @@
 
 * Added support for tile instance properties (by Christian Henz)
 * Added ability to create stamp brushes from the tile palette
+* Added import/export of configuration
 * Embedded the tile palette
 * Report out of memory error when saving map as image
 * Properties table now displays the properties in alphabetical order
 * Fixed properties dialog to also save values that were still being edited
+* Fixed automatically adding the file extention when not given
 * Worked around an issue with the open file dialog on GNU classpath
 * Worked around an issue with setting a null cursor on GNU classpath
 

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/TODO	2006-10-07 21:37:01 UTC (rev 700)
@@ -5,10 +5,10 @@
 
 * Remove copy constructors in favour of clone method (DONE)
 
-* Add import/export of options (WIP)
+* Add import/export of options (DONE)
 
-    See about reusing overwrite confirmation and default extension
-    functionality from ConfirmingFileChooser.
+    Update translations for dialog.saveas.confirm.mismatch and add translations
+    for import/export
 
 * Allow embedding of tile palette beneath the map view (WIP)
 

Modified: trunk/plugins/json/src/org/json/JSONArray.java
===================================================================
--- trunk/plugins/json/src/org/json/JSONArray.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/plugins/json/src/org/json/JSONArray.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -99,7 +99,7 @@
 
     /**
      * Construct a JSONArray from a source string.
-     * @param string     A string that begins with 
+     * @param string     A string that begins with
      * <code>[</code>&nbsp;<small>(left bracket)</small>
      *  and ends with <code>]</code>&nbsp;<small>(right bracket)</small>.
      * @exception ParseException The string must conform to JSON syntax.
@@ -120,7 +120,7 @@
 
     /**
      * Get the object value associated with an index.
-     * @param index 
+     * @param index
      *  The index must be between 0 and length() - 1.
      * @return An object value.
      * @exception NoSuchElementException
@@ -166,7 +166,7 @@
 
 
     /**
-     * Get the double value associated with an index.     
+     * Get the double value associated with an index.
      * @param index The index must be between 0 and length() - 1.
      * @return      The value.
      * @exception NoSuchElementException if the key is not found
@@ -181,7 +181,7 @@
             return ((Number) o).doubleValue();
         }
         if (o instanceof String) {
-            return new Double((String)o).doubleValue();
+            return Double.parseDouble((String) o);
         }
         throw new NumberFormatException("JSONObject[" +
             index + "] is not a number.");
@@ -190,7 +190,7 @@
 
     /**
      * Get the int value associated with an index.
-     * 
+     *
      * @param index The index must be between 0 and length() - 1.
      * @return      The value.
      * @exception NoSuchElementException if the key is not found
@@ -383,7 +383,7 @@
                 return ((Number) o).doubleValue();
             }
             try {
-                return new Double((String)o).doubleValue();
+                return Double.parseDouble((String) o);
             }
             catch (Exception e) {
             }
@@ -653,8 +653,8 @@
      * @param indentFactor The number of spaces to add to each level of
      *  indentation.
      * @return a printable, displayable, transmittable
-     *  representation of the object, beginning 
-     *  with <code>[</code>&nbsp;<small>(left bracket)</small> and ending 
+     *  representation of the object, beginning
+     *  with <code>[</code>&nbsp;<small>(left bracket)</small> and ending
      *  with <code>]</code>&nbsp;<small>(right bracket)</small>.
      */
     public String toString(int indentFactor) {

Modified: trunk/plugins/json/src/org/json/JSONObject.java
===================================================================
--- trunk/plugins/json/src/org/json/JSONObject.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/plugins/json/src/org/json/JSONObject.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -159,9 +159,9 @@
 
     /**
      * Construct a JSONObject from a string.
-     * 
-     * @param string    A string beginning 
-     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending 
+     *
+     * @param string    A string beginning
+     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending
      *  with <code>}</code>&nbsp;<small>(right brace)</small>.
      *  @exception ParseException The string must be properly formatted.
      */
@@ -186,7 +186,7 @@
      * JSONArray is stored under the key to hold all of the accumulated values.
      * If there is already a JSONArray, then the new value is appended to it.
      * In contrast, the put method replaces the previous value.
-     * 
+     *
      * @param key   A key string.
      * @param value An object to be accumulated under the key.
      * @return this.
@@ -213,8 +213,8 @@
 
     /**
      * Get the value object associated with a key.
-     * 
      *
+     *
      * @param key   A key string.
      * @return      The object associated with the key.
      * @exception NoSuchElementException if the key is not found.
@@ -233,7 +233,7 @@
      * Get the boolean value associated with a key.
      * @param key   A key string.
      * @return      The truth.
-     * 
+     *
      * @exception NoSuchElementException if the key is not found.
      * @exception ClassCastException
      *  if the value is not a Boolean or the String "true" or "false".
@@ -267,7 +267,7 @@
             return ((Number)o).doubleValue();
         }
         if (o instanceof String) {
-            return new Double((String)o).doubleValue();
+            return Double.parseDouble((String) o);
         }
         throw new NumberFormatException("JSONObject[" +
             quote(key) + "] is not a number.");
@@ -336,7 +336,7 @@
 
 
     /**
-     * Get the string associated with a key.     
+     * Get the string associated with a key.
      * @param key   A key string.
      * @return      A string which is the value.
      * @exception NoSuchElementException if the key is not found.
@@ -518,7 +518,7 @@
                 return ((Number)o).doubleValue();
             }
             try {
-                return new Double((String)o).doubleValue();
+                return Double.parseDouble((String) o);
             }
             catch (Exception e) {
             }
@@ -800,8 +800,8 @@
      * Warning: This method assumes that the data structure is acyclical.
      *
      * @return a printable, displayable, portable, transmittable
-     *  representation of the object, beginning 
-     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending 
+     *  representation of the object, beginning
+     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending
      *  with <code>}</code>&nbsp;<small>(right brace)</small>.
      */
     public String toString() {
@@ -842,7 +842,7 @@
      *  indentation.
      * @return a printable, displayable, portable, transmittable
      *  representation of the object, beginning
-     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending 
+     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending
      *  with <code>}</code>&nbsp;<small>(right brace)</small>.
      */
     public String toString(int indentFactor) {
@@ -858,8 +858,8 @@
      *  indentation.
      * @param indent The indentation of the top level.
      * @return a printable, displayable, transmittable
-     *  representation of the object, beginning 
-     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending 
+     *  representation of the object, beginning
+     *  with <code>{</code>&nbsp;<small>(left brace)</small> and ending
      *  with <code>}</code>&nbsp;<small>(right brace)</small>.
      */
     String toString(int indentFactor, int indent) {

Modified: trunk/plugins/json/src/org/json/JSONTokener.java
===================================================================
--- trunk/plugins/json/src/org/json/JSONTokener.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/plugins/json/src/org/json/JSONTokener.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -109,7 +109,7 @@
 
 
     /**
-     * Get the next n characters.     
+     * Get the next n characters.
      * @param n     The number of characters to take.
      * @return      A string of n characters.
      * @exception ParseException
@@ -319,7 +319,7 @@
             } catch (Exception e) {
             }
         }
-        if (s.equals("")) {
+        if (s.length() == 0) {
             throw syntaxError("Missing value.");
         }
         return s;

Modified: trunk/plugins/mappy/src/tiled/plugins/mappy/MappyMapWriter.java
===================================================================
--- trunk/plugins/mappy/src/tiled/plugins/mappy/MappyMapWriter.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/plugins/mappy/src/tiled/plugins/mappy/MappyMapWriter.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -27,7 +27,7 @@
  */
 public class MappyMapWriter implements MapWriter
 {
-    private LinkedList chunks;
+    private final LinkedList chunks;
 
     public MappyMapWriter() {
         chunks = new LinkedList();
@@ -51,13 +51,12 @@
         System.out.println("Asked to write "+filename);
     }
 
-    public void writeMap(Map map, OutputStream in) throws Exception {
-        in.write("FORM".getBytes());
+    public void writeMap(Map map, OutputStream out) throws Exception {
+        out.write("FORM".getBytes());
         // TODO: write the size of the file minus this header
-        in.write("FMAP".getBytes());
+        out.write("FMAP".getBytes());
         createMPHDChunk(map);
 
-
         // TODO: write all the chunks
     }
 
@@ -104,14 +103,14 @@
     }
 
 
-    private void createMPHDChunk(Map m) throws IOException {
-        Chunk c = new Chunk("MPHD");
-        OutputStream out = c.getOutputStream();
-        String ver = m.getProperties().getProperty("version");
+    private void createMPHDChunk(Map map) throws IOException {
+        Chunk chunk = new Chunk("MPHD");
+        OutputStream out = chunk.getOutputStream();
+        String ver = map.getProperties().getProperty("version");
         if (ver == null || ver.length() < 3) {
             ver = "0.3";                            // default the value
         }
-        TileSet set = (TileSet) m.getTilesets().get(0);
+        TileSet set = (TileSet) map.getTilesets().get(0);
 
         //FIXME
         //out.write(Integer.parseInt(ver.substring(0,ver.indexOf('.')-1)));
@@ -119,29 +118,31 @@
         out.write(0);
         out.write(3);
         out.write(1); out.write(0);                 // LSB, reserved
-        Util.writeShort(m.getWidth(), out);  Util.writeShort(m.getHeight(), out);
+        Util.writeShort(map.getWidth(), out);
+        Util.writeShort(map.getHeight(), out);
         out.write(0); out.write(0); out.write(0); out.write(0);     // reserved
-        Util.writeShort(m.getTileWidth(), out); Util.writeShort(m.getTileHeight(), out);
+        Util.writeShort(map.getTileWidth(), out);
+        Util.writeShort(map.getTileHeight(), out);
         Util.writeShort(16, out);                   // tile bitdepth
         Util.writeShort(32, out);                   // blkstr bytewidth
-        Util.writeShort(findAllBlocks(m).size(), out);
+        Util.writeShort(findAllBlocks(map).size(), out);
         Util.writeShort(set.getMaxTileId(), out);
 
-        chunks.add(c);
+        chunks.add(chunk);
     }
 
-    private void createBKDTChunk(Map m) {
-        Chunk c = new Chunk("BKDT");
-        LinkedList blocks = findAllBlocks(m);
+    private void createBKDTChunk(Map map) {
+        Chunk chunk = new Chunk("BKDT");
+        LinkedList blocks = findAllBlocks(map);
         Iterator itr = blocks.iterator();
         while(itr.hasNext()) {
             MappyMapReader.BlkStr b = (BlkStr) itr.next();
             // TODO: write the block
         }
-        chunks.add(c);
+        chunks.add(chunk);
     }
 
-    private LinkedList findAllBlocks(Map m) {
+    private LinkedList findAllBlocks(Map map) {
         // TODO: this
         return null;
     }

Modified: trunk/src/tiled/core/Map.java
===================================================================
--- trunk/src/tiled/core/Map.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/core/Map.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -31,8 +31,6 @@
     public static final int MDO_ORTHO   = 1;
     /** Isometric. */
     public static final int MDO_ISO     = 2;
-    /** Oblique. */
-    public static final int MDO_OBLIQUE = 3;
     /** Hexagonal. */
     public static final int MDO_HEX     = 4;
     /** Shifted (used for iso and hex). */
@@ -74,7 +72,7 @@
 
     /**
      * Removes a change listener.
-     * @param listener
+     * @param listener the listener to remove
      */
     public void removeMapChangeListener(MapChangeListener listener) {
         mapChangeListeners.remove(listener);
@@ -97,6 +95,8 @@
     /**
      * Notifies all registered map change listeners about the removal of a
      * tileset.
+     *
+     * @param index the index of the removed tileset
      */
     protected void fireTilesetRemoved(int index) {
         Iterator iterator = mapChangeListeners.iterator();
@@ -111,6 +111,8 @@
     /**
      * Notifies all registered map change listeners about the addition of a
      * tileset.
+     *
+     * @param tileset the new tileset
      */
     protected void fireTilesetAdded(TileSet tileset) {
         Iterator iterator = mapChangeListeners.iterator();
@@ -196,7 +198,8 @@
      * processing is complete.
      *
      * @param tileset TileSet to remove
-     * @throws LayerLockedException
+     * @throws LayerLockedException when the tileset is in use on a locked
+     *         layer
      */
     public void removeTileset(TileSet tileset) throws LayerLockedException {
         // Sanity check
@@ -372,14 +375,15 @@
      * Get the tile set that matches the given global tile id, only to be used
      * when loading a map.
      *
-     * @param gid
-     * @return TileSet
+     * @param gid a global tile id
+     * @return the tileset containing the tile with the given global tile id,
+     *         or <code>null</code> when no such tileset exists
      */
     public TileSet findTileSetForTileGID(int gid) {
         Iterator itr = tilesets.iterator();
         TileSet has = null;
         while (itr.hasNext()) {
-            TileSet ts = (TileSet)itr.next();
+            TileSet ts = (TileSet) itr.next();
             if (ts.getFirstGid() <= gid) {
                 has = ts;
             }
@@ -474,7 +478,7 @@
     /**
      * Returns the orientation of this map. Orientation will be one of
      * {@link Map#MDO_ISO}, {@link Map#MDO_ORTHO}, {@link Map#MDO_HEX},
-     * {@link Map#MDO_OBLIQUE} and {@link Map#MDO_SHIFTED}.
+     * and {@link Map#MDO_SHIFTED}.
      *
      * @return The orientation from the enumerated set
      */

Modified: trunk/src/tiled/core/Sprite.java
===================================================================
--- trunk/src/tiled/core/Sprite.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/core/Sprite.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -5,69 +5,73 @@
  *  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;
 
-import java.awt.*;
+import java.awt.Image;
+import java.awt.Rectangle;
 import java.util.Iterator;
 import java.util.Vector;
 
-public class Sprite {
-
+/**
+ * @version $Id$
+ */
+public class Sprite
+{
     private Vector keys;
     private int borderWidth = 0;
     private int fpl = 0;
     private int totalKeys = -1;
 
-    private float currentFrame=0;
+    private float currentFrame = 0;
     private Rectangle frameSize;
-    private boolean bPlaying=true;
+    private boolean bPlaying = true;
 
     public class KeyFrame
     {
-    	public static final int MASK_ANIMATION = 0x0000000F;
-    	
-        public static final int KEY_LOOP    = 0x01;
-        public static final int KEY_STOP    = 0x02;
-        public static final int KEY_AUTO    = 0x04;
+        public static final int MASK_ANIMATION = 0x0000000F;
+
+        public static final int KEY_LOOP = 0x01;
+        public static final int KEY_STOP = 0x02;
+        public static final int KEY_AUTO = 0x04;
         public static final int KEY_REVERSE = 0x08;
 
         public static final int KEY_NAME_LENGTH_MAX = 32;
 
-        private String name=null;
-        private int id=-1;
-        private int flags=KEY_LOOP;
-        private float frameRate=1.0f;   //one fps
-        private Tile [] frames; 
+        private String name = null;
+        private int id = -1;
+        private int flags = KEY_LOOP;
+        private float frameRate = 1.0f;   //one fps
+        private Tile[] frames;
 
         public KeyFrame() {
-            flags=KEY_LOOP;
+            flags = KEY_LOOP;
         }
 
         public KeyFrame(String name) {
-        	this();
-            this.name=name;
+            this();
+            this.name = name;
         }
 
-        public KeyFrame(String name, Tile [] tile) {
-        	this(name);
-        	this.frames = tile;
+        public KeyFrame(String name, Tile[] tile) {
+            this(name);
+            frames = tile;
         }
 
         public void setName(String name) {
-            this.name=name;
+            this.name = name;
         }
 
         public void setFrameRate(float r) {
-            frameRate=r;
+            frameRate = r;
         }
 
         public void setId(int id) {
-            this.id=id;
+            this.id = id;
         }
 
         public int getId() {
@@ -75,15 +79,15 @@
         }
 
         public int getLastFrame() {
-        	return frames.length-1;
+            return frames.length - 1;
         }
-        
+
         public boolean isFrameLast(int frame) {
-        	return frames.length-1==frame;
+            return frames.length - 1 == frame;
         }
-        
+
         public void setFlags(int f) {
-            flags=f;
+            flags = f;
         }
 
         public int getFlags() {
@@ -95,160 +99,158 @@
         }
 
         public Tile getFrame(int f) {
-        	if(f > 0 && f < frames.length) {
-        		return frames[f];
-        	}
-        	return null;
+            if (f > 0 && f < frames.length) {
+                return frames[f];
+            }
+            return null;
         }
-        
+
         public float getFrameRate() {
             return frameRate;
         }
 
         public int getTotalFrames() {
-        	return frames.length;
+            return frames.length;
         }
-        
+
         public boolean equalsIgnoreCase(String n) {
-            if (name!=null)
-                return(name.equalsIgnoreCase(n));
-            return(false);
+            return name != null && name.equalsIgnoreCase(n);
         }
 
         public String toString() {
-            return "("+name+")"+id+": @ "+frameRate;
+            return "(" + name + ")" + id + ": @ " + frameRate;
         }
     }
 
-    private KeyFrame currentKey=null;
-    
+    private KeyFrame currentKey = null;
+
     public Sprite() {
         frameSize = new Rectangle();
         keys = new Vector();
     }
 
     public Sprite(Tile[] frames) {
-    	setFrames(frames);
+        setFrames(frames);
     }
-    
-    public Sprite(Image image, int fpl, int border,int totalFrames) {
-        Tile [] frames = null;
-        this.fpl=fpl;
-        borderWidth=border;
 
+    public Sprite(Image image, int fpl, int border, int totalFrames) {
+        Tile[] frames = null;
+        this.fpl = fpl;
+        borderWidth = border;
+
         //TODO: break up the image into tiles
-        
+
         //given this information, extrapolate the rest...
-        
-        frameSize.width=image.getWidth(null)/(fpl+borderWidth*fpl);
-        frameSize.height=(int) (image.getHeight(null)/(Math.ceil(totalFrames/fpl)+Math.ceil(totalFrames/fpl)*borderWidth));
+
+        frameSize.width = image.getWidth(null) / (fpl + borderWidth * fpl);
+        frameSize.height = (int) (image.getHeight(null) / (Math.ceil(totalFrames / fpl) + Math.ceil(totalFrames / fpl) * borderWidth));
         createKey("", frames, KeyFrame.KEY_LOOP);
     }
 
-    public void setFrames(Tile [] frames) {
-    	frameSize=new Rectangle(0,0,frames[0].getWidth(),frames[0].getHeight());
-    	
-    	createKey("", frames, KeyFrame.KEY_LOOP);
+    public void setFrames(Tile[] frames) {
+        frameSize = new Rectangle(0, 0, frames[0].getWidth(), frames[0].getHeight());
+
+        createKey("", frames, KeyFrame.KEY_LOOP);
     }
 
     public void setFrameSize(int w, int h) {
-        frameSize.width=w;
-        frameSize.height=h;
+        frameSize.width = w;
+        frameSize.height = h;
     }
 
     public void setBorderWidth(int b) {
-        borderWidth=b;
+        borderWidth = b;
     }
 
     public void setFpl(int f) {
-        fpl=f;
+        fpl = f;
     }
 
     public void setCurrentFrame(float c) {
-    	if (c < 0) {
-    		switch(currentKey.flags & KeyFrame.MASK_ANIMATION) {
-    			case KeyFrame.KEY_LOOP:
-    				currentFrame = currentKey.getLastFrame();
-    			break;
-    			case KeyFrame.KEY_AUTO:
-    				currentKey = getPreviousKey();
-    				currentFrame = currentKey.getLastFrame();
-    			break;
-    			case KeyFrame.KEY_REVERSE:
-    				currentKey.setFrameRate(-currentKey.getFrameRate());
-    				currentFrame = 0;
-    			break;
-    			case KeyFrame.KEY_STOP:
-    				bPlaying = false;
-    				currentFrame = 0;
-    			break;
-    		}
-    	} else if (c > currentKey.getLastFrame()) {
-    		switch(currentKey.flags & KeyFrame.MASK_ANIMATION) {
-				case KeyFrame.KEY_LOOP:
-					currentFrame = 0;
-				break;
-				case KeyFrame.KEY_AUTO:
-					currentFrame = 0;
-					currentKey = getNextKey();
-				break;
-				case KeyFrame.KEY_REVERSE:
-					currentKey.setFrameRate(-currentKey.getFrameRate());
-					currentFrame = currentKey.getLastFrame();
-				break;
-				case KeyFrame.KEY_STOP:
-					bPlaying = false;
-					currentFrame = currentKey.getLastFrame();
-				break;
-    		}
-    	} else {
-    		currentFrame=c;
-    	}
+        if (c < 0) {
+            switch (currentKey.flags & KeyFrame.MASK_ANIMATION) {
+                case KeyFrame.KEY_LOOP:
+                    currentFrame = currentKey.getLastFrame();
+                    break;
+                case KeyFrame.KEY_AUTO:
+                    currentKey = getPreviousKey();
+                    currentFrame = currentKey.getLastFrame();
+                    break;
+                case KeyFrame.KEY_REVERSE:
+                    currentKey.setFrameRate(-currentKey.getFrameRate());
+                    currentFrame = 0;
+                    break;
+                case KeyFrame.KEY_STOP:
+                    bPlaying = false;
+                    currentFrame = 0;
+                    break;
+            }
+        } else if (c > currentKey.getLastFrame()) {
+            switch (currentKey.flags & KeyFrame.MASK_ANIMATION) {
+                case KeyFrame.KEY_LOOP:
+                    currentFrame = 0;
+                    break;
+                case KeyFrame.KEY_AUTO:
+                    currentFrame = 0;
+                    currentKey = getNextKey();
+                    break;
+                case KeyFrame.KEY_REVERSE:
+                    currentKey.setFrameRate(-currentKey.getFrameRate());
+                    currentFrame = currentKey.getLastFrame();
+                    break;
+                case KeyFrame.KEY_STOP:
+                    bPlaying = false;
+                    currentFrame = currentKey.getLastFrame();
+                    break;
+            }
+        } else {
+            currentFrame = c;
+        }
     }
 
     public void setTotalKeys(int t) {
-        totalKeys=t;
+        totalKeys = t;
     }
 
     public Rectangle getFrameSize() {
-        return(frameSize);
+        return frameSize;
     }
 
     public int getTotalFrames() {
-    	int total = 0;
-    	Iterator itr = keys.iterator();
-    	while (itr.hasNext()) {
-    		total += ((KeyFrame)itr.next()).getTotalFrames();
-    	}
-    	
-        return(total);
+        int total = 0;
+        Iterator itr = keys.iterator();
+        while (itr.hasNext()) {
+            total += ((KeyFrame) itr.next()).getTotalFrames();
+        }
+
+        return total;
     }
 
     public int getBorderWidth() {
-        return(borderWidth);
+        return borderWidth;
     }
 
     public Tile getCurrentFrame() {
-    	return currentKey.getFrame((int)currentFrame);
+        return currentKey.getFrame((int) currentFrame);
     }
 
     public KeyFrame getNextKey() {
-    	Iterator itr = keys.iterator();
-    	while(itr.hasNext()) {
-    		KeyFrame k = (KeyFrame)itr.next();
-    		if(k == currentKey) {
-    			if(itr.hasNext()) return (KeyFrame)itr.next();
-    		}
-    	}
-    	
-    	return (KeyFrame)keys.get(0);
+        Iterator itr = keys.iterator();
+        while (itr.hasNext()) {
+            KeyFrame k = (KeyFrame) itr.next();
+            if (k == currentKey) {
+                if (itr.hasNext()) return (KeyFrame) itr.next();
+            }
+        }
+
+        return (KeyFrame) keys.get(0);
     }
-    
+
     public KeyFrame getPreviousKey() {
-    	//TODO: this
-    	return null;
+        //TODO: this
+        return null;
     }
-    
+
     public KeyFrame getCurrentKey() {
         return currentKey;
     }
@@ -263,12 +265,12 @@
 
     public void setKeyFrameTo(String name) {
         Iterator itr = keys.iterator();
-        while(itr.hasNext()) {
-        	KeyFrame k = (KeyFrame) itr.next();
-        	if(k.equalsIgnoreCase(name)) {
-        		currentKey=k;
-        		break;
-        	}
+        while (itr.hasNext()) {
+            KeyFrame k = (KeyFrame) itr.next();
+            if (k.equalsIgnoreCase(name)) {
+                currentKey = k;
+                break;
+            }
         }
     }
 
@@ -281,7 +283,7 @@
         keys.remove(getKey(name));
     }
 
-    public void createKey(String name, Tile [] frames, int flags) {
+    public void createKey(String name, Tile[] frames, int flags) {
         KeyFrame kf = new KeyFrame(name, frames);
         kf.setName(name);
         kf.setFlags(flags);
@@ -290,16 +292,17 @@
 
     public void iterateFrame() {
 
-        if (currentKey!=null) {
+        if (currentKey != null) {
             if (bPlaying) {
-                setCurrentFrame(currentFrame+currentKey.getFrameRate());
+                setCurrentFrame(currentFrame + currentKey.getFrameRate());
             }
         }
     }
 
     /**
      * Sets the current frame relative to the starting frame of the
-     * current key. 
+     * current key.
+     *
      * @param c
      */
     public void keySetFrame(int c) {
@@ -315,50 +318,52 @@
     }
 
     public void keyStepBack(int amt) {
-        setCurrentFrame(currentFrame-amt);
+        setCurrentFrame(currentFrame - amt);
     }
 
     public void keyStepForward(int amt) {
-        setCurrentFrame(currentFrame+amt);
+        setCurrentFrame(currentFrame + amt);
     }
 
     public KeyFrame getKey(String keyName) {
         Iterator itr = keys.iterator();
         while (itr.hasNext()) {
-        	KeyFrame k = (KeyFrame) itr.next();
-        	if (k != null && k.equalsIgnoreCase(keyName)) {
-        		return k;
-        	}
+            KeyFrame k = (KeyFrame) itr.next();
+            if (k != null && k.equalsIgnoreCase(keyName)) {
+                return k;
+            }
         }
         return null;
     }
 
-	public KeyFrame getKey(int i) {
-		return (KeyFrame)keys.get(i);
-	}
+    public KeyFrame getKey(int i) {
+        return (KeyFrame) keys.get(i);
+    }
 
-    public Iterator getKeys() throws Exception{
+    public Iterator getKeys() throws Exception {
         return keys.iterator();
     }
 
     public Rectangle getCurrentFrameRect() {
         int x = 0, y = 0;
-        
-        if(frameSize.height>0 && frameSize.width>0) {
-	        y=(((int)currentFrame)/fpl)*(frameSize.height+borderWidth);
-	        x=(((int)currentFrame)%fpl)*(frameSize.width+borderWidth);
+
+        if (frameSize.height > 0 && frameSize.width > 0) {
+            y = ((int) currentFrame / fpl) * (frameSize.height + borderWidth);
+            x = ((int) currentFrame % fpl) * (frameSize.width + borderWidth);
         }
-        
-    	return new Rectangle(x, y, frameSize.width, frameSize.height);
+
+        return new Rectangle(x, y, frameSize.width, frameSize.height);
     }
 
     /**
      * @see Object#toString()
      */
     public String toString() {
-        String s = null;
-        s = "Frame: ("+frameSize.width+"x"+frameSize.height+")\nBorder: "+borderWidth+"\nFPL: "+fpl+"\nTotal Frames: "+getTotalFrames()+"\nTotal keys: "+totalKeys;
-        return s;
+        return "Frame: (" + frameSize.width + "x" + frameSize.height + ")\n" +
+                "Border: " + borderWidth + "\n" +
+                "FPL: " + fpl + "\n" +
+                "Total Frames: " + getTotalFrames() + "\n" +
+                "Total keys: " + totalKeys;
     }
 }
 

Modified: trunk/src/tiled/core/TileSet.java
===================================================================
--- trunk/src/tiled/core/TileSet.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/core/TileSet.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -361,7 +361,7 @@
      */
     public Tile getTile(int i) {
         try {
-            return (Tile)tiles.get(i);
+            return (Tile) tiles.get(i);
         } catch (ArrayIndexOutOfBoundsException a) {}
         return null;
     }
@@ -374,9 +374,10 @@
      */
     public Tile getFirstTile() {
         Tile ret = null;
-        final Iterator itr = iterator();
-        if (itr.hasNext()) {
-            ret = (Tile)itr.next();
+        int i = 0;
+        while (ret == null && i <= getMaxTileId()) {
+            ret = getTile(i);
+            i++;
         }
         return ret;
     }

Modified: trunk/src/tiled/io/PluginLogger.java
===================================================================
--- trunk/src/tiled/io/PluginLogger.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/io/PluginLogger.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -19,26 +19,27 @@
  */
 public class PluginLogger
 {
-	private LinkedList messages;
+    private LinkedList messages = new LinkedList();
 
-	public void error(Object message) {
-	}
+    public void error(Object message) {
+    }
 
-	public void warn(Object message) {
-	}
+    public void warn(Object message) {
+    }
 
-	public void info(Object message) {
-	}
-	
-	public void debug(Object message) {
-	}
+    public void info(Object message) {
+    }
 
-	public boolean isEmpty() {
-		return messages.isEmpty();
-	}
+    public void debug(Object message) {
+    }
 
-	public class PluginMessage {
-		private int type;
-		private Object message;
-	}
+    public boolean isEmpty() {
+        return messages.isEmpty();
+    }
+
+    public class PluginMessage
+    {
+        private int type;
+        private Object message;
+    }
 }


Property changes on: trunk/src/tiled/io/PluginLogger.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/src/tiled/io/xml/XMLMapTransformer.java
===================================================================
--- trunk/src/tiled/io/xml/XMLMapTransformer.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/io/xml/XMLMapTransformer.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -57,7 +57,7 @@
         if (filename.indexOf("://") > 0 || filename.startsWith("file:")) {
             url = filename;
         } else {
-            url = (new File(filename)).toURL().toString();
+            url = new File(filename).toURL().toString();
         }
         return url;
     }
@@ -73,7 +73,7 @@
     }
 
     private void reflectInvokeMethod(Object invokeVictim, Method method,
-            String[] args) throws InvocationTargetException, Exception
+            String[] args) throws Exception
     {
         Class[] parameterTypes = method.getParameterTypes();
         Object[] conformingArguments = new Object[parameterTypes.length];
@@ -109,8 +109,6 @@
             map.setOrientation(Map.MDO_ORTHO);
         } else if ("hexagonal".equalsIgnoreCase(o)) {
             map.setOrientation(Map.MDO_HEX);
-        } else if ("oblique".equalsIgnoreCase(o)) {
-            map.setOrientation(Map.MDO_OBLIQUE);
         } else if ("shifted".equalsIgnoreCase(o)) {
             map.setOrientation(Map.MDO_SHIFTED);
         } else {
@@ -180,8 +178,7 @@
         return o;
     }
 
-    private Image unmarshalImage(Node t, String baseDir)
-        throws MalformedURLException, IOException
+    private Image unmarshalImage(Node t, String baseDir) throws IOException
     {
         Image img = null;
 
@@ -200,9 +197,9 @@
             NodeList nl = t.getChildNodes();
 
             for (int i = 0; i < nl.getLength(); i++) {
-                Node n = nl.item(i);
-                if ("data".equals(n.getNodeName())) {
-                    Node cdata = n.getFirstChild();
+                Node node = nl.item(i);
+                if ("data".equals(node.getNodeName())) {
+                    Node cdata = node.getFirstChild();
                     if (cdata == null) {
                         logger.warn("image <data> tag enclosed no " +
                                 "data. (empty data tag)");
@@ -243,13 +240,12 @@
     {
         TileSet set = null;
         Node tsNode;
-        Document tsDoc = null;
 
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         try {
             DocumentBuilder builder = factory.newDocumentBuilder();
             //builder.setErrorHandler(new XMLErrorHandler());
-            tsDoc = builder.parse(in, ".");
+            Document tsDoc = builder.parse(in, ".");
 
             String xmlPathSave = xmlPath;
             if (filename.indexOf(File.separatorChar) >= 0) {
@@ -259,15 +255,15 @@
 
             NodeList tsNodeList = tsDoc.getElementsByTagName("tileset");
 
-            for (int itr = 0; (tsNode = tsNodeList.item(itr)) != null; itr++) {
+            // There can be only one tileset in a .tsx file.
+            tsNode = tsNodeList.item(0);
+            if (tsNode != null)
+            {
                 set = unmarshalTileset(tsNode);
                 if (set.getSource() != null) {
                     logger.warn("Recursive external Tilesets are not supported.");
                 }
                 set.setSource(filename);
-                // NOTE: This is a deliberate break. multiple tilesets per TSX are
-                // not supported yet (maybe never)...
-                break;
             }
 
             xmlPath = xmlPathSave;
@@ -693,7 +689,7 @@
         }
     }
 
-    private Map unmarshal(InputStream in) throws IOException, Exception {
+    private Map unmarshal(InputStream in) throws Exception {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         Document doc;
         try {

Modified: trunk/src/tiled/io/xml/XMLMapWriter.java
===================================================================
--- trunk/src/tiled/io/xml/XMLMapWriter.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/io/xml/XMLMapWriter.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -114,8 +114,6 @@
                 w.writeAttribute("orientation", "orthogonal"); break;
             case Map.MDO_ISO:
                 w.writeAttribute("orientation", "isometric"); break;
-            case Map.MDO_OBLIQUE:
-                w.writeAttribute("orientation", "oblique"); break;
             case Map.MDO_HEX:
                 w.writeAttribute("orientation", "hexagonal"); break;
             case Map.MDO_SHIFTED:

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -491,6 +491,8 @@
 
     /**
      * Creates the tool bar.
+     *
+     * @return the created tool bar
      */
     private JToolBar createToolBar() {
         Icon iconMove = Resources.getIcon("gimp-tool-move-22.png");
@@ -1181,11 +1183,11 @@
             }
         } else if (command.equals(Resources.getString("menu.tilesets.import"))) {
             if (currentMap != null) {
-                JFileChooser ch = new JFileChooser(currentMap.getFilename());
+                JFileChooser chooser = new JFileChooser(currentMap.getFilename());
                 MapReader[] readers = pluginLoader.getReaders();
                 for (int i = 0; i < readers.length; i++) {
                     try {
-                        ch.addChoosableFileFilter(new TiledFileFilter(
+                        chooser.addChoosableFileFilter(new TiledFileFilter(
                                     readers[i].getFilter(),
                                     readers[i].getName()));
                     } catch (Exception e) {
@@ -1193,12 +1195,12 @@
                     }
                 }
 
-                ch.addChoosableFileFilter(
+                chooser.addChoosableFileFilter(
                         new TiledFileFilter(TiledFileFilter.FILTER_TSX));
 
-                int ret = ch.showOpenDialog(appFrame);
+                int ret = chooser.showOpenDialog(appFrame);
                 if (ret == JFileChooser.APPROVE_OPTION) {
-                    String filename = ch.getSelectedFile().getAbsolutePath();
+                    String filename = chooser.getSelectedFile().getAbsolutePath();
                     try {
                         TileSet set = MapHelper.loadTileset(filename);
                         currentMap.addTileset(set);
@@ -1257,8 +1259,8 @@
                 new PluginDialog(appFrame, pluginLoader);
             pluginDialog.setVisible(true);
         } else if (command.equals(Resources.getString("menu.edit.preferences"))) {
-            ConfigurationDialog d = new ConfigurationDialog(appFrame);
-            d.configure();
+            ConfigurationDialog dialog = new ConfigurationDialog(appFrame);
+            dialog.configure();
         } else {
             System.out.println(event);
         }
@@ -1747,8 +1749,8 @@
         }
     }
 
-    public void setBrush(AbstractBrush b) {
-        currentBrush = b;
+    public void setBrush(AbstractBrush brush) {
+        currentBrush = brush;
 
         Rectangle brushRedraw = currentBrush.getBounds();
 
@@ -1807,10 +1809,10 @@
         }
 
         try {
-            Map m = MapHelper.loadMap(file);
+            Map map = MapHelper.loadMap(file);
 
-            if (m != null) {
-                setCurrentMap(m);
+            if (map != null) {
+                setCurrentMap(map);
                 updateRecent(file);
                 return true;
             } else {
@@ -1840,11 +1842,12 @@
      */
     public void saveMapImage(String filename) {
         if (filename == null) {
-            JFileChooser ch = new JFileChooser();
-            ch.setDialogTitle("Save as image");
+            JFileChooser chooser = new JFileChooser();
+            chooser.setDialogTitle("Save as image");
 
-            if (ch.showSaveDialog(appFrame) == JFileChooser.APPROVE_OPTION) {
-                filename = ch.getSelectedFile().getAbsolutePath();
+            if (chooser.showSaveDialog(appFrame) ==
+                    JFileChooser.APPROVE_OPTION) {
+                filename = chooser.getSelectedFile().getAbsolutePath();
             }
         }
 
@@ -1853,32 +1856,33 @@
             myView.setShowGrid(mapView.getShowGrid());
             myView.setMode(MapView.PF_NOSPECIAL, true);
             myView.setZoom(mapView.getZoom());
-            Dimension d = myView.getPreferredSize();
+            Dimension imgSize = myView.getPreferredSize();
 
             try {
-                BufferedImage i = new BufferedImage(d.width, d.height,
-                                                    BufferedImage.TYPE_INT_ARGB);
-                Graphics2D g = i.createGraphics();
-                g.setClip(0, 0, d.width, d.height);
+                BufferedImage img = new BufferedImage(
+                        imgSize.width, imgSize.height, BufferedImage.TYPE_INT_ARGB);
+                Graphics2D g = img.createGraphics();
+                g.setClip(0, 0, imgSize.width, imgSize.height);
                 myView.paint(g);
 
-                String format = filename.substring(filename.lastIndexOf('.') + 1);
+                int lastDot = filename.lastIndexOf('.');
+                String format = filename.substring(lastDot + 1);
 
                 try {
-                    ImageIO.write(i, format, new File(filename));
+                    ImageIO.write(img, format, new File(filename));
                 } catch (IOException e) {
                     e.printStackTrace();
                     JOptionPane.showMessageDialog(appFrame,
-                                                  "Error while saving " + filename + ": " + e.toString(),
-                                                  "Error while saving map image",
-                                                  JOptionPane.ERROR_MESSAGE);
+                            "Error while saving " + filename + ": " + e.toString(),
+                            "Error while saving map image",
+                            JOptionPane.ERROR_MESSAGE);
                 }
             } catch (OutOfMemoryError memoryError) {
                 JOptionPane.showMessageDialog(appFrame,
-                                              "Out of memory while creating image. Try increasing\n" +
-                                                      "your maximum heap size or zooming out a bit.",
-                                              "Out of memory",
-                                              JOptionPane.ERROR_MESSAGE);
+                        "Out of memory while creating image. Try increasing\n" +
+                                "your maximum heap size or zooming out a bit.",
+                        "Out of memory",
+                        JOptionPane.ERROR_MESSAGE);
             }
         }
     }
@@ -1981,12 +1985,7 @@
             if (!tilesets.isEmpty()) {
                 Iterator it = tilesets.iterator();
                 while (it.hasNext() && firstTile == null) {
-                    TileSet set = (TileSet) it.next();
-                    int i = 0;
-                    while (firstTile == null && i <= set.getMaxTileId()) {
-                        firstTile = set.getTile(i);
-                        i++;
-                    }
+                    firstTile = ((TileSet) it.next()).getFirstTile();
                 }
             }
             setCurrentTile(firstTile);

Modified: trunk/src/tiled/mapeditor/actions/SaveAsAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/SaveAsAction.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/actions/SaveAsAction.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -13,7 +13,6 @@
 package tiled.mapeditor.actions;
 
 import java.awt.event.ActionEvent;
-import java.io.File;
 import javax.swing.AbstractAction;
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
@@ -24,6 +23,7 @@
 import tiled.mapeditor.MapEditor;
 import tiled.mapeditor.Resources;
 import tiled.mapeditor.util.TiledFileFilter;
+import tiled.mapeditor.util.ConfirmingFileChooser;
 import tiled.util.TiledConfiguration;
 
 /**
@@ -38,11 +38,6 @@
 
     private static final String ACTION_NAME = Resources.getString("action.map.saveas.name");
     private static final String ACTION_TOOLTIP = Resources.getString("action.map.saveas.tooltip");
-    private static final String UNKNOWN_TYPE_MESSAGE = Resources.getString("dialog.saveas.unknown-type.message");
-    private static final String CONFIRM_MISMATCH = Resources.getString("dialog.saveas.confirm.mismatch");
-    private static final String CONFIRM_MISMATCH_TITLE = Resources.getString("dialog.saveas.confirm.mismatch.title");
-    private static final String FILE_EXISTS_MESSAGE = Resources.getString("general.file.exists.message");
-    private static final String FILE_EXISTS_TITLE = Resources.getString("general.file.exists.title");
     private static final String SAVEAS_ERROR_MESSAGE = Resources.getString("dialog.saveas.error.message");
     private static final String SAVEAS_ERROR_TITLE = Resources.getString("dialog.saveas.error.title");
 
@@ -64,7 +59,8 @@
     protected void showFileChooser()
     {
         // Start at the location of the most recently loaded map file
-        String startLocation = TiledConfiguration.node("recent").get("file0", "");
+        String startLocation =
+                TiledConfiguration.node("recent").get("file0", null);
 
         TiledFileFilter byExtensionFilter =
                 new TiledFileFilter(TiledFileFilter.FILTER_EXT);
@@ -72,6 +68,7 @@
                 new TiledFileFilter(TiledFileFilter.FILTER_TMX);
 
         JFileChooser chooser = new ConfirmingFileChooser(startLocation);
+        chooser.setAcceptAllFileFilterUsed(false);
         chooser.addChoosableFileFilter(byExtensionFilter);
         chooser.addChoosableFileFilter(tmxFilter);
 
@@ -89,10 +86,14 @@
         int result = chooser.showSaveDialog(editor.getAppFrame());
         if (result == JFileChooser.APPROVE_OPTION)
         {
+            savingCancelled = false;
             TiledFileFilter saver = (TiledFileFilter) chooser.getFileFilter();
             String selectedFile = chooser.getSelectedFile().getAbsolutePath();
             saveFile(saver, selectedFile);
         }
+        else {
+            savingCancelled = true;
+        }
     }
 
     /**
@@ -135,101 +136,4 @@
     {
         return savingCancelled;
     }
-
-    public void resetSavingCancelled ()
-    {
-        savingCancelled = false;
-    }
-
-    /**
-     * This file chooser extends the {@link JFileChooser} in a number of ways.
-     * <ul>
-     *   <li>Adds an extention to the filename based on the file filter, when
-     *       the user didn't specify any.</li>
-     *   <li>If the file to be saved is not accepted by the chosen file filter,
-     *       it confirms that the user really wants to do this. This is done
-     *       because the same file filter is used to determine with which
-     *       plugin to load the file.</li>
-     *   <li>Confirms before overwriting an existing file.</li>
-     * </ul>
-     * This file chooser can only be used with {@link TiledFileFilter}.
-     */
-    private final class ConfirmingFileChooser extends JFileChooser
-    {
-        public ConfirmingFileChooser(String currentDirectoryPath) {
-            super(currentDirectoryPath);
-            setAcceptAllFileFilterUsed(false);
-            setDialogTitle(Resources.getString("dialog.saveas.title"));
-        }
-
-        public void approveSelection ()
-        {
-            File file = new File(getSelectedFile().getAbsolutePath());
-            TiledFileFilter saver = (TiledFileFilter) getFileFilter();
-
-            // If the file does not have an extention, append the first
-            // extension specified by the file filter.
-            String filename = file.getName();
-            int lastDot = filename.lastIndexOf('.');
-
-            if (lastDot == -1 || lastDot == filename.length() - 1) {
-                if (saver.getType() == TiledFileFilter.FILTER_EXT) {
-                    // Impossible to determine extension with this filter
-                    JOptionPane.showMessageDialog(this,
-                                                  UNKNOWN_TYPE_MESSAGE);
-                    return;
-                }
-
-                String newFilePath = file.getAbsolutePath();
-
-                // Add a dot if it wasn't at the end already
-                if (lastDot != filename.length() - 1) {
-                    newFilePath += ".";
-                }
-
-                file = new File(newFilePath + saver.getFirstExtention());
-            }
-
-            // Check that chosen plugin accepts the file. It is a good idea to
-            // warn the user when this is not the case, because loading the map
-            // becomes a problem.
-            if (saver.getType() != TiledFileFilter.FILTER_EXT) {
-                if (!saver.accept(file)) {
-                    int result = JOptionPane.showConfirmDialog(
-                            editor.getAppFrame(),
-                            CONFIRM_MISMATCH, CONFIRM_MISMATCH_TITLE,
-                            JOptionPane.YES_NO_OPTION);
-
-                    if (result != JOptionPane.OK_OPTION) {
-                        return;
-                    }
-                }
-            }
-
-            // Confirm overwrite if the file happens to exist already
-            if (file.exists())
-            {
-                int answer = JOptionPane.showConfirmDialog(
-                        editor.getAppFrame(),
-                        FILE_EXISTS_MESSAGE, FILE_EXISTS_TITLE,
-                        JOptionPane.YES_NO_OPTION);
-
-                if (answer == JOptionPane.YES_OPTION)
-                {
-                    savingCancelled = false;
-                    super.approveSelection();
-                }
-            }
-            else {
-                savingCancelled = false;
-                super.approveSelection();
-            }
-        }
-
-        public void cancelSelection ()
-        {
-            savingCancelled = true;
-            super.cancelSelection();
-        }
-    }
 }

Modified: trunk/src/tiled/mapeditor/animation/AnimationDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/animation/AnimationDialog.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/animation/AnimationDialog.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -198,8 +198,8 @@
             Sprite.KeyFrame k =
                     currentSprite.getKey((String) keyframe.getSelectedItem());
             if (k != null) {
-                lCurrentFrame.setText("" + currentSprite.getCurrentFrame());
-                lFrameRate.setText("" + k.getFrameRate());
+                lCurrentFrame.setText(String.valueOf(currentSprite.getCurrentFrame()));
+                lFrameRate.setText(String.valueOf(k.getFrameRate()));
             }
         }
     }
@@ -320,7 +320,7 @@
     /**
      * Draws checkerboard background.
      */
-    private void paintBackground(Graphics g) {
+    private static void paintBackground(Graphics g) {
         Rectangle clip = g.getClipBounds();
         int side = 10;
 
@@ -345,7 +345,6 @@
     }
 
     public void paint(Graphics g) {
-
         if (owner != null) {
             Dimension d = getSize();
             if (buffer == null) {

Modified: trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/dialogs/ConfigurationDialog.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -20,6 +20,8 @@
 import java.util.prefs.Preferences;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.FileInputStream;
 import javax.swing.*;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
@@ -27,6 +29,8 @@
 import tiled.mapeditor.widget.IntegerSpinner;
 import tiled.mapeditor.widget.VerticalStaticJPanel;
 import tiled.mapeditor.Resources;
+import tiled.mapeditor.util.ConfirmingFileChooser;
+import tiled.mapeditor.util.ConfirmableFileFilter;
 import tiled.util.TiledConfiguration;
 
 /**
@@ -42,10 +46,10 @@
     private JCheckBox cbGridAA;
     //private JColorChooser gridColor;
 
-    private final Preferences prefs = TiledConfiguration.root();
-    private final Preferences savingPrefs = prefs.node("saving");
-    private final Preferences ioPrefs = prefs.node("io");
-    private final Preferences displayPrefs = prefs.node("display");
+    private static final Preferences prefs = TiledConfiguration.root();
+    private static final Preferences savingPrefs = prefs.node("saving");
+    private static final Preferences ioPrefs = prefs.node("io");
+    private static final Preferences displayPrefs = prefs.node("display");
 
     private static final String DIALOG_TITLE = Resources.getString("dialog.preferences.title");
     private static final String CLOSE_BUTTON = Resources.getString("general.button.close");
@@ -66,6 +70,19 @@
     private static final String EXPORT_BUTTON = "Export...";
     private static final String IMPORT_BUTTON = "Import...";
 
+    private static final ConfirmableFileFilter xmlFileFilter =
+            new ConfirmableFileFilter() {
+                public String getDefaultExtension() {
+                    return "xml";
+                }
+                public boolean accept(File file) {
+                    return file.isDirectory() || file.getPath().endsWith(".xml");
+                }
+                public String getDescription() {
+                    return "XML files (*.xml)";
+                }
+            };
+
     public ConfigurationDialog(JFrame parent) {
         super(parent, DIALOG_TITLE, true);
         init();
@@ -164,7 +181,7 @@
         });
 
         JButton importButton = new JButton(IMPORT_BUTTON);
-        exportButton.addActionListener(new ActionListener() {
+        importButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent actionEvent) {
                 doImport();
             }
@@ -180,13 +197,10 @@
         /* BUTTONS PANEL */
         JPanel buttons = new VerticalStaticJPanel();
         buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
-        /*
-        // todo: add once import/export feature file choosers
         buttons.add(exportButton);
         buttons.add(Box.createRigidArea(new Dimension(5, 5)));
         buttons.add(importButton);
         buttons.add(Box.createRigidArea(new Dimension(5, 5)));
-        */
         buttons.add(Box.createGlue());
         buttons.add(closeButton);
 
@@ -328,27 +342,58 @@
         rbEmbedInSet.setEnabled(embedImages);
     }
 
-    private static void doExport() {
-        File configFile = new File("tiled-configuration.xml");
-        FileOutputStream outputStream = null;
-        try {
+    private void doExport() {
+        JFileChooser chooser = new ConfirmingFileChooser(null);
+        chooser.addChoosableFileFilter(xmlFileFilter);
+        int result = chooser.showSaveDialog(this);
+
+        if (result == JFileChooser.APPROVE_OPTION)
+        {
+            File configFile = chooser.getSelectedFile();
+
             try {
-                outputStream = new FileOutputStream(configFile);
-                TiledConfiguration.root().exportSubtree(outputStream);
-            }
-            finally {
-                if (outputStream != null) {
-                    outputStream.close();
+                FileOutputStream outputStream = null;
+                try {
+                    outputStream = new FileOutputStream(configFile);
+                    prefs.exportSubtree(outputStream);
                 }
+                finally {
+                    if (outputStream != null) {
+                        outputStream.close();
+                    }
+                }
             }
+            catch (Exception e) {
+                System.out.println("Error while exporting configuration:\n" +
+                        e.toString());
+            }
         }
-        catch (Exception e) {
-            System.out.println("Error while exporting configuration:\n" +
-                    e.toString());
-        }
     }
 
-    private static void doImport() {
-        // todo: implement
+    private void doImport() {
+        JFileChooser chooser = new JFileChooser();
+        chooser.addChoosableFileFilter(xmlFileFilter);
+        int result = chooser.showOpenDialog(this);
+
+        if (result == JFileChooser.APPROVE_OPTION)
+        {
+            File configFile = chooser.getSelectedFile();
+            try {
+                FileInputStream inputStream = null;
+                try {
+                    inputStream = new FileInputStream(configFile);
+                    Preferences.importPreferences(inputStream);
+                }
+                finally {
+                    if (inputStream != null) {
+                        inputStream.close();
+                    }
+                }
+            } catch (Exception e) {
+                System.out.println("Error while importing configuration:\n" +
+                        e.toString());
+            }
+            updateFromConfiguration();
+        }
     }
 }

Modified: trunk/src/tiled/mapeditor/dialogs/ImageColorDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/ImageColorDialog.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/dialogs/ImageColorDialog.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -28,7 +28,7 @@
 /**
  * @version $Id$
  */
-public class ImageColorDialog extends JDialog implements MouseListener, 
+public class ImageColorDialog extends JDialog implements MouseListener,
 		MouseMotionListener
 {
     private Image image;
@@ -41,11 +41,11 @@
     private static final String DIALOG_TITLE = Resources.getString("dialog.imagecolor.title");
     private static final String CANCEL_BUTTON = Resources.getString("general.button.cancel");
     /* -- */
-    
-    public ImageColorDialog(Image i) {
-        image = i;
-        PixelGrabber pg = new PixelGrabber(i, 0, 0, -1, -1, true);
 
+    public ImageColorDialog(Image image) {
+        this.image = image;
+        PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true);
+
         try {
             pg.grabPixels();
         }
@@ -98,7 +98,7 @@
         mainPanel.add(buttonPanel);
 
         setContentPane(mainPanel);
-        
+
         //create actionlisteners
         cancelButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent actionEvent) {

Modified: trunk/src/tiled/mapeditor/dialogs/NewMapDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/NewMapDialog.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/dialogs/NewMapDialog.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -48,7 +48,6 @@
     private static final String OK_BUTTON = Resources.getString("general.button.ok");
     private static final String CANCEL_BUTTON = Resources.getString("general.button.cancel");
     private static final String ISOMETRIC_MAPTYPE = Resources.getString("general.maptype.isometric");
-    private static final String OBLIQUE_MAPTYPE = Resources.getString("general.maptype.oblique");
     private static final String HEXAGONAL_MAPTYPE = Resources.getString("general.maptype.hexagonal");
     private static final String SHIFTED_MAPTYPE = Resources.getString("general.maptype.shifted");
     private static final String ORTHOGONAL_MAPTYPE = Resources.getString("general.maptype.orthogonal");
@@ -139,7 +138,6 @@
         // TODO: Enable views when implemented decently
         //mapTypeChooser.addItem(HEXAGONAL_MAPTYPE);
         //mapTypeChooser.addItem(SHIFTED_MAPTYPE);
-        //mapTypeChooser.addItem(OBLIQUE_MAPTYPE);
 
         JPanel miscPropPanel = new VerticalStaticJPanel();
         miscPropPanel.setLayout(new GridBagLayout());
@@ -192,8 +190,6 @@
 
             if (mapTypeString.equals(ISOMETRIC_MAPTYPE)) {
                 orientation = Map.MDO_ISO;
-            } else if (mapTypeString.equals(OBLIQUE_MAPTYPE)) {
-                orientation = Map.MDO_OBLIQUE;
             } else if (mapTypeString.equals(HEXAGONAL_MAPTYPE)) {
                 orientation = Map.MDO_HEX;
             } else if (mapTypeString.equals(SHIFTED_MAPTYPE)) {

Modified: trunk/src/tiled/mapeditor/plugin/PluginClassLoader.java
===================================================================
--- trunk/src/tiled/mapeditor/plugin/PluginClassLoader.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/plugin/PluginClassLoader.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -36,12 +36,12 @@
  */
 public final class PluginClassLoader extends URLClassLoader
 {
-    private Vector plugins;
-    private Vector readers, writers;
-    private Hashtable readerFormats, writerFormats;
+    private final Vector plugins;
+    private final Vector readers, writers;
+    private final Hashtable readerFormats, writerFormats;
     private static PluginClassLoader instance;
 
-    public PluginClassLoader() {
+    private PluginClassLoader() {
         super(new URL[0]);
         plugins = new Vector();
         readers = new Vector();
@@ -50,15 +50,6 @@
         writerFormats = new Hashtable();
     }
 
-    public PluginClassLoader(URL[] urls) {
-        super(urls);
-        plugins = new Vector();
-        readers = new Vector();
-        writers = new Vector();
-        readerFormats = new Hashtable();
-        writerFormats = new Hashtable();
-    }
-
     public static synchronized PluginClassLoader getInstance() {
         if (instance == null) {
             instance = new PluginClassLoader();
@@ -104,81 +95,84 @@
             String aName =
                 aPath.substring(aPath.lastIndexOf(File.separatorChar) + 1);
 
-            if (aPath.endsWith(".jar")) {
-                try {
-                    monitor.setNote("Reading " + aName + "...");
-                    JarFile jf = new JarFile(files[i]);
+            // Skip non-jar files.
+            if (!aPath.endsWith(".jar")) {
+                continue;
+            }
 
-                    monitor.setProgress(i);
+            try {
+                monitor.setNote("Reading " + aName + "...");
+                JarFile jf = new JarFile(files[i]);
 
-                    if (jf.getManifest() == null)
-                        continue;
+                monitor.setProgress(i);
 
-                    String readerClassName =
-                        jf.getManifest().getMainAttributes().getValue(
-                                "Reader-Class");
-                    String writerClassName =
-                        jf.getManifest().getMainAttributes().getValue(
-                                "Writer-Class");
+                if (jf.getManifest() == null)
+                    continue;
 
-                    Class readerClass = null, writerClass = null;
+                String readerClassName =
+                    jf.getManifest().getMainAttributes().getValue(
+                            "Reader-Class");
+                String writerClassName =
+                    jf.getManifest().getMainAttributes().getValue(
+                            "Writer-Class");
 
-                    // Verify that the jar has the necessary files to be a
-                    // plugin
-                    if (readerClassName == null && writerClassName == null) {
-                        continue;
-                    }
+                Class readerClass = null, writerClass = null;
 
-                    monitor.setNote("Loading " + aName + "...");
-                    addURL((new File(aPath)).toURL());
+                // Verify that the jar has the necessary files to be a
+                // plugin
+                if (readerClassName == null && writerClassName == null) {
+                    continue;
+                }
 
-                    if (readerClassName != null) {
-                        JarEntry reader = jf.getJarEntry(
-                                readerClassName.replace('.', '/') + ".class");
+                monitor.setNote("Loading " + aName + "...");
+                addURL(new File(aPath).toURL());
 
-                        if (reader != null) {
-                            readerClass = loadFromJar(
-                                    jf, reader, readerClassName);
-                        }else System.err.println("Manifest entry "+readerClassName+" does not match any class in the jar.");
-                    }
-                    if (writerClassName != null) {
-                        JarEntry writer = jf.getJarEntry(
-                                writerClassName.replace('.', '/') + ".class");
+                if (readerClassName != null) {
+                    JarEntry reader = jf.getJarEntry(
+                            readerClassName.replace('.', '/') + ".class");
 
-                        if (writer != null) {
-                            writerClass = loadFromJar(
-                                    jf, writer, writerClassName);
-                        } else System.err.println("Manifest entry "+writerClassName+" does not match any class in the jar.");
-                    }
+                    if (reader != null) {
+                        readerClass = loadFromJar(
+                                jf, reader, readerClassName);
+                    }else System.err.println("Manifest entry "+readerClassName+" does not match any class in the jar.");
+                }
+                if (writerClassName != null) {
+                    JarEntry writer = jf.getJarEntry(
+                            writerClassName.replace('.', '/') + ".class");
 
-                    boolean bPlugin = false;
-                    if (doesImplement(readerClass, "tiled.io.MapReader")) {
-                        bPlugin = true;
-                    }
-                    if (doesImplement(writerClass, "tiled.io.MapWriter")) {
-                        bPlugin = true;
-                    }
+                    if (writer != null) {
+                        writerClass = loadFromJar(
+                                jf, writer, writerClassName);
+                    } else System.err.println("Manifest entry "+writerClassName+" does not match any class in the jar.");
+                }
 
-                    if (bPlugin) {
-                        if (readerClass != null) _add(readerClass);
-                        if (writerClass != null) _add(writerClass);
-                        //System.out.println(
-                        //        "Added " + files[i].getCanonicalPath());
-                    }
+                boolean bPlugin = false;
+                if (isReader(readerClass)) {
+                    bPlugin = true;
+                }
+                if (isWriter(writerClass)) {
+                    bPlugin = true;
+                }
 
-                } catch (IOException e) {
-                    e.printStackTrace();
+                if (bPlugin) {
+                    if (readerClass != null) _add(readerClass);
+                    if (writerClass != null) _add(writerClass);
+                    //System.out.println(
+                    //        "Added " + files[i].getCanonicalPath());
                 }
+
+            } catch (IOException e) {
+                e.printStackTrace();
             }
         }
     }
 
     public MapReader[] getReaders() {
-        return (MapReader[])readers.toArray(new MapReader[readers.size()]);
+        return (MapReader[]) readers.toArray(new MapReader[readers.size()]);
     }
 
     public MapWriter[] getWriters() {
-        return (MapWriter[])writers.toArray(new MapWriter[writers.size()]);
+        return (MapWriter[]) writers.toArray(new MapWriter[writers.size()]);
     }
 
     public Object getReaderFor(String file) throws Exception {
@@ -229,14 +223,14 @@
         return defineClass(className, buffer, 0, buffer.length);
     }
 
-    private static boolean doesImplement(Class c, String interfaceName)
+    private static boolean doesImplement(Class klass, String interfaceName)
         throws Exception
     {
-        if (c == null) {
+        if (klass == null) {
             return false;
         }
 
-        Class[] interfaces = c.getInterfaces();
+        Class[] interfaces = klass.getInterfaces();
         for (int i = 0; i < interfaces.length; i++) {
             String name = interfaces[i].toString();
             if (name.substring(name.indexOf(' ') + 1).equals(interfaceName)) {
@@ -246,24 +240,28 @@
         return false;
     }
 
-    private static boolean isReader(Class c) throws Exception {
-        return doesImplement(c, "tiled.io.MapReader");
+    private static boolean isReader(Class klass) throws Exception {
+        return doesImplement(klass, "tiled.io.MapReader");
     }
 
-    private void _add(Class c) throws Exception{
+    private static boolean isWriter(Class writerClass) throws Exception {
+        return doesImplement(writerClass, "tiled.io.MapWriter");
+    }
+
+    private void _add(Class klass) throws Exception{
         try {
-            PluggableMapIO p = (PluggableMapIO) c.newInstance();
-            String clname = c.toString();
+            PluggableMapIO p = (PluggableMapIO) klass.newInstance();
+            String clname = klass.toString();
             clname = clname.substring(clname.indexOf(' ') + 1);
             String filter = p.getFilter();
             String[] ext = filter.split(",");
 
-            if (isReader(c)) {
+            if (isReader(klass)) {
                 for (int i = 0; i < ext.length; i++) {
                     readerFormats.put(ext[i], clname);
                 }
                 readers.add(p);
-            } else {
+            } else if (isWriter(klass)) {
                 for (int i = 0; i < ext.length; i++){
                     writerFormats.put(ext[i], clname);
                 }

Modified: trunk/src/tiled/mapeditor/resources/gui.properties
===================================================================
--- trunk/src/tiled/mapeditor/resources/gui.properties	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/resources/gui.properties	2006-10-07 21:37:01 UTC (rev 700)
@@ -131,7 +131,7 @@
 dialog.resizemap.width.label=Width:
 dialog.resizemap.x.label=X:
 dialog.resizemap.y.label=Y:
-dialog.saveas.confirm.mismatch=The file extension does not match the plugin. Do you wish to continue?
+dialog.saveas.confirm.mismatch=The file extension does not match the file type. Do you wish to continue?
 dialog.saveas.confirm.mismatch.title=Force save?
 dialog.saveas.error.message=Error while attempting to save
 dialog.saveas.error.title=Error while saving map

Added: trunk/src/tiled/mapeditor/util/ConfirmableFileFilter.java
===================================================================
--- trunk/src/tiled/mapeditor/util/ConfirmableFileFilter.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/util/ConfirmableFileFilter.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -0,0 +1,35 @@
+/*
+ *  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.mapeditor.util;
+
+import javax.swing.filechooser.FileFilter;
+
+/**
+ * A file filter with an additional method to query the default extension used
+ * by files filtered with this file filter. Used by the
+ * {@link ConfirmingFileChooser} to add this default extension when left out.
+ *
+ * @version $Id$
+ */
+public abstract class ConfirmableFileFilter extends FileFilter
+{
+    /**
+     * Returns the default extension used by files filtered with this file
+     * filter.
+     *
+     * @return a string representing the default extension (ie. "tmx"), or
+     *         <code>null</code> when a default extension doesn't exist (ie.
+     *         when the filter determines the type using the extension)
+     */
+    public abstract String getDefaultExtension();
+}


Property changes on: trunk/src/tiled/mapeditor/util/ConfirmableFileFilter.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/src/tiled/mapeditor/util/ConfirmingFileChooser.java
===================================================================
--- trunk/src/tiled/mapeditor/util/ConfirmingFileChooser.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/util/ConfirmingFileChooser.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -0,0 +1,128 @@
+/*
+ *  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.mapeditor.util;
+
+import java.io.File;
+import java.awt.Component;
+import java.awt.HeadlessException;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+
+import tiled.mapeditor.Resources;
+
+/**
+ * This file chooser extends the {@link javax.swing.JFileChooser} in a number
+ * of ways.
+ * <ul>
+ *   <li>Adds an extention to the filename based on the file filter, when
+ *       the user didn't specify any.</li>
+ *   <li>If the file to be saved is not accepted by the chosen file filter,
+ *       it confirms that the user really wants to do this. This is done
+ *       because the same file filter is used to determine with which
+ *       plugin to load the file.</li>
+ *   <li>Confirms before overwriting an existing file.</li>
+ * </ul>
+ * This file chooser can only be used with
+ * {@link tiled.mapeditor.util.ConfirmableFileFilter}.
+ */
+public final class ConfirmingFileChooser extends JFileChooser
+{
+    private static final String UNKNOWN_TYPE_MESSAGE = Resources.getString("dialog.saveas.unknown-type.message");
+    private static final String CONFIRM_MISMATCH = Resources.getString("dialog.saveas.confirm.mismatch");
+    private static final String CONFIRM_MISMATCH_TITLE = Resources.getString("dialog.saveas.confirm.mismatch.title");
+    private static final String FILE_EXISTS_MESSAGE = Resources.getString("general.file.exists.message");
+    private static final String FILE_EXISTS_TITLE = Resources.getString("general.file.exists.title");
+
+    public ConfirmingFileChooser(String currentDirectoryPath) {
+        super(currentDirectoryPath);
+    }
+
+    public int showSaveDialog(Component component) throws HeadlessException {
+        setDialogTitle(Resources.getString("dialog.saveas.title"));
+        return super.showSaveDialog(component);
+    }
+
+    public ConfirmingFileChooser() {
+        this(null);
+    }
+
+    public void approveSelection ()
+    {
+        // When it's an open dialog, we don't need the extension or overwrite
+        // checks. Probably you should just be using JFileChooser.
+        if (getDialogType() == JFileChooser.OPEN_DIALOG) {
+            super.approveSelection();
+            return;
+        }
+
+        File file = new File(getSelectedFile().getAbsolutePath());
+        ConfirmableFileFilter filter =
+                (ConfirmableFileFilter) getFileFilter();
+
+        // If the file does not have an extention, append the default
+        // extension specified by the file filter.
+        String filename = file.getName();
+        int lastDot = filename.lastIndexOf('.');
+
+        if (lastDot == -1 || lastDot == filename.length() - 1) {
+            String extension = filter.getDefaultExtension();
+
+            if (extension == null) {
+                // Impossible to determine extension with this filter
+                JOptionPane.showMessageDialog(this, UNKNOWN_TYPE_MESSAGE);
+                return;
+            }
+
+            String newFilePath = file.getAbsolutePath();
+
+            // Add a dot if it wasn't at the end already
+            if (lastDot != filename.length() - 1) {
+                newFilePath += ".";
+            }
+
+            file = new File(newFilePath + extension);
+            setSelectedFile(file);
+        }
+
+        // Check that chosen plugin accepts the file. It is a good idea to
+        // warn the user when this is not the case, because loading the map
+        // becomes a problem.
+        if (!filter.accept(file)) {
+            int result = JOptionPane.showConfirmDialog(
+                    this,
+                    CONFIRM_MISMATCH, CONFIRM_MISMATCH_TITLE,
+                    JOptionPane.YES_NO_OPTION);
+
+            if (result != JOptionPane.OK_OPTION) {
+                return;
+            }
+        }
+
+        // Confirm overwrite if the file happens to exist already
+        if (file.exists())
+        {
+            int answer = JOptionPane.showConfirmDialog(
+                    this,
+                    FILE_EXISTS_MESSAGE, FILE_EXISTS_TITLE,
+                    JOptionPane.YES_NO_OPTION);
+
+            if (answer == JOptionPane.YES_OPTION)
+            {
+                super.approveSelection();
+            }
+        }
+        else {
+            super.approveSelection();
+        }
+    }
+}


Property changes on: trunk/src/tiled/mapeditor/util/ConfirmingFileChooser.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/src/tiled/mapeditor/util/TiledFileFilter.java
===================================================================
--- trunk/src/tiled/mapeditor/util/TiledFileFilter.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/util/TiledFileFilter.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -15,7 +15,6 @@
 import java.io.File;
 import java.util.Iterator;
 import java.util.LinkedList;
-import javax.swing.filechooser.FileFilter;
 
 import tiled.io.PluggableMapIO;
 import tiled.io.xml.XMLMapWriter;
@@ -24,7 +23,7 @@
 /**
  * @version $Id$
  */
-public class TiledFileFilter extends FileFilter
+public class TiledFileFilter extends ConfirmableFileFilter
 {
     public static final int FILTER_EXT  = 0;
     public static final int FILTER_TMX  = 1;
@@ -95,30 +94,35 @@
         }
     }
 
-    public void setDescription(String d) {
-        desc = d;
+    public void setDescription(String description) {
+        desc = description;
     }
 
-    public void addExtention(String e) {
-        exts.add(e);
+    public void addExtention(String extension) {
+        exts.add(extension);
     }
 
     public PluggableMapIO getPlugin() {
         return pmio;
     }
 
-    public String getFirstExtention() {
-        return (String) exts.getFirst();
+    public String getDefaultExtension() {
+        if (!exts.isEmpty()) {
+            return (String) exts.getFirst();
+        }
+        else {
+            return null;
+        }
     }
 
     public int getType() {
         return type;
     }
 
-    public boolean accept(File f) {
-        // todo: Verify that the "!f.exists()" check is rather weird.
-        if (type != FILTER_EXT && (f.isFile() || !f.exists())) {
-            String fileName = f.getPath().toLowerCase();
+    public boolean accept(File file) {
+        // todo: Verify that the "!file.exists()" check is rather weird.
+        if (type != FILTER_EXT && (file.isFile() || !file.exists())) {
+            String fileName = file.getPath().toLowerCase();
 
             Iterator itr = exts.iterator();
             while (itr.hasNext()) {
@@ -133,20 +137,19 @@
     }
 
     public String getDescription() {
-        String filter = "";
+        StringBuffer filter = new StringBuffer();
 
         if (!exts.isEmpty()) {
-            filter += " (";
+            filter.append(" (");
             Iterator itr = exts.iterator();
             while (itr.hasNext()) {
-                String ext = (String) itr.next();
-                filter = filter + "*." + ext;
+                filter.append("*.").append((String) itr.next());
                 if (itr.hasNext()) {
-                    filter += ",";
+                    filter.append(",");
                 }
             }
 
-            filter += ")";
+            filter.append(")");
         }
 
         return desc + filter;

Modified: trunk/src/tiled/mapeditor/util/TilesetTableModel.java
===================================================================
--- trunk/src/tiled/mapeditor/util/TilesetTableModel.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/util/TilesetTableModel.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -81,9 +81,9 @@
         }
     }
 
-    private int checkSetUsage(TileSet s) {
+    private int checkSetUsage(TileSet set) {
         int used = 0;
-        Iterator tileIterator = s.iterator();
+        Iterator tileIterator = set.iterator();
 
         while (tileIterator.hasNext()) {
             Tile tile = (Tile)tileIterator.next();

Modified: trunk/src/tiled/mapeditor/widget/ImageViewPanel.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/ImageViewPanel.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/mapeditor/widget/ImageViewPanel.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -23,10 +23,10 @@
 {
 	private final Image image;
 
-    public ImageViewPanel(Image i) {
-        image = i;
+    public ImageViewPanel(Image image) {
+        this.image = image;
     }
-	
+
 	public Dimension getPreferredSize() {
 		return new Dimension(150, 150);
 	}
@@ -42,7 +42,7 @@
 	public boolean getScrollableTracksViewportWidth() {
 		return false;
 	}
-	
+
 	public void paint(Graphics g) {
 		g.drawImage(image, 0, 0, null);
 	}

Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/view/MapView.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -202,8 +202,6 @@
             mapView = new OrthoMapView(p);
         } else if (orientation == Map.MDO_HEX) {
             mapView = new HexMapView(p);
-        } else if (orientation == Map.MDO_OBLIQUE) {
-            mapView = new ObliqueMapView(p);
         } else if (orientation == Map.MDO_SHIFTED) {
             mapView = new ShiftedMapView(p);
         }

Deleted: trunk/src/tiled/view/ObliqueMapView.java
===================================================================
--- trunk/src/tiled/view/ObliqueMapView.java	2006-10-02 19:22:56 UTC (rev 699)
+++ trunk/src/tiled/view/ObliqueMapView.java	2006-10-07 21:37:01 UTC (rev 700)
@@ -1,86 +0,0 @@
-/*
- *  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.view;
-
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.Polygon;
-import java.awt.Rectangle;
-
-import tiled.core.*;
-
-/**
- * @version $Id$
- */
-public class ObliqueMapView extends MapView
-{
-    /**
-     * Creates a new oblique map view that displays the specified map.
-     *
-     * @param map the map to be displayed by this map view
-     */
-    public ObliqueMapView(Map map) {
-        super(map);
-    }
-
-    public int getScrollableBlockIncrement(
-            Rectangle visibleRect, int orientation, int direction)
-    {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    public int getScrollableUnitIncrement(
-            Rectangle visibleRect, int orientation, int direction)
-    {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    public Dimension getPreferredSize() {
-        // TODO Auto-generated method stub
-        return new Dimension(0, 0);
-    }
-
-    protected void paintLayer(Graphics2D g2d, TileLayer layer) {
-        // TODO Auto-generated method stub
-    }
-
-    protected void paintLayer(Graphics2D g2d, ObjectGroup og) {
-        // TODO Auto-generated method stub
-    }
-
-    protected void paintGrid(Graphics2D g2d) {
-        // TODO: Implement paintGrid for ObliqueMapView
-    }
-
-    protected void paintCoordinates(Graphics2D g2d) {
-        // TODO: Implement paintCoordinates for ObliqueMapView
-    }
-
-    public Point screenToTileCoords(int x, int y) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    protected Polygon createGridPolygon(int tx, int ty, int border) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public Point tileToScreenCoords(double x, double y) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-}




More information about the tiled-commit mailing list