Collection of Binding helpers for JavaFX(8)

Overview

Advanced-Bindings for JavaFX (8)

Build Status

advanced-bindings is a collection of useful helpers and custom binding implementations to simplify the development of applications that are heavily based on JavaFX's Properties and Bindings.

New Features?

If you have ideas for new custom bindings that could be added to the library feel free to add an issue.

Links

JavaDoc

## Maven Dependencies

Advanced-Bindings releases are available in the Maven Central Repository. You can use it like this:

Stable release

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>

Current Development version (Snapshot)

The development version is published automatically to the Sonatype Snapshot repository.

Gradle

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

dependencies {
    compile 'eu.lestard:advanced-bindings:0.5.0-SNAPSHOT'
}

Maven

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

Features

MathBindings

eu.lestard.advanced_bindings.api.MathBindings.*

Contains Bindings for all methods of java.lang.Math

Example:

@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);
}

NumberBindings

Example: safeDevide A binding to express a division like Bindings.divide with the difference that no ArithmeticException will be thrown when a division by zero happens. Instead a default value of 0 is used (or another value defined by the user).

This can be useful because with the standard divide binding you can run into problems when defining something like this:

IntegerProperty a = new SimpleIntegerProperty();
IntegerProperty b = new SimpleIntegerProperty();

NumberBinding result = Bindings
  .when(b.isEqualTo(0))
  .then(0)
  .otherwise(a.divide(b));

This won't work as expected and will throw an ArithmeticException because the expression a.divide(b) is evaluated independently from the b.isEqualTo(0) condition.

With Advanced-Bindings you can write this instead:

IntegerProperty a = new SimpleIntegerProperty();
IntegerProperty b = new SimpleIntegerProperty();

IntegerBinding result = NumberBindings.divideSafe(a,b);

This won't throw an ArithmenticException even when b has a value of 0. While this is "wrong" from a mathematical point of view it can simplify the development of bindings based applications a lot, for example when b is bound to a Slider that has an initial value of 0.

Example: isNaN

@Test
public void testIsNan(){
    DoubleProperty a = new SimpleDoubleProperty();
    DoubleProperty b = new SimpleDoubleProperty();

    final DoubleBinding quotient = a.divide(b);
    BooleanBinding nan = NumberBindings.isNaN(quotient);


    a.set(2);
    b.set(4);

    assertThat(nan).isFalse();


    a.set(0);
    b.set(0);

    assertThat(nan).isTrue();
}

Example: isInfinite

@Test
public void testIsInfinite(){
    DoubleProperty a = new SimpleDoubleProperty();
    DoubleProperty b = new SimpleDoubleProperty();

    DoubleBinding product =  a.multiply(b);

    BooleanBinding infinite = NumberBindings.isInfinite(product);


    a.set(2);
    b.set(4);

    assertThat(infinite).isFalse();

    b.set(Double.MAX_VALUE);

    assertThat(infinite).isTrue();
}

StringBindings

Example: RegExp

@Test
public void testMatches(){
    StringProperty text = new SimpleStringProperty();

    String pattern = "[0-9]*";  // only numbers are allowed

    BooleanBinding matches = StringBindings.matches(text, pattern);


    text.set("19");

    assertThat(matches).isTrue();


    text.set("no number");

    assertThat(matches).isFalse();
}

CollectionBindings

Example: Sum of all integers in an observable list

@Test
public void testSum(){
    ObservableList<Integer> numbers = FXCollections.observableArrayList();

    NumberBinding sum = CollectionBindings.sum(numbers);


    numbers.addAll(1, 2, 3, 5, 8, 13, 21);

    assertThat(sum).hasValue(53.0);

    numbers.add(34);

    assertThat(sum).hasValue(87.0);
}

SwitchBindings

In JavaFX there are standard methods to create IF-THEN-ELSE bindings. But there is no way to create something like a switch for use cases where there are a lot of cases.

Advanced-Bindings has a builder to create switch like bindings:

IntegerProperty base = new SimpleIntegerProperty();

ObservableValue<String> result = switchBinding(base, String.class)
      .bindCase(1, i -> "one")
      .bindCase(3, i -> "three")
      .bindCase(10, i -> "ten")
      .bindDefault(() -> "nothing")
      .build();

There are two differences to the normal switch statement of Java:

  • While the standard switch statement has a limitation to numbers, Strings and Enums. Only those types can be used as control variable. There is no such limitation for the Switch binding. Every type that has a properly overwritten equals method can be used.
  • There is no "fall-through" and therefore no break is needed.
Comments
  • Several updates to the build setup

    Several updates to the build setup

    • apply license plugin. format all files with proper license headers.
    • append LICENSE file to JAR.
    • append extra JAR manifest properties.
    • update build dependencies.
    opened by aalmiray 2
  • Add Collection overloads to LogicBindings

    Add Collection overloads to LogicBindings

    Title says it all. Closes #5.

    I also changed the filter.findAny.isPresent chains to allMatch and anyMatch for readability and (minor) performance improvement.

    opened by HoldYourWaffle 1
  • Update gradle wrapper

    Update gradle wrapper

    The gradle wrapper is long overdue for an update, especially since gradle 2.3 is no longer supported by IntelliJ.

    I unfortunately had to (temporarily) remove the sonar-runner plugin because it's no longer available. I know there are alternatives, but I have no idea what sonar-runner actually is, so I didn't try replacing it myself (yet). I'd love to hear if and how I can/should replace it!

    opened by HoldYourWaffle 1
  • LogicBindings with Collection<>

    LogicBindings with Collection<>

    At the moment the LogicBindings methods for or and and bindings are taking a varargs array of ObservableBooleanValue.

    Add an overloaded method that takes a Collection or List of elements instead of a varargs array.

    opened by manuel-mauky 0
  • Division binding with default value for division by zero cases

    Division binding with default value for division by zero cases

    With the standard Bindings of JavaFX you can create a binding like this:

    IntegerProperty a = new SimpleIntegerProperty();
    IntegerProperty b = new SimpleIntegerProperty();
    
    NumberBinding result = Bindings.when(a.isEqualTo(0)).then(0).otherwise(a.divide(b));
    

    However this will throw an ArithmeticException because of a division by zero.

    To solve these cases add a binding like this:

    NumberBinding result = NumberBindings.divideSafe(a, b, 0);
    

    In this example the third parameter is a default value that is used everytime a division by zero is happening.

    enhancement 
    opened by manuel-mauky 0
  • AND / OR BooleanBindings with variable number of arguments

    AND / OR BooleanBindings with variable number of arguments

    BooleanProperty a = new SimpleBooleanProperty(true);
    BooleanProperty b = new SimpleBooleanProperty(true);
    BooleanProperty c = new SimpleBooleanProperty(false);
    
    BooleanBinding result = LogicBindings.and(a, b, c);
    
    assertThat(result).isFalse();
    
    opened by manuel-mauky 0
  • BigdecimalProperty

    BigdecimalProperty

    JavaFX misses BigDecimalProperties, so you can't use them like IntegerProperties with the fluent API of the NumberProperty.

    https://docs.oracle.com/javafx/2/api/javafx/beans/binding/NumberExpressionBase.html shows the available implementations (DoubleExpression, FloatExpression, IntegerExpression, LongExpression)

    An implementation for BigDecimals would be usefull. (Got them requested in workshops)

    opened by sialcasa 1
Releases(v0.3.0)
Owner
Manuel Mauky
Manuel Mauky
A collection of tools and libraries for easier development on the JavaFX platform!

This project is archived I do not realistically have the time to take care of this project, unfortunately. It originally was built along a Twitter cli

Tristan Deloche 100 Dec 13, 2022
A collection of Apple UI controls implemented in JavaFX.

Apple FX A collection of Apple UI controls implemented in JavaFX. Available Macos controls: MacosButton MacosCheckBox MacosRadioButton MacosLabel Maco

Gerrit Grunwald 17 Sep 25, 2022
Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.

FXTrayIcon Library intended for use in JavaFX applications that makes adding a System Tray icon easier. The FXTrayIcon class handles all the messy AWT

Dustin Redmond 248 Dec 30, 2022
Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE 8 and provides the functionalities to use and handle easily Tiles in your JavaFX application.

Lib-Tile Intention Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE and provides the functionalities to use and handle easily Tile

Peter Rogge 13 Apr 13, 2022
DataFX - is a JavaFX frameworks that provides additional features to create MVC based applications in JavaFX by providing routing and a context for CDI.

What you’ve stumbled upon here is a project that intends to make retrieving, massaging, populating, viewing, and editing data in JavaFX UI controls ea

Guigarage 110 Dec 29, 2022
🍏 A collection of partial JNA bindings for various macOS frameworks. (e.g. Foundation, AppKit, etc.)

JNApple ?? A collection of partial JNA bindings for various macOS frameworks. (e.g. Foundation, AppKit, etc.) Usage These are just some common example

Iridescent 3 Jun 19, 2022
Docking framework for JavaFX platform

Docking framework for JavaFX platform AnchorFX is a gratis and open source library for JavaFX to create graphical interfaces with docking features Anc

Alessio Vinerbi 197 Oct 15, 2022
A library of +70 ready-to-use animations for JavaFX

AnimateFX A library of ready-to-use animations for JavaFX Features: Custom animations Custom interpolators Play/Stop animation Play an animation after

Loïc Sculier 366 Jan 5, 2023
BootstrapFX: Bootstrap for JavaFX

BootstrapFX BootstrapFX is a partial port of Twitter Bootstrap for JavaFX. It mainly provides a CSS stylesheet that closely resembles the original whi

Kordamp 810 Dec 28, 2022
A Java framework for creating sophisticated calendar views (JavaFX 8, 9, 10, and 11)

CalendarFX A Java framework for creating sophisticated calendar views based on JavaFX. A detailed developer manual can be found online: CalendarFX 8 D

DLSC Software & Consulting GmbH 660 Jan 6, 2023
Allow runtime modification of JavaFX CSS

cssfx ⚠ WARNING ⚠ In version 11.3.0 we have relocated & refactored the project. maven groupId has been changed to fr.brouillard.oss java module name h

Matthieu Brouillard 134 Jan 2, 2023
A JavaFX UI framework to create fully customized undecorated windows

CustomStage A JavaFX undecorated stage which can fully be customized Donations If this project is helpful to you and love my work and feel like showin

Oshan Mendis 186 Jan 6, 2023
MDI components for JavaFX

DesktopPaneFX DesktopPaneFX is a JavaFX version of Swing’s JDesktopPane which can be used as a container for individual "child" similar to JInternalFr

Kordamp 58 Sep 23, 2022
Efficient VirtualFlow for JavaFX

Flowless Efficient VirtualFlow for JavaFX. VirtualFlow is a layout container that lays out cells in a vertical or horizontal flow. The main feature of

null 163 Nov 24, 2022
A framework for easily creating forms for a JavaFX UI.

FormsFX Forms for business application made easy. Creating forms in Java has never been this easy! Maven To use this framework as part of your Maven b

DLSC Software & Consulting GmbH 534 Dec 30, 2022
:icecream: iOS frosty/translucent effect to JavaFX

FroXty is JavaFX library which replicates the famous iOS translucent effect with ease. Set-up FroXty can be imported into your project either by downl

Giorgio Garofalo 33 Dec 11, 2022
💠 Undecorated JavaFX Scene with implemented move, resize, minimise, maximise, close and Windows Aero Snap controls.

Support me joining PI Network app with invitation code AlexKent FX-BorderlessScene ( Library ) ?? Undecorated JavaFX Scene with implemented move, resi

Alexander Kentros 125 Jan 4, 2023
Dynamic JavaFX form generation

FXForm 2 Stop coding forms: FXForm 2 can do it for you! About FXForm2 is a library providing automatic JavaFX form generation. How does it work? Write

dooApp 209 Jan 9, 2023
A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

FXGraphics2D Version 2.1, 3 October 2020. Overview FXGraphics2D is a free implementation of Java's Graphics2D API that targets the JavaFX Canvas. It m

David Gilbert 184 Dec 31, 2022