| 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.awt.Adjustable.HORIZONTAL; |
| 19 |
|
import static java.awt.Adjustable.VERTICAL; |
| 20 |
|
|
| 21 |
|
import java.awt.Point; |
| 22 |
|
import java.util.HashMap; |
| 23 |
|
import java.util.Map; |
| 24 |
|
|
| 25 |
|
import javax.swing.JScrollBar; |
| 26 |
|
|
| 27 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
@link |
| 31 |
|
|
| 32 |
|
@author |
| 33 |
|
@author |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 9 |
Complexity Density: 0.56 |
|
| 35 |
|
public final class JScrollBarLocation { |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
private static final int BLOCK_OFFSET = 4; |
| 39 |
|
|
| 40 |
|
private static final Map<Integer, JScrollBarLocationStrategy> LOCATIONS = new HashMap<Integer, JScrollBarLocationStrategy>(); |
| 41 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 42 |
30
|
static {... |
| 43 |
30
|
LOCATIONS.put(HORIZONTAL, new HorizontalJScrollBarLocation()); |
| 44 |
30
|
LOCATIONS.put(VERTICAL, new VerticalJScrollBarLocation()); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@param |
| 54 |
|
@param |
| 55 |
|
@return |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 57 |
8
|
@RunsInCurrentThread... |
| 58 |
|
public Point thumbLocation(JScrollBar scrollBar, int position) { |
| 59 |
8
|
double fraction = (double) position / maximumMinusMinimum(scrollBar); |
| 60 |
8
|
return locationStrategyFor(scrollBar).thumbLocation(scrollBar, fraction); |
| 61 |
|
} |
| 62 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 63 |
8
|
@RunsInCurrentThread... |
| 64 |
|
private int maximumMinusMinimum(JScrollBar scrollBar) { |
| 65 |
8
|
return scrollBar.getMaximum() - scrollBar.getMinimum(); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
@param |
| 75 |
|
@return |
| 76 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 77 |
8
|
@RunsInCurrentThread... |
| 78 |
|
public Point blockLocationToScrollUp(JScrollBar scrollBar) { |
| 79 |
8
|
Point p = unitLocationToScrollUp(scrollBar); |
| 80 |
8
|
int offset = BLOCK_OFFSET; |
| 81 |
8
|
return blockLocation(scrollBar, p, offset); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
@param |
| 91 |
|
@return |
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 93 |
8
|
@RunsInCurrentThread... |
| 94 |
|
public Point blockLocationToScrollDown(JScrollBar scrollBar) { |
| 95 |
8
|
Point p = unitLocationToScrollDown(scrollBar); |
| 96 |
8
|
int offset = -BLOCK_OFFSET; |
| 97 |
8
|
return blockLocation(scrollBar, p, offset); |
| 98 |
|
} |
| 99 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 100 |
16
|
@RunsInCurrentThread... |
| 101 |
|
private Point blockLocation(JScrollBar scrollBar, Point unitLocation, int offset) { |
| 102 |
16
|
return locationStrategyFor(scrollBar).blockLocation(scrollBar, unitLocation, offset); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
@param |
| 112 |
|
@return |
| 113 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 114 |
8
|
@RunsInCurrentThread... |
| 115 |
|
public Point unitLocationToScrollUp(JScrollBar scrollBar) { |
| 116 |
8
|
int arrow = locationStrategyFor(scrollBar).arrow(scrollBar); |
| 117 |
8
|
return new Point(arrow / 2, arrow / 2); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@param |
| 127 |
|
@return |
| 128 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
8
|
@RunsInCurrentThread... |
| 130 |
|
public Point unitLocationToScrollDown(JScrollBar scrollBar) { |
| 131 |
8
|
return locationStrategyFor(scrollBar).unitLocationToScrollDown(scrollBar); |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
40
|
@RunsInCurrentThread... |
| 135 |
|
private JScrollBarLocationStrategy locationStrategyFor(JScrollBar scrollBar) { |
| 136 |
40
|
return LOCATIONS.get(scrollBar.getOrientation()); |
| 137 |
|
} |
| 138 |
|
} |