001: package abbot.editor.recorder;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005:
006: import abbot.script.*;
007: import abbot.tester.WindowTracker;
008:
009: /**
010: * Record basic semantic events you might find on an Window. <p>
011: */
012: public class WindowRecorder extends ContainerRecorder {
013:
014: private Window window;
015: private Point where;
016: private Dimension size;
017:
018: public WindowRecorder(Resolver resolver) {
019: super (resolver);
020: }
021:
022: protected void init(int recordingType) {
023: super .init(recordingType);
024: window = null;
025: where = null;
026: size = null;
027: }
028:
029: protected boolean isWindowEvent(AWTEvent event) {
030: return (event.getSource() instanceof Window
031: // Checking for window ready avoids picking up
032: // spurious resize events on first window show
033: && ((Window) event.getSource()).isShowing()
034: && WindowTracker.getTracker().isWindowReady(
035: (Window) event.getSource()) && (event.getID() == ComponentEvent.COMPONENT_MOVED || event
036: .getID() == ComponentEvent.COMPONENT_RESIZED))
037: || event.getID() == WindowEvent.WINDOW_CLOSING
038: || super .isWindowEvent(event);
039: }
040:
041: protected boolean parseWindowEvent(AWTEvent event) {
042: int id = event.getID();
043: boolean consumed = true;
044: if (id == ComponentEvent.COMPONENT_MOVED) {
045: window = (Window) event.getSource();
046: where = window.getLocationOnScreen();
047: setFinished(true);
048: } else if (id == ComponentEvent.COMPONENT_RESIZED) {
049: window = (Window) event.getSource();
050: size = window.getSize();
051: setFinished(true);
052: } else if (id == WindowEvent.WINDOW_CLOSING) {
053: window = (Window) event.getSource();
054: setFinished(true);
055: } else {
056: consumed = super .parseWindowEvent(event);
057: }
058: return consumed;
059: }
060:
061: protected Step createStep() {
062: Step step;
063: if (getRecordingType() == SE_WINDOW && window != null) {
064: if (where != null) {
065: step = createMove(window, where);
066: } else if (size != null) {
067: step = createResize(window, size);
068: } else {
069: step = createClose(window);
070: }
071: } else {
072: step = super .createStep();
073: }
074: return step;
075: }
076:
077: protected Step createClose(Window window) {
078: ComponentReference ref = getResolver().addComponent(window);
079: return new Action(getResolver(), null, "actionClose",
080: new String[] { ref.getID() }, Window.class);
081: }
082:
083: protected Step createMove(Window window, Point where) {
084: // If the window is not yet showing, ignore it
085: if (!WindowTracker.getTracker().isWindowReady(window))
086: return null;
087:
088: ComponentReference ref = getResolver().addComponent(window);
089: return new Action(getResolver(), null, "actionMove",
090: new String[] { ref.getID(), String.valueOf(where.x),
091: String.valueOf(where.y) }, Window.class);
092: }
093:
094: protected Step createResize(Window window, Dimension size) {
095: // If the window is not yet showing, ignore it
096: if (!window.isShowing())
097: return null;
098:
099: ComponentReference ref = getResolver().addComponent(window);
100: return new Action(getResolver(), null, "actionResize",
101: new String[] { ref.getID(), String.valueOf(size.width),
102: String.valueOf(size.height), }, Window.class);
103: }
104: }
|