Skip to content

Commit d3149a8

Browse files
committed
Update README
1 parent 468aada commit d3149a8

11 files changed

Lines changed: 118 additions & 48 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
.idea
3-
.nb-gradle
3+
.nb-gradle
4+
out

README.md

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,117 @@
11
# JavaFXTaskbarProgressBar
2-
## This library allows you to add taskbar progressbars to your javafx stages.
3-
The library uses another library called [Bridj](https://github.com/nativelibs4java/BridJ).
4-
With the Bridj library you can add taskbar progressbars only to the old swing JFrames,
5-
but not for your javafx stages. But this library will be your solution i hope :).
2+
## This library allows you to add native taskbar-progressbar functionality to your JavaFX stages.
3+
The library uses another library called [bridj](https://github.com/nativelibs4java/BridJ) that
4+
can give access to native operations in java. With the Bridj library you can easily add taskbar progressbars
5+
to the old swing JFrames but for javafx stages it's too complicated to achieve.<br>
6+
<b>This library is for you who want to easily use this amazing native functionality with JavaFX!</b>
7+
8+
## Compatibility
9+
This library only works with java 8 but java 11 support is coming soon!
10+
11+
## Background: what are taskbar progressbars?
12+
Since Windows 7 there is a taskbar-progressbar feature in Windows systems.
13+
A good example for this when you copy something using the file explorer:<br>
14+
![Taskbar progressbar in windows 7](images/areo-progressbar.jpg) <br>
15+
This library allows you to do this in java (with javaFX)!
616

717
## How to include it to your project
818
You can download the jar file from the releases.
19+
Every release has two jar files: one is a fat jar that contains the bridj binaries
20+
as well (so if you use this you don't have to include bridj separately for your project);
21+
and another jar that doesn't contain the external bridj binaries (in this case you have
22+
to download it separately).
923

10-
## How to use it
24+
## How to use it in practice
1125

12-
Create your stage:
13-
```java
14-
Stage stage = new Stage();
15-
```
26+
### Types of progressbar
27+
Before we jump in we have to know the 4 types of a taskbar-progressbar:<br>
28+
* `NORMAL` - a progressbar with normal green color
29+
* `PAUSED` - a progressbar with a yellow color
30+
* `ERROR` - a progressbar with a red color
31+
* `INDETERMINATE` - a progressbar that doesn't show any fix progress
32+
* `NO_PROGRESS` - a progressbar that doesn't show anything
33+
<br><br>
34+
All these types are represented by an enum called `com.nativejavafx.taskbar.TaskbarProgressbar.Type`.
35+
36+
Now let's see how can we actually use this through code.<br>
37+
There are multiple ways to create taskbar progressbars with this library:
1638

17-
Then, you have to create the TaskbarProgressbar object:
39+
#### Static methods
40+
Firstly you have to import the necessary class:
1841
```java
19-
TaskbarProgressbar taskProgressbar = new TaskbarProgressbar(stage);
42+
import com.nativejavafx.taskbar.TaskbarProgressbar;
43+
```
44+
...and you have to show the javafx Stage before any operation:
2045
```
21-
Before you start the taskbar progressbar, you must show the stage
46+
primaryStage.show();
47+
```
48+
Then call the static method:
2249
```java
23-
stage.show();
50+
TaskbarProgressbar.showCustomProgress(primaryStage, 50, 100, TaskbarProgressbar.Type.NORMAL);
2451
```
25-
Now you can do everything that the taskbar progressbar can do, for example you can show a progress:
52+
53+
It looks okay but it's not safe to do that. This functionality isn't supported by every OS.
54+
<b>If you use this way to create taskbar progressbars you always have to check that the current OS
55+
supports this functionality!</b>
56+
57+
So let's correct the code:
2658
```java
27-
taskProgressbar.showOtherProgress(50, 100, TaskbarProgressbar.TaskbarProgressbarType.NORMAL);
59+
if (TaskbarProgressbar.isSupported()) {
60+
TaskbarProgressbar.showCustomProgress(primaryStage, 50, 100, TaskbarProgressbar.Type.NORMAL);
61+
}
2862
```
29-
It will creates this view at the taskbar:
30-
![](https://i.stack.imgur.com/IG7v5.png).
3163

32-
There are 5 types of the taskbar progressbar:
64+
<b>Result:</b><br>
65+
![Normal Taskbar progressbar](images/normal-progress.jpg)
3366

34-
`TaskbarProgressbar.TaskbarProgressbarType.NORMAL` - It is the normal progressbar with the green color
35-
`TaskbarProgressbar.TaskbarProgressbarType.ERROR` - It is the error progressbar with the red color.
36-
`TaskbarProgressbar.TaskbarProgressbarType.PAUSED` - It is the paused progressbar with the yellow color.
67+
You have to do a similar thing if you want to show an indeterminate progress:
68+
```java
69+
if (TaskbarProgressbar.isSupported()) {
70+
TaskbarProgressbar.showIndeterminateProgress(primaryStage);
71+
}
72+
```
73+
<b>Result:</b><br>
74+
![Indeterminate Taskbar progressbar](images/indeterminate.gif)
3775

38-
`TaskbarProgressbar.TaskbarProgressbarType.NO_PROGRESS` - It is the empty progressbar
39-
`TaskbarProgressbar.TaskbarProgressbarType.INDETERMINATE` - It is the indeterminate progressbar. It doesn't show any fix progress.
76+
To stop the progress:
77+
```java
78+
TaskbarProgressbar.stopProgress(primaryStage);
79+
```
80+
#### Through instantiation
81+
Firstly (after you imported the necessary class) create a `TaskbarProgressbar` instance:
82+
```java
83+
TaskbarProgressbar progressbar = TaskbarProgressbar.createInstance(primaryStage);
84+
```
85+
Before any operation you have to show the Stage:
86+
```java
87+
primaryStage.show();
88+
```
89+
After that just use the created instance for the operations:
90+
```
91+
progressbar.showCustomProgress(50, 100, TaskbarProgressbar.Type.NORMAL);
92+
```
93+
<b><i>Note: in this case to check that the OS supports this functionality is unnecessary
94+
because the object checks it automatically!</i></b>
95+
96+
The result is the same:<br>
97+
![Normal Taskbar progressbar](images/normal-progress.jpg)
4098

41-
If you want to show an indeterminate progress:
99+
If you want an indeterminate process:
42100
```java
43-
taskbarProgressbar.showIndeterminateProgress();
101+
progressbar.showIndeterminateProgress();
44102
```
45-
If you want to stop the progress:
103+
To stop the progress:
46104
```java
47-
taskbarProgressbar.stopProgress();
105+
progressbar.stopProgress();
48106
```
107+
#### Full example
108+
109+
110+
## More screenshots
111+
Some more screenshots about what can you do with this library
112+
* A paused progress example:<br>
113+
Code: `progressbar.showCustomProgress(70, 100, TaskbarProgressbar.Type.PAUSED);`<br>
114+
![Paused progress](images/paused-progress.jpg)
115+
* An error progress example:<br>
116+
Code: `progressbar.showCustomProgress(40, 100, TaskbarProgressbar.Type.ERROR);`<br>
117+
![Paused progress](images/error-progress.jpg)

images/areo-progressbar.jpg

1.97 KB
Loading

images/error-progress.jpg

1.91 KB
Loading

images/indeterminate.gif

36.1 KB
Loading

images/normal-progress.jpg

1.82 KB
Loading

images/paused-progress.jpg

2.02 KB
Loading

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void showIndeterminateProgress() {
1414
}
1515

1616
@Override
17-
public void showCustomProgress(long done, long max, TaskbarProgressbarType type) {
17+
public void showCustomProgress(long done, long max, Type type) {
1818
}
1919

2020
@Override

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class TaskbarProgressbar {
1919
* Defines the types of the taskbar progressbars
2020
* that can be used on a Windows 7+ system.
2121
*/
22-
public enum TaskbarProgressbarType {
22+
public enum Type {
2323
ERROR(ITaskbarList3.TbpFlag.TBPF_ERROR),
2424
INDETERMINATE(ITaskbarList3.TbpFlag.TBPF_INDETERMINATE),
2525
NO_PROGRESS(ITaskbarList3.TbpFlag.TBPF_NOPROGRESS),
@@ -28,7 +28,7 @@ public enum TaskbarProgressbarType {
2828

2929
private final ITaskbarList3.TbpFlag bridjPair;
3030

31-
TaskbarProgressbarType(ITaskbarList3.TbpFlag bridjPair) {
31+
Type(ITaskbarList3.TbpFlag bridjPair) {
3232
this.bridjPair = bridjPair;
3333
}
3434

@@ -55,13 +55,13 @@ public ITaskbarList3.TbpFlag getBridjPair() {
5555
* @param type the type of the progress; must't be null
5656
* @throws NullPointerException if the type is null
5757
*/
58-
public abstract void showCustomProgress(long done, long max, TaskbarProgressbarType type);
58+
public abstract void showCustomProgress(long done, long max, Type type);
5959

6060
/**
6161
* Shows a 100% error progress
6262
*/
6363
public void showFullErrorProgress() {
64-
this.showCustomProgress(100, 100, TaskbarProgressbarType.ERROR);
64+
this.showCustomProgress(100, 100, Type.ERROR);
6565
}
6666

6767

@@ -119,17 +119,17 @@ public static void showIndeterminateProgress(Stage stage) {
119119
* Shows a custom progress on the taskbar.
120120
*
121121
* <p><br>
122-
* Actually calls the {@link TaskbarProgressbar#showCustomProgress(int, long, long, TaskbarProgressbarType)}
122+
* Actually calls the {@link TaskbarProgressbar#showCustomProgress(int, long, long, Type)}
123123
* method with the index of the stage.
124124
*
125125
* @param stage the javaFX stage to show the progress on; mustn't be null
126126
* @param done specifies the actual "done" value of the max value
127127
* @param max specifies the max, 100% value of the loading
128128
* @param type the type of the progress; mustn't be null
129129
* @throws NullPointerException if the stage or the type is null
130-
* @see TaskbarProgressbar#showCustomProgress(int, long, long, TaskbarProgressbarType)
130+
* @see TaskbarProgressbar#showCustomProgress(int, long, long, Type)
131131
*/
132-
public static void showCustomProgress(Stage stage, long done, long max, TaskbarProgressbarType type) {
132+
public static void showCustomProgress(Stage stage, long done, long max, Type type) {
133133
showCustomProgress(getIndexOfStage(stage), done, max, type);
134134
}
135135

@@ -141,7 +141,7 @@ public static void stopProgress(int windowIndex) {
141141
long hwndVal = getHWNDValueOf(windowIndex);
142142
progressbar.setHwnd(Pointer.pointerToAddress(hwndVal));
143143

144-
progressbar.getService().execute(() -> progressbar.getList().SetProgressState((Pointer) progressbar.getHwnd(), TaskbarProgressbarType.NO_PROGRESS.getBridjPair()));
144+
progressbar.getService().execute(() -> progressbar.getList().SetProgressState((Pointer) progressbar.getHwnd(), Type.NO_PROGRESS.getBridjPair()));
145145
}
146146

147147
@SuppressWarnings({"unchecked", "deprecation"})
@@ -151,11 +151,11 @@ public static void showIndeterminateProgress(int windowIndex) {
151151
long hwndVal = getHWNDValueOf(windowIndex);
152152
progressbar.setHwnd(Pointer.pointerToAddress(hwndVal));
153153

154-
progressbar.getService().execute(() -> progressbar.getList().SetProgressState((Pointer) progressbar.getHwnd(), TaskbarProgressbarType.INDETERMINATE.getBridjPair()));
154+
progressbar.getService().execute(() -> progressbar.getList().SetProgressState((Pointer) progressbar.getHwnd(), Type.INDETERMINATE.getBridjPair()));
155155
}
156156

157157
@SuppressWarnings({"unchecked", "deprecation"})
158-
public static void showCustomProgress(int windowIndex, long done, long endValue, TaskbarProgressbarType type) {
158+
public static void showCustomProgress(int windowIndex, long done, long endValue, Type type) {
159159
TaskbarProgressbarImpl progressbar = new TaskbarProgressbarImpl();
160160

161161
long hwndVal = getHWNDValueOf(windowIndex);
@@ -176,7 +176,7 @@ public static void showFullErrorProgress(int windowIndex) {
176176

177177
progressbar.getService().execute(() -> {
178178
progressbar.getList().SetProgressValue((Pointer) progressbar.getHwnd(), 100, 100);
179-
progressbar.getList().SetProgressState((Pointer) progressbar.getHwnd(), TaskbarProgressbarType.ERROR.getBridjPair());
179+
progressbar.getList().SetProgressState((Pointer) progressbar.getHwnd(), Type.ERROR.getBridjPair());
180180
});
181181
}
182182

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void stopProgress() {
6767
long hwndVal = com.sun.glass.ui.Window.getWindows().get(getIndexOfStage(stage)).getNativeWindow();
6868
hwnd = Pointer.pointerToAddress(hwndVal);
6969

70-
es.execute(() -> list.SetProgressState((Pointer) hwnd, TaskbarProgressbar.TaskbarProgressbarType.NO_PROGRESS.getBridjPair()));
70+
es.execute(() -> list.SetProgressState((Pointer) hwnd, Type.NO_PROGRESS.getBridjPair()));
7171
}
7272

7373
@Override
@@ -76,12 +76,12 @@ public void showIndeterminateProgress() {
7676
long hwndVal = com.sun.glass.ui.Window.getWindows().get(getIndexOfStage(stage)).getNativeWindow();
7777
hwnd = Pointer.pointerToAddress(hwndVal);
7878

79-
es.execute(() -> list.SetProgressState((Pointer) hwnd, TaskbarProgressbar.TaskbarProgressbarType.INDETERMINATE.getBridjPair()));
79+
es.execute(() -> list.SetProgressState((Pointer) hwnd, Type.INDETERMINATE.getBridjPair()));
8080
}
8181

8282
@Override
8383
@SuppressWarnings({"unchecked", "deprecation"})
84-
public void showCustomProgress(long startValue, long endValue, TaskbarProgressbar.TaskbarProgressbarType type) {
84+
public void showCustomProgress(long startValue, long endValue, Type type) {
8585
long hwndVal = com.sun.glass.ui.Window.getWindows().get(getIndexOfStage(stage)).getNativeWindow();
8686
hwnd = Pointer.pointerToAddress(hwndVal);
8787

0 commit comments

Comments
 (0)