path
, that are
* located in paths
.
*/
private void removeSiblings(TreePath path, TreePath[] paths) {
// Find the siblings
if (path.getPathCount() == 1) {
// Special case, set the root to null
for (int counter = paths.length - 1; counter >= 0; counter--) {
paths[counter] = null;
}
treeModel.setRoot(null);
} else {
// Find the siblings of path.
TreePath parent = path.getParentPath();
MutableTreeNode parentNode = (MutableTreeNode) parent.
getLastPathComponent();
ArrayListpaths
. Will return null if there is no non-null
* TreePath is paths
.
*/
private TreePath findShallowestPath(TreePath[] paths) {
int shallowest = -1;
TreePath shallowestPath = null;
for (int counter = paths.length - 1; counter >= 0; counter--) {
if (paths[counter] != null) {
if (shallowest != -1) {
if (paths[counter].getPathCount() < shallowest) {
shallowest = paths[counter].getPathCount();
shallowestPath = paths[counter];
if (shallowest == 1) {
return shallowestPath;
}
}
} else {
shallowestPath = paths[counter];
shallowest = paths[counter].getPathCount();
}
}
}
return shallowestPath;
}
/**
* An Comparator that bases the return value on the index of the
* passed in objects in the TreeModel.
*
* This is actually rather expensive, it would be more efficient
* to extract the indices and then do the comparision.
*/
private class PositionComparator implements Comparator