Class BehaviorBase<C extends Control>

java.lang.Object
com.sun.javafx.scene.control.behavior.BehaviorBase<C>
Direct Known Subclasses:
ButtonBehavior, ScrollPaneBehavior, TabPaneBehavior, TextInputControlBehavior, TitledPaneBehavior

public class BehaviorBase<C extends Control> extends Object
A convenient base class from which all our built-in behaviors extend. The main functionality in BehaviorBase revolves around infrastructure for resolving key events into function calls. The differences between platforms can be subtle, and we attempt to build sufficient infrastructure into BehaviorBase to minimize the amount of code and the complexity of code necessary to support multiple platforms sufficiently well.

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:

  • TraverseUp
  • TraverseDown
  • TraverseLeft
  • TraverseRight
  • TraverseNext
  • TraversePrevious

Note that by convention, action names are camel case with the first letter uppercase, matching class naming conventions.

  • Field Details

    • IS_TOUCH_SUPPORTED

      protected static final boolean IS_TOUCH_SUPPORTED
      A static final reference to whether the platform we are on supports touch.
      See Also:
    • TRAVERSAL_BINDINGS

      protected static final List<KeyBinding> TRAVERSAL_BINDINGS
      The default key bindings for focus traversal. For many behavior implementations, you may be able to use this directly. The built in names for these traversal actions are:
      • TraverseUp
      • TraverseDown
      • TraverseLeft
      • TraverseRight
      • TraverseNext
      • TraversePrevious
  • Constructor Details

    • BehaviorBase

      public BehaviorBase(C control, List<KeyBinding> keyBindings)
      Create a new BehaviorBase for the given control. The Control must not be null.
      Parameters:
      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.
  • Method Details

    • dispose

      public void dispose()
      Called by a Skin when the Skin is disposed. This method allows a Behavior to implement any logic necessary to clean up itself after the Behavior is no longer needed. Calling dispose twice has no effect. This method is intended to be overridden by subclasses, although all subclasses must call super.dispose() or a potential memory leak will result.
    • getControl

      public final C getControl()
      Gets the control associated with this behavior. Even after the BehaviorBase is disposed, this reference will be non-null.
      Returns:
      The control for this Behavior.
    • callActionForEvent

      protected void callActionForEvent(KeyEvent e)
      Invokes the appropriate action for this key event. This is the main entry point where key events are passed when they occur. This method is responsible for invoking matchActionForEvent, callAction, and consuming the event if it was handled by this control.
      Parameters:
      e - The key event. Must not be null.
    • matchActionForEvent

      protected String matchActionForEvent(KeyEvent e)
      Given a key event, this method will find the matching action name, or null if there is not one.
      Parameters:
      e - The key event. Must not be null.
      Returns:
      The name of the action to invoke, or null if there is not one.
    • callAction

      protected void callAction(String name)
      Called to invoke the action associated with the given 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.

    • focusChanged

      protected void focusChanged()
      Called whenever the focus on the control has changed. This method is intended to be overridden by subclasses that are interested in focus change events.
    • mousePressed

      public void mousePressed(MouseEvent e)
      Invoked by a Skin when the body of the control has been pressed by the mouse. Subclasses should be sure to call super unless they intend to disable any built-in support.
      Parameters:
      e - the mouse event
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Invoked by a Skin when the body of the control has been dragged by the mouse. Subclasses should be sure to call super unless they intend to disable any built-in support (for example, for tooltips).
      Parameters:
      e - the mouse event
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Invoked by a Skin when the body of the control has been released by the mouse. Subclasses should be sure to call super unless they intend to disable any built-in support (for example, for tooltips).
      Parameters:
      e - the mouse event
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Invoked by a Skin when the body of the control has been entered by the mouse. Subclasses should be sure to call super unless they intend to disable any built-in support.
      Parameters:
      e - the mouse event
    • mouseExited

      public void mouseExited(MouseEvent e)
      Invoked by a Skin when the body of the control has been exited by the mouse. Subclasses should be sure to call super unless they intend to disable any built-in support.
      Parameters:
      e - the mouse event