Java Code Examples for java.awt.event.KeyEvent#KEY_RELEASED

The following examples show how to use java.awt.event.KeyEvent#KEY_RELEASED . 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: MenuBar.java    From openjdk-jdk8u with GNU General Public License v2.0 8 votes vote down vote up
boolean handleShortcut(KeyEvent e) {
    // Is it a key event?
    int id = e.getID();
    if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
        return false;
    }

    // Is the accelerator modifier key pressed?
    int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    if ((e.getModifiers() & accelKey) == 0) {
        return false;
    }

    // Pass MenuShortcut on to child menus.
    int nmenus = getMenuCount();
    for (int i = 0 ; i < nmenus ; i++) {
        Menu m = getMenu(i);
        if (m.handleShortcut(e)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: AWTKeyStroke.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>AWTKeyStroke</code> which represents the
 * stroke which generated a given <code>KeyEvent</code>.
 * <p>
 * This method obtains the keyChar from a <code>KeyTyped</code>
 * event, and the keyCode from a <code>KeyPressed</code> or
 * <code>KeyReleased</code> event. The <code>KeyEvent</code> modifiers are
 * obtained for all three types of <code>KeyEvent</code>.
 *
 * @param anEvent the <code>KeyEvent</code> from which to
 *      obtain the <code>AWTKeyStroke</code>
 * @throws NullPointerException if <code>anEvent</code> is null
 * @return the <code>AWTKeyStroke</code> that precipitated the event
 */
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
    int id = anEvent.getID();
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
        return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
                               anEvent.getKeyCode(),
                               anEvent.getModifiers(),
                               (id == KeyEvent.KEY_RELEASED));
      case KeyEvent.KEY_TYPED:
        return getCachedStroke(anEvent.getKeyChar(),
                               KeyEvent.VK_UNDEFINED,
                               anEvent.getModifiers(),
                               false);
      default:
        // Invalid ID for this KeyEvent
        return null;
    }
}
 
Example 3
Source File: KeyStrokeAdapter.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @param event    the specified key event to process
 * @param extended {@code true} if extended key code should be used
 * @return a key stroke or {@code null} if it is not applicable
 * @see JComponent#processKeyBindings(KeyEvent, boolean)
 */
public static KeyStroke getKeyStroke(KeyEvent event, boolean extended) {
  if (event != null && !event.isConsumed()) {
    int id = event.getID();
    if (id == KeyEvent.KEY_TYPED) {
      return extended ? null : getKeyStroke(event.getKeyChar(), 0);
    }
    boolean released = id == KeyEvent.KEY_RELEASED;
    if (released || id == KeyEvent.KEY_PRESSED) {
      int code = event.getKeyCode();
      if (extended) {
        if (Registry.is("actionSystem.extendedKeyCode.disabled")) {
          return null;
        }
        code = getExtendedKeyCode(event);
        if (code == event.getKeyCode()) {
          return null;
        }
      }
      return getKeyStroke(code, event.getModifiers(), released);
    }
  }
  return null;
}
 
Example 4
Source File: AWTEvent.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Consumes this event, if this event can be consumed. Only low-level,
 * system events can be consumed
 */
protected void consume() {
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
      case MouseEvent.MOUSE_MOVED:
      case MouseEvent.MOUSE_DRAGGED:
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_WHEEL:
      case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
      case InputMethodEvent.CARET_POSITION_CHANGED:
          consumed = true;
          break;
      default:
          // event type cannot be consumed
    }
}
 
Example 5
Source File: AWTKeyStroke.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>AWTKeyStroke</code> which represents the
 * stroke which generated a given <code>KeyEvent</code>.
 * <p>
 * This method obtains the keyChar from a <code>KeyTyped</code>
 * event, and the keyCode from a <code>KeyPressed</code> or
 * <code>KeyReleased</code> event. The <code>KeyEvent</code> modifiers are
 * obtained for all three types of <code>KeyEvent</code>.
 *
 * @param anEvent the <code>KeyEvent</code> from which to
 *      obtain the <code>AWTKeyStroke</code>
 * @throws NullPointerException if <code>anEvent</code> is null
 * @return the <code>AWTKeyStroke</code> that precipitated the event
 */
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
    int id = anEvent.getID();
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
        return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
                               anEvent.getKeyCode(),
                               anEvent.getModifiers(),
                               (id == KeyEvent.KEY_RELEASED));
      case KeyEvent.KEY_TYPED:
        return getCachedStroke(anEvent.getKeyChar(),
                               KeyEvent.VK_UNDEFINED,
                               anEvent.getModifiers(),
                               false);
      default:
        // Invalid ID for this KeyEvent
        return null;
    }
}
 
Example 6
Source File: AWTKeyStroke.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>AWTKeyStroke</code> which represents the
 * stroke which generated a given <code>KeyEvent</code>.
 * <p>
 * This method obtains the keyChar from a <code>KeyTyped</code>
 * event, and the keyCode from a <code>KeyPressed</code> or
 * <code>KeyReleased</code> event. The <code>KeyEvent</code> modifiers are
 * obtained for all three types of <code>KeyEvent</code>.
 *
 * @param anEvent the <code>KeyEvent</code> from which to
 *      obtain the <code>AWTKeyStroke</code>
 * @throws NullPointerException if <code>anEvent</code> is null
 * @return the <code>AWTKeyStroke</code> that precipitated the event
 */
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
    int id = anEvent.getID();
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
        return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
                               anEvent.getKeyCode(),
                               anEvent.getModifiers(),
                               (id == KeyEvent.KEY_RELEASED));
      case KeyEvent.KEY_TYPED:
        return getCachedStroke(anEvent.getKeyChar(),
                               KeyEvent.VK_UNDEFINED,
                               anEvent.getModifiers(),
                               false);
      default:
        // Invalid ID for this KeyEvent
        return null;
    }
}
 
Example 7
Source File: CommandDispatcher.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectAccountCommand() {
    JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();

    int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
    KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED);
    KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'R' );
    KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R,  KeyEvent.CHAR_UNDEFINED );
    jf.dispatchEvent(pressed);
    jf.dispatchEvent(typed);
    jf.dispatchEvent(released);

    mChannel.writeAck("");
}
 
Example 8
Source File: KeyboardHandler.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Utility method, calls one of <code>keyPressed()</code>,
 * <code>keyReleased()</code>, or <code>keyTyped()</code>.
 */
public void processKeyEvent(KeyEvent evt) {
   switch(evt.getID())
   {
   case KeyEvent.KEY_TYPED:
      keyTyped(evt);
      break;
   case KeyEvent.KEY_PRESSED:
      keyPressed(evt);
      break;
   case KeyEvent.KEY_RELEASED:
      keyReleased(evt);
      break;
   }
}
 
Example 9
Source File: AWTKeyStroke.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the type of <code>KeyEvent</code> which corresponds to
 * this <code>AWTKeyStroke</code>.
 *
 * @return <code>KeyEvent.KEY_PRESSED</code>,
 *         <code>KeyEvent.KEY_TYPED</code>,
 *         or <code>KeyEvent.KEY_RELEASED</code>
 * @see java.awt.event.KeyEvent
 */
public final int getKeyEventType() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return KeyEvent.KEY_TYPED;
    } else {
        return (onKeyRelease)
            ? KeyEvent.KEY_RELEASED
            : KeyEvent.KEY_PRESSED;
    }
}
 
Example 10
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testDeleteRowActionByDelete() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(3, newState.length);
    assertEquals("just another line with leading and trailing whitespaces", newState[1][0]);
    assertEquals("  and one more value  ", newState[1][1]);
}
 
Example 11
Source File: WindowsRootPaneUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
        // mnemonic combination, it's consumed, but we need
        // set altKeyPressed to false, otherwise after selection
        // component by mnemonic combination a menu will be open
        altKeyPressed = false;
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
Example 12
Source File: TextArea.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void processKeyEvent(KeyEvent e) {
    if (e.isControlDown() && e.getID() == KeyEvent.KEY_RELEASED) {
        int keyCode = e.getKeyCode();
        if (keyCode == KeyEvent.VK_EQUALS || keyCode == KeyEvent.VK_PLUS) {
            if (changeSize(e.isShiftDown(), true)) e.consume();
        } else if (keyCode == KeyEvent.VK_MINUS) {
            if (changeSize(e.isShiftDown(), false)) e.consume();
        } else if (keyCode == KeyEvent.VK_0) {
            if (resetSize()) e.consume();
        }
    }
    
    if (!e.isConsumed()) super.processKeyEvent(e);
}
 
Example 13
Source File: WButtonPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
     switch (e.getID()) {
        case KeyEvent.KEY_RELEASED:
            if (e.getKeyCode() == KeyEvent.VK_SPACE){
                handleAction(e.getWhen(), e.getModifiers());
            }
        break;
     }
     return false;
}
 
Example 14
Source File: NeverLog.java    From ExternalPlugins with GNU General Public License v3.0 5 votes vote down vote up
private void pressKey()
{
	KeyEvent keyPress = new KeyEvent(this.client.getCanvas(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE);
	this.client.getCanvas().dispatchEvent(keyPress);
	KeyEvent keyRelease = new KeyEvent(this.client.getCanvas(), KeyEvent.KEY_RELEASED, System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE);
	this.client.getCanvas().dispatchEvent(keyRelease);
	KeyEvent keyTyped = new KeyEvent(this.client.getCanvas(), KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, KeyEvent.VK_BACK_SPACE);
	this.client.getCanvas().dispatchEvent(keyTyped);
}
 
Example 15
Source File: CommandDispatcher.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private void handleReconnectDataCommand() {
     JFrame jf = MainWindowManager.mainWindowManager().getMainWindow(1, TimeUnit.MILLISECONDS);

     int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK;
     KeyEvent pressed=new KeyEvent(jf,  KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F, KeyEvent.CHAR_UNDEFINED);
     KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'F' );
     KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_F,  KeyEvent.CHAR_UNDEFINED );
     jf.dispatchEvent(pressed);
     jf.dispatchEvent(typed);
     jf.dispatchEvent(released);
   
     mChannel.writeAck("");
}
 
Example 16
Source File: XButtonPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
void handleJavaKeyEvent(KeyEvent e) {
    int id = e.getID();
    switch (id) {
      case KeyEvent.KEY_PRESSED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed=true;
              armed=true;
              repaint();
              action(e.getWhen(),e.getModifiers());
          }

          break;

      case KeyEvent.KEY_RELEASED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed = false;
              armed = false;
              repaint();
          }

          break;


    }
}
 
Example 17
Source File: DefaultKeyboardFocusManager.java    From hottub 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 18
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 19
Source File: DefaultKeyboardFocusManager.java    From jdk1.8-source-analysis 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 20
Source File: AltProcessor.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean postProcessKeyEvent ( @NotNull final KeyEvent ev )
{
    if ( ev.isConsumed () )
    {
        // Ignoring consumed events
        return false;
    }
    if ( ev.getKeyCode () == KeyEvent.VK_ALT )
    {
        root = SwingUtilities.getRootPane ( ev.getComponent () );
        winAncestor = root == null ? null : CoreSwingUtils.getWindowAncestor ( root );

        if ( ev.getID () == KeyEvent.KEY_PRESSED )
        {
            if ( !altKeyPressed )
            {
                altPressed ( ev );
            }
            altKeyPressed = true;
            return true;
        }
        else if ( ev.getID () == KeyEvent.KEY_RELEASED )
        {
            if ( altKeyPressed )
            {
                altReleased ();
            }
            else
            {
                final MenuSelectionManager msm = MenuSelectionManager.defaultManager ();
                final MenuElement[] path = msm.getSelectedPath ();
                if ( path.length <= 0 )
                {
                    WebLookAndFeel.setMnemonicHidden ( true );
                    repaintMnemonicsInWindow ( winAncestor );
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    }
    else
    {
        altKeyPressed = false;
    }
    return false;
}