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

org.webswing.javafx.toolkit.WebTimer Maven / Gradle / Ivy

There is a newer version: 20.2.4
Show newest version
package org.webswing.javafx.toolkit;

import com.sun.glass.ui.Timer;
import org.webswing.toolkit.util.DeamonThreadFactory;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class WebTimer extends Timer {
	static ScheduledExecutorService timer ;
	private ScheduledFuture future;

	protected WebTimer(final Runnable runnable) {
		super(runnable);
	}

	@Override
	protected long _start(final Runnable runnable, int period) {
		if (timer == null) {
			timer = Executors.newSingleThreadScheduledExecutor(DeamonThreadFactory.getInstance("Webswing FX Timer"));
		}
		future= timer.scheduleAtFixedRate(runnable, 0, period, TimeUnit.MILLISECONDS);
		return 1; // need something non-zero to denote success.
	}

	@Override
	protected long _start(Runnable runnable) {
		throw new RuntimeException("vsync timer not supported");
	}

	@Override
	protected void _stop(long timer) {
		if (future != null) {
			future.cancel(false);
			future = null;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy