本文整理汇总了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;
}
}
}
示例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;
}
示例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;
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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());
}