-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from melissalinkert/progress-api
Add progress API
- Loading branch information
Showing
6 changed files
with
310 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/com/glencoesoftware/bioformats2raw/IProgressListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2022 Glencoe Software, Inc. All rights reserved. | ||
* | ||
* This software is distributed under the terms described by the LICENSE.txt | ||
* file you can find at the root of the distribution bundle. If the file is | ||
* missing please request a copy by contacting info@glencoesoftware.com | ||
*/ | ||
package com.glencoesoftware.bioformats2raw; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface IProgressListener extends EventListener { | ||
|
||
/** | ||
* Indicates the beginning of processing a particular series. | ||
* | ||
* @param series the series index being processed | ||
*/ | ||
void notifySeriesStart(int series); | ||
|
||
/** | ||
* Indicates the end of processing a particular series. | ||
* | ||
* @param series the series index being processed | ||
*/ | ||
void notifySeriesEnd(int series); | ||
|
||
/** | ||
* Indicates the beginning of processing a particular resolution. | ||
* | ||
* @param resolution the resolution index being processed | ||
* @param tileCount the total number of tiles in this resolution | ||
*/ | ||
void notifyResolutionStart(int resolution, int tileCount); | ||
|
||
/** | ||
* Indicates the end of processing a particular resolution. | ||
* | ||
* @param resolution the resolution index being processed | ||
*/ | ||
void notifyResolutionEnd(int resolution); | ||
|
||
/** | ||
* Indicates that the given chunk is about to be processed. | ||
* | ||
* @param plane plane index | ||
* @param xx X coordinate | ||
* @param yy Y coordinate | ||
* @param zz Z coordinate | ||
*/ | ||
void notifyChunkStart(int plane, int xx, int yy, int zz); | ||
|
||
/** | ||
* Indicates that the given chunk has been processed. | ||
* | ||
* @param plane plane index | ||
* @param xx X coordinate | ||
* @param yy Y coordinate | ||
* @param zz Z coordinate | ||
*/ | ||
void notifyChunkEnd(int plane, int xx, int yy, int zz); | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/glencoesoftware/bioformats2raw/NoOpProgressListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) 2022 Glencoe Software, Inc. All rights reserved. | ||
* | ||
* This software is distributed under the terms described by the LICENSE.txt | ||
* file you can find at the root of the distribution bundle. If the file is | ||
* missing please request a copy by contacting info@glencoesoftware.com | ||
*/ | ||
package com.glencoesoftware.bioformats2raw; | ||
|
||
public class NoOpProgressListener implements IProgressListener { | ||
|
||
@Override | ||
public void notifySeriesStart(int series) { | ||
} | ||
|
||
@Override | ||
public void notifySeriesEnd(int series) { | ||
} | ||
|
||
@Override | ||
public void notifyResolutionStart(int resolution, int tileCount) { | ||
} | ||
|
||
@Override | ||
public void notifyResolutionEnd(int resolution) { | ||
} | ||
|
||
@Override | ||
public void notifyChunkStart(int plane, int xx, int yy, int zz) { | ||
} | ||
|
||
@Override | ||
public void notifyChunkEnd(int plane, int xx, int yy, int zz) { | ||
} | ||
|
||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/glencoesoftware/bioformats2raw/ProgressBarListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright (c) 2022 Glencoe Software, Inc. All rights reserved. | ||
* | ||
* This software is distributed under the terms described by the LICENSE.txt | ||
* file you can find at the root of the distribution bundle. If the file is | ||
* missing please request a copy by contacting info@glencoesoftware.com | ||
*/ | ||
package com.glencoesoftware.bioformats2raw; | ||
|
||
import me.tongfei.progressbar.DelegatingProgressBarConsumer; | ||
import me.tongfei.progressbar.ProgressBar; | ||
import me.tongfei.progressbar.ProgressBarBuilder; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ProgressBarListener implements IProgressListener { | ||
|
||
// not a typo - the progress bar consumes Converter's logging output | ||
private static final Logger LOGGER = LoggerFactory.getLogger(Converter.class); | ||
|
||
private String logLevel; | ||
private ProgressBar pb; | ||
private int currentSeries = -1; | ||
|
||
/** | ||
* Create a new progress listener that displays a progress bar. | ||
* | ||
* @param level logging level | ||
*/ | ||
public ProgressBarListener(String level) { | ||
logLevel = level; | ||
} | ||
|
||
|
||
@Override | ||
public void notifySeriesStart(int series) { | ||
currentSeries = series; | ||
} | ||
|
||
@Override | ||
public void notifySeriesEnd(int series) { | ||
} | ||
|
||
@Override | ||
public void notifyResolutionStart(int resolution, int tileCount) { | ||
ProgressBarBuilder builder = new ProgressBarBuilder() | ||
.setInitialMax(tileCount) | ||
.setTaskName(String.format("[%d/%d]", currentSeries, resolution)); | ||
|
||
if (!(logLevel.equals("OFF") || | ||
logLevel.equals("ERROR") || | ||
logLevel.equals("WARN"))) | ||
{ | ||
builder.setConsumer(new DelegatingProgressBarConsumer(LOGGER::trace)); | ||
} | ||
pb = builder.build(); | ||
} | ||
|
||
@Override | ||
public void notifyChunkStart(int plane, int xx, int yy, int zz) { | ||
// intentional no-op | ||
} | ||
|
||
@Override | ||
public void notifyChunkEnd(int plane, int xx, int yy, int zz) { | ||
if (pb != null) { | ||
pb.step(); | ||
} | ||
} | ||
|
||
@Override | ||
public void notifyResolutionEnd(int resolution) { | ||
if (pb != null) { | ||
pb.close(); | ||
pb = null; | ||
} | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/glencoesoftware/bioformats2raw/test/TestProgressListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright (c) 2022 Glencoe Software, Inc. All rights reserved. | ||
* | ||
* This software is distributed under the terms described by the LICENSE.txt | ||
* file you can find at the root of the distribution bundle. If the file is | ||
* missing please request a copy by contacting info@glencoesoftware.com | ||
*/ | ||
package com.glencoesoftware.bioformats2raw.test; | ||
|
||
import com.glencoesoftware.bioformats2raw.IProgressListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestProgressListener implements IProgressListener { | ||
|
||
private List<Integer> finishedResolutions = new ArrayList<Integer>(); | ||
private int startedTiles = 0; | ||
private int completedTiles = 0; | ||
private int expectedTileCount = 0; | ||
|
||
@Override | ||
public void notifySeriesStart(int series) { | ||
} | ||
|
||
@Override | ||
public void notifySeriesEnd(int series) { | ||
} | ||
|
||
@Override | ||
public void notifyResolutionStart(int resolution, int tileCount) { | ||
expectedTileCount = tileCount; | ||
} | ||
|
||
@Override | ||
public void notifyChunkStart(int plane, int xx, int yy, int zz) { | ||
synchronized (this) { | ||
startedTiles++; | ||
} | ||
} | ||
|
||
@Override | ||
public void notifyChunkEnd(int plane, int xx, int yy, int zz) { | ||
synchronized (this) { | ||
completedTiles++; | ||
} | ||
} | ||
|
||
@Override | ||
public void notifyResolutionEnd(int resolution) { | ||
if (startedTiles == completedTiles && completedTiles == expectedTileCount) { | ||
finishedResolutions.add(completedTiles); | ||
} | ||
completedTiles = 0; | ||
startedTiles = 0; | ||
} | ||
|
||
/** | ||
* Get the recorded tile counts for each completed resolution. | ||
* | ||
* @return an array with one element per resolution | ||
*/ | ||
public Integer[] getTileCounts() { | ||
return finishedResolutions.toArray(new Integer[finishedResolutions.size()]); | ||
} | ||
|
||
} |
Oops, something went wrong.