changeset 6844:8c3083ca5111

RT-36699 [ToggleButton, RadioButton] arrow keys allow selection of disabled Toggle Reviewed by: jgiles
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 22 Apr 2014 08:52:01 +0200
parents 71d5359db7ee
children 669f56bc38e9
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ToggleButtonBehavior.java modules/controls/src/main/java/javafx/scene/control/ToggleButton.java
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ToggleButtonBehavior.java	Tue Apr 22 11:37:08 2014 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ToggleButtonBehavior.java	Tue Apr 22 08:52:01 2014 +0200
@@ -27,6 +27,7 @@
 import com.sun.javafx.scene.control.skin.Utils;
 import javafx.collections.ObservableList;
 import javafx.geometry.NodeOrientation;
+import javafx.scene.Node;
 import javafx.scene.control.Control;
 import javafx.scene.control.Toggle;
 import javafx.scene.control.ToggleButton;
@@ -75,18 +76,24 @@
                 if (Utils.isTwoLevelFocus()) {
                     super.callAction(toggleToTraverseAction(name));
                 } else if (traversingToNext) {
-                    if (currentToggleIdx == toggles.size() - 1) {
+                    int nextToggleIndex = currentToggleIdx;
+                    Toggle toggle = null;
+                    while (++nextToggleIndex < toggles.size() && (toggle = toggles.get(nextToggleIndex)) instanceof Node &&
+                            ((Node)toggle).isDisabled());
+                    if (nextToggleIndex == toggles.size()) {
                         super.callAction(toggleToTraverseAction(name));
                     } else {
-                        Toggle toggle = toggles.get(currentToggleIdx + 1);
                         toggleGroup.selectToggle(toggle);
                         ((Control)toggle).requestFocus();
                     }
                 } else {
-                    if (currentToggleIdx == 0) {
+                    int prevToggleIndex = currentToggleIdx;
+                    Toggle toggle = null;
+                    while (--prevToggleIndex >= 0 && (toggle = toggles.get(prevToggleIndex)) instanceof Node &&
+                            ((Node)toggle).isDisabled());
+                    if (prevToggleIndex < 0) {
                         super.callAction(toggleToTraverseAction(name));
                     } else {
-                        Toggle toggle = toggles.get(currentToggleIdx - 1);
                         toggleGroup.selectToggle(toggle);
                         ((Control)toggle).requestFocus();
                     }
--- a/modules/controls/src/main/java/javafx/scene/control/ToggleButton.java	Tue Apr 22 11:37:08 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/ToggleButton.java	Tue Apr 22 08:52:01 2014 +0200
@@ -154,6 +154,10 @@
                 @Override protected void invalidated() {
                     final boolean selected = get();
                     final ToggleGroup tg = getToggleGroup();
+                    // Note: these changes need to be done before selectToggle/clearSelectedToggle since
+                    // those operations change properties and can execute user code, possibly modifying selected property again
+                    pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, selected);
+                    accSendNotification(Attribute.SELECTED);
                     if (tg != null) {
                         if (selected) {
                             tg.selectToggle(ToggleButton.this);
@@ -161,8 +165,6 @@
                             tg.clearSelectedToggle();
                         }
                     }
-                    pseudoClassStateChanged(PSEUDO_CLASS_SELECTED, selected);
-                    accSendNotification(Attribute.SELECTED);
                 }
 
                 @Override