1 /* 2 * Copyright (c) 2007, 2018, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.jemmy.swt; 24 25 import org.eclipse.swt.widgets.Scrollable; 26 import org.jemmy.Rectangle; 27 import org.jemmy.control.ControlType; 28 import org.jemmy.env.Environment; 29 30 /** 31 * Base wrapper for scrollable controls such as Table and Tree 32 * 33 * @author erikgreijus 34 * @param <T> 35 */ 36 @ControlType(Scrollable.class) 37 public class ScrollableWrap<T extends Scrollable> extends ControlWrap<T> { 38 39 public ScrollableWrap(Environment env, T node) { 40 super(env, node); 41 } 42 43 /** 44 * Returns the screen bounds of this Scrollable 45 * 46 * @return A Rectangle describing the screen bounds of this Scrollable 47 */ 48 @Override 49 public Rectangle getScreenBounds() { 50 return getScreenBounds(Scrollable.class.cast(getControl()), getEnvironment()); 51 } 52 53 /** 54 * Returns the screen bounds of this Scrollable 55 * 56 * @param scrollable This Scrollable 57 * @param env The environment 58 * @return A Rectangle describing the screen bounds of this Scrollable 59 */ 60 public static Rectangle getScreenBounds(Scrollable scrollable, Environment env) { 61 Rectangle res = getBounds(scrollable, env); 62 org.eclipse.swt.graphics.Point loc = getScreenLocation(scrollable, env); 63 res.x = loc.x; 64 res.y = loc.y; 65 return res; 66 } 67 68 /** 69 * Returns a rectangle describing the visible part of the supplied 70 * Scrollable. 71 * 72 * @see org.eclipse.swt.widgets.Scrollable#getClientArea() 73 * @param scrollable The Scrollable for which to get the client area 74 * @param env The Jemmy Environment 75 * @return A rectangle describing the visible part of this scrollable 76 */ 77 public static Rectangle getBounds(final Scrollable scrollable, Environment env) { 78 GetAction<org.eclipse.swt.graphics.Rectangle> action = new GetAction<org.eclipse.swt.graphics.Rectangle>() { 79 80 @Override 81 public void run(Object... parameters) { 82 setResult(scrollable.getClientArea()); 83 } 84 85 @Override 86 public String toString() { 87 return "Getting bounds (client area) for " + scrollable; 88 } 89 }; 90 env.getExecutor().execute(env, true, action); 91 org.eclipse.swt.graphics.Rectangle res = action.getResult(); 92 return new Rectangle(res.x, res.y, res.width, res.height); 93 } 94 }