| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.driver; |
| 17 |
|
|
| 18 |
|
import static java.util.Collections.sort; |
| 19 |
|
import static org.fest.swing.driver.JListCellBoundsQuery.cellBounds; |
| 20 |
|
import static org.fest.swing.driver.JListCellCenterQuery.cellCenter; |
| 21 |
|
import static org.fest.swing.edt.GuiActionRunner.execute; |
| 22 |
|
|
| 23 |
|
import java.awt.Point; |
| 24 |
|
import java.util.*; |
| 25 |
|
|
| 26 |
|
import javax.swing.JList; |
| 27 |
|
|
| 28 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 29 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 30 |
|
import org.fest.swing.cell.JListCellReader; |
| 31 |
|
import org.fest.swing.edt.GuiQuery; |
| 32 |
|
import org.fest.swing.util.StringTextMatcher; |
| 33 |
|
import org.fest.swing.util.TextMatcher; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@link |
| 37 |
|
|
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (44) |
Complexity: 13 |
Complexity Density: 0.52 |
|
| 40 |
|
final class JListMatchingItemQuery { |
| 41 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 42 |
1
|
@RunsInEDT... |
| 43 |
|
static Point centerOfMatchingItemCell(final JList list, final String value, final JListCellReader cellReader) { |
| 44 |
1
|
return execute(new GuiQuery<Point>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 45 |
1
|
protected Point executeInEDT() {... |
| 46 |
1
|
int itemIndex = matchingItemIndex(list, new StringTextMatcher(value), cellReader); |
| 47 |
1
|
return cellCenter(list, cellBounds(list, itemIndex)); |
| 48 |
|
} |
| 49 |
|
}); |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 52 |
33
|
@RunsInCurrentThread... |
| 53 |
|
static int matchingItemIndex(JList list, TextMatcher matcher, JListCellReader cellReader) { |
| 54 |
33
|
int size = list.getModel().getSize(); |
| 55 |
100
|
for (int i = 0; i < size; i++) |
| 56 |
26
|
if (matcher.isMatching(cellReader.valueAt(list, i))) return i; |
| 57 |
7
|
return -1; |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 60 |
16
|
@RunsInEDT... |
| 61 |
|
static List<Integer> matchingItemIndices(final JList list, final TextMatcher matcher, |
| 62 |
|
final JListCellReader cellReader) { |
| 63 |
16
|
return execute(new GuiQuery<List<Integer>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 64 |
16
|
protected List<Integer> executeInEDT() {... |
| 65 |
16
|
Set<Integer> indices = new HashSet<Integer>(); |
| 66 |
16
|
int size = list.getModel().getSize(); |
| 67 |
58
|
for (int i = 0; i < size; i++) |
| 68 |
23
|
if (matcher.isMatching(cellReader.valueAt(list, i))) indices.add(i); |
| 69 |
15
|
List<Integer> indexList = new ArrayList<Integer>(indices); |
| 70 |
15
|
sort(indexList); |
| 71 |
15
|
return indexList; |
| 72 |
|
} |
| 73 |
|
}); |
| 74 |
|
} |
| 75 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
12
|
@RunsInEDT... |
| 77 |
|
static List<String> matchingItemValues(final JList list, final TextMatcher matcher, |
| 78 |
|
final JListCellReader cellReader) { |
| 79 |
12
|
return execute(new GuiQuery<List<String>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 80 |
12
|
protected List<String> executeInEDT() {... |
| 81 |
12
|
List<String> values = new ArrayList<String>(); |
| 82 |
12
|
int size = list.getModel().getSize(); |
| 83 |
46
|
for (int i = 0; i < size; i++) { |
| 84 |
34
|
String value = cellReader.valueAt(list, i); |
| 85 |
19
|
if (matcher.isMatching(value)) values.add(value); |
| 86 |
|
} |
| 87 |
12
|
return values; |
| 88 |
|
} |
| 89 |
|
}); |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 92 |
|
private JListMatchingItemQuery() {}... |
| 93 |
|
} |