modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/CellBehaviorBase.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization

*** 29,39 **** import javafx.scene.control.Control; import javafx.scene.control.FocusModel; import javafx.scene.control.IndexedCell; import javafx.scene.control.MultipleSelectionModel; import javafx.scene.control.SelectionMode; ! import javafx.scene.input.ContextMenuEvent; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import java.util.ArrayList; import java.util.List; --- 29,39 ---- import javafx.scene.control.Control; import javafx.scene.control.FocusModel; import javafx.scene.control.IndexedCell; import javafx.scene.control.MultipleSelectionModel; import javafx.scene.control.SelectionMode; ! import com.sun.javafx.scene.control.inputmap.InputMap; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import java.util.ArrayList; import java.util.List;
*** 99,108 **** --- 99,110 ---- * * * Private fields * * * **************************************************************************/ + private final InputMap<T> 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. private boolean latePress = false;
*** 112,123 **** * * * Constructors * * * **************************************************************************/ ! public CellBehaviorBase(T control, List<KeyBinding> bindings) { ! super(control, bindings); } protected abstract Control getCellContainer(); // e.g. ListView protected abstract MultipleSelectionModel<?> getSelectionModel(); --- 114,138 ---- * * * Constructors * * * **************************************************************************/ ! 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) ! ); } protected abstract Control getCellContainer(); // e.g. ListView protected abstract MultipleSelectionModel<?> getSelectionModel();
*** 129,149 **** protected boolean isClickPositionValid(final double x, final double y) { return true; } /*************************************************************************** * * * Public API * * * **************************************************************************/ protected int getIndex() { ! return getControl() instanceof IndexedCell ? ((IndexedCell<?>)getControl()).getIndex() : -1; } ! @Override public void mousePressed(MouseEvent e) { if (e.isSynthesized()) { latePress = true; } else { latePress = isSelected(); if (!latePress) { --- 144,170 ---- protected boolean isClickPositionValid(final double x, final double y) { return true; } + /*************************************************************************** * * * Public API * * * **************************************************************************/ + /** {@inheritDoc} */ + @Override public InputMap<T> getInputMap() { + return cellInputMap; + } + protected int getIndex() { ! return getNode() instanceof IndexedCell ? ((IndexedCell<?>)getNode()).getIndex() : -1; } ! public void mousePressed(MouseEvent e) { if (e.isSynthesized()) { latePress = true; } else { latePress = isSelected(); if (!latePress) {
*** 151,169 **** e.isShiftDown(), e.isShortcutDown()); } } } ! @Override public void mouseReleased(MouseEvent e) { if (latePress) { latePress = false; doSelect(e.getX(), e.getY(), e.getButton(), e.getClickCount(), e.isShiftDown(), e.isShortcutDown()); } } ! @Override public void mouseDragged(MouseEvent e) { latePress = false; } --- 172,190 ---- e.isShiftDown(), e.isShortcutDown()); } } } ! public void mouseReleased(MouseEvent e) { if (latePress) { latePress = false; doSelect(e.getX(), e.getY(), e.getButton(), e.getClickCount(), e.isShiftDown(), e.isShortcutDown()); } } ! public void mouseDragged(MouseEvent e) { latePress = false; }
*** 174,184 **** **************************************************************************/ 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 Control cellContainer = getCellContainer(); // If the mouse event is not contained within this TreeCell, then // we don't want to react to it. --- 195,205 ---- **************************************************************************/ 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 = getNode(); final Control cellContainer = getCellContainer(); // If the mouse event is not contained within this TreeCell, then // we don't want to react to it.
*** 261,276 **** protected void handleClicks(MouseButton button, int clickCount, boolean isAlreadySelected) { // handle editing, which only occurs with the primary mouse button if (button == MouseButton.PRIMARY) { if (clickCount == 1 && isAlreadySelected) { ! edit(getControl()); } else if (clickCount == 1) { // cancel editing edit(null); ! } else if (clickCount == 2 && getControl().isEditable()) { ! edit(getControl()); } } } void selectRows(int focusedIndex, int index) { --- 282,297 ---- protected void handleClicks(MouseButton button, int clickCount, boolean isAlreadySelected) { // handle editing, which only occurs with the primary mouse button if (button == MouseButton.PRIMARY) { if (clickCount == 1 && isAlreadySelected) { ! edit(getNode()); } else if (clickCount == 1) { // cancel editing edit(null); ! } else if (clickCount == 2 && getNode().isEditable()) { ! edit(getNode()); } } } void selectRows(int focusedIndex, int index) {
*** 309,316 **** } } } protected boolean isSelected() { ! return getControl().isSelected(); } } --- 330,337 ---- } } } protected boolean isSelected() { ! return getNode().isSelected(); } }