Top Description Fields Constructors Methods
com.sun.jfx.incubator.scene.control.input

public abstract Class BehaviorBase<C extends Control>

extends Object
Class Inheritance
Type Parameters
<C>
the type of the control
Imports
java.util.function.BooleanSupplier, javafx.event.Event, .EventHandler, .EventType, javafx.scene.TraversalDirection, javafx.scene.control.Control, javafx.scene.input.KeyCode, com.sun.javafx.PlatformUtil, com.sun.jfx.incubator.scene.control.input.SkinInputMap.Stateful, jfx.incubator.scene.control.input.FunctionTag, .KeyBinding

This class provides convenient foundation for custom Control developers intended to simplify writing stateful behaviors.

A concrete behavior implementation should do the following:

  1. provide default behavior methods (one for each function tag)
  2. implement populateSkinInputMap() method, in which map control's function tags to the behavior methods, map key bindings to the function tags, add additional event handlers, using registerFunction(FunctionTag, Runnable), registerKey(KeyBinding, FunctionTag), registerKey(KeyCode, FunctionTag), and addHandler() methods correspondingly.
  3. in the corresponding skin's {code Skin.install()}, set the skin input map to the control's input map.
Example (in the actual skin class):
@Override
    public void install() {
        super.install();
        setSkinInputMap(behavior.getSkinInputMap());
  }

Field Summary

Modifier and TypeField and Description
private final C
private SkinInputMap.Stateful

Constructor Summary

AccessConstructor and Description
public
BehaviorBase(C
the owner Control instance
c
)

The constructor.

Method Summary

Modifier and TypeMethod and Description
protected final <
the actual event type
T extends Event
>
void
addHandler(EventType<T>
the event type
type
,
EventHandler<T>
the event handler
handler
)

Adds an event handler for the specified event type, in the context of this Behavior.

protected final <
the actual event type
T extends Event
>
void
addHandler(EventCriteria<T>
the matching criteria
criteria
,
EventHandler<T>
the event handler
handler
)

Adds an event handler for the specific event criteria, in the context of this Behavior.

protected final void
duplicateMapping(KeyBinding
the existing key binding
existing
,
KeyBinding
the new key binding
newk
)

This convenience method registers a copy of the behavior-specific mappings from one key binding to another.

protected final C

Returns:

the owner
getControl
()

Returns the associated Control instance.

public final SkinInputMap.Stateful

Returns:

the input map
getSkinInputMap
()

Returns the skin input map associated with this behavior.

protected final boolean

Returns:

true on a Linux platform
isLinux
()

Returns true if this method is invoked on a Linux platform.

protected final boolean

Returns:

true on a Mac OS platform
isMac
()

Returns true if this method is invoked on a Mac OS platform.

protected final boolean

Returns:

true on a Windows platform
isWindows
()

Returns true if this method is invoked on a Windows platform.

protected abstract void
populateSkinInputMap()

In this method, which is called by javafx.scene.control.Skin#install(), the child class populates the SkinInputMap by registering key mappings and event handlers.

protected final void
register(FunctionTag
the function tag
tag
,
KeyBinding
the key binding
k
,
Runnable
the function
func
)

This convenience method maps the function tag to the specified function, and at the same time maps the specified key binding to that function tag.

protected final void
register(FunctionTag
the function tag
tag
,
KeyBinding
the key binding
k
,
BooleanSupplier
the function
func
)

This convenience method maps the function tag to the specified function, and at the same time maps the specified key binding to that function tag.

protected final void
register(FunctionTag
the function tag
tag
,
KeyCode
the key code
code
,
Runnable
the function
func
)

This convenience method maps the function tag to the specified function, and at the same time maps the specified key binding to that function tag.

protected final void
registerFunction(FunctionTag
the function tag
tag
,
Runnable
the function
function
)

Maps a function to the specified function tag.

protected final void
registerFunction(FunctionTag
the function tag
tag
,
BooleanSupplier
the function
function
)

Maps a function to the specified function tag.

protected final void
registerKey(KeyBinding
the key binding
k
,
FunctionTag
the function tag
tag
)

Maps a key binding to the specified function tag.

protected final void
registerKey(KeyCode
the key code to construct a KeyBinding
code
,
FunctionTag
the function tag
tag
)

Maps a key binding to the specified function tag.

private void
traverse(TraversalDirection
The direction to traverse
dir
)

Called by any of the BehaviorBase traverse methods to actually effect a traversal of the focus.

public final void
traverseDown()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node below the current one.

public final void
traverseLeft()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node left of the current one.

public final void
traverseNext()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node in the focus traversal cycle.

public final void
traversePrevious()

Calls the focus traversal engine and indicates that traversal should go the previous focusTraversable Node in the focus traversal cycle.

public final void
traverseRight()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node right of the current one.

public final void
traverseUp()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node above the current one.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

controlback to summary
private final C control
skinInputMapback to summary
private SkinInputMap.Stateful skinInputMap

Constructor Detail

BehaviorBaseback to summary
public BehaviorBase(C c)

The constructor.

Parameters
c:C

the owner Control instance

Method Detail

addHandlerback to summary
protected final <T extends Event> void addHandler(EventType<T> type, EventHandler<T> handler)

Adds an event handler for the specified event type, in the context of this Behavior.

Parameters
<T>
the actual event type
type:EventType<T>

the event type

handler:EventHandler<T>

the event handler

addHandlerback to summary
protected final <T extends Event> void addHandler(EventCriteria<T> criteria, EventHandler<T> handler)

Adds an event handler for the specific event criteria, in the context of this Behavior. This is a more specific version of addHandler(EventType, EventHandler) method.

Parameters
<T>
the actual event type
criteria:EventCriteria<T>

the matching criteria

handler:EventHandler<T>

the event handler

duplicateMappingback to summary
protected final void duplicateMapping(KeyBinding existing, KeyBinding newk)

This convenience method registers a copy of the behavior-specific mappings from one key binding to another. The method does nothing if no behavior specific mapping can be found.

Parameters
existing:KeyBinding

the existing key binding

newk:KeyBinding

the new key binding

getControlback to summary
protected final C getControl()

Returns the associated Control instance.

Returns:C

the owner

getSkinInputMapback to summary
public final SkinInputMap.Stateful getSkinInputMap()

Returns the skin input map associated with this behavior.

Returns:SkinInputMap.Stateful

the input map

isLinuxback to summary
protected final boolean isLinux()

Returns true if this method is invoked on a Linux platform.

Returns:boolean

true on a Linux platform

isMacback to summary
protected final boolean isMac()

Returns true if this method is invoked on a Mac OS platform.

Returns:boolean

true on a Mac OS platform

isWindowsback to summary
protected final boolean isWindows()

Returns true if this method is invoked on a Windows platform.

Returns:boolean

true on a Windows platform

populateSkinInputMapback to summary
protected abstract void populateSkinInputMap()

In this method, which is called by javafx.scene.control.Skin#install(), the child class populates the SkinInputMap by registering key mappings and event handlers.

If a subclass overrides this method, it is important to call the superclass implementation.

registerback to summary
protected final void register(FunctionTag tag, KeyBinding k, Runnable func)

This convenience method maps the function tag to the specified function, and at the same time maps the specified key binding to that function tag.

Parameters
tag:FunctionTag

the function tag

k:KeyBinding

the key binding

func:Runnable

the function

registerback to summary
protected final void register(FunctionTag tag, KeyBinding k, BooleanSupplier func)

This convenience method maps the function tag to the specified function, and at the same time maps the specified key binding to that function tag.

The event which triggered execution of the function will be consumed if the function returns true.

Parameters
tag:FunctionTag

the function tag

k:KeyBinding

the key binding

func:BooleanSupplier

the function

registerback to summary
protected final void register(FunctionTag tag, KeyCode code, Runnable func)

This convenience method maps the function tag to the specified function, and at the same time maps the specified key binding to that function tag.

Parameters
tag:FunctionTag

the function tag

code:KeyCode

the key code

func:Runnable

the function

registerFunctionback to summary
protected final void registerFunction(FunctionTag tag, Runnable function)

Maps a function to the specified function tag.

Parameters
tag:FunctionTag

the function tag

function:Runnable

the function

registerFunctionback to summary
protected final void registerFunction(FunctionTag tag, BooleanSupplier function)

Maps a function to the specified function tag.

The event which triggered execution of the function will be consumed if the function returns true.

Parameters
tag:FunctionTag

the function tag

function:BooleanSupplier

the function

registerKeyback to summary
protected final void registerKey(KeyBinding k, FunctionTag tag)

Maps a key binding to the specified function tag. A null key binding will result in no change to this input map. This method will not override a user mapping.

Parameters
k:KeyBinding

the key binding

tag:FunctionTag

the function tag

registerKeyback to summary
protected final void registerKey(KeyCode code, FunctionTag tag)

Maps a key binding to the specified function tag. This method will not override a user mapping added by registerKey(KeyBinding, FunctionTag).

Parameters
code:KeyCode

the key code to construct a KeyBinding

tag:FunctionTag

the function tag

traverseback to summary
private void traverse(TraversalDirection dir)

Called by any of the BehaviorBase traverse methods to actually effect a traversal of the focus. The default behavior of this method is to simply traverse on the given node, passing the given direction. A subclass may override this method.

Parameters
dir:TraversalDirection

The direction to traverse

traverseDownback to summary
public final void traverseDown()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node below the current one.

traverseLeftback to summary
public final void traverseLeft()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node left of the current one.

traverseNextback to summary
public final void traverseNext()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node in the focus traversal cycle.

traversePreviousback to summary
public final void traversePrevious()

Calls the focus traversal engine and indicates that traversal should go the previous focusTraversable Node in the focus traversal cycle.

traverseRightback to summary
public final void traverseRight()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node right of the current one.

traverseUpback to summary
public final void traverseUp()

Calls the focus traversal engine and indicates that traversal should go the next focusTraversable Node above the current one.