/**
   The panel that will display the UML diagram of a class
   @author Sugiharto Widjaja
   @version 05/08/02
*/

import javax.swing.*;
import java.util.*;
import java.awt.*;

public class ComplexObjectNode extends JPanel
{

   /**
      Construct a ComplexObjectNode object
      @param args the name of the class
   */
   public ComplexObjectNode(String args)
   {
      theArgs = args;
      mainClass = null;
      errorMsg = null;
   }

   /**
      Try to create a Class object from a given class name.
      Create a panel and an object node from the Class object.
      Add the node to the panel and expand the object node.
      @throw ClassNotFoundException
      @throw InstantiationException
      @throw IllegalAccessException
   */
   public void createClass()
   {
      try
      {
         mainClass = Class.forName(theArgs);
         panel = new NodePanel();
         theNode = new ObjectNode(mainClass.newInstance(), panel);
         panel.add(theNode);
         theNode.expand(panel);
      }
      catch(ClassNotFoundException e)
      {
         errorMsg = "Class \" " + theArgs + " \" is not found";
      }
      catch(InstantiationException e)
      {
         errorMsg = "Cannot instantiate class \" " + theArgs + " \"";
      }
      catch(IllegalAccessException e)
      {
         errorMsg = "Cannot access class \" " + theArgs + " \"";
      }
   }

   /**
      Get the NodePanel
      @return NodePanel
   */
   public NodePanel getPanel()
   {
      return panel;
   }

   /**
      Get the error msg if an error occurs while trying to create a class
      object and its instance.
      @return the error msg, null if no error occurs
   */
   public String getErrorMsg()
   {
      return errorMsg;
   }

   // The name of the class
   private String theArgs;
   // The Class object
   private Class mainClass;
   // The panel where all the UML graphs will be put at
   private NodePanel panel;
   // The Class node
   private ObjectNode theNode;
   // Error message that tells us what error occurs during creation of a Class object
   private String errorMsg;
}

