|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JLabelFinder.java | - | 72.7% | 83.3% | 76.5% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit.finder;
|
|
| 2 |
|
|
| 3 |
import java.awt.Component;
|
|
| 4 |
|
|
| 5 |
import javax.swing.JLabel;
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
/**
|
|
| 9 |
* Class for checking if the component being searched for has been found
|
|
| 10 |
* The pattern syntax can be found at the Jakarta RegExp API Documentation in {@link org.apache.regexp.RE}.
|
|
| 11 |
*
|
|
| 12 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
| 13 |
*/
|
|
| 14 |
public class JLabelFinder extends Finder { |
|
| 15 |
/**
|
|
| 16 |
* The text of the component.
|
|
| 17 |
*/
|
|
| 18 |
private String m_text;
|
|
| 19 |
|
|
| 20 |
/**
|
|
| 21 |
* A boolean specifying whether the filtration is case insensitive.
|
|
| 22 |
*/
|
|
| 23 |
private boolean m_caseIndependent = false; |
|
| 24 |
|
|
| 25 |
/**
|
|
| 26 |
* Constructor accepting all arguments needed to filter component.
|
|
| 27 |
*
|
|
| 28 |
* @param text The desired pattern for the text of the component.
|
|
| 29 |
*/
|
|
| 30 | 7 |
public JLabelFinder(final String text) {
|
| 31 | 7 |
this(text, false); |
| 32 |
} |
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* Constructor accepting all arguments needed to filter component.
|
|
| 36 |
*
|
|
| 37 |
* @param text The desired pattern for the text of the component.
|
|
| 38 |
* @param caseIndependent Whether the match should be case independent
|
|
| 39 |
* (true) or not (false)
|
|
| 40 |
*/
|
|
| 41 | 11 |
public JLabelFinder(final String text, final boolean caseIndependent) { |
| 42 | 11 |
m_text = text; |
| 43 | 11 |
this.m_caseIndependent = caseIndependent;
|
| 44 | 11 |
createPatternMatcher(m_text, caseIndependent); |
| 45 |
} |
|
| 46 |
|
|
| 47 |
|
|
| 48 |
/**
|
|
| 49 |
* Set the finder into a case independent mode.
|
|
| 50 |
* @param ignoreCase true if case should be ignored.
|
|
| 51 |
*/
|
|
| 52 | 0 |
public void setCaseIndependent(final boolean ignoreCase) { |
| 53 | 0 |
super.setCaseIndependent(ignoreCase);
|
| 54 | 0 |
m_caseIndependent = ignoreCase; |
| 55 | 0 |
createPatternMatcher(m_text, m_caseIndependent); |
| 56 |
} |
|
| 57 |
|
|
| 58 |
/**
|
|
| 59 |
* Set the label text to be matched.
|
|
| 60 |
* @param text Text to be matched.
|
|
| 61 |
*/
|
|
| 62 | 1 |
public final void setText(final String text) { |
| 63 | 1 |
m_text = text; |
| 64 | 1 |
createPatternMatcher(m_text, m_caseIndependent); |
| 65 |
} |
|
| 66 |
|
|
| 67 |
/**
|
|
| 68 |
* Get the label text to be matched.
|
|
| 69 |
* @return label text to be matched.
|
|
| 70 |
*/
|
|
| 71 | 2 |
public final String getText() {
|
| 72 | 2 |
return m_text;
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/**
|
|
| 76 |
* Method that returns true if the given component matches the search
|
|
| 77 |
* criteria.
|
|
| 78 |
*
|
|
| 79 |
* @param comp The component to test
|
|
| 80 |
* @return true if this component is a match
|
|
| 81 |
*/
|
|
| 82 | 179 |
public boolean testComponent(final Component comp) { |
| 83 | 179 |
return ((comp != null) && isValidForProcessing(comp, JLabel.class) |
| 84 |
&& evaluate( |
|
| 85 |
((JLabel) comp).getText(), |
|
| 86 |
m_text)); |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
|
|
||||||||||