public @Nullable Component getFocusedComponent(@NotNull Window window) {
    synchronized (myLock) {
      WindowInfo info = windowToInfo.get(window);
      if (info == null) { // it means that we don't manage this window, so just return standard focus owner
        // return window.getFocusOwner();
        // TODO[vova,anton] usage of getMostRecentFocusOwner is experimental. But it seems suitable here.
        return window.getMostRecentFocusOwner();
      }

      FocusWatcher focusWatcher = info.myFocusWatcherRef.get();
      if (focusWatcher != null) {
        final Component focusedComponent = focusWatcher.getFocusedComponent();
        if (focusedComponent != null && focusedComponent.isShowing()) {
          return focusedComponent;
        }
        else {
          return window == KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() ? window : null;
        }
      }
      else {
        // info isn't valid, i.e. window was garbage collected, so we need the remove invalid info
        // and return null
        windowToInfo.remove(window);
        return null;
      }
    }
  }
public @Nullable Component getFocusedComponent(@NotNull Window window)