1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.progress;
|
---|
3 |
|
---|
4 | import java.util.concurrent.LinkedBlockingQueue;
|
---|
5 | import java.util.concurrent.ThreadPoolExecutor;
|
---|
6 | import java.util.concurrent.TimeUnit;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.tools.Utils;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Executor that displays the progress monitor to the user.
|
---|
13 | *
|
---|
14 | * Similar to Executors.newSingleThreadExecutor(), but displays the
|
---|
15 | * progress monitor whenever a new task is executed.
|
---|
16 | */
|
---|
17 | public class ProgressMonitorExecutor extends ThreadPoolExecutor {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Creates a new {@code ProgressMonitorExecutor}
|
---|
21 | * @param nameFormat see {@link Utils#newThreadFactory(String, int)}
|
---|
22 | * @param threadPriority see {@link Utils#newThreadFactory(String, int)}
|
---|
23 | */
|
---|
24 | public ProgressMonitorExecutor(final String nameFormat, final int threadPriority) {
|
---|
25 | super(1, 1, 0L, TimeUnit.MILLISECONDS,
|
---|
26 | new LinkedBlockingQueue<Runnable>(),
|
---|
27 | Utils.newThreadFactory(nameFormat, threadPriority));
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void execute(Runnable command) {
|
---|
32 | if (Main.currentProgressMonitor != null) {
|
---|
33 | //TODO show only if this can't be in background or better if always in background is not checked
|
---|
34 | Main.currentProgressMonitor.showForegroundDialog();
|
---|
35 | }
|
---|
36 | super.execute(command);
|
---|
37 | }
|
---|
38 |
|
---|
39 | }
|
---|