You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/09/10 03:11:57 UTC

svn commit: r813188 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: TableView.java skin/terra/TerraTableViewSkin.java

Author: tvolkert
Date: Thu Sep 10 01:11:57 2009
New Revision: 813188

URL: http://svn.apache.org/viewvc?rev=813188&view=rev
Log:
Fixed bug in TerraTableViewSkin - wasn't accounting for default-width columns in getPreferredWidth()

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java?rev=813188&r1=813187&r2=813188&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java Thu Sep 10 01:11:57 2009
@@ -120,10 +120,6 @@
          * specifies a fixed column width.
          */
         public Column(String name, Object headerData, int width, boolean relative) {
-            if (width < 0) {
-                throw new IllegalArgumentException("width is negative.");
-            }
-
             this.name = name;
             this.headerData = headerData;
             this.width = width;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=813188&r1=813187&r2=813188&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java Thu Sep 10 01:11:57 2009
@@ -133,7 +133,13 @@
             TableView.Column column = columns.get(i);
 
             if (!column.isRelative()) {
-                preferredWidth += column.getWidth();
+                int columnWidth = column.getWidth();
+
+                if (columnWidth == -1) {
+                    columnWidth = getPreferredColumnWidth(column);
+                }
+
+                preferredWidth += columnWidth;
 
                 // Include space for vertical gridlines; even if we are
                 // not painting them, the header does
@@ -190,16 +196,7 @@
                 int columnWidth = column.getWidth();
 
                 if (columnWidth == -1) {
-                    // Calculate the maximum cell width
-                    columnWidth = 0;
-
-                    TableView.CellRenderer cellRenderer = column.getCellRenderer();
-                    List<?> tableData = tableView.getTableData();
-
-                    for (Object rowData : tableData) {
-                        cellRenderer.render(rowData, tableView, column, false, false, false);
-                        columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
-                    }
+                    columnWidth = getPreferredColumnWidth(column);
                 }
 
                 columnWidths.add(columnWidth);
@@ -374,6 +371,26 @@
     }
 
     /**
+     * Gets the preferred width of a column, which is the maximum preferred
+     * width of the column's cells.
+     */
+    private int getPreferredColumnWidth(TableView.Column column) {
+        int columnWidth = 0;
+
+        TableView tableView = (TableView)getComponent();
+
+        TableView.CellRenderer cellRenderer = column.getCellRenderer();
+        List<?> tableData = tableView.getTableData();
+
+        for (Object rowData : tableData) {
+            cellRenderer.render(rowData, tableView, column, false, false, false);
+            columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
+        }
+
+        return columnWidth;
+    }
+
+    /**
      * Returns the table row height, which is determined as the maximum
      * preferred height of all cell renderers.
      *