⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 desktop.java

📁 基于Junit的 功能和单元测试的的测试工具。只支持Swing.
💻 JAVA
字号:
package org.uispec4j;

import junit.framework.AssertionFailedError;
import org.uispec4j.assertion.Assertion;
import org.uispec4j.assertion.UISpecAssert;
import org.uispec4j.utils.Utils;

import javax.swing.*;
import java.awt.*;

/**
 * Wrapper for Multiple Desktop Interface (MDI) widgets implemented as JDesktopPane components.
 */
public class Desktop extends AbstractUIComponent {
  public static final String TYPE_NAME = "desktop";
  public static final Class[] SWING_CLASSES = {JDesktopPane.class};

  private final JDesktopPane jDesktopPane;

  public Desktop(JDesktopPane jDesktopPane) {
    this.jDesktopPane = jDesktopPane;
  }

  public Component getAwtComponent() {
    return jDesktopPane;
  }

  public String getDescriptionTypeName() {
    return "desktop";
  }

  /**
   * Returs all the internal windows contained in the desktop.
   */
  public Window[] getWindows() {
    JInternalFrame[] allFrames = jDesktopPane.getAllFrames();
    Window[] result = new Window[allFrames.length];
    for (int i = 0; i < allFrames.length; i++) {
      result[i] = new Window(allFrames[i]);
    }
    return result;
  }

  public Assertion containsWindow(final String title) {
    return new Assertion() {
      public void check() {
        JInternalFrame[] allFrames = jDesktopPane.getAllFrames();
        for (int i = 0; i < allFrames.length; i++) {
          if (Utils.equals(title, allFrames[i].getTitle())) {
            return;
          }
        }
        throw new AssertionFailedError("No window with title '" + title + "' found");
      }
    };
  }

  /**
   * Returns a window given its title, and waits if it is not available yet.
   * This method will fail after a given timeout if the window is not found.
   *
   * @see UISpec4J#setWindowInterceptionTimeLimit(long)
   */
  public Window getWindow(String title) throws ComponentAmbiguityException {
    InternalFrameIntercepted assertion = new InternalFrameIntercepted(title);
    UISpecAssert.waitUntil(assertion, UISpec4J.getWindowInterceptionTimeLimit());
    return assertion.getResult();
  }

  private class InternalFrameIntercepted extends Assertion {

    private String windowTitle;
    private Window result;

    public InternalFrameIntercepted(String windowTitle) {
      this.windowTitle = windowTitle;
    }

    public void check() throws Exception {
      Window[] windows = getWindows();
      for (int i = 0; i < windows.length; i++) {
        Window window = windows[i];
        if (windowTitle.equals(window.getTitle())) {
          if (result != null) {
            throw new ComponentAmbiguityException("There are several windows with title '" +
                                                  windowTitle + "'");
          }
          result = window;
        }
      }
      if (result == null) {
        throw new ItemNotFoundException("Window '" + windowTitle + "' not found");
      }
    }

    public Window getResult() {
      return result;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -