Advanced-Bindings

Advanced-Bindings is a collection of JavaFX custom binding implementations to simplify the creation of application logic based on data bindings.

The first main goal of the project was to create bindings for all methods of java.lang.Math.

To use the library simply add the dependency to your gradle or maven project:

Gradle:

compile 'eu.lestard:advanced-bindings:0.4.0'

Maven:

<dependency>
    <groupId>eu.lestard</groupId>
    <artifactId>advanced-bindings</artifactId>
    <version>0.4.0</version>
</dependency>

If you have ideas or wishes for new custom bindings I would be very pleased to hear them. Feel free to add an issue at the github issue tracker

You can find the source code on github: https://github.com/lestard/advanced-bindings

The JavaDoc can be found here: https://lestard.github.io/advanced-bindings/javadoc/0.4.0/

Related Articles:

  • Reactive Programming and JavaFX - Article in german JavaMagazin

    | tagged as
    Summary:

    I've written an article for the german JavaMagazin 7.15 with the topic "Reactive Programming mit JavaFX" (you can find it here online: jaxenter.de). In the article I'm introducing the reactive programming paradigm from the perspective of a UI developer. Reactive Programming is technique to escape from the so called "callback hell". Instead of reacting to user events with callbacks (i.e. side effects on a global state) you define dependencies between time-varing values that will be updated automatically by the programming environment when changes or events are happening. With its properties and data-binding API, JavaFX already has a good base for reactive programming. One point I wanted to highlight in the article is the fact that you don't necessarily need a functional programming language to do "Reactive Programming". Of course the original work and research in the field of reactive programming was done with functional languages but it's possible with non-functional languages like Java too (of course the syntax is far more inconvenient but thats a fact that apparently every java developer has resigned to ;-)). A relatively simple abstraction over the Observer design pattern is all you need, like it is done in the internal implementation of the JavaFX properties and databindings. To make the programming easier there are also libraries available that can help to write JavaFX application in a reactive programming way. The first library I'm introducing in the article is my own Advanced-Bindings project that can be used for more complex bindings. After that I'm using the really cool ReactFX library for composition of event streams. At the end I'm presenting the library RxJava which is obviously the most famous of the stated libs. In the article I'm showing how you can integrate a RxJava based service in a JavaFX application.
    ...

  • New release of Advanced-Bindings

    | tagged as
    Summary:

    Last week I've released a new minor version of my Advanced-Bindings library. In this post I will describe the new features in more detail.

    Logic Bindings

    In the standard JavaFX Bindings API there are methods to create bindings for the logical OR and AND operations. The drawback of these methods is that they can only be used to combine exactly two observable boolean values. In the new LogicBindings class there are now methods to create OR and AND bindings with a variable number of arguments.
    ObservableBooleanValue a = ...
    ObservableBooleanValue b = ...
    ObservableBooleanValue c = ...
    ObservableBooleanValue d = ...
    
    BooleanBinding and = LogicBindings.and(a,b,c,d);
    
    BooleanBinding or = LogicBindings.or(a,b,c,d);
    
    

    ...

  • Advanced-Bindings for JavaFX

    | tagged as
    Summary:

    I'm a big fan of JavaFX's Properties and Data-Bindings. In my opinion, one of the most interesting part of the data binding capabilities of JavaFX is that you can create a binding that represents a calculation of values. For example you can create a binding that represents the addition of two integer properties:

    import javafx.beans.binding.Bindings; 
    import static eu.lestard.assertj.javafx.api.Assertions.assertThat;
    ...
    
    @Test
    public void test(){
        IntegerProperty a = new SimpleIntegerProperty(12);
        IntegerProperty b = new SimpleIntegerProperty(30);
    
        NumberBinding c = Bindings.add(a, b);
    
    
        assertThat(c).hasValue(42);
    
        a.set(2);
    
        assertThat(c).hasValue(32);
    }
    
    
    There are binding method for basic operations like add, subtract, multiply, divide. But what if you need some more specific operations like exponentiation or sine? To fill this gap I have created a library called "advanced-bindings" that will become a collection of custom bindings that are needed to create application logic with data bindings. The first step was to create binding implementations for all methods of java.lang.Math. This way you can do stuff like this:
    @Test
    public void testPow(){
    
        DoubleProperty a = new SimpleDoubleProperty(3);
        DoubleProperty b = new SimpleDoubleProperty(2);
    
        final DoubleBinding pow = MathBindings.pow(a, b);
    
        // 3^2 = 9
        assertThat(pow).hasValue(9.0);
    
        a.set(5);
        b.set(3);
    
        // 5^3 = 125
        assertThat(pow).hasValue(125.0);
    }
    
    In the future I will add more useful helpers and custom bindings. If you have ideas feel free to add an issue at github. I have uploaded the library to maven-central so you can use it with Gradle:
    compile 'eu.lestard:advanced-bindings:0.1.0'
    
    or with Maven:
    <dependency>
        <groupId>eu.lestard</groupId>
        <artifactId>advanced-bindings</artifactId>
        <version>0.1.0</version>
    </dependency>
    

    ...