[tiled] r607 - in trunk/src/tiled: core mapeditor mapeditor/actions mapeditor/resources mapeditor/widget plugins/mappy

svn@biggeruniverse.com svn at biggeruniverse.com
Sat Apr 22 07:37:11 PDT 2006


Author: bjorn
Date: 2006-04-22 09:37:10 -0500 (Sat, 22 Apr 2006)
New Revision: 607

Added:
   trunk/src/tiled/mapeditor/actions/AbstractLayerAction.java
   trunk/src/tiled/mapeditor/actions/AddLayerAction.java
   trunk/src/tiled/mapeditor/actions/CloneLayerAction.java
   trunk/src/tiled/mapeditor/actions/DeleteLayerAction.java
   trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java
   trunk/src/tiled/mapeditor/actions/MergeLayerDownAction.java
   trunk/src/tiled/mapeditor/actions/MoveLayerDownAction.java
   trunk/src/tiled/mapeditor/actions/MoveLayerUpAction.java
Modified:
   trunk/src/tiled/core/Map.java
   trunk/src/tiled/core/MultilayerPlane.java
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/resources/gui.properties
   trunk/src/tiled/mapeditor/widget/TButton.java
   trunk/src/tiled/mapeditor/widget/TMenuItem.java
   trunk/src/tiled/plugins/mappy/MappyMapReader.java
Log:
Moved all layer actions into action classes, based on AbstractLayerAction.

Modified: trunk/src/tiled/core/Map.java
===================================================================
--- trunk/src/tiled/core/Map.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/core/Map.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -258,7 +258,7 @@
      *
      * @see MultilayerPlane#swapLayerUp
      */
-    public void swapLayerUp(int index) throws Exception {
+    public void swapLayerUp(int index) {
         super.swapLayerUp(index);
         fireMapChanged();
     }
@@ -268,7 +268,7 @@
      *
      * @see MultilayerPlane#swapLayerDown
      */
-    public void swapLayerDown(int index) throws Exception {
+    public void swapLayerDown(int index) {
         super.swapLayerDown(index);
         fireMapChanged();
     }
@@ -278,7 +278,7 @@
      *
      * @see MultilayerPlane#mergeLayerDown
      */
-    public void mergeLayerDown(int index) throws Exception {
+    public void mergeLayerDown(int index) {
         super.mergeLayerDown(index);
         fireMapChanged();
     }

Modified: trunk/src/tiled/core/MultilayerPlane.java
===================================================================
--- trunk/src/tiled/core/MultilayerPlane.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/core/MultilayerPlane.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -161,11 +161,10 @@
      * Moves the layer at <code>index</code> up one in the vector.
      *
      * @param index the index of the layer to swap up
-     * @throws Exception
      */
-    public void swapLayerUp(int index) throws Exception {
+    public void swapLayerUp(int index) {
         if (index + 1 == layers.size()) {
-            throw new Exception(
+            throw new RuntimeException(
                     "Can't swap up when already at the top.");
         }
 
@@ -178,11 +177,11 @@
      * Moves the layer at <code>index</code> down one in the vector.
      *
      * @param index the index of the layer to swap down
-     * @throws Exception
      */
-    public void swapLayerDown(int index) throws Exception {
+    public void swapLayerDown(int index) {
         if (index - 1 < 0) {
-            throw new Exception("Can't swap down when already at the bottom.");
+            throw new RuntimeException(
+                    "Can't swap down when already at the bottom.");
         }
 
         MapLayer hold = (MapLayer)layers.get(index - 1);
@@ -193,13 +192,12 @@
     /**
      * Merges the layer at <code>index</code> with the layer below it
      *
-     * @see tiled.core.MapLayer#mergeOnto
+     * @see MapLayer#mergeOnto
      * @param index the index of the layer to merge down
-     * @throws Exception
      */
-    public void mergeLayerDown(int index) throws Exception {
+    public void mergeLayerDown(int index) {
         if (index - 1 < 0) {
-            throw new Exception("Can't merge down bottom layer.");
+            throw new RuntimeException("Can't merge down bottom layer.");
         }
 
         getLayer(index).mergeOnto(getLayer(index - 1));

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -35,6 +35,7 @@
 import tiled.mapeditor.util.*;
 import tiled.mapeditor.widget.*;
 import tiled.mapeditor.undo.*;
+import tiled.mapeditor.actions.*;
 import tiled.util.TileMergeHelper;
 import tiled.util.TiledConfiguration;
 import tiled.io.MapHelper;
@@ -81,66 +82,69 @@
     private final PluginClassLoader pluginLoader;
     private final Preferences prefs = TiledConfiguration.root();
 
-    int currentPointerState;
-    Tile currentTile;
-    int currentLayer = -1;
-    boolean bMouseIsDown;
-    SelectionLayer cursorHighlight;
-    Point mousePressLocation, mouseInitialPressLocation;
-    Point moveDist;
-    int mouseButton;
-    AbstractBrush currentBrush;
-    SelectionLayer marqueeSelection;
-    MapLayer clipboardLayer;
+    private int currentPointerState;
+    private Tile currentTile;
+    private int currentLayer = -1;
+    private boolean bMouseIsDown;
+    private SelectionLayer cursorHighlight;
+    private Point mousePressLocation, mouseInitialPressLocation;
+    private Point moveDist;
+    private int mouseButton;
+    private AbstractBrush currentBrush;
+    private SelectionLayer marqueeSelection;
+    private MapLayer clipboardLayer;
 
     // GUI components
-    JMenu       fileMenu, editMenu, selectMenu, viewMenu, helpMenu;
-    JMenu       mapMenu, layerMenu, tilesetMenu;
-    JPanel      mainPanel;
-    JPanel      toolPanel;
-    JPanel      dataPanel;
-    JPanel      statusBar;
-    JMenuBar    menuBar;
-    JMenuItem   undoMenuItem, redoMenuItem;
-    JMenuItem   copyMenuItem, cutMenuItem, pasteMenuItem;
-    JCheckBoxMenuItem gridMenuItem, boundaryMenuItem, cursorMenuItem;
-    JCheckBoxMenuItem coordinatesMenuItem;
-    JMenuItem   layerAdd, layerClone, layerDel;
-    JMenuItem   layerUp, layerDown;
-    JMenuItem   layerMerge, layerMergeAll;
-    JMenuItem   layerProperties;
-    JMenu       recentMenu;
-    JScrollPane mapScrollPane;
-    JTable      layerTable;
-    JList       editHistoryList;
-    MiniMapViewer miniMap;
+    private JMenu       fileMenu, editMenu, selectMenu, viewMenu, helpMenu;
+    private JMenu       mapMenu, layerMenu, tilesetMenu;
+    private JPanel      mainPanel;
+    private JPanel      toolPanel;
+    private JPanel      dataPanel;
+    private JPanel      statusBar;
+    private JMenuBar    menuBar;
+    private JMenuItem   undoMenuItem, redoMenuItem;
+    private JMenuItem   copyMenuItem, cutMenuItem, pasteMenuItem;
+    private JCheckBoxMenuItem gridMenuItem, boundaryMenuItem, cursorMenuItem;
+    private JCheckBoxMenuItem coordinatesMenuItem;
+    private JMenuItem   layerAdd, layerClone, layerDel;
+    private JMenuItem   layerUp, layerDown;
+    private JMenuItem   layerMerge, layerMergeAll;
+    private JMenuItem   layerProperties;
+    private JMenu       recentMenu;
+    private JScrollPane mapScrollPane;
+    private JTable      layerTable;
+    private JList       editHistoryList;
+    private MiniMapViewer miniMap;
 
-    TileButton  tilePaletteButton;
-    JFrame      appFrame;
-    JSlider     opacitySlider;
-    JLabel      zoomLabel, tileCoordsLabel;
+    private TileButton  tilePaletteButton;
+    private JFrame      appFrame;
+    private JSlider     opacitySlider;
+    private JLabel      zoomLabel, tileCoordsLabel;
 
-    AbstractButton layerAddButton, layerCloneButton, layerDelButton;
-    AbstractButton layerUpButton, layerDownButton;
-    AbstractButton paintButton, eraseButton, pourButton;
-    AbstractButton eyedButton, marqueeButton, moveButton;
-    AbstractButton objectMoveButton, objectAddButton;
+    private AbstractButton layerAddButton, layerCloneButton, layerDelButton;
+    private AbstractButton layerUpButton, layerDownButton;
+    private AbstractButton paintButton, eraseButton, pourButton;
+    private AbstractButton eyedButton, marqueeButton, moveButton;
+    private AbstractButton objectMoveButton, objectAddButton;
 
-    TilePalettePanel tilePalettePanel;
-    TilePaletteDialog tilePaletteDialog;
-    AboutDialog aboutDialog;
-    MapLayerEdit paintEdit;
+    private TilePalettePanel tilePalettePanel;
+    private TilePaletteDialog tilePaletteDialog;
+    private AboutDialog aboutDialog;
+    private MapLayerEdit paintEdit;
 
     /** Available brushes */
-    Vector brushes = new Vector();
-    Brush eraserBrush;
+    private Vector brushes = new Vector();
+    private Brush eraserBrush;
 
     // Actions
-    final Action zoomInAction, zoomOutAction, zoomNormalAction;
-    final Action undoAction, redoAction;
-    final Action rot90Action, rot180Action, rot270Action;
-    final Action flipHorAction, flipVerAction;
-    final Action selectAllAction, inverseAction, cancelSelectionAction;
+    private final Action zoomInAction, zoomOutAction, zoomNormalAction;
+    private final Action undoAction, redoAction;
+    private final Action rot90Action, rot180Action, rot270Action;
+    private final Action flipHorAction, flipVerAction;
+    private final Action selectAllAction, inverseAction, cancelSelectionAction;
+    private final Action addLayerAction, cloneLayerAction, deleteLayerAction;
+    private final Action moveLayerDownAction, moveLayerUpAction;
+    private final Action mergeLayerDownAction, mergeAllLayersAction;
 
     public MapEditor() {
         /*eraserBrush = new Eraser();
@@ -191,9 +195,16 @@
         selectAllAction = new SelectAllAction();
         cancelSelectionAction = new CancelSelectionAction();
         inverseAction = new InverseSelectionAction();
+        addLayerAction = new AddLayerAction(this);
+        cloneLayerAction = new CloneLayerAction(this);
+        deleteLayerAction = new DeleteLayerAction(this);
+        moveLayerUpAction = new MoveLayerUpAction(this);
+        moveLayerDownAction = new MoveLayerDownAction(this);
+        mergeLayerDownAction = new MergeLayerDownAction(this);
+        mergeAllLayersAction = new MergeAllLayersAction(this);
 
         // Create our frame
-        appFrame = new JFrame("Tiled");
+        appFrame = new JFrame(Resources.getString("dialog.main.title"));
         appFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         appFrame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent event) {
@@ -337,19 +348,13 @@
         mapEventAdapter.addListener(mapMenu);
 
 
-        layerAdd = createMenuItem(Resources.getString("action.layer.add.name"), null,
-                Resources.getString("action.layer.add.tooltip"));
-        layerClone = createMenuItem(Resources.getString("action.layer.duplicate.name"), null,
-                Resources.getString("action.layer.duplicate.tooltip"));
-        layerDel = createMenuItem(Resources.getString("action.layer.delete.name"), null,
-                Resources.getString("action.layer.delete.tooltip"));
-        layerUp = createMenuItem(Resources.getString("action.layer.moveup.name"), null,
-                "Move layer up one in layer stack", "shift PAGE_UP");
-        layerDown = createMenuItem("Move Layer Down", null,
-                "Move layer down one in layer stack", "shift PAGE_DOWN");
-        layerMerge = createMenuItem("Merge Down", null,
-                "Merge current layer onto next lower", "shift control M");
-        layerMergeAll = createMenuItem("Merge All", null, "Merge all layers");
+        layerAdd = new TMenuItem(addLayerAction);
+        layerClone = new TMenuItem(cloneLayerAction);
+        layerDel = new TMenuItem(deleteLayerAction);
+        layerUp = new TMenuItem(moveLayerUpAction);
+        layerDown = new TMenuItem(moveLayerDownAction);
+        layerMerge = new TMenuItem(mergeLayerDownAction);
+        layerMergeAll = new TMenuItem(mergeAllLayersAction);
         layerProperties = createMenuItem("Layer Properties", null,
                 "Current layer properties");
 
@@ -509,13 +514,6 @@
 
         dataPanel = new JPanel(new BorderLayout());
 
-        // Try to load the icons
-        Icon imgAdd = Resources.getIcon("gnome-new.png");
-        Icon imgDel = Resources.getIcon("gnome-delete.png");
-        Icon imgDup = Resources.getIcon("gimp-duplicate-16.png");
-        Icon imgUp = Resources.getIcon("gnome-up.png");
-        Icon imgDown = Resources.getIcon("gnome-down.png");
-
         //navigation and tool options
         // TODO: the minimap is prohibitively slow, need to speed this up
         // before it can be used
@@ -534,7 +532,8 @@
         // Opacity slider
         opacitySlider = new JSlider(0, 100, 100);
         opacitySlider.addChangeListener(this);
-        JLabel opacityLabel = new JLabel("Opacity: ");
+        JLabel opacityLabel = new JLabel(
+                Resources.getString("dialog.main.opacity.label"));
         opacityLabel.setLabelFor(opacitySlider);
 
         JPanel sliderPanel = new JPanel();
@@ -546,13 +545,11 @@
                     sliderPanel.getPreferredSize().height));
 
         // Layer buttons
-        layerAddButton = createButton(imgAdd, Resources.getString("action.layer.add.name"), "Add Layer");
-        layerDelButton = createButton(imgDel, Resources.getString("action.layer.delete.name"), "Delete Layer");
-        layerCloneButton = createButton(imgDup, Resources.getString("action.layer.duplicate.name"),
-                "Duplicate Layer");
-        layerUpButton = createButton(imgUp, Resources.getString("action.layer.moveup.name"), "Move Layer Up");
-        layerDownButton = createButton(imgDown, "Move Layer Down",
-                "Move Layer Down");
+        layerAddButton = new TButton(addLayerAction);
+        layerDelButton = new TButton(deleteLayerAction);
+        layerCloneButton = new TButton(cloneLayerAction);
+        layerUpButton = new TButton(moveLayerUpAction);
+        layerDownButton = new TButton(moveLayerDownAction);
 
         mapEventAdapter.addListener(layerAddButton);
 
@@ -719,7 +716,7 @@
     /**
      * Returns the currently selected tile.
      *
-     * @return The currently selected tile.
+     * @return the currently selected tile
      */
     public Tile getCurrentTile() {
         return currentTile;
@@ -728,7 +725,7 @@
     /**
      * Returns the current map.
      *
-     * @return The currently selected map.
+     * @return the currently selected map
      */
     public Map getCurrentMap() {
         return currentMap;
@@ -737,16 +734,33 @@
     /**
      * Returns the currently selected layer.
      *
-     * @return THe currently selected layer.
+     * @return the currently selected layer
      */
     public MapLayer getCurrentLayer() {
         return currentMap.getLayer(currentLayer);
     }
 
     /**
+     * Returns the currently selected layer index.
+     *
+     * @return the currently selected layer index
+     */
+    public int getCurrentLayerIndex() {
+        return currentLayer;
+    }
+
+    /**
+     * Returns the {@link UndoableEditSupport} instance.
+     * @return the undo support
+     */
+    public UndoableEditSupport getUndoSupport() {
+        return undoSupport;
+    }
+
+    /**
      * Returns the main application frame.
      *
-     * @return The frame of the main application
+     * @return the frame of the main application
      */
     public Frame getAppFrame() {
         return appFrame;
@@ -761,89 +775,6 @@
         updateTitle();
     }
 
-    private void doLayerStateChange(ActionEvent event) {
-        if (currentMap == null) {
-            return;
-        }
-
-        String command = event.getActionCommand();
-        Vector layersBefore = new Vector(currentMap.getLayerVector());
-
-        if (command.equals(Resources.getString("action.layer.add.name"))) {
-            currentMap.addLayer();
-            setCurrentLayer(currentMap.getTotalLayers() - 1);
-        } else if (command.equals(Resources.getString("action.layer.duplicate.name"))) {
-            if (currentLayer >= 0) {
-                try {
-                    MapLayer clone =
-                        (MapLayer)getCurrentLayer().clone();
-                    clone.setName(clone.getName() + " copy");
-                    currentMap.addLayer(clone);
-                } catch (CloneNotSupportedException ex) {
-                    ex.printStackTrace();
-                }
-                setCurrentLayer(currentMap.getTotalLayers() - 1);
-            }
-        } else if (command.equals(Resources.getString("action.layer.moveup.name"))) {
-            if (currentLayer >= 0) {
-                try {
-                    currentMap.swapLayerUp(currentLayer);
-                    setCurrentLayer(currentLayer + 1);
-                } catch (Exception ex) {
-                    System.out.println(ex.toString());
-                }
-            }
-        } else if (command.equals("Move Layer Down")) {
-            if (currentLayer >= 0) {
-                try {
-                    currentMap.swapLayerDown(currentLayer);
-                    setCurrentLayer(currentLayer - 1);
-                } catch (Exception ex) {
-                    System.out.println(ex.toString());
-                }
-            }
-        } else if (command.equals(Resources.getString("action.layer.delete.name"))) {
-            if (currentLayer >= 0) {
-                currentMap.removeLayer(currentLayer);
-                setCurrentLayer(currentLayer < 0 ? 0 : currentLayer);
-            }
-        } else if (command.equals("Merge Down")) {
-            if (currentLayer >= 0) {
-                try {
-                    currentMap.mergeLayerDown(currentLayer);
-                    setCurrentLayer(currentLayer - 1);
-                } catch (Exception ex) {
-                    System.out.println(ex.toString());
-                }
-            }
-        } else if (command.equals("Merge All")) {
-            if (JOptionPane.showConfirmDialog(appFrame,
-                    "Do you wish to merge tile images, and create a new tile set?",
-                    "Merge Tiles?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) {
-                TileMergeHelper tmh = new TileMergeHelper(currentMap);
-                int len = currentMap.getTotalLayers();
-                //TODO: Add a dialog option: "Yes, visible only"
-                TileLayer newLayer = tmh.merge(0, len, true);
-                currentMap.removeAllLayers();
-                currentMap.addLayer(newLayer);
-                currentMap.addTileset(tmh.getSet());
-            } else {
-                while (currentMap.getTotalLayers() > 1) {
-                    try {
-                        currentMap.mergeLayerDown(
-                                currentMap.getTotalLayers() - 1);
-                    } catch (Exception ex) {}
-                }
-            }
-            setCurrentLayer(0);
-        }
-
-        MapLayerStateEdit mapLayerStateEdit = new MapLayerStateEdit(
-                currentMap, layersBefore,
-                new Vector(currentMap.getLayerVector()), command);
-        undoSupport.postEdit(mapLayerStateEdit);
-    }
-
     private void doMouse(MouseEvent event) {
         if (currentMap == null || currentLayer < 0) {
             return;
@@ -867,10 +798,10 @@
                     paintEdit.setPresentationName("Paint");
                     if (layer instanceof TileLayer) {
                         try {
-							mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));
-						} catch (Exception e) {
-							e.printStackTrace();
-						}
+                            mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
                     }
                     break;
                 case PS_ERASE:
@@ -1144,14 +1075,6 @@
         } else if (command.equals("Brush...")) {
             BrushDialog bd = new BrushDialog(this, appFrame, currentBrush);
             bd.setVisible(true);
-        } else if (command.equals("Add Layer") ||
-                command.equals("Duplicate Layer") ||
-                command.equals("Delete Layer") ||
-                command.equals("Move Layer Up") ||
-                command.equals("Move Layer Down") ||
-                command.equals("Merge Down") ||
-                command.equals("Merge All")) {
-            doLayerStateChange(event);
         } else if (command.equals("New Tileset...")) {
             if (currentMap != null) {
                 NewTilesetDialog dialog =
@@ -1209,7 +1132,7 @@
         } else if (command.equals("Properties")) {
             PropertiesDialog pd = new PropertiesDialog(appFrame,
                     currentMap.getProperties());
-            pd.setTitle("Map Properties");
+            pd.setTitle(Resources.getString("dialog.properties.map.title"));
             pd.getProps();
         } else if (command.equals("Layer Properties")) {
             MapLayer layer = getCurrentLayer();
@@ -1696,7 +1619,7 @@
     }
 
     private void updateTitle() {
-        String title = "Tiled";
+        String title = Resources.getString("dialog.main.title");
 
         if (currentMap != null) {
             String filename = currentMap.getFilename();
@@ -2090,7 +2013,7 @@
         updateHistory();
     }
 
-    private void setCurrentLayer(int index) {
+    public void setCurrentLayer(int index) {
         if (currentMap != null) {
             int totalLayers = currentMap.getTotalLayers();
             if (totalLayers > index && index >= 0) {

Added: trunk/src/tiled/mapeditor/actions/AbstractLayerAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/AbstractLayerAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/AbstractLayerAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,75 @@
+/*
+ *  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.actions;
+
+import java.awt.event.ActionEvent;
+import java.util.Vector;
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+
+import tiled.core.Map;
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.undo.MapLayerStateEdit;
+
+/**
+ * Provides a common abstract class for actions that modify the layer
+ * configuration. It makes sure the undo/redo information is properly
+ * maintained.
+ *
+ * @version $Id$
+ */
+public abstract class AbstractLayerAction extends AbstractAction
+{
+    protected final MapEditor editor;
+
+    protected AbstractLayerAction(MapEditor editor,
+                                  String name, String description)
+    {
+        super(name);
+        putValue(SHORT_DESCRIPTION, description);
+        putValue(ACTION_COMMAND_KEY, name);
+        this.editor = editor;
+    }
+
+    protected AbstractLayerAction(MapEditor editor,
+                                  String name, String description, Icon icon)
+    {
+        this(editor, name, description);
+        putValue(SMALL_ICON, icon);
+    }
+
+    /**
+     * Wraps {@link #doPerformAction} in order to capture the layer vector
+     * before and after the action is performed.
+     */
+    public final void actionPerformed(ActionEvent e) {
+        // Capture the layers before the operation is executed.
+        Map map = editor.getCurrentMap();
+        Vector layersBefore = new Vector(map.getLayerVector());
+
+        doPerformAction();
+
+        // Capture the layers after the operation is executed and create the
+        // layer state edit instance.
+        Vector layersAfter = new Vector(map.getLayerVector());
+        MapLayerStateEdit mapLayerStateEdit =
+                new MapLayerStateEdit(map, layersBefore, layersAfter,
+                                      e.getActionCommand());
+        editor.getUndoSupport().postEdit(mapLayerStateEdit);
+    }
+
+    /**
+     * Actually performs the action that modifies the layer configuration.
+     */
+    public abstract void doPerformAction();
+}

Added: trunk/src/tiled/mapeditor/actions/AddLayerAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/AddLayerAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/AddLayerAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,38 @@
+/*
+ *  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.actions;
+
+import tiled.mapeditor.Resources;
+import tiled.mapeditor.MapEditor;
+import tiled.core.Map;
+
+/**
+ * Adds a layer to the current map and selects it.
+ *
+ * @version $Id$
+ */
+public class AddLayerAction extends AbstractLayerAction
+{
+    public AddLayerAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.add.name"),
+              Resources.getString("action.layer.add.tooltip"),
+              Resources.getIcon("gnome-new.png"));
+    }
+
+    public void doPerformAction() {
+        Map currentMap = editor.getCurrentMap();
+        currentMap.addLayer();
+        editor.setCurrentLayer(currentMap.getTotalLayers() - 1);
+    }
+}


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

Added: trunk/src/tiled/mapeditor/actions/CloneLayerAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/CloneLayerAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/CloneLayerAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,54 @@
+/*
+ *  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.actions;
+
+import java.text.MessageFormat;
+
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.core.Map;
+import tiled.core.MapLayer;
+
+/**
+ * Clones the current layer, adds the clone to the map at the top of the layer
+ * stack and then selects it.
+ *
+ * @version $Id$
+ */
+public class CloneLayerAction extends AbstractLayerAction
+{
+    public CloneLayerAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.duplicate.name"),
+              Resources.getString("action.layer.duplicate.tooltip"),
+              Resources.getIcon("gimp-duplicate-16.png"));
+    }
+
+    public void doPerformAction() {
+        MapLayer currentLayer = editor.getCurrentLayer();
+        Map currentMap = editor.getCurrentMap();
+
+        if (currentLayer != null) {
+            try {
+                MapLayer clone = (MapLayer) currentLayer.clone();
+                String newName = Resources.getString(
+                        "action.layer.duplicate.newlayer.name");
+                clone.setName(MessageFormat.format(newName, clone.getName()));
+                currentMap.addLayer(clone);
+            } catch (CloneNotSupportedException ex) {
+                ex.printStackTrace();
+            }
+            editor.setCurrentLayer(currentMap.getTotalLayers() - 1);
+        }
+    }
+}


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

Added: trunk/src/tiled/mapeditor/actions/DeleteLayerAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/DeleteLayerAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/DeleteLayerAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,49 @@
+/*
+ *  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.actions;
+
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.core.Map;
+
+/**
+ * Deletes the selected layer and selects the layer that takes the same index.
+ *
+ * @version $Id$
+ */
+public class DeleteLayerAction extends AbstractLayerAction
+{
+    public DeleteLayerAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.delete.name"),
+              Resources.getString("action.layer.delete.tooltip"),
+              Resources.getIcon("gnome-delete.png"));
+    }
+
+    public void doPerformAction() {
+        Map map = editor.getCurrentMap();
+        int layerIndex = editor.getCurrentLayerIndex();
+        int totalLayers = map.getTotalLayers();
+
+        if (layerIndex >= 0) {
+            map.removeLayer(layerIndex);
+
+            // If the topmost layer was selected, the layer index is invalid
+            // after removing that layer. The right thing to do is to reset it
+            // to the new topmost layer.
+            if (layerIndex == totalLayers - 1) {
+                editor.setCurrentLayer(totalLayers - 2);
+            }
+        }
+    }
+}

Added: trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/MergeAllLayersAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,59 @@
+/*
+ *  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.actions;
+
+import javax.swing.JOptionPane;
+
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.util.TileMergeHelper;
+import tiled.core.TileLayer;
+import tiled.core.Map;
+
+/**
+ * Merges all layers of the map. Optionally it will create a new tileset with
+ * merged tiles.
+ *
+ * @version $Id$
+ */
+public class MergeAllLayersAction extends AbstractLayerAction
+{
+    public MergeAllLayersAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.mergeall.name"),
+              Resources.getString("action.layer.mergeall.tooltip"));
+    }
+
+    public void doPerformAction() {
+        Map map = editor.getCurrentMap();
+
+        if (JOptionPane.showConfirmDialog(editor.getAppFrame(),
+                                          "Do you wish to merge tile images, and create a new tile set?",
+                                          "Merge Tiles?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) {
+            TileMergeHelper tmh = new TileMergeHelper(map);
+            int len = map.getTotalLayers();
+            //TODO: Add a dialog option: "Yes, visible only"
+            TileLayer newLayer = tmh.merge(0, len, true);
+            map.removeAllLayers();
+            map.addLayer(newLayer);
+            map.addTileset(tmh.getSet());
+        } else {
+            // todo: The merging should be done to a new layer. Currently the
+            // todo: merge is done in-place, causing undo not to work properly.
+            while (map.getTotalLayers() > 1) {
+                map.mergeLayerDown(map.getTotalLayers() - 1);
+            }
+        }
+        editor.setCurrentLayer(0);
+    }
+}


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

Added: trunk/src/tiled/mapeditor/actions/MergeLayerDownAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/MergeLayerDownAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/MergeLayerDownAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,47 @@
+/*
+ *  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.actions;
+
+import javax.swing.KeyStroke;
+
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.core.Map;
+
+/**
+ * Merges the current layer with the one below and selects the merged layer.
+ *
+ * @version $Id$
+ */
+public class MergeLayerDownAction extends AbstractLayerAction
+{
+    public MergeLayerDownAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.mergedown.name"),
+              Resources.getString("action.layer.mergedown.tooltip"));
+
+        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift control M"));
+    }
+
+    public void doPerformAction() {
+        Map map = editor.getCurrentMap();
+        int layerIndex = editor.getCurrentLayerIndex();
+
+        if (layerIndex > 0) {
+            // todo: The merged layer should be a copy. Currently the merge is
+            // todo: done in-place, which makes undo not work properly.
+            map.mergeLayerDown(layerIndex);
+            editor.setCurrentLayer(layerIndex - 1);
+        }
+    }
+}


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

Added: trunk/src/tiled/mapeditor/actions/MoveLayerDownAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/MoveLayerDownAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/MoveLayerDownAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,46 @@
+/*
+ *  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.actions;
+
+import javax.swing.KeyStroke;
+
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.core.Map;
+
+/**
+ * Swaps the currently selected layer with the layer below.
+ *
+ * @version $Id$
+ */
+public class MoveLayerDownAction extends AbstractLayerAction
+{
+    public MoveLayerDownAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.movedown.name"),
+              Resources.getString("action.layer.movedown.tooltip"),
+              Resources.getIcon("gnome-down.png"));
+
+        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift PAGE_DOWN"));
+    }
+
+    public void doPerformAction() {
+        Map map = editor.getCurrentMap();
+        int layerIndex = editor.getCurrentLayerIndex();
+
+        if (layerIndex > 0) {
+            map.swapLayerDown(layerIndex);
+            editor.setCurrentLayer(layerIndex - 1);
+        }
+    }
+}


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

Added: trunk/src/tiled/mapeditor/actions/MoveLayerUpAction.java
===================================================================
--- trunk/src/tiled/mapeditor/actions/MoveLayerUpAction.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/actions/MoveLayerUpAction.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -0,0 +1,47 @@
+/*
+ *  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.actions;
+
+import javax.swing.KeyStroke;
+
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.Resources;
+import tiled.core.Map;
+
+/**
+ * Swaps the currently selected layer with the layer above.
+ *
+ * @version $Id$
+ */
+public class MoveLayerUpAction extends AbstractLayerAction
+{
+    public MoveLayerUpAction(MapEditor editor) {
+        super(editor,
+              Resources.getString("action.layer.moveup.name"),
+              Resources.getString("action.layer.moveup.tooltip"),
+              Resources.getIcon("gnome-up.png"));
+
+        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift PAGE_UP"));
+    }
+
+    public void doPerformAction() {
+        Map map = editor.getCurrentMap();
+        int layerIndex = editor.getCurrentLayerIndex();
+        int totalLayers = map.getTotalLayers();
+
+        if (layerIndex < totalLayers - 1) {
+            map.swapLayerUp(layerIndex);
+            editor.setCurrentLayer(layerIndex + 1);
+        }
+    }
+}


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

Modified: trunk/src/tiled/mapeditor/resources/gui.properties
===================================================================
--- trunk/src/tiled/mapeditor/resources/gui.properties	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/resources/gui.properties	2006-04-22 14:37:10 UTC (rev 607)
@@ -12,12 +12,14 @@
 dialog.brush.title=Brush Options
 dialog.brush.tab.shape=Shape
 dialog.brush.tab.custom=Custom
+dialog.imagecolor.title=Color Chooser
 dialog.newmap.height.label=Height:
 dialog.newmap.mapsize.title=Map size
 dialog.newmap.maptype.label=Map type:
 dialog.newmap.tilesize.title=Tile size
 dialog.newmap.title=New Map
 dialog.newmap.width.label=Width:
+dialog.newtile.title=New Tile
 dialog.newtileset.autotiles.label=Automatically create tiles from images
 dialog.newtileset.button.properties=Set Default Properties...
 dialog.newtileset.colorchoose.error.title=Error while choosing color
@@ -32,18 +34,6 @@
 dialog.newtileset.tilewidth.label=Tile width:
 dialog.newtileset.title=New Tileset
 dialog.newtileset.usetransparentcolor.label=Use transparent color
-dialog.newtileset.button.properties=Set Default Properties...
-dialog.newtile.title=New Tile
-dialog.tile.title=Edit Tileset
-dialog.tile.button.newtile=Add Tile
-dialog.tile.button.deletetile=Delete Tile
-dialog.tile.button.changeimage=Change Image
-dialog.tile.button.duptile=Duplicate Tile
-dialog.tile.button.animation=Animation
-dialog.tile.button.createtile=Create Tile
-dialog.tile.imgload.error.message=Error while loading image:
-dialog.tile.imgload.error.title=Error while loading image
-dialog.tileimage.title=Choose Tile Image
 dialog.openmap.error.title=Error while opening map file
 dialog.plugins.info.button=Info
 dialog.plugins.remove.button=Remove
@@ -79,12 +69,11 @@
 dialog.tile.title=Edit Tileset
 dialog.tileimage.title=Choose Tile Image
 dialog.tilepalette.title=Palette
-dialog.imagecolor.title=Color Chooser
+general.button.apply=Apply
 general.button.browse=Browse...
 general.button.cancel=Cancel
 general.button.close=Close
 general.button.delete=Delete
-general.button.apply=Apply
 general.button.ok=OK
 general.button.preview=Preview...
 general.file.exists.message=The file already exists. Do you wish to overwrite it?
@@ -100,3 +89,13 @@
 general.tile.tile=Tile
 general.tile.tiles=Tiles
 general.tile.tileset=Tileset
+action.layer.movedown.name=Move Layer Down
+action.layer.mergedown.name=Merge Down
+action.layer.moveup.tooltip=Move layer up one in layer stack
+action.layer.movedown.tooltip=Move layer down one in layer stack
+action.layer.mergedown.tooltip=Merge current layer onto next lower
+action.layer.mergeall.name=Merge All
+action.layer.mergeall.tooltip=Merge all layers
+action.layer.duplicate.newlayer.name=Copy of {0}
+dialog.main.title=Tiled
+dialog.main.opacity.label=Opacity:
\ No newline at end of file

Modified: trunk/src/tiled/mapeditor/widget/TButton.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TButton.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/widget/TButton.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -5,7 +5,7 @@
  *  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>
  */
@@ -16,14 +16,15 @@
 import javax.swing.Action;
 import javax.swing.JButton;
 
-
 /**
  * Tiled button extends on JButton in that it allows for not accepting
  * any text from an attached action. It also doesn't display any margins.
+ *
+ * @version $Id$
  */
 public class TButton extends JButton
 {
-    private boolean showText = false;
+    private boolean showText;
 
     public TButton() {
         setMargin(new Insets(0, 0, 0, 0));

Modified: trunk/src/tiled/mapeditor/widget/TMenuItem.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TMenuItem.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/mapeditor/widget/TMenuItem.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -5,7 +5,7 @@
  *  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>
  */
@@ -16,14 +16,15 @@
 import javax.swing.Icon;
 import javax.swing.JMenuItem;
 
-
 /**
  * Tiled menu item extends on JMenuItem in that it allows for not accepting
  * any icon from an attached action.
+ *
+ * @version $Id$
  */
 public class TMenuItem extends JMenuItem
 {
-    private boolean showIcon = false;
+    private boolean showIcon;
 
     public TMenuItem(boolean showIcon) {
         this.showIcon = showIcon;

Modified: trunk/src/tiled/plugins/mappy/MappyMapReader.java
===================================================================
--- trunk/src/tiled/plugins/mappy/MappyMapReader.java	2006-04-11 02:05:19 UTC (rev 606)
+++ trunk/src/tiled/plugins/mappy/MappyMapReader.java	2006-04-22 14:37:10 UTC (rev 607)
@@ -30,7 +30,7 @@
     private int twidth, theight;
 
     private PluginLogger logger;
-    
+
     public static class BlkStr {
         public BlkStr() {
         }
@@ -252,10 +252,10 @@
 
         for (int i = 0; i < m.getHeight(); i++) {
             for (int j = 0; j < m.getWidth(); j++) {
-                int block = (int)((Util.readShort(in)&0x00FF) / BLKSTR_WIDTH);
-                //System.out.print(""+block);
+                int block = (Util.readShort(in) & 0x00FF) / BLKSTR_WIDTH;
+                //System.out.print("" + block);
                 BlkStr blk = (BlkStr)blocks.get(block);
-                //System.out.println("bg: "+blk.bg);
+                //System.out.println("bg: " + blk.bg);
                 bg.setTileAt(j,i, set.getTile((int)blk.bg));
                 fg0.setTileAt(j,i, set.getTile((int)blk.fg0));
                 fg1.setTileAt(j,i, set.getTile((int)blk.fg1));
@@ -267,7 +267,7 @@
 
     /**
      * BGFX blocks are synonymous with {@link tiled.core.Tile}s
-     * 
+     *
      * @param m The Map to add Tiles to
      * @param in
      * @param num Number of Tiles to read




More information about the tiled-commit mailing list