mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-23 10:31:24 -08:00
* Make eclipse formatter better follow our conventions and format all of it * Don't join wrapped lines to allow for hand-formatting * Fix formatting of switch statements and add breaks in enum declarations * Use new formatter by @thebutlah, adjust formatter more
52 lines
1.0 KiB
Java
52 lines
1.0 KiB
Java
package dev.slimevr.gui.swing;
|
|
|
|
import javax.swing.*;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
public class ButtonTimer {
|
|
|
|
private static final Timer timer = new Timer();
|
|
|
|
public static void runTimer(
|
|
AbstractButton button,
|
|
int seconds,
|
|
String defaultText,
|
|
Runnable runnable
|
|
) {
|
|
if (seconds <= 0) {
|
|
button.setText(defaultText);
|
|
runnable.run();
|
|
} else {
|
|
button.setText(String.valueOf(seconds));
|
|
timer.schedule(new ButtonTimerTask(button, seconds - 1, defaultText, runnable), 1000);
|
|
}
|
|
}
|
|
|
|
private static class ButtonTimerTask extends TimerTask {
|
|
|
|
private final AbstractButton button;
|
|
private final int seconds;
|
|
private final String defaultText;
|
|
private final Runnable runnable;
|
|
|
|
private ButtonTimerTask(
|
|
AbstractButton button,
|
|
int seconds,
|
|
String defaultText,
|
|
Runnable runnable
|
|
) {
|
|
this.button = button;
|
|
this.seconds = seconds;
|
|
this.defaultText = defaultText;
|
|
this.runnable = runnable;
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
runTimer(button, seconds, defaultText, runnable);
|
|
}
|
|
}
|
|
}
|