/* * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.javafx.scene.control.behavior; import javafx.application.ConditionalFeature; import javafx.application.Platform; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.control.Control; import javafx.scene.input.ContextMenuEvent; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; import java.util.ArrayList; import java.util.Collections; import java.util.List; import com.sun.javafx.scene.traversal.Direction; import static javafx.scene.input.KeyCode.DOWN; import static javafx.scene.input.KeyCode.LEFT; import static javafx.scene.input.KeyCode.RIGHT; import static javafx.scene.input.KeyCode.TAB; import static javafx.scene.input.KeyCode.UP; /** * 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:
*Note that by convention, action names are camel case with the first letter * uppercase, matching class naming conventions.
*/ public class BehaviorBaseWhen 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 callAction(String name) { switch (name) { case TRAVERSE_UP: traverseUp(); break; case TRAVERSE_DOWN: traverseDown(); break; case TRAVERSE_LEFT: traverseLeft(); break; case TRAVERSE_RIGHT: traverseRight(); break; case TRAVERSE_NEXT: traverseNext(); break; case TRAVERSE_PREVIOUS: traversePrevious(); break; } } /*************************************************************************** * Focus Traversal methods * **************************************************************************/ /** * 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 * call impl_traverse on the given node, passing the given direction. A * subclass may override this method. * * @param node The node to call impl_traverse on * @param dir The direction to traverse */ protected void traverse(final Node node, final Direction dir) { node.impl_traverse(dir); } /** * Calls the focus traversal engine and indicates that traversal should * go the next focusTraversable Node above the current one. */ public final void traverseUp() { traverse(control, com.sun.javafx.scene.traversal.Direction.UP); } /** * Calls the focus traversal engine and indicates that traversal should * go the next focusTraversable Node below the current one. */ public final void traverseDown() { traverse(control, com.sun.javafx.scene.traversal.Direction.DOWN); } /** * Calls the focus traversal engine and indicates that traversal should * go the next focusTraversable Node left of the current one. */ public final void traverseLeft() { traverse(control, com.sun.javafx.scene.traversal.Direction.LEFT); } /** * Calls the focus traversal engine and indicates that traversal should * go the next focusTraversable Node right of the current one. */ public final void traverseRight() { traverse(control, com.sun.javafx.scene.traversal.Direction.RIGHT); } /** * Calls the focus traversal engine and indicates that traversal should * go the next focusTraversable Node in the focus traversal cycle. */ public final void traverseNext() { traverse(control, com.sun.javafx.scene.traversal.Direction.NEXT); } /** * Calls the focus traversal engine and indicates that traversal should * go the previous focusTraversable Node in the focus traversal cycle. */ public final void traversePrevious() { traverse(control, com.sun.javafx.scene.traversal.Direction.PREVIOUS); } /*************************************************************************** * Event handler methods. * * * * I'm not sure why only mouse events are here. What about drag and * * drop events for instance? What about touch events? What about the * * other mouse events? It does seem like these need to be here, because * * for example mouse interaction logic might differ from platform to * * platform, and the Behavior is supposed to implement all the user * * interaction logic (not just key handling). So it seems like * * BehaviorBase should have methods for handling all forms of input events,* * and not just these four mouse events. * **************************************************************************/ /** * 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. */ protected void focusChanged() { } /** * 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. * * @param e the mouse event */ public void mousePressed(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). * * @param e the mouse event */ public void mouseDragged(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). * * @param e the mouse event */ public void mouseReleased(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. * * @param e the mouse event */ public void mouseEntered(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. * * @param e the mouse event */ public void mouseExited(MouseEvent e) { } /** * Invoked by a Skin when the control has had its context menu requested, * most commonly by right-clicking on the control. Subclasses should be sure * to call super unless they intend to disable any built-in support. * * @param e the context menu event */ public void contextMenuRequested(ContextMenuEvent e) { } }