dorkbox.systemTray.util.EventDispatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SystemTray Show documentation
Show all versions of SystemTray Show documentation
Cross-platform SystemTray support for Swing/AWT, GtkStatusIcon, and AppIndicator on Java 6+
package dorkbox.systemTray.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import dorkbox.util.NamedThreadFactory;
/**
* Adds events to a single thread event dispatch, so that regardless of OS, all event callbacks happen on the same thread -- which is NOT
* the GTK/AWT/SWING event dispatch thread. There can be ODD peculiarities across on GTK with how AWT/SWING react with the GTK Event
* Dispatch Thread.
*/
public
class EventDispatch {
private static ExecutorService eventDispatchExecutor = null;
/**
* Schedule an event to occur sometime in the future.
*/
public static synchronized
void runLater(Runnable runnable) {
if (eventDispatchExecutor == null) {
eventDispatchExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("SystemTrayEventDispatch", false));
}
eventDispatchExecutor.execute(runnable);
}
/**
* Shutdown the event dispatch
*/
public static synchronized
void shutdown() {
if (eventDispatchExecutor != null) {
eventDispatchExecutor.shutdownNow();
eventDispatchExecutor = null;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy