| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package org.fest.swing.input; |
| 16 |
|
|
| 17 |
|
import static java.awt.AWTEvent.*; |
| 18 |
|
import static javax.swing.SwingUtilities.getDeepestComponentAt; |
| 19 |
|
import static org.fest.swing.awt.AWT.locationOnScreenOf; |
| 20 |
|
import static org.fest.swing.input.MouseInfo.BUTTON_MASK; |
| 21 |
|
|
| 22 |
|
import java.awt.*; |
| 23 |
|
import java.awt.event.*; |
| 24 |
|
|
| 25 |
|
import net.jcip.annotations.GuardedBy; |
| 26 |
|
import net.jcip.annotations.ThreadSafe; |
| 27 |
|
|
| 28 |
|
import org.fest.swing.exception.UnexpectedException; |
| 29 |
|
import org.fest.swing.listener.EventDispatchThreadedEventListener; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@ThreadSafe |
|
|
|
| 56.2% |
Uncovered Elements: 39 (89) |
Complexity: 32 |
Complexity Density: 0.6 |
|
| 39 |
|
public class InputState { |
| 40 |
|
|
| 41 |
|
@GuardedBy("this") private final MouseInfo mouseInfo = new MouseInfo(); |
| 42 |
|
@GuardedBy("this") private final DragDropInfo dragDropInfo = new DragDropInfo(); |
| 43 |
|
|
| 44 |
|
@GuardedBy("this") private int modifiers; |
| 45 |
|
@GuardedBy("this") private long lastEventTime; |
| 46 |
|
|
| 47 |
|
private EventNormalizer normalizer; |
| 48 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 49 |
582
|
public InputState(Toolkit toolkit) {... |
| 50 |
582
|
long mask = MOUSE_MOTION_EVENT_MASK | MOUSE_EVENT_MASK | KEY_EVENT_MASK; |
| 51 |
582
|
AWTEventListener listener = new EventDispatchThreadedEventListener() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
5205
|
protected void processEvent(AWTEvent event) {... |
| 53 |
5205
|
update(event); |
| 54 |
|
} |
| 55 |
|
}; |
| 56 |
582
|
normalizer = new EventNormalizer(); |
| 57 |
582
|
normalizer.startListening(toolkit, listener, mask); |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 60 |
0
|
public synchronized void clear() {... |
| 61 |
0
|
mouseInfo.clear(); |
| 62 |
0
|
dragDropInfo.clear(); |
| 63 |
0
|
modifiers = 0; |
| 64 |
0
|
lastEventTime = 0; |
| 65 |
|
} |
| 66 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 67 |
0
|
public void dispose() {... |
| 68 |
0
|
normalizer.stopListening(); |
| 69 |
0
|
normalizer = null; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
@param |
| 75 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 76 |
5205
|
public void update(AWTEvent event) {... |
| 77 |
837
|
if (event instanceof KeyEvent) updateState((KeyEvent) event); |
| 78 |
4368
|
if (event instanceof MouseEvent) updateState((MouseEvent) event); |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 81 |
837
|
private void updateState(KeyEvent event) {... |
| 82 |
2
|
if (isOld(event)) return; |
| 83 |
835
|
synchronized (this) { |
| 84 |
835
|
lastEventTime(event); |
| 85 |
835
|
modifiers(event.getModifiers()); |
| 86 |
|
|
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 90 |
4368
|
private void updateState(MouseEvent event) {... |
| 91 |
15
|
if (isOld(event)) return; |
| 92 |
|
|
| 93 |
|
|
| 94 |
4353
|
Point eventScreenLocation = null; |
| 95 |
|
|
| 96 |
4353
|
try { |
| 97 |
4353
|
eventScreenLocation = locationOnScreenOf(event.getComponent()); |
| 98 |
|
} catch (IllegalComponentStateException e) { |
| 99 |
|
|
| 100 |
|
} catch (UnexpectedException e) { |
| 101 |
0
|
if (!(e.getCause() instanceof IllegalComponentStateException)) throw e; |
| 102 |
|
} |
| 103 |
4353
|
synchronized (this) { |
| 104 |
4353
|
lastEventTime(event); |
| 105 |
4353
|
dragDropInfo.update(event); |
| 106 |
4353
|
mouseInfo.modifiers(modifiers); |
| 107 |
4353
|
mouseInfo.update(event, eventScreenLocation); |
| 108 |
4353
|
modifiers(mouseInfo.modifiers()); |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
5205
|
private boolean isOld(InputEvent event) {... |
| 113 |
5205
|
return event.getWhen() < lastEventTime(); |
| 114 |
|
} |
| 115 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
5188
|
private void lastEventTime(InputEvent event) {... |
| 117 |
5188
|
lastEventTime = event.getWhen(); |
| 118 |
|
} |
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
5188
|
private void modifiers(int newModifiers) {... |
| 121 |
5188
|
modifiers = newModifiers; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@return |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 128 |
0
|
public synchronized Component deepestComponentUnderMousePointer() {... |
| 129 |
0
|
Component c = mouseComponent(); |
| 130 |
0
|
if (c != null) c = childAt(c, mouseLocation()); |
| 131 |
0
|
return c; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
@return |
| 138 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 139 |
0
|
public synchronized Component mouseComponent() {... |
| 140 |
0
|
return mouseInfo.component(); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
@param |
| 156 |
|
@param |
| 157 |
|
@return |
| 158 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 159 |
0
|
public static Component childAt(Component parent, Point where) {... |
| 160 |
0
|
return getDeepestComponentAt(parent, where.x, where.y); |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
@return |
| 166 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 167 |
21
|
public synchronized boolean dragInProgress() {... |
| 168 |
21
|
return dragDropInfo.isDragging(); |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
@link |
| 173 |
|
@return |
| 174 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 175 |
0
|
public synchronized Component dragSource() {... |
| 176 |
0
|
return dragDropInfo.source(); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
@return |
| 182 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 183 |
0
|
public synchronized Point dragOrigin() {... |
| 184 |
0
|
return dragDropInfo.origin(); |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
@return |
| 190 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 191 |
0
|
public synchronized int clickCount() {... |
| 192 |
0
|
return mouseInfo.clickCount(); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
|
@return |
| 198 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 199 |
5205
|
public synchronized long lastEventTime() {... |
| 200 |
5205
|
return lastEventTime; |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
@return |
| 206 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 207 |
0
|
public synchronized int modifiers() {... |
| 208 |
0
|
return modifiers; |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
@return |
| 214 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 215 |
0
|
public synchronized int keyModifiers() {... |
| 216 |
0
|
return modifiers & ~BUTTON_MASK; |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
@return |
| 222 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 223 |
1611
|
public synchronized int buttons() {... |
| 224 |
1611
|
return mouseInfo.buttons(); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
@return |
| 231 |
|
|
| 232 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 233 |
0
|
public synchronized Point mouseLocation() {... |
| 234 |
0
|
return mouseInfo.location(); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
|
| 238 |
|
|
| 239 |
|
@return |
| 240 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 241 |
0
|
public synchronized Point mouseLocationOnScreen() {... |
| 242 |
0
|
return mouseInfo.locationOnScreen(); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
@return |
| 248 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 249 |
0
|
public boolean isNativeDragActive() {... |
| 250 |
0
|
return dragDropInfo.isNativeDragActive(); |
| 251 |
|
} |
| 252 |
|
} |