| 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 org.fest.swing.driver.ComponentStateValidator.validateIsEnabledAndShowing; |
| 19 |
|
import static org.fest.swing.driver.JListCellBoundsQuery.cellBounds; |
| 20 |
|
import static org.fest.swing.driver.JListCellCenterQuery.cellCenter; |
| 21 |
|
import static org.fest.swing.driver.JListItemIndexValidator.validateIndex; |
| 22 |
|
import static org.fest.swing.driver.JListMatchingItemQuery.matchingItemIndex; |
| 23 |
|
import static org.fest.swing.edt.GuiActionRunner.execute; |
| 24 |
|
|
| 25 |
|
import java.awt.Point; |
| 26 |
|
import java.awt.Rectangle; |
| 27 |
|
|
| 28 |
|
import javax.swing.JList; |
| 29 |
|
|
| 30 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 31 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 32 |
|
import org.fest.swing.cell.JListCellReader; |
| 33 |
|
import org.fest.swing.edt.GuiQuery; |
| 34 |
|
import org.fest.swing.util.Pair; |
| 35 |
|
import org.fest.swing.util.TextMatcher; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@link |
| 40 |
|
|
| 41 |
|
@author |
| 42 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (42) |
Complexity: 13 |
Complexity Density: 0.5 |
|
| 43 |
|
final class JListScrollToItemTask { |
| 44 |
|
|
| 45 |
|
static final Pair<Integer, Point> ITEM_NOT_FOUND = new Pair<Integer, Point>(-1, null); |
| 46 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 47 |
12
|
@RunsInEDT... |
| 48 |
|
|
| 49 |
|
static Point scrollToItem(final JList list, final int index) { |
| 50 |
12
|
return execute(new GuiQuery<Point>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 51 |
12
|
protected Point executeInEDT() {... |
| 52 |
12
|
validateIsEnabledAndShowing(list); |
| 53 |
7
|
validateIndex(list, index); |
| 54 |
7
|
return scrollToItemWithIndex(list, index); |
| 55 |
|
} |
| 56 |
|
}); |
| 57 |
|
} |
| 58 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 59 |
32
|
@RunsInEDT... |
| 60 |
|
|
| 61 |
|
static Pair<Integer, Point> scrollToItem(final JList list, final TextMatcher matcher, final JListCellReader cellReader) { |
| 62 |
32
|
return execute(new GuiQuery<Pair<Integer, Point>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 63 |
32
|
protected Pair<Integer, Point> executeInEDT() {... |
| 64 |
32
|
validateIsEnabledAndShowing(list); |
| 65 |
15
|
int index = matchingItemIndex(list, matcher, cellReader); |
| 66 |
2
|
if (index < 0) return ITEM_NOT_FOUND; |
| 67 |
13
|
return new Pair<Integer, Point>(index, scrollToItemWithIndex(list, index)); |
| 68 |
|
} |
| 69 |
|
}); |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
14
|
@RunsInEDT... |
| 73 |
|
|
| 74 |
|
static Pair<Integer, Point> scrollToItemIfNotSelectedYet(final JList list, final TextMatcher matcher, |
| 75 |
|
final JListCellReader cellReader) { |
| 76 |
14
|
return execute(new GuiQuery<Pair<Integer, Point>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 77 |
14
|
protected Pair<Integer, Point> executeInEDT() {... |
| 78 |
14
|
validateIsEnabledAndShowing(list); |
| 79 |
10
|
int index = matchingItemIndex(list, matcher, cellReader); |
| 80 |
2
|
if (index < 0) return ITEM_NOT_FOUND; |
| 81 |
8
|
return new Pair<Integer, Point>(index, scrollToItemWithIndexIfNotSelectedYet(list, index)); |
| 82 |
|
} |
| 83 |
|
}); |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
52
|
@RunsInEDT... |
| 87 |
|
|
| 88 |
|
static Point scrollToItemIfNotSelectedYet(final JList list, final int index) { |
| 89 |
52
|
return execute(new GuiQuery<Point>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 90 |
52
|
protected Point executeInEDT() {... |
| 91 |
52
|
validateIsEnabledAndShowing(list); |
| 92 |
40
|
validateIndex(list, index); |
| 93 |
36
|
return scrollToItemWithIndexIfNotSelectedYet(list, index); |
| 94 |
|
} |
| 95 |
|
}); |
| 96 |
|
} |
| 97 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 98 |
44
|
@RunsInCurrentThread... |
| 99 |
|
|
| 100 |
|
private static Point scrollToItemWithIndexIfNotSelectedYet(final JList list, final int index) { |
| 101 |
7
|
if (list.getSelectedIndex() == index) return null; |
| 102 |
37
|
return scrollToItemWithIndex(list, index); |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 105 |
57
|
@RunsInCurrentThread... |
| 106 |
|
private static Point scrollToItemWithIndex(JList list, int index) { |
| 107 |
57
|
Rectangle cellBounds = cellBounds(list, index); |
| 108 |
57
|
list.scrollRectToVisible(cellBounds); |
| 109 |
57
|
return cellCenter(list, cellBounds); |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 112 |
|
private JListScrollToItemTask() {}... |
| 113 |
|
} |