當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeNode.getParent方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:BeansTestCase.java

示例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;
}
 
開發者ID:zeng198821,項目名稱:CodeGenerate,代碼行數:20,代碼來源:CheckTreeSelectionModel.java

示例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);
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:ElementTreePanel.java

示例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;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:29,代碼來源:TreeSearch.java

示例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;
    }
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:27,代碼來源:TreeSearch.java

示例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;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:28,代碼來源:TreeSearch.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:ElementTreePanel.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:NodeRenderDataProvider.java

示例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);
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:OutlineView.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:PropertiesRowModel.java

示例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();
}
 
開發者ID:bufferhe4d,項目名稱:call-IDE,代碼行數:9,代碼來源:MethodNode.java

示例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();
}
 
開發者ID:bufferhe4d,項目名稱:call-IDE,代碼行數:10,代碼來源:ConstructorNode.java

示例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;
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:15,代碼來源:GenericTreeModel.java

示例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;
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:15,代碼來源:GenericTreeModel.java

示例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());
}
 
開發者ID:JFrogDev,項目名稱:jfrog-idea-plugin,代碼行數:8,代碼來源:ComponentUtils.java


注:本文中的javax.swing.tree.TreeNode.getParent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。