changeset 7265:28bccddb2475

RT-37523 BooleanProperty.booleanProperty(ObjectProperty<Boolean>) changes value of source property
author Martin Sladecek <martin.sladecek@oracle.com>
date Fri, 13 Jun 2014 12:00:55 +0200
parents 9f5303fb78fb
children 0be1e326561e
files modules/base/src/main/java/com/sun/javafx/binding/BidirectionalBinding.java modules/base/src/main/java/javafx/beans/property/BooleanProperty.java modules/base/src/main/java/javafx/beans/property/DoubleProperty.java modules/base/src/main/java/javafx/beans/property/FloatProperty.java modules/base/src/main/java/javafx/beans/property/IntegerProperty.java modules/base/src/main/java/javafx/beans/property/LongProperty.java modules/base/src/test/java/javafx/beans/property/BooleanPropertyTest.java modules/base/src/test/java/javafx/beans/property/DoublePropertyTest.java modules/base/src/test/java/javafx/beans/property/FloatPropertyTest.java modules/base/src/test/java/javafx/beans/property/IntegerPropertyTest.java modules/base/src/test/java/javafx/beans/property/LongPropertyTest.java
diffstat 11 files changed, 42 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/modules/base/src/main/java/com/sun/javafx/binding/BidirectionalBinding.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/main/java/com/sun/javafx/binding/BidirectionalBinding.java	Fri Jun 13 12:00:55 2014 +0200
@@ -125,6 +125,33 @@
         return bindNumber(property1, (Property<Number>)property2);
     }
 
+    public static BidirectionalBinding bindNumber(IntegerProperty property1, Property<Integer> property2) {
+        return bindNumberObject(property1, property2);
+    }
+
+    public static BidirectionalBinding bindNumber(LongProperty property1, Property<Long> property2) {
+        return bindNumberObject(property1, property2);
+    }
+
+    public static BidirectionalBinding bindNumber(FloatProperty property1, Property<Float> property2) {
+        return bindNumberObject(property1, property2);
+    }
+
+    public static BidirectionalBinding bindNumber(DoubleProperty property1, Property<Double> property2) {
+        return bindNumberObject(property1, property2);
+    }
+
+    private static <T extends Number> BidirectionalBinding bindNumberObject(Property<Number> property1, Property<T> property2) {
+        checkParameters(property1, property2);
+
+        final BidirectionalBinding<Number> binding = new TypedNumberBidirectionalBinding<T>(property2, property1);
+
+        property1.setValue(property2.getValue());
+        property1.addListener(binding);
+        property2.addListener(binding);
+        return binding;
+    }
+
     private static <T extends Number> BidirectionalBinding bindNumber(Property<T> property1, Property<Number> property2) {
         checkParameters(property1, property2);
         
--- a/modules/base/src/main/java/javafx/beans/property/BooleanProperty.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/main/java/javafx/beans/property/BooleanProperty.java	Fri Jun 13 12:00:55 2014 +0200
@@ -138,7 +138,7 @@
         }
         return property instanceof BooleanProperty ? (BooleanProperty)property : new BooleanPropertyBase() {
             {
-                BidirectionalBinding.bind(property, this);
+                BidirectionalBinding.bind(this, property);
             }
 
             @Override
--- a/modules/base/src/main/java/javafx/beans/property/DoubleProperty.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/main/java/javafx/beans/property/DoubleProperty.java	Fri Jun 13 12:00:55 2014 +0200
@@ -153,7 +153,7 @@
         }
         return new DoublePropertyBase() {
             {
-                BidirectionalBinding.bindNumber(property, this);
+                BidirectionalBinding.bindNumber(this, property);
             }
 
             @Override
--- a/modules/base/src/main/java/javafx/beans/property/FloatProperty.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/main/java/javafx/beans/property/FloatProperty.java	Fri Jun 13 12:00:55 2014 +0200
@@ -148,7 +148,7 @@
         }
         return new FloatPropertyBase() {
             {
-                BidirectionalBinding.bindNumber(property, this);
+                BidirectionalBinding.bindNumber(this, property);
             }
 
             @Override
--- a/modules/base/src/main/java/javafx/beans/property/IntegerProperty.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/main/java/javafx/beans/property/IntegerProperty.java	Fri Jun 13 12:00:55 2014 +0200
@@ -148,7 +148,7 @@
         }
         return new IntegerPropertyBase() {
             {
-                BidirectionalBinding.bindNumber(property, this);
+                BidirectionalBinding.bindNumber(this, property);
             }
 
             @Override
--- a/modules/base/src/main/java/javafx/beans/property/LongProperty.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/main/java/javafx/beans/property/LongProperty.java	Fri Jun 13 12:00:55 2014 +0200
@@ -146,7 +146,7 @@
         }
         return new LongPropertyBase() {
             {
-                BidirectionalBinding.bindNumber(property, this);
+                BidirectionalBinding.bindNumber(this, property);
             }
 
             @Override
--- a/modules/base/src/test/java/javafx/beans/property/BooleanPropertyTest.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/test/java/javafx/beans/property/BooleanPropertyTest.java	Fri Jun 13 12:00:55 2014 +0200
@@ -148,10 +148,10 @@
     
     @Test
     public void testObjectToBoolean() {
-        final ObjectProperty<Boolean> valueModel = new SimpleObjectProperty<Boolean>();
+        final ObjectProperty<Boolean> valueModel = new SimpleObjectProperty<Boolean>(true);
         final BooleanProperty exp = BooleanProperty.booleanProperty(valueModel);
 
-        assertEquals(false, exp.get());
+        assertEquals(true, exp.get());
         valueModel.set(true);
         assertEquals(true, exp.get());
         valueModel.set(false);
--- a/modules/base/src/test/java/javafx/beans/property/DoublePropertyTest.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/test/java/javafx/beans/property/DoublePropertyTest.java	Fri Jun 13 12:00:55 2014 +0200
@@ -133,10 +133,10 @@
     
     @Test
     public void testAsObject() {
-        final DoubleProperty valueModel = new SimpleDoubleProperty();
+        final DoubleProperty valueModel = new SimpleDoubleProperty(2d);
         final ObjectProperty<Double> exp = valueModel.asObject();
 
-        assertEquals(0.0, exp.getValue(), EPSILON);
+        assertEquals(2d, exp.getValue(), EPSILON);
         valueModel.set(-4354.3);
         assertEquals(-4354.3, exp.getValue(), EPSILON);
         valueModel.set(5e11);
--- a/modules/base/src/test/java/javafx/beans/property/FloatPropertyTest.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/test/java/javafx/beans/property/FloatPropertyTest.java	Fri Jun 13 12:00:55 2014 +0200
@@ -149,10 +149,10 @@
     
     @Test
     public void testObjectToFloat() {
-        final ObjectProperty<Float> valueModel = new SimpleObjectProperty<Float>();
+        final ObjectProperty<Float> valueModel = new SimpleObjectProperty<Float>(2f);
         final FloatProperty exp = FloatProperty.floatProperty(valueModel);
 
-        assertEquals(0.0f, exp.floatValue(), EPSILON);
+        assertEquals(2f, exp.floatValue(), EPSILON);
         valueModel.set(-4354.3f);
         assertEquals(-4354.3f, exp.floatValue(), EPSILON);
         valueModel.set(5e11f);
--- a/modules/base/src/test/java/javafx/beans/property/IntegerPropertyTest.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/test/java/javafx/beans/property/IntegerPropertyTest.java	Fri Jun 13 12:00:55 2014 +0200
@@ -148,10 +148,10 @@
     
     @Test
     public void testObjectToInteger() {
-        final ObjectProperty<Integer> valueModel = new SimpleObjectProperty<Integer>();
+        final ObjectProperty<Integer> valueModel = new SimpleObjectProperty<Integer>(2);
         final IntegerProperty exp = IntegerProperty.integerProperty(valueModel);
         
-        assertEquals(0, exp.intValue());
+        assertEquals(2, exp.intValue());
         valueModel.set(-4354);
         assertEquals(-4354, exp.intValue());
         valueModel.set(5);
--- a/modules/base/src/test/java/javafx/beans/property/LongPropertyTest.java	Fri Jun 13 12:36:57 2014 +1200
+++ b/modules/base/src/test/java/javafx/beans/property/LongPropertyTest.java	Fri Jun 13 12:00:55 2014 +0200
@@ -147,10 +147,10 @@
     
     @Test
     public void testObjectToLong() {
-        final ObjectProperty<Long> valueModel = new SimpleObjectProperty<Long>();
+        final ObjectProperty<Long> valueModel = new SimpleObjectProperty<Long>(2L);
         final LongProperty exp = LongProperty.longProperty(valueModel);
 
-        assertEquals(0L, exp.longValue());
+        assertEquals(2L, exp.longValue());
         valueModel.set(-4354L);
         assertEquals(-4354L, exp.longValue());
         valueModel.set(5L);