01: package org.uispec4j.finder;
02:
03: import org.uispec4j.utils.ArrayUtils;
04: import org.uispec4j.utils.ComponentUtils;
05:
06: import java.awt.*;
07: import java.util.List;
08:
09: class Messages {
10: public static String computeAmbiguityMessage(
11: Component[] matchingComponents, String type, String name) {
12: String[] componentNames = new String[matchingComponents.length];
13: for (int i = 0; i < matchingComponents.length; i++) {
14: String displayedName = ComponentUtils
15: .getDisplayedName(matchingComponents[i]);
16: componentNames[i] = (displayedName == null || displayedName
17: .length() == 0) ? matchingComponents[i].getName()
18: : displayedName;
19: }
20: return computeAmbiguityMessage(componentNames, type, name);
21: }
22:
23: public static String computeAmbiguityMessage(
24: String[] componentNames, String type, String name) {
25: StringBuffer message = new StringBuffer("Several components");
26: if (type != null) {
27: message.append(" of type '").append(type).append("'");
28: }
29: if (name != null) {
30: message.append(" match the pattern '").append(name).append(
31: "'");
32: } else {
33: message.append(" have been found");
34: }
35: message.append(" in this panel: [");
36: for (int i = 0; i < componentNames.length; i++) {
37: message.append(componentNames[i]);
38: message.append((i < componentNames.length - 1) ? ',' : ']');
39: }
40: return message.toString();
41: }
42:
43: public static String computeNotFoundMessage(String type,
44: String name, List availableNames) {
45: if (name != null) {
46: return "Component '" + name + "' of type '" + type
47: + "' not found" + getPostfix(availableNames);
48: }
49: if (type != null) {
50: return "No component of type '" + type + "' found"
51: + getPostfix(availableNames);
52: }
53: return "No component found";
54: }
55:
56: private static String getPostfix(List availableNames) {
57: if ((availableNames == null) || availableNames.isEmpty()) {
58: return "";
59: }
60: return " - available names: "
61: + ArrayUtils.toString(availableNames);
62: }
63: }
|