import com.rational.test.ft.object.interfaces.GuiTestObject;
import com.rational.test.ft.script.RationalTestScript;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
public class WTextField extends GuiTestObject {
public WTextField(TestObject textfield) {
super(textfield);
}
public void click()
{
super.click();
}
public void setText(String s) {
this.click(); //activate text field
this.clearText();
this.inputKeys(escapeSpecialChars(s));
}
protected static String escapeSpecialChars(String s){
if (s == null) return null;
//must replace curly braces first or they keep getting added.
String[] re_chars = { "{", "}", "~", "(", ")", "+", "^", "%" };
for (int i = 0; i< re_chars.length; i++){
s = Stringfuncs.replace(s, re_chars[i], "{" + re_chars[i] + "}");
}
return s;
}
public void clearText()
{
this.inputKeys("^a{ExtDelete}");
}
public void typeKeys(String s)
{
this.click();
this.inputKeys(s);
}
protected void inputKeys(String s)
{
RationalTestScript.getScreen().inputKeys(s);
}
public void setTextInputChars(String s)
{
this.click(); //activate text field
this.clearText();
this.inputChars(s);
}
public void typeChars(String s)
{
this.click();
inputChars(s);
}
protected void inputChars(String s)
{
RationalTestScript.getScreen().inputChars(s);
}
public String getText() {
return this.getProperty(".value").toString();
}
public void setTextThruClipboard(String s)
{
this.clearText();
//set clipboard content with specified string
this.setClipboardText(s);
//paste clipboard contents
this.typeKeys("^v");
}
protected void setClipboardText(String s)
{
//get clipboard object
Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
//set clipboard contents
StringSelection ss = new java.awt.datatransfer.StringSelection(s);
clip.setContents(ss, ss);
}
}