[tiled] r676 - in trunk/src/tiled: core mapeditor

svn@biggeruniverse.com svn at biggeruniverse.com
Fri Jun 23 05:58:41 PDT 2006


Author: bjorn
Date: 2006-06-23 07:58:41 -0500 (Fri, 23 Jun 2006)
New Revision: 676

Modified:
   trunk/src/tiled/core/MapLayer.java
   trunk/src/tiled/core/MultilayerPlane.java
   trunk/src/tiled/core/ObjectGroup.java
   trunk/src/tiled/core/TileLayer.java
   trunk/src/tiled/mapeditor/MapEditor.java
Log:
Removed copy constructors in favor of copy method.

Modified: trunk/src/tiled/core/MapLayer.java
===================================================================
--- trunk/src/tiled/core/MapLayer.java	2006-06-23 01:56:03 UTC (rev 675)
+++ trunk/src/tiled/core/MapLayer.java	2006-06-23 12:58:41 UTC (rev 676)
@@ -63,13 +63,6 @@
         setBounds(r);
     }
 
-    public MapLayer(MapLayer ml) {
-        this(ml.bounds);
-        name = ml.getName();
-
-        properties = new Properties(ml.getProperties());
-    }
-
     /**
      * @param m the map this layer is part of
      */
@@ -265,7 +258,7 @@
     public abstract boolean isUsed(Tile t);
 
     public abstract boolean isEmpty();
-    
+
     /**
      * Creates a copy of this layer.
      *
@@ -278,6 +271,7 @@
 
         // Create a new bounds object
         clone.bounds = new Rectangle(bounds);
+        clone.properties = new Properties(getProperties());
 
         return clone;
     }

Modified: trunk/src/tiled/core/MultilayerPlane.java
===================================================================
--- trunk/src/tiled/core/MultilayerPlane.java	2006-06-23 01:56:03 UTC (rev 675)
+++ trunk/src/tiled/core/MultilayerPlane.java	2006-06-23 12:58:41 UTC (rev 676)
@@ -208,13 +208,17 @@
         }
 
         // TODO: We're not accounting for different types of layers!!!
+        TileLayer ntl;
+        try {
+            ntl = (TileLayer) getLayer(index - 1).clone();
+        }
+        catch (CloneNotSupportedException e) {
+            e.printStackTrace();
+            return;
+        }
 
-        TileLayer ntl = new TileLayer((TileLayer)getLayer(index - 1));
-        ntl.copyFrom(getLayer(index - 1));
         getLayer(index).mergeOnto(ntl);
         setLayer(index - 1, ntl);
-        
-        //getLayer(index).mergeOnto(getLayer(index - 1));
         removeLayer(index);
     }
 

Modified: trunk/src/tiled/core/ObjectGroup.java
===================================================================
--- trunk/src/tiled/core/ObjectGroup.java	2006-06-23 01:56:03 UTC (rev 675)
+++ trunk/src/tiled/core/ObjectGroup.java	2006-06-23 12:58:41 UTC (rev 676)
@@ -23,9 +23,13 @@
 {
     private LinkedList boundObjects;
 
+    /**
+     * Default constructor.
+     */
     public ObjectGroup() {
         boundObjects = new LinkedList();
     }
+
     /**
      * Creates an object group that is part of the given map and has the given
      * origin.
@@ -52,15 +56,6 @@
     }
 
     /**
-     * Clone constructor.
-     *
-     * @param group the group to clone
-     */
-    public ObjectGroup(ObjectGroup group) {
-        boundObjects = new LinkedList();
-    }
-
-    /**
      * @see MapLayer#rotate(int)
      */
     public void rotate(int angle) {
@@ -97,11 +92,17 @@
     public boolean isUsed(Tile t) {
         return false;
     }
-    
+
     public boolean isEmpty() {
     	return boundObjects.isEmpty();
     }
 
+    public Object clone() throws CloneNotSupportedException {
+        ObjectGroup clone = (ObjectGroup) super.clone();
+        clone.boundObjects = new LinkedList(boundObjects);
+        return clone;
+    }
+
     /**
      * @deprecated
      */

Modified: trunk/src/tiled/core/TileLayer.java
===================================================================
--- trunk/src/tiled/core/TileLayer.java	2006-06-23 01:56:03 UTC (rev 675)
+++ trunk/src/tiled/core/TileLayer.java	2006-06-23 12:58:41 UTC (rev 676)
@@ -52,21 +52,6 @@
     }
 
     /**
-     * Copy constructor. Copies all data from given TileLayer
-     *
-     * @param ml
-     */
-    public TileLayer(TileLayer ml) {
-        super(ml);
-
-        map = new Tile[bounds.height][];
-        for (int y = 0; y < bounds.height; y++) {
-            map[y] = new Tile[bounds.width];
-            System.arraycopy(ml.map[y], 0, map[y], 0, bounds.width);
-        }
-    }
-
-    /**
      * @param m the map this layer is part of
      */
     TileLayer(Map m) {
@@ -186,7 +171,7 @@
     	}
     	return true;
     }
-    
+
     /**
      * Sets the bounds (in tiles) to the specified Rectangle. <b>Caution:</b>
      * this causes a reallocation of the data array, and all previous data is
@@ -299,7 +284,7 @@
      * Returns the first occurance (using top down, left to right search) of
      * the given tile.
      *
-     * @param t the {@link tiled.core.Tile} to look for
+     * @param t the {@link Tile} to look for
      * @return A java.awt.Point instance of the first instance of t, or
      *         <code>null</code> if it is not found
      */
@@ -422,8 +407,7 @@
      * @exception CloneNotSupportedException
      */
     public Object clone() throws CloneNotSupportedException {
-        TileLayer clone;
-        clone = (TileLayer)super.clone();
+        TileLayer clone = (TileLayer) super.clone();
 
         // Clone the layer data
         clone.map = new Tile[map.length][];

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-06-23 01:56:03 UTC (rev 675)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-06-23 12:58:41 UTC (rev 676)
@@ -353,7 +353,6 @@
         			Resources.getString("menu.edit.brush.tooltip"),
                     "control B"));
 
-        // todo : enable/disable undo/redo depending on whether a map is loaded
         mapEventAdapter.addListener(copyMenuItem);
         mapEventAdapter.addListener(cutMenuItem);
         mapEventAdapter.addListener(pasteMenuItem);
@@ -1613,9 +1612,14 @@
         if (newTile == oldTile || layer.getLocked()) return;
 
         Rectangle area;
-        TileLayer before = new TileLayer(layer);
+        TileLayer before = (TileLayer) createLayerCopy(layer);
         TileLayer after;
 
+        // Check that the copy was succesfully created
+        if (before == null) {
+            return;
+        }
+
         if (marqueeSelection == null) {
             area = new Rectangle(new Point(x, y));
             Stack stack = new Stack();
@@ -1808,12 +1812,13 @@
     }
 
     private static MapLayer createLayerCopy(MapLayer layer) {
-        if (layer instanceof TileLayer) {
-            return new TileLayer((TileLayer)layer);
-        } else if (layer instanceof ObjectGroup) {
-            return new ObjectGroup((ObjectGroup)layer);
+        try {
+            return (MapLayer) layer.clone();
         }
-        return null;
+        catch (CloneNotSupportedException e) {
+            e.printStackTrace();
+            return null;
+        }
     }
 
     public void updateRecent(String filename) {




More information about the tiled-commit mailing list