001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.progress;
003
004import java.util.concurrent.LinkedBlockingQueue;
005import java.util.concurrent.ThreadPoolExecutor;
006import java.util.concurrent.TimeUnit;
007
008import org.openstreetmap.josm.Main;
009
010/**
011 * Executor that displays the progress monitor to the user.
012 * 
013 * Similar to Executors.newSingleThreadExecutor(), but displays the
014 * progress monitor whenever a new task is executed.
015 */
016public class ProgressMonitorExecutor extends ThreadPoolExecutor {
017
018    public ProgressMonitorExecutor() {
019        super(1, 1, 0L, TimeUnit.MILLISECONDS,
020                new LinkedBlockingQueue<Runnable>());
021    }
022
023    @Override
024    public void execute(Runnable command) {
025        if (Main.currentProgressMonitor != null) {
026            //TODO show only if this can't be in background or better if always in background is not checked
027            Main.currentProgressMonitor.showForegroundDialog();
028        }
029        super.execute(command);
030    }
031
032}