Add Utils.waitForClose

This commit is contained in:
Sam Harwell 2012-12-18 18:15:21 -06:00
parent 62531d2ea1
commit 6a5f609797
1 changed files with 35 additions and 0 deletions

View File

@ -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();
}
}