01: package abbot.tester;
02:
03: import java.awt.*;
04: import abbot.util.Bugs;
05:
06: /** Provides user actions for TextComponent-derived components. */
07: public class TextComponentTester extends ComponentTester {
08:
09: /**
10: * Type the given text into the given component, replacing all
11: * text already there.
12: */
13: public void actionEnterText(Component c, String text) {
14: actionSelectText(c, 0, ((TextComponent) c).getText().length());
15: actionKeyString(c, text);
16: }
17:
18: /** Set the caret position. */
19: public void actionSetCaretPosition(Component c, final int index) {
20: final TextComponent tc = (TextComponent) c;
21: invokeLater(c, new Runnable() {
22: public void run() {
23: tc.setCaretPosition(index);
24: }
25: });
26: }
27:
28: /** Start a selection at the given index. */
29: public void actionStartSelection(Component c, final int index) {
30: final TextComponent tc = (TextComponent) c;
31: invokeLater(c, new Runnable() {
32: public void run() {
33: tc.setSelectionStart(index);
34: }
35: });
36: }
37:
38: /** Terminate a selection on the given index. */
39: public void actionEndSelection(Component c, final int index) {
40: final TextComponent tc = (TextComponent) c;
41: invokeLater(c, new Runnable() {
42: public void run() {
43: tc.setSelectionEnd(index);
44: }
45: });
46: }
47:
48: /** Select the given text range. */
49: public void actionSelectText(Component c, final int start,
50: final int end) {
51: final TextComponent tc = (TextComponent) c;
52: invokeAndWait(c, new Runnable() {
53: public void run() {
54: tc.select(start, end);
55: }
56: });
57: if (Bugs.hasTextComponentSelectionDelay())
58: delay(100);
59: }
60: }
|