All Projects → manuel-mauky → advanced-bindings

manuel-mauky / advanced-bindings

Licence: Apache-2.0 license
Collection of Binding helpers for JavaFX(8)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to advanced-bindings

lib-preferences
Lib-Preferences is a library for easy storing simple data to a Preferences.properties file in a Java(FX) & Maven desktop application.
Stars: ✭ 12 (-80.95%)
Mutual labels:  javafx, javafx-library
animated
🌊 Implicit animations for JavaFX.
Stars: ✭ 79 (+25.4%)
Mutual labels:  javafx, javafx-library
Bank-Account-Simulation
A Bank Account Simulation with JavaFX and SQLite back-end. Material UX|UI.
Stars: ✭ 19 (-69.84%)
Mutual labels:  javafx, javafx-library
MaskedTextField
MaskedTextField is an component similar to JFormmatedText field and can be used in same way.
Stars: ✭ 21 (-66.67%)
Mutual labels:  javafx, javafx-library
Grid
A grid component for javafx
Stars: ✭ 23 (-63.49%)
Mutual labels:  javafx, javafx-library
JasperViewerFX
The JasperViewerFX is a free JavaFX library which aims to avoid use of JasperReport's swing viewer
Stars: ✭ 27 (-57.14%)
Mutual labels:  javafx, javafx-library
medusa
A JavaFX library for Gauges
Stars: ✭ 605 (+860.32%)
Mutual labels:  javafx, javafx-library
FluxFX
Flux architecture with JavaFX
Stars: ✭ 24 (-61.9%)
Mutual labels:  javafx, javafx-library
DashboardFx
JavaFx Dashboard
Stars: ✭ 272 (+331.75%)
Mutual labels:  javafx, javafx-library
Awesomejavafx
A curated list of awesome JavaFX libraries, books, frameworks, etc...
Stars: ✭ 2,488 (+3849.21%)
Mutual labels:  javafx, javafx-library
wt4
Work tracker for JIRA
Stars: ✭ 26 (-58.73%)
Mutual labels:  javafx
vic2 economy analyzer
Victoria 2 savegame economy analyzer, updated version
Stars: ✭ 44 (-30.16%)
Mutual labels:  javafx
jfx-asynctask
This project was created to simplify how to handle Thread tasks in Javafx, and it is based on the same idea of AsyncTask from Android.
Stars: ✭ 33 (-47.62%)
Mutual labels:  javafx
worldclock
A Sci-fi looking World Clock created using JavaFX.
Stars: ✭ 28 (-55.56%)
Mutual labels:  javafx
JFXC
Jonato JavaFX Controls - More Power for your JavaFX Gui
Stars: ✭ 42 (-33.33%)
Mutual labels:  javafx
OmniGraph
Desktop application for creating graphs and algorithm visualisation
Stars: ✭ 27 (-57.14%)
Mutual labels:  javafx
Azkar-App
Desktop Application 💻 for Calculating Muslim prayer times 🕌 , Morning and Nights Azkar 🤲 with notification for random Azkar that pops-up in specific time.
Stars: ✭ 64 (+1.59%)
Mutual labels:  javafx
YuMusic
A Music Player Build with JavaFX WebView, iView,RequireJS
Stars: ✭ 17 (-73.02%)
Mutual labels:  javafx
sliding-puzzle
Sliding puzzle game implemented in Scala / Scala.js / JavaFX
Stars: ✭ 25 (-60.32%)
Mutual labels:  javafx
openjfx.github.io
openjfx.io
Stars: ✭ 31 (-50.79%)
Mutual labels:  javafx

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].