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 java.awt.Rectangle; 26 import org.eclipse.swt.widgets.Shell; 27 import org.jemmy.action.GetAction; 28 import org.jemmy.control.ControlType; 29 import org.jemmy.control.Property; 30 import org.jemmy.control.Wrap; 31 import org.jemmy.env.Environment; 32 import org.jemmy.interfaces.ControlInterface; 33 import org.jemmy.interfaces.MenuOwner; 34 35 /** 36 * 37 * @author shura 38 */ 39 @ControlType(Shell.class) 40 public class ShellWrap<T extends Shell> extends CompositeWrap<T> { 41 42 final SWTMenuOwner menuBar; 43 44 public ShellWrap(Environment env, T node) { 45 super(env, node); 46 menuBar = new SWTMenuOwner(this, true); 47 } 48 49 public static Rectangle getBounds(final Shell s, Environment env) { 50 GetAction<org.eclipse.swt.graphics.Rectangle> action = new GetAction<org.eclipse.swt.graphics.Rectangle>() { 51 52 public void run(Object... parameters) { 53 setResult(s.getBounds()); 54 } 55 56 @Override 57 public String toString() { 58 return "Getting bounds for " + s; 59 } 60 61 }; 62 env.getExecutor().execute(env, true, action); 63 org.eclipse.swt.graphics.Rectangle res = action.getResult(); 64 return new Rectangle(res.x, res.y, res.width, res.height); 65 } 66 67 public static Rectangle getClientArea(final Shell s, Environment env) { 68 GetAction<org.eclipse.swt.graphics.Rectangle> action = new GetAction<org.eclipse.swt.graphics.Rectangle>() { 69 70 public void run(Object... parameters) { 71 setResult(s.getClientArea()); 72 } 73 74 @Override 75 public String toString() { 76 return "Getting client area for " + s; 77 } 78 79 }; 80 env.getExecutor().execute(env, true, action); 81 org.eclipse.swt.graphics.Rectangle res = action.getResult(); 82 return new Rectangle(res.x, res.y, res.width, res.height); 83 } 84 85 @Property(Wrap.TEXT_PROP_NAME) 86 public String getText() { 87 return new GetAction<String>() { 88 89 @Override 90 public void run(Object... parameters) { 91 setResult(getControl().getText()); 92 } 93 }.dispatch(getEnvironment()); 94 } 95 96 @Override 97 public <INTERFACE extends ControlInterface> INTERFACE as(Class<INTERFACE> interfaceClass) { 98 if(MenuOwner.class.isAssignableFrom(interfaceClass)) { 99 return (INTERFACE) menuBar; 100 } 101 return super.as(interfaceClass); 102 } 103 104 @Override 105 public <INTERFACE extends ControlInterface> boolean is(Class<INTERFACE> interfaceClass) { 106 if(MenuOwner.class.isAssignableFrom(interfaceClass)) { 107 return true; 108 } 109 return super.is(interfaceClass); 110 } 111 }