Package org.uispec4j.interception.toolkit

Source Code of org.uispec4j.interception.toolkit.UISpecDialogPeer

package org.uispec4j.interception.toolkit;

import org.uispec4j.Window;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

public class UISpecDialogPeer extends Empty.DialogPeer {
  private JDialog dialog;
  private boolean listenerRegistered;

  public UISpecDialogPeer(JDialog dialog) {
    this.dialog = dialog;
  }

  public void show() {
    try {
      UISpecDisplay.instance().assertAcceptsWindow(new Window(dialog));
    }
    catch (Error t) {
      if (SwingUtilities.isEventDispatchThread()) {
        dialog.setVisible(false);
        return;
      }
      else {
        throw t;
      }
    }
    if (!listenerRegistered) {
      dialog.addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent e) {
          try {
            UISpecDisplay.instance().showDialog(dialog);
          }
          catch (Throwable t) {
            throw new RuntimeException(t);
          }
        }
      });
      listenerRegistered = true;
    }
  }

  public Toolkit getToolkit() {
    return UISpecToolkit.instance();
  }
}
TOP

Related Classes of org.uispec4j.interception.toolkit.UISpecDialogPeer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.