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

svn@biggeruniverse.com svn at biggeruniverse.com
Thu Jun 22 15:30:04 PDT 2006


Author: bjorn
Date: 2006-06-22 17:30:03 -0500 (Thu, 22 Jun 2006)
New Revision: 670

Modified:
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/widget/TileButton.java
Log:
Cleanup of tile button, which is now included in the toolbar. Also fixed the weird behaviour with a draggable toolbar. These changes were already included in the 0.6.0rc3 release.

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-06-22 22:26:21 UTC (rev 669)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-06-22 22:30:03 UTC (rev 670)
@@ -27,6 +27,8 @@
 
 import javax.imageio.ImageIO;
 import javax.swing.*;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.LineBorder;
 import javax.swing.event.*;
 import javax.swing.undo.UndoableEditSupport;
 
@@ -74,7 +76,7 @@
     private Cursor curMarquee;
 
     /** Current release version. */
-    public static final String version = "0.6.0 RC2";
+    public static final String version = "0.6.0";
 
     private Map currentMap;
     private MapView mapView;
@@ -99,7 +101,6 @@
 
     // GUI components
     private JPanel      mainPanel;
-    private JPanel      toolPanel;
     private JPanel      dataPanel;
     private JPanel      statusBar;
     private JMenuBar    menuBar;
@@ -276,7 +277,6 @@
                 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
         mapScrollPane.setBorder(null);
 
-        createToolBar();
         createData();
         createStatusBar();
 
@@ -285,7 +285,7 @@
         mainSplit.setResizeWeight(1.0);
 
         mainPanel = new JPanel(new BorderLayout());
-        mainPanel.add(toolPanel, BorderLayout.WEST);
+        mainPanel.add(createToolBar(), BorderLayout.WEST);
         mainPanel.add(mainSplit);
         mainPanel.add(statusBar, BorderLayout.SOUTH);
 
@@ -471,7 +471,7 @@
     /**
      * Creates the tool bar.
      */
-    private void createToolBar() {
+    private JToolBar createToolBar() {
         Icon iconMove = Resources.getIcon("gimp-tool-move-22.png");
         Icon iconPaint = Resources.getIcon("gimp-tool-pencil-22.png");
         Icon iconErase = Resources.getIcon("gimp-tool-eraser-22.png");
@@ -497,7 +497,7 @@
         mapEventAdapter.addListener(objectMoveButton);
 
         JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);
-        toolBar.setFloatable(false);
+        toolBar.setFloatable(true);
         toolBar.add(moveButton);
         toolBar.add(paintButton);
         toolBar.add(eraseButton);
@@ -510,16 +510,16 @@
         //toolBar.add(Box.createRigidArea(new Dimension(0, 5)));
         toolBar.add(new TButton(zoomInAction));
         toolBar.add(new TButton(zoomOutAction));
+        toolBar.add(Box.createRigidArea(new Dimension(5, 5)));
+        toolBar.add(Box.createGlue());
 
-        tilePaletteButton = new TileButton(new Dimension(24, 24));
+        tilePaletteButton = new TileButton();
         tilePaletteButton.setActionCommand("palette");
-        tilePaletteButton.setMaintainAspect(true);
         mapEventAdapter.addListener(tilePaletteButton);
         tilePaletteButton.addActionListener(this);
+        toolBar.add(tilePaletteButton);
 
-        toolPanel = new JPanel(new BorderLayout());
-        toolPanel.add(toolBar, BorderLayout.NORTH);
-        toolPanel.add(tilePaletteButton, BorderLayout.SOUTH);
+        return toolBar;
     }
 
     private void createData() {

Modified: trunk/src/tiled/mapeditor/widget/TileButton.java
===================================================================
--- trunk/src/tiled/mapeditor/widget/TileButton.java	2006-06-22 22:26:21 UTC (rev 669)
+++ trunk/src/tiled/mapeditor/widget/TileButton.java	2006-06-22 22:30:03 UTC (rev 670)
@@ -18,50 +18,31 @@
 import javax.swing.event.EventListenerList;
 
 import tiled.core.*;
-import tiled.mapeditor.util.*;
+import tiled.mapeditor.Resources;
 
 /**
  * @version $Id$
  */
 public class TileButton extends JButton
 {
-    private Tile tile;
-    private Dimension size;
-    private boolean maintainAspect;
-    private EventListenerList tileSelectionListeners;
+    private static final int ICON_SIZE = 24;
+    private static final Icon DEFAULT_ICON = Resources.getIcon("empty.png");
 
-    public TileButton(Tile t, Dimension d) {
+    public TileButton() {
         setMargin(new Insets(0, 0, 0, 0));
-        size = d;
-        maintainAspect = false;
-        setTile(t);
+        setIcon(DEFAULT_ICON);
     }
 
-    public TileButton(Dimension d) {
-        this(null, d);
-    }
+    public void setTile(Tile tile) {
+        Icon icon = DEFAULT_ICON;
 
-    public TileButton(Tile t) {
-        this(t, null);
-    }
-
-    public TileButton() {
-        this(null, null);
-    }
-
-    public void setTile(Tile t) {
-        tile = t;
-        ImageIcon icon = null;
-        Insets i = getInsets();
-
         if (tile != null && tile.getImage() != null) {
             Image tileImg = tile.getImage();
             int imgWidth = tileImg.getWidth(null);
-            int w = getWidth() - i.left - i.right;
 
-            if (imgWidth > w) {
-                icon = new ImageIcon(tileImg.getScaledInstance(w,
-                        (tileImg.getHeight(null) * w) / imgWidth,
+            if (imgWidth > ICON_SIZE) {
+                icon = new ImageIcon(tileImg.getScaledInstance(ICON_SIZE,
+                        (tileImg.getHeight(null) * ICON_SIZE) / imgWidth,
                         Image.SCALE_SMOOTH));
             } else {
                 icon = new ImageIcon(tileImg);
@@ -70,93 +51,4 @@
 
         setIcon(icon);
     }
-
-    /*
-     * Methods for Size Information.
-     */
-    /*
-    private Dimension calculatePreferredSize( ) {
-        Insets i = getInsets( );
-
-        if( tile != null ) {
-            int w = tile.getWidth( ) + i.left + i.right;
-            int h = tile.getHeight( ) + i.top + i.bottom;
-            return new Dimension( w, h );
-        }
-
-        return null;
-    }
-
-    private Dimension calculateInnerSize( ) {
-        Insets i = getInsets( );
-        int w = getWidth( ) - i.left - i.right;
-        int h = getHeight( ) - i.top - i.bottom;
-        return new Dimension( w, h );
-    }
-
-    public Dimension getPreferredSize( ) {
-        Dimension d;
-
-        if( maintainAspect ) {
-            if( ( d = calculatePreferredSize( ) ) != null )	{
-                Dimension s = new Dimension( );
-                s.width  = getWidth( );
-                s.height = (int)
-                    (getWidth( ) / ( (double)d.width / (double)d.height) );
-                return s;
-            }
-        }
-        else if( size != null ) {
-            return size;
-        }
-        else if( ( d = calculatePreferredSize( ) ) != null ) {
-            return d;
-        }
-        d = super.getPreferredSize( );
-        if( d.height < 2 ) {
-            d.height = 5;
-        }
-        if( d.width < 2 ) {
-            d.height = 5;
-        }
-        return d;
-    }
-    */
-
-    public void setMaintainAspect(boolean v) {
-        maintainAspect = v;
-    }
-
-    public boolean isAspectMaintained() {
-        return maintainAspect;
-    }
-
-    /**
-     * Adds a tile selection listener. The listener will be notified when the
-     * tile shown by the tile button changes.
-     */
-    public void addTileSelectionListener(TileSelectionListener l) {
-        tileSelectionListeners.add(TileSelectionListener.class, l);
-    }
-
-    /**
-     * Removes a tile selection listener.
-     */
-    public void removeTileSelectionListener(TileSelectionListener l) {
-        tileSelectionListeners.remove(TileSelectionListener.class, l);
-    }
-
-    /**
-     * Notifies all registered tile selection listeners about a newly selected
-     * tile.
-     */
-    protected void fireActionPerformed(TileSelectionEvent e) {
-        Object[] listeners = tileSelectionListeners.getListenerList();
-
-        for (int i = listeners.length - 2; i >= 0; i -= 2) {
-            if (listeners[i] == TileSelectionListener.class) {
-                ((TileSelectionListener)listeners[i + 1]).tileSelected(e);
-            }
-        }
-    }
 }




More information about the tiled-commit mailing list