Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.control;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import org.jemmy.JemmyException;
import org.jemmy.Point;
import org.jemmy.Rectangle;
import org.jemmy.TimeoutExpiredException;
import org.jemmy.action.GetAction;
import org.jemmy.env.Environment;
import org.jemmy.env.TestOut;
import org.jemmy.env.Timeout;
import org.jemmy.image.Image;
import org.jemmy.interfaces.*;
import org.jemmy.timing.State;
/**
* This is a wrap which holds reference to a control without UI hierarchy. It
* also encapsulates all the logic to deal with the underlying control, in terms
* of implementations of ControlInterface.
*
* @see Wrap#as(java.lang.Class)
* @see Wrap#is(java.lang.Class)
* @param type of the encapsulated object.
* @author shura, erikgreijus
*/
@ControlType(Object.class)
@ControlInterfaces({Mouse.class, Keyboard.class, Drag.class})
public abstract class Wrap {
public static final String BOUNDS_PROP_NAME = "bounds";
public static final String CLICKPOINT_PROP_NAME = "clickPoint";
public static final String CONTROL_CLASS_PROP_NAME = "control.class";
public static final String CONTROL_PROP_NAME = "control";
public static final String INPUT_FACTORY_PROPERTY = "input.control.interface.factory";
public static final String IMAGE_LOADER_PROPERTY = "image.loader";
public static final String IMAGE_CAPTURER_PROPERTY = "image.capturer";
public static final String TEXT_PROP_NAME = "text";
public static final String POSITION_PROP_NAME = "position";
public static final String VALUE_PROP_NAME = "value";
public static final String WRAPPER_CLASS_PROP_NAME = "wrapper.class";
public static final String TOOLTIP_PROP_NAME = "tooltip";
public static final String NAME_PROP_NAME = "name";
public static final Timeout WAIT_STATE_TIMEOUT = new Timeout("wait.state", 1000);
public static final String OUTPUT = Wrap.class.getName() + ".OUTPUT";
private static DefaultWrapper theWrapper = new DefaultWrapper(Environment.getEnvironment());
static {
Environment.getEnvironment().initTimeout(WAIT_STATE_TIMEOUT);
Environment.getEnvironment().initOutput(OUTPUT, TestOut.getNullOutput());
Environment.getEnvironment().initTimeout(Mouse.CLICK);
Environment.getEnvironment().initTimeout(Drag.BEFORE_DRAG_TIMEOUT);
Environment.getEnvironment().initTimeout(Drag.BEFORE_DROP_TIMEOUT);
Environment.getEnvironment().initTimeout(Drag.IN_DRAG_TIMEOUT);
Environment.getEnvironment().initTimeout(Keyboard.PUSH);
}
public static DefaultWrapper getWrapper() {
return theWrapper;
}
CONTROL node;
Environment env;
/**
* Fur null source.
*
* @see org.jemmy.env.Environment
* @param env The environment
*/
protected Wrap(Environment env) {
this.env = env;
node = null;
fillTheProps(false);
}
/**
*
* @see org.jemmy.env.Environment
* @param env The environment
* @param node The encapsulated object
*/
protected Wrap(Environment env, CONTROL node) {
this.env = env;
this.node = node;
}
/**
*
* @see org.jemmy.env.Environment
* @return environment instance used by this
*/
public Environment getEnvironment() {
return env;
}
public void setEnvironment(Environment env) {
this.env = env;
}
/**
*
* @return The encapsulated object
*/
@Property(CONTROL_PROP_NAME)
public CONTROL getControl() {
return node;
}
/**
* Return default point to click, drag. This implementation returns the
* center must be overriden if something different is desired.
*
* @return the default click point
*/
@Property(CLICKPOINT_PROP_NAME)
public Point getClickPoint() {
return new Point(getScreenBounds().width / 2, (getScreenBounds().height / 2));
}
/**
* Returns control bounds in screen coordinates. These bounds could include
* parts that are covered by other controls or clipped out by parent
* components. If the control is not shown {@linkplain
* JemmyException JemmyException} will be thrown.
*
* @return control bounds in screen coordinates.
* @throws JemmyException if the control is not visible
*/
@Property(BOUNDS_PROP_NAME)
public abstract Rectangle getScreenBounds();
/**
* Transforms point in local control coordinate system to screen
* coordinates.
*
* @param local the local coordinate
* @return a absolute translated point
* @see #toLocal(org.jemmy.Point)
*/
public Point toAbsolute(Point local) {
Rectangle bounds = getScreenBounds();
return local.translate(bounds.x, bounds.y);
}
/**
* Transforms point in screen coordinates to local control coordinate
* system.
*
* @param local the local coordinate
* @return coordinates which should be used for mouse operations.
* @see #toAbsolute(org.jemmy.Point)
*/
public Point toLocal(Point local) {
Rectangle bounds = getScreenBounds();
return local.translate(-bounds.x, -bounds.y);
}
/**
* Captures the screen area held by the component. ImageFactory performs the
* actual capturing.
*
* @return TODO find a replacement
*/
public Image getScreenImage() {
Rectangle bounds = getScreenBounds();
return getScreenImage(new Rectangle(0, 0, bounds.width, bounds.height));
}
/**
* Captures portion of the screen area held by the component. ImageFactory
* performs the actual capturing.
*
* @param rect Part of the control to capture
* @return TODO find a replacement
*/
public Image getScreenImage(Rectangle rect) {
if (getEnvironment().getImageCapturer() == null) {
throw new JemmyException("Image capturer is not specified.");
}
return getEnvironment().getImageCapturer().capture(this, rect);
}
/**
* Waits for a portion of image to be exact the same as the parameter.
*
* @see Wrap#as(java.lang.Class)
* @param golden the image to match against
* @param rect A portion of control to compare.
* @param resID ID of a result image to save in case of failure. No image
* saved if null.
* @param diffID ID of a diff image to save in case of failure. No image
* saved if null.
*/
public void waitImage(final Image golden, final Rectangle rect, String resID, String diffID) {
try {
waitState(new State