
org.jemmy.input.TextImpl Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.jemmy.input;
import org.jemmy.action.Action;
import org.jemmy.control.Wrap;
import org.jemmy.interfaces.Focusable;
import org.jemmy.interfaces.Keyboard;
import org.jemmy.interfaces.Keyboard.KeyboardButtons;
import org.jemmy.interfaces.Keyboard.KeyboardModifiers;
import org.jemmy.interfaces.Text;
import org.jemmy.timing.State;
import static org.jemmy.interfaces.Keyboard.KeyboardButtons.*;
/**
*
* @author shura
*/
public abstract class TextImpl implements Text {
private static final int DEFAULT_SELECT_ALL_CLICK_COUNT = 3;
private Wrap> target;
private int selectAllClickCount = DEFAULT_SELECT_ALL_CLICK_COUNT;
boolean keyboardSelection;
protected TextImpl(Wrap> target, boolean keyboardSelection) {
this.target = target;
this.keyboardSelection = keyboardSelection;
}
protected TextImpl(Wrap> target) {
this(target, false);
}
public Wrap> getWrap() {
return target;
}
/**
* Types text into the control. Wrap may implement Focusable.
*
* @see Focusable
* @param newText the new text
*/
public void type(final String newText) {
target.getEnvironment().getExecutor().execute(target.getEnvironment(), false, new Action() {
public void run(Object... parameters) {
if (target.is(Focusable.class)) {
target.as(Focusable.class).focuser().focus();
}
char[] chars = newText.toCharArray();
Keyboard kb = target.keyboard();
for (char c : chars) {
kb.typeChar(c);
}
target.getEnvironment().getWaiter(Wrap.WAIT_STATE_TIMEOUT.getName()).ensureState(new State
© 2015 - 2025 Weber Informatics LLC | Privacy Policy