package extractor.ui;

import javax.swing.JTree;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeSelectionModel;
import java.net.URL;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.tree.*;
import javax.swing.*;

import extractor.classToEjb.classToEntity.*;
import extractor.classToEjb.*;

public class ResultEntityBean extends JPanel {

    EntityBeanExtractor ex;
    
    public ResultEntityBean(EntityBeanExtractor ex) {
    	this.ex = ex;
    	
        //Create the nodes.
        DefaultMutableTreeNode top = new DefaultMutableTreeNode(ex.ejbName);
        createNodes(top);

        //Create a tree that allows one selection at a time.
        final JTree tree = new JTree(top);
        tree.getSelectionModel().setSelectionMode
                (TreeSelectionModel.SINGLE_TREE_SELECTION);

        //Listen for when the selection changes.
        tree.addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                                   tree.getLastSelectedPathComponent();

                if (node == null) return;

                Object nodeInfo = node.getUserObject();
                if (node.isLeaf()) {
                        System.out.print("I'm a leaf. ");
                } else {
                    
                }
            }
        });

	DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
	renderer.setLeafIcon(new ImageIcon("images/class.gif"));
	tree.setCellRenderer(renderer);

        JScrollPane treeView = new JScrollPane(tree);
        treeView.setPreferredSize(new Dimension(500, 300));
	treeView.setBorder(BorderFactory.createTitledBorder("Entity bean ÃßÃâ°á°ú : "));		
	
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
        add(treeView, BorderLayout.CENTER);
    }

    private void createNodes(DefaultMutableTreeNode top) {
        DefaultMutableTreeNode bean = null;
        DefaultMutableTreeNode beanMethod = null;
        
        bean = new DefaultMutableTreeNode(ex.beanName);
        top.add(bean);
        
        bean = new DefaultMutableTreeNode(ex.remoteIF.remoteName);
        top.add(bean);
        
        bean = new DefaultMutableTreeNode(ex.homeIF.homeName);
        top.add(bean);

	/*RemoteInterfaceInfo remoteInfo= ebInfo.getRemoteIF();	
	System.out.println("remoteInfo = " + remoteInfo);
        bean = new DefaultMutableTreeNode(remoteInfo.remoteName);
        top.add(bean);
        Vector remoteMethods = remoteInfo.methods;
        for(Enumeration e=remoteMethods.elements();e.hasMoreElements();)
        {
        	beanMethod = new DefaultMutableTreeNode(e.nextElement());
        	bean.add(beanMethod);
        }*/
    }

  	public void execute() 
  	{

  	}

    /*public static void main(String[] args) {
        ResultEntityBean r = new ResultEntityBean();
        JFrame frame = new JFrame();        
 
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });  
	frame.getContentPane().add(r);
 
        frame.pack();
        frame.setVisible(true);
    }*/
}
