imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
16 stars 25 forks source link

Adds a clickable swing task monitor progress bar to imagej legacy ui #274

Closed NicoKiaru closed 2 years ago

NicoKiaru commented 2 years ago
NicoKiaru commented 2 years ago

This PR depends on a snapshot version of scijava-ui-swing and explicitely overrides scijava-common for the moment,

To test it, here are two simple groovy scripts:

#@TaskService taskService

def task = taskService.createTask("Task 0");
task.setProgressMaximum(100)
task.run(() -> {
    try {
        Thread.sleep(2000)
        task.setProgressValue(20)
        Thread.sleep(2000)
        task.setProgressValue(40)
        Thread.sleep(2000)
        task.setProgressValue(60)
        Thread.sleep(2000)
        task.setProgressValue(80)
        Thread.sleep(2000)
        IJ.log('Done')
    } catch (InterruptedException e) {
        IJ.log(task.getCancelReason())
        IJ.log('Interrupted')
    }
})

try {
    task.waitFor() // If you want to wait for the end of the task, will return if cancelled
} catch (Exception e) {

}

IJ.log("Task "+task.getName()+" cancelled ? "+task.isCanceled())

import ij.IJ

And

#@TaskService taskService
#@File file

def task = taskService.createTask("Task 0");
task.setProgressMaximum(100)
task.start()
def isCancelled = false

task.setCancelCallBack(() -> {
    IJ.log('User interrupted')
    isCancelled = true
})

Thread.sleep(2000)
task.setProgressValue(20)
Thread.sleep(2000)
task.setProgressValue(40)
Thread.sleep(2000)

if (isCancelled) {
    task.finish()
} else {
    task.setProgressValue(60)
    Thread.sleep(2000)
    task.setProgressValue(80)
    Thread.sleep(2000)
    IJ.log('Done')
    task.finish()
}

IJ.log("Task cancelled ? "+task.isCanceled())

import ij.IJ

The modification of the batch processor comes in a separate and independent PR

imagesc-bot commented 2 years ago

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/demo-and-proposal-new-progress-bars-for-fiji/64956/6