--- old/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/PaginationBehavior.java 2015-09-03 14:48:25.215255200 -0700 +++ new/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/PaginationBehavior.java 2015-09-03 14:48:24.628221600 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,74 +25,52 @@ package com.sun.javafx.scene.control.behavior; -import javafx.geometry.NodeOrientation; import javafx.scene.control.Pagination; -import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyEvent; +import com.sun.javafx.scene.control.inputmap.InputMap; import javafx.scene.input.MouseEvent; -import java.util.ArrayList; -import java.util.List; -import com.sun.javafx.scene.control.skin.PaginationSkin; + +import static javafx.scene.input.KeyCode.*; +import static com.sun.javafx.scene.control.inputmap.InputMap.KeyMapping; +import static com.sun.javafx.scene.control.inputmap.InputMap.MouseMapping; public class PaginationBehavior extends BehaviorBase { - /************************************************************************** - * Setup KeyBindings * - *************************************************************************/ - private static final String LEFT = "Left"; - private static final String RIGHT = "Right"; - - protected static final List PAGINATION_BINDINGS = new ArrayList(); - static { - PAGINATION_BINDINGS.add(new KeyBinding(KeyCode.LEFT, LEFT)); - PAGINATION_BINDINGS.add(new KeyBinding(KeyCode.RIGHT, RIGHT)); - } - - protected String matchActionForEvent(KeyEvent e) { - String action = super.matchActionForEvent(e); - if (action != null) { - if (e.getCode() == KeyCode.LEFT) { - if (getControl().getEffectiveNodeOrientation() == NodeOrientation.RIGHT_TO_LEFT) { - action = RIGHT; - } - } else if (e.getCode() == KeyCode.RIGHT) { - if (getControl().getEffectiveNodeOrientation() == NodeOrientation.RIGHT_TO_LEFT) { - action = LEFT; - } - } - } - return action; - } - - @Override protected void callAction(String name) { - if (LEFT.equals(name)) { - PaginationSkin ps = (PaginationSkin)getControl().getSkin(); - ps.selectPrevious(); - } else if (RIGHT.equals(name)) { - PaginationSkin ps = (PaginationSkin)getControl().getSkin(); - ps.selectNext(); - } else { - super.callAction(name); - } - } - - /*************************************************************************** - * * - * Mouse event handling * - * * - **************************************************************************/ - - @Override public void mousePressed(MouseEvent e) { - super.mousePressed(e); - Pagination p = getControl(); - p.requestFocus(); - } - - /************************************************************************** - * State and Functions * - *************************************************************************/ + private final InputMap paginationInputMap; public PaginationBehavior(Pagination pagination) { - super(pagination, PAGINATION_BINDINGS); + super(pagination); + + // create a map for paginiation-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) + paginationInputMap = createInputMap(); + + // then button-specific mappings for key and mouse input + addDefaultMapping(paginationInputMap, + new KeyMapping(LEFT, e -> rtl(pagination, this::right, this::left)), + new KeyMapping(RIGHT, e -> rtl(pagination, this::left, this::right)), + new MouseMapping(MouseEvent.MOUSE_PRESSED, this::mousePressed) + ); + } + + @Override public InputMap getInputMap() { + return paginationInputMap; + } + + public void mousePressed(MouseEvent e) { + getNode().requestFocus(); + } + + private void left() { + movePage(-1); + } + + private void right() { + movePage(1); + } + + private void movePage(int delta) { + final Pagination pagination = getNode(); + final int currentPageIndex = pagination.getCurrentPageIndex(); + pagination.setCurrentPageIndex(currentPageIndex + delta); } }