本文整理汇总了Java中javax.swing.tree.TreeNode.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java TreeNode.getParent方法的具体用法?Java TreeNode.getParent怎么用?Java TreeNode.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeNode
的用法示例。
在下文中一共展示了TreeNode.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTreePath
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public static TreePath getTreePath(JTreeOperator treeOperator, String targetNode, NodeConverter converter) {
Stack<TreeNode> lifo = new Stack<TreeNode>();
lifo.push((TreeNode) treeOperator.getRoot());
while(!lifo.isEmpty()) {
TreeNode actNode = lifo.pop();
if(targetNode.equals(converter.getDisplayName(actNode))) {
List<TreeNode> path = new LinkedList<TreeNode>();
path.add(actNode);
actNode = actNode.getParent();
while(actNode!=null) {
path.add(0,actNode);
actNode = actNode.getParent();
}
TreeNode[] res = path.toArray(new TreeNode[path.size()]);
return new TreePath(res);
}
final Enumeration children = actNode.children();
while(children.hasMoreElements()) {
lifo.add((TreeNode)children.nextElement());
}
}
return null;
}
示例2: getPathToRoot
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private TreeNode[] getPathToRoot(TreeNode aNode) {
TreeNode[] retNodes;
ArrayList<TreeNode> temp = new ArrayList<TreeNode>();
/* Check for null, in case someone passed in a null node, or
they passed in an element that isn't rooted at root. */
while (aNode != null) {
temp.add(aNode);
aNode = aNode.getParent();
}
int num = temp.size();
retNodes = new TreeNode[num];
for (int i = num - 1; i >= 0; i--) {
retNodes[num - 1 - i] = temp.get(i);
}
return retNodes;
}
示例3: nodeChanged
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Invoke this method after you've changed how node is to be
* represented in the tree.
*/
@Override
public void nodeChanged(TreeNode node) {
if (listenerList != null && node != null) {
TreeNode parent = node.getParent();
if (parent == null && node != root) {
parent = root;
}
if (parent != null) {
int anIndex = getIndexOfChild(parent, node);
if (anIndex != -1) {
int[] cIndexs = new int[1];
cIndexs[0] = anIndex;
nodesChanged(parent, cIndexs);
}
}
}
}
示例4: getNextSibling
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the next sibling of this node in the parent's children array.
* Returns null if this node has no parent or is the parent's last child.
* This method performs a linear search that is O(n) where n is the number
* of children; to traverse the entire array, use the parent's child
* enumeration instead.
*
* @param node
* @see #children
* @return the sibling of this node that immediately follows this node
*/
public TreeNode getNextSibling(TreeNode node) {
TreeNode retval;
TreeNode myParent = node.getParent();
if (myParent == null) {
retval = null;
} else {
retval = getChildAfter(myParent, node); // linear search
}
if (retval != null && !isNodeSibling(node, retval)) {
// throw new Error("child of parent is not a sibling");
}
return retval;
}
示例5: getPreviousSibling
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the previous sibling of this node in the parent's children array.
* Returns null if this node has no parent or is the parent's first child.
* This method performs a linear search that is O(n) where n is the number
* of children.
*
* @param node
* @return the sibling of this node that immediately precedes this node
*/
public TreeNode getPreviousSibling(TreeNode node) {
TreeNode retval;
TreeNode myParent = (TreeNode) node.getParent();
if (myParent == null) {
retval = null;
} else {
retval = getChildBefore(myParent, node); // linear search
}
if (retval != null && !isNodeSibling(node, retval)) {
// throw new Error("child of parent is not a sibling");
}
return retval;
}
示例6: isNodeSibling
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns true if <code>anotherNode</code> is a sibling of (has the same
* parent as) this node. A node is its own sibling. If
* <code>anotherNode</code> is null, returns false.
*
* @param node
* @param anotherNode node to test as sibling of this node
* @return true if <code>anotherNode</code> is a sibling of this node
*/
public boolean isNodeSibling(TreeNode node, TreeNode anotherNode) {
boolean retval;
if (anotherNode == null) {
retval = false;
} else if (anotherNode == node) {
retval = true;
} else {
TreeNode myParent = node.getParent();
retval = (myParent != null && myParent == anotherNode.getParent());
if (retval && !isNodeChild(node.getParent(), anotherNode)) {
throw new Error("sibling has different parent");
}
}
return retval;
}
示例7: getPathToRoot
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
/**
* Returns the path to a particluar node. This is recursive.
*/
@Override
protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
TreeNode[] retNodes;
/* Check for null, in case someone passed in a null node, or
they passed in an element that isn't rooted at root. */
if (aNode == null) {
if (depth == 0) {
return null;
} else {
retNodes = new TreeNode[depth];
}
} else {
depth++;
if (aNode == root) {
retNodes = new TreeNode[depth];
} else {
TreeNode parent = aNode.getParent();
if (parent == null) {
parent = root;
}
retNodes = getPathToRoot(parent, depth);
}
retNodes[retNodes.length - depth] = aNode;
}
return retNodes;
}
示例8: getIcon
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public javax.swing.Icon getIcon(Object o) {
if (!showIcons) {
return emptyIcon;
}
Node n = Visualizer.findNode(o);
if (n == null) {
throw new IllegalStateException("TreeNode must be VisualizerNode but was: " + o + " of class " + o.getClass().getName());
}
boolean expanded = false;
if (o instanceof TreeNode) {
TreeNode tn = (TreeNode)o;
ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
while (tn != null) {
al.add(tn);
tn = tn.getParent();
}
Collections.reverse(al);
TreePath tp = new TreePath(al.toArray());
AbstractLayoutCache layout = table.getLayoutCache();
expanded = layout.isExpanded(tp);
}
java.awt.Image image = null;
if (expanded) {
image = n.getOpenedIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
} else {
image = n.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
}
return new ImageIcon(image);
}
示例9: expandSelection
import javax.swing.tree.TreeNode; //导入方法依赖的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: rowForNode
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
private int rowForNode(Node n) {
TreeNode tn = Visualizer.findVisualizer(n);
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());
int row = outline.getLayoutCache().getRowForPath(tp);
return row;
}
return -1;
}
示例11: configureNode
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public void configureNode() {
TreeNode parent = this.parent;
while (!(parent instanceof ClassNode))
parent = parent.getParent();
file = ((ClassNode) parent).file;
position = metDec.getBegin().get();
}
示例12: configureNode
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public void configureNode() {
TreeNode parent = getParent();
while (! (parent instanceof ClassNode))
parent = parent.getParent();
file = ((ClassNode) parent).file;
position = conDec.getBegin().get();
}
示例13: canMoveUp
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public boolean canMoveUp(GenericTreeModel<T> model, T node)
{
TreeNode parent = node.getParent();
if( parent == null )
{
return false;
}
else
{
int index = parent.getIndex(node);
return index > 0 || parent.getParent() != null;
}
}
示例14: canMoveDown
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
@Override
public boolean canMoveDown(GenericTreeModel<T> model, T node)
{
TreeNode parent = node.getParent();
if( parent == null )
{
return false;
}
else
{
int index = parent.getIndex(node);
return index < parent.getChildCount() - 1 || parent.getParent() != null;
}
}
示例15: getTreePath
import javax.swing.tree.TreeNode; //导入方法依赖的package包/类
public static TreePath getTreePath(TreeNode treeNode) {
List<Object> nodes = Lists.newArrayList(treeNode);
while ((treeNode = treeNode.getParent()) != null) {
nodes.add(0, treeNode);
}
return new TreePath(nodes.toArray());
}