org.tigris.gef.base
Class ModeCreate

java.lang.Object
  extended by org.tigris.gef.base.ModeImpl
      extended by org.tigris.gef.base.FigModifyingModeImpl
          extended by org.tigris.gef.base.ModeCreate
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.util.EventListener, FigModifyingMode, Mode
Direct Known Subclasses:
ModeCreateEdge, ModeCreateFigCircle, ModeCreateFigImage, ModeCreateFigInk, ModeCreateFigLine, ModeCreateFigPoly, ModeCreateFigRect, ModeCreateFigRRect, ModeCreateFigText, ModeCreatePolyEdge

public abstract class ModeCreate
extends FigModifyingModeImpl

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  int _defaultHeight
           
protected  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 org.tigris.gef.base.FigModifyingModeImpl
editor
 
Fields inherited from class org.tigris.gef.base.ModeImpl
_args
 
Constructor Summary
ModeCreate()
           
ModeCreate(Editor par)
           
 
Method Summary
protected  void createFig(java.awt.event.MouseEvent me)
           
abstract  Fig createNewItem(java.awt.event.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.
 java.awt.Cursor getInitialCursor()
          By default all creation modes use CROSSHAIR_CURSOR.
 void keyPressed(java.awt.event.KeyEvent ke)
           
 void mouseDragged(java.awt.event.MouseEvent me)
          On mouse drag, resize the new item as the user moves the mouse.
 void mousePressed(java.awt.event.MouseEvent me)
          On mouse down, make a new Fig in memory.
 void mouseReleased(java.awt.event.MouseEvent me)
          On mouse up, officially add the new item to the parent Editor and select it.
 void paint(java.awt.Graphics g)
          Paint this mode by painting the new item.
 
Methods inherited from class org.tigris.gef.base.FigModifyingModeImpl
done, getEditor, instructions, isFigEnclosedIn, print, setCursor, setEditor
 
Methods inherited from class org.tigris.gef.base.ModeImpl
canExit, getArg, getArgs, init, keyReleased, keyTyped, leave, mouseClicked, mouseEntered, mouseExited, mouseMoved, setArg, setArgs, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.tigris.gef.base.Mode
canExit, getArg, getArgs, init, setArg, setArgs, start
 

Field Detail

_defaultWidth

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


_defaultHeight

protected int _defaultHeight

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 java.awt.Cursor getInitialCursor()
By default all creation modes use CROSSHAIR_CURSOR.

Specified by:
getInitialCursor in interface FigModifyingMode
Overrides:
getInitialCursor in class FigModifyingModeImpl

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
On mouse down, make a new Fig in memory.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class ModeImpl

createFig

protected void createFig(java.awt.event.MouseEvent me)

mouseDragged

public void mouseDragged(java.awt.event.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.damageAll(_newItem).

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class ModeImpl

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
On mouse up, officially add the new item to the parent Editor and select it. Then exit this mode.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class ModeImpl

keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
Specified by:
keyPressed in interface java.awt.event.KeyListener
Overrides:
keyPressed in class ModeImpl

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(java.awt.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.

Specified by:
paint in interface FigModifyingMode
Overrides:
paint in class FigModifyingModeImpl

createNewItem

public abstract Fig createNewItem(java.awt.event.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).