/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2007-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at LICENSE.html or
* http://www.sun.com/cddl.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this License Header
* Notice in each file.
*
* If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Contributor(s): Alexandre (Shura) Iline. (shurymury@gmail.com)
*
* The Original Software is the Jemmy library.
* The Initial Developer of the Original Software is Alexandre Iline.
* All Rights Reserved.
*
*/
package org.jemmy.awt;
import java.awt.Component;
import java.awt.Cursor;
import org.jemmy.Point;
import org.jemmy.Rectangle;
import org.jemmy.action.GetAction;
import org.jemmy.control.Wrap;
import org.jemmy.control.ControlType;
import org.jemmy.control.MethodProperties;
import org.jemmy.control.Property;
import org.jemmy.dock.DefaultParent;
import org.jemmy.dock.DockInfo;
import org.jemmy.dock.ObjectLookup;
import org.jemmy.env.Environment;
import org.jemmy.interfaces.Parent;
import org.jemmy.lookup.Any;
import org.jemmy.lookup.LookupCriteria;
import org.netbeans.jemmy.operators.ComponentOperator;
/**
*
* @param <T>
* @author shura
*/
@ControlType (Component.class)
@MethodProperties(value={"isShowing"}, types={Boolean.class})
@DockInfo(generateSubtypeLookups=true, anonymous=true)
public class AWTComponentOperator<T extends Component> extends Wrap<T> {
@ObjectLookup("")
public static <B extends Component> LookupCriteria<B> anyLookup(Class<B> tp) {
return new Any<B>();
}
@DefaultParent("all AWT components")
public static <CONTROL extends Component> Parent<? super Component> getAWT(Class<CONTROL> controlType) {
return AWT.getAWT();
}
public static final String CURSOR = "cursor";
ComponentOperator oper;
/**
*
* @param env
* @param node
*/
public AWTComponentOperator(Environment env, T node) {
super(env, node);
oper = new ComponentOperator(node);
}
public Rectangle getScreenBounds() {
Point pos = new Point(0,0);
Component cnt = getControl();
do {
pos.x += cnt.getLocation().x;
pos.y += cnt.getLocation().y;
} while((cnt = cnt.getParent()) != null);
//SwingUtilities.convertPointToScreen(pos, getControl());
return new Rectangle(pos.x, pos.y, oper.getWidth(), oper.getHeight());
}
@Property(CURSOR)
public Cursor getCursor() {
return new GetAction<Cursor>() {
@Override
public void run(Object... parameters) throws Exception {
setResult(getControl().getCursor());
}
}.dispatch(getEnvironment());
}
}