| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.core; |
| 17 |
|
|
| 18 |
|
import static java.lang.String.valueOf; |
| 19 |
|
import static org.fest.util.Objects.areEqual; |
| 20 |
|
import static org.fest.util.Strings.*; |
| 21 |
|
|
| 22 |
|
import java.awt.Component; |
| 23 |
|
|
| 24 |
|
import javax.swing.JLabel; |
| 25 |
|
|
| 26 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
@link |
| 30 |
|
@link |
| 31 |
|
@see |
| 32 |
|
@see |
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 11 |
Complexity Density: 0.55 |
|
| 36 |
|
public class LabelMatcher extends AbstractComponentMatcher { |
| 37 |
|
|
| 38 |
|
private final String label; |
| 39 |
|
private final Class<? extends Component> type; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@link |
| 43 |
|
@param |
| 44 |
|
@throws |
| 45 |
|
@throws |
| 46 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 47 |
6
|
public LabelMatcher(String label) {... |
| 48 |
6
|
this(label, false); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@link |
| 53 |
|
@param |
| 54 |
|
@param |
| 55 |
|
@throws |
| 56 |
|
@throws |
| 57 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 58 |
13
|
public LabelMatcher(String label, boolean requireShowing) {... |
| 59 |
13
|
this(label, Component.class, requireShowing); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
@link |
| 64 |
|
@param |
| 65 |
|
@param |
| 66 |
|
@throws |
| 67 |
|
@throws |
| 68 |
|
@throws |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
1
|
public LabelMatcher(String label, Class<? extends Component> type) {... |
| 71 |
1
|
this(label, type, false); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@link |
| 76 |
|
@param |
| 77 |
|
@param |
| 78 |
|
@param |
| 79 |
|
@throws |
| 80 |
|
@throws |
| 81 |
|
@throws |
| 82 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 83 |
25
|
public LabelMatcher(String label, Class<? extends Component> type, boolean requireShowing) {... |
| 84 |
25
|
super(requireShowing); |
| 85 |
25
|
if (label == null) |
| 86 |
1
|
throw new NullPointerException("The text of the label associated to the component to find should not be null"); |
| 87 |
24
|
if (isEmpty(label)) |
| 88 |
1
|
throw new IllegalArgumentException("The text of the label associated to the component to find should not be empty"); |
| 89 |
1
|
if (type == null) throw new NullPointerException("The type of component to find should not be null"); |
| 90 |
22
|
this.label = label; |
| 91 |
22
|
this.type = type; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
@link |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
@link |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
@link |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
@return |
| 109 |
|
|
| 110 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 111 |
96
|
@RunsInCurrentThread... |
| 112 |
|
public boolean matches(Component c) { |
| 113 |
76
|
if (!(c instanceof JLabel)) return false; |
| 114 |
20
|
JLabel labelForComponent = (JLabel)c; |
| 115 |
10
|
if (!areEqual(labelForComponent.getText(), label)) return false; |
| 116 |
10
|
Component labeled = labelForComponent.getLabelFor(); |
| 117 |
10
|
return type.isInstance(labeled) && requireShowingMatches(labeled); |
| 118 |
|
} |
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
6
|
@Override public String toString() {... |
| 121 |
6
|
return concat( |
| 122 |
|
getClass().getName(), "[", |
| 123 |
|
"label=", quote(label), ", ", |
| 124 |
|
"type=", type.getName(), ", ", |
| 125 |
|
"requireShowing=", valueOf(requireShowing()), |
| 126 |
|
"]" |
| 127 |
|
); |
| 128 |
|
} |
| 129 |
|
} |