< prev index next >

core/JemmyCore/src/org/jemmy/input/TextImpl.java

Print this page




  28 import org.jemmy.control.Wrap;
  29 import org.jemmy.interfaces.Focusable;
  30 import org.jemmy.interfaces.Keyboard;
  31 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  32 import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
  33 import org.jemmy.interfaces.Text;
  34 import org.jemmy.timing.State;
  35 import static org.jemmy.interfaces.Keyboard.KeyboardButtons.*;
  36 
  37 /**
  38  *
  39  * @author shura
  40  */
  41 public abstract class TextImpl implements Text {
  42 
  43     private static final int DEFAULT_SELECT_ALL_CLICK_COUNT = 3;
  44     private Wrap<?> target;
  45     private int selectAllClickCount = DEFAULT_SELECT_ALL_CLICK_COUNT;
  46     boolean keyboardSelection;
  47 
  48     /**
  49      *
  50      * @param target
  51      * @param keyboardSelection
  52      */
  53     protected TextImpl(Wrap<?> target, boolean keyboardSelection) {
  54         this.target = target;
  55         this.keyboardSelection = keyboardSelection;
  56     }
  57 
  58     /**
  59      *
  60      * @param target
  61      */
  62     protected TextImpl(Wrap<?> target) {
  63         this(target, false);
  64     }
  65 
  66     /**
  67      *
  68      * @return
  69      */
  70     public Wrap<?> getWrap() {
  71         return target;
  72     }
  73 
  74     /**
  75      * Types text into the control. Wrap may implement Focusable.
  76      *
  77      * @see Focusable
  78      * @param newText
  79      */
  80     public void type(final String newText) {
  81         target.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() {
  82             public void run(Object... parameters) {
  83                 if (target.is(Focusable.class)) {
  84                     target.as(Focusable.class).focuser().focus();
  85                 }
  86                 char[] chars = newText.toCharArray();
  87                 Keyboard kb = target.keyboard();
  88                 for (char c : chars) {
  89                     kb.typeChar(c);
  90                 }
  91                 target.getEnvironment().getWaiter(Wrap.WAIT_STATE_TIMEOUT.getName()).ensureState(new State<Object>() {
  92                     public Object reached() {
  93                         return text().contains(newText) ? "" : null;
  94                     }
  95 
  96                     @Override
  97                     public String toString() {
  98                         return "text() equals '" + newText + "', text() = '" + text() + "'";




  28 import org.jemmy.control.Wrap;
  29 import org.jemmy.interfaces.Focusable;
  30 import org.jemmy.interfaces.Keyboard;
  31 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  32 import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
  33 import org.jemmy.interfaces.Text;
  34 import org.jemmy.timing.State;
  35 import static org.jemmy.interfaces.Keyboard.KeyboardButtons.*;
  36 
  37 /**
  38  *
  39  * @author shura
  40  */
  41 public abstract class TextImpl implements Text {
  42 
  43     private static final int DEFAULT_SELECT_ALL_CLICK_COUNT = 3;
  44     private Wrap<?> target;
  45     private int selectAllClickCount = DEFAULT_SELECT_ALL_CLICK_COUNT;
  46     boolean keyboardSelection;
  47 





  48     protected TextImpl(Wrap<?> target, boolean keyboardSelection) {
  49         this.target = target;
  50         this.keyboardSelection = keyboardSelection;
  51     }
  52 




  53     protected TextImpl(Wrap<?> target) {
  54         this(target, false);
  55     }
  56 




  57     public Wrap<?> getWrap() {
  58         return target;
  59     }
  60 
  61     /**
  62      * Types text into the control. Wrap may implement Focusable.
  63      *
  64      * @see Focusable
  65      * @param newText the new text
  66      */
  67     public void type(final String newText) {
  68         target.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() {
  69             public void run(Object... parameters) {
  70                 if (target.is(Focusable.class)) {
  71                     target.as(Focusable.class).focuser().focus();
  72                 }
  73                 char[] chars = newText.toCharArray();
  74                 Keyboard kb = target.keyboard();
  75                 for (char c : chars) {
  76                     kb.typeChar(c);
  77                 }
  78                 target.getEnvironment().getWaiter(Wrap.WAIT_STATE_TIMEOUT.getName()).ensureState(new State<Object>() {
  79                     public Object reached() {
  80                         return text().contains(newText) ? "" : null;
  81                     }
  82 
  83                     @Override
  84                     public String toString() {
  85                         return "text() equals '" + newText + "', text() = '" + text() + "'";


< prev index next >