public class BehaviorBase<C extends Control>
extends java.lang.Object
Although BehaviorBase is typically used as a base class, it is not abstract and several skins instantiate an instance of BehaviorBase directly.
BehaviorBase also implements the hooks for focus traversal. This implementation is sufficient for most subclasses of BehaviorBase. The following action names are registered in the keyMap for handling focus traversal. Subclasses which need to invoke focus traversal using non-standard key strokes should map key strokes to these action names:
Note that by convention, action names are camel case with the first letter uppercase, matching class naming conventions.
Modifier and Type | Field and Description |
---|---|
private C |
control
The Control with which this Behavior is used.
|
private InvalidationListener |
focusListener
Listens to any focus events on the Control and calls protected methods as a result
|
protected static boolean |
IS_TOUCH_SUPPORTED
A static final reference to whether the platform we are on supports touch.
|
private java.util.List<KeyBinding> |
keyBindings
The key bindings for this Behavior.
|
private EventHandler<KeyEvent> |
keyEventListener
Listens to any key events on the Control and responds to them
|
protected static java.util.List<KeyBinding> |
TRAVERSAL_BINDINGS
The default key bindings for focus traversal.
|
(package private) static java.lang.String |
TRAVERSE_DOWN |
(package private) static java.lang.String |
TRAVERSE_LEFT |
(package private) static java.lang.String |
TRAVERSE_NEXT |
(package private) static java.lang.String |
TRAVERSE_PREVIOUS |
(package private) static java.lang.String |
TRAVERSE_RIGHT |
(package private) static java.lang.String |
TRAVERSE_UP |
Constructor and Description |
---|
BehaviorBase(C control,
java.util.List<KeyBinding> keyBindings)
Create a new BehaviorBase for the given control.
|
Modifier and Type | Method and Description |
---|---|
protected void |
callAction(java.lang.String name)
Called to invoke the action associated with the given name.
|
protected void |
callActionForEvent(KeyEvent e)
Invokes the appropriate action for this key event.
|
void |
contextMenuRequested(ContextMenuEvent e)
Invoked by a Skin when the control has had its context menu requested,
most commonly by right-clicking on the control.
|
void |
dispose()
Called by a Skin when the Skin is disposed.
|
protected void |
focusChanged()
Called whenever the focus on the control has changed.
|
C |
getControl()
Gets the control associated with this behavior.
|
protected java.lang.String |
matchActionForEvent(KeyEvent e)
Given a key event, this method will find the matching action name, or null if there
is not one.
|
void |
mouseDragged(MouseEvent e)
Invoked by a Skin when the body of the control has been dragged by
the mouse.
|
void |
mouseEntered(MouseEvent e)
Invoked by a Skin when the body of the control has been entered by
the mouse.
|
void |
mouseExited(MouseEvent e)
Invoked by a Skin when the body of the control has been exited by
the mouse.
|
void |
mousePressed(MouseEvent e)
Invoked by a Skin when the body of the control has been pressed by
the mouse.
|
void |
mouseReleased(MouseEvent e)
Invoked by a Skin when the body of the control has been released by
the mouse.
|
protected void |
traverse(Node node,
Direction dir)
Called by any of the BehaviorBase traverse methods to actually effect a
traversal of the focus.
|
void |
traverseDown()
Calls the focus traversal engine and indicates that traversal should
go the next focusTraversable Node below the current one.
|
void |
traverseLeft()
Calls the focus traversal engine and indicates that traversal should
go the next focusTraversable Node left of the current one.
|
void |
traverseNext()
Calls the focus traversal engine and indicates that traversal should
go the next focusTraversable Node in the focus traversal cycle.
|
void |
traversePrevious()
Calls the focus traversal engine and indicates that traversal should
go the previous focusTraversable Node in the focus traversal cycle.
|
void |
traverseRight()
Calls the focus traversal engine and indicates that traversal should
go the next focusTraversable Node right of the current one.
|
void |
traverseUp()
Calls the focus traversal engine and indicates that traversal should
go the next focusTraversable Node above the current one.
|
protected static final boolean IS_TOUCH_SUPPORTED
protected static final java.util.List<KeyBinding> TRAVERSAL_BINDINGS
static final java.lang.String TRAVERSE_UP
static final java.lang.String TRAVERSE_DOWN
static final java.lang.String TRAVERSE_LEFT
static final java.lang.String TRAVERSE_RIGHT
static final java.lang.String TRAVERSE_NEXT
static final java.lang.String TRAVERSE_PREVIOUS
private final C extends Control control
private final java.util.List<KeyBinding> keyBindings
private final EventHandler<KeyEvent> keyEventListener
private final InvalidationListener focusListener
public BehaviorBase(C control, java.util.List<KeyBinding> keyBindings)
control
- The control. Must not be null.keyBindings
- The key bindings that should be used with this behavior.
Null is treated as an empty list.public void dispose()
public final C getControl()
protected void callActionForEvent(KeyEvent e)
e
- The key event. Must not be null.protected java.lang.String matchActionForEvent(KeyEvent e)
e
- The key event. Must not be null.protected void callAction(java.lang.String name)
When a KeyEvent is handled, it is first passed through callActionForEvent which resolves which "action" should be executed based on the key event. This action is indicated by name. This name is then passed to this function which is responsible for invoking the right function based on the name.
protected void traverse(Node node, Direction dir)
node
- The node to call impl_traverse ondir
- The direction to traversepublic final void traverseUp()
public final void traverseDown()
public final void traverseLeft()
public final void traverseRight()
public final void traverseNext()
public final void traversePrevious()
protected void focusChanged()
public void mousePressed(MouseEvent e)
e
- the mouse eventpublic void mouseDragged(MouseEvent e)
e
- the mouse eventpublic void mouseReleased(MouseEvent e)
e
- the mouse eventpublic void mouseEntered(MouseEvent e)
e
- the mouse eventpublic void mouseExited(MouseEvent e)
e
- the mouse eventpublic void contextMenuRequested(ContextMenuEvent e)
e
- the context menu event