From 6a5f609797f33bdd2e629d4df8a621927e1736be Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 18 Dec 2012 18:15:21 -0600 Subject: [PATCH] Add Utils.waitForClose --- .../src/org/antlr/v4/runtime/misc/Utils.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/Utils.java b/runtime/Java/src/org/antlr/v4/runtime/misc/Utils.java index 352dad1a8..bd299cd73 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/Utils.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/Utils.java @@ -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(); + } }