01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05: import javax.swing.event.*;
06:
07: import abbot.util.Bugs;
08:
09: /** Provides methods to verify that the robot on the current platform works
10: * properly.
11: */
12: public class RobotVerifier {
13: // No instantiations
14: private RobotVerifier() {
15: }
16:
17: private static final String WINDOW_NAME = "Abbot Robot Verification";
18:
19: /** Auto-detect whether the robot actually works.
20: Use this to tell whether we're in w32 service mode without access
21: to the desktop.
22: @return false if the robot fails.
23: */
24: public static boolean verify(java.awt.Robot robot) {
25: if (!Bugs.needsRobotVerification())
26: return true;
27:
28: final int SIZE = 4;
29: Frame f = new Frame(WINDOW_NAME);
30: f.setName(WINDOW_NAME);
31: Window w = new Window(f);
32: Color color = new Color(0, 1, 2);
33: w.setBackground(color);
34: w.setName(WINDOW_NAME);
35: w.pack();
36: w.setSize(SIZE, SIZE);
37: w.setLocation(100, 100);
38: w.setVisible(true);
39: robot.waitForIdle();
40: WindowTracker tracker = WindowTracker.getTracker();
41: while (!tracker.isWindowReady(w)) {
42: robot.delay(20);
43: }
44: try {
45: Color sample = robot.getPixelColor(100, 100);
46: return sample.equals(color);
47: } finally {
48: w.dispose();
49: }
50: }
51:
52: /** Quick printout of whether the robot works. */
53: public static void main(String[] args) {
54: try {
55: boolean works = verify(new java.awt.Robot());
56: System.out.println("Robot is " + (works ? "" : "not ")
57: + "functional");
58: } catch (AWTException e) {
59: System.out.println("Robot is not available");
60: }
61: System.exit(0);
62: }
63: }
|