All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dua3.utility.fx.controls.SimpleInputControl Maven / Gradle / Ivy

The newest version!
package com.dua3.utility.fx.controls;

import javafx.beans.property.Property;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.scene.control.Control;

import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

public class SimpleInputControl implements InputControl {

    private final C control;
    private final State state;
    private final Supplier dflt;

    protected SimpleInputControl(C control, Property value, Supplier dflt, Function> validate) {
        this.control = control;
        this.state = new State<>(value, dflt, validate);
        this.dflt = dflt;

        reset();
    }

    @Override
    public C node() {
        return control;
    }

    @Override
    public Property valueProperty() {
        return state.valueProperty();
    }

    @Override
    public void reset() {
        state.valueProperty().setValue(dflt.get());
    }

    @Override
    public ReadOnlyBooleanProperty validProperty() {
        return state.validProperty();
    }

    @Override
    public ReadOnlyStringProperty errorProperty() {
        return state.errorProperty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy