changeset 2305:f821636af849

RT-27780: Cell selection in TreeTableView doesn't render properly on column with disclosure nodes
author jgiles
date Fri, 18 Jan 2013 11:13:29 +1300
parents e86a42f510c2
children 94e17a82ab82
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableCellSkin.java
diffstat 2 files changed, 63 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Thu Jan 17 15:46:08 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Fri Jan 18 11:13:29 2013 +1300
@@ -68,7 +68,7 @@
      * disclosureNode width per TreeView. We use WeakHashMap to help prevent
      * any memory leaks.
      */
-    private static final Map<Control, Double> maxDisclosureWidthMap = new WeakHashMap<Control, Double>();
+    static final Map<Control, Double> maxDisclosureWidthMap = new WeakHashMap<Control, Double>();
     
     protected int getIndentationLevel(C control) {
         // TreeTableView.getNodeLevel(control.getTreeTable)
@@ -369,7 +369,7 @@
     }
 
     @Override protected void layoutChildren(double x, final double y,
-            double w, final double h) {
+            final double w, final double h) {
         
         if (isDirty) {
             recreateCells();
@@ -483,8 +483,6 @@
                     // further indentation code starts here
                     ///////////////////////////////////////////
                     if (indentationRequired && column == indentationColumnIndex) {
-                        x += leftMargin;
-                        
                         if (disclosureVisible) {
                             double ph = disclosureNode.prefHeight(disclosureWidth);
                             
@@ -493,16 +491,16 @@
                             } else {
                                 fadeIn(disclosureNode);
                                 disclosureNode.resize(disclosureWidth, ph);
-                                positionInArea(disclosureNode, x, y,
+                                positionInArea(disclosureNode, x + leftMargin, y,
                                         disclosureWidth, h, /*baseline ignored*/0,
                                         HPos.CENTER, VPos.CENTER);
+                                disclosureNode.toFront();
                             }
                         }
                         
                         // determine starting point of the graphic or cell node, and the
                         // remaining width available to them
                         Node graphic = getGraphic();
-                        x += disclosureWidth;
                         
                         if (graphic != null) {
                             graphicWidth = graphic.prefWidth(-1) + 3;
@@ -511,16 +509,12 @@
                                 fadeOut(graphic);
                             } else {
                                 fadeIn(graphic);
-                                positionInArea(graphic, x, y,
+                                positionInArea(graphic, x + leftMargin + disclosureWidth, y,
                                             disclosureWidth, h, /*baseline ignored*/0,
                                             HPos.CENTER, VPos.CENTER);
+                                graphic.toFront();
                             }
-                            
-                            x += graphicWidth;
-                            w -= graphicWidth;
                         }
-                        
-                        w -= (leftMargin + disclosureWidth + graphicWidth);
                     }
                     ///////////////////////////////////////////
                     // further indentation code ends here
@@ -578,27 +572,16 @@
                     // cell spanning code ends here
                     ///////////////////////////////////////////
                     
-                    // a little bit more special code for indentation purposes.
-                    // we use j here to prevent the table cells being sized as
-                    // negative or 0 widths. If this is allowed, the vertical 
-                    // lines for that column are removed from view, which 
-                    // doesn't look right.
-                    double j = width - (leftMargin + disclosureWidth + graphicWidth);
+                    tableCell.resize(width, height);
+
                     if (indentationRequired && column == indentationColumnIndex) {
-                        // the min width of a table cell is now 1 pixel
-                        tableCell.resize(Math.max(1, j), height);
-                    } else {
-                        tableCell.resize(width, height);
-                    }
-
-                    if (indentationRequired && column > indentationColumnIndex) {
-                        tableCell.relocate(x - leftMargin - disclosureWidth - graphicWidth, insets.getTop());
+                        tableCell.relocate(x, insets.getTop());
                     } else {
                         // if j is a negative number (because the width is smaller
                         // that the left margin and disclosure node), we relocate
                         // the cell to the left (and subtract 1 to take into 
                         // account the minimum 1px width we resize cells to above).
-                        tableCell.relocate(x + Math.min(0, j - 1), insets.getTop());
+                        tableCell.relocate(x, insets.getTop());
                     }
                 } else {
                     if (fixedCellLengthEnabled) {
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableCellSkin.java	Thu Jan 17 15:46:08 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableCellSkin.java	Fri Jan 18 11:13:29 2013 +1300
@@ -25,9 +25,11 @@
 package com.sun.javafx.scene.control.skin;
 
 import com.sun.javafx.scene.control.behavior.TreeTableCellBehavior;
+import java.util.Map;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.ReadOnlyDoubleProperty;
 import javafx.scene.Node;
+import javafx.scene.control.Control;
 import javafx.scene.control.TreeItem;
 import javafx.scene.control.TreeTableCell;
 import javafx.scene.control.TreeTableColumn;
@@ -58,56 +60,61 @@
     @Override protected ReadOnlyDoubleProperty columnWidthProperty() {
         return tableColumn.widthProperty();
     }
-    
+
+    @Override protected double leftLabelPadding() {
+        double leftPadding = super.leftLabelPadding();
+        
+        // RT-27167: we must take into account the disclosure node and the
+        // indentation (which is not taken into account by the LabeledSkinBase.
+        final double height = getCellSize();
+
+        TreeTableCell cell = getSkinnable();
+
+        TreeTableColumn tableColumn = cell.getTableColumn();
+        if (tableColumn == null) return leftPadding;
+
+        // check if this column is the TreeTableView treeColumn (i.e. the 
+        // column showing the disclosure node and graphic).
+        TreeTableView treeTable = cell.getTreeTableView();
+        if (treeTable == null) return leftPadding;
+
+        int columnIndex = treeTable.getVisibleLeafIndex(tableColumn);
+
+        TreeTableColumn treeColumn = treeTable.getTreeColumn();
+        if ((treeColumn == null && columnIndex != 0) || (treeColumn != null && ! tableColumn.equals(treeColumn))) {
+            return leftPadding;
+        }
+
+        TreeTableRow treeTableRow = cell.getTreeTableRow();
+        if (treeTableRow == null) return leftPadding;
+
+        TreeItem treeItem = treeTableRow.getTreeItem();
+        if (treeItem == null) return leftPadding;
+        
+        int nodeLevel = TreeTableView.getNodeLevel(treeItem);
+        if (! treeTable.isShowRoot()) nodeLevel--;
+
+        // FIXME we're assuming an indent of 10px here, which is not
+        // necessarily accurate as it is configurable via -fx-indent.
+        // Unfortunately this value is stored in TreeTableRowSkin.
+        leftPadding += nodeLevel * 10;
+
+        // add in the width of the disclosure node, if one exists
+        Map<Control, Double> mdwp = TableRowSkinBase.maxDisclosureWidthMap;
+        leftPadding += mdwp.containsKey(treeTable) ? mdwp.get(treeTable) : 0;
+
+        // adding in the width of the graphic on the tree item
+        Node graphic = treeItem.getGraphic();
+        leftPadding += graphic == null ? 0 : graphic.prefWidth(height);
+        
+        return leftPadding;
+    }
+
     @Override protected double computePrefWidth(double height) {
         if (isDeferToParentForPrefWidth) {
             // RT-27167: we must take into account the disclosure node and the
             // indentation (which is not taken into account by the LabeledSkinBase.
-            double pw = super.computePrefWidth(height);
-            
-            TreeTableCell cell = getSkinnable();
-            
-            TreeTableColumn tableColumn = cell.getTableColumn();
-            if (tableColumn == null) return pw;
-            
-            // check if this column is the TreeTableView treeColumn (i.e. the 
-            // column showing the disclosure node and graphic).
-            TreeTableView treeTable = cell.getTreeTableView();
-            if (treeTable == null) return pw;
-            
-            int columnIndex = treeTable.getVisibleLeafIndex(tableColumn);
-            
-            TreeTableColumn treeColumn = treeTable.getTreeColumn();
-            if ((treeColumn == null && columnIndex != 0) || (treeColumn != null && ! tableColumn.equals(treeColumn))) {
-                return pw;
-            }
-            
-            TreeTableRow treeTableRow = cell.getTreeTableRow();
-            if (treeTableRow == null) return pw;
-            
-            TreeItem treeItem = treeTableRow.getTreeItem();
-            if (treeItem == null) return pw;
-            
-            int nodeLevel = TreeTableView.getNodeLevel(treeItem);
-            if (! treeTable.isShowRoot()) nodeLevel--;
-
-            // FIXME we're assuming an indent of 10px here, which is not
-            // necessarily accurate as it is configurable via -fx-indent.
-            // Unfortunately this value is stored in TreeTableRowSkin.
-            pw += nodeLevel * 10;
-            
-            // add in the width of the disclosure node, if one exists
-            Node disclosureNode = treeTableRow.getDisclosureNode();
-            pw += disclosureNode == null ? 0 : disclosureNode.prefWidth(height);
-
-            // Adding a little extra for padding
-            pw += 13;
-
-            // adding in the width of the graphic on the tree item
-            Node graphic = treeItem.getGraphic();
-            pw += graphic == null ? 0 : graphic.prefWidth(height);
-
-            return pw;
+            return super.computePrefWidth(height);
         }
         return columnWidthProperty().get();
     }