forked from jasder/antlr
Add Utils.waitForClose
This commit is contained in:
parent
62531d2ea1
commit
6a5f609797
|
@ -30,6 +30,9 @@
|
|||
|
||||
package org.antlr.v4.runtime.misc;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
@ -82,4 +85,36 @@ public class Utils {
|
|||
w.write(content);
|
||||
w.close();
|
||||
}
|
||||
|
||||
public static void waitForClose(final Window window) throws InterruptedException {
|
||||
final Object lock = new Object();
|
||||
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (lock) {
|
||||
while (window.isVisible()) {
|
||||
try {
|
||||
lock.wait(500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
t.start();
|
||||
|
||||
window.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent arg0) {
|
||||
synchronized (lock) {
|
||||
window.setVisible(false);
|
||||
lock.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue