Example usage for javafx.scene Scene getFocusOwner

List of usage examples for javafx.scene Scene getFocusOwner

Introduction

In this page you can find the example usage for javafx.scene Scene getFocusOwner.

Prototype

public final Node getFocusOwner() 

Source Link

Usage

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * {@inheritDoc} <br>//  ww  w.  j a va2s  . c  o  m
 * <b>* Currently delegates the key type to the Robot </b>
 */
public void type(final Object graphicsComponent, char c) throws RobotException {

    Validate.notNull(graphicsComponent, "The graphic component must not be null"); //$NON-NLS-1$

    final KeyEvent event = new KeyEvent(KeyEvent.KEY_TYPED, String.valueOf(c), StringUtils.EMPTY, null, false,
            false, false, false);

    InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK });
    IRobotEventConfirmer confirmer = m_interceptor.intercept(options);

    m_queuer.invokeLater("Type character", new Runnable() { //$NON-NLS-1$
        @Override
        public void run() {
            final Scene scene;
            if (graphicsComponent instanceof Stage) {
                scene = ((Stage) graphicsComponent).getScene();
            } else {
                scene = ((Node) graphicsComponent).getScene();
            }

            Node focusOwner = scene.getFocusOwner();
            EventTarget eventTarget = focusOwner != null ? focusOwner : scene;

            Event.fireEvent(eventTarget, event);
        }
    });

    confirmer.waitToConfirm(graphicsComponent, new KeyJavaFXEventMatcher(KeyEvent.KEY_TYPED));

}