public abstract class DnDStateMachine extends CStateMachine
DnDStateMachine
is a predefined state machine to
implement "press-drag-release" interactions on shapes contained in a
SwingStates' canvas.
DnDStateMachine
can be used directly by only
overriding actions for press, drag and release (methods
pressAction
, dragAction
and releaseAction
.
Example: This program makes shapes drawn in a canvas movable by drag'n drop.
DnDStateMachine smDragShapes = new DnDStateMachine(BasicInputStateMachine.BUTTON1) { public void dragAction(CShape shape, double previousX, double previousY, double currentX, double currentY) { shape.translateBy(currentX - previousX, currentY - previousY); } public void releaseAction(CShape shape, double previousX, double previousY, double currentX, double currentY) { shape.translateBy(currentX - previousX, currentY - previousY); } }; smDragShapes.attachTo(canvas);
Modifier and Type | Field and Description |
---|---|
State |
move
The two states (start and move) of this machine.
|
State |
start
The two states (start and move) of this machine.
|
ANIMATION_RESUMED, ANIMATION_STARTED, ANIMATION_STOPPED, ANIMATION_SUSPENDED
ALT, ALT_CONTROL, ALT_CONTROL_SHIFT, ALT_SHIFT, ANYBUTTON, ANYMODIFIER, BUTTON1, BUTTON2, BUTTON3, CONTROL, CONTROL_SHIFT, NOBUTTON, NOMODIFIER, SHIFT
TIME_OUT
Constructor and Description |
---|
DnDStateMachine(int button)
Builds a state machine to manage press-drag-release
interactions that are inited on a
CShape . |
DnDStateMachine(int button,
java.lang.Class classTag)
Builds a state machine to manage press-drag-release
interactions that are inited on a
CShape
which has a tag of a given class classTag . |
DnDStateMachine(int button,
CTag tag)
Builds a state machine to manage press-drag-release
interactions that are inited on a
CShape
which has a given tag. |
Modifier and Type | Method and Description |
---|---|
void |
dragAction(CShape shape,
double previousX,
double previousY,
double currentX,
double currentY)
The method to override in subclasses to specify
action to do when a drag event occurs.
|
void |
pressAction(CShape shape,
double currentX,
double currentY)
The method to override in subclasses to specify
action to do when a press event on a
CShape
occurs. |
void |
releaseAction(CShape shape,
double previousX,
double previousY,
double currentX,
double currentY)
The method to override in subclasses to specify
action to do when a release event occurs.
|
attachTo, attachTo, controls, detach, getControlledObjects, greaterPriorityThan, greatestPriority, isAttachedTo, lowerPriorityThan, lowestPriority
addAsListenerOf, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, removeAsListenerOf
actionPerformed, addStateMachineListener, addStateMachineListener, armTimer, armTimer, consumes, disarmTimer, disarmTimer, doReset, doResume, doSuspend, eventOccured, fireEvent, fireEvent, getAllStates, getCurrentState, getInitialState, getState, hasConsumed, init, initStatesAndTransitions, isActive, isInited, processEvent, processEvent, removeStateMachineListener, removeStateMachineListener, reset, resume, setActive, suspend
public State start
public State move
public DnDStateMachine(int button)
CShape
.button
- The mouse button for press and release events (constants BUTTON1, BUTTON2, etc. in class BasicInputStateMachine
).BasicInputStateMachine.BUTTON1
,
BasicInputStateMachine.BUTTON2
,
BasicInputStateMachine.BUTTON3
public DnDStateMachine(int button, java.lang.Class classTag)
CShape
which has a tag of a given class classTag
.button
- The mouse button for press and release events (constants BUTTON1, BUTTON2, etc. in class BasicInputStateMachine
).classTag
- The class of the tag.BasicInputStateMachine.BUTTON1
,
BasicInputStateMachine.BUTTON2
,
BasicInputStateMachine.BUTTON3
public DnDStateMachine(int button, CTag tag)
CShape
which has a given tag.button
- The mouse button for press and release events (constants BUTTON1, BUTTON2, etc. in class BasicInputStateMachine
).tag
- The tag.BasicInputStateMachine.BUTTON1
,
BasicInputStateMachine.BUTTON2
,
BasicInputStateMachine.BUTTON3
public void pressAction(CShape shape, double currentX, double currentY)
CShape
occurs.shape
- The shape on which occured the press eventcurrentX
- The mouse x-coordinatecurrentY
- The mouse y-coordinatepublic void dragAction(CShape shape, double previousX, double previousY, double currentX, double currentY)
CShape
).shape
- The shape on which occured the press eventpreviousX
- The last mouse x-coordinatepreviousY
- The last mouse y-coordinatecurrentX
- The mouse x-coordinatecurrentY
- The mouse y-coordinatepublic void releaseAction(CShape shape, double previousX, double previousY, double currentX, double currentY)
CShape
).shape
- The shape on which occured the press eventpreviousX
- The last mouse x-coordinatepreviousY
- The last mouse y-coordinatecurrentX
- The mouse x-coordinatecurrentY
- The mouse y-coordinate