01: package abbot.editor.recorder;
02:
03: import java.awt.*;
04: import java.awt.event.WindowEvent;
05:
06: import abbot.Log;
07: import abbot.script.*;
08:
09: /**
10: * Record basic semantic events you might find on an Window. <p>
11: */
12: public class FrameRecorder extends WindowRecorder {
13:
14: private Frame frame;
15: private int newState;
16:
17: public FrameRecorder(Resolver resolver) {
18: super (resolver);
19: }
20:
21: private int WINDOW_STATE_CHANGED = 9 + WindowEvent.WINDOW_FIRST;
22:
23: protected synchronized void init(int recordingType) {
24: super .init(recordingType);
25: frame = null;
26: }
27:
28: /** Additionally handle state change events (1.4 and later). */
29: protected boolean isWindowEvent(AWTEvent event) {
30: return ((event.getSource() instanceof Frame) && event.getID() == WINDOW_STATE_CHANGED)
31: || super .isWindowEvent(event);
32: }
33:
34: protected boolean parseWindowEvent(AWTEvent event) {
35: int id = event.getID();
36: boolean consumed = true;
37: if (id == WINDOW_STATE_CHANGED) {
38: frame = (Frame) event.getSource();
39: newState = getExtendedState(frame);
40: setFinished(true);
41: } else {
42: consumed = super .parseWindowEvent(event);
43: }
44: return consumed;
45: }
46:
47: protected Step createStep() {
48: if (getRecordingType() == SE_WINDOW && frame != null) {
49: return createFrameStateChange(frame, newState);
50: }
51: return super .createStep();
52: }
53:
54: protected Step createFrameStateChange(Frame frame, int newState) {
55: ComponentReference ref = getResolver().addComponent(frame);
56: return new Action(getResolver(), null,
57: newState == Frame.NORMAL ? "actionNormalize"
58: : "actionMaximize",
59: new String[] { ref.getID() }, Frame.class);
60: }
61:
62: protected Step createResize(Window window, Dimension size) {
63: Step step = null;
64: if (((Frame) window).isResizable()) {
65: ComponentReference ref = getResolver().addComponent(window);
66: step = new Action(getResolver(), null, "actionResize",
67: new String[] { ref.getID(),
68: String.valueOf(size.width),
69: String.valueOf(size.height), }, Frame.class);
70: }
71: return step;
72: }
73:
74: protected int getExtendedState(Frame frame) {
75: try {
76: Integer state = (Integer) Frame.class.getMethod(
77: "getExtendedState", new Class[] {}).invoke(frame,
78: new Object[] {});
79: Log.debug("State is " + state);
80: return state.intValue();
81: } catch (Exception e) {
82: return frame.getState();
83: }
84: }
85:
86: }
|