| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package org.fest.swing.driver; |
| 16 |
|
|
| 17 |
|
import static org.fest.swing.driver.AbstractButtonTextQuery.textOf; |
| 18 |
|
import static org.fest.util.Objects.areEqual; |
| 19 |
|
import static org.fest.util.Strings.*; |
| 20 |
|
|
| 21 |
|
import java.awt.Component; |
| 22 |
|
|
| 23 |
|
import javax.swing.JMenuItem; |
| 24 |
|
import javax.swing.JPopupMenu; |
| 25 |
|
|
| 26 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 27 |
|
import org.fest.swing.core.ComponentMatcher; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
@link |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
@author |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 8 |
Complexity Density: 0.53 |
|
| 36 |
|
public class JMenuItemMatcher implements ComponentMatcher { |
| 37 |
|
|
| 38 |
|
private static final String SEPARATOR = "|"; |
| 39 |
|
|
| 40 |
|
private final String label; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@link |
| 44 |
|
@param |
| 45 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 46 |
7
|
public JMenuItemMatcher(String... path) {... |
| 47 |
7
|
this.label = join(path).with(SEPARATOR); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@link |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
@param |
| 58 |
|
@return |
| 59 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 60 |
45
|
@RunsInCurrentThread... |
| 61 |
|
public boolean matches(Component c) { |
| 62 |
32
|
if (!(c instanceof JMenuItem)) return false; |
| 63 |
13
|
JMenuItem menuItem = (JMenuItem) c; |
| 64 |
13
|
String text = menuItem.getText(); |
| 65 |
13
|
return areEqual(label, text) || areEqual(label, pathOf(menuItem)); |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 68 |
19
|
@RunsInCurrentThread... |
| 69 |
|
private String pathOf(JMenuItem menuItem) { |
| 70 |
19
|
Component parent = parentOrInvokerOf(menuItem); |
| 71 |
19
|
if (parent instanceof JMenuItem) |
| 72 |
7
|
return concat(pathOf((JMenuItem)parent), SEPARATOR, textOf(menuItem)); |
| 73 |
12
|
return textOf(menuItem); |
| 74 |
|
} |
| 75 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 76 |
19
|
@RunsInCurrentThread... |
| 77 |
|
private Component parentOrInvokerOf(JMenuItem menuItem) { |
| 78 |
19
|
Component parent = menuItem.getParent(); |
| 79 |
19
|
if (parent instanceof JPopupMenu) |
| 80 |
10
|
parent = ((JPopupMenu)parent).getInvoker(); |
| 81 |
19
|
return parent; |
| 82 |
|
} |
| 83 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
2
|
@Override public String toString() {... |
| 85 |
2
|
return concat(getClass().getName(), "[", "label=", quote(label), "]"); |
| 86 |
|
} |
| 87 |
|
} |