1 /* 2 * Copyright (c) 2007, 2017 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package org.jemmy.lookup; 26 27 import org.jemmy.Rectangle; 28 import org.jemmy.control.Wrap; 29 30 /** 31 * 32 * @param <CONTROL> 33 * @author shura 34 */ 35 public abstract class RelativeCoordinateLookup<CONTROL> extends CoordinateLookup<CONTROL> { 36 37 private static final int MAX_SCREEN_SIZE = 100000; 38 39 private Wrap wrap; 40 private boolean includeControl; 41 private int hr; 42 private int vr; 43 44 /** 45 * 46 * @param wrap 47 * @param includeControl 48 * @param hr 49 * @param vr 50 */ 51 public RelativeCoordinateLookup(Wrap wrap, boolean includeControl, int hr, int vr) { 52 super(wrap.getScreenBounds()); 53 this.wrap = wrap; 54 this.includeControl = includeControl; 55 this.hr = hr; 56 this.vr = vr; 57 } 58 59 /** 60 * 61 * @return 62 */ 63 @Override 64 protected Rectangle getArea() { 65 return constructArea(wrap, includeControl, hr, vr); 66 } 67 68 private static Rectangle constructArea(Wrap wrap, boolean includeControl, int hr, int vr) { 69 Rectangle res = new Rectangle(); 70 res.width = MAX_SCREEN_SIZE; 71 res.height = MAX_SCREEN_SIZE; 72 Rectangle bounds = wrap.getScreenBounds(); 73 if (hr != 0) { 74 if (hr < 0) { 75 res.x = -MAX_SCREEN_SIZE + bounds.x + (includeControl ? bounds.width : 0); 76 } else { 77 res.x = bounds.x + (includeControl ? 0 : bounds.width); 78 } 79 } else { 80 res.x = -MAX_SCREEN_SIZE / 2 + bounds.x + (includeControl ? bounds.width / 2 : 0); 81 } 82 if (vr != 0) { 83 if (vr < 0) { 84 res.y = -MAX_SCREEN_SIZE + bounds.y + (includeControl ? bounds.height : 0); 85 } else { 86 res.y = bounds.y + (includeControl ? 0 : bounds.height); 87 } 88 } else { 89 res.y = -MAX_SCREEN_SIZE / 2 + bounds.y + (includeControl ? bounds.height / 2 : 0); 90 } 91 return res; 92 } 93 94 }