001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id: AWTTextKeyboardDriver.java,v 1.5 2007/10/05 11:37:08 jskrivanek Exp $ $Revision: 1.5 $ $Date: 2007/10/05 11:37:08 $
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.text;
048:
049: import java.awt.event.InputEvent;
050: import java.awt.event.KeyEvent;
051:
052: import org.netbeans.jemmy.Timeout;
053:
054: import org.netbeans.jemmy.operators.ComponentOperator;
055: import org.netbeans.jemmy.operators.TextAreaOperator;
056: import org.netbeans.jemmy.operators.TextComponentOperator;
057:
058: /**
059: * TextDriver for AWT text component types.
060: * Uses keyboard operations.
061: *
062: * @author Alexandre Iline(alexandre.iline@sun.com)
063: */
064: public class AWTTextKeyboardDriver extends TextKeyboardDriver {
065: /**
066: * Constructs a AWTTextKeyboardDriver.
067: */
068: public AWTTextKeyboardDriver() {
069: super (
070: new String[] { "org.netbeans.jemmy.operators.TextComponentOperator" });
071: }
072:
073: public String getText(ComponentOperator oper) {
074: return (((TextComponentOperator) oper).getText());
075: }
076:
077: public int getCaretPosition(ComponentOperator oper) {
078: return (((TextComponentOperator) oper).getCaretPosition());
079: }
080:
081: public int getSelectionStart(ComponentOperator oper) {
082: return (((TextComponentOperator) oper).getSelectionStart());
083: }
084:
085: public int getSelectionEnd(ComponentOperator oper) {
086: return (((TextComponentOperator) oper).getSelectionEnd());
087: }
088:
089: public NavigationKey[] getKeys(ComponentOperator oper) {
090: boolean multiString = oper instanceof TextAreaOperator;
091: NavigationKey[] result = new NavigationKey[multiString ? 4 : 2];
092: result[0] = new UpKey(KeyEvent.VK_LEFT, 0);
093: result[1] = new DownKey(KeyEvent.VK_RIGHT, 0);
094: ((UpKey) result[0]).setDownKey((DownKey) result[1]);
095: ((DownKey) result[1]).setUpKey((UpKey) result[0]);
096: if (multiString) {
097: result[2] = new UpKey(KeyEvent.VK_UP, 0);
098: result[3] = new DownKey(KeyEvent.VK_DOWN, 0);
099: ((UpKey) result[2]).setDownKey((DownKey) result[3]);
100: ((DownKey) result[3]).setUpKey((UpKey) result[2]);
101: }
102: return (result);
103: }
104:
105: public Timeout getBetweenTimeout(ComponentOperator oper) {
106: return (oper.getTimeouts()
107: .create("TextComponentOperator.BetweenKeysTimeout"));
108: }
109: }
|