| 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.ComponentStateValidator.validateIsEnabledAndShowing; |
| 18 |
|
import static org.fest.swing.driver.JSliderSetValueTask.setValue; |
| 19 |
|
import static org.fest.swing.edt.GuiActionRunner.execute; |
| 20 |
|
import static org.fest.util.Strings.concat; |
| 21 |
|
|
| 22 |
|
import java.awt.Point; |
| 23 |
|
|
| 24 |
|
import javax.swing.JSlider; |
| 25 |
|
|
| 26 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 27 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 28 |
|
import org.fest.swing.core.Robot; |
| 29 |
|
import org.fest.swing.edt.GuiQuery; |
| 30 |
|
import org.fest.swing.util.GenericRange; |
| 31 |
|
import org.fest.swing.util.Pair; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@link |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@link |
| 42 |
|
|
| 43 |
|
@author |
| 44 |
|
@author |
| 45 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (49) |
Complexity: 16 |
Complexity Density: 0.48 |
|
| 46 |
|
public class JSliderDriver extends JComponentDriver { |
| 47 |
|
|
| 48 |
|
private final JSliderLocation location; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@link |
| 52 |
|
@param |
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 54 |
57
|
public JSliderDriver(Robot robot) {... |
| 55 |
57
|
super(robot); |
| 56 |
57
|
location = new JSliderLocation(); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@param |
| 62 |
|
@throws |
| 63 |
|
@throws |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
6
|
@RunsInEDT... |
| 66 |
|
public void slideToMaximum(JSlider slider) { |
| 67 |
6
|
slide(slider, validateAndFindSlideToMaximumInfo(slider, location)); |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
6
|
@RunsInEDT... |
| 71 |
|
private static Pair<Integer, GenericRange<Point>> validateAndFindSlideToMaximumInfo(final JSlider slider, |
| 72 |
|
final JSliderLocation location) { |
| 73 |
6
|
return execute(new GuiQuery<Pair<Integer, GenericRange<Point>>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 74 |
6
|
protected Pair<Integer, GenericRange<Point>> executeInEDT() {... |
| 75 |
6
|
validateIsEnabledAndShowing(slider); |
| 76 |
2
|
int value = slider.getMaximum(); |
| 77 |
2
|
GenericRange<Point> fromAndTo = slideInfo(slider, location, value); |
| 78 |
2
|
return new Pair<Integer, GenericRange<Point>>(value, fromAndTo); |
| 79 |
|
} |
| 80 |
|
}); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
@param |
| 86 |
|
@throws |
| 87 |
|
@throws |
| 88 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 89 |
6
|
@RunsInEDT... |
| 90 |
|
public void slideToMinimum(JSlider slider) { |
| 91 |
6
|
slide(slider, validateAndFindSlideToMinimumInfo(slider, location)); |
| 92 |
|
} |
| 93 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 94 |
6
|
@RunsInEDT... |
| 95 |
|
private static Pair<Integer, GenericRange<Point>> validateAndFindSlideToMinimumInfo(final JSlider slider, |
| 96 |
|
final JSliderLocation location) { |
| 97 |
6
|
return execute(new GuiQuery<Pair<Integer, GenericRange<Point>>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 98 |
6
|
protected Pair<Integer, GenericRange<Point>> executeInEDT() {... |
| 99 |
6
|
validateIsEnabledAndShowing(slider); |
| 100 |
2
|
int value = slider.getMinimum(); |
| 101 |
2
|
GenericRange<Point> fromAndTo = slideInfo(slider, location, value); |
| 102 |
2
|
return new Pair<Integer, GenericRange<Point>>(value, fromAndTo); |
| 103 |
|
} |
| 104 |
|
}); |
| 105 |
|
} |
| 106 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
4
|
@RunsInEDT... |
| 108 |
|
private void slide(JSlider slider, Pair<Integer, GenericRange<Point>> slideInfo) { |
| 109 |
4
|
slide(slider, slideInfo.i, slideInfo.ii); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
@param |
| 115 |
|
@param |
| 116 |
|
@throws |
| 117 |
|
@throws |
| 118 |
|
@throws |
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 120 |
16
|
@RunsInEDT... |
| 121 |
|
public void slide(JSlider slider, int value) { |
| 122 |
16
|
GenericRange<Point> slideInfo = validateAndFindSlideInfo(slider, location, value); |
| 123 |
8
|
slide(slider, value, slideInfo); |
| 124 |
|
} |
| 125 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 126 |
12
|
@RunsInEDT... |
| 127 |
|
private void slide(JSlider slider, int value, GenericRange<Point> fromAndTo) { |
| 128 |
12
|
moveMouseIgnoringAnyError(slider, fromAndTo.from); |
| 129 |
12
|
moveMouseIgnoringAnyError(slider, fromAndTo.to); |
| 130 |
12
|
setValue(slider, value); |
| 131 |
12
|
robot.waitForIdle(); |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
16
|
@RunsInEDT... |
| 135 |
|
private static GenericRange<Point> validateAndFindSlideInfo(final JSlider slider, final JSliderLocation location, |
| 136 |
|
final int value) { |
| 137 |
16
|
return execute(new GuiQuery<GenericRange<Point>>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 138 |
16
|
protected GenericRange<Point> executeInEDT() {... |
| 139 |
16
|
validateValue(slider, value); |
| 140 |
12
|
validateIsEnabledAndShowing(slider); |
| 141 |
8
|
return slideInfo(slider, location, value); |
| 142 |
|
} |
| 143 |
|
}); |
| 144 |
|
} |
| 145 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 146 |
16
|
@RunsInCurrentThread... |
| 147 |
|
private static void validateValue(JSlider slider, int value) { |
| 148 |
16
|
int min = slider.getMinimum(); |
| 149 |
16
|
int max = slider.getMaximum(); |
| 150 |
12
|
if (value >= min && value <= max) return; |
| 151 |
4
|
throw new IllegalArgumentException( |
| 152 |
|
concat("Value <", value, "> is not within the JSlider bounds of <", min, "> and <", max, ">")); |
| 153 |
|
} |
| 154 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 155 |
12
|
@RunsInCurrentThread... |
| 156 |
|
private static GenericRange<Point> slideInfo(JSlider slider, JSliderLocation location, int value) { |
| 157 |
12
|
Point from = location.pointAt(slider, slider.getValue()); |
| 158 |
12
|
Point to = location.pointAt(slider, value); |
| 159 |
12
|
return new GenericRange<Point>(from, to); |
| 160 |
|
} |
| 161 |
|
} |