// 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: Mode.java
// Classes: Mode
// Original Author: ics125b spring 1996
// $Id: Mode.java,v 1.2 2000/09/19 21:08:33 dougo Exp $

// Modified by : Kedar Patankar
// Last Modified 22 Oct 1997

package edu.neu.ccs.demeter.tools.apstudio.graphedit;

import java.awt.Event;
import java.awt.Graphics;
import java.awt.Cursor;
import java.awt.event.MouseEvent;

/** This is the abstract superclass of all editor mode's. A Mode is
 * responsible for handling most of the events that come to the
 * Editor. A Mode defines a context for interperting those events. For
 * example, a mouse drag in ModeSelect will define a selection
 * rectangle, while a mouse drag in ModeCreateArc will drag out a
 * rubberband arc. Placing the logic for most event handing in Mode's
 * is key to keeping the Editor source code small and manageable, and
 * also key to allowing addition of new kinds of user interactions
 * without always modifying Editor and having to integrate ones
 * modifications with other contributors modifications. Mode's should
 * interpert user input and ask the Editor to execute
 * Action's. Placing the logic to manipulate the document into
 * Action's helps keep Mode's small and promotes sharing of Action
 * code.
 *
 * @see Editor
 * @see Action
 * @see ModeSelect
 * @see ModeCreateArc
 */

public abstract class Mode 
{

  /** The Editor that is in this mode. Each Mode instance belongs to
   * exactly one Editor instance.  */
  public Document parent;
  
  /** Construct a new Mode instance with the given Editor as its
   * parent */
  public Mode(Document par) { parent = par; }

  /** Construct a new Mode instance without any Editor as its parent,
   * the parent must be filled in before the instance is actually
   * used. This constructor is needed because ActionSetMode can only
   * call Class.newInstance which does not pass constructor arguments.
   *
   * @see ActionSetMode
   * @see Class#newInstance */
  public Document parent() { return parent; }

  /** When a Mode handles a certain event that indicates that the user
   * wants to exit that Mode (e.g., a mouse up event after a drag in
   * ModeCreateArc) the Mode calls done to set the parent Editor's
   * Mode to some other Mode (normally ModeSelect). */
  public void done() 
  { 
	  parent.mode(parent.nextMode()); 
  }

  /** Modes can draw themselves to give the user feedback. For
   * example, ModePlace draws the object being placed. Mode's are
   * drawn on top of (after) the Editor's current view and on top of
   * any selections. */
  public void draw(Graphics g) { }

  /** Mode's define event handlers. Subclasses of Mode define specific
   * handlers and invoke Actions. By default all these event handler
   * methods just return false. By convention if a Mode can not handle
   * a given event, it should call its inheritied event handler and
   * return the result that it produces. */
  public void mouseUp(MouseEvent e) {}
  public void mouseDown(MouseEvent e) {}
  public void mouseDrag(MouseEvent e) {}

  public abstract void setCursorType();
  public  abstract void setMessage(Editor e);

} /* end class Mode */

