< prev index next >

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

Print this page




  28 import org.jemmy.control.Wrap;
  29 import org.jemmy.env.Environment;
  30 import org.jemmy.interfaces.Keyboard.KeyboardButton;
  31 import org.jemmy.interfaces.Keyboard.KeyboardModifier;
  32 import org.jemmy.interfaces.Text;
  33 
  34 /**
  35  *
  36  * @author shura
  37  */
  38 public abstract class CaretText extends AbstractCaretOwner implements Text {
  39 
  40     static {
  41         Environment.getEnvironment().setPropertyIfNotSet(RegexCaretDirection.REGEX_FLAGS, 0);
  42     }
  43 
  44     TextCaret caret;
  45     TextImpl text;
  46     Wrap<?> wrap;
  47 
  48     /**
  49      *
  50      * @param wrap
  51      */
  52     public CaretText(Wrap<?> wrap) {
  53         this.wrap = wrap;
  54         text = new TextImpl(wrap) {
  55             public String text() {
  56                 return CaretText.this.text();
  57             }
  58         };
  59     }
  60 
  61     public TextCaret caret() {
  62         if (caret == null) {
  63             initCaret();
  64         }
  65         return caret;
  66     }
  67 
  68     protected void initCaret() {
  69         caret = new TextCaret(wrap, this);
  70     }
  71 
  72     /**
  73      *
  74      * @return
  75      */
  76     protected int getFlags() {
  77         return (Integer)wrap.getEnvironment().
  78                 getProperty(RegexCaretDirection.REGEX_FLAGS, 0);
  79     }
  80 
  81     public void type(String newText) {
  82         text.type(newText);
  83     }
  84 
  85     public void clear() {
  86         text.clear();
  87     }
  88 
  89     /**
  90      * Moves caret to a beginning/end of an <code>index</code>'th occurance of the regex.
  91      * @param regex
  92      * @param front
  93      * @param index

  94      */
  95     public void to(String regex, boolean front, int index) {
  96         caret().to(new RegexCaretDirection(this, this, regex, getFlags(), front, index));
  97     }
  98 
  99     /**
 100      * Moves caret to a beginning/end of the first occurance of the regex.
 101      * @param regex
 102      * @param front

 103      */
 104     public void to(String regex, boolean front) {
 105         to(regex, front, 0);
 106     }
 107 
 108     /**
 109      * Moves caret to a beginning the first occurance of the regex.
 110      * @param regex

 111      */
 112     public void to(String regex) {
 113         to(regex, true);
 114     }
 115 
 116     /**
 117      *
 118      * @param left
 119      * @param leftMods
 120      * @param right
 121      * @param rightMods
 122      */
 123     public void addNavKeys(KeyboardButton left, KeyboardModifier[] leftMods,
 124             KeyboardButton right, KeyboardModifier[] rightMods) {
 125         caret().addNavKeys(left, leftMods, right, rightMods);
 126     }
 127 
 128     /**
 129      *
 130      * @param left
 131      * @param right
 132      */
 133     public void addNavKeys(KeyboardButton left, KeyboardButton right) {
 134         addNavKeys(left, new KeyboardModifier[0], right, new KeyboardModifier[0]);
 135     }
 136 }


  28 import org.jemmy.control.Wrap;
  29 import org.jemmy.env.Environment;
  30 import org.jemmy.interfaces.Keyboard.KeyboardButton;
  31 import org.jemmy.interfaces.Keyboard.KeyboardModifier;
  32 import org.jemmy.interfaces.Text;
  33 
  34 /**
  35  *
  36  * @author shura
  37  */
  38 public abstract class CaretText extends AbstractCaretOwner implements Text {
  39 
  40     static {
  41         Environment.getEnvironment().setPropertyIfNotSet(RegexCaretDirection.REGEX_FLAGS, 0);
  42     }
  43 
  44     TextCaret caret;
  45     TextImpl text;
  46     Wrap<?> wrap;
  47 




  48     public CaretText(Wrap<?> wrap) {
  49         this.wrap = wrap;
  50         text = new TextImpl(wrap) {
  51             public String text() {
  52                 return CaretText.this.text();
  53             }
  54         };
  55     }
  56 
  57     public TextCaret caret() {
  58         if (caret == null) {
  59             initCaret();
  60         }
  61         return caret;
  62     }
  63 
  64     protected void initCaret() {
  65         caret = new TextCaret(wrap, this);
  66     }
  67 




  68     protected int getFlags() {
  69         return (Integer)wrap.getEnvironment().
  70                 getProperty(RegexCaretDirection.REGEX_FLAGS, 0);
  71     }
  72 
  73     public void type(String newText) {
  74         text.type(newText);
  75     }
  76 
  77     public void clear() {
  78         text.clear();
  79     }
  80 
  81     /**
  82      * Moves caret to a beginning/end of an <code>index</code>'th occurance of the regex.
  83      *
  84      * @param regex the regular expression to search for
  85      * @param front todo document
  86      * @param index todo document
  87      */
  88     public void to(String regex, boolean front, int index) {
  89         caret().to(new RegexCaretDirection(this, this, regex, getFlags(), front, index));
  90     }
  91 
  92     /**
  93      * Moves caret to a beginning/end of the first occurance of the regex.
  94      *
  95      * @param regex the regular expression to search for
  96      * @param front todo document
  97      */
  98     public void to(String regex, boolean front) {
  99         to(regex, front, 0);
 100     }
 101 
 102     /**
 103      * Moves caret to a beginning the first occurance of the regex.
 104      *
 105      * @param regex the regular expression to search for
 106      */
 107     public void to(String regex) {
 108         to(regex, true);
 109     }
 110 







 111     public void addNavKeys(KeyboardButton left, KeyboardModifier[] leftMods,
 112             KeyboardButton right, KeyboardModifier[] rightMods) {
 113         caret().addNavKeys(left, leftMods, right, rightMods);
 114     }
 115 





 116     public void addNavKeys(KeyboardButton left, KeyboardButton right) {
 117         addNavKeys(left, new KeyboardModifier[0], right, new KeyboardModifier[0]);
 118     }
 119 }
< prev index next >