01: package abbot.finder.matchers;
02:
03: import java.awt.Component;
04: import abbot.util.AWT;
05:
06: /** Provides matching of Components by component name. */
07: public class NameMatcher extends AbstractMatcher {
08: private String name;
09:
10: /** Construct a matcher that will match any component that has
11: explicitly been assigned the given <code>name</code>. Auto-generated
12: names (e.g. <code>win0</code>, <code>frame3</code>, etc. for AWT
13: (native) based components will not match.
14: */
15: public NameMatcher(String name) {
16: this .name = name;
17: }
18:
19: /** @return whether the given component has been explicitly assigned the
20: name given in the constructor.
21: */
22: public boolean matches(Component c) {
23: String cname = c.getName();
24: if (name == null)
25: return cname == null || AWT.hasDefaultName(c);
26: return stringsMatch(name, cname);
27: }
28:
29: public String toString() {
30: return "Name matcher (" + name + ")";
31: }
32: }
|