Example usage for javafx.beans.binding When When

List of usage examples for javafx.beans.binding When When

Introduction

In this page you can find the example usage for javafx.beans.binding When When.

Prototype

public When(final @NamedArg("condition") ObservableBooleanValue condition) 

Source Link

Document

The constructor of When .

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleProperty a = new SimpleDoubleProperty(0);
    DoubleProperty b = new SimpleDoubleProperty(0);

    DoubleBinding s = a.add(b).divide(2.0D);

    final DoubleBinding aBinding = new When(a.add(b).greaterThan(b).and(a.add(a).greaterThan(b)))
            .then(s.multiply(s.subtract(a)).multiply(s.subtract(b))).otherwise(0.0D);

    a.set(3);/*  www .j  a  va  2s.c om*/
    b.set(4);
    System.out.println(a.get());
    System.out.println(b.get());
    System.out.println(aBinding.get());

    a.set(2);
    b.set(2);
    System.out.println(a.get());
    System.out.println(b.get());
    System.out.println(aBinding.get());

}

From source file:Main.java

@Override
public void start(Stage stage) {
    Button b1 = new Button("B1");
    Button b2 = new Button("B2");
    Button b3 = new Button("B3");
    Button visibleBtn = new Button("Make Invisible");

    visibleBtn.setOnAction(e -> b2.setVisible(!b2.isVisible()));

    visibleBtn.textProperty().bind(new When(b2.visibleProperty()).then("Invisible").otherwise("Visible"));

    b2.managedProperty().bind(b2.visibleProperty());

    HBox root = new HBox();
    root.getChildren().addAll(visibleBtn, b1, b2, b3);

    Scene scene = new Scene(root);
    stage.setScene(scene);/*from w w  w  .  j  a v  a 2 s . c  o m*/
    stage.setTitle("");
    stage.show();
}

From source file:de.thomasbolz.renamer.RenamerGUI.java

/**
 * Initialize the property bindings.//w  w  w .j  a v a 2s.  co  m
 */
private void initBindings() {

    // reflect changes of srcDirectory in the GUI and store the new source dir to the preferences
    srcDirectory.addListener(new ChangeListener<File>() {
        @Override
        public void changed(ObservableValue<? extends File> observableValue, File oldFile, File newFile) {
            if (newFile != null) {
                String path = newFile.getAbsolutePath();
                lblSource.setText(path);
                setSourceDirectoryToPrefs(path);
            }
            setSimulationMode(true);
        }
    });
    // reflect changes of targetDirectory in the GUI and store the new target dir to the preferences
    targetDirectory.addListener(new ChangeListener<File>() {
        @Override
        public void changed(ObservableValue<? extends File> observableValue, File oldFile, File newFile) {
            if (newFile != null) {
                String path = newFile.getAbsolutePath();
                lblTarget.setText(path);
                setTargetDirectoryToPrefs(path);
            }
            setSimulationMode(true);
        }
    });
    btnRename.textProperty()
            .bind(new When(simulationMode).then("Simulate renaming").otherwise("Execute renaming"));
}