1 /*
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1075
1076 /* Return the a11y focus to a control in the scene. */
1077 getSkinnable().notifyAccessibleAttributeChanged(AccessibleAttribute.FOCUS_NODE);
1078 }
1079 setFocusedMenuIndex(-1);
1080 }
1081
1082 private void moveToMenu(Direction dir, boolean doShow) {
1083 boolean showNextMenu = doShow && focusedMenu.isShowing();
1084 findSibling(dir, focusedMenuIndex).ifPresent(p -> {
1085 setFocusedMenuIndex(p.getValue());
1086 if (showNextMenu) {
1087 // we explicitly do *not* allow selection - we are moving
1088 // to a sibling menu, and therefore selection should be reset
1089 showMenu(p.getKey(), false);
1090 }
1091 });
1092 }
1093
1094 private Optional<Pair<Menu,Integer>> findSibling(Direction dir, int startIndex) {
1095 final int childCount = container.getChildren().size();
1096 int nextIndex = startIndex;
1097 if (nextIndex == -1) return Optional.empty();
1098 if (dir.isForward() && nextIndex == childCount - 1) {
1099 // loop forwards to start
1100 nextIndex = 0;
1101 } else if (!dir.isForward() && nextIndex == 0) {
1102 // loop backwards to end
1103 nextIndex = childCount - 1;
1104 } else {
1105 nextIndex += dir.isForward() ? 1 : -1;
1106 }
1107 // RT_19359
1108 if (getSkinnable().getMenus().get(nextIndex).isDisable()) return findSibling(dir, nextIndex);
1109 clearMenuButtonHover();
1110 return Optional.of(new Pair<>(getSkinnable().getMenus().get(nextIndex), nextIndex));
1111 }
1112
1113 private void updateFocusedIndex() {
1114 int index = 0;
1115 for(Node n : container.getChildren()) {
1116 if (n.isHover()) {
1117 setFocusedMenuIndex(index);
1118 return;
1119 }
1120 index++;
1121 }
1122 menuModeEnd();
1123 }
1124
1125 private void clearMenuButtonHover() {
1126 for(Node n : container.getChildren()) {
1127 if (n.isHover()) {
1128 ((MenuBarButton)n).clearHover();
|
1 /*
2 * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1075
1076 /* Return the a11y focus to a control in the scene. */
1077 getSkinnable().notifyAccessibleAttributeChanged(AccessibleAttribute.FOCUS_NODE);
1078 }
1079 setFocusedMenuIndex(-1);
1080 }
1081
1082 private void moveToMenu(Direction dir, boolean doShow) {
1083 boolean showNextMenu = doShow && focusedMenu.isShowing();
1084 findSibling(dir, focusedMenuIndex).ifPresent(p -> {
1085 setFocusedMenuIndex(p.getValue());
1086 if (showNextMenu) {
1087 // we explicitly do *not* allow selection - we are moving
1088 // to a sibling menu, and therefore selection should be reset
1089 showMenu(p.getKey(), false);
1090 }
1091 });
1092 }
1093
1094 private Optional<Pair<Menu,Integer>> findSibling(Direction dir, int startIndex) {
1095 if (startIndex == -1) {
1096 return Optional.empty();
1097 }
1098
1099 final int totalMenus = getSkinnable().getMenus().size();
1100 int i = 0;
1101 int nextIndex = 0;
1102
1103 // Traverse all menus in menubar to find nextIndex
1104 while (i < totalMenus) {
1105 i++;
1106
1107 nextIndex = (startIndex + (dir.isForward() ? 1 : -1)) % totalMenus;
1108
1109 if (nextIndex == -1) {
1110 // loop backwards to end
1111 nextIndex = totalMenus - 1;
1112 }
1113
1114 // if menu at nextIndex is disabled, skip it
1115 if (getSkinnable().getMenus().get(nextIndex).isDisable()) {
1116 // Calculate new nextIndex by continuing loop
1117 startIndex = nextIndex;
1118 } else {
1119 // nextIndex is to be highlighted
1120 break;
1121 }
1122 }
1123
1124 clearMenuButtonHover();
1125 return Optional.of(new Pair<>(getSkinnable().getMenus().get(nextIndex), nextIndex));
1126 }
1127
1128 private void updateFocusedIndex() {
1129 int index = 0;
1130 for(Node n : container.getChildren()) {
1131 if (n.isHover()) {
1132 setFocusedMenuIndex(index);
1133 return;
1134 }
1135 index++;
1136 }
1137 menuModeEnd();
1138 }
1139
1140 private void clearMenuButtonHover() {
1141 for(Node n : container.getChildren()) {
1142 if (n.isHover()) {
1143 ((MenuBarButton)n).clearHover();
|