01: package abbot.finder;
02:
03: import java.awt.Component;
04:
05: /** Provides methods for determining the best match among a group of matching
06: components.<p>
07: For use with implementations of {@link ComponentFinder}.
08: You can conveniently inline a custom matcher like so:<br>
09: <pre><code>
10: ComponentFinder finder = BasicFinder.getDefault();
11: ...
12: // Find the widest label with known text
13: JLabel label = (JLabel)finder.find(new MultiMatcher() {
14: public boolean matches(Component c) {
15: return c instanceof JLabel
16: && "OK".equals(((JLabel)c).getText());
17: }
18: public Component bestMatch(Component[] candidates)
19: throws MultipleComponentsFoundException {
20: Component biggest = candidates[0];
21: for (int i=1;i < candidates.length;i++) {
22: if (biggest.getWidth() < candidates[i].getWidth())
23: biggest = candidates[i];
24: }
25: return biggest;
26: }
27: });
28: </code></pre>
29: @see ComponentFinder
30: */
31: public interface MultiMatcher extends Matcher {
32: /** Returns the best match among all the given candidates, or throws an
33: exception if there is no best match.
34: */
35: Component bestMatch(Component[] candidates)
36: throws MultipleComponentsFoundException;
37: }
|