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

us.ihmc.javafx.FunctionalObservableValue Maven / Gradle / Ivy

The newest version!
package us.ihmc.javafx;

import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;

import java.util.ArrayList;
import java.util.function.Supplier;

public class FunctionalObservableValue implements ObservableValue
{
   private final ArrayList changeListeners = new ArrayList<>();
   private final ArrayList invalidationListeners = new ArrayList<>();
   private final Supplier getter;

   public FunctionalObservableValue(Supplier getter)
   {
      this.getter = getter;
   }

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

   @Override
   public void addListener(ChangeListener listener)
   {
      changeListeners.add(listener);
   }

   @Override
   public void removeListener(ChangeListener listener)
   {
      changeListeners.remove(listener);
   }

   @Override
   public void addListener(InvalidationListener listener)
   {
      invalidationListeners.add(listener);
   }

   @Override
   public void removeListener(InvalidationListener listener)
   {
      invalidationListeners.remove(listener);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy