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

📄 messages.java

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

import org.uispec4j.utils.ArrayUtils;
import org.uispec4j.utils.ComponentUtils;

import java.awt.*;
import java.util.List;

class Messages {
  public static String computeAmbiguityMessage(Component[] matchingComponents, String type, String name) {
    String[] componentNames = new String[matchingComponents.length];
    for (int i = 0; i < matchingComponents.length; i++) {
      String displayedName = ComponentUtils.getDisplayedName(matchingComponents[i]);
      componentNames[i] = (displayedName == null || displayedName.length() == 0) ?
                          matchingComponents[i].getName() : displayedName;
    }
    return computeAmbiguityMessage(componentNames, type, name);
  }

  public static String computeAmbiguityMessage(String[] componentNames, String type, String name) {
    StringBuffer message = new StringBuffer("Several components");
    if (type != null) {
      message.append(" of type '").append(type).append("'");
    }
    if (name != null) {
      message.append(" match the pattern '").append(name).append("'");
    }
    else {
      message.append(" have been found");
    }
    message.append(" in this panel: [");
    for (int i = 0; i < componentNames.length; i++) {
      message.append(componentNames[i]);
      message.append((i < componentNames.length - 1) ? ',' : ']');
    }
    return message.toString();
  }

  public static String computeNotFoundMessage(String type, String name, List availableNames) {
    if (name != null) {
      return "Component '" + name + "' of type '" + type + "' not found" + getPostfix(availableNames);
    }
    if (type != null) {
      return "No component of type '" + type + "' found" + getPostfix(availableNames);
    }
    return "No component found";
  }

  private static String getPostfix(List availableNames) {
    if ((availableNames == null) || availableNames.isEmpty()) {
      return "";
    }
    return " - available names: " + ArrayUtils.toString(availableNames);
  }
}

⌨️ 快捷键说明

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