1 package org.glassbox.widgets;
2
3 import java.awt.event.ActionEvent;
4 import javax.swing.*;
5
6 /***
7 An action which can be used to notify a thread waiting in an Object's wait() method.
8 */
9 public class NotifyAction extends AbstractAction {
10 private Object _wait;
11
12 public NotifyAction() {
13 super();
14 _wait = new Object();
15 }
16
17 public NotifyAction(String name) {
18 super(name);
19 _wait = new Object();
20 }
21
22 public NotifyAction(String name, Icon icon) {
23 super(name, icon);
24 _wait = new Object();
25 }
26
27 public void actionPerformed(ActionEvent e) {
28 synchronized (_wait) {
29 _wait.notify();
30 }
31 }
32
33 public void waitForAction() throws InterruptedException {
34 synchronized (_wait) {
35 _wait.wait();
36 }
37 }
38 }