-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathSplashManager.java
More file actions
99 lines (80 loc) · 2.21 KB
/
SplashManager.java
File metadata and controls
99 lines (80 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.neuronrobotics.bowlerstudio;
import java.awt.Graphics2D;
import java.util.function.BooleanSupplier;
import org.jfree.util.Log;
public class SplashManager {
private static Graphics2D splashGraphics;
private static boolean loadFirst = true;
private static BooleanSupplier closePreventer = () -> false;
public static void closeSplash() {
if (isVisibleSplash())
closeSplashLocal();
}
private static void closeSplashLocal() {
if (BowlerStudio.splash != null) {
BowlerStudio.splash.close();
splashGraphics = null;
return;
}
if (closePreventer.getAsBoolean()) {
Log.debug("Close prevented by " + closePreventer);
return;
}
PsudoSplash.close();
}
public static boolean isVisibleSplash() {
if (BowlerStudio.splash != null)
return BowlerStudio.splash.isVisible();
if (!PsudoSplash.isInitialized())
return false;
return PsudoSplash.isVisibleSplash();
}
private static void updateSplash() {
PsudoSplash.get().updateSplash();
}
public static void renderSplashFrame(int percent, String message) {
if (loadFirst) {
initialize();
}
String string = percent + "% " + message;
// com.neuronrobotics.sdk.common.Log.debug(" Splash Rendering " + percent + " "
// + message);
PsudoSplash.get().setMessage(string);
waitForUpdate();
}
public static void onLogUpdate(String message) {
if (loadFirst) {
initialize();
}
PsudoSplash.get().onLogUpdate(message, null);
waitForUpdate();
}
private static void waitForUpdate() {
updateSplash();
// if (Platform.isFxApplicationThread())
// throw new RuntimeException("Splash manager can not be opened from a javafx
// thread!");
int index = 0;
while (!SplashManager.isVisibleSplash()) {
com.neuronrobotics.sdk.common.Log.debug("Waiting for splash to open before moving on");
try {
Thread.sleep(100);
index++;
} catch (InterruptedException e) {
return;
}
if (index > 10)
return;
}
}
private static void initialize() {
com.neuronrobotics.sdk.common.Log.error("No splash screen available!");
loadFirst = false;
}
public static BooleanSupplier getClosePreventer() {
return closePreventer;
}
public static void setClosePreventer(BooleanSupplier cp) {
closePreventer = cp;
}
}