< prev index next >

src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java

Print this page
rev 47712 : Fixed JDK-8190281: Code cleanup in src\java.desktop\sharelasses\javax\swing ree\VariableHeightLayoutCache.java
Remove the streams related code changes, since it is increasing the class size by 1kb.
Moved the increment of nextIndex back into the conditional, since
moving it out makes it a functional changes, and needs to be accompanied with a testcase.
Properly align the code to the previous state at line no 1000,
so that unnecessary changes are not introduced.
Fixed condition check from == to <=.
Call getRowCount() only once, and cache it.

*** 923,950 **** * Returns the index of the row containing location. If there * are no rows, -1 is returned. If location is beyond the last * row index, the last row index is returned. */ private int getRowContainingYLocation(int location) { ! if(isFixedRowHeight()) { ! if(getRowCount() == 0) return -1; return Math.max(0, Math.min(getRowCount() - 1, location / getRowHeight())); } ! int max, maxY, mid, min, minY; ! TreeStateNode node; - if((max = getRowCount()) <= 0) - return -1; - mid = min = 0; while(min < max) { mid = (max - min) / 2 + min; ! node = (TreeStateNode)visibleNodes.elementAt(mid); ! minY = node.getYOrigin(); ! maxY = minY + node.getPreferredHeight(); if(location < minY) { max = mid - 1; } else if(location >= maxY) { min = mid + 1; --- 923,948 ---- * Returns the index of the row containing location. If there * are no rows, -1 is returned. If location is beyond the last * row index, the last row index is returned. */ private int getRowContainingYLocation(int location) { ! int max = getRowCount(); ! ! if(max <= 0) return -1; + if(isFixedRowHeight()) { return Math.max(0, Math.min(getRowCount() - 1, location / getRowHeight())); } ! int min = 0, mid = 0; while(min < max) { mid = (max - min) / 2 + min; ! TreeStateNode node = (TreeStateNode)visibleNodes.elementAt(mid); ! int minY = node.getYOrigin(); ! int maxY = minY + node.getPreferredHeight(); if(location < minY) { max = mid - 1; } else if(location >= maxY) { min = mid + 1;
*** 1006,1018 **** node = this.getNode(counter); nodeWidth = node.getPreferredWidth() + node.getXOrigin(); if(nodeWidth > maxWidth) maxWidth = nodeWidth; } return maxWidth; } - /** * Responsible for creating a TreeStateNode that will be used * to track display information about value. */ private TreeStateNode createNodeForValue(Object value) { --- 1004,1016 ---- node = this.getNode(counter); nodeWidth = node.getPreferredWidth() + node.getXOrigin(); if(nodeWidth > maxWidth) maxWidth = nodeWidth; } + return maxWidth; } /** * Responsible for creating a TreeStateNode that will be used * to track display information about value. */ private TreeStateNode createNodeForValue(Object value) {
*** 1360,1380 **** Rectangle bounds = getNodeDimensions(this.getUserObject(), index, getLevel(), isExpanded(), boundsBuffer); ! if(bounds == null) { xOrigin = 0; preferredWidth = preferredHeight = 0; updateNodeSizes = true; ! } ! else if(bounds.height == 0) { ! xOrigin = 0; ! preferredWidth = preferredHeight = 0; ! updateNodeSizes = true; ! } ! else { xOrigin = bounds.x; preferredWidth = bounds.width; if(isFixedRowHeight()) preferredHeight = getRowHeight(); else --- 1358,1372 ---- Rectangle bounds = getNodeDimensions(this.getUserObject(), index, getLevel(), isExpanded(), boundsBuffer); ! if(bounds == null || bounds.height == 0) { xOrigin = 0; preferredWidth = preferredHeight = 0; updateNodeSizes = true; ! } else { xOrigin = bounds.x; preferredWidth = bounds.width; if(isFixedRowHeight()) preferredHeight = getRowHeight(); else
*** 1475,1517 **** if (!hasBeenExpanded) { TreeStateNode newNode; Object realNode = getValue(); TreeModel treeModel = getModel(); int count = treeModel.getChildCount(realNode); ! hasBeenExpanded = true; ! if(originalRow == -1) { ! for (int i = 0; i < count; i++) { ! newNode = createNodeForValue(treeModel.getChild ! (realNode, i)); ! this.add(newNode); ! newNode.updatePreferredSize(-1); ! } ! } ! else { ! int offset = originalRow + 1; for (int i = 0; i < count; i++) { newNode = createNodeForValue(treeModel.getChild (realNode, i)); this.add(newNode); newNode.updatePreferredSize(offset); } } - } int i = originalRow; Enumeration<TreeNode> cursor = preorderEnumeration(); cursor.nextElement(); // don't add me, I'm already in ! int newYOrigin; - if(isFixed) - newYOrigin = 0; - else if(this == root && !isRootVisible()) - newYOrigin = 0; - else - newYOrigin = getYOrigin() + this.getPreferredHeight(); TreeStateNode aNode; if(!isFixed) { while (cursor.hasMoreElements()) { aNode = (TreeStateNode) cursor.nextElement(); if(!updateNodeSizes && !aNode.hasValidSize()) --- 1467,1494 ---- if (!hasBeenExpanded) { TreeStateNode newNode; Object realNode = getValue(); TreeModel treeModel = getModel(); int count = treeModel.getChildCount(realNode); ! int offset = originalRow == -1 ? -1 : originalRow + 1; hasBeenExpanded = true; ! for (int i = 0; i < count; i++) { newNode = createNodeForValue(treeModel.getChild (realNode, i)); this.add(newNode); newNode.updatePreferredSize(offset); } } int i = originalRow; Enumeration<TreeNode> cursor = preorderEnumeration(); cursor.nextElement(); // don't add me, I'm already in ! int newYOrigin = isFixed || (this == root && !isRootVisible()) ? ! 0 : getYOrigin() + this.getPreferredHeight(); TreeStateNode aNode; if(!isFixed) { while (cursor.hasMoreElements()) { aNode = (TreeStateNode) cursor.nextElement(); if(!updateNodeSizes && !aNode.hasValidSize())
*** 1742,1759 **** * the number of children of parent. */ protected boolean updateNextIndex() { // nextIndex == -1 identifies receiver, make sure is expanded // before descend. ! if(nextIndex == -1 && !parent.isExpanded()) ! return false; ! ! // Check that it can have kids ! if(childCount == 0) ! return false; ! // Make sure next index not beyond child count. ! else if(++nextIndex >= childCount) return false; TreeStateNode child = (TreeStateNode)parent. getChildAt(nextIndex); --- 1719,1732 ---- * the number of children of parent. */ protected boolean updateNextIndex() { // nextIndex == -1 identifies receiver, make sure is expanded // before descend. ! if((nextIndex == -1 && !parent.isExpanded()) || ! childCount == 0 || // Check that it can have kids ! ++nextIndex >= childCount) // Make sure next index not beyond ! // child count. return false; TreeStateNode child = (TreeStateNode)parent. getChildAt(nextIndex);
< prev index next >