use of com.canoo.platform.remoting.client.javafx.Converter in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXBooleanUnidirectionalWithConverter.
@Test
public void testJavaFXBooleanUnidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
WritableBooleanValue writableBooleanValue = new SimpleBooleanProperty();
Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s);
stringDolphinProperty.set("Hello");
assertEquals(booleanJavaFXProperty.get(), false);
Binding binding = FXBinder.bind(booleanJavaFXProperty).to(stringDolphinProperty, stringBooleanConverter);
assertEquals(booleanJavaFXProperty.get(), false);
stringDolphinProperty.set("true");
assertEquals(booleanJavaFXProperty.get(), true);
stringDolphinProperty.set(null);
assertEquals(booleanJavaFXProperty.get(), false);
binding.unbind();
stringDolphinProperty.set("true");
assertEquals(booleanJavaFXProperty.get(), false);
stringDolphinProperty.set("false");
binding = FXBinder.bind(writableBooleanValue).to(stringDolphinProperty, stringBooleanConverter);
assertEquals(writableBooleanValue.get(), false);
stringDolphinProperty.set("true");
assertEquals(writableBooleanValue.get(), true);
stringDolphinProperty.set(null);
assertEquals(writableBooleanValue.get(), false);
binding.unbind();
stringDolphinProperty.set("true");
assertEquals(writableBooleanValue.get(), false);
}
use of com.canoo.platform.remoting.client.javafx.Converter in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXDoubleBidirectionalWithConverter.
@Test
public void testJavaFXDoubleBidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
Converter<String, Double> stringDoubleConverter = s -> s == null ? null : Double.parseDouble(s);
Converter<Double, String> doubleStringConverter = d -> d == null ? null : d.toString();
BidirectionalConverter<String, Double> doubleBidirectionalConverter = new DefaultBidirectionalConverter<>(stringDoubleConverter, doubleStringConverter);
stringDolphinProperty.set("47.0");
assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
Binding binding = FXBinder.bind(doubleJavaFXProperty).bidirectionalToNumeric(stringDolphinProperty, doubleBidirectionalConverter);
assertEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 100.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
doubleJavaFXProperty.set(12.0);
assertEquals(stringDolphinProperty.get(), "12.0");
doubleJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), "0.0");
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
}
use of com.canoo.platform.remoting.client.javafx.Converter in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXBooleanBidirectionalWithConverter.
@Test
public void testJavaFXBooleanBidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
Converter<Boolean, String> booleanStringConverter = b -> b == null ? null : b.toString();
Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s);
BidirectionalConverter<Boolean, String> booleanStringBidirectionalConverter = new DefaultBidirectionalConverter<>(booleanStringConverter, stringBooleanConverter);
stringDolphinProperty.set("true");
assertNotEquals(booleanJavaFXProperty.get(), true);
Binding binding = FXBinder.bind(booleanJavaFXProperty).bidirectionalTo(stringDolphinProperty, booleanStringBidirectionalConverter.invert());
assertEquals(booleanJavaFXProperty.get(), true);
stringDolphinProperty.set("false");
assertEquals(booleanJavaFXProperty.get(), false);
stringDolphinProperty.set(null);
assertEquals(booleanJavaFXProperty.get(), false);
booleanJavaFXProperty.set(true);
assertEquals(stringDolphinProperty.get(), "true");
booleanJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), "false");
binding.unbind();
stringDolphinProperty.set("true");
assertEquals(booleanJavaFXProperty.get(), false);
}
use of com.canoo.platform.remoting.client.javafx.Converter in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXStringBidirectionalWithConverter.
@Test
public void testJavaFXStringBidirectionalWithConverter() {
Property<Double> doubleDolphinProperty = new MockedProperty<>();
StringProperty stringJavaFXProperty = new SimpleStringProperty();
Converter<String, Double> doubleStringConverter = s -> s == null ? null : Double.parseDouble(s);
Converter<Double, String> stringDoubleConverter = d -> d == null ? null : d.toString();
BidirectionalConverter<Double, String> doubleStringBidirectionalConverter = new DefaultBidirectionalConverter<>(stringDoubleConverter, doubleStringConverter);
doubleDolphinProperty.set(0.1);
assertNotEquals(stringJavaFXProperty.get(), "0.1");
Binding binding = FXBinder.bind(stringJavaFXProperty).bidirectionalTo(doubleDolphinProperty, doubleStringBidirectionalConverter);
assertEquals(stringJavaFXProperty.get(), "0.1");
doubleDolphinProperty.set(0.2);
assertEquals(stringJavaFXProperty.get(), "0.2");
doubleDolphinProperty.set(null);
assertEquals(stringJavaFXProperty.get(), null);
stringJavaFXProperty.set("0.1");
assertEquals(doubleDolphinProperty.get(), 0.1);
stringJavaFXProperty.setValue("0.2");
assertEquals(doubleDolphinProperty.get(), 0.2);
binding.unbind();
doubleDolphinProperty.set(0.3);
assertEquals(stringJavaFXProperty.get(), "0.2");
}
use of com.canoo.platform.remoting.client.javafx.Converter in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXDoubleUnidirectionalWithConverter.
@Test
public void testJavaFXDoubleUnidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
WritableDoubleValue writableDoubleValue = new SimpleDoubleProperty();
Converter<String, Double> stringDoubleConverter = s -> s == null ? null : Double.parseDouble(s);
stringDolphinProperty.set("47.0");
assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
Binding binding = FXBinder.bind(doubleJavaFXProperty).to(stringDolphinProperty, stringDoubleConverter);
assertEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 100.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
stringDolphinProperty.set("12.0");
binding = FXBinder.bind(doubleJavaFXProperty).to(stringDolphinProperty, stringDoubleConverter);
assertEquals(doubleJavaFXProperty.doubleValue(), 12.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
stringDolphinProperty.set("47.0");
binding = FXBinder.bind(writableDoubleValue).to(stringDolphinProperty, stringDoubleConverter);
assertEquals(writableDoubleValue.get(), 47.0, EPSILON);
stringDolphinProperty.set("100.0");
assertEquals(writableDoubleValue.get(), 100.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(writableDoubleValue.get(), 0.0, EPSILON);
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(writableDoubleValue.get(), 0.0, EPSILON);
}
Aggregations