| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.monitor; |
| 17 |
|
|
| 18 |
|
import java.awt.Component; |
| 19 |
|
import java.awt.Window; |
| 20 |
|
import java.util.*; |
| 21 |
|
|
| 22 |
|
import net.jcip.annotations.GuardedBy; |
| 23 |
|
import net.jcip.annotations.ThreadSafe; |
| 24 |
|
|
| 25 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
@author |
| 31 |
|
|
| 32 |
|
@ThreadSafe |
|
|
|
| 100% |
Uncovered Elements: 0 (53) |
Complexity: 16 |
Complexity Density: 0.46 |
|
| 33 |
|
class Windows { |
| 34 |
|
|
| 35 |
|
static int WINDOW_READY_DELAY = 10000; |
| 36 |
|
|
| 37 |
|
@link |
| 38 |
|
@GuardedBy("lock") final Map<Window, TimerTask> pending = new WeakHashMap<Window, TimerTask>(); |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@GuardedBy("lock") final Map<Window, Boolean> open = new WeakHashMap<Window, Boolean>(); |
| 42 |
|
|
| 43 |
|
@link |
| 44 |
|
@GuardedBy("lock") final Map<Window, Boolean> closed = new WeakHashMap<Window, Boolean>(); |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@GuardedBy("lock") final Map<Window, Boolean> hidden = new WeakHashMap<Window, Boolean>(); |
| 48 |
|
|
| 49 |
|
private final Timer windowReadyTimer; |
| 50 |
|
|
| 51 |
|
private final Object lock = new Object(); |
| 52 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
636
|
Windows() {... |
| 54 |
636
|
windowReadyTimer = new Timer("Window Ready Timer", true); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@link |
| 59 |
|
@link |
| 60 |
|
@param |
| 61 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 62 |
1314
|
void attachNewWindowVisibilityMonitor(Window target) {... |
| 63 |
1314
|
WindowVisibilityMonitor monitor = new WindowVisibilityMonitor(this); |
| 64 |
1314
|
target.addWindowListener(monitor); |
| 65 |
1314
|
target.addComponentListener(monitor); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
@param |
| 71 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 72 |
24
|
@RunsInCurrentThread... |
| 73 |
|
void markExisting(Window w) { |
| 74 |
24
|
synchronized(lock) { |
| 75 |
24
|
addWindowTo(w, open); |
| 76 |
18
|
if (!w.isShowing()) addWindowTo(w, hidden); |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
@param |
| 83 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 84 |
112
|
void markAsHidden(Window w) {... |
| 85 |
112
|
synchronized(lock) { |
| 86 |
112
|
addWindowTo(w, hidden); |
| 87 |
112
|
removeWindowFrom(w, pending); |
| 88 |
|
} |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
@param |
| 94 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 95 |
1550
|
void markAsShowing(final Window w) {... |
| 96 |
1550
|
synchronized(lock) { |
| 97 |
1550
|
TimerTask task = new TimerTask() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
134
|
public void run() { markAsReady(w); }... |
| 99 |
|
}; |
| 100 |
1550
|
windowReadyTimer.schedule(new ProtectingTimerTask(task), WINDOW_READY_DELAY); |
| 101 |
1550
|
pending.put(w, task); |
| 102 |
|
} |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
@param |
| 108 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 109 |
4503
|
void markAsReady(Window w) {... |
| 110 |
4503
|
synchronized(lock) { |
| 111 |
3661
|
if (!pending.containsKey(w)) return; |
| 112 |
842
|
removeWindowFrom(w, closed, hidden, pending); |
| 113 |
842
|
addWindowTo(w, open); |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@param |
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 121 |
5073
|
void markAsClosed(Window w) {... |
| 122 |
5073
|
synchronized(lock) { |
| 123 |
5073
|
removeWindowFrom(w, open, hidden, pending); |
| 124 |
5073
|
addWindowTo(w, closed); |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 128 |
6069
|
private void addWindowTo(Window w, Map<Window, Boolean> map) {... |
| 129 |
6069
|
map.put(w, true); |
| 130 |
|
} |
| 131 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 132 |
6027
|
private void removeWindowFrom(Window w, Map<?, ?>... maps) {... |
| 133 |
17857
|
for (Map<?, ?> map : maps) map.remove(w); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
@param |
| 139 |
|
@return |
| 140 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 141 |
4143
|
boolean isClosed(Component c) {... |
| 142 |
4143
|
synchronized(lock) { |
| 143 |
4143
|
return closed.containsKey(c); |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
@param |
| 150 |
|
@return |
| 151 |
|
|
| 152 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 153 |
3774
|
boolean isReady(Window w) {... |
| 154 |
3774
|
synchronized(lock) { |
| 155 |
3774
|
return open.containsKey(w) && !hidden.containsKey(w); |
| 156 |
|
} |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
@param |
| 162 |
|
@return |
| 163 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 164 |
2
|
boolean isHidden(Window w) {... |
| 165 |
2
|
synchronized(lock) { |
| 166 |
2
|
return hidden.containsKey(w); |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
@param |
| 173 |
|
@return |
| 174 |
|
|
| 175 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 176 |
2690
|
boolean isShowingButNotReady(Window w) {... |
| 177 |
2690
|
synchronized(lock) { |
| 178 |
2690
|
return pending.containsKey(w); |
| 179 |
|
} |
| 180 |
|
} |
| 181 |
|
} |