| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.input; |
| 17 |
|
|
| 18 |
|
import static java.awt.event.InputEvent.*; |
| 19 |
|
import static java.awt.event.MouseEvent.*; |
| 20 |
|
import static org.fest.swing.query.ComponentShowingQuery.isShowing; |
| 21 |
|
|
| 22 |
|
import java.awt.Component; |
| 23 |
|
import java.awt.Point; |
| 24 |
|
import java.awt.event.MouseEvent; |
| 25 |
|
import java.lang.ref.WeakReference; |
| 26 |
|
import java.util.Stack; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@author |
| 32 |
|
|
|
|
|
| 61.2% |
Uncovered Elements: 38 (98) |
Complexity: 30 |
Complexity Density: 0.51 |
|
| 33 |
|
class MouseInfo { |
| 34 |
|
|
| 35 |
|
static final int BUTTON_MASK = BUTTON1_MASK | BUTTON2_MASK | BUTTON3_MASK; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
private Point location = new Point(0, 0); |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
private Point locationOnScreen = new Point(0, 0); |
| 42 |
|
|
| 43 |
|
private final Stack<WeakReference<Component>> componentStack = new Stack<WeakReference<Component>>(); |
| 44 |
|
private final Stack<Point> locationStack = new Stack<Point>(); |
| 45 |
|
private final Stack<Point> screenLocationStack = new Stack<Point>(); |
| 46 |
|
|
| 47 |
|
private int buttons; |
| 48 |
|
private int modifiers; |
| 49 |
|
private int clickCount; |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 51 |
0
|
void clear() {... |
| 52 |
0
|
buttons = modifiers = clickCount = 0; |
| 53 |
0
|
componentStack.clear(); |
| 54 |
0
|
locationStack.clear(); |
| 55 |
0
|
screenLocationStack.clear(); |
| 56 |
|
} |
| 57 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 58 |
4353
|
void update(MouseEvent event, Point eventScreenLocation) {... |
| 59 |
|
|
| 60 |
4353
|
clickCount(event.getClickCount()); |
| 61 |
4353
|
updateOnMousePressed(event); |
| 62 |
4353
|
updateOnMouseReleased(event); |
| 63 |
4353
|
updateOnMouseEntered(event, eventScreenLocation); |
| 64 |
4353
|
updateOnMouseExited(event); |
| 65 |
54
|
if (eventScreenLocation == null) return; |
| 66 |
4299
|
Point where = event.getPoint(); |
| 67 |
4299
|
location = componentStack.empty() ? null : new Point(where); |
| 68 |
4299
|
locationOnScreen.setLocation(eventScreenLocation); |
| 69 |
4299
|
locationOnScreen.translate(where.x, where.y); |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 72 |
4353
|
private void updateOnMousePressed(MouseEvent event) {... |
| 73 |
3992
|
if (event.getID() != MOUSE_PRESSED) return; |
| 74 |
361
|
int buttonUsed = buttonUsed(event); |
| 75 |
361
|
buttons |= buttonUsed; |
| 76 |
361
|
modifiers |= buttonUsed; |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 79 |
4353
|
private void updateOnMouseReleased(MouseEvent event) {... |
| 80 |
4033
|
if (event.getID() != MOUSE_RELEASED) return; |
| 81 |
320
|
int buttonUsed = buttonUsed(event); |
| 82 |
320
|
buttons &= ~buttonUsed; |
| 83 |
320
|
modifiers &= ~buttonUsed; |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
681
|
private int buttonUsed(MouseEvent event) {... |
| 87 |
681
|
return event.getModifiers() & BUTTON_MASK; |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 90 |
4353
|
private void updateOnMouseEntered(MouseEvent event, Point eventScreenLocation) {... |
| 91 |
3266
|
if (event.getID() != MOUSE_ENTERED) return; |
| 92 |
1087
|
componentStack.push(new WeakReference<Component>(event.getComponent())); |
| 93 |
1087
|
Point eventPoint = event.getPoint(); |
| 94 |
1087
|
locationStack.push(eventPoint); |
| 95 |
1087
|
screenLocationStack.push(eventScreenLocation != null ? eventScreenLocation : eventPoint); |
| 96 |
|
} |
| 97 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 98 |
4353
|
private void updateOnMouseExited(MouseEvent event) {... |
| 99 |
4059
|
if (event.getID() != MOUSE_EXITED || componentStack.empty()) return; |
| 100 |
294
|
componentStack.pop(); |
| 101 |
294
|
locationStack.pop(); |
| 102 |
294
|
screenLocationStack.pop(); |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 105 |
0
|
public Component component() {... |
| 106 |
0
|
if (componentStack.empty()) return null; |
| 107 |
0
|
Component c = componentStack.peek().get(); |
| 108 |
|
|
| 109 |
0
|
if (c != null && isShowing(c)) return c; |
| 110 |
0
|
componentStack.pop(); |
| 111 |
0
|
locationStack.pop(); |
| 112 |
0
|
screenLocationStack.pop(); |
| 113 |
0
|
c = component(); |
| 114 |
0
|
if (c != null) { |
| 115 |
0
|
location = locationStack.peek(); |
| 116 |
0
|
locationOnScreen = screenLocationStack.peek(); |
| 117 |
|
} |
| 118 |
0
|
return c; |
| 119 |
|
} |
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 121 |
1611
|
int buttons() {... |
| 122 |
1611
|
return buttons; |
| 123 |
|
} |
| 124 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
0
|
void buttons(int newButtons) {... |
| 126 |
0
|
buttons = newButtons; |
| 127 |
|
} |
| 128 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
4353
|
int modifiers() {... |
| 130 |
4353
|
return modifiers; |
| 131 |
|
} |
| 132 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 133 |
4353
|
void modifiers(int newModifiers) {... |
| 134 |
4353
|
modifiers = newModifiers; |
| 135 |
|
} |
| 136 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 137 |
0
|
int clickCount() {... |
| 138 |
0
|
return clickCount; |
| 139 |
|
} |
| 140 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 141 |
4353
|
void clickCount(int newClickCount) {... |
| 142 |
4353
|
clickCount = newClickCount; |
| 143 |
|
} |
| 144 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
0
|
Point location() {... |
| 146 |
0
|
return pointFrom(location); |
| 147 |
|
} |
| 148 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 149 |
0
|
Point locationOnScreen() {... |
| 150 |
0
|
return pointFrom(locationOnScreen); |
| 151 |
|
} |
| 152 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 153 |
0
|
private Point pointFrom(Point source) {... |
| 154 |
0
|
return source != null ? new Point(source) : null; |
| 155 |
|
} |
| 156 |
|
} |