/* * 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. * * 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.dock; import org.jemmy.Rectangle; import org.jemmy.action.GetAction; import org.jemmy.control.Wrap; import org.jemmy.env.Environment; import org.jemmy.interfaces.Drag; import org.jemmy.interfaces.Keyboard; import org.jemmy.interfaces.Mouse; import org.jemmy.interfaces.Parent; import org.jemmy.lookup.Lookup; import org.jemmy.lookup.LookupCriteria; /** * Superclass for all "docks" - classes which simple provide API for lookup, interfaces * and properties. * @author shura */ public class Dock { /** * Default suffix to construct result image name. */ public static final String DEFAULT_RESULT_IMAGE_SUFFIX = "default.result.image.suffix"; /** * Default suffix to construct diff image name. */ public static final String DEFAULT_DIFF_IMAGE_SUFFIX = "default.diff.image.suffix"; static { Environment.getEnvironment().setPropertyIfNotSet(DEFAULT_DIFF_IMAGE_SUFFIX, "-diff"); Environment.getEnvironment().setPropertyIfNotSet(DEFAULT_RESULT_IMAGE_SUFFIX, "-result"); } private Wrap wrap; protected Dock(Wrap wrap) { this.wrap = wrap; } /** * Method which at the end actually get called from all dock lookup * constructors. * @param * @param parent * @param controlType * @param index * @param criteria * @return */ protected static Wrap lookup(Parent parent, Class controlType, int index, LookupCriteria... criteria) { Lookup lookup; if (criteria.length > 0) { lookup = parent.lookup(controlType, criteria[0]); for (int i = 1; i < criteria.length; i++) { lookup = lookup.lookup(controlType, criteria[i]); } } else { lookup = parent.lookup(controlType); } return lookup.wrap(index); } /** * * @return Wrap instance obtainer through lookup */ public Wrap wrap() { return wrap; } /** * * @return Wrap instance obtainer through lookup */ public Object control() { return wrap.getControl(); } /** * Shortcut to wrap().mouse() */ public Mouse mouse() { return wrap.mouse(); } /** * Shortcut to wrap().keyboard() */ public Keyboard keyboard() { return wrap.keyboard(); } /** * Shortcut to wrap().drag() */ public Drag drag() { return wrap.drag(); } /** * Shortcut to wrap().getScreenBounds() */ public Rectangle bounds() { return wrap.getScreenBounds(); } protected

P getProperty(GetAction

action) { action.execute(); return action.getResult(); } /** * * @return wrap().getEnvironment(). */ public Environment environment() { return wrap.getEnvironment(); } /** * Loads image with goldenId id waits for the control to match it. * @see Wrap#waitImage(org.jemmy.image.Image, org.jemmy.Rectangle, java.lang.String, java.lang.String) */ public void waitImage(String goldenId, Rectangle rect, String resID, String diffID) { wrap.waitImage(environment().getImageLoader().load(goldenId), rect, resID, diffID); } /** * Constructs names for diff and result images and waits for the control to match it. * Diff and result names * constructed by adding suffixes. Suffixes are obtained from environment with * default values being "-diff" and "-result" * @see #waitImage(java.lang.String, org.jemmy.Rectangle, java.lang.String, java.lang.String) * @see #DEFAULT_DIFF_IMAGE_SUFFIX * @see #DEFAULT_RESULT_IMAGE_SUFFIX */ public void waitImage(String goldenId, Rectangle rect) { waitImage(goldenId, rect, goldenId + environment().getProperty(DEFAULT_RESULT_IMAGE_SUFFIX), goldenId + environment().getProperty(DEFAULT_DIFF_IMAGE_SUFFIX)); } /** * Loads image with goldenId id waits for the control to match it. * @see Wrap#waitImage(org.jemmy.image.Image, java.lang.String, java.lang.String) */ public void waitImage(String goldenId, String resID, String diffID) { wrap.waitImage(environment().getImageLoader().load(goldenId), resID, diffID); } /** * Constructs names for diff and result images and waits for the control to match it. * Diff and result names * constructed by adding suffixes. Suffixes are obtained from environment with * default values being "-diff" and "-result" * @see #waitImage(java.lang.String, java.lang.String, java.lang.String) * @see #DEFAULT_DIFF_IMAGE_SUFFIX * @see #DEFAULT_RESULT_IMAGE_SUFFIX */ public void waitImage(String goldenId) { waitImage(goldenId, goldenId + environment().getProperty(DEFAULT_RESULT_IMAGE_SUFFIX), goldenId + environment().getProperty(DEFAULT_DIFF_IMAGE_SUFFIX)); } }