本文整理汇总了Java中javax.swing.tree.TreePath.isDescendant方法的典型用法代码示例。如果您正苦于以下问题:Java TreePath.isDescendant方法的具体用法?Java TreePath.isDescendant怎么用?Java TreePath.isDescendant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreePath
的用法示例。
在下文中一共展示了TreePath.isDescendant方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasAsParent
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* implementation of JTreeOperator.TreePathChooser
*
* @param path TreePath
* @param indexInParent int
* @return boolean
*/
@Override
public boolean hasAsParent(TreePath path, int indexInParent) {
if (path.getPathCount() <= parentPathCount) {
return path.isDescendant(parentPath);
}
if (arr.length + parentPathCount < path.getPathCount()) {
return (false);
}
if (indices.length >= path.getPathCount() - parentPathCount
&& indices[path.getPathCount() - parentPathCount - 1] != indexInParent) {
return (false);
}
Object[] comps = path.getPath();
for (int i = parentPathCount; i < comps.length; i++) {
if (!comparator.equals(comps[i].toString(), arr[i - parentPathCount])) {
return (false);
}
}
return (true);
}
示例2: removedNodes
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
void removedNodes(List<VisualizerNode> removed) {
TreeSelectionModel sm = tree.getSelectionModel();
TreePath[] selPaths = (sm != null) ? sm.getSelectionPaths() : null;
List<TreePath> remSel = null;
for (VisualizerNode vn : removed) {
visHolder.removeRecur(vn.getChildren(false));
if (selPaths != null) {
TreePath path = new TreePath(vn.getPathToRoot());
for(TreePath tp : selPaths) {
if (path.isDescendant(tp)) {
if (remSel == null) {
remSel = new ArrayList<TreePath>();
}
remSel.add(tp);
}
}
}
}
removedNodeWasSelected = remSel != null;
if (remSel != null) {
try {
sm.removeSelectionPaths(remSel.toArray(new TreePath[remSel.size()]));
} catch (NullPointerException e) {
// if editing of label of removed node was in progress
// BasicTreeUI will try to cancel editing and repaint node
// which fails because node is already removed so it cannot get bounds of it
// catch and ignore (issue #136123)
}
}
}
示例3: getTreeCommonAncestors
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Finds the common ancestors from the given selected paths
*
* @param selectedPaths
* - The paths selected
* @return A List containing the common ancestors
*/
public static List<TreePath> getTreeCommonAncestors(TreePath[] selectedPaths) {
List<TreePath> commonAncestors = new ArrayList<TreePath>();
if (selectedPaths != null) {
commonAncestors.add(selectedPaths[0]);
for (int i = 0; i < selectedPaths.length; i++) {
boolean newPathToAdd = false;
List<TreePath> pathsToRemove = new ArrayList<TreePath>();
for (TreePath treePath : commonAncestors) {
if (treePath.isDescendant(selectedPaths[i])) {
newPathToAdd = false;
break;
} else if (selectedPaths[i].isDescendant(treePath)) {
pathsToRemove.add(treePath);
newPathToAdd = false;
} else {
newPathToAdd = true;
}
}
if (!pathsToRemove.isEmpty()) {
commonAncestors.removeAll(pathsToRemove);
commonAncestors.add(selectedPaths[i]);
} else if (newPathToAdd) {
commonAncestors.add(selectedPaths[i]);
}
}
}
return commonAncestors;
}
示例4: compare
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public int compare(RowMapping rm1, RowMapping rm2) {
int index1 = rm1.getModelRowIndex();
int index2 = rm2.getModelRowIndex();
if (index1 == index2) {
return 0;
}
TreePath tp1 = getLayoutCache().getPathForRow(index1);
TreePath tp2 = getLayoutCache().getPathForRow(index2);
if (tp1 == null) {
if (tp2 == null) {
return 0;
} else {
return -1;
}
} else if (tp2 == null) {
return 1;
}
if (tp1.isDescendant(tp2)) {
return -1;
}
if (tp2.isDescendant(tp1)) {
return 1;
}
boolean tp1Changed = false;
boolean tp2Changed = false;
TreePath parent1 = tp1.getParentPath();
TreePath parent2 = tp2.getParentPath();
if (parent1 != null && parent2 != null && parent1.equals(parent2) &&
getOutlineModel().isLeaf(tp1.getLastPathComponent()) &&
getOutlineModel().isLeaf(tp2.getLastPathComponent())) {
return ascending ? super.compare(rm1, rm2) : - super.compare(rm1, rm2);
}
while (tp1.getPathCount() < tp2.getPathCount()) {
tp2 = tp2.getParentPath();
tp2Changed = true;
}
while (tp1.getPathCount() > tp2.getPathCount()) {
tp1 = tp1.getParentPath();
tp1Changed = true;
}
parent1 = tp1.getParentPath();
parent2 = tp2.getParentPath();
while (parent1 != null && parent2 != null && !parent1.equals(parent2)) {
tp1 = parent1;
tp2 = parent2;
parent1 = tp1.getParentPath();
parent2 = tp2.getParentPath();
tp1Changed = true;
tp2Changed = true;
}
if (tp1Changed || tp2Changed) {
return compare(tempSortMap.get(tp1), tempSortMap.get(tp2));
} else {
return ascending ? super.compare(rm1, rm2) : - super.compare(rm1, rm2);
}
}