public void actionPerformed(ActionEvent e) {
      final KeyboardFocusManager currentKeyboardFocusManager =
          KeyboardFocusManager.getCurrentKeyboardFocusManager();
      final Window activeWindow = currentKeyboardFocusManager.getActiveWindow();
      if (activeWindow instanceof JDialog
          && ((JDialog) activeWindow).isModal()
          && !SwingUtilities.isDescendingFrom(
              Controller.getCurrentController().getViewController().getMapView(), activeWindow)) {
        popup.hide();
        hideTimer.removeActionListener(this);
        hideTimer.stop();
      }

      if (tip.getMousePosition(true) != null || mouseOverComponent()) {
        hideTimer.restart();
        return;
      }
      final Component focusOwner = currentKeyboardFocusManager.getFocusOwner();
      if (focusOwner != null) {
        if (SwingUtilities.isDescendingFrom(focusOwner, tip)) {
          hideTimer.restart();
          return;
        }
      }

      popup.hide();
      hideTimer.removeActionListener(this);
      hideTimer.stop();
    }
示例#2
0
 /**
  * Tries to find the current focused window.
  *
  * @return the current focused window, or <code>null</code> if no such window could be found.
  */
 public static final Window getCurrentWindow() {
   Window owner;
   final KeyboardFocusManager kbdFocusManager =
       KeyboardFocusManager.getCurrentKeyboardFocusManager();
   owner = kbdFocusManager.getFocusedWindow();
   if (owner == null) {
     owner = kbdFocusManager.getActiveWindow();
   }
   return owner;
 }
示例#3
0
 public static boolean isActiveWindow(Window window) {
   KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   return (manager.getActiveWindow() == window);
 }
示例#4
0
  /*
   * Requests platform to set native focus on a frame/dialog.
   * In case of a simple window, triggers appropriate java focus change.
   */
  public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
      focusLog.fine("requesting native focus to " + this);
    }

    if (!focusAllowedFor()) {
      focusLog.fine("focus is not allowed");
      return false;
    }

    // if (platformWindow.rejectFocusRequest(cause)) {
    //    return false;
    // }

    AppContext targetAppContext = AWTAccessor.getComponentAccessor().getAppContext(getTarget());
    KeyboardFocusManager kfm =
        AWTAccessor.getKeyboardFocusManagerAccessor()
            .getCurrentKeyboardFocusManager(targetAppContext);
    Window currentActive = kfm.getActiveWindow();

    Window opposite = LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();

    // Make the owner active window.
    if (isSimpleWindow()) {
      focusLog.fine("This is a Simple Window.");
      LWWindowPeer owner = getOwnerFrameDialog(this);

      // If owner is not natively active, request native
      // activation on it w/o sending events up to java.
      if (owner != null && !owner.platformWindow.isActive()) {
        if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
          focusLog.fine("requesting native focus to the owner " + owner);
        }
        LWWindowPeer currentActivePeer =
            currentActive == null
                ? null
                : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(currentActive);

        // Ensure the opposite is natively active and suppress sending events.
        if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
          if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
            focusLog.fine("the opposite is " + currentActivePeer);
          }
          currentActivePeer.skipNextFocusChange = true;
        }
        owner.skipNextFocusChange = true;

        owner.platformWindow.requestWindowFocus();
      }

      // DKFM will synthesize all the focus/activation events correctly.
      changeFocusedWindow(true, opposite);
      focusLog.fine("DKFM will synthesize all the focus/activation events correctly");
      return true;

      // In case the toplevel is active but not focused, change focus directly,
      // as requesting native focus on it will not have effect.
    } else if (getTarget() == currentActive && !getTarget().hasFocus()) {

      changeFocusedWindow(true, opposite);
      focusLog.fine("toplevel is active but not focused, change focus directly");
      return true;
    }

    focusLog.fine("platformWindow.requestWindowFocus()");
    return platformWindow.requestWindowFocus();
  }
 @Override
 public void mouseClicked(MouseEvent e) {
   KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   kfm.getActiveWindow().requestFocus();
 }