| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.monitor; |
| 17 |
|
|
| 18 |
|
import static java.awt.AWTEvent.COMPONENT_EVENT_MASK; |
| 19 |
|
import static java.awt.AWTEvent.WINDOW_EVENT_MASK; |
| 20 |
|
import static java.awt.event.ComponentEvent.COMPONENT_SHOWN; |
| 21 |
|
import static java.awt.event.WindowEvent.*; |
| 22 |
|
import static org.fest.swing.listener.WeakEventListener.attachAsWeakEventListener; |
| 23 |
|
import static org.fest.swing.query.ComponentParentQuery.parentOf; |
| 24 |
|
|
| 25 |
|
import java.applet.Applet; |
| 26 |
|
import java.awt.*; |
| 27 |
|
import java.awt.event.AWTEventListener; |
| 28 |
|
import java.awt.event.ComponentEvent; |
| 29 |
|
|
| 30 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@author |
| 36 |
|
|
|
|
|
| 93.9% |
Uncovered Elements: 4 (66) |
Complexity: 22 |
Complexity Density: 0.61 |
|
| 37 |
|
final class ContextMonitor implements AWTEventListener { |
| 38 |
|
|
| 39 |
|
private static final long EVENT_MASK = WINDOW_EVENT_MASK | COMPONENT_EVENT_MASK; |
| 40 |
|
|
| 41 |
|
private final Context context; |
| 42 |
|
private final Windows windows; |
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 44 |
704
|
ContextMonitor(Context context, Windows windows) {... |
| 45 |
704
|
this.context = context; |
| 46 |
704
|
this.windows = windows; |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 49 |
634
|
void attachTo(Toolkit toolkit) {... |
| 50 |
634
|
attachAsWeakEventListener(toolkit, this, EVENT_MASK); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
@inheritDoc |
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 54 |
37455
|
@RunsInEDT... |
| 55 |
|
public void eventDispatched(AWTEvent e) { |
| 56 |
37455
|
if (!(e instanceof ComponentEvent)) return; |
| 57 |
37455
|
ComponentEvent event = (ComponentEvent) e; |
| 58 |
37455
|
Component component = event.getComponent(); |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
22981
|
if (!(component instanceof Applet) && !(component instanceof Window)) return; |
| 64 |
14474
|
processEvent(event); |
| 65 |
|
|
| 66 |
14474
|
if (!component.getToolkit().getSystemEventQueue().equals(context.storedQueueFor(component))) |
| 67 |
2225
|
context.addContextFor(component); |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 9 |
Complexity Density: 0.69 |
|
| 70 |
14474
|
private void processEvent(ComponentEvent event) {... |
| 71 |
14474
|
Component component = event.getComponent(); |
| 72 |
14474
|
int id = event.getID(); |
| 73 |
14474
|
if (id == WINDOW_OPENED) { |
| 74 |
908
|
recognizeAsOpenWindow(component); |
| 75 |
908
|
return; |
| 76 |
|
} |
| 77 |
13566
|
if (id == WINDOW_CLOSED) { |
| 78 |
5086
|
recognizeAsClosedWindow(component); |
| 79 |
5086
|
return; |
| 80 |
|
} |
| 81 |
20
|
if (id == WINDOW_CLOSING) return; |
| 82 |
8460
|
if ((id >= WINDOW_FIRST && id <= WINDOW_LAST) || id == COMPONENT_SHOWN) |
| 83 |
412
|
if ((!context.rootWindows().contains(component)) || windows.isClosed(component)) recognizeAsOpenWindow(component); |
| 84 |
|
} |
| 85 |
|
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 86 |
1320
|
private void recognizeAsOpenWindow(Component component) {... |
| 87 |
1320
|
context.addContextFor(component); |
| 88 |
|
|
| 89 |
|
|
| 90 |
1320
|
if (!(component instanceof Window)) return; |
| 91 |
1320
|
windows.attachNewWindowVisibilityMonitor((Window)component); |
| 92 |
1320
|
windows.markAsShowing((Window) component); |
| 93 |
|
|
| 94 |
7
|
if (component instanceof FileDialog) windows.markAsReady((Window) component); |
| 95 |
|
} |
| 96 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 97 |
5086
|
private void recognizeAsClosedWindow(Component component) {... |
| 98 |
4522
|
if (parentOf(component) == null) context.removeContextFor(component); |
| 99 |
5079
|
if (component instanceof Window) windows.markAsClosed((Window)component); |
| 100 |
|
} |
| 101 |
|
} |