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

The following examples show how to use java.awt.event.WindowEvent#WINDOW_GAINED_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: Util.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
    EventListener listener = null;

    switch (eventID) {
    case WindowEvent.WINDOW_GAINED_FOCUS:
        listener = wgfListener;
        break;
    case FocusEvent.FOCUS_GAINED:
        listener = fgListener;
        break;
    case ActionEvent.ACTION_PERFORMED:
        listener = apListener;
        break;
    }

    listener.listen(comp, printEvent);
    action.run();
    return Util.waitForCondition(listener.getNotifier(), time);
}
 
Example 2
Source File: SwingUtils.java    From ib-controller with GNU General Public License v3.0 6 votes vote down vote up
static String windowEventToString(int eventID) {
    switch (eventID) { 
        case WindowEvent.WINDOW_ACTIVATED:
            return "Activated";
        case WindowEvent.WINDOW_CLOSED:
            return "Closed";
        case WindowEvent.WINDOW_CLOSING:
            return "Closing";
        case WindowEvent.WINDOW_DEACTIVATED:
            return "Deactivated";
        case WindowEvent.WINDOW_DEICONIFIED:
            return "Deiconfied";
        case WindowEvent.WINDOW_GAINED_FOCUS:
            return "Focused";
        case WindowEvent.WINDOW_ICONIFIED:
            return "Iconified";
        case WindowEvent.WINDOW_LOST_FOCUS:
            return "Lost focus";
        case WindowEvent.WINDOW_OPENED:
            return "Opened";
        case WindowEvent.WINDOW_STATE_CHANGED:
            return "State changed";
        default:
            return "???";
    }
}
 
Example 3
Source File: Util.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
    EventListener listener = null;

    switch (eventID) {
    case WindowEvent.WINDOW_GAINED_FOCUS:
        listener = wgfListener;
        break;
    case FocusEvent.FOCUS_GAINED:
        listener = fgListener;
        break;
    case ActionEvent.ACTION_PERFORMED:
        listener = apListener;
        break;
    }

    listener.listen(comp, printEvent);
    action.run();
    return Util.waitForCondition(listener.getNotifier(), time);
}
 
Example 4
Source File: Util.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
    EventListener listener = null;

    switch (eventID) {
    case WindowEvent.WINDOW_GAINED_FOCUS:
        listener = wgfListener;
        break;
    case FocusEvent.FOCUS_GAINED:
        listener = fgListener;
        break;
    case ActionEvent.ACTION_PERFORMED:
        listener = apListener;
        break;
    }

    listener.listen(comp, printEvent);
    action.run();
    return Util.waitForCondition(listener.getNotifier(), time);
}
 
Example 5
Source File: MainWindow.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void windowStateChanged(WindowEvent e) {
	if (e.getNewState() == WindowEvent.WINDOW_LOST_FOCUS) {
		//e.getWindow().setVisible(false);
		Log.println("LOST FOCUS");
	}
	if (e.getNewState() == WindowEvent.WINDOW_ACTIVATED) {
		//e.getWindow().setVisible(false);
		Log.println("ACTIVATED");
	}
	if (e.getNewState() == WindowEvent.WINDOW_GAINED_FOCUS) {
		//e.getWindow().setVisible(false);
		Log.println("GOT FOCUS");
	}
}
 
Example 6
Source File: XWindowPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusIn_Dispatch() {
    if (EventQueue.isDispatchThread()) {
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
        SunToolkit.setSystemGenerated(we);
        target.dispatchEvent(we);
    }
}
 
Example 7
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 8
Source File: XWindowPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void handleWindowFocusIn_Dispatch() {
    if (EventQueue.isDispatchThread()) {
        XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
        SunToolkit.setSystemGenerated(we);
        target.dispatchEvent(we);
    }
}
 
Example 9
Source File: XWindowPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusIn(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    /* wrap in Sequenced, then post*/
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 10
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;
    }

}
 
Example 11
Source File: XComponentPeer.java    From jdk8u_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;
    }

}
 
Example 12
Source File: XWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusInSync(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    sendEvent(we);
}
 
Example 13
Source File: XWindowPeer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusIn(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    /* wrap in Sequenced, then post*/
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    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 handleWindowFocusIn(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    /* wrap in Sequenced, then post*/
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 15
Source File: XWindowPeer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusInSync(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    sendEvent(we);
}
 
Example 16
Source File: XWindowPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusIn(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    /* wrap in Sequenced, then post*/
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 17
Source File: XWindowPeer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusIn(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    /* wrap in Sequenced, then post*/
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    postEvent(wrapInSequenced((AWTEvent) we));
}
 
Example 18
Source File: XWindowPeer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusInSync(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    sendEvent(we);
}
 
Example 19
Source File: XComponentPeer.java    From jdk8u-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;
    }

}
 
Example 20
Source File: XWindowPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleWindowFocusInSync(long serial) {
    WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
    XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
    sendEvent(we);
}