1 /*
   2  * Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package org.jemmy.input;
  25 
  26 import org.jemmy.control.Wrap;
  27 import org.jemmy.interfaces.CaretOwner;
  28 import org.jemmy.interfaces.IntervalSelector;
  29 import org.jemmy.interfaces.Keyboard.KeyboardButton;
  30 import org.jemmy.interfaces.Keyboard.KeyboardButtons;
  31 import org.jemmy.interfaces.Keyboard.KeyboardModifier;
  32 
  33 /**
  34  *
  35  * @author shura
  36  */
  37 public class TextCaret extends CaretImpl implements IntervalSelector {
  38 
  39     /**
  40      *
  41      * @param wrap
  42      * @param scroll
  43      */
  44     public TextCaret(Wrap<?> wrap, CaretOwner scroll) {
  45         super(wrap, scroll);
  46         addScrollAction(new KeyboardScrollAction(KeyboardButtons.LEFT, KeyboardButtons.RIGHT));
  47     }
  48 
  49     /**
  50      *
  51      * @param down
  52      * @param downMods
  53      * @param up
  54      * @param upMods
  55      */
  56     public void addNavKeys(KeyboardButton down, KeyboardModifier[] downMods,
  57             KeyboardButton up, KeyboardModifier[] upMods) {
  58         addScrollAction(new CaretImpl.KeyboardScrollAction(down, downMods, up, upMods));
  59     }
  60 
  61     /**
  62      *
  63      * @param down
  64      * @param up
  65      */
  66     public void addNavKeys(KeyboardButton down, KeyboardButton up) {
  67         addNavKeys(down, new KeyboardModifier[0], up, new KeyboardModifier[0]);
  68     }
  69 
  70     public void selectTo(double value) {
  71         getWrap().keyboard().pressKey(KeyboardButtons.SHIFT);
  72         to(value);
  73         getWrap().keyboard().releaseKey(KeyboardButtons.SHIFT);
  74     }
  75 
  76     public void selectTo(Direction condition) {
  77         getWrap().keyboard().pressKey(KeyboardButtons.SHIFT);
  78         to(condition);
  79         getWrap().keyboard().releaseKey(KeyboardButtons.SHIFT);
  80     }
  81 }