summaryrefslogtreecommitdiff
path: root/NET/worlds/console/BlockingDialog.java
blob: b32b5b8d1295f63d49449e558dd153a7de450d50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package NET.worlds.console;

import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class BlockingDialog extends Dialog implements ActionListener {
   private static final long serialVersionUID = 8379457384966170912L;
   boolean stillWaiting = true;

   public BlockingDialog(Frame parent, String title, boolean modal) {
      super(parent, title, modal);
      this.addWindowListener(new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent e) {
            BlockingDialog.this.finish();
         }
      });
   }

   @Override
   public void actionPerformed(ActionEvent e) {
      this.finish();
   }

   public void finish() {
      this.responded();
      this.setVisible(false);
   }

   public synchronized void waitForResponse() {
      try {
         while (this.stillWaiting) {
            this.wait();
         }
      } catch (Exception var2) {
      }
   }

   public synchronized void responded() {
      this.stillWaiting = false;
      this.notifyAll();
   }
}