[tiled] r680 - in trunk/src/tiled/mapeditor: . util widget

svn@biggeruniverse.com svn at biggeruniverse.com
Fri Jun 23 17:50:04 PDT 2006


Author: bjorn
Date: 2006-06-23 19:50:03 -0500 (Fri, 23 Jun 2006)
New Revision: 680

Added:
   trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java
Modified:
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/util/TileSelectionEvent.java
   trunk/src/tiled/mapeditor/widget/TilePalettePanel.java
Log:
Added an embedded tabbed tilesets pane below the map view. The tile palette dialog hasn't been removed yet so the differences can now be evaluated easily.

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-06-23 19:54:33 UTC (rev 679)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-06-24 00:50:03 UTC (rev 680)
@@ -21,24 +21,32 @@
 import java.util.Iterator;
 import java.util.Stack;
 import java.util.Vector;
-import java.util.prefs.Preferences;
 import java.util.prefs.PreferenceChangeEvent;
 import java.util.prefs.PreferenceChangeListener;
-
+import java.util.prefs.Preferences;
 import javax.imageio.ImageIO;
 import javax.swing.*;
-import javax.swing.event.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 import javax.swing.undo.UndoableEditSupport;
 
 import tiled.core.*;
 import tiled.io.MapHelper;
 import tiled.io.MapReader;
 import tiled.mapeditor.actions.*;
-import tiled.mapeditor.brush.*;
+import tiled.mapeditor.brush.AbstractBrush;
+import tiled.mapeditor.brush.Brush;
+import tiled.mapeditor.brush.CustomBrush;
+import tiled.mapeditor.brush.ShapeBrush;
 import tiled.mapeditor.dialogs.*;
 import tiled.mapeditor.plugin.PluginClassLoader;
 import tiled.mapeditor.selection.SelectionLayer;
-import tiled.mapeditor.undo.*;
+import tiled.mapeditor.undo.MapLayerEdit;
+import tiled.mapeditor.undo.MapLayerStateEdit;
+import tiled.mapeditor.undo.MoveLayerEdit;
+import tiled.mapeditor.undo.UndoHandler;
 import tiled.mapeditor.util.*;
 import tiled.mapeditor.widget.*;
 import tiled.util.TiledConfiguration;
@@ -119,6 +127,7 @@
     private AbstractButton eyedButton, marqueeButton, moveButton;
     private AbstractButton objectMoveButton, objectAddButton;
 
+    private TabbedTilesetsPane tabbedTilesetsPane;
     private TilePaletteDialog tilePaletteDialog;
     private AboutDialog aboutDialog;
     private MapLayerEdit paintEdit;
@@ -283,13 +292,23 @@
         createData();
         createStatusBar();
 
+        // todo: Make continuouslayout an option. Because it's slow, some
+        // todo: people may prefer not to have that.
         JSplitPane mainSplit = new JSplitPane(
-                JSplitPane.HORIZONTAL_SPLIT, false, mapScrollPane, dataPanel);
+                JSplitPane.HORIZONTAL_SPLIT, true, mapScrollPane, dataPanel);
+        mainSplit.setOneTouchExpandable(true);
         mainSplit.setResizeWeight(1.0);
 
+        tabbedTilesetsPane = new TabbedTilesetsPane(this);
+        JSplitPane paletteSplit = new JSplitPane(
+                JSplitPane.VERTICAL_SPLIT, true, mainSplit,
+                tabbedTilesetsPane);
+        paletteSplit.setOneTouchExpandable(true);
+        paletteSplit.setResizeWeight(1.0);
+
         mainPanel = new JPanel(new BorderLayout());
         mainPanel.add(createToolBar(), BorderLayout.WEST);
-        mainPanel.add(mainSplit);
+        mainPanel.add(paletteSplit, BorderLayout.CENTER);
         mainPanel.add(statusBar, BorderLayout.SOUTH);
 
         return mainPanel;
@@ -1873,6 +1892,9 @@
         sb.makeQuadBrush(new Rectangle(0, 0, 1, 1));
         setBrush(sb);
 
+        tilePaletteDialog.setMap(currentMap);
+        tabbedTilesetsPane.setMap(currentMap);
+
         if (!mapLoaded) {
             mapEventAdapter.fireEvent(MapEventAdapter.ME_MAPINACTIVE);
             mapView = null;
@@ -1882,7 +1904,6 @@
             tileCoordsLabel.setPreferredSize(null);
             tileCoordsLabel.setText(" ");
             zoomLabel.setText(" ");
-            tilePaletteDialog.setMap(currentMap);
             setCurrentTile(null);
         } else {
             final Preferences display = prefs.node("display");
@@ -1908,7 +1929,6 @@
             coordinatesMenuItem.setState(
                     mapView.getMode(MapView.PF_COORDINATES));
 
-            tilePaletteDialog.setMap(currentMap);
 
             tileCoordsLabel.setText(String.valueOf(currentMap.getWidth() - 1)
                     + ", " + (currentMap.getHeight() - 1));

Modified: trunk/src/tiled/mapeditor/util/TileSelectionEvent.java
===================================================================
--- trunk/src/tiled/mapeditor/util/TileSelectionEvent.java	2006-06-23 19:54:33 UTC (rev 679)
+++ trunk/src/tiled/mapeditor/util/TileSelectionEvent.java	2006-06-24 00:50:03 UTC (rev 680)
@@ -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,7 +16,11 @@
 
 import tiled.core.Tile;
 
-
+/**
+ * An event that describes the selection of a tile.
+ *
+ * @version $Id$
+ */
 public class TileSelectionEvent extends EventObject
 {
     private Tile tile;

Added: trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java	2006-06-23 19:54:33 UTC (rev 679)
+++ trunk/src/tiled/mapeditor/widget/TabbedTilesetsPane.java	2006-06-24 00:50:03 UTC (rev 680)
@@ -0,0 +1,104 @@
+/*
+ *  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>
+ *
+ *  This class is based on TilesetChooserTabbedPane from Stendhal Map Editor
+ *  by Matthias Totz <mtotz at users.sourceforge.net>
+ */
+
+package tiled.mapeditor.widget;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+
+import tiled.core.Map;
+import tiled.core.TileSet;
+import tiled.mapeditor.MapEditor;
+import tiled.mapeditor.util.TileSelectionEvent;
+import tiled.mapeditor.util.TileSelectionListener;
+
+/**
+ * Shows one tab for each Tileset.
+ *
+ * todo: Since the width of this widget is no longer arbitrary but related
+ * todo: to the width of the map editor, there should be an option to set
+ * todo: the number of tiles in a row equal to what it was on the tileset
+ * todo: image.
+ *
+ * @version $Id$
+ */
+public class TabbedTilesetsPane extends JTabbedPane implements TileSelectionListener
+{
+    /**
+     * List of the tile palette panels (one for each tileset).
+     */
+    private final List tilePanels = new ArrayList();
+    private final MapEditor mapEditor;
+
+    /**
+     * Constructor.
+     */
+    public TabbedTilesetsPane(MapEditor mapEditor) {
+        this.mapEditor = mapEditor;
+    }
+
+    /**
+     * Sets the tiles panes to the the ones from this map.
+     */
+    public void setMap(Map currentMap) {
+        if (currentMap == null) {
+            removeAll();
+        } else {
+            recreateTabs(currentMap.getTilesets());
+        }
+    }
+
+    /**
+     * Creates the panels for the tilesets.
+     */
+    private void recreateTabs(List tilesets) {
+        // Stop listening to the tile palette panels
+        for (Iterator it = tilePanels.iterator(); it.hasNext();) {
+            TilePalettePanel panel = (TilePalettePanel) it.next();
+            panel.removeTileSelectionListener(this);
+        }
+        tilePanels.clear();
+
+        // Remove all tabs
+        removeAll();
+
+        if (tilesets != null) {
+            // Add a new tab for each tileset of the map
+            for (Iterator it = tilesets.iterator(); it.hasNext();)
+            {
+                TileSet tileset = (TileSet) it.next();
+                if (tileset != null) {
+                    TilePalettePanel tilePanel = new TilePalettePanel();
+                    tilePanel.setTileset(tileset);
+                    tilePanel.addTileSelectionListener(this);
+                    JScrollPane paletteScrollPane = new JScrollPane(tilePanel,
+                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+                            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+                    addTab(tileset.getName(), paletteScrollPane);
+                }
+            }
+        }
+    }
+
+    /**
+     * Informs the editor of the new tile.
+     */
+    public void tileSelected(TileSelectionEvent e) {
+        mapEditor.setCurrentTile(e.getTile());
+    }
+}


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

Modified: trunk/src/tiled/mapeditor/widget/TilePalettePanel.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TilePalettePanel.java	2006-06-23 19:54:33 UTC (rev 679)
+++ trunk/src/tiled/mapeditor/widget/TilePalettePanel.java	2006-06-24 00:50:03 UTC (rev 680)
@@ -12,19 +12,25 @@
 
 package tiled.mapeditor.widget;
 
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Rectangle;
 import java.awt.event.MouseEvent;
 import java.util.Vector;
-
 import javax.swing.JPanel;
 import javax.swing.Scrollable;
 import javax.swing.event.EventListenerList;
 import javax.swing.event.MouseInputAdapter;
 
-import tiled.core.*;
-import tiled.mapeditor.util.*;
+import tiled.core.Tile;
+import tiled.core.TileSet;
+import tiled.mapeditor.util.TileSelectionEvent;
+import tiled.mapeditor.util.TileSelectionListener;
 
 /**
+ * Displays a tileset and allows selecting a specific tile.
+ *
  * @version $Id$
  */
 public class TilePalettePanel extends JPanel implements Scrollable
@@ -57,15 +63,15 @@
      * Adds tile selection listener. The listener will be notified when the
      * user selects a tile.
      */
-    public void addTileSelectionListener(TileSelectionListener l) {
-        tileSelectionListeners.add(TileSelectionListener.class, l);
+    public void addTileSelectionListener(TileSelectionListener listener) {
+        tileSelectionListeners.add(TileSelectionListener.class, listener);
     }
 
     /**
      * Removes tile selection listener.
      */
-    public void removeTileSelectionlistener(TileSelectionListener l) {
-        tileSelectionListeners.remove(TileSelectionListener.class, l);
+    public void removeTileSelectionListener(TileSelectionListener listener) {
+        tileSelectionListeners.remove(TileSelectionListener.class, listener);
     }
 
     protected void fireTileSelectionEvent(Tile selectedTile) {
@@ -93,7 +99,7 @@
         repaint();
     }
 
-    public Tile getTileAtPoint(int x, int y) {
+    private Tile getTileAtPoint(int x, int y) {
         int twidth = tileset.getTileWidth() + 1;
         int theight = tileset.getTileHeight() + 1;
         int tilesPerRow = Math.max(1, (getWidth() - 1) / twidth);
@@ -126,9 +132,16 @@
             int startY = clip.y / theight;
             int endY = (clip.y + clip.height) / theight + 1;
             int tileAt = tilesPerRow * startY;
+            int gx;
+            int gy = startY * theight;
 
-            for (int y = startY, gy = startY * theight; y < endY; y++) {
-                for (int x = 0, gx = 1; x < tilesPerRow && tileAt < tilesetMap.size(); x++, tileAt++) {
+            for (int y = startY; y < endY; y++) {
+                gx = 1;
+
+                for (int x = 0;
+                     x < tilesPerRow && tileAt < tilesetMap.size();
+                     x++, tileAt++)
+                {
                     Tile tile = (Tile) tilesetMap.get(tileAt);
 
                     if (tile != null) {




More information about the tiled-commit mailing list