1/* 2 * Copyright (c) 1997, 2016, 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 */ 23package org.netbeans.jemmy.drivers.text; 24 25import java.awt.event.KeyEvent; 26 27import org.netbeans.jemmy.Timeout; 28import org.netbeans.jemmy.operators.ComponentOperator; 29import org.netbeans.jemmy.operators.TextAreaOperator; 30import org.netbeans.jemmy.operators.TextComponentOperator; 31 32/** 33 * TextDriver for AWT text component types. Uses keyboard operations. 34 * 35 * @author Alexandre Iline(alexandre.iline@oracle.com) 36 */ 37public class AWTTextKeyboardDriver extends TextKeyboardDriver { 38 39 /** 40 * Constructs a AWTTextKeyboardDriver. 41 */ 42 public AWTTextKeyboardDriver() { 43 super(new String[]{"org.netbeans.jemmy.operators.TextComponentOperator"}); 44 } 45 46 @Override 47 public String getText(ComponentOperator oper) { 48 return ((TextComponentOperator) oper).getText(); 49 } 50 51 @Override 52 public int getCaretPosition(ComponentOperator oper) { 53 return ((TextComponentOperator) oper).getCaretPosition(); 54 } 55 56 @Override 57 public int getSelectionStart(ComponentOperator oper) { 58 return ((TextComponentOperator) oper).getSelectionStart(); 59 } 60 61 @Override 62 public int getSelectionEnd(ComponentOperator oper) { 63 return ((TextComponentOperator) oper).getSelectionEnd(); 64 } 65 66 @Override 67 public NavigationKey[] getKeys(ComponentOperator oper) { 68 boolean multiString = oper instanceof TextAreaOperator; 69 NavigationKey[] result = new NavigationKey[multiString ? 4 : 2]; 70 result[0] = new UpKey(KeyEvent.VK_LEFT, 0); 71 result[1] = new DownKey(KeyEvent.VK_RIGHT, 0); 72 ((UpKey) result[0]).setDownKey((DownKey) result[1]); 73 ((DownKey) result[1]).setUpKey((UpKey) result[0]); 74 if (multiString) { 75 result[2] = new UpKey(KeyEvent.VK_UP, 0); 76 result[3] = new DownKey(KeyEvent.VK_DOWN, 0); 77 ((UpKey) result[2]).setDownKey((DownKey) result[3]); 78 ((DownKey) result[3]).setUpKey((UpKey) result[2]); 79 } 80 return result; 81 } 82 83 @Override 84 public Timeout getBetweenTimeout(ComponentOperator oper) { 85 return oper.getTimeouts().create("TextComponentOperator.BetweenKeysTimeout"); 86 } 87} 88