Add callback handlers for LiveWindow (#2053)

Fixes #2223
This commit is contained in:
Thad House
2020-01-12 22:37:24 -08:00
committed by Peter Johnson
parent 73302f6162
commit cb66bcca3c
7 changed files with 75 additions and 3 deletions

View File

@@ -33,6 +33,9 @@ public class LiveWindow {
private static boolean liveWindowEnabled;
private static boolean telemetryEnabled = true;
private static Runnable enabledListener;
private static Runnable disabledListener;
private static Component getOrAdd(Sendable sendable) {
Component data = (Component) SendableRegistry.getData(sendable, dataHandle);
if (data == null) {
@@ -46,6 +49,14 @@ public class LiveWindow {
throw new UnsupportedOperationException("This is a utility class!");
}
public static synchronized void setEnabledListener(Runnable runnable) {
enabledListener = runnable;
}
public static synchronized void setDisabledListener(Runnable runnable) {
disabledListener = runnable;
}
public static synchronized boolean isEnabled() {
return liveWindowEnabled;
}
@@ -65,11 +76,17 @@ public class LiveWindow {
updateValues(); // Force table generation now to make sure everything is defined
if (enabled) {
System.out.println("Starting live window mode.");
if (enabledListener != null) {
enabledListener.run();
}
} else {
System.out.println("stopping live window mode.");
SendableRegistry.foreachLiveWindow(dataHandle, cbdata -> {
cbdata.builder.stopLiveWindowMode();
});
if (disabledListener != null) {
disabledListener.run();
}
}
enabledEntry.setBoolean(enabled);
}