当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.getWhen方法代码示例

本文整理汇总了Java中java.awt.event.KeyEvent.getWhen方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getWhen方法的具体用法?Java KeyEvent.getWhen怎么用?Java KeyEvent.getWhen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.event.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getWhen方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
protected void process(KeyEvent e) {
  // If we've consumed a KeyPressed event,
  // then automatically consume any following KeyTyped event
  // resulting from the same keypress
  // This prevents echoing characters to the Chat area if they're keycommand for selected pieces
  if (lastConsumedEvent != null
      && lastConsumedEvent.getWhen() == e.getWhen()) {
    e.consume();
  }
  else {
    lastConsumedEvent = null;
  }
  final int c = e.getKeyCode();
  // Don't pass SHIFT or CONTROL only to counters
  if (!e.isConsumed() && c != KeyEvent.VK_SHIFT && c != KeyEvent.VK_CONTROL) {
    Command comm = KeyBuffer.getBuffer().keyCommand
        (KeyStroke.getKeyStrokeForEvent(e));
    if (comm != null && !comm.isNull()) {
      GameModule.getGameModule().sendAndLog(comm);
      e.consume();
      lastConsumedEvent = e;
    }
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:ForwardToKeyBuffer.java

示例2: repostIfFollowsKeyEvents

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:DefaultKeyboardFocusManager.java

示例3: purgeStampedEvents

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
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;
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:DefaultKeyboardFocusManager.java

示例4: eventDispatched

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void eventDispatched(AWTEvent event) {
    if (!(event instanceof KeyEvent)) {
        return;
    }
    KeyEvent keyEvent = (KeyEvent)event;
    if (keyEvent.getKeyCode() == KeyEvent.VK_ALT) {
        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
        KeyEvent kev = new KeyEvent(
            (Component)keyEvent.getSource(), KeyEvent.KEY_RELEASED, keyEvent.getWhen(),
            keyEvent.getModifiers(), keyEvent.getKeyCode(), keyEvent.getKeyChar()

        );
        KeyboardPopupSwitcher.processInterruption(kev);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:KeyboardPopupSwitcher.java

示例5: pumpApprovedKeyEvents

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:DefaultKeyboardFocusManager.java

示例6: processKeyBinding

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
protected @Override boolean processKeyBinding(KeyStroke ks,
                                KeyEvent e,
                                int condition,
                                boolean pressed) {
    if (Utilities.isMac()) {
        int mods = e.getModifiers();
        boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0;
        boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0;
        if (isAlt && (e instanceof MarkedKeyEvent)) {
            mods = mods & ~ KeyEvent.CTRL_MASK;
            mods = mods & ~ KeyEvent.CTRL_DOWN_MASK;
            mods |= KeyEvent.ALT_MASK;
            mods |= KeyEvent.ALT_DOWN_MASK;
            
            KeyEvent newEvent = new MarkedKeyEvent (
                (Component) e.getSource(), e.getID(), 
                e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(), 
                e.getKeyLocation());
            
            KeyStroke newStroke = null;
            if( null != ks ) {
                newStroke = e.getID() == KeyEvent.KEY_TYPED ?
                    KeyStroke.getKeyStroke (ks.getKeyChar(), mods) :
                    KeyStroke.getKeyStroke (ks.getKeyCode(), mods,
                    !ks.isOnKeyRelease());
            }
            
            boolean result = super.processKeyBinding (newStroke, 
                newEvent, condition, pressed);
            
            if (newEvent.isConsumed()) {
                e.consume();
            }
            return result;
        } else if (!isAlt) {
            return super.processKeyBinding (ks, e, condition, pressed);
        } else {
            return false;
        }
    } else {
        return super.processKeyBinding (ks, e, condition, pressed);
    }                     
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:MenuBar.java

示例7: altReleased

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
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);
        }
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:WindowsRootPaneUI.java

示例8: createNew

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public KeyEvent createNew(KeyEvent old) {
    return new KeyEvent(component, old.getID(), old.getWhen(), old.getModifiers(), old.getKeyCode(),
            old.getKeyChar(), old.getKeyLocation());
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:5,代码来源:InternalKeyboard.java


注:本文中的java.awt.event.KeyEvent.getWhen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。