changeset 7094:92f153791fa4

RT-28412 [ToggleGroup] incorrect behavior of selectToggle method Reviewed by: jgiles
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 21 May 2014 09:33:01 +0200
parents 2973eb756769
children 0e6a232fa8c4
files modules/controls/src/main/java/javafx/scene/control/ToggleGroup.java modules/controls/src/test/java/javafx/scene/control/ToggleGroupTest.java
diffstat 2 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/ToggleGroup.java	Wed May 21 08:40:37 2014 +0200
+++ b/modules/controls/src/main/java/javafx/scene/control/ToggleGroup.java	Wed May 21 09:33:01 2014 +0200
@@ -120,6 +120,9 @@
                 throw new java.lang.RuntimeException("A bound value cannot be set.");
             }
             final Toggle old = get();
+            if (old == newSelectedToggle) {
+                return;
+            }
             if (setSelected(newSelectedToggle, true) ||
                     (newSelectedToggle != null && newSelectedToggle.getToggleGroup() == ToggleGroup.this) ||
                     (newSelectedToggle == null)) {
--- a/modules/controls/src/test/java/javafx/scene/control/ToggleGroupTest.java	Wed May 21 08:40:37 2014 +0200
+++ b/modules/controls/src/test/java/javafx/scene/control/ToggleGroupTest.java	Wed May 21 09:33:01 2014 +0200
@@ -502,4 +502,22 @@
         assertFalse(b2.isSelected());
         assertFalse(b3.isSelected());
     }
+
+    @Test public void testSelectingTwiceIsNop() {
+        b1.setToggleGroup(g1);
+        b2.setToggleGroup(g1);
+
+        assertFalse(b1.isSelected());
+        assertFalse(b2.isSelected());
+
+        g1.selectToggle(b1);
+        assertTrue(b1.isSelected());
+        assertFalse(b2.isSelected());
+        assertEquals(g1.getSelectedToggle(), b1);
+
+        g1.selectToggle(b1);
+        assertTrue(b1.isSelected());
+        assertFalse(b2.isSelected());
+        assertEquals(g1.getSelectedToggle(), b1);
+    }
 }