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

svn commit: r834474 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin: BoxPaneSkin.java terra/TerraListViewSkin.java terra/TerraTableViewHeaderSkin.java terra/TerraTableViewSkin.java

Author: gbrown
Date: Tue Nov 10 14:17:03 2009
New Revision: 834474

URL: http://svn.apache.org/viewvc?rev=834474&view=rev
Log:
Fix some bugs in baseline alignment.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java?rev=834474&r1=834473&r2=834474&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/BoxPaneSkin.java Tue Nov 10 14:17:03 2009
@@ -251,6 +251,8 @@
             }
         }
 
+        height += (padding.top + padding.bottom);
+
         if (baseline != -1) {
             if (fill) {
                 baseline += padding.top;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java?rev=834474&r1=834473&r2=834474&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java Tue Nov 10 14:17:03 2009
@@ -108,12 +108,12 @@
         ListView listView = (ListView)getComponent();
         List<Object> listData = (List<Object>)listView.getListData();
 
-        ListView.ItemRenderer renderer = listView.getItemRenderer();
+        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
 
         int index = 0;
         for (Object item : listData) {
-            renderer.render(item, index++, listView, false, false, false, false);
-            preferredWidth = Math.max(preferredWidth, renderer.getPreferredWidth(-1));
+            itemRenderer.render(item, index++, listView, false, false, false, false);
+            preferredWidth = Math.max(preferredWidth, itemRenderer.getPreferredWidth(-1));
         }
 
         if (listView.getCheckmarksEnabled()) {
@@ -147,9 +147,9 @@
                 + checkboxPadding.right)), 0);
         }
 
-        ListView.ItemRenderer renderer = listView.getItemRenderer();
-        renderer.render(null, -1, listView, false, false, false, false);
-        baseline = renderer.getBaseline(width, getItemHeight());
+        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
+        itemRenderer.render(null, -1, listView, false, false, false, false);
+        baseline = itemRenderer.getBaseline(width, getItemHeight());
 
         return baseline;
     }
@@ -164,7 +164,7 @@
     public void paint(Graphics2D graphics) {
         ListView listView = (ListView)getComponent();
         List<Object> listData = (List<Object>)listView.getListData();
-        ListView.ItemRenderer renderer = listView.getItemRenderer();
+        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
 
         int width = getWidth();
         int height = getHeight();
@@ -239,9 +239,9 @@
             Graphics2D rendererGraphics = (Graphics2D)graphics.create(itemX, itemY,
                 itemWidth, itemHeight);
 
-            renderer.render(item, itemIndex, listView, selected, checked, highlighted, disabled);
-            renderer.setSize(itemWidth, itemHeight);
-            renderer.paint(rendererGraphics);
+            itemRenderer.render(item, itemIndex, listView, selected, checked, highlighted, disabled);
+            itemRenderer.setSize(itemWidth, itemHeight);
+            itemRenderer.paint(rendererGraphics);
             rendererGraphics.dispose();
         }
     }
@@ -286,10 +286,10 @@
 
     public int getItemHeight() {
         ListView listView = (ListView)getComponent();
-        ListView.ItemRenderer renderer = listView.getItemRenderer();
-        renderer.render(null, -1, listView, false, false, false, false);
+        ListView.ItemRenderer itemRenderer = listView.getItemRenderer();
+        itemRenderer.render(null, -1, listView, false, false, false, false);
 
-        int itemHeight = renderer.getPreferredHeight(-1);
+        int itemHeight = itemRenderer.getPreferredHeight(-1);
         if (listView.getCheckmarksEnabled()) {
             itemHeight = Math.max(CHECKBOX.getHeight() + (checkboxPadding.top
                 + checkboxPadding.bottom), itemHeight);

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java?rev=834474&r1=834473&r2=834474&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraTableViewHeaderSkin.java Tue Nov 10 14:17:03 2009
@@ -118,7 +118,7 @@
     private Color pressedBevelColor;
     private Color disabledBevelColor;
 
-    private ArrayList<Integer> columnWidths = null;
+    private ArrayList<Integer> headerWidths = null;
 
     private int pressedHeaderIndex = -1;
     private int resizeHeaderIndex = -1;
@@ -172,7 +172,8 @@
         TableView tableView = tableViewHeader.getTableView();
 
         if (tableView != null) {
-            preferredWidth = tableView.getPreferredWidth(height);
+            preferredWidth = TerraTableViewSkin.getPreferredWidth(tableView,
+                includeTrailingVerticalGridLine);
         }
 
         return preferredWidth;
@@ -215,18 +216,17 @@
         TableView tableView = tableViewHeader.getTableView();
 
         if (tableView != null) {
+            ArrayList<Integer> headerWidths = TerraTableViewSkin.getColumnWidths(tableView, width);
+            int rowHeight = getPreferredHeight(width) - 1;
+
             TableView.ColumnSequence columns = tableView.getColumns();
             TableViewHeader.DataRenderer dataRenderer = tableViewHeader.getDataRenderer();
 
             for (int i = 0, n = columns.getLength(); i < n; i++) {
                 TableView.Column column = columns.get(i);
                 dataRenderer.render(column.getHeaderData(), tableViewHeader, false);
-
-                Dimensions size = dataRenderer.getPreferredSize();
-                baseline = Math.max(baseline, dataRenderer.getBaseline(size.width, size.height));
+                baseline = Math.max(baseline, dataRenderer.getBaseline(headerWidths.get(i), rowHeight));
             }
-
-            baseline += 1;
         }
 
         return baseline;
@@ -238,15 +238,9 @@
         TableView tableView = tableViewHeader.getTableView();
 
         if (tableView != null) {
-            TableView.ColumnSequence columns = tableView.getColumns();
-            int n = columns.getLength();
-
-            columnWidths = new ArrayList<Integer>(n);
-
-            for (int i = 0; i < n; i++) {
-                Bounds columnBounds = tableView.getColumnBounds(i);
-                columnWidths.add(columnBounds.width);
-            }
+            headerWidths = TerraTableViewSkin.getColumnWidths(tableView, getWidth());
+        } else {
+            headerWidths = null;
         }
     }
 
@@ -286,11 +280,11 @@
             TableView.ColumnSequence columns = tableView.getColumns();
             TableViewHeader.DataRenderer dataRenderer = tableViewHeader.getDataRenderer();
 
-            int cellX = 0;
+            int headerX = 0;
             for (int columnIndex = 0, columnCount = columns.getLength();
                 columnIndex < columnCount; columnIndex++) {
                 TableView.Column column = columns.get(columnIndex);
-                int columnWidth = columnWidths.get(columnIndex);
+                int headerWidth = headerWidths.get(columnIndex);
 
                 // Paint the pressed bevel
                 if (columnIndex == pressedHeaderIndex) {
@@ -302,10 +296,10 @@
                 // Paint the header data
                 Object headerData = column.getHeaderData();
                 dataRenderer.render(headerData, tableViewHeader, false);
-                dataRenderer.setSize(columnWidth, height - 1);
+                dataRenderer.setSize(headerWidth, height - 1);
 
-                Graphics2D rendererGraphics = (Graphics2D)graphics.create(cellX, 0,
-                    columnWidth, height - 1);
+                Graphics2D rendererGraphics = (Graphics2D)graphics.create(headerX, 0,
+                    headerWidth, height - 1);
                 dataRenderer.paint(rendererGraphics);
                 rendererGraphics.dispose();
 
@@ -329,12 +323,11 @@
                 }
 
                 if (sortImage != null) {
-                    int sortImageMargin = sortImage.getWidth()
-                    + SORT_INDICATOR_PADDING * 2;
+                    int sortImageMargin = sortImage.getWidth() + SORT_INDICATOR_PADDING * 2;
 
-                    if (columnWidth >= dataRenderer.getPreferredWidth(-1) + sortImageMargin) {
+                    if (headerWidth >= dataRenderer.getPreferredWidth(-1) + sortImageMargin) {
                         Graphics2D sortImageGraphics = (Graphics2D)graphics.create();
-                        sortImageGraphics.translate(cellX + columnWidth - sortImageMargin,
+                        sortImageGraphics.translate(headerX + headerWidth - sortImageMargin,
                             (height - sortImage.getHeight()) / 2);
                         sortImage.paint(sortImageGraphics);
                         sortImageGraphics.dispose();
@@ -342,15 +335,15 @@
                 }
 
                 // Draw the divider
-                cellX += columnWidth;
+                headerX += headerWidth;
 
                 if (columnIndex < columnCount - 1
                     || includeTrailingVerticalGridLine) {
                     graphics.setPaint(borderColor);
-                    GraphicsUtilities.drawLine(graphics, cellX, 0, height, Orientation.VERTICAL);
+                    GraphicsUtilities.drawLine(graphics, headerX, 0, height, Orientation.VERTICAL);
                 }
 
-                cellX++;
+                headerX++;
             }
         }
     }
@@ -361,48 +354,48 @@
             throw new IllegalArgumentException("x is negative");
         }
 
-        int index = -1;
+        int headerIndex = -1;
 
         TableViewHeader tableViewHeader = (TableViewHeader)getComponent();
         TableView tableView = tableViewHeader.getTableView();
 
         if (tableView != null) {
             int i = 0;
-            int n = columnWidths.getLength();
-            int columnX = 0;
+            int n = tableView.getColumns().getLength();
+            int headerX = 0;
             while (i < n
-                && x > columnX) {
-                columnX += (columnWidths.get(i) + 1);
+                && x > headerX) {
+                headerX += (headerWidths.get(i) + 1);
                 i++;
             }
 
-            if (x <= columnX) {
-                index = i - 1;
+            if (x <= headerX) {
+                headerIndex = i - 1;
             }
         }
 
-        return index;
+        return headerIndex;
     }
 
     @Override
-    public Bounds getHeaderBounds(int index) {
+    public Bounds getHeaderBounds(int headerIndex) {
         Bounds headerBounds = null;
 
         TableViewHeader tableViewHeader = (TableViewHeader)getComponent();
         TableView tableView = tableViewHeader.getTableView();
 
         if (tableView != null) {
-            if (index < 0
-                || index >= columnWidths.getLength()) {
+            if (headerIndex < 0
+                || headerIndex >= headerWidths.getLength()) {
                 throw new IndexOutOfBoundsException();
             }
 
             int cellX = 0;
-            for (int i = 0; i < index; i++) {
-                cellX += (columnWidths.get(i) + 1);
+            for (int i = 0; i < headerIndex; i++) {
+                cellX += (headerWidths.get(i) + 1);
             }
 
-            headerBounds = new Bounds(cellX, 0, columnWidths.get(index), getHeight() - 1);
+            headerBounds = new Bounds(cellX, 0, headerWidths.get(headerIndex), getHeight() - 1);
         }
 
         return headerBounds;

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=834474&r1=834473&r2=834474&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 Tue Nov 10 14:17:03 2009
@@ -119,9 +119,12 @@
 
     @Override
     public int getPreferredWidth(int height) {
+        return getPreferredWidth((TableView)getComponent(), includeTrailingVerticalGridLine);
+    }
+
+    public static int getPreferredWidth(TableView tableView, boolean includeTrailingVerticalGridLine) {
         int preferredWidth = 0;
 
-        TableView tableView = (TableView)getComponent();
         TableView.ColumnSequence columns = tableView.getColumns();
 
         int n = columns.getLength();
@@ -197,14 +200,14 @@
         int baseline = -1;
 
         TableView.ColumnSequence columns = tableView.getColumns();
+        ArrayList<Integer> columnWidths = getColumnWidths(tableView, width);
+        int rowHeight = getRowHeight();
 
         for (int i = 0, n = columns.getLength(); i < n; i++) {
             TableView.Column column = columns.get(i);
             TableView.CellRenderer cellRenderer = column.getCellRenderer();
             cellRenderer.render(null, -1, i, tableView, column.getName(), false, false, false);
-
-            Dimensions size = cellRenderer.getPreferredSize();
-            baseline = Math.max(baseline, cellRenderer.getBaseline(size.width, size.height));
+            baseline = Math.max(baseline, cellRenderer.getBaseline(columnWidths.get(i), rowHeight));
         }
 
         return baseline;
@@ -212,62 +215,7 @@
 
     @Override
     public void layout() {
-        // Recalculate column widths
-        TableView tableView = (TableView)getComponent();
-
-        int width = getWidth();
-
-        int fixedWidth = 0;
-        int relativeWidth = 0;
-
-        TableView.ColumnSequence columns = tableView.getColumns();
-        int n = columns.getLength();
-
-        columnWidths = new ArrayList<Integer>(n);
-
-        for (int i = 0; i < n; i++) {
-            TableView.Column column = columns.get(i);
-
-            if (column.isRelative()) {
-                columnWidths.add(0);
-                relativeWidth += column.getWidth();
-            } else {
-                int columnWidth = column.getWidth();
-
-                if (columnWidth == -1) {
-                    // Calculate the maximum cell width
-                    columnWidth = 0;
-
-                    TableView.CellRenderer cellRenderer = column.getCellRenderer();
-                    List<?> tableData = tableView.getTableData();
-
-                    int rowIndex = 0;
-                    for (Object rowData : tableData) {
-                        cellRenderer.render(rowData, rowIndex++, i, tableView, column.getName(),
-                            false, false, false);
-                        columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
-                    }
-                }
-
-                columnWidth = Math.min(Math.max(columnWidth, column.getMinimumWidth()), column.getMaximumWidth());
-                columnWidths.add(columnWidth);
-                fixedWidth += columnWidth;
-            }
-        }
-
-        fixedWidth += n - 1;
-        int variableWidth = Math.max(width - fixedWidth, 0);
-
-        for (int i = 0; i < n; i++) {
-            TableView.Column column = columns.get(i);
-
-            if (column.isRelative()) {
-                int columnWidth = (int)Math.round((double)(column.getWidth()
-                    * variableWidth) / (double)relativeWidth);
-                columnWidths.update(i, Math.min(Math.max(columnWidth, column.getMinimumWidth()),
-                    column.getMaximumWidth()));
-            }
-        }
+        columnWidths = getColumnWidths((TableView)getComponent(), getWidth());
     }
 
     @Override
@@ -324,7 +272,7 @@
             for (int columnIndex = 0, columnCount = columns.getLength();
                 columnIndex < columnCount; columnIndex++) {
                 TableView.Column column = columns.get(columnIndex);
-                int columnWidth = getColumnWidth(columnIndex);
+                int columnWidth = columnWidths.get(columnIndex);
 
                 String columnName = column.getName();
                 SortDirection sortDirection = tableView.getSort().get(columnName);
@@ -371,7 +319,7 @@
 
                 TableView.CellRenderer cellRenderer = column.getCellRenderer();
 
-                int columnWidth = getColumnWidth(columnIndex);
+                int columnWidth = columnWidths.get(columnIndex);
 
                 Graphics2D rendererGraphics = (Graphics2D)graphics.create(columnX, rowY,
                     columnWidth, rowHeight);
@@ -397,7 +345,7 @@
 
             for (int columnIndex = 0, columnCount = columns.getLength();
                 columnIndex < columnCount; columnIndex++) {
-                columnX += getColumnWidth(columnIndex);
+                columnX += columnWidths.get(columnIndex);
 
                 if (columnIndex < columnCount - 1
                     || includeTrailingVerticalGridLine) {
@@ -431,7 +379,7 @@
                 for (int columnIndex = 0, columnCount = columns.getLength();
                     columnIndex < columnCount; columnIndex++) {
                     TableView.Column column = columns.get(columnIndex);
-                    int columnWidth = getColumnWidth(columnIndex);
+                    int columnWidth = columnWidths.get(columnIndex);
 
                     String columnName = column.getName();
                     SortDirection sortDirection = tableView.getSort().get(columnName);
@@ -506,17 +454,17 @@
 
         TableView tableView = (TableView)getComponent();
 
+        int columnIndex = -1;
+
         int i = 0;
         int n = tableView.getColumns().getLength();
         int columnX = 0;
         while (i < n
             && x > columnX) {
-            columnX += (getColumnWidth(i) + 1);
+            columnX += (columnWidths.get(i) + 1);
             i++;
         }
 
-        int columnIndex = -1;
-
         if (x <= columnX) {
             columnIndex = i - 1;
         }
@@ -530,28 +478,14 @@
         return new Bounds(0, rowIndex * (rowHeight + 1), getWidth(), rowHeight);
     }
 
-    public int getColumnWidth(int columnIndex) {
-        if (columnWidths == null) {
-            layout();
-        }
-
-        if (columnIndex < 0
-            || columnIndex >= columnWidths.getLength()) {
-            throw new IndexOutOfBoundsException("Column index out of bounds: " +
-                columnIndex);
-        }
-
-        return columnWidths.get(columnIndex);
-    }
-
     @Override
     public Bounds getColumnBounds(int columnIndex) {
         int columnX = 0;
         for (int i = 0; i < columnIndex; i++) {
-            columnX += (getColumnWidth(i) + 1);
+            columnX += (columnWidths.get(i) + 1);
         }
 
-        return new Bounds(columnX, 0, getColumnWidth(columnIndex), getHeight());
+        return new Bounds(columnX, 0, columnWidths.get(columnIndex), getHeight());
     }
 
     @Override
@@ -567,12 +501,68 @@
 
         int cellX = 0;
         for (int i = 0; i < columnIndex; i++) {
-            cellX += (getColumnWidth(i) + 1);
+            cellX += (columnWidths.get(i) + 1);
         }
 
         int rowHeight = getRowHeight();
 
-        return new Bounds(cellX, rowIndex * (rowHeight + 1), getColumnWidth(columnIndex), rowHeight);
+        return new Bounds(cellX, rowIndex * (rowHeight + 1), columnWidths.get(columnIndex), rowHeight);
+    }
+
+    public static ArrayList<Integer> getColumnWidths(TableView tableView, int width) {
+        int fixedWidth = 0;
+        int relativeWidth = 0;
+
+        TableView.ColumnSequence columns = tableView.getColumns();
+        int n = columns.getLength();
+
+        ArrayList<Integer> columnWidths = new ArrayList<Integer>(n);
+
+        for (int i = 0; i < n; i++) {
+            TableView.Column column = columns.get(i);
+
+            if (column.isRelative()) {
+                columnWidths.add(0);
+                relativeWidth += column.getWidth();
+            } else {
+                int columnWidth = column.getWidth();
+
+                if (columnWidth == -1) {
+                    // Calculate the maximum cell width
+                    columnWidth = 0;
+
+                    TableView.CellRenderer cellRenderer = column.getCellRenderer();
+                    List<?> tableData = tableView.getTableData();
+
+                    int rowIndex = 0;
+                    for (Object rowData : tableData) {
+                        cellRenderer.render(rowData, rowIndex++, i, tableView, column.getName(),
+                            false, false, false);
+                        columnWidth = Math.max(cellRenderer.getPreferredWidth(-1), columnWidth);
+                    }
+                }
+
+                columnWidth = Math.min(Math.max(columnWidth, column.getMinimumWidth()), column.getMaximumWidth());
+                columnWidths.add(columnWidth);
+                fixedWidth += columnWidth;
+            }
+        }
+
+        fixedWidth += n - 1;
+        int variableWidth = Math.max(width - fixedWidth, 0);
+
+        for (int i = 0; i < n; i++) {
+            TableView.Column column = columns.get(i);
+
+            if (column.isRelative()) {
+                int columnWidth = (int)Math.round((double)(column.getWidth()
+                    * variableWidth) / (double)relativeWidth);
+                columnWidths.update(i, Math.min(Math.max(columnWidth, column.getMinimumWidth()),
+                    column.getMaximumWidth()));
+            }
+        }
+
+        return columnWidths;
     }
 
     @Override