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

us.ihmc.javafx.parameter.JavaFXParameterTableEntry Maven / Gradle / Ivy

The newest version!
package us.ihmc.javafx.parameter;

import javafx.beans.InvalidationListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import us.ihmc.javafx.FunctionalObservableValue;

import java.util.function.Consumer;
import java.util.function.Supplier;

public class JavaFXParameterTableEntry
{
   private final String parameterName;
   private final Supplier getter;
   private final Consumer setter;
   private final ObservableValue observableName;
   private final ObservableValue> observableValue;
   private final Spinner spinner;

   public JavaFXParameterTableEntry(String parameterName,
                                    Supplier getter,
                                    Consumer setter,
                                    InvalidationListener onUserSpunSpinner,
                                    SpinnerValueFactory spinnerValueFactory)
   {
      this.parameterName = parameterName;
      this.getter = getter;
      this.setter = setter;
      observableName = new FunctionalObservableValue<>(this::getParameterName);
      observableValue = new FunctionalObservableValue<>(this::getSpinner);

      spinner = new Spinner<>();
      spinner.setEditable(true);
      spinner.setValueFactory(spinnerValueFactory);
      spinner.getValueFactory().valueProperty().addListener((observable, old, newValue) ->
      {
         setter.accept(newValue);
         onUserSpunSpinner.invalidated(observable); // these have to be in this order!
      });
      spinner.setMaxWidth(100.0);
   }

   public void setValue(T value)
   {
      setter.accept(value);
   }

   public T getValue()
   {
      return getter.get();
   }

   public ObservableValue getObservableName()
   {
      return observableName;
   }

   public ObservableValue> getObservableValue()
   {
      return observableValue;
   }

   public String getParameterName()
   {
      return parameterName;
   }

   public Spinner getSpinner()
   {
      return spinner;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy