jfxtras.labs.scene.control.scheduler.skin.AllResources Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfxtras-labs Show documentation
Show all versions of jfxtras-labs Show documentation
Experimental components for JavaFX 2
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 extends Scheduler.Resource> 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;
}
}