001: package abbot.editor.recorder;
002:
003: import java.awt.*;
004: import java.awt.event.ComponentEvent;
005:
006: import javax.swing.JInternalFrame;
007: import javax.swing.event.InternalFrameEvent;
008:
009: import abbot.Log;
010: import abbot.script.*;
011: import abbot.tester.ComponentTester;
012: import abbot.util.AWT;
013:
014: /**
015: * Handle the recording of events related to an internal frame
016: * (JInternalFrame). Like instances of Window, we must insert
017: * waits for the showing and hiding of internal frames.
018: * <P>
019: * NOTE: InternalFrameEvents are not normally posted to the AWT event queue.
020: * @author pickens
021: * @author twall
022: */
023: public class JInternalFrameRecorder extends JComponentRecorder {
024: private JInternalFrame frame;
025: private String type;
026: private static final String UNKNOWN = "unknown";
027: private static final String SHOW = "show";
028: private static final String HIDE = "hide";
029: private static final String CLOSE = "close";
030: private static final String ICONIFY = "iconify";
031: private static final String DEICONIFY = "deiconify";
032: private static final String MOVE = "move";
033: private static final String RESIZE = "resize";
034:
035: public static final int SE_INTERNAL_FRAME = SE_ACTION_MAP + 1;
036: public static final int SE_DECORATION = SE_INTERNAL_FRAME + 1;
037:
038: /**
039: * Constructor for JInternalFrameRecorder.
040: * @param resolver
041: */
042: public JInternalFrameRecorder(Resolver resolver) {
043: super (resolver);
044: }
045:
046: protected void init(int rtype) {
047: super .init(rtype);
048: frame = null;
049: type = UNKNOWN;
050: }
051:
052: /**
053: * @see abbot.editor.recorder.ComponentRecorder#accept(java.awt.AWTEvent)
054: */
055: public boolean accept(AWTEvent event) {
056: int id = event.getID();
057: Log.debug("Source is " + event.getSource());
058: if (event.getSource() instanceof JInternalFrame) {
059: if (id == ComponentEvent.COMPONENT_SHOWN
060: || id == ComponentEvent.COMPONENT_HIDDEN
061: || id == ComponentEvent.COMPONENT_MOVED
062: || id == ComponentEvent.COMPONENT_RESIZED
063: || id == InternalFrameEvent.INTERNAL_FRAME_CLOSING
064: || id == InternalFrameEvent.INTERNAL_FRAME_ICONIFIED
065: || id == InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED) {
066: init(SE_INTERNAL_FRAME);
067: return true;
068: }
069: } else if (AWT.isInternalFrameDecoration((Component) event
070: .getSource())) {
071: init(SE_DECORATION);
072: return true;
073: }
074: return false;
075: }
076:
077: public boolean parse(AWTEvent event) {
078: boolean consumed = true;
079: switch (getRecordingType()) {
080: case SE_INTERNAL_FRAME:
081: consumed = parseInternalFrameAction(event);
082: break;
083: case SE_DECORATION:
084: setFinished(true);
085: break;
086: default:
087: consumed = super .parse(event);
088: break;
089: }
090: return consumed;
091: }
092:
093: protected boolean parseInternalFrameAction(AWTEvent event) {
094: frame = (JInternalFrame) event.getSource();
095: switch (event.getID()) {
096: case ComponentEvent.COMPONENT_SHOWN:
097: type = SHOW;
098: break;
099: case ComponentEvent.COMPONENT_HIDDEN:
100: type = HIDE;
101: break;
102: case ComponentEvent.COMPONENT_RESIZED:
103: type = RESIZE;
104: break;
105: case ComponentEvent.COMPONENT_MOVED:
106: type = MOVE;
107: break;
108: case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
109: type = CLOSE;
110: break;
111: case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
112: type = ICONIFY;
113: break;
114: case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
115: type = DEICONIFY;
116: break;
117: default:
118: throw new IllegalArgumentException("Unrecognized event: "
119: + event);
120: }
121: setFinished(true);
122: return true;
123: }
124:
125: protected Step createStep() {
126: Step step;
127: switch (getRecordingType()) {
128: case SE_INTERNAL_FRAME:
129: step = createInternalFrameAction(frame, type);
130: break;
131: case SE_DECORATION:
132: step = null;
133: break;
134: default:
135: step = super .createStep();
136: break;
137: }
138: return step;
139: }
140:
141: protected Step createInternalFrameAction(JInternalFrame target,
142: String type) {
143: ComponentReference ref = getResolver().addComponent(target);
144: if (type == SHOW || type == HIDE) {
145: Assert step = new Assert(getResolver(), null,
146: ComponentTester.class.getName(),
147: "assertComponentShowing", new String[] { ref
148: .getID() }, "true", type == HIDE);
149: step.setWait(true);
150: return step;
151: } else if (type == MOVE) {
152: Point loc = target.getLocation();
153: return new Action(getResolver(), null, "actionMove",
154: new String[] { ref.getID(), String.valueOf(loc.x),
155: String.valueOf(loc.y) },
156: JInternalFrame.class);
157: } else if (type == RESIZE) {
158: Dimension size = target.getSize();
159: return new Action(getResolver(), null, "actionResize",
160: new String[] { ref.getID(),
161: String.valueOf(size.width),
162: String.valueOf(size.height) },
163: JInternalFrame.class);
164: } else {
165: String action = type == CLOSE ? "actionClose"
166: : ((type == ICONIFY) ? "actionIconify"
167: : "actionDeiconify");
168: return new Action(getResolver(), null, action,
169: new String[] { ref.getID() }, JInternalFrame.class);
170: }
171: }
172: }
|