changeset 5184:5475dfc3d98a

RT-30206 : [Button] default and cancel accelerator removing is implemented incorrectly in behavior set to false, reviewed by Leif
author mickf
date Tue, 01 Oct 2013 13:13:03 +0100
parents 2c2b8f13d1cb
children 5a67a3c94fee
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ButtonSkin.java
diffstat 1 files changed, 29 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ButtonSkin.java	Mon Sep 30 13:56:25 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ButtonSkin.java	Tue Oct 01 13:13:03 2013 +0100
@@ -121,19 +121,24 @@
             KeyCode acceleratorCode = KeyCode.ENTER;
             defaultAcceleratorKeyCodeCombination = new KeyCodeCombination(acceleratorCode);
 
+            Runnable oldDefault = scene.getAccelerators().get(defaultAcceleratorKeyCodeCombination);
             if (!value) {
-                /*
-                ** first check of there's a default button already
-                */
-                Runnable oldDefault = scene.getAccelerators().get(defaultAcceleratorKeyCodeCombination);
-                if (!defaultButtonRunnable.equals(oldDefault)) {
-                    /*
-                    ** is it us?
-                    */
+                /**
+                 * first check of there's a default button already
+                 */
+                if (defaultButtonRunnable.equals(oldDefault)) {
+                    /**
+                     * is it us?
+                     */
                     scene.getAccelerators().remove(defaultAcceleratorKeyCodeCombination);
                 }
             }
-            scene.getAccelerators().put(defaultAcceleratorKeyCodeCombination, defaultButtonRunnable);
+            else {
+                if (!defaultButtonRunnable.equals(oldDefault)) {
+                    scene.getAccelerators().remove(defaultAcceleratorKeyCodeCombination);
+                    scene.getAccelerators().put(defaultAcceleratorKeyCodeCombination, defaultButtonRunnable);
+                }
+            }
         }
     }
 
@@ -145,19 +150,24 @@
             KeyCode acceleratorCode = KeyCode.ESCAPE;
             cancelAcceleratorKeyCodeCombination = new KeyCodeCombination(acceleratorCode);
         
+            Runnable oldCancel = scene.getAccelerators().get(cancelAcceleratorKeyCodeCombination);
             if (!value) {
-                /*
-                ** first check of there's a cancel button already
-                */
-                Runnable oldCancel = scene.getAccelerators().get(cancelAcceleratorKeyCodeCombination);
-                if (!cancelButtonRunnable.equals(oldCancel)) {
-                    /*
-                    ** is it us?
-                    */
+                /**
+                 * first check of there's a cancel button already
+                 */
+                if (cancelButtonRunnable.equals(oldCancel)) {
+                    /**
+                     * is it us?
+                     */
                     scene.getAccelerators().remove(cancelAcceleratorKeyCodeCombination);
                 }
-            }        
-            scene.getAccelerators().put(cancelAcceleratorKeyCodeCombination, cancelButtonRunnable);
+            }
+            else {
+                if (!cancelButtonRunnable.equals(oldCancel)) {
+                    scene.getAccelerators().remove(cancelAcceleratorKeyCodeCombination);
+                    scene.getAccelerators().put(cancelAcceleratorKeyCodeCombination, cancelButtonRunnable);
+                }
+            }
         }
     }
 }