Skip to content

Commit

Permalink
Merge branch 'master' into 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Dansoftowner committed Feb 16, 2021
2 parents ef00bfc + 79b95a1 commit 244c68b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/nativejavafx/taskbar/TaskbarProgressbarImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.nativejavafx.taskbar;

import com.nativejavafx.taskbar.exception.StageNotShownException;
import com.nativejavafx.taskbar.exception.UnsupportedSystemException;
import com.nativejavafx.taskbar.strategy.HWNDStrategy;
import javafx.stage.Stage;
import org.bridj.Pointer;
Expand Down Expand Up @@ -83,20 +85,23 @@ private void setProgressState(Stage stage, Type type) {

@Override
public void stopProgress() {
validate(stage.get());
if (this.stage.get() != null) {
setProgressState(stage.get(), Type.NO_PROGRESS);
}
}

@Override
public void showIndeterminateProgress() {
validate(stage.get());
if (this.stage.get() != null) {
setProgressState(stage.get(), Type.INDETERMINATE);
}
}

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

@Override
public void setProgressType(@NotNull Type type) {
validate(stage.get());
setProgressState(stage.get(), type);
}

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

private void validate(Stage stage) {
checkSystemSupported();
checkStageShown(stage);
}

private void checkStageShown(Stage stage) {
if (!stage.isShowing()) throw new StageNotShownException(
"The given Stage is not showing and therefore taskbar-progressbar can't be created"
);
}

private void checkSystemSupported() {
if (isNotSupported()) throw new UnsupportedSystemException(
String.format(
"%s (system: %s, version: %s)",
"Your system does not support taskbar-progressbar!",
System.getProperty("os.name"),
System.getProperty("os.version")
)
);
}

private static final class DaemonThread extends Thread {
DaemonThread(Runnable runnable) {
super(runnable);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nativejavafx.taskbar.exception;

public class StageNotShownException extends RuntimeException {
public StageNotShownException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nativejavafx.taskbar.exception;

public class UnsupportedSystemException extends RuntimeException {
public UnsupportedSystemException(String message) {
super(message);
}
}

0 comments on commit 244c68b

Please sign in to comment.