1
|
|
package abbot.editor.recorder;
|
2
|
|
|
3
|
|
import java.awt.*;
|
4
|
|
import java.awt.event.ComponentEvent;
|
5
|
|
|
6
|
|
import javax.swing.JInternalFrame;
|
7
|
|
import javax.swing.event.InternalFrameEvent;
|
8
|
|
|
9
|
|
import abbot.Log;
|
10
|
|
import abbot.script.*;
|
11
|
|
import abbot.tester.ComponentTester;
|
12
|
|
import abbot.util.AWT;
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
public class JInternalFrameRecorder extends JComponentRecorder {
|
24
|
|
private JInternalFrame frame;
|
25
|
|
private String type;
|
26
|
|
private static final String UNKNOWN = "unknown";
|
27
|
|
private static final String SHOW = "show";
|
28
|
|
private static final String HIDE = "hide";
|
29
|
|
private static final String CLOSE = "close";
|
30
|
|
private static final String ICONIFY = "iconify";
|
31
|
|
private static final String DEICONIFY = "deiconify";
|
32
|
|
private static final String MOVE = "move";
|
33
|
|
private static final String RESIZE = "resize";
|
34
|
|
|
35
|
|
public static final int SE_INTERNAL_FRAME = SE_ACTION_MAP + 1;
|
36
|
|
public static final int SE_DECORATION = SE_INTERNAL_FRAME + 1;
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
60
|
public JInternalFrameRecorder(Resolver resolver) {
|
43
|
60
|
super(resolver);
|
44
|
|
}
|
45
|
|
|
46
|
12
|
protected void init(int rtype) {
|
47
|
12
|
super.init(rtype);
|
48
|
12
|
frame = null;
|
49
|
12
|
type = UNKNOWN;
|
50
|
|
}
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
39
|
public boolean accept(AWTEvent event) {
|
56
|
39
|
int id = event.getID();
|
57
|
39
|
Log.debug("Source is " + event.getSource());
|
58
|
39
|
if (event.getSource() instanceof JInternalFrame) {
|
59
|
12
|
if (id == ComponentEvent.COMPONENT_SHOWN
|
60
|
|
|| id == ComponentEvent.COMPONENT_HIDDEN
|
61
|
|
|| id == ComponentEvent.COMPONENT_MOVED
|
62
|
|
|| id == ComponentEvent.COMPONENT_RESIZED
|
63
|
|
|| id == InternalFrameEvent.INTERNAL_FRAME_CLOSING
|
64
|
|
|| id == InternalFrameEvent.INTERNAL_FRAME_ICONIFIED
|
65
|
|
|| id == InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED) {
|
66
|
8
|
init(SE_INTERNAL_FRAME);
|
67
|
8
|
return true;
|
68
|
|
}
|
69
|
|
}
|
70
|
27
|
else if (AWT.isInternalFrameDecoration((Component)event.getSource())) {
|
71
|
4
|
init(SE_DECORATION);
|
72
|
4
|
return true;
|
73
|
|
}
|
74
|
27
|
return false;
|
75
|
|
}
|
76
|
|
|
77
|
12
|
public boolean parse(AWTEvent event) {
|
78
|
12
|
boolean consumed = true;
|
79
|
12
|
switch(getRecordingType()) {
|
80
|
8
|
case SE_INTERNAL_FRAME:
|
81
|
8
|
consumed = parseInternalFrameAction(event);
|
82
|
8
|
break;
|
83
|
4
|
case SE_DECORATION:
|
84
|
4
|
setFinished(true);
|
85
|
4
|
break;
|
86
|
0
|
default:
|
87
|
0
|
consumed = super.parse(event);
|
88
|
0
|
break;
|
89
|
|
}
|
90
|
12
|
return consumed;
|
91
|
|
}
|
92
|
|
|
93
|
8
|
protected boolean parseInternalFrameAction(AWTEvent event) {
|
94
|
8
|
frame = (JInternalFrame)event.getSource();
|
95
|
8
|
switch(event.getID()) {
|
96
|
1
|
case ComponentEvent.COMPONENT_SHOWN:
|
97
|
1
|
type = SHOW;
|
98
|
1
|
break;
|
99
|
2
|
case ComponentEvent.COMPONENT_HIDDEN:
|
100
|
2
|
type = HIDE;
|
101
|
2
|
break;
|
102
|
1
|
case ComponentEvent.COMPONENT_RESIZED:
|
103
|
1
|
type = RESIZE;
|
104
|
1
|
break;
|
105
|
1
|
case ComponentEvent.COMPONENT_MOVED:
|
106
|
1
|
type = MOVE;
|
107
|
1
|
break;
|
108
|
1
|
case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
|
109
|
1
|
type = CLOSE;
|
110
|
1
|
break;
|
111
|
1
|
case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
|
112
|
1
|
type = ICONIFY;
|
113
|
1
|
break;
|
114
|
1
|
case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
|
115
|
1
|
type = DEICONIFY;
|
116
|
1
|
break;
|
117
|
0
|
default:
|
118
|
0
|
throw new IllegalArgumentException("Unrecognized event: " + event);
|
119
|
|
}
|
120
|
8
|
setFinished(true);
|
121
|
8
|
return true;
|
122
|
|
}
|
123
|
|
|
124
|
12
|
protected Step createStep() {
|
125
|
12
|
Step step;
|
126
|
12
|
switch(getRecordingType()) {
|
127
|
8
|
case SE_INTERNAL_FRAME:
|
128
|
8
|
step = createInternalFrameAction(frame, type);
|
129
|
8
|
break;
|
130
|
4
|
case SE_DECORATION:
|
131
|
4
|
step = null;
|
132
|
4
|
break;
|
133
|
0
|
default:
|
134
|
0
|
step = super.createStep();
|
135
|
0
|
break;
|
136
|
|
}
|
137
|
12
|
return step;
|
138
|
|
}
|
139
|
|
|
140
|
8
|
protected Step createInternalFrameAction(JInternalFrame target,
|
141
|
|
String type) {
|
142
|
8
|
ComponentReference ref = getResolver().addComponent(target);
|
143
|
8
|
if (type == SHOW || type == HIDE) {
|
144
|
3
|
Assert step = new Assert(getResolver(),
|
145
|
|
null,
|
146
|
|
ComponentTester.class.getName(),
|
147
|
|
"assertComponentShowing",
|
148
|
|
new String[] { ref.getID() },
|
149
|
|
"true", type == HIDE);
|
150
|
3
|
step.setWait(true);
|
151
|
3
|
return step;
|
152
|
|
}
|
153
|
5
|
else if (type == MOVE) {
|
154
|
1
|
Point loc = target.getLocation();
|
155
|
1
|
return new Action(getResolver(), null,
|
156
|
|
"actionMove", new String[] {
|
157
|
|
ref.getID(),
|
158
|
|
String.valueOf(loc.x),
|
159
|
|
String.valueOf(loc.y)
|
160
|
|
}, JInternalFrame.class);
|
161
|
|
}
|
162
|
4
|
else if (type == RESIZE) {
|
163
|
1
|
Dimension size = target.getSize();
|
164
|
1
|
return new Action(getResolver(), null,
|
165
|
|
"actionResize", new String[] {
|
166
|
|
ref.getID(),
|
167
|
|
String.valueOf(size.width),
|
168
|
|
String.valueOf(size.height)
|
169
|
|
}, JInternalFrame.class);
|
170
|
|
}
|
171
|
|
else {
|
172
|
3
|
String action = type == CLOSE
|
173
|
|
? "actionClose"
|
174
|
2
|
: ((type == ICONIFY)
|
175
|
|
? "actionIconify" : "actionDeiconify");
|
176
|
3
|
return new Action(getResolver(), null,
|
177
|
|
action, new String[] { ref.getID() },
|
178
|
|
JInternalFrame.class);
|
179
|
|
}
|
180
|
|
}
|
181
|
|
}
|
182
|
|
|