Example usage for java.awt Window isFocused

List of usage examples for java.awt Window isFocused

Introduction

In this page you can find the example usage for java.awt Window isFocused.

Prototype

public boolean isFocused() 

Source Link

Document

Returns whether this Window is focused.

Usage

From source file:Main.java

/**
 * Returns active application window.//from w  w w  .jav a 2  s  .c  om
 *
 * @return active application window
 */
public static Window getActiveWindow() {
    final Window[] windows = Window.getWindows();
    Window window = null;
    for (final Window w : windows) {
        if (w.isShowing() && w.isActive() && w.isFocused()) {
            window = w;
            break;
        }
    }
    return window;
}

From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java

/**
 * {@inheritDoc}/*w w  w .  j ava  2  s  . c  o  m*/
 */
public void activateApplication(String method) throws RobotException {
    try {
        Window window = getActiveWindow();
        if (window == null) {
            return;
        }
        WindowActivationMethod wam = WindowActivationMethod.createWindowActivationMethod(method, m_robot,
                m_queuer);
        wam.activate(window);

        // Verify that window was successfully activated
        Window activeWindow = (Window) m_queuer.invokeAndWait("getActiveWindow", //$NON-NLS-1$
                new IRunnable() {
                    public Object run() throws StepExecutionException {
                        if (Frame.getFrames().length == 0) {
                            return null;
                        }
                        for (int i = 0; i < Frame.getFrames().length; ++i) {
                            Window curWindow = Frame.getFrames()[i];
                            while (curWindow.getOwner() != null) {
                                curWindow = curWindow.getOwner();
                            }
                            if (curWindow.isFocused()) {
                                return curWindow;
                            }
                        }
                        return null;
                    }
                });
        if (activeWindow != window) {
            throw new StepExecutionException(I18n.getString(TestErrorEvent.WINDOW_ACTIVATION_FAILED, true),
                    EventFactory.createActionError(TestErrorEvent.WINDOW_ACTIVATION_FAILED));
        }

    } catch (Exception exc) {
        throw new RobotException(exc);
    }
}