Skip to content

Commit be67962

Browse files
committed
Create a Std output progress listener
It's nice to have a simple default, instead of always creating your own
1 parent c7f3a94 commit be67962

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎imagej/imagej-ops2-tutorial/src/main/java/net/imagej/ops2/tutorial/ReportingProgress.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.scijava.ops.spi.OpField;
3838
import org.scijava.progress.Progress;
3939
import org.scijava.progress.ProgressListener;
40+
import org.scijava.progress.StandardOutputProgressLogger;
4041
import org.scijava.types.Nil;
4142

4243
/**
@@ -116,11 +117,9 @@ public static void main(String... args) {
116117
OpEnvironment ops = OpEnvironment.getEnvironment();
117118

118119
// ProgressListeners consume task updates.
119-
// This ProgressListener simply prints out the status of the Op
120-
// to the console, but we could print out something else,
121-
// or pass this information somewhere else.
122-
ProgressListener l = task -> //
123-
System.out.printf("Progress of %s: %.2f\n", task.description(), task.progress());
120+
// This ProgressListener simply logs to standard output, but we could print
121+
// out something else, or pass this information somewhere else.
122+
ProgressListener l = new StandardOutputProgressLogger();
124123
// To listen to Op progress updates, the ProgressListener must be registered
125124
// through the Progress API. To listen to all Op executions, use the
126125
// following call:

‎scijava/scijava-progress/pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
<allowedDuplicateClasses>${scijava-progress.allowedDuplicateClasses}</allowedDuplicateClasses>
106106
</properties>
107107
<dependencies>
108-
<!-- SciJava dependencies -->
109108
<!-- Test scope dependencies -->
110109
<dependency>
111110
<groupId>org.junit.jupiter</groupId>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
package org.scijava.progress;
3+
4+
/**
5+
* Simple {@link ProgressListener} logging updates to standard output.
6+
*
7+
* @author Gabriel Selzer
8+
*/
9+
public class StandardOutputProgressLogger implements ProgressListener {
10+
11+
@Override
12+
public void acknowledgeUpdate(Task task) {
13+
if (task.isComplete()) {
14+
System.out.printf("Progress of %s: Complete\n", task.description());
15+
}
16+
else {
17+
System.out.printf( //
18+
"Progress of %s: %.2f\n", //
19+
task.description(), //
20+
task.progress() //
21+
);
22+
}
23+
}
24+
}

‎scijava/scijava-progress/src/test/java/org/scijava/progress/DefaultProgressTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ public void testGlobalProgressListener() {
201201
}
202202

203203
/**
204-
* Test that {@link ProgressListener}s added at a global level can listen to a
205-
* progressible object without being explicitly linked
204+
* Test that {@link ProgressListener}s added at a global level can determine
205+
* whether to listen to a {@link Task} by looking at its description.
206206
*/
207207
@Test
208208
public void testProgressListenerIdentifiers() {

0 commit comments

Comments
 (0)