⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntftree.java

📁 UCS (Ultra Corba Simulator) is one more powerful corba client/servant simulator tool than other simi
💻 JAVA
字号:
package com.corba.mnq.ntf;

import java.awt.*;
import javax.swing.tree.*;
import javax.swing.*;

public class NtfTree extends JTree 
{
    public  static DefaultMutableTreeNode rootNode=null;
 
    public  static NtfTable ntfTable;
    
    
    public NtfTree(NtfTable theTable)
    {
		ntfTable = theTable;
    }
    public void setRootUserObject( NtfNode cn )
    {
       	rootNode = new DefaultMutableTreeNode("root");
    	rootNode.setAllowsChildren(true);
    	setModel(new DefaultTreeModel(rootNode,true));  	
    	rootNode.setUserObject(cn);	 
    }
    /**
     * Bind a new name context and insert it
     */
    public void createChild(DefaultMutableTreeNode pNode,DefaultMutableTreeNode child)
    {
	  	DefaultTreeModel model = (DefaultTreeModel)getModel();
	  	if( pNode==null)
	  		System.out.println("pnode is null");
	  	if( child==null)
	  		System.out.println("child is null");
  
    	model.insertNodeInto(child,pNode,0);			   	
    }
    
    public void createUserNode( String name, NtfNode userNode )
    {
		TreePath path = null;
		int length = 0;
		try 
		{ 
		    path = getSelectionPath(); 
		    length = path.getPathCount();
		}
		catch (Exception e)
		{
		    JOptionPane.showMessageDialog(this,"Nothing selected",
						  "Selection error",JOptionPane.ERROR_MESSAGE);
		    return;
		}
		//add specific code
		if( length>0 ) 
		{
			DefaultMutableTreeNode pNode = (DefaultMutableTreeNode)path.getPathComponent(length-1);
	
			if (pNode.getAllowsChildren())
			{
				DefaultMutableTreeNode node = new DefaultMutableTreeNode();
			    	node.setUserObject(userNode);
			    	node.setAllowsChildren(true);
			    	DefaultTreeModel model = (DefaultTreeModel)getModel();
			    	model.insertNodeInto(node,pNode,0);			
			    	update();
			}
			else 
			{
			    JOptionPane.showMessageDialog(this,
		                                          "Please select a allow node",
							  "Selection error", JOptionPane.ERROR_MESSAGE);
			}
		}
	
    }

    /**
     * unbind a context and remove it from this tree
     */
	
    public void deleteUserNode()
    {
		DefaultMutableTreeNode node;
		TreePath path = null;
		int length = 0;
		try 
		{ 
		    path = getSelectionPath(); 
		    length = path.getPathCount();
	
		    if (length > 0)
		    {
			node = (DefaultMutableTreeNode)path.getPathComponent(length-1);
			NtfNode cn = (NtfNode)node.getUserObject();
			//process cn
			DefaultTreeModel model = (DefaultTreeModel)getModel();
			model.removeNodeFromParent(node);                
	                // select the parent node and display its content
	                DefaultMutableTreeNode parent = (DefaultMutableTreeNode)path.getPathComponent(length-2);
	                setSelectionPath(new TreePath(parent.getPath()));
			((NtfNode)parent.getUserObject()).display();
		    }
		}
		catch (Exception e) 
		{
	            e.printStackTrace();
	
		    JOptionPane.showMessageDialog(this,
						  "Nothing selected or invalid selection",
						  "Selection error",
						  JOptionPane.ERROR_MESSAGE);
		}
    }

    /**
     * update the entire tree of contexts
     */
	 
    public synchronized void update()
    {
    	DefaultTreeModel model = (DefaultTreeModel)getModel();
		ntfTable.update();
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -