001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit https://imagingbook.com for additional details. 008 ******************************************************************************/ 009package imagingbook.common.ij; 010 011import ij.IJ; 012import imagingbook.common.util.progress.ProgressMonitor; 013import imagingbook.common.util.progress.ProgressReporter; 014 015/** 016 * Implementation of {@link ProgressMonitor} which periodically polls the completion state of the associated target task 017 * ({@link ProgressReporter}) and sends this information to ImageJ's progress bar (if ImageJ is running). 018 * 019 * @author WB 020 * @version 2022/09/07 021 * @see ProgressReporter 022 * @see ProgressMonitor 023 */ 024public class IjProgressBarMonitor extends ProgressMonitor { 025 026 /** 027 * Constructor. 028 * @param target the target task ({@link ProgressReporter}) to be monitored 029 */ 030 public IjProgressBarMonitor(ProgressReporter target) { 031 super(target); 032 } 033 034 @Override 035 public void handleProgress(double progress, long nanoTime) { 036 if (IJ.getInstance() != null) { 037 IJ.showProgress(progress); 038 } 039 } 040 041 @Override 042 public void close() { 043 super.close(); 044 IJ.showProgress(1); 045 } 046 047}