Skip to content

Commit 244c68b

Browse files
committed
Merge branch 'master' into 11
2 parents ef00bfc + 79b95a1 commit 244c68b

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/main/java/com/nativejavafx/taskbar/TaskbarProgressbarImpl.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.nativejavafx.taskbar;
1616

17+
import com.nativejavafx.taskbar.exception.StageNotShownException;
18+
import com.nativejavafx.taskbar.exception.UnsupportedSystemException;
1719
import com.nativejavafx.taskbar.strategy.HWNDStrategy;
1820
import javafx.stage.Stage;
1921
import org.bridj.Pointer;
@@ -83,20 +85,23 @@ private void setProgressState(Stage stage, Type type) {
8385

8486
@Override
8587
public void stopProgress() {
88+
validate(stage.get());
8689
if (this.stage.get() != null) {
8790
setProgressState(stage.get(), Type.NO_PROGRESS);
8891
}
8992
}
9093

9194
@Override
9295
public void showIndeterminateProgress() {
96+
validate(stage.get());
9397
if (this.stage.get() != null) {
9498
setProgressState(stage.get(), Type.INDETERMINATE);
9599
}
96100
}
97101

98102
@Override
99103
public void showCustomProgress(long startValue, long endValue, @NotNull Type type) {
104+
validate(stage.get());
100105
if (this.stage.get() != null) {
101106
final Pointer<Integer> pointer = getPointer(stage.get());
102107
executor.execute(() -> {
@@ -108,6 +113,7 @@ public void showCustomProgress(long startValue, long endValue, @NotNull Type typ
108113

109114
@Override
110115
public void setProgressType(@NotNull Type type) {
116+
validate(stage.get());
111117
setProgressState(stage.get(), type);
112118
}
113119

@@ -116,6 +122,28 @@ public void closeOperations() {
116122
executor.submit(() -> iTaskbarList3.get().Release());
117123
}
118124

125+
private void validate(Stage stage) {
126+
checkSystemSupported();
127+
checkStageShown(stage);
128+
}
129+
130+
private void checkStageShown(Stage stage) {
131+
if (!stage.isShowing()) throw new StageNotShownException(
132+
"The given Stage is not showing and therefore taskbar-progressbar can't be created"
133+
);
134+
}
135+
136+
private void checkSystemSupported() {
137+
if (isNotSupported()) throw new UnsupportedSystemException(
138+
String.format(
139+
"%s (system: %s, version: %s)",
140+
"Your system does not support taskbar-progressbar!",
141+
System.getProperty("os.name"),
142+
System.getProperty("os.version")
143+
)
144+
);
145+
}
146+
119147
private static final class DaemonThread extends Thread {
120148
DaemonThread(Runnable runnable) {
121149
super(runnable);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.nativejavafx.taskbar.exception;
2+
3+
public class StageNotShownException extends RuntimeException {
4+
public StageNotShownException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.nativejavafx.taskbar.exception;
2+
3+
public class UnsupportedSystemException extends RuntimeException {
4+
public UnsupportedSystemException(String message) {
5+
super(message);
6+
}
7+
}

0 commit comments

Comments
 (0)