Java Code Examples for java.awt.event.WindowEvent#WINDOW_LOST_FOCUS

The following examples show how to use java.awt.event.WindowEvent#WINDOW_LOST_FOCUS . 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: SunToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example 2
Source File: XWindowPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    /* wrap in Sequenced, then post*/
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 3
Source File: SunToolkit.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example 4
Source File: XWindowPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    /* wrap in Sequenced, then post*/
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 5
Source File: XWindowPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    /* wrap in Sequenced, then post*/
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 6
Source File: XWindowPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    /* wrap in Sequenced, then post*/
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 7
Source File: SunToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example 8
Source File: SunToolkit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example 9
Source File: Window.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
boolean eventEnabled(AWTEvent e) {
    switch(e.id) {
      case WindowEvent.WINDOW_OPENED:
      case WindowEvent.WINDOW_CLOSING:
      case WindowEvent.WINDOW_CLOSED:
      case WindowEvent.WINDOW_ICONIFIED:
      case WindowEvent.WINDOW_DEICONIFIED:
      case WindowEvent.WINDOW_ACTIVATED:
      case WindowEvent.WINDOW_DEACTIVATED:
        if ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 ||
            windowListener != null) {
            return true;
        }
        return false;
      case WindowEvent.WINDOW_GAINED_FOCUS:
      case WindowEvent.WINDOW_LOST_FOCUS:
        if ((eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 ||
            windowFocusListener != null) {
            return true;
        }
        return false;
      case WindowEvent.WINDOW_STATE_CHANGED:
        if ((eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 ||
            windowStateListener != null) {
            return true;
        }
        return false;
      default:
        break;
    }
    return super.eventEnabled(e);
}
 
Example 10
Source File: SunToolkit.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example 11
Source File: XWindowPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    /* wrap in Sequenced, then post*/
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 12
Source File: SunToolkit.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public static void postEvent(AppContext appContext, AWTEvent event) {
    if (event == null) {
        throw new NullPointerException();
    }

    AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
    if (sea != null && sea.isSequencedEvent(event)) {
        AWTEvent nested = sea.getNested(event);
        if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
            nested instanceof TimedWindowEvent)
        {
            TimedWindowEvent twe = (TimedWindowEvent)nested;
            ((SunToolkit)Toolkit.getDefaultToolkit()).
                setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
        }
    }

    // All events posted via this method are system-generated.
    // Placing the following call here reduces considerably the
    // number of places throughout the toolkit that would
    // otherwise have to be modified to precisely identify
    // system-generated events.
    setSystemGenerated(event);
    AppContext eventContext = targetToAppContext(event.getSource());
    if (eventContext != null && !eventContext.equals(appContext)) {
        throw new RuntimeException("Event posted on wrong app context : " + event);
    }
    PostEventQueue postEventQueue =
        (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
    if (postEventQueue != null) {
        postEventQueue.postEvent(event);
    }
}
 
Example 13
Source File: XWindowPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusOut(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    /* wrap in Sequenced, then post*/
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 14
Source File: XWindowPeer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    sendEvent(we);
}
 
Example 15
Source File: XWindowPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    sendEvent(we);
}
 
Example 16
Source File: XWindowPeer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    sendEvent(we);
}
 
Example 17
Source File: XComponentPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void handleEvent(java.awt.AWTEvent e) {
    if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && target.isEnabled())  {
        if (e instanceof MouseEvent) {
            if (e instanceof MouseWheelEvent) {
                handleJavaMouseWheelEvent((MouseWheelEvent) e);
            }
            else
                handleJavaMouseEvent((MouseEvent) e);
        }
        else if (e instanceof KeyEvent) {
            handleF10JavaKeyEvent((KeyEvent)e);
            handleJavaKeyEvent((KeyEvent)e);
        }
    }
    else if (e instanceof KeyEvent && !((InputEvent)e).isConsumed()) {
        // even if target is disabled.
        handleF10JavaKeyEvent((KeyEvent)e);
    }
    else if (e instanceof InputMethodEvent) {
        handleJavaInputMethodEvent((InputMethodEvent) e);
    }

    int id = e.getID();

    switch(id) {
      case PaintEvent.PAINT:
          // Got native painting
          paintPending = false;
          // Fallthrough to next statement
      case PaintEvent.UPDATE:
          // Skip all painting while layouting and all UPDATEs
          // while waiting for native paint
          if (!isLayouting && !paintPending) {
              paintArea.paint(target,false);
          }
          return;
      case FocusEvent.FOCUS_LOST:
      case FocusEvent.FOCUS_GAINED:
          handleJavaFocusEvent(e);
          break;
      case WindowEvent.WINDOW_LOST_FOCUS:
      case WindowEvent.WINDOW_GAINED_FOCUS:
          handleJavaWindowFocusEvent(e);
          break;
      default:
          break;
    }

}
 
Example 18
Source File: XWindowPeer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    sendEvent(we);
}
 
Example 19
Source File: XWindowPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow(null);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusOwner(null);
    sendEvent(we);
}
 
Example 20
Source File: XComponentPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleEvent(java.awt.AWTEvent e) {
    if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && target.isEnabled())  {
        if (e instanceof MouseEvent) {
            if (e instanceof MouseWheelEvent) {
                handleJavaMouseWheelEvent((MouseWheelEvent) e);
            }
            else
                handleJavaMouseEvent((MouseEvent) e);
        }
        else if (e instanceof KeyEvent) {
            handleF10JavaKeyEvent((KeyEvent)e);
            handleJavaKeyEvent((KeyEvent)e);
        }
    }
    else if (e instanceof KeyEvent && !((InputEvent)e).isConsumed()) {
        // even if target is disabled.
        handleF10JavaKeyEvent((KeyEvent)e);
    }
    else if (e instanceof InputMethodEvent) {
        handleJavaInputMethodEvent((InputMethodEvent) e);
    }

    int id = e.getID();

    switch(id) {
      case PaintEvent.PAINT:
          // Got native painting
          paintPending = false;
          // Fallthrough to next statement
      case PaintEvent.UPDATE:
          // Skip all painting while layouting and all UPDATEs
          // while waiting for native paint
          if (!isLayouting && !paintPending) {
              paintArea.paint(target,false);
          }
          return;
      case FocusEvent.FOCUS_LOST:
      case FocusEvent.FOCUS_GAINED:
          handleJavaFocusEvent(e);
          break;
      case WindowEvent.WINDOW_LOST_FOCUS:
      case WindowEvent.WINDOW_GAINED_FOCUS:
          handleJavaWindowFocusEvent(e);
          break;
      default:
          break;
    }

}