01: package abbot.tester;
02:
03: import java.awt.*;
04: import javax.accessibility.AccessibleContext;
05:
06: import abbot.i18n.Strings;
07:
08: /** Provides user actions on a Window. */
09: public class WindowTester extends ContainerTester {
10:
11: /** The window's size seems as good an ID as any. If someone has a bunch
12: * of frameless windows floating about, they can come up with a better
13: * ID.
14: */
15: public String deriveTag(Component comp) {
16: // If the component class is custom, don't provide a tag
17: if (isCustom(comp.getClass()))
18: return null;
19:
20: String tag = null;
21: AccessibleContext context = ((Window) comp)
22: .getAccessibleContext();
23: tag = deriveAccessibleTag(context);
24: if (tag == null || "".equals(tag)) {
25: Dimension size = comp.getSize();
26: tag = String.valueOf(size.width) + "x"
27: + String.valueOf(size.height);
28: }
29: return tag;
30: }
31:
32: /** Send a WINDOW_CLOSING event to the window, equivalent to the user
33: closing the window through the window manager. Note that this will
34: not necessarily close the window.
35: */
36: public void actionClose(Component c) {
37: close((Window) c);
38: waitForIdle();
39: }
40:
41: /** Move the window to the given location. */
42: public void actionMove(Component w, int screenx, int screeny) {
43: if (!userMovable(w))
44: throw new ActionFailedException(Strings
45: .get("tester.Window.no_move"));
46: move((Window) w, screenx, screeny);
47: waitForIdle();
48: }
49:
50: /** Move the window to the given location. */
51: public void actionMoveBy(Component w, int dx, int dy) {
52: if (!userMovable(w))
53: throw new ActionFailedException(Strings
54: .get("tester.Window.no_move"));
55: moveBy((Window) w, dx, dy);
56: waitForIdle();
57: }
58:
59: /** Resize the given window. Note that this will fail on frames or
60: * dialogs which are not resizable.
61: */
62: public void actionResize(Component w, int width, int height) {
63: if (!userResizable(w))
64: throw new ActionFailedException(Strings
65: .get("tester.Window.no_resize"));
66: resize((Window) w, width, height);
67: waitForIdle();
68: }
69:
70: /** Resize the given window. Note that this will fail on frames or
71: * dialogs which are not resizable.
72: */
73: public void actionResizeBy(Component w, int dx, int dy) {
74: if (!userResizable(w))
75: throw new ActionFailedException(Strings
76: .get("tester.Window.no_resize"));
77: resizeBy((Window) w, dx, dy);
78: waitForIdle();
79: }
80:
81: /** Activate the given Window. */
82: public void actionActivate(Window w) {
83: activate(w);
84: waitForIdle();
85: }
86: }
|