uci.gef
Class Mode

java.lang.Object
  |
  +--uci.gef.Mode
Direct Known Subclasses:
ModeBroom, ModeCreate, ModeDragScroll, ModeModify, ModePlace, ModePopup, ModeSelect

public abstract class Mode
extends Object
implements Serializable, KeyListener, MouseListener, MouseMotionListener

This is the abstract superclass of all editor modes. 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 ModeCreateEdge will drag out a rubberband line. Placing the logic for most event handing in Modes 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. Modes should interpert user input and ask the Editor to execute Cmds. Placing the logic to manipulate the document into Cmds helps keep Mode's small and promotes sharing of Cmd code.

See Also:
Editor, Cmd, ModeSelect, ModeCreateEdge, Serialized Form

Field Summary
protected  Hashtable _args
          Arguments to this mode.
 Editor _editor
          The Editor that is in this mode.
 
Constructor Summary
Mode()
          Construct a new Mode instance without any Editor as its parent, the parent must be filled in before the instance is actually used.
Mode(Editor par)
          Construct a new Mode instance with the given Editor as its _editor
 
Method Summary
 boolean canExit()
          Some Mode's should never be exited, but by default any Mode can exit.
 void done()
          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 ModeCreateEdge) the Mode calls done to set the parent Editor's Mode to some other Mode (normally ModeSelect).
 Object getArg(String s)
           
 Hashtable getArgs()
           
 Editor getEditor()
          Get the parent Editor of this Mode
 Cursor getInitialCursor()
          Returns the cursor that should be shown when this Mode starts.
 String instructions()
          Reply a string of instructions that should be shown in the statusbar when this mode starts.
 void keyPressed(KeyEvent ke)
           
 void keyReleased(KeyEvent ke)
           
 void keyTyped(KeyEvent ke)
           
 void mouseClicked(MouseEvent me)
           
 void mouseDragged(MouseEvent me)
           
 void mouseEntered(MouseEvent me)
           
 void mouseExited(MouseEvent me)
           
 void mouseMoved(MouseEvent me)
           
 void mousePressed(MouseEvent me)
           
 void mouseReleased(MouseEvent me)
           
 void paint(Graphics g)
          Modes can paint themselves to give the user feedback.
 void print(Graphics g)
          Just calls paint(g) bt default.
 void setArg(String key, Object value)
           
 void setArgs(Hashtable args)
           
 void setCursor(Cursor c)
          Set the mouse cursor to some appropriate for this mode.
 void setEditor(Editor w)
          Set the parent Editor of this Mode
 void start()
          When the user performs the first AWT Event that indicate that they want to do some work in this mode, then change the global next mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_editor

public Editor _editor
The Editor that is in this mode. Each Mode instance belongs to exactly one Editor instance.

_args

protected Hashtable _args
Arguments to this mode. These are usually set just after the mode is created, and the are used later.
See Also:
ModeCreateEdge
Constructor Detail

Mode

public Mode(Editor par)
Construct a new Mode instance with the given Editor as its _editor

Mode

public Mode()
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 CmdSetMode can only call Class.newInstance which does not pass constructor arguments.
See Also:
CmdSetMode
Method Detail

setEditor

public void setEditor(Editor w)
Set the parent Editor of this Mode

getEditor

public Editor getEditor()
Get the parent Editor of this Mode

getInitialCursor

public Cursor getInitialCursor()
Returns the cursor that should be shown when this Mode starts.

setArgs

public void setArgs(Hashtable args)

setArg

public void setArg(String key,
                   Object value)

getArgs

public Hashtable getArgs()

getArg

public Object getArg(String s)

keyPressed

public void keyPressed(KeyEvent ke)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent ke)
Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent ke)
Specified by:
keyTyped in interface KeyListener

mouseMoved

public void mouseMoved(MouseEvent me)
Specified by:
mouseMoved in interface MouseMotionListener

mouseDragged

public void mouseDragged(MouseEvent me)
Specified by:
mouseDragged in interface MouseMotionListener

mouseClicked

public void mouseClicked(MouseEvent me)
Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent me)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent me)
Specified by:
mouseReleased in interface MouseListener

mouseExited

public void mouseExited(MouseEvent me)
Specified by:
mouseExited in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent me)
Specified by:
mouseEntered in interface MouseListener

done

public void done()
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 ModeCreateEdge) the Mode calls done to set the parent Editor's Mode to some other Mode (normally ModeSelect).

start

public void start()
When the user performs the first AWT Event that indicate that they want to do some work in this mode, then change the global next mode. For example, this is useful when the user clicks on a palette button which sets the global next mode. That Mode should only be given to one Editor, after that it should go back to ModeSelect, unless the sticky flag is set.

canExit

public boolean canExit()
Some Mode's should never be exited, but by default any Mode can exit. Mode's which return false for canExit() will not be popped from a ModeManager.
See Also:
ModeManager

instructions

public String instructions()
Reply a string of instructions that should be shown in the statusbar when this mode starts.

setCursor

public void setCursor(Cursor c)
Set the mouse cursor to some appropriate for this mode.

paint

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

print

public void print(Graphics g)
Just calls paint(g) bt default.