6d98a5fc2455b116db0ef86aecdc74a4b6f8e23f
[debian/openrocket] / src / net / sf / openrocket / util / ConcurrentProgressMonitor.java
1 package net.sf.openrocket.util;
2
3 import java.awt.Component;
4
5 import javax.swing.ProgressMonitor;
6 import javax.swing.SwingUtilities;
7
8
9 /**
10  * A thread-safe <code>ProgressMonitor</code>.  This class may be instantiated
11  * and the method {@link #setProgress(int)} called safely from any thread.
12  * <p>
13  * Why the FSCK&!¤#&%¤ isn't the default API version thread-safe?!?!
14  * 
15  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
16  */
17 public class ConcurrentProgressMonitor extends ProgressMonitor {
18
19         public ConcurrentProgressMonitor(Component parentComponent, Object message,
20                         String note, int min, int max) {
21                 super(parentComponent, message, note, min, max);
22         }
23
24         @Override
25         public void setProgress(final int nv) {
26                 
27                 if (SwingUtilities.isEventDispatchThread()) {
28                         super.setProgress(nv);
29                 } else {
30                         
31                         SwingUtilities.invokeLater(new Runnable() {
32
33                                 @Override
34                                 public void run() {
35                                         ConcurrentProgressMonitor.super.setProgress(nv);
36                                 }
37                                 
38                         });
39                         
40                 }
41         }
42         
43         
44
45 }