Java Code Examples for java.awt.event.KeyEvent#getWhen()

The following examples show how to use java.awt.event.KeyEvent#getWhen() . 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 jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private boolean repostIfFollowsKeyEvents(WindowEvent e) {
    if (!(e instanceof TimedWindowEvent)) {
        return false;
    }
    TimedWindowEvent we = (TimedWindowEvent)e;
    long time = we.getWhen();
    synchronized (this) {
        KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst();
        if (ke != null && time >= ke.getWhen()) {
            TypeAheadMarker marker = typeAheadMarkers.isEmpty() ? null : typeAheadMarkers.getFirst();
            if (marker != null) {
                Window toplevel = marker.untilFocused.getContainingWindow();
                // Check that the component awaiting focus belongs to
                // the current focused window. See 8015454.
                if (toplevel != null && toplevel.isFocused()) {
                    SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e));
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: DefaultKeyboardFocusManager.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean repostIfFollowsKeyEvents(WindowEvent e) {
    if (!(e instanceof TimedWindowEvent)) {
        return false;
    }
    TimedWindowEvent we = (TimedWindowEvent)e;
    long time = we.getWhen();
    synchronized (this) {
        KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst();
        if (ke != null && time >= ke.getWhen()) {
            TypeAheadMarker marker = typeAheadMarkers.isEmpty() ? null : typeAheadMarkers.getFirst();
            if (marker != null) {
                Window toplevel = marker.untilFocused.getContainingWindow();
                // Check that the component awaiting focus belongs to
                // the current focused window. See 8015454.
                if (toplevel != null && toplevel.isFocused()) {
                    SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e));
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: DefaultKeyboardFocusManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void purgeStampedEvents(long start, long end) {
    if (start < 0) {
        return;
    }

    for (Iterator<KeyEvent> iter = enqueuedKeyEvents.iterator(); iter.hasNext(); ) {
        KeyEvent ke = iter.next();
        long time = ke.getWhen();

        if (start < time && (end < 0 || time <= end)) {
            iter.remove();
        }

        if (end >= 0 && time > end) {
            break;
        }
    }
}
 
Example 4
Source File: DefaultKeyboardFocusManager.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean repostIfFollowsKeyEvents(WindowEvent e) {
    if (!(e instanceof TimedWindowEvent)) {
        return false;
    }
    TimedWindowEvent we = (TimedWindowEvent)e;
    long time = we.getWhen();
    synchronized (this) {
        KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst();
        if (ke != null && time >= ke.getWhen()) {
            TypeAheadMarker marker = typeAheadMarkers.isEmpty() ? null : typeAheadMarkers.getFirst();
            if (marker != null) {
                Window toplevel = marker.untilFocused.getContainingWindow();
                // Check that the component awaiting focus belongs to
                // the current focused window. See 8015454.
                if (toplevel != null && toplevel.isFocused()) {
                    SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e));
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 5
Source File: DefaultKeyboardFocusManager.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private void purgeStampedEvents(long start, long end) {
    if (start < 0) {
        return;
    }

    for (Iterator iter = enqueuedKeyEvents.iterator(); iter.hasNext(); ) {
        KeyEvent ke = (KeyEvent)iter.next();
        long time = ke.getWhen();

        if (start < time && (end < 0 || time <= end)) {
            iter.remove();
        }

        if (end >= 0 && time > end) {
            break;
        }
    }
}
 
Example 6
Source File: DefaultKeyboardFocusManager.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private void purgeStampedEvents(long start, long end) {
    if (start < 0) {
        return;
    }

    for (Iterator<KeyEvent> iter = enqueuedKeyEvents.iterator(); iter.hasNext(); ) {
        KeyEvent ke = iter.next();
        long time = ke.getWhen();

        if (start < time && (end < 0 || time <= end)) {
            iter.remove();
        }

        if (end >= 0 && time > end) {
            break;
        }
    }
}
 
Example 7
Source File: DefaultKeyboardFocusManager.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void pumpApprovedKeyEvents() {
    KeyEvent ke;
    do {
        ke = null;
        synchronized (this) {
            if (enqueuedKeyEvents.size() != 0) {
                ke = enqueuedKeyEvents.getFirst();
                if (typeAheadMarkers.size() != 0) {
                    TypeAheadMarker marker = typeAheadMarkers.getFirst();
                    // Fixed 5064013: may appears that the events have the same time
                    // if (ke.getWhen() >= marker.after) {
                    // The fix is rolled out.

                    if (ke.getWhen() > marker.after) {
                        ke = null;
                    }
                }
                if (ke != null) {
                    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                        focusLog.finer("Pumping approved event {0}", ke);
                    }
                    enqueuedKeyEvents.removeFirst();
                }
            }
        }
        if (ke != null) {
            preDispatchKeyEvent(ke);
        }
    } while (ke != null);
}
 
Example 8
Source File: DefaultKeyboardFocusManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void pumpApprovedKeyEvents() {
    KeyEvent ke;
    do {
        ke = null;
        synchronized (this) {
            if (enqueuedKeyEvents.size() != 0) {
                ke = enqueuedKeyEvents.getFirst();
                if (typeAheadMarkers.size() != 0) {
                    TypeAheadMarker marker = typeAheadMarkers.getFirst();
                    // Fixed 5064013: may appears that the events have the same time
                    // if (ke.getWhen() >= marker.after) {
                    // The fix is rolled out.

                    if (ke.getWhen() > marker.after) {
                        ke = null;
                    }
                }
                if (ke != null) {
                    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                        focusLog.finer("Pumping approved event {0}", ke);
                    }
                    enqueuedKeyEvents.removeFirst();
                }
            }
        }
        if (ke != null) {
            preDispatchKeyEvent(ke);
        }
    } while (ke != null);
}
 
Example 9
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void keyTyped(KeyEvent e) {
  JTable src = (JTable) e.getComponent();
  int max = src.getRowCount();
  if (max == 0 || e.isAltDown() || isNavigationKey(e)) { // || BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
    // Nothing to select
    return;
  }
  boolean startingFromSelection = !src.getSelectionModel().isSelectionEmpty();
  char c = e.getKeyChar();
  int increment = e.isShiftDown() ? -1 : 1;
  long time = e.getWhen();
  int startIndex = src.getSelectedRow();
  if (time - lastTime < TIME_FACTOR) {
    typedString += c;
    if (prefix.length() == 1 && c == prefix.charAt(0)) {
      // Subsequent same key presses move the keyboard focus to the next
      // object that starts with the same letter.
      startIndex += increment;
    } else {
      prefix = typedString;
    }
  } else {
    startIndex += increment;
    typedString = Objects.toString(c);
    prefix = typedString;
  }
  lastTime = time;

  scrollNextMatch(src, max, e, prefix, startIndex, startingFromSelection);
}
 
Example 10
Source File: DefaultKeyboardFocusManager.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                                focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            }
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
                    focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                }
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that preceed it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (iter.next().untilFocused == target) {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                            focusLog.finer("Event without marker {0}", e);
                        }
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 11
Source File: DefaultKeyboardFocusManager.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                                focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            }
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
                    focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                }
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that preceed it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (iter.next().untilFocused == target) {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                            focusLog.finer("Event without marker {0}", e);
                        }
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 12
Source File: DefaultKeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                                focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            }
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
                    focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                }
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that preceed it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (iter.next().untilFocused == target) {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                            focusLog.finer("Event without marker {0}", e);
                        }
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 13
Source File: WindowsRootPaneUI.java    From openjdk-jdk8u 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: WindowsRootPaneUI.java    From openjdk-8 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 15
Source File: DefaultKeyboardFocusManager.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                                focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            }
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
                    focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                }
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that preceed it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (iter.next().untilFocused == target) {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                            focusLog.finer("Event without marker {0}", e);
                        }
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 16
Source File: GlobalSearchPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	switch (e.getKeyCode()) {
		case KeyEvent.VK_DOWN:
			resultDialog.selectNext();
			e.consume();
			break;
		case KeyEvent.VK_UP:
			resultDialog.selectPrevious();
			e.consume();
			break;
		case KeyEvent.VK_ENTER:
			resultDialog.activateSelected();
			e.consume();
			break;
		case KeyEvent.VK_TAB:
			if (e.isShiftDown()) {
				searchField.requestFocusInWindow();
			} else {
				showFilterMenu();
			}
			e.consume();
			break;
		default:
			if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
				putCursorIntoSearchfield();
				final KeyEvent newKeyEvent = new KeyEvent(searchField, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar());
				searchField.dispatchEvent(newKeyEvent);
				e.consume();
				break;
			}

			// remove non-printable characters from Unicode
			String input = ("" + e.getKeyChar()).replaceAll("\\p{C}", "");

			if (input != null && !"".equals(input) && Character.isDefined(input.charAt(0))) {
				e.consume();
				final String text = searchField.getText() + input;
				SwingUtilities.invokeLater(() -> {
					searchField.setText(text);
					putCursorIntoSearchfield();
				});
			}
			break;
	}
}
 
Example 17
Source File: DefaultKeyboardFocusManager.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                                focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            }
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
                    focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                }
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that precede it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (iter.next().untilFocused == target) {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                            focusLog.finer("Event without marker {0}", e);
                        }
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 18
Source File: DefaultKeyboardFocusManager.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                                focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            }
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
                    focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                }
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that preceed it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator<TypeAheadMarker> iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (iter.next().untilFocused == target) {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                            focusLog.finer("Event without marker {0}", e);
                        }
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 19
Source File: DefaultKeyboardFocusManager.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
private boolean typeAheadAssertions(Component target, AWTEvent e) {

        // Clear any pending events here as well as in the FOCUS_GAINED
        // handler. We need this call here in case a marker was removed in
        // response to a call to dequeueKeyEvents.
        pumpApprovedKeyEvents();

        switch (e.getID()) {
            case KeyEvent.KEY_TYPED:
            case KeyEvent.KEY_PRESSED:
            case KeyEvent.KEY_RELEASED: {
                KeyEvent ke = (KeyEvent)e;
                synchronized (this) {
                    if (e.isPosted && typeAheadMarkers.size() != 0) {
                        TypeAheadMarker marker = (TypeAheadMarker)
                            typeAheadMarkers.getFirst();
                        // Fixed 5064013: may appears that the events have the same time
                        // if (ke.getWhen() >= marker.after) {
                        // The fix is rolled out.

                        if (ke.getWhen() > marker.after) {
                            focusLog.finer("Storing event {0} because of marker {1}", ke, marker);
                            enqueuedKeyEvents.addLast(ke);
                            return true;
                        }
                    }
                }

                // KeyEvent was posted before focus change request
                return preDispatchKeyEvent(ke);
            }

            case FocusEvent.FOCUS_GAINED:
                focusLog.finest("Markers before FOCUS_GAINED on {0}", target);
                dumpMarkers();
                // Search the marker list for the first marker tied to
                // the Component which just gained focus. Then remove
                // that marker, any markers which immediately follow
                // and are tied to the same component, and all markers
                // that preceed it. This handles the case where
                // multiple focus requests were made for the same
                // Component in a row and when we lost some of the
                // earlier requests. Since FOCUS_GAINED events will
                // not be generated for these additional requests, we
                // need to clear those markers too.
                synchronized (this) {
                    boolean found = false;
                    if (hasMarker(target)) {
                        for (Iterator iter = typeAheadMarkers.iterator();
                             iter.hasNext(); )
                        {
                            if (((TypeAheadMarker)iter.next()).untilFocused ==
                                target)
                            {
                                found = true;
                            } else if (found) {
                                break;
                            }
                            iter.remove();
                        }
                    } else {
                        // Exception condition - event without marker
                        focusLog.finer("Event without marker {0}", e);
                    }
                }
                focusLog.finest("Markers after FOCUS_GAINED");
                dumpMarkers();

                redispatchEvent(target, e);

                // Now, dispatch any pending KeyEvents which have been
                // released because of the FOCUS_GAINED event so that we don't
                // have to wait for another event to be posted to the queue.
                pumpApprovedKeyEvents();
                return true;

            default:
                redispatchEvent(target, e);
                return true;
        }
    }
 
Example 20
Source File: WindowsRootPaneUI.java    From jdk8u-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);
        }
    }

}