01: package org.uispec4j.interception.toolkit;
02:
03: import junit.framework.AssertionFailedError;
04: import org.uispec4j.Window;
05:
06: import javax.swing.*;
07: import java.awt.*;
08: import java.awt.event.ComponentAdapter;
09: import java.awt.event.ComponentEvent;
10:
11: public class UISpecDialogPeer extends Empty.DialogPeer {
12: private JDialog dialog;
13: private boolean listenerRegistered;
14:
15: public UISpecDialogPeer(JDialog dialog) {
16: this .dialog = dialog;
17: }
18:
19: public void show() {
20: try {
21: UISpecDisplay.instance().assertAcceptsWindow(
22: new Window(dialog));
23: } catch (AssertionFailedError t) {
24: if (SwingUtilities.isEventDispatchThread()) {
25: dialog.setVisible(false);
26: return;
27: } else {
28: throw t;
29: }
30: }
31: if (!listenerRegistered) {
32: dialog.addComponentListener(new ComponentAdapter() {
33: public void componentShown(ComponentEvent e) {
34: try {
35: UISpecDisplay.instance().showDialog(dialog);
36: } catch (Throwable t) {
37: throw new RuntimeException(t);
38: }
39: }
40: });
41: listenerRegistered = true;
42: }
43: }
44:
45: public Toolkit getToolkit() {
46: return UISpecToolkit.instance();
47: }
48: }
|