create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / util / ConcurrentProgressMonitor.java
1 package net.sf.openrocket.gui.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         @Override
44         public void close() {
45                 if (SwingUtilities.isEventDispatchThread()) {
46                         super.close();
47                 } else {
48                         
49                         SwingUtilities.invokeLater(new Runnable() {
50
51                                 @Override
52                                 public void run() {
53                                         ConcurrentProgressMonitor.super.close();
54                                 }
55                                 
56                         });
57                 }
58         }
59
60
61 }