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

jfxtras.labs.scene.control.scheduler.skin.AllResources Maven / Gradle / Ivy

The newest version!
package jfxtras.labs.scene.control.scheduler.skin;

import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.WeakListChangeListener;
import jfxtras.labs.scene.control.scheduler.Scheduler;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tom Eugelink
 * @author Islam Khachmakhov
 */
public class AllResources {

    final private ObservableList resources;
    final private ListChangeListener listChangeListener= new ListChangeListener() {

        @Override
        public void onChanged(Change c) {
            fireOnChangeListener();
        }
    };

    public AllResources(ObservableList resources) {
        this.resources = resources;

        this.resources.addListener(new WeakListChangeListener<>(listChangeListener));
    }


    /**
     * fires when something changes in the events
     */
    public void addOnChangeListener(Runnable runnable) {
        this.runnables.add(runnable);
    }
    public void removeOnChangeListener(Runnable runnable) {
        this.runnables.remove(runnable);
    }
    private List runnables = new ArrayList<>();

    private void fireOnChangeListener() {
        for (Runnable runnable : runnables) {
//            runnable.run();
            Platform.runLater(runnable);
        }
    }

    List collectRegular() {
        return resources;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy