本文整理汇总了Java中javax.swing.tree.TreePath.getParentPath方法的典型用法代码示例。如果您正苦于以下问题:Java TreePath.getParentPath方法的具体用法?Java TreePath.getParentPath怎么用?Java TreePath.getParentPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreePath
的用法示例。
在下文中一共展示了TreePath.getParentPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: areSiblingsSelected
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private boolean areSiblingsSelected(TreePath path) {
TreePath parent = path.getParentPath();
if (parent == null) {
return true;
}
Object node = path.getLastPathComponent();
Object parentNode = parent.getLastPathComponent();
int childCount = model.getChildCount(parentNode);
for (int i = 0; i < childCount; i++) {
Object childNode = model.getChild(parentNode, i);
if (childNode == node) {
continue;
}
if (!isPathSelected(parent.pathByAddingChild(childNode))) {
return false;
}
}
return true;
}
示例2: getRowForPath
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Gets the row in the Outline table for a given TreePath or -1 if the
* TreePath is invalid.
*
* @param irTreePath TreePath in question
* @return Row of the path or -1 if it is invalid.
*/
public int getRowForPath(TreePath irTreePath) {
if (irTreePath.getParentPath() == null) {
return getVisibleRootModifier();
}
if (!isExpanded(irTreePath.getParentPath())) {
expandPath(irTreePath.getParentPath());
}
int lnRow = -1;
while (irTreePath.getParentPath() != null) {
lnRow += 1 + getPrecedingSiblingsRowSpan(irTreePath);
irTreePath = irTreePath.getParentPath();
}
return lnRow;
}
示例3: getPrecedingSiblingsRowSpan
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Gets the rowspan of siblings which are above irTreePath in the tree. Only
* expanded paths are taken into account.
*
* @param irTreePath
* @return
*/
protected int getPrecedingSiblingsRowSpan(TreePath irTreePath) {
OutlineModel lrModel = getOutline().getOutlineModel();
if (irTreePath.getParentPath() == null) {
return 0 + getVisibleRootModifier();
}
Object lrLast = irTreePath.getLastPathComponent();
TreePath lrParent = irTreePath.getParentPath();
int lnRowSpan = 0;
int lnIndex = lrModel.getIndexOfChild(lrParent.getLastPathComponent(), lrLast);
for (int i = lnIndex - 1; i >= 0; i--) {
Object lrSibling = lrModel.getChild(lrParent.getLastPathComponent(), i);
lnRowSpan += getRowSpanOfLastElement(lrParent.pathByAddingChild(lrSibling));
}
return lnRowSpan;
}
示例4: getNextPath
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
TreePath getNextPath(TreePath path, boolean down) {
TreeModel _model = model.treeModel;
TreeNode node = (TreeNode)path.getLastPathComponent();
if (down && _model.getChildCount(node) > 0)
return path.pathByAddingChild(_model.getChild(node, 0));
TreePath parentPath = path.getParentPath();
if (!down && parentPath == null)
return path.pathByAddingChild(_model.getChild(node, 0));
TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
int idx = _model.getIndexOfChild(parent, node) + 1;
if (_model.getChildCount(parent) > idx)
return parentPath.pathByAddingChild(_model.getChild(parent, idx));
if (!down && parentPath.getParentPath() == null) {
return parentPath.pathByAddingChild(_model.getChild(parent, 0));
} else {
return getNextPath(parentPath, false);
}
}
示例5: areSiblingsSelected
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private boolean areSiblingsSelected(TreePath path) {
TreePath parent = path.getParentPath();
if (parent == null) {
return true;
}
Object node = path.getLastPathComponent();
Object parentNode = parent.getLastPathComponent();
int childCount = model.getChildCount(parentNode);
for (int i = 0; i < childCount; i++) {
Object childNode = model.getChild(parentNode, i);
if (childNode == node) {
continue;
}
if (!isPathSelected(parent.pathByAddingChild(childNode))) {
return false;
}
}
return true;
}
示例6: clickOnPath
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Clicks on the node.
*
* @param path a path to click on.
* @param clickCount a number of clicks
* @param mouseButton InputEvent.BUTTON1/2/3_MASK value
* @param modifiers Combination of InputEvent.*_MASK values
* @throws TimeoutExpiredException
*/
public void clickOnPath(TreePath path, int clickCount, int mouseButton, int modifiers) {
if (path != null) {
output.printLine("Click on \"" + path.toString()
+ "\" path");
output.printGolden("Click on path");
makeComponentVisible();
if (path.getParentPath() != null) {
expandPath(path.getParentPath());
}
makeVisible(path);
scrollToPath(path);
Point point = getPointToClick(path);
clickMouse((int) point.getX(), (int) point.getY(), clickCount, mouseButton, modifiers);
} else {
throw (new NoSuchPathException());
}
}
示例7: isPathSelected
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public boolean isPathSelected(TreePath path, boolean dig) {
if (!dig) {
return super.isPathSelected(path);
}
while (path != null && !super.isPathSelected(path)) {
path = path.getParentPath();
}
return path != null;
}
示例8: toggleRemoveSelection
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private void toggleRemoveSelection(TreePath path) {
Stack stack = new Stack();
TreePath parent = path.getParentPath();
while (parent != null && !isPathSelected(parent)) {
stack.push(parent);
parent = parent.getParentPath();
}
if (parent != null) {
stack.push(parent);
} else {
super.removeSelectionPaths(new TreePath[]{path});
return;
}
while (!stack.isEmpty()) {
TreePath temp = (TreePath) stack.pop();
TreePath peekPath = stack.isEmpty() ? path : (TreePath) stack.peek();
Object node = temp.getLastPathComponent();
Object peekNode = peekPath.getLastPathComponent();
int childCount = model.getChildCount(node);
for (int i = 0; i < childCount; i++) {
Object childNode = model.getChild(node, i);
if (childNode != peekNode) {
super.addSelectionPaths(new TreePath[]{temp.pathByAddingChild(childNode)});
}
}
}
super.removeSelectionPaths(new TreePath[]{parent});
}
示例9: expandSelection
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Tries to expand nodes selected in the explorer manager.
*/
private void expandSelection() {
Node[] arr = manager.getSelectedNodes ();
for (int i = 0; i < arr.length; i++) {
if ( (arr[i].getParentNode() == null) && (! outline.isRootVisible())) {
// don't try to show root if it is invisible
continue;
}
TreeNode tn = Visualizer.findVisualizer(arr[i]);
if (tn != null) {
ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
while (tn != null) {
al.add(tn);
tn = tn.getParent();
}
Collections.reverse(al);
TreePath tp = new TreePath(al.toArray());
Deque<TreePath> pathsStack = new ArrayDeque<TreePath>(al.size());
while ((tp != null) && (tp.getPathCount() > 0)) {
tp = tp.getParentPath();
if (tp != null) {
pathsStack.addFirst(tp);
}
}
for (TreePath etp : pathsStack) {
outline.expandPath(etp);
}
}
}
}
示例10: isVisible
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Test if the tree path is visible (the parent path is expanded).
* @param path The tree path to test
* @return <code>true</code> if the path is visible, <code>false</code> otherwise.
*/
public boolean isVisible(TreePath path) {
if(path != null) {
TreePath parentPath = path.getParentPath();
if(parentPath != null) {
return isExpanded(parentPath);
}
// Root.
return true;
}
return false;
}
示例11: isPathSelected
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public boolean isPathSelected(TreePath path, boolean dig) {
if (!dig) {
return super.isPathSelected(path);
}
while (path != null && !super.isPathSelected(path)) {
path = path.getParentPath();
}
return path != null;
}
示例12: toggleRemoveSelection
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private void toggleRemoveSelection(TreePath path) {
java.util.Stack<TreePath> stack = new Stack<TreePath>();
TreePath parent = path.getParentPath();
while (parent != null && !isPathSelected(parent)) {
stack.push(parent);
parent = parent.getParentPath();
}
if (parent != null) {
stack.push(parent);
} else {
super.removeSelectionPaths(new TreePath[] { path });
return;
}
while (!stack.isEmpty()) {
TreePath temp = stack.pop();
TreePath peekPath = stack.isEmpty() ? path : (TreePath) stack.peek();
Object node = temp.getLastPathComponent();
Object peekNode = peekPath.getLastPathComponent();
int childCount = model.getChildCount(node);
for (int i = 0; i < childCount; i++) {
Object childNode = model.getChild(node, i);
if (childNode != peekNode) {
super.addSelectionPaths(new TreePath[] { temp.pathByAddingChild(childNode) });
}
}
}
super.removeSelectionPaths(new TreePath[] { parent });
}
示例13: select
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private void select(String id) {
DefaultMutableTreeNode node = nodeMap.get(id);
if (node == null) {
logger.warning("Unable to find node with id '" + id + "'.");
} else {
TreePath oldPath = tree.getSelectionPath();
if (oldPath != null && oldPath.getParentPath() != null) {
tree.collapsePath(oldPath.getParentPath());
}
TreePath newPath = new TreePath(node.getPath());
tree.scrollPathToVisible(newPath);
tree.expandPath(newPath);
showDetails((ColopediaTreeItem) node.getUserObject());
}
}
示例14: updatePredecessorsWithCheckMode
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
protected void updatePredecessorsWithCheckMode(TreePath tp, boolean check) {
TreePath parentPath = tp.getParentPath();
// If it is the root, stop the recursive calls and return
if (parentPath == null) {
return;
}
CheckedNode parentCheckedNode = nodesCheckingState.get(parentPath);
TreeNode parentNode = (TreeNode) parentPath.getLastPathComponent();
parentCheckedNode.allChildrenSelected = true;
parentCheckedNode.isSelected = false;
for (int i = 0; i < getChildCount(parentNode); i++) {
TreePath childPath = parentPath.pathByAddingChild(getChildAt(parentNode, i));
CheckedNode childCheckedNode = nodesCheckingState.get(childPath);
// It is enough that even one subtree is not fully selected
// to determine that the parent is not fully selected
if (!childCheckedNode.allChildrenSelected) {
parentCheckedNode.allChildrenSelected = false;
}
// If at least one child is selected, selecting also the parent
if (childCheckedNode.isSelected) {
parentCheckedNode.isSelected = true;
}
}
if (parentCheckedNode.isSelected) {
checkedPaths.add(parentPath);
} else {
checkedPaths.remove(parentPath);
}
// Go to upper predecessor
updatePredecessorsWithCheckMode(parentPath, check);
}
示例15: 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);
}
}