--- old/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/CellBehaviorBase.java 2015-09-03 14:47:03.325571400 -0700 +++ new/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/CellBehaviorBase.java 2015-09-03 14:47:02.642532300 -0700 @@ -31,7 +31,7 @@ import javafx.scene.control.IndexedCell; import javafx.scene.control.MultipleSelectionModel; import javafx.scene.control.SelectionMode; -import javafx.scene.input.ContextMenuEvent; +import com.sun.javafx.scene.control.inputmap.InputMap; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; @@ -101,6 +101,8 @@ * * **************************************************************************/ + private final InputMap cellInputMap; + // To support touch devices, we have to slightly modify this behavior, such // that selection only happens on mouse release, if only minimal dragging // has occurred. @@ -114,8 +116,21 @@ * * **************************************************************************/ - public CellBehaviorBase(T control, List bindings) { - super(control, bindings); + public CellBehaviorBase(T control) { + super(control); + + // create a map for cell-specific mappings (this reuses the default + // InputMap installed on the control, if it is non-null, allowing us to pick up any user-specified mappings) + cellInputMap = createInputMap(); + + // TODO add focus traversal mappings (?) + // addDefaultMapping(cellInputMap, FocusTraversalInputMap.getFocusTraversalMappings()); + + addDefaultMapping( + new InputMap.MouseMapping(MouseEvent.MOUSE_PRESSED, this::mousePressed), + new InputMap.MouseMapping(MouseEvent.MOUSE_RELEASED, this::mouseReleased), + new InputMap.MouseMapping(MouseEvent.MOUSE_DRAGGED, this::mouseDragged) + ); } @@ -131,17 +146,23 @@ } + /*************************************************************************** * * * Public API * * * **************************************************************************/ + /** {@inheritDoc} */ + @Override public InputMap getInputMap() { + return cellInputMap; + } + protected int getIndex() { - return getControl() instanceof IndexedCell ? ((IndexedCell)getControl()).getIndex() : -1; + return getNode() instanceof IndexedCell ? ((IndexedCell)getNode()).getIndex() : -1; } - @Override public void mousePressed(MouseEvent e) { + public void mousePressed(MouseEvent e) { if (e.isSynthesized()) { latePress = true; } else { @@ -153,7 +174,7 @@ } } - @Override public void mouseReleased(MouseEvent e) { + public void mouseReleased(MouseEvent e) { if (latePress) { latePress = false; doSelect(e.getX(), e.getY(), e.getButton(), e.getClickCount(), @@ -161,7 +182,7 @@ } } - @Override public void mouseDragged(MouseEvent e) { + public void mouseDragged(MouseEvent e) { latePress = false; } @@ -176,7 +197,7 @@ protected void doSelect(final double x, final double y, final MouseButton button, final int clickCount, final boolean shiftDown, final boolean shortcutDown) { // we update the cell to point to the new tree node - final T cell = getControl(); + final T cell = getNode(); final Control cellContainer = getCellContainer(); @@ -263,12 +284,12 @@ // handle editing, which only occurs with the primary mouse button if (button == MouseButton.PRIMARY) { if (clickCount == 1 && isAlreadySelected) { - edit(getControl()); + edit(getNode()); } else if (clickCount == 1) { // cancel editing edit(null); - } else if (clickCount == 2 && getControl().isEditable()) { - edit(getControl()); + } else if (clickCount == 2 && getNode().isEditable()) { + edit(getNode()); } } } @@ -311,6 +332,6 @@ } protected boolean isSelected() { - return getControl().isSelected(); + return getNode().isSelected(); } }