mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
8190281: Code cleanup in src\java.desktop\share\classes\javax\swing\tree\VariableHeightLayoutCache.java
Reviewed-by: psadhukhan, serb, ssadetsky
This commit is contained in:
parent
f06ebe9b3a
commit
2ba2b2f07b
1 changed files with 46 additions and 87 deletions
|
@ -409,11 +409,10 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
*/
|
*/
|
||||||
public void treeNodesChanged(TreeModelEvent e) {
|
public void treeNodesChanged(TreeModelEvent e) {
|
||||||
if(e != null) {
|
if(e != null) {
|
||||||
int changedIndexs[];
|
int changedIndexs[] = e.getChildIndices();
|
||||||
TreeStateNode changedNode;
|
TreeStateNode changedNode = getNodeForPath(
|
||||||
|
SwingUtilities2.getTreePath(e, getModel()), false, false);
|
||||||
|
|
||||||
changedIndexs = e.getChildIndices();
|
|
||||||
changedNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
|
|
||||||
if(changedNode != null) {
|
if(changedNode != null) {
|
||||||
Object changedValue = changedNode.getValue();
|
Object changedValue = changedNode.getValue();
|
||||||
|
|
||||||
|
@ -421,17 +420,12 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
child indexs that are passed in. */
|
child indexs that are passed in. */
|
||||||
changedNode.updatePreferredSize();
|
changedNode.updatePreferredSize();
|
||||||
if(changedNode.hasBeenExpanded() && changedIndexs != null) {
|
if(changedNode.hasBeenExpanded() && changedIndexs != null) {
|
||||||
int counter;
|
for(int index : changedIndexs) {
|
||||||
TreeStateNode changedChildNode;
|
TreeStateNode changedChildNode = (TreeStateNode)changedNode
|
||||||
|
.getChildAt(index);
|
||||||
for(counter = 0; counter < changedIndexs.length;
|
|
||||||
counter++) {
|
|
||||||
changedChildNode = (TreeStateNode)changedNode
|
|
||||||
.getChildAt(changedIndexs[counter]);
|
|
||||||
/* Reset the user object. */
|
/* Reset the user object. */
|
||||||
changedChildNode.setUserObject
|
changedChildNode.setUserObject
|
||||||
(treeModel.getChild(changedValue,
|
(treeModel.getChild(changedValue, index));
|
||||||
changedIndexs[counter]));
|
|
||||||
changedChildNode.updatePreferredSize();
|
changedChildNode.updatePreferredSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,34 +456,26 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
*/
|
*/
|
||||||
public void treeNodesInserted(TreeModelEvent e) {
|
public void treeNodesInserted(TreeModelEvent e) {
|
||||||
if(e != null) {
|
if(e != null) {
|
||||||
int changedIndexs[];
|
int changedIndexs[] = e.getChildIndices();
|
||||||
TreeStateNode changedParentNode;
|
TreeStateNode changedParentNode = getNodeForPath(
|
||||||
|
SwingUtilities2.getTreePath(e, getModel()), false, false);
|
||||||
changedIndexs = e.getChildIndices();
|
|
||||||
changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
|
|
||||||
/* Only need to update the children if the node has been
|
/* Only need to update the children if the node has been
|
||||||
expanded once. */
|
expanded once. */
|
||||||
// PENDING(scott): make sure childIndexs is sorted!
|
// PENDING(scott): make sure childIndexs is sorted!
|
||||||
if(changedParentNode != null && changedIndexs != null &&
|
if(changedParentNode != null && changedIndexs != null &&
|
||||||
changedIndexs.length > 0) {
|
changedIndexs.length > 0) {
|
||||||
if(changedParentNode.hasBeenExpanded()) {
|
if(changedParentNode.hasBeenExpanded()) {
|
||||||
boolean makeVisible;
|
boolean makeVisible =((changedParentNode == root &&
|
||||||
int counter;
|
|
||||||
Object changedParent;
|
|
||||||
TreeStateNode newNode;
|
|
||||||
int oldChildCount = changedParentNode.
|
|
||||||
getChildCount();
|
|
||||||
|
|
||||||
changedParent = changedParentNode.getValue();
|
|
||||||
makeVisible = ((changedParentNode == root &&
|
|
||||||
!rootVisible) ||
|
!rootVisible) ||
|
||||||
(changedParentNode.getRow() != -1 &&
|
(changedParentNode.getRow() != -1 &&
|
||||||
changedParentNode.isExpanded()));
|
changedParentNode.isExpanded()));
|
||||||
for(counter = 0;counter < changedIndexs.length;counter++)
|
int oldChildCount = changedParentNode.getChildCount();
|
||||||
|
|
||||||
|
for(int index : changedIndexs)
|
||||||
{
|
{
|
||||||
newNode = this.createNodeAt(changedParentNode,
|
this.createNodeAt(changedParentNode, index);
|
||||||
changedIndexs[counter]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(oldChildCount == 0) {
|
if(oldChildCount == 0) {
|
||||||
// Update the size of the parent.
|
// Update the size of the parent.
|
||||||
changedParentNode.updatePreferredSize();
|
changedParentNode.updatePreferredSize();
|
||||||
|
@ -643,7 +629,7 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
rebuild(true);
|
rebuild(true);
|
||||||
}
|
}
|
||||||
else if(changedNode != null) {
|
else if(changedNode != null) {
|
||||||
int nodeIndex, oldRow;
|
int nodeIndex;
|
||||||
TreeStateNode newNode, parent;
|
TreeStateNode newNode, parent;
|
||||||
boolean wasExpanded, wasVisible;
|
boolean wasExpanded, wasVisible;
|
||||||
int newIndex;
|
int newIndex;
|
||||||
|
@ -925,24 +911,22 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
* row index, the last row index is returned.
|
* row index, the last row index is returned.
|
||||||
*/
|
*/
|
||||||
private int getRowContainingYLocation(int location) {
|
private int getRowContainingYLocation(int location) {
|
||||||
if(isFixedRowHeight()) {
|
final int rows = getRowCount();
|
||||||
if(getRowCount() == 0)
|
|
||||||
|
if(rows <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
return Math.max(0, Math.min(getRowCount() - 1,
|
if(isFixedRowHeight()) {
|
||||||
|
return Math.max(0, Math.min(rows - 1,
|
||||||
location / getRowHeight()));
|
location / getRowHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int max, maxY, mid, min, minY;
|
int max = rows, min = 0, mid = 0;
|
||||||
TreeStateNode node;
|
|
||||||
|
|
||||||
if((max = getRowCount()) <= 0)
|
|
||||||
return -1;
|
|
||||||
mid = min = 0;
|
|
||||||
while(min < max) {
|
while(min < max) {
|
||||||
mid = (max - min) / 2 + min;
|
mid = (max - min) / 2 + min;
|
||||||
node = (TreeStateNode)visibleNodes.elementAt(mid);
|
TreeStateNode node = (TreeStateNode)visibleNodes.elementAt(mid);
|
||||||
minY = node.getYOrigin();
|
int minY = node.getYOrigin();
|
||||||
maxY = minY + node.getPreferredHeight();
|
int maxY = minY + node.getPreferredHeight();
|
||||||
if(location < minY) {
|
if(location < minY) {
|
||||||
max = mid - 1;
|
max = mid - 1;
|
||||||
}
|
}
|
||||||
|
@ -954,8 +938,8 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
}
|
}
|
||||||
if(min == max) {
|
if(min == max) {
|
||||||
mid = min;
|
mid = min;
|
||||||
if(mid >= getRowCount())
|
if(mid >= rows)
|
||||||
mid = getRowCount() - 1;
|
mid = rows - 1;
|
||||||
}
|
}
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
@ -1008,9 +992,9 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
if(nodeWidth > maxWidth)
|
if(nodeWidth > maxWidth)
|
||||||
maxWidth = nodeWidth;
|
maxWidth = nodeWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
return maxWidth;
|
return maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for creating a TreeStateNode that will be used
|
* Responsible for creating a TreeStateNode that will be used
|
||||||
* to track display information about value.
|
* to track display information about value.
|
||||||
|
@ -1362,17 +1346,11 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
isExpanded(),
|
isExpanded(),
|
||||||
boundsBuffer);
|
boundsBuffer);
|
||||||
|
|
||||||
if(bounds == null) {
|
if(bounds == null || bounds.height == 0) {
|
||||||
xOrigin = 0;
|
xOrigin = 0;
|
||||||
preferredWidth = preferredHeight = 0;
|
preferredWidth = preferredHeight = 0;
|
||||||
updateNodeSizes = true;
|
updateNodeSizes = true;
|
||||||
}
|
} else {
|
||||||
else if(bounds.height == 0) {
|
|
||||||
xOrigin = 0;
|
|
||||||
preferredWidth = preferredHeight = 0;
|
|
||||||
updateNodeSizes = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
xOrigin = bounds.x;
|
xOrigin = bounds.x;
|
||||||
preferredWidth = bounds.width;
|
preferredWidth = bounds.width;
|
||||||
if(isFixedRowHeight())
|
if(isFixedRowHeight())
|
||||||
|
@ -1477,18 +1455,9 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
Object realNode = getValue();
|
Object realNode = getValue();
|
||||||
TreeModel treeModel = getModel();
|
TreeModel treeModel = getModel();
|
||||||
int count = treeModel.getChildCount(realNode);
|
int count = treeModel.getChildCount(realNode);
|
||||||
|
int offset = originalRow == -1 ? -1 : originalRow + 1;
|
||||||
hasBeenExpanded = true;
|
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++) {
|
for (int i = 0; i < count; i++) {
|
||||||
newNode = createNodeForValue(treeModel.getChild
|
newNode = createNodeForValue(treeModel.getChild
|
||||||
(realNode, i));
|
(realNode, i));
|
||||||
|
@ -1496,20 +1465,14 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
newNode.updatePreferredSize(offset);
|
newNode.updatePreferredSize(offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int i = originalRow;
|
int i = originalRow;
|
||||||
Enumeration<TreeNode> cursor = preorderEnumeration();
|
Enumeration<TreeNode> cursor = preorderEnumeration();
|
||||||
cursor.nextElement(); // don't add me, I'm already in
|
cursor.nextElement(); // don't add me, I'm already in
|
||||||
|
|
||||||
int newYOrigin;
|
int newYOrigin = isFixed || (this == root && !isRootVisible()) ?
|
||||||
|
0 : getYOrigin() + this.getPreferredHeight();
|
||||||
|
|
||||||
if(isFixed)
|
|
||||||
newYOrigin = 0;
|
|
||||||
else if(this == root && !isRootVisible())
|
|
||||||
newYOrigin = 0;
|
|
||||||
else
|
|
||||||
newYOrigin = getYOrigin() + this.getPreferredHeight();
|
|
||||||
TreeStateNode aNode;
|
TreeStateNode aNode;
|
||||||
if(!isFixed) {
|
if(!isFixed) {
|
||||||
while (cursor.hasMoreElements()) {
|
while (cursor.hasMoreElements()) {
|
||||||
|
@ -1744,14 +1707,10 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
|
||||||
protected boolean updateNextIndex() {
|
protected boolean updateNextIndex() {
|
||||||
// nextIndex == -1 identifies receiver, make sure is expanded
|
// nextIndex == -1 identifies receiver, make sure is expanded
|
||||||
// before descend.
|
// before descend.
|
||||||
if(nextIndex == -1 && !parent.isExpanded())
|
if((nextIndex == -1 && !parent.isExpanded()) ||
|
||||||
return false;
|
childCount == 0 || // Check that it can have kids
|
||||||
|
++nextIndex >= childCount) // Make sure next index not beyond
|
||||||
// Check that it can have kids
|
// child count.
|
||||||
if(childCount == 0)
|
|
||||||
return false;
|
|
||||||
// Make sure next index not beyond child count.
|
|
||||||
else if(++nextIndex >= childCount)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
TreeStateNode child = (TreeStateNode)parent.
|
TreeStateNode child = (TreeStateNode)parent.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue