Java Code Examples for sun.awt.SunToolkit#getContainingWindow()

The following examples show how to use sun.awt.SunToolkit#getContainingWindow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultKeyboardFocusManager.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private boolean doRestoreFocus(Component toFocus, Component vetoedComponent,
                               boolean clearOnFailure)
{
    boolean success = true;
    if (toFocus != vetoedComponent && toFocus.isShowing() && toFocus.canBeFocusOwner() &&
        (success = toFocus.requestFocus(false, FocusEvent.Cause.ROLLBACK)))
    {
        return true;
    } else {
        if (!success && getGlobalFocusedWindow() != SunToolkit.getContainingWindow(toFocus)) {
            restoreFocusTo = toFocus;
            return true;
        }
        Component nextFocus = toFocus.getNextFocusCandidate();
        if (nextFocus != null && nextFocus != vetoedComponent &&
            nextFocus.requestFocusInWindow(FocusEvent.Cause.ROLLBACK))
        {
            return true;
        } else if (clearOnFailure) {
            clearGlobalFocusOwnerPriv();
            return true;
        } else {
            return false;
        }
    }
}
 
Example 2
Source File: KeyboardFocusManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean focusedWindowChanged(Component to, Component from) {
    Window wto = SunToolkit.getContainingWindow(to);
    Window wfrom = SunToolkit.getContainingWindow(from);
    if (wto == null && wfrom == null) {
        return true;
    }
    if (wto == null) {
        return true;
    }
    if (wfrom == null) {
        return true;
    }
    return (wto != wfrom);
}
 
Example 3
Source File: WChoicePeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
protected void disposeImpl() {
    // TODO: we should somehow reset the listener when the choice
    // is moved to another toplevel without destroying its peer.
    Window parentWindow = SunToolkit.getContainingWindow((Component)target);
    if (parentWindow != null) {
        WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
        if (wpeer != null) {
            wpeer.removeWindowListener(windowListener);
        }
    }
    super.disposeImpl();
}
 
Example 4
Source File: KeyboardFocusManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean focusedWindowChanged(Component to, Component from) {
    Window wto = SunToolkit.getContainingWindow(to);
    Window wfrom = SunToolkit.getContainingWindow(from);
    if (wto == null && wfrom == null) {
        return true;
    }
    if (wto == null) {
        return true;
    }
    if (wfrom == null) {
        return true;
    }
    return (wto != wfrom);
}
 
Example 5
Source File: KeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Window which will be active after processing this request,
 * or null if this is a duplicate request. The active Window is useful
 * because some native platforms do not support setting the native focus
 * owner to null. On these platforms, the obvious choice is to set the
 * focus owner to the focus proxy of the active Window.
 */
static Window markClearGlobalFocusOwner() {
    // need to call this out of synchronized block to avoid possible deadlock
    // see 6454631.
    final Component nativeFocusedWindow =
            getCurrentKeyboardFocusManager().getNativeFocusedWindow();

    synchronized (heavyweightRequests) {
        HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
        if (hwFocusRequest ==
            HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
        {
            // duplicate request
            return null;
        }

        heavyweightRequests.add
            (HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER);

        Component activeWindow = ((hwFocusRequest != null)
            ? SunToolkit.getContainingWindow(hwFocusRequest.heavyweight)
            : nativeFocusedWindow);
        while (activeWindow != null &&
               !((activeWindow instanceof Frame) ||
                 (activeWindow instanceof Dialog)))
        {
            activeWindow = activeWindow.getParent_NoClientCode();
        }

        return (Window) activeWindow;
    }
}
 
Example 6
Source File: KeyboardFocusManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isTemporary(Component to, Component from) {
    Window wto = SunToolkit.getContainingWindow(to);
    Window wfrom = SunToolkit.getContainingWindow(from);
    if (wto == null && wfrom == null) {
        return false;
    }
    if (wto == null) {
        return true;
    }
    if (wfrom == null) {
        return false;
    }
    return (wto != wfrom);
}
 
Example 7
Source File: WChoicePeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
protected void disposeImpl() {
    // TODO: we should somehow reset the listener when the choice
    // is moved to another toplevel without destroying its peer.
    Window parentWindow = SunToolkit.getContainingWindow((Component)target);
    if (parentWindow != null) {
        WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
        if (wpeer != null) {
            wpeer.removeWindowListener(windowListener);
        }
    }
    super.disposeImpl();
}
 
Example 8
Source File: WChoicePeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void disposeImpl() {
    // TODO: we should somehow reset the listener when the choice
    // is moved to another toplevel without destroying its peer.
    Window parentWindow = SunToolkit.getContainingWindow((Component)target);
    if (parentWindow != null) {
        final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
                                            .getPeer(parentWindow);
        if (wpeer != null) {
            wpeer.removeWindowListener(windowListener);
        }
    }
    super.disposeImpl();
}
 
Example 9
Source File: KeyboardFocusManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isTemporary(Component to, Component from) {
    Window wto = SunToolkit.getContainingWindow(to);
    Window wfrom = SunToolkit.getContainingWindow(from);
    if (wto == null && wfrom == null) {
        return false;
    }
    if (wto == null) {
        return true;
    }
    if (wfrom == null) {
        return false;
    }
    return (wto != wfrom);
}
 
Example 10
Source File: KeyboardFocusManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean focusedWindowChanged(Component to, Component from) {
    Window wto = SunToolkit.getContainingWindow(to);
    Window wfrom = SunToolkit.getContainingWindow(from);
    if (wto == null && wfrom == null) {
        return true;
    }
    if (wto == null) {
        return true;
    }
    if (wfrom == null) {
        return true;
    }
    return (wto != wfrom);
}
 
Example 11
Source File: KeyboardFocusManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Window which will be active after processing this request,
 * or null if this is a duplicate request. The active Window is useful
 * because some native platforms do not support setting the native focus
 * owner to null. On these platforms, the obvious choice is to set the
 * focus owner to the focus proxy of the active Window.
 */
static Window markClearGlobalFocusOwner() {
    // need to call this out of synchronized block to avoid possible deadlock
    // see 6454631.
    final Component nativeFocusedWindow =
            getCurrentKeyboardFocusManager().getNativeFocusedWindow();

    synchronized (heavyweightRequests) {
        HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
        if (hwFocusRequest ==
            HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
        {
            // duplicate request
            return null;
        }

        heavyweightRequests.add
            (HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER);

        Component activeWindow = ((hwFocusRequest != null)
            ? SunToolkit.getContainingWindow(hwFocusRequest.heavyweight)
            : nativeFocusedWindow);
        while (activeWindow != null &&
               !((activeWindow instanceof Frame) ||
                 (activeWindow instanceof Dialog)))
        {
            activeWindow = activeWindow.getParent_NoClientCode();
        }

        return (Window) activeWindow;
    }
}
 
Example 12
Source File: KeyboardFocusManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Window which will be active after processing this request,
 * or null if this is a duplicate request. The active Window is useful
 * because some native platforms do not support setting the native focus
 * owner to null. On these platforms, the obvious choice is to set the
 * focus owner to the focus proxy of the active Window.
 */
static Window markClearGlobalFocusOwner() {
    // need to call this out of synchronized block to avoid possible deadlock
    // see 6454631.
    final Component nativeFocusedWindow =
            getCurrentKeyboardFocusManager().getNativeFocusedWindow();

    synchronized (heavyweightRequests) {
        HeavyweightFocusRequest hwFocusRequest = getLastHWRequest();
        if (hwFocusRequest ==
            HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
        {
            // duplicate request
            return null;
        }

        heavyweightRequests.add
            (HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER);

        Component activeWindow = ((hwFocusRequest != null)
            ? SunToolkit.getContainingWindow(hwFocusRequest.heavyweight)
            : nativeFocusedWindow);
        while (activeWindow != null &&
               !((activeWindow instanceof Frame) ||
                 (activeWindow instanceof Dialog)))
        {
            activeWindow = activeWindow.getParent_NoClientCode();
        }

        return (Window) activeWindow;
    }
}
 
Example 13
Source File: WindowsRootPaneUI.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
Example 14
Source File: WComponentPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean requestFocus(Component lightweightChild, boolean temporary,
                            boolean focusedWindowChangeAllowed, long time,
                            FocusEvent.Cause cause)
{
    if (WKeyboardFocusManagerPeer.
        processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
                                              focusedWindowChangeAllowed, time))
    {
        return true;
    }

    int result = WKeyboardFocusManagerPeer
        .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
                                        temporary, focusedWindowChangeAllowed,
                                        time, cause);

    switch (result) {
      case WKeyboardFocusManagerPeer.SNFH_FAILURE:
          return false;
      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
          }
          Window parentWindow = SunToolkit.getContainingWindow((Component)target);
          if (parentWindow == null) {
              return rejectFocusRequestHelper("WARNING: Parent window is null");
          }
          final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
                                               .getPeer(parentWindow);
          if (wpeer == null) {
              return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
          }
          boolean res = wpeer.requestWindowFocus(cause);

          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Requested window focus: " + res);
          }
          // If parent window can be made focused and has been made focused(synchronously)
          // then we can proceed with children, otherwise we retreat.
          if (!(res && parentWindow.isFocused())) {
              return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
          }
          return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
                                                        (Component)target,
                                                        temporary,
                                                        focusedWindowChangeAllowed,
                                                        time, cause);

      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
          // Either lightweight or excessive request - all events are generated.
          return true;
    }
    return false;
}
 
Example 15
Source File: WindowsRootPaneUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
Example 16
Source File: WComponentPeer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean requestFocus(Component lightweightChild, boolean temporary,
                            boolean focusedWindowChangeAllowed, long time,
                            CausedFocusEvent.Cause cause)
{
    if (WKeyboardFocusManagerPeer.
        processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
                                              focusedWindowChangeAllowed, time))
    {
        return true;
    }

    int result = WKeyboardFocusManagerPeer
        .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
                                        temporary, focusedWindowChangeAllowed,
                                        time, cause);

    switch (result) {
      case WKeyboardFocusManagerPeer.SNFH_FAILURE:
          return false;
      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
          }
          Window parentWindow = SunToolkit.getContainingWindow((Component)target);
          if (parentWindow == null) {
              return rejectFocusRequestHelper("WARNING: Parent window is null");
          }
          WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
          if (wpeer == null) {
              return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
          }
          boolean res = wpeer.requestWindowFocus(cause);

          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Requested window focus: " + res);
          }
          // If parent window can be made focused and has been made focused(synchronously)
          // then we can proceed with children, otherwise we retreat.
          if (!(res && parentWindow.isFocused())) {
              return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
          }
          return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
                                                        (Component)target,
                                                        temporary,
                                                        focusedWindowChangeAllowed,
                                                        time, cause);

      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
          // Either lightweight or excessive request - all events are generated.
          return true;
    }
    return false;
}
 
Example 17
Source File: WComponentPeer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean requestFocus(Component lightweightChild, boolean temporary,
                            boolean focusedWindowChangeAllowed, long time,
                            CausedFocusEvent.Cause cause)
{
    if (WKeyboardFocusManagerPeer.
        processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
                                              focusedWindowChangeAllowed, time))
    {
        return true;
    }

    int result = WKeyboardFocusManagerPeer
        .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
                                        temporary, focusedWindowChangeAllowed,
                                        time, cause);

    switch (result) {
      case WKeyboardFocusManagerPeer.SNFH_FAILURE:
          return false;
      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
          }
          Window parentWindow = SunToolkit.getContainingWindow((Component)target);
          if (parentWindow == null) {
              return rejectFocusRequestHelper("WARNING: Parent window is null");
          }
          WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
          if (wpeer == null) {
              return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
          }
          boolean res = wpeer.requestWindowFocus(cause);

          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Requested window focus: " + res);
          }
          // If parent window can be made focused and has been made focused(synchronously)
          // then we can proceed with children, otherwise we retreat.
          if (!(res && parentWindow.isFocused())) {
              return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
          }
          return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
                                                        (Component)target,
                                                        temporary,
                                                        focusedWindowChangeAllowed,
                                                        time, cause);

      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
          // Either lightweight or excessive request - all events are generated.
          return true;
    }
    return false;
}
 
Example 18
Source File: WindowsRootPaneUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
Example 19
Source File: WComponentPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean requestFocus(Component lightweightChild, boolean temporary,
                            boolean focusedWindowChangeAllowed, long time,
                            CausedFocusEvent.Cause cause)
{
    if (WKeyboardFocusManagerPeer.
        processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
                                              focusedWindowChangeAllowed, time))
    {
        return true;
    }

    int result = WKeyboardFocusManagerPeer
        .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
                                        temporary, focusedWindowChangeAllowed,
                                        time, cause);

    switch (result) {
      case WKeyboardFocusManagerPeer.SNFH_FAILURE:
          return false;
      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
          }
          Window parentWindow = SunToolkit.getContainingWindow((Component)target);
          if (parentWindow == null) {
              return rejectFocusRequestHelper("WARNING: Parent window is null");
          }
          WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
          if (wpeer == null) {
              return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
          }
          boolean res = wpeer.requestWindowFocus(cause);

          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Requested window focus: " + res);
          }
          // If parent window can be made focused and has been made focused(synchronously)
          // then we can proceed with children, otherwise we retreat.
          if (!(res && parentWindow.isFocused())) {
              return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
          }
          return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
                                                        (Component)target,
                                                        temporary,
                                                        focusedWindowChangeAllowed,
                                                        time, cause);

      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
          // Either lightweight or excessive request - all events are generated.
          return true;
    }
    return false;
}
 
Example 20
Source File: WComponentPeer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean requestFocus(Component lightweightChild, boolean temporary,
                            boolean focusedWindowChangeAllowed, long time,
                            CausedFocusEvent.Cause cause)
{
    if (WKeyboardFocusManagerPeer.
        processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
                                              focusedWindowChangeAllowed, time))
    {
        return true;
    }

    int result = WKeyboardFocusManagerPeer
        .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
                                        temporary, focusedWindowChangeAllowed,
                                        time, cause);

    switch (result) {
      case WKeyboardFocusManagerPeer.SNFH_FAILURE:
          return false;
      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
          }
          Window parentWindow = SunToolkit.getContainingWindow((Component)target);
          if (parentWindow == null) {
              return rejectFocusRequestHelper("WARNING: Parent window is null");
          }
          WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
          if (wpeer == null) {
              return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
          }
          boolean res = wpeer.requestWindowFocus(cause);

          if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
              focusLog.finer("Requested window focus: " + res);
          }
          // If parent window can be made focused and has been made focused(synchronously)
          // then we can proceed with children, otherwise we retreat.
          if (!(res && parentWindow.isFocused())) {
              return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
          }
          return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
                                                        (Component)target,
                                                        temporary,
                                                        focusedWindowChangeAllowed,
                                                        time, cause);

      case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
          // Either lightweight or excessive request - all events are generated.
          return true;
    }
    return false;
}