1
|
|
package abbot.editor.recorder;
|
2
|
|
|
3
|
|
import java.awt.*;
|
4
|
|
import java.awt.event.*;
|
5
|
|
|
6
|
|
import javax.swing.text.JTextComponent;
|
7
|
|
|
8
|
|
import abbot.Log;
|
9
|
|
import abbot.tester.Robot;
|
10
|
|
import abbot.script.*;
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
public class JTextComponentRecorder extends JComponentRecorder {
|
16
|
|
|
17
|
|
private JTextComponent target;
|
18
|
|
private int startIndex;
|
19
|
|
private int endIndex;
|
20
|
|
|
21
|
|
public static final int SE_SELECTION = 30;
|
22
|
|
|
23
|
37
|
public JTextComponentRecorder(Resolver resolver) {
|
24
|
37
|
super(resolver);
|
25
|
|
}
|
26
|
|
|
27
|
158
|
protected void init(int rtype) {
|
28
|
158
|
super.init(rtype);
|
29
|
158
|
target = null;
|
30
|
158
|
startIndex = -1;
|
31
|
158
|
endIndex = -1;
|
32
|
|
}
|
33
|
|
|
34
|
|
|
35
|
123
|
protected boolean isMappedEvent(KeyEvent ev) {
|
36
|
123
|
if (super.isMappedEvent(ev)) {
|
37
|
27
|
javax.swing.Action action = getAction(ev);
|
38
|
27
|
return !"default-typed".equals(action.getValue(javax.swing.Action.NAME));
|
39
|
|
}
|
40
|
96
|
return false;
|
41
|
|
}
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
10
|
protected boolean dragStarted(Component target,
|
47
|
|
int x, int y,
|
48
|
|
int modifiers,
|
49
|
|
MouseEvent dragEvent) {
|
50
|
10
|
Log.debug("Tracking text selection");
|
51
|
10
|
setRecordingType(SE_DROP);
|
52
|
10
|
this.target = (JTextComponent)target;
|
53
|
10
|
startIndex = this.target.viewToModel(new Point(x, y));
|
54
|
|
|
55
|
10
|
return true;
|
56
|
|
}
|
57
|
|
|
58
|
20
|
protected boolean parseDrop(AWTEvent event) {
|
59
|
20
|
boolean consumed = super.parseDrop(event);
|
60
|
20
|
if (event.getID() == MouseEvent.MOUSE_DRAGGED) {
|
61
|
8
|
MouseEvent me = (MouseEvent)event;
|
62
|
8
|
endIndex = target.viewToModel(me.getPoint());
|
63
|
|
}
|
64
|
12
|
else if (event.getID() == MouseEvent.MOUSE_RELEASED) {
|
65
|
10
|
endIndex = target.viewToModel(((MouseEvent)event).getPoint());
|
66
|
10
|
setFinished(true);
|
67
|
|
}
|
68
|
20
|
return consumed;
|
69
|
|
}
|
70
|
|
|
71
|
50
|
protected Step createStep() {
|
72
|
50
|
Step step;
|
73
|
50
|
if (getRecordingType() == SE_DROP) {
|
74
|
10
|
step = createDrop(target, startIndex, endIndex);
|
75
|
|
}
|
76
|
|
else {
|
77
|
40
|
step = super.createStep();
|
78
|
|
}
|
79
|
50
|
return step;
|
80
|
|
}
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
3
|
protected Step createClick(Component comp, int x, int y,
|
85
|
|
int mods, int count) {
|
86
|
3
|
if (mods == MouseEvent.BUTTON1_MASK && count == 1) {
|
87
|
3
|
ComponentReference cr = getResolver().addComponent(comp);
|
88
|
3
|
JTextComponent tc = (JTextComponent)comp;
|
89
|
3
|
int index = tc.viewToModel(new Point(x, y));
|
90
|
3
|
return new Action(getResolver(), null,
|
91
|
|
"actionClick", new String[] {
|
92
|
|
cr.getID(),
|
93
|
|
String.valueOf(index),
|
94
|
|
}, JTextComponent.class);
|
95
|
|
}
|
96
|
|
else {
|
97
|
0
|
return super.createClick(comp, x, y, mods, count);
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|
101
|
10
|
protected Step createDrop(Component comp, int start, int end) {
|
102
|
10
|
ComponentReference cr = getResolver().addComponent(comp);
|
103
|
10
|
return new Action(getResolver(), null,
|
104
|
|
"actionSelectText", new String[] {
|
105
|
|
cr.getID(),
|
106
|
|
String.valueOf(start),
|
107
|
|
String.valueOf(end)
|
108
|
|
}, JTextComponent.class);
|
109
|
|
}
|
110
|
|
}
|
111
|
|
|
112
|
|
|