|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractButtonFinder.java | - | 78.9% | 90.9% | 83.3% |
|
1 |
package junit.extensions.jfcunit.finder;
|
|
2 |
|
|
3 |
import java.awt.Component;
|
|
4 |
|
|
5 |
import javax.swing.AbstractButton;
|
|
6 |
import javax.swing.Icon;
|
|
7 |
|
|
8 |
|
|
9 |
/**
|
|
10 |
* Class for checking if the ({@link javax.swing.AbstractButton}) component being searched for has been found.
|
|
11 |
* The pattern syntax can be found at the Jakarta RegExp API Documentation in {@link org.apache.regexp.RE}.
|
|
12 |
* This class delegates the matching of the Icon to an instance of {@link junit.extensions.jfcunit.finder.IconMatcher}
|
|
13 |
*
|
|
14 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
15 |
*/
|
|
16 |
public class AbstractButtonFinder extends Finder { |
|
17 |
/**
|
|
18 |
* The matcher for the icon of the {@link javax.swing.AbstractButton} component.
|
|
19 |
*/
|
|
20 |
private IconMatcher m_iconMatcher;
|
|
21 |
|
|
22 |
/**
|
|
23 |
* The text of the {@link javax.swing.AbstractButton} component.
|
|
24 |
*/
|
|
25 |
private String m_label;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* A boolean specifying whether the filtration is case insensitive.
|
|
29 |
*/
|
|
30 |
private boolean m_caseIndependent = false; |
|
31 |
|
|
32 |
/**
|
|
33 |
* Constructor accepting all arguments needed to filter the component.
|
|
34 |
*
|
|
35 |
* @param text The desired pattern for the text of the component.
|
|
36 |
*/
|
|
37 | 24 |
public AbstractButtonFinder(final String text) {
|
38 | 24 |
this(text, null, false); |
39 |
} |
|
40 |
|
|
41 |
/**
|
|
42 |
* Constructor accepting all arguments needed to filter the component.
|
|
43 |
*
|
|
44 |
* @param text The desired pattern for the text of the component.
|
|
45 |
* @param caseIndependent Whether the match should be case independent (true) or not (false).
|
|
46 |
*/
|
|
47 | 1 |
public AbstractButtonFinder(final String text, final boolean caseIndependent) { |
48 | 1 |
this(text, null, caseIndependent); |
49 |
} |
|
50 |
|
|
51 |
/**
|
|
52 |
* Constructor accepting all arguments needed to filter the component.
|
|
53 |
*
|
|
54 |
* @param icon The desired pattern for the icon of the component.
|
|
55 |
*/
|
|
56 | 2 |
public AbstractButtonFinder(final Icon icon) {
|
57 | 2 |
this(null, icon, false); |
58 |
} |
|
59 |
|
|
60 |
/**
|
|
61 |
* Constructor accepting all arguments needed to filter the component.
|
|
62 |
*
|
|
63 |
* @param str The desired pattern for the text of the component.
|
|
64 |
* @param icon The desired pattern for the icon of the component.
|
|
65 |
*/
|
|
66 | 8 |
public AbstractButtonFinder(final String str, final Icon icon) {
|
67 | 8 |
this(str, icon, false); |
68 |
} |
|
69 |
|
|
70 |
/**
|
|
71 |
* Constructor accepting all arguments needed to filter the component.
|
|
72 |
*
|
|
73 |
* @param str The desired pattern for the text of the component.
|
|
74 |
* @param icon The desired pattern for the icon of the component.
|
|
75 |
* @param caseIndependent Whether the match should be case independent (true) or not (false)
|
|
76 |
*/
|
|
77 | 44 |
public AbstractButtonFinder(final String str, final Icon icon,
|
78 |
final boolean caseIndependent) {
|
|
79 | 44 |
setText(str); |
80 | 44 |
setIcon(icon); |
81 |
|
|
82 | 44 |
this.m_caseIndependent = caseIndependent;
|
83 | 44 |
recreatePatternMatcher(m_label, caseIndependent); |
84 |
} |
|
85 |
|
|
86 |
/**
|
|
87 |
* Set the text of the button to be found.
|
|
88 |
* @param text Text of the button.
|
|
89 |
*/
|
|
90 | 45 |
public final void setText(final String text) { |
91 | 45 |
m_label = text; |
92 | 45 |
recreatePatternMatcher(m_label, m_caseIndependent); |
93 |
} |
|
94 |
|
|
95 |
/**
|
|
96 |
* Set the finder into a case independent mode.
|
|
97 |
* @param ignoreCase true if case should be ignored.
|
|
98 |
*/
|
|
99 | 0 |
public void setCaseIndependent(final boolean ignoreCase) { |
100 | 0 |
super.setCaseIndependent(ignoreCase);
|
101 | 0 |
m_caseIndependent = ignoreCase; |
102 | 0 |
recreatePatternMatcher(m_label, m_caseIndependent); |
103 |
} |
|
104 |
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Get the text of the label to be matched.
|
|
108 |
* @return String text of the label.
|
|
109 |
*/
|
|
110 | 2 |
public final String getText() {
|
111 | 2 |
return m_label;
|
112 |
} |
|
113 |
|
|
114 |
/**
|
|
115 |
* Set the icon to be matched.
|
|
116 |
* @param icon Icon to be matched.
|
|
117 |
*/
|
|
118 | 45 |
public final void setIcon(final Icon icon) { |
119 | 45 |
try {
|
120 | 45 |
m_iconMatcher = new IconMatcher(icon);
|
121 |
} catch (InterruptedException ex) {
|
|
122 | 0 |
m_iconMatcher = null;
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
/**
|
|
127 |
* Get the icon to be matched.
|
|
128 |
* @return Iocn to be matched.
|
|
129 |
*/
|
|
130 | 2 |
public final Icon getIcon() {
|
131 | 2 |
return m_iconMatcher.getIcon();
|
132 |
} |
|
133 |
|
|
134 |
/**
|
|
135 |
* Method that returns true if the given component matches the search
|
|
136 |
* criteria.
|
|
137 |
*
|
|
138 |
* @param comp The component to test.
|
|
139 |
* @return true if this component is a match.
|
|
140 |
*/
|
|
141 | 354 |
public boolean testComponent(final Component comp) { |
142 | 354 |
return ((comp != null) |
143 |
&& isValidForProcessing(comp, AbstractButton.class)
|
|
144 |
&& ((m_label == null)
|
|
145 |
|| evaluate( |
|
146 |
((AbstractButton) comp).getText(), |
|
147 |
m_label)) |
|
148 |
&& m_iconMatcher.matches(((AbstractButton) comp).getIcon())); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|