Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
16   177   11   1.6
2   51   0.69   10
10     1.1  
1    
 
  FrameMatcher       Line # 31 16 0% 11 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jul 16, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.core.matcher;
17   
18    import static java.lang.String.valueOf;
19    import static org.fest.util.Strings.concat;
20   
21    import java.awt.Frame;
22    import java.util.regex.Pattern;
23   
24    import org.fest.swing.annotation.RunsInCurrentThread;
25   
26    /**
27    * Understands matching a <code>{@link Frame}</code> by type, name or title.
28    *
29    * @author Alex Ruiz
30    */
 
31    public final class FrameMatcher extends NamedComponentMatcherTemplate<Frame> {
32   
33    private Object title;
34   
35    /**
36    * Creates a new <code>{@link FrameMatcher}</code> that matches a <code>{@link Frame}</code> that:
37    * <ol>
38    * <li>has a matching name</li>
39    * <li>(optionally) has matching title</li>
40    * <li>(optionally) is showing on the screen</li>
41    * <p>
42    * The following code listing shows how to match a <code>{@link Frame}</code> by name and title:
43    * <pre>
44    * FrameMatcher m = {@link #withName(String) withName}("myApp").{@link #andTitle(String) andTitle}("My App");
45    * </pre>
46    * </p>
47    * <p>
48    * The following code listing shows how to match a <code>{@link Frame}</code>, that should be showing on the screen,
49    * by name and title:
50    * <pre>
51    * FrameMatcher m = {@link #withName(String) withName}("myApp").{@link #andTitle(String) andTitle}("My App").{@link #andShowing() andShowing}();
52    * </pre>
53    * </p>
54    * @param name the id to match.
55    * @return the created matcher.
56    */
 
57  12 toggle public static FrameMatcher withName(String name) {
58  12 return new FrameMatcher(name, ANY);
59    }
60   
61    /**
62    * Creates a new <code>{@link FrameMatcher}</code> that matches a <code>{@link Frame}</code> by its title.
63    * <p>
64    * The following code listing shows how to match a <code>{@link Frame}</code> by title:
65    * <pre>
66    * FrameMatcher m = {@link #withTitle(String) withTitle}("My App");
67    * </pre>
68    * </p>
69    * <p>
70    * The following code listing shows how to match a <code>{@link Frame}</code>, that should be showing on the screen,
71    * by title:
72    * <pre>
73    * FrameMatcher m = {@link #withTitle(String) withTitle}("My App").{@link #andShowing() andShowing}();
74    * </pre>
75    * </p>
76    * @param title the title to match. It can be a regular expression.
77    * @return the created matcher.
78    */
 
79  7 toggle public static FrameMatcher withTitle(String title) {
80  7 return new FrameMatcher(ANY, title);
81    }
82   
83    /**
84    * Creates a new <code>{@link FrameMatcher}</code> that matches a <code>{@link Frame}</code> by its title.
85    * <p>
86    * The following code listing shows how to match a <code>{@link Frame}</code> by title, using a regular expression
87    * matcher:
88    * <pre>
89    * FrameMatcher m = {@link #withTitle(Pattern) withTitle}(Pattern.compile("My.*"));
90    * </pre>
91    * </p>
92    * <p>
93    * The following code listing shows how to match a <code>{@link Frame}</code>, that should be showing on the screen,
94    * by title:
95    * <pre>
96    * FrameMatcher m = {@link #withTitle(Pattern) withTitle}(Pattern.compile("My.*")).{@link #andShowing() andShowing}();
97    * </pre>
98    * </p>
99    * @param titlePattern the title to match.
100    * @return the created matcher.
101    * @since 1.2
102    */
 
103  2 toggle public static FrameMatcher withTitle(Pattern titlePattern) {
104  2 return new FrameMatcher(ANY, titlePattern);
105    }
106   
107    /**
108    * Creates a new <code>{@link FrameMatcher}</code> that matches any <code>{@link Frame}</code>.
109    * @return the created matcher.
110    */
 
111  2 toggle public static FrameMatcher any() {
112  2 return new FrameMatcher(ANY, ANY);
113    }
114   
 
115  23 toggle private FrameMatcher(Object name, Object title) {
116  23 super(Frame.class, name);
117  23 this.title = title;
118    }
119   
120    /**
121    * Specifies the title to match. If this matcher was created using <code>{@link #withTitle(String)}</code> or
122    * <code>{@link FrameMatcher#withTitle(Pattern)}</code>, this method will simply update the title to match.
123    * @param newTitle the new title to match. It can be a regular expression.
124    * @return this matcher.
125    */
 
126  6 toggle public FrameMatcher andTitle(String newTitle) {
127  6 title = newTitle;
128  6 return this;
129    }
130   
131    /**
132    * Specifies the title to match. If this matcher was created using <code>{@link #withTitle(String)}</code> or
133    * <code>{@link FrameMatcher#withTitle(Pattern)}</code>, this method will simply update the title to match.
134    * @param titlePattern the regular expression pattern to match.
135    * @return this matcher.
136    * @since 1.2
137    */
 
138  4 toggle public FrameMatcher andTitle(Pattern titlePattern) {
139  4 title = titlePattern;
140  4 return this;
141    }
142   
143    /**
144    * Indicates that the <code>{@link Frame}</code> to match should be showing on the screen.
145    * @return this matcher.
146    */
 
147  5 toggle public FrameMatcher andShowing() {
148  5 requireShowing(true);
149  5 return this;
150    }
151   
152    /**
153    * Indicates whether the title of the given <code>{@link Frame}</code> is equal to the title in this matcher.
154    * <p>
155    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
156    * responsible for calling this method from the EDT.
157    * </p>
158    * @param frame the <code>Frame</code> to match.
159    * @return <code>true</code> if the title in the <code>Frame</code> is equal to the title in this matcher,
160    * <code>false</code> otherwise.
161    */
 
162  19 toggle @RunsInCurrentThread
163    protected boolean isMatching(Frame frame) {
164  5 if (!isNameMatching(frame.getName())) return false;
165  14 return arePropertyValuesMatching(title, frame.getTitle());
166    }
167   
 
168  1 toggle @Override public String toString() {
169  1 return concat(
170    getClass().getName(), "[",
171    "name=", quotedName(), ", ",
172    "title=", quoted(title), ", ",
173    "requireShowing=", valueOf(requireShowing()),
174    "]"
175    );
176    }
177    }