// Copyright (c) 1995, 1996 Regents of the University of California.
// All rights reserved.
//
// This software was developed by the Arcadia project
// at the University of California, Irvine.
//
// Redistribution and use in source and binary forms are permitted
// provided that the above copyright notice and this paragraph are
// duplicated in all such forms and that any documentation,
// advertising materials, and other materials related to such
// distribution and use acknowledge that the software was developed
// by the University of California, Irvine.  The name of the
// University may not be used to endorse or promote products derived
// from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

// File: NetNode.java
// Classes: NetNode
// Original Author: ics125b spring 1996
// $Id: NetNode.java,v 1.1.1.1 1997/02/27 20:52:35 chandra Exp $

package uci.graphedit;

import java.util.Vector;
import java.util.Enumeration;
import java.awt.Event;
import java.awt.Point;

/** This class models a node in our underlying connected graph
 * model. Nodes have ports that are their connection points to other
 * nodes. Arcs from one port to another.
 *
 * @see NetArc
 * @see NetPort
 */

public class NetNode extends NetPrimitive 
{

  /** A list of the ports on this node */
  protected Vector inArcList;
  protected Vector outArcList;
  protected int uid;
  protected Perspective _perspective;

  public NetNode(){inArcList=new Vector();outArcList=new Vector();}
  
  public int outSize(){return outArcList.size();}
  public int getId(){return uid;}
  public Vector inList(){return inArcList;}
  public Vector outList(){return outArcList;}
  /** Remove this node from the underling connected graph model. */

  public void dispose() 
  {
    System.out.println("disposing: " + toString());
    disposeArcs();
  }

  /** Add an arc to the list of arcs connected to this port. Called
  * when the user defines a new arc. Normally, you would not call
  this directly, you would call NetArc#connect(). */
  public void addInArc(NetArc arc) { inArcList.addElement(arc); }
  public void addOutArc(NetArc arc) { outArcList.addElement(arc); }

  /** Remove an arc from the list of arcs connected to this
   * port. Called when the user deletes an arc. Normally, you would
   * not call this directly, you would call NetArc#dispose().*/
  public void removeArc(NetArc arc) 
  { 
	  inArcList.removeElement(arc); 
	  outArcList.removeElement(arc);
  }


  /** Remove this port from the underlying connected graph model and
   * dispose all arcs connected to it. */
  public void disposeArcs() 
  {
	  Enumeration arcs=inArcList.elements();
	  while (arcs.hasMoreElements()) 
		  ((NetArc) arcs.nextElement()).dispose();
	  arcs=outArcList.elements();
	  while (arcs.hasMoreElements()) 
		  ((NetArc) arcs.nextElement()).dispose();
  }



  /** Usually when nodes are created it is deon through newInstance
   *  and there is no chance to supply a default node or to connect
   *  this node to some other application level object. So after a
   *  node is constructed initialize is called to supply that
   *  information. <p>
   *
   * Needs-More-Work: what is the class protocol design here? */
  public void initialize(NetNode default_node,String name,Document d,Point p){}
  public void initialize(VertexInfo model,Document d,int id) { }


  /** Add a perspective to my list of predefined perspectives. */
  public void set_Perspective(Perspective p) {_perspective=p;}

  /** By default the zeroth perspective will be used */
  public Perspective get_Perspective() { return _perspective;}


  /** NetNode's can process events. If the Editor does not want to
   * process an Event and the Editor's current Mode does not want to
   * process it, then the Event is passed to the NetNode under the
   * mouse, if there is one. This allows nodes to react to user input
   * * to do application specific actions. By default all of these
   * event * handlers do nothing and return false. By convention,
   * event * handlers in subclasses should call the handler in their
   * superclass * if the choose not to handle an event. */
  public boolean keyDown(Event e, int key) { return false; }
  public boolean mouseMove(Event e, int x, int y) { return false; }
  public boolean mouseDrag(Event e, int x, int y) { return false; }
  public boolean mouseDown(Event e, int x, int y) { return false; }
  public boolean mouseUp(Event e,int x,int y) {return false;}


  /** Do some application specific action just after this node is
   * disconnected from another node. the arguments contain some info
   * about what ports were connected. */
  public void postDisconnect(NetNode sourceNode,NetNode destNode) { }

} /* end class NetNode */