uci.gef
Class ModeCreate

java.lang.Object
  |
  +--uci.gef.Mode
        |
        +--uci.gef.ModeCreate
Direct Known Subclasses:
ModeCreateEdge, ModeCreateEdgeAndNode, ModeCreateFigCircle, ModeCreateFigImage, ModeCreateFigInk, ModeCreateFigLine, ModeCreateFigPoly, ModeCreateFigRect, ModeCreateFigRRect, ModeCreateFigText, ModeCreatePolyEdge

public abstract class ModeCreate
extends Mode

Abstract superclass for all Mode's that create new Figs. This class factors our shared code that would otherwise be duplicated in its subclasses. On a mouse down the new item is created in memory. On mouse drag the new item is resized via its createDrag() method. On mouse up the new item is officially added to the Layer being edited in the parent Editor, the item is selected, and the Editor is placed in the next Mode (usually ModeSelect). Subclasses override various of these event handlers to give specific behaviors, for example, ModeCreateEdge handles dragging differently.

See Also:
ModeCreateEdge, ModeCreateFigRect, ModeCreateFigRRect, ModeCreateFigLine, ModeCreateFigCircle, ModeCreateFigPoly, ModeCreateFigInk, ModeCreateFigText, ModeCreateFigImage, Serialized Form

Field Summary
protected static int _defaultHeight
          The default size of a Fig if the user simply clicks instead of dragging out a size.
protected static int _defaultWidth
          The default size of a Fig if the user simply clicks instead of dragging out a size.
protected  Fig _newItem
          This holds the Fig to be added to the parent Editor.
protected  int anchorX
          Original mouse down event coordinates
protected  int anchorY
          Original mouse down event coordinates
 
Fields inherited from class uci.gef.Mode
_args, _editor
 
Constructor Summary
ModeCreate()
           
ModeCreate(Editor par)
           
 
Method Summary
abstract  Fig createNewItem(MouseEvent me, int snapX, int snapY)
          Abstact method to construct a new Fig to be added to the Editor.
protected  void creationDrag(int x, int y)
          Update the new item to reflect the new mouse position.
 Cursor getInitialCursor()
          By default all creation modes use CROSSHAIR_CURSOR.
 void mouseDragged(MouseEvent me)
          On mouse drag, resize the new item as the user moves the mouse.
 void mousePressed(MouseEvent me)
          On mouse down, make a new Fig in memory.
 void mouseReleased(MouseEvent me)
          On mouse up, officially add the new item to the parent Editor and select it.
 void paint(Graphics g)
          Paint this mode by painting the new item.
 
Methods inherited from class uci.gef.Mode
canExit, done, getArg, getArgs, getEditor, instructions, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, mouseMoved, print, setArg, setArgs, setCursor, setEditor, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_defaultWidth

protected static int _defaultWidth
The default size of a Fig if the user simply clicks instead of dragging out a size.

_defaultHeight

protected static int _defaultHeight
The default size of a Fig if the user simply clicks instead of dragging out a size.

anchorX

protected int anchorX
Original mouse down event coordinates

anchorY

protected int anchorY
Original mouse down event coordinates

_newItem

protected Fig _newItem
This holds the Fig to be added to the parent Editor.
Constructor Detail

ModeCreate

public ModeCreate(Editor par)

ModeCreate

public ModeCreate()
Method Detail

getInitialCursor

public Cursor getInitialCursor()
By default all creation modes use CROSSHAIR_CURSOR.
Overrides:
getInitialCursor in class Mode

mousePressed

public void mousePressed(MouseEvent me)
On mouse down, make a new Fig in memory.
Overrides:
mousePressed in class Mode

mouseDragged

public void mouseDragged(MouseEvent me)
On mouse drag, resize the new item as the user moves the mouse. Maybe the Fig createDrag() method should be removed and I should call dragHandle(). That would elimiate one method from each oif several classes, but dragging during creation is not really the same thing as dragging after creation....

Note: _newItem has not been added to any Layer yet. So you cannot use _newItem.damage(), instead use _editor.damaged(_newItem).

Overrides:
mouseDragged in class Mode

mouseReleased

public void mouseReleased(MouseEvent me)
On mouse up, officially add the new item to the parent Editor and select it. Then exit this mode.
Overrides:
mouseReleased in class Mode

creationDrag

protected void creationDrag(int x,
                            int y)
Update the new item to reflect the new mouse position. By default let the new item set its size, subclasses may override. If the user simply clicks instead of dragging then use the default size. If the user actually drags out a Fig, then use its size as the new default size.
See Also:
creationDrag(int, int)

paint

public void paint(Graphics g)
Paint this mode by painting the new item. This is the only feedback that the user will get since the new item is not officially added to the Editor's document yet.
Overrides:
paint in class Mode

createNewItem

public abstract Fig createNewItem(MouseEvent me,
                                  int snapX,
                                  int snapY)
Abstact method to construct a new Fig to be added to the Editor. Typically, subclasses will make a new instance of some Fig based on the given mouse down event and the state of the parent Editor (specifically, its default graphical attributes).