import netscape_beta.application.*;
import netscape_beta.util.*;

/**
 * A class that displays visitors.  New visitors
 * are added by dragging a TreeNode in the class
 * graph into this view.
 *
 *
 * @version        1.0 12 Dec 1996
 * @author         Andrew Miller
 */
public class DemVisitorView extends ContainerView implements DragDestination
{
  protected static int m_sxSpacing = 10;
  protected static int m_sySpacing = 10;
  protected DemDoc m_doc = null;
  protected static DemScrollVisitorView m_parent = null;

  protected int m_yOffset;

    /**
     * Constructs a new DemVisitorView and display it in the given bounds
     * in the specified view, displaying the visitors for the specified doc.
     * @param rcView     The window's bounds.
     * @param parent     The parent view responsible for scrolling.
     * @param doc        The document to display.
     */
  public DemVisitorView(Rect rcView, DemScrollVisitorView parent, DemDoc doc)
  {
	// initialize the super
	super(rcView);

	m_doc = doc;
    m_parent = parent;

	setBorder(new BezelBorder(BezelBorder.LOWERED, Color.lightGray));
	setBackgroundColor(Color.white);

	// add it to the parent and update the view
	parent.addSubview(this);

	// set initial y-offset for contents
	m_yOffset = m_sxSpacing;
  }

    /**
     * Provides access to the view's document.
     * @return           The view's document.
     */
  public DemDoc getDoc()
  {
	return m_doc;
  }

    /**
     * Overridden to prevent resizing.  The DemVisitorView 
     * never needs to be risized since it is always contained
     * within a scroll group.
     * @return           Always false.
     */
  public boolean isResizable()
  {
	return false;
  }

    /**
     * Handle a drag and drop.  If a TreeNode is dropped,
     * create a new Visitor for it.
     * @param  ds        The dragsession.         
     * @return           true if a TreeNode was dropped
     */
  public boolean dragDropped(DragSession ds)
  {
      if(TreeNode.dataType().equals(ds.dataType()))
      {
		 // make a new visitor
		 TreeNode treeNode = (TreeNode)ds.data();
		 Visitor node = new Visitor(m_sySpacing,m_yOffset, treeNode.getNameForTraversal(), this);     
         
         m_doc.get_visitorManager().addVisitor(node);
         
         // view may have been resized by the insertion of the Drawable
         // into the view
         m_parent.updateScrolls();

         // force a repaint of the view
         setDirty(true);
		 
		 // update yoffset for next time
		 m_yOffset += node.height() + m_sxSpacing;
		 return true;
      }
      else
      {
         return false;
      }
  }
  
    /**
     * Handle a drag-entered. 
     * @return           true if a TreeNode was dragged
     */
  public boolean dragEntered(DragSession ds)
  {
      if(TreeNode.dataType().equals(ds.dataType()))
      {
           return true;
      }
      else
      {
           return false;
      }
  }

    /**
     * Determines if a drag-and-drop can occur in this view.
     * @return           true if a TreeNode was dragged
     */
  public DragDestination acceptsDrag(DragSession session, int x, int y) {
        // If an icon is being dragged to us, return the DragDestination
        // (the DemVisitorView itself.)
        if (TreeNode.dataType().equals(session.dataType())) {
            return this;
        } else {
            return null;
        }
    }
  
    /**
     * Implemented for use of interface.  Performs no action.
     */
  public void dragExited(DragSession ds)
  {
  }

   /**
     * Handle a drag-move in this view.
     * @return           true if a TreeNode was dragged
     */
 public boolean dragMoved(DragSession ds)
  {
      if(ds.dataType() == TreeNode.dataType)
      {
           return true;
      }
      else
      {
          return false;
      }
  }

}
