当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMutableTreeNode.getLevel方法代码示例

本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.getLevel方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.getLevel方法的具体用法?Java DefaultMutableTreeNode.getLevel怎么用?Java DefaultMutableTreeNode.getLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.tree.DefaultMutableTreeNode的用法示例。


在下文中一共展示了DefaultMutableTreeNode.getLevel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: filterNodeByKey

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
 * Filter node by key.
 *
 * @param node the node
 * @param key the key
 */
private void filterNodeByKey(DefaultMutableTreeNode node, String key){
		
		Vector<DefaultMutableTreeNode> toDeleteVect= new Vector<DefaultMutableTreeNode>();
		
		@SuppressWarnings("unchecked")
		Enumeration<DefaultMutableTreeNode> e = node.breadthFirstEnumeration();
		if(e != null){
			while (e.hasMoreElements()){
				DefaultMutableTreeNode actualElement = e.nextElement();
				if (actualElement.isLeaf() == true && key.isEmpty() == false && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == false) {
					//--- immediate removal invalidates the enumeration ---
	//				actualElement.removeFromParent();
					// --- remember for later removal ---
					toDeleteVect.add(actualElement); 
				}
				if(actualElement.isLeaf() == true && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == true){
					//--- (re)expand collapsed parent if search string matches ---
					int level = actualElement.getLevel() -1;
					StringBuilder sb = new StringBuilder();
					sb.append(level -1).append(",");
					String levelString = sb.toString();
					if(expansionState.contains(levelString) == false){
						levelString = sb.append(level).append(",").toString();
						expansionState = expansionState.concat(levelString);
					}
				}
			}
		}
		//--- delete nodes ---
		for( int i=0; i < toDeleteVect.size(); i++){
			toDeleteVect.get(i).removeFromParent();
		}
	}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:40,代码来源:ThreadInfoStorageTree.java

示例2: canImport

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
public boolean canImport(TransferHandler.TransferSupport support) {
    if(!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    if(!support.isDataFlavorSupported(nodesFlavor)) {
        return false;
    }
    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dl =
            (JTree.DropLocation)support.getDropLocation();
    JTree tree = (JTree)support.getComponent();
    int dropRow = tree.getRowForPath(dl.getPath());
    int[] selRows = tree.getSelectionRows();
    for(int i = 0; i < selRows.length; i++) {
        if(selRows[i] == dropRow) {
            return false;
        }
    }
    // Do not allow MOVE-action drops if a non-leaf node is
    // selected unless all of its children are also selected.
    int action = support.getDropAction();
    if(action == MOVE) {
        return haveCompleteNode(tree);
    }
    // Do not allow a non-leaf node to be copied to a level
    // which is less than its source level.
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode target =
        (DefaultMutableTreeNode)dest.getLastPathComponent();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode firstNode =
        (DefaultMutableTreeNode)path.getLastPathComponent();
    if(firstNode.getChildCount() > 0 &&
           target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:40,代码来源:TreeTransferHandler.java

示例3: createTransferable

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree)c;
    TreePath[] paths = tree.getSelectionPaths();
    if(paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies =
            new ArrayList<DefaultMutableTreeNode>();
        List<DefaultMutableTreeNode> toRemove =
            new ArrayList<DefaultMutableTreeNode>();
        DefaultMutableTreeNode node =
            (DefaultMutableTreeNode)paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for(int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next =
                (DefaultMutableTreeNode)paths[i].getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if(next.getLevel() < node.getLevel()) {
                break;
            } else if(next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes =
            copies.toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove =
            toRemove.toArray(new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:39,代码来源:TreeTransferHandler.java

示例4: run

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public void run() {
	createChildren(fileRoot, root);
	DefaultMutableTreeNode currentNode = root.getNextNode();
	if (currentNode.getLevel() == 1)
		tree.expandPath(new TreePath(currentNode.getPath()));
}
 
开发者ID:csanuragjain,项目名称:APKRepatcher,代码行数:8,代码来源:APKRepatcher.java

示例5: canImport

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public boolean canImport(TransferHandler.TransferSupport transferSupport) {
    if (!transferSupport.isDrop()) {
        return false;
    }
    transferSupport.setShowDropLocation(true);
    if (!transferSupport.isDataFlavorSupported(myDataFlavor)) {
        return false;
    }
    JTree tree = (JTree) transferSupport.getComponent();
    int[] selectionRows = tree.getSelectionRows();

    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dropLocation = (JTree.DropLocation) transferSupport.getDropLocation();
    int dropRow = tree.getRowForPath(dropLocation.getPath());
    if (Arrays.asList(selectionRows).contains(dropRow)) {
        return false;
    }

    // Do not allow MOVE-action drops if a non-leaf node is selected unless all of its children are also selected
    if (transferSupport.getDropAction() == MOVE) {
        return haveCompleteNode(tree);
    }

    // Do not allow a non-leaf node to be copied to a level which is less than its source level.
    TreePath destinationPath = dropLocation.getPath();
    DefaultMutableTreeNode target = (DefaultMutableTreeNode) destinationPath.getLastPathComponent();
    TreePath path = tree.getPathForRow(selectionRows[0]);
    DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (firstNode.getChildCount() > 0 && target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:35,代码来源:RmlTagTreeTransferHandler.java

示例6: createTransferable

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree) c;
    TreePath[] paths = tree.getSelectionPaths();
    if (paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies = new ArrayList<DefaultMutableTreeNode>();
        List<DefaultMutableTreeNode> toRemove = new ArrayList<DefaultMutableTreeNode>();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = new DefaultMutableTreeNode(node);
        copies.add(copy);
        toRemove.add(node);
        for (int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
            if (next.getLevel() < node.getLevel()) {
                break;
            } else if (next.getLevel() > node.getLevel()) {
                copy.add(new DefaultMutableTreeNode(next));
            } else {
                copies.add(new DefaultMutableTreeNode(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes = copies.toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove = toRemove.toArray(new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:32,代码来源:RmlTagTreeTransferHandler.java

示例7: canImport

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    support.setShowDropLocation(true);
    if (!support.isDataFlavorSupported(nodesFlavor)) {
        return false;
    }
    // Do not allow a drop on the drag source selections.
    JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
    JTree tree = (JTree) support.getComponent();
    int dropRow = tree.getRowForPath(dl.getPath());
    int[] selRows = tree.getSelectionRows();
    for (int i = 0; i < selRows.length; i++) {
        if (selRows[i] == dropRow) {
            return false;
        }
    }
    // Do not allow MOVE-action drops if a non-leaf node is
    // selected unless all of its children are also selected.
    int action = support.getDropAction();
    if (action == MOVE) {
        return haveCompleteNode(tree);
    }
    // Do not allow a non-leaf node to be copied to a level
    // which is less than its source level.
    TreePath dest = dl.getPath();
    DefaultMutableTreeNode target = (DefaultMutableTreeNode)
            dest.getLastPathComponent();
    TreePath path = tree.getPathForRow(selRows[0]);
    DefaultMutableTreeNode firstNode = (DefaultMutableTreeNode)
            path.getLastPathComponent();
    if (firstNode.getChildCount() > 0
            && target.getLevel() < firstNode.getLevel()) {
        return false;
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:LastNodeLowerHalfDrop.java

示例8: createTransferable

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree) c;
    TreePath[] paths = tree.getSelectionPaths();
    if (paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies = new ArrayList<>();
        List<DefaultMutableTreeNode> toRemove = new ArrayList<>();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for (int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next = (DefaultMutableTreeNode) paths[i]
                    .getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if (next.getLevel() < node.getLevel()) {
                break;
            } else if (next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes = copies
                .toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove = toRemove.toArray(
                new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:LastNodeLowerHalfDrop.java

示例9: addSingleMultipleNode

import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
protected DefaultMutableTreeNode addSingleMultipleNode(DefaultMutableTreeNode node, boolean isInnerClass){
	
	// --- Get all needed information about the node, which has to be copied --------
	DynType dt = (DynType) node.getUserObject();
	String clazz = dt.getClassName();
	OntologySingleClassSlotDescription oscsd = dt.getOntologySingleClassSlotDescription();
	
	JPanel oldPanel = dt.getPanel();
	JPanel parentPanel = (JPanel) oldPanel.getParent();

	// --- Get parent node ----------------------------------------------------------
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); 
	int depth2WorkOn = parentNode.getLevel()-1;
	
	// --- Create the panel/node as needed as a copy of the current node ------------
	JPanel blindPanel = new JPanel();
	blindPanel.setLayout(null);
	DefaultMutableTreeNode newNode = null;
	
	if (isInnerClass==true) {
		newNode = this.createInnerElements(oscsd, clazz, depth2WorkOn+1, blindPanel, parentNode, true);
		if (oldPanel.isVisible()==false) {
			// --- Case special class: set invisible and small ------------ 
			this.setJPanelInvisibleAndSmall(newNode);
		}
		
	} else {
		newNode = this.createOuterElements(oscsd, depth2WorkOn, blindPanel, parentNode, true);
	}
	
	// --- Place the node at the right position in the tree -------------------------
	newNode.removeFromParent();
	int nodeIndexPos = parentNode.getIndex(node)+1;
	objectTree.insertNodeInto(newNode, parentNode, nodeIndexPos);
	
	// --- Set the size of the new Panel --------------------------------------------
	DynType dtNew = (DynType) newNode.getUserObject();
	JPanel newPanel = dtNew.getPanel();
	
	// --- Layout the new panel -----------------------------------------------------
	if (oldPanel.isVisible()==true) {
		// ----------------------------------------------------------------
		// --- The normal case for visible classes ------------------------
		// ----------------------------------------------------------------			
		this.setPanelBounds(newPanel);
		newPanel.setPreferredSize(newPanel.getSize());

		// --- Now place the new sub panel on the right super panel -------
		int movement = oldPanel.getHeight() + 2;
		int xPos = oldPanel.getX();
		int yPos = oldPanel.getY() + movement;
		newPanel.setBounds(xPos, yPos, newPanel.getWidth(), newPanel.getHeight());
		
		// --- Add to parent panel ----------------------------------------
		parentPanel.add(newPanel);
		parentPanel.validate();
		this.setPanelBounds(parentPanel);
		
		// --- Now move the rest of the elements on the form ----------------------------
		this.moveAfterAddOrRemove(movement, newNode);
		
	} else {
		// ----------------------------------------------------------------
		// --- The case for special classes, that have to be invisible ----
		// ----------------------------------------------------------------
		newPanel.setVisible(false);
		newPanel.setBounds(oldPanel.getBounds());
		
	}
	
	// --- refresh the GUI ----------------------------------------------------------
	this.adjustPreferredSize();
	
	return newNode;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:77,代码来源:DynForm.java


注:本文中的javax.swing.tree.DefaultMutableTreeNode.getLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。