| 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 org.fest.swing.query.ComponentVisibleQuery.isVisible; |
| 19 |
|
import static org.fest.swing.timing.Pause.pause; |
| 20 |
|
import static org.fest.swing.util.TimeoutWatch.startWatchWithTimeoutOf; |
| 21 |
|
|
| 22 |
|
import java.awt.Component; |
| 23 |
|
import java.awt.event.ComponentAdapter; |
| 24 |
|
import java.awt.event.ComponentEvent; |
| 25 |
|
|
| 26 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 27 |
|
import org.fest.swing.exception.WaitTimedOutError; |
| 28 |
|
import org.fest.swing.util.TimeoutWatch; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@link |
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 11 |
Complexity Density: 0.55 |
|
| 35 |
|
public final class ComponentShownWaiter extends ComponentAdapter { |
| 36 |
|
|
| 37 |
|
private static final int DEFAULT_TIMEOUT = 5000; |
| 38 |
|
private static final int DEFAULT_SLEEP_TIME = 10; |
| 39 |
|
|
| 40 |
|
private Component toWaitFor; |
| 41 |
|
private volatile boolean shown; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@param |
| 46 |
|
@throws |
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 48 |
1
|
public static void waitTillShown(Component toWaitFor) {... |
| 49 |
1
|
new ComponentShownWaiter(toWaitFor).startWaiting(DEFAULT_TIMEOUT); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
@param |
| 55 |
|
@param |
| 56 |
|
@throws |
| 57 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 58 |
3
|
public static void waitTillShown(Component toWaitFor, long timeout) {... |
| 59 |
3
|
new ComponentShownWaiter(toWaitFor).startWaiting(timeout); |
| 60 |
|
} |
| 61 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 62 |
4
|
private ComponentShownWaiter(Component toWaitFor) {... |
| 63 |
4
|
this.toWaitFor = toWaitFor; |
| 64 |
4
|
toWaitFor.addComponentListener(this); |
| 65 |
|
} |
| 66 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 67 |
4
|
private void startWaiting(long timeout) {... |
| 68 |
1
|
if (alreadyVisible()) return; |
| 69 |
3
|
TimeoutWatch watch = startWatchWithTimeoutOf(timeout); |
| 70 |
615
|
while (!shown) { |
| 71 |
614
|
pause(DEFAULT_SLEEP_TIME); |
| 72 |
614
|
if (watch.isTimeOut()) { |
| 73 |
2
|
done(); |
| 74 |
2
|
throw new WaitTimedOutError("Timed out waiting for component to be visible"); |
| 75 |
|
} |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 79 |
4
|
private boolean alreadyVisible() {... |
| 80 |
3
|
if (!isVisible(toWaitFor)) return false; |
| 81 |
1
|
done(); |
| 82 |
1
|
return true; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@param |
| 88 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 89 |
1
|
@RunsInEDT... |
| 90 |
|
@Override public void componentShown(ComponentEvent e) { |
| 91 |
1
|
shown = true; |
| 92 |
1
|
done(); |
| 93 |
|
} |
| 94 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 95 |
4
|
private void done() {... |
| 96 |
4
|
toWaitFor.removeComponentListener(this); |
| 97 |
4
|
toWaitFor = null; |
| 98 |
|
} |
| 99 |
|
} |