[tiled] r697 - in trunk: . src/tiled/mapeditor src/tiled/mapeditor/dialogs src/tiled/mapeditor/util

svn at biggeruniverse.com svn at biggeruniverse.com
Mon Oct 2 03:30:28 PDT 2006


Author: bjorn
Date: 2006-10-02 05:30:28 -0500 (Mon, 02 Oct 2006)
New Revision: 697

Modified:
   trunk/CHANGES
   trunk/TODO
   trunk/src/tiled/mapeditor/MapEditor.java
   trunk/src/tiled/mapeditor/dialogs/PropertiesDialog.java
   trunk/src/tiled/mapeditor/dialogs/TileDialog.java
   trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
   trunk/src/tiled/mapeditor/util/PropertiesTableModel.java
Log:
Properties table now displays the properties in alphabetical order.


Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/CHANGES	2006-10-02 10:30:28 UTC (rev 697)
@@ -4,6 +4,7 @@
 * Added ability to create stamp brushes from the tile palette
 * 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
 
 0.6.1 - July 15th, 2006

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/TODO	2006-10-02 10:30:28 UTC (rev 697)
@@ -1,6 +1,8 @@
 ROADMAP TO FUTURE RELEASES
 
 0.7.0
+* Check that tile palette panel doesn't keep listening after being replaced.
+
 * Remove copy constructors in favour of clone method (DONE)
 
 * Add import/export of options (WIP)

Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/src/tiled/mapeditor/MapEditor.java	2006-10-02 10:30:28 UTC (rev 697)
@@ -71,8 +71,8 @@
     private static final int PS_MOVE    = 6;
     private static final int PS_MOVEOBJ = 7;
 
-    private static final int APP_WIDTH = 640;
-    private static final int APP_HEIGHT = 480;
+    private static final int APP_WIDTH = 800;
+    private static final int APP_HEIGHT = 600;
 
     private Cursor curDefault;
     private Cursor curPaint;

Modified: trunk/src/tiled/mapeditor/dialogs/PropertiesDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/PropertiesDialog.java	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/src/tiled/mapeditor/dialogs/PropertiesDialog.java	2006-10-02 10:30:28 UTC (rev 697)
@@ -15,7 +15,6 @@
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.Enumeration;
 import java.util.Properties;
 import javax.swing.*;
 import javax.swing.table.TableCellEditor;
@@ -103,15 +102,7 @@
     }
 
     private void updateInfo() {
-        // Make a copy of the properties that will be changed by the
-        // properties table model.
-        Properties props = new Properties();
-        Enumeration keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = (String)keys.nextElement();
-            props.put(key, properties.getProperty(key));
-        }
-        tableModel.update(props);
+        tableModel.setProperties(properties);
     }
 
     public void getProps() {
@@ -126,17 +117,10 @@
             editor.stopCellEditing();
         }
 
-        // Copy over the new set of properties from the properties table
-        // model.
+        // Apply possibly changed properties.
         properties.clear();
+        properties.putAll(tableModel.getProperties());
 
-        Properties newProps = tableModel.getProperties();
-        Enumeration keys = newProps.keys();
-        while (keys.hasMoreElements()) {
-            String key = (String)keys.nextElement();
-            properties.put(key, newProps.getProperty(key));
-        }
-
         dispose();
     }
 

Modified: trunk/src/tiled/mapeditor/dialogs/TileDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/TileDialog.java	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/src/tiled/mapeditor/dialogs/TileDialog.java	2006-10-02 10:30:28 UTC (rev 697)
@@ -28,6 +28,7 @@
 import javax.swing.*;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
+import javax.swing.table.TableCellEditor;
 
 import tiled.core.Map;
 import tiled.core.Tile;
@@ -79,13 +80,13 @@
     private static final String TILE_CREATED_TITLE = Resources.getString("action.tile.create.done.title");
 
 
-    public TileDialog(Dialog parent, TileSet s, Map m) {
-        super(parent, DIALOG_TITLE + " '" + s.getName() + "'", true);
+    public TileDialog(Dialog parent, TileSet tileset, Map map) {
+        super(parent, DIALOG_TITLE + " '" + tileset.getName() + "'", true);
         location = "";
-        tileset = s;    //unofficial
-        map = m;        //also unofficial
+        this.tileset = tileset;    //unofficial
+        this.map = map;        //also unofficial
         init();
-        setTileset(s);
+        setTileset(tileset);
         setCurrentTile(null);
         pack();
         setLocationRelativeTo(getOwner());
@@ -223,6 +224,7 @@
         okButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent actionEvent) {
             	tileset.setName(tilesetNameEntry.getText());
+                applyTileProperties();
                 dispose();
             }
         });
@@ -233,11 +235,11 @@
             return;
         }
 
-        TileImageDialog d = new TileImageDialog(this, tileset,
+        TileImageDialog dialog = new TileImageDialog(this, tileset,
             currentTile.getImageId());
-        d.setVisible(true);
-        if (d.getImageId() >= 0) {
-            currentTile.setImage(d.getImageId());
+        dialog.setVisible(true);
+        if (dialog.getImageId() >= 0) {
+            currentTile.setImage(dialog.getImageId());
         }
     }
 
@@ -330,22 +332,37 @@
         }
     }
 
-    private void setCurrentTile(Tile tile) {
-        // Update the old current tile's properties
-        // (happens automatically as properties are changed in place now)
-        /*
-        if (currentTile != null) {
-            PropertiesTableModel model =
-                (PropertiesTableModel)tileProperties.getModel();
-            currentTile.setProperties(model.getProperties());
+    public void valueChanged(ListSelectionEvent e) {
+        if (e.getSource() == tileList) {
+            setCurrentTile((Tile) tileList.getSelectedValue());
+        } else if (e.getSource() == imageList) {
+            setImageIndex(imageList.getSelectedIndex());
         }
-        */
+    }
 
+    private void setCurrentTile(Tile tile) {
+        applyTileProperties();
+
         currentTile = tile;
         updateTileInfo();
         updateEnabledState();
     }
 
+    private void applyTileProperties() {
+        // Make sure there is no active cell editor anymore
+        TableCellEditor editor = tileProperties.getCellEditor();
+        if (editor != null) {
+            editor.stopCellEditing();
+        }
+
+        // Apply possibly changed properties
+        if (currentTile != null) {
+            PropertiesTableModel model =
+                    (PropertiesTableModel) tileProperties.getModel();
+            currentTile.setProperties(model.getProperties());
+        }
+    }
+
     private void setImageIndex(int i) {
         currentImageIndex = i;
         updateEnabledState();
@@ -372,31 +389,21 @@
      * Updates the properties table with the properties of the current tile.
      */
     private void updateTileInfo() {
+        PropertiesTableModel model =
+                (PropertiesTableModel) tileProperties.getModel();
+
         if (currentTile == null) {
-            return;
+            model.setProperties(new Properties());
         }
-
-        Properties tileProps = currentTile.getProperties();
-
-        // (disabled making a copy, as properties are changed in place now)
-        /*
-        Properties editProps = new Properties();
-        for (Enumeration keys = tileProps.keys(); keys.hasMoreElements();) {
-            String key = (String)keys.nextElement();
-            editProps.put(key, tileProps.getProperty(key));
+        else {
+            model.setProperties(currentTile.getProperties());
         }
-        */
-
-        ((PropertiesTableModel)tileProperties.getModel()).update(tileProps);
     }
 
     public void actionPerformed(ActionEvent event) {
         Object source = event.getSource();
 
-        if (source == okButton) {
-            tileset.setName(tilesetNameEntry.getText());
-            dispose();
-        } else if (source == deleteTileButton) {
+        if (source == deleteTileButton) {
             int answer = JOptionPane.showConfirmDialog(
                     this,
                     Resources.getString("action.tile.delete.confirm.message"),
@@ -474,12 +481,4 @@
 
         repaint();
     }
-
-    public void valueChanged(ListSelectionEvent e) {
-        if (e.getSource() == tileList) {
-            setCurrentTile((Tile)tileList.getSelectedValue());
-        } else if (e.getSource() == imageList) {
-            setImageIndex(imageList.getSelectedIndex());
-        }
-    }
 }

Modified: trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java
===================================================================
--- trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/src/tiled/mapeditor/dialogs/TileInstancePropertiesDialog.java	2006-10-02 10:30:28 UTC (rev 697)
@@ -20,6 +20,7 @@
 import java.util.LinkedList;
 import java.util.Properties;
 import javax.swing.*;
+import javax.swing.table.TableCellEditor;
 
 import tiled.core.MapLayer;
 import tiled.core.Tile;
@@ -35,13 +36,13 @@
  */
 public class TileInstancePropertiesDialog extends JDialog
 {
-    private JTable tProperties;
+    private JTable propertiesTable;
     private Properties properties = new Properties();
     private PropertiesTableModel tableModel = new PropertiesTableModel();
 
-    private static final String DIALOG_TITLE = "Tile Properties"; // Resource this
-    private static final String APPLY_BUTTON = "Apply"; // Resource this
-    private static final String APPLY_TOOLTIP = "Apply properties to selected tiles"; // Resource this
+    private static final String DIALOG_TITLE = "Tile Properties"; // todo: Resource this
+    private static final String APPLY_BUTTON = Resources.getString("general.button.apply");
+    private static final String APPLY_TOOLTIP = "Apply properties to selected tiles"; // todo: Resource this
     private static final String DELETE_BUTTON = Resources.getString("general.button.delete");
 
     private final MapEditor editor;
@@ -56,8 +57,8 @@
     }
 
     private void init() {
-        tProperties = new JTable(tableModel);
-        JScrollPane propScrollPane = new JScrollPane(tProperties);
+        propertiesTable = new JTable(tableModel);
+        JScrollPane propScrollPane = new JScrollPane(propertiesTable);
         propScrollPane.setPreferredSize(new Dimension(200, 150));
 
         JButton applyButton = new JButton(APPLY_BUTTON);
@@ -159,15 +160,7 @@
     }
 
     private void updateInfo() {
-        // Make a copy of the properties that will be changed by the
-        // properties table model.
-        Properties props = new Properties();
-        Enumeration keys = properties.keys();
-        while (keys.hasMoreElements()) {
-            String key = (String) keys.nextElement();
-            props.put(key, properties.getProperty(key));
-        }
-        tableModel.update(props);
+        tableModel.setProperties(properties);
     }
 
     public void getProps() {
@@ -176,18 +169,16 @@
     }
 
     private void buildPropertiesAndApply() {
-        // Copy over the new set of properties from the properties table
-        // model.
+        // Make sure there is no active cell editor anymore
+        TableCellEditor cellEditor = propertiesTable.getCellEditor();
+        if (cellEditor != null) {
+            cellEditor.stopCellEditing();
+        }
 
+        // Apply possibly changed properties.
         properties.clear();
+        properties.putAll(tableModel.getProperties());
 
-        Properties newProps = tableModel.getProperties();
-        Enumeration keys = newProps.keys();
-        while (keys.hasMoreElements()) {
-            String key = (String) keys.nextElement();
-            properties.put(key, newProps.getProperty(key));
-        }
-
         applyPropertiesToTiles();
     }
 
@@ -200,12 +191,12 @@
     }
 
     private void deleteSelected() {
-        int total = tProperties.getSelectedRowCount();
+        int total = propertiesTable.getSelectedRowCount();
         Object[] keys = new Object[total];
-        int[] selRows = tProperties.getSelectedRows();
+        int[] selRows = propertiesTable.getSelectedRows();
 
         for (int i = 0; i < total; i++) {
-            keys[i] = tProperties.getValueAt(selRows[i], 0);
+            keys[i] = propertiesTable.getValueAt(selRows[i], 0);
         }
 
         for (int i = 0; i < total; i++) {

Modified: trunk/src/tiled/mapeditor/util/PropertiesTableModel.java
===================================================================
--- trunk/src/tiled/mapeditor/util/PropertiesTableModel.java	2006-09-10 16:17:28 UTC (rev 696)
+++ trunk/src/tiled/mapeditor/util/PropertiesTableModel.java	2006-10-02 10:30:28 UTC (rev 697)
@@ -13,6 +13,8 @@
 package tiled.mapeditor.util;
 
 import java.util.Properties;
+import java.util.SortedMap;
+import java.util.TreeMap;
 import javax.swing.table.AbstractTableModel;
 
 import tiled.mapeditor.Resources;
@@ -22,13 +24,15 @@
  */
 public class PropertiesTableModel extends AbstractTableModel
 {
-    private Properties properties;
-    
-    private static final String[] columnNames = { Resources.getString("dialog.properties.column.name"), 
-    												Resources.getString("dialog.properties.column.value") };
+    private SortedMap properties;
 
+    private static final String[] columnNames = {
+            Resources.getString("dialog.properties.column.name"),
+            Resources.getString("dialog.properties.column.value")
+    };
+
     public PropertiesTableModel() {
-        properties = new Properties();
+        properties = new TreeMap();
     }
 
     public int getRowCount() {
@@ -64,27 +68,24 @@
     }
 
     public void setValueAt(Object value, int row, int col) {
-        if (row >= 0) {
-            if (row >= properties.size() && col == 0) {
-                if (((String)value).length() > 0) {
-                    properties.setProperty((String)value, "");
-                    fireTableDataChanged();
+        if (row >= properties.size() && col == 0) {
+            if (((String) value).length() > 0) {
+                properties.put((String) value, "");
+                fireTableDataChanged();
+            }
+        } else {
+            if (col == 1) {
+                properties.put((String) getValueAt(row, 0), (String) value);
+                fireTableCellUpdated(row, col);
+            } else if (col == 0) {
+                String val = (String) getValueAt(row, 1);
+                if (getValueAt(row, col) != null) {
+                    properties.remove(getValueAt(row, col));
                 }
-            } else {
-                if (col == 1) {
-                    properties.setProperty(
-                            (String)getValueAt(row, 0), (String)value);
-                    fireTableCellUpdated(row, col);
-                } else if (col == 0) {
-                    String val = (String)getValueAt(row, 1);
-                    if (getValueAt(row, col) != null) {
-                        properties.remove(getValueAt(row, col));
-                    }
-                    if (((String)value).length() > 0) {
-                        properties.setProperty((String)value, val);
-                    }
-                    fireTableDataChanged();
+                if (((String) value).length() > 0) {
+                    properties.put((String) value, val);
                 }
+                fireTableDataChanged();
             }
         }
     }
@@ -94,12 +95,15 @@
         fireTableDataChanged();
     }
 
-    public void update(Properties props) {
-        properties = props;
+    public void setProperties(Properties props) {
+        properties.clear();
+        properties.putAll(props);
         fireTableDataChanged();
     }
 
     public Properties getProperties() {
-        return properties;
+        Properties props = new Properties();
+        props.putAll(properties);
+        return props;
     }
 }




More information about the tiled-commit mailing list