下面列出了怎么用java.awt.Event的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Method to register a hotkey using the RegisterHotKey Windows API call.
* <p>
*
* @param aEvent the ActionEvent fired.
*/
private void btnRegisterHotKey_actionPerformed(ActionEvent aEvent) {
// assign the WINDOWS+A key to the unique id 88 for identification
JIntellitype.getInstance().registerHotKey(WINDOWS_A, JIntellitype.MOD_WIN, 'A');
JIntellitype.getInstance().registerHotKey(ALT_SHIFT_B, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, 'B');
JIntellitype.getInstance().registerSwingHotKey(CTRL_SHIFT_C, Event.CTRL_MASK + Event.SHIFT_MASK, 'C');
// use a 0 for the modifier if you just want a single keystroke to be a
// hotkey
JIntellitype.getInstance().registerHotKey(PRINT_SCREEN, 0, 44);
JIntellitype.getInstance().registerHotKey(F11, "F11");
JIntellitype.getInstance().registerHotKey(F12, JIntellitype.MOD_ALT, 123);
JIntellitype.getInstance().registerHotKey(SEMICOLON, 0, 186);
JIntellitype.getInstance().registerHotKey(TICK, 0, 192);
// clear the text area
textArea.setText("");
output("RegisterHotKey WINDOWS+A was assigned uniqueID 88");
output("RegisterHotKey ALT+SHIFT+B was assigned uniqueID 89");
output("RegisterHotKey CTRL+SHIFT+C was assigned uniqueID 90");
output("RegisterHotKey PRINT_SCREEN was assigned uniqueID 91");
output("RegisterHotKey F9 was assigned uniqueID 92");
output("RegisterHotKey F12 was assigned uniqueID 93");
output("RegisterHotKey SEMICOLON was assigned uniqueID 94");
output("Press WINDOWS+A or ALT+SHIFT+B or CTRL+SHIFT+C in another application and you will see the debug output in the textarea.");
}
private void processKey(char key) {
//out("select: '" + key);
if (((int) key) == Event.BACK_SPACE) {
init();
return;
}
myPrefix += key;
myPrefix = myPrefix.toLowerCase();
//out("prefix: " + myPrefix);
for (int i = myIndex; i < getItemCount(); i++) {
String item = getItemAt(i).toString().toLowerCase();
//out(" see: " + item);
if (item.startsWith(myPrefix)) {
myIndex = i;
return;
}
}
}
/**
* Method declaration
*
*
* @param e
*/
// [email protected] 20020130 - comment by fredt
// to remove this deprecated method we need to rewrite the Tree class as a
// ScrollPane component
public boolean handleEvent(Event e) {
switch (e.id) {
case Event.SCROLL_LINE_UP :
case Event.SCROLL_LINE_DOWN :
case Event.SCROLL_PAGE_UP :
case Event.SCROLL_PAGE_DOWN :
case Event.SCROLL_ABSOLUTE :
iX = sbHoriz.getValue();
iY = iRowHeight * sbVert.getValue();
repaint();
return true;
}
return super.handleEvent(e);
}
/**
* Method declaration
*
*
* @param e
*/
// [email protected] 20020130 - comment by fredt
// to remove this deprecated method we need to rewrite the Grid class as a
// ScrollPane component
// sqlbob: I believe that changing to the JDK1.1 event handler
// would require browsers to use the Java plugin.
public boolean handleEvent(Event e) {
switch (e.id) {
case Event.SCROLL_LINE_UP :
case Event.SCROLL_LINE_DOWN :
case Event.SCROLL_PAGE_UP :
case Event.SCROLL_PAGE_DOWN :
case Event.SCROLL_ABSOLUTE :
iX = sbHoriz.getValue();
iY = iRowHeight * sbVert.getValue();
repaint();
return true;
}
return super.handleEvent(e);
}
/**
* Method declaration
*
*
* @param e
* @param x
* @param y
*/
public boolean mouseDrag(Event e, int x, int y) {
if (bDrag && x < iWidth) {
int w = x - iXDrag;
if (w < 0) {
w = 0;
}
iColWidth[iColDrag] = w;
adjustScroll();
repaint();
}
return true;
}
public void actionPerformed(ActionEvent event) {
Object src = event.getSource();
if (src == download) {
DownloadView d = DownloadView.create(searchView.getArchive(), doc);
searchView.doDownload(d);
}
if (src == details) {
if ((event.getModifiers() & Event.SHIFT_MASK) == Event.SHIFT_MASK) {
// This is indented for debugging!
entry.setContentType("text/plain"); //$NON-NLS-1$
entry.setText(doc.toString());
}
else {
doToggleDetails();
}
}
if (src == gplay) {
BrowseUtil.openUrl(doc.getShareUrl());
SwingUtilities.invokeLater(searchView); // Re - focus
}
if (src == permissions) {
doTogglePermissions();
}
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
@Override
public void show(Event e) {
Component origin = (Component)e.target;
if (origin != null) {
Point loc = origin.getLocationOnScreen();
e.x += loc.x;
e.y += loc.y;
execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
}
}
private void setupActions() {
DockingAction action = new DockingAction("Hello World", getName() ) {
@Override
public void actionPerformed( ActionContext context ) {
Msg.info(this, "Hello World:: action");
announce("Hello World");
}
};
action.setEnabled( true );
String helloGroup = "Hello";
ImageIcon prevImage = ResourceManager.loadImage(PREV_IMAGE);
action.setMenuBarData( new MenuData( new String[] {"Misc", "Hello World"}, prevImage, helloGroup ) );
action.setPopupMenuData( new MenuData( new String[] {"Hello World"}, prevImage, helloGroup ) );
action.setKeyBindingData( new KeyBindingData( KeyStroke.getKeyStroke('H', Event.CTRL_MASK ) ) );
action.setToolBarData( new ToolBarData( prevImage, helloGroup ) );
action.setDescription("Hello World");
action.setHelpLocation(new HelpLocation("SampleHelpTopic", "KS_Hello_World"));
tool.addAction(action);
action = new DockingAction("Hello Program", getName() ) {
@Override
public void actionPerformed( ActionContext context ) {
Msg.info(this, "Hello Program:: action");
sayHelloProgram();
}
};
action.setEnabled(false);
ImageIcon nextImage = ResourceManager.loadImage(NEXT_IMAGE);
action.setMenuBarData( new MenuData( new String[]{"Misc", "Hello Program"}, nextImage, helloGroup ) );
action.setKeyBindingData( new KeyBindingData( KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK ) ) );
action.setToolBarData( new ToolBarData( nextImage, helloGroup ) );
action.setDescription("Hello Program");
action.setHelpLocation(new HelpLocation("SampleHelpTopic", "KS_Hello_Program"));
tool.addAction(action);
// remember this action so I can enable/disable it later
helloProgramAction = action;
}
@Override
public void show(Event e) {
Component origin = (Component)e.target;
if (origin != null) {
Point loc = origin.getLocationOnScreen();
e.x += loc.x;
e.y += loc.y;
execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
}
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
private int defaultStopHotkeyModifiers() {
int mod = Event.SHIFT_MASK + Event.META_MASK;
if (!Settings.isMac()) {
mod = Event.SHIFT_MASK + Event.ALT_MASK;
}
return mod;
}
@Override public void checkIOIntegration(final Event e) {
try {
queue.put(e.key);
} catch (InterruptedException ex) {
Logger.getLogger(Console.class.getName()).
log(Level.SEVERE, null, ex);
}
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
public static RTObject ctor1(final Event e) {
final Type intType = StaticScope.globalScope().lookupTypeDeclaration("int");
final StaticScope intScope = intType.enclosedScope();
final RTType rTIntType = InterpretiveCodeGenerator.scopeToRTTypeDeclaration(intScope);
final Type stringType = StaticScope.globalScope().lookupTypeDeclaration("String");
final StaticScope stringScope = stringType.enclosedScope();
final RTType rTStringType = InterpretiveCodeGenerator.scopeToRTTypeDeclaration(stringScope);
final Type eventType = StaticScope.globalScope().lookupTypeDeclaration("Event");
final StaticScope eventScope = eventType.enclosedScope();
final RTType rTEventType = InterpretiveCodeGenerator.scopeToRTTypeDeclaration(eventScope);
final RTObject theEventObject = new RTObjectCommon(rTEventType);
theEventObject.addObjectDeclaration("id", rTIntType);
theEventObject.addObjectDeclaration("key", rTIntType);
theEventObject.addObjectDeclaration("keyString", rTStringType);
theEventObject.addObjectDeclaration("x", rTIntType);
theEventObject.addObjectDeclaration("y", rTIntType);
theEventObject.setObject("x", new RTIntegerObject(e.x));
theEventObject.setObject("y", new RTIntegerObject(e.y));
theEventObject.setObject("id", new RTIntegerObject(e.id));
theEventObject.setObject("key", new RTIntegerObject(e.key));
final char cKey = (char)e.key;
final String keyAsString = "" + cKey;
theEventObject.setObject("keyString", new RTStringObject(keyAsString));
return theEventObject;
}
public String getMenuKey() {
int menuShortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
if ((menuShortcutKeyMask & Event.CTRL_MASK) == Event.CTRL_MASK) {
return "Control";
}
if ((menuShortcutKeyMask & Event.META_MASK) == Event.META_MASK) {
return "Meta";
}
return "";
}
public static Keys getMenuKey() {
int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
if (keyMask == Event.CTRL_MASK) {
return Keys.CONTROL;
}
if (keyMask == Event.META_MASK) {
return Keys.META;
}
if (keyMask == Event.ALT_MASK) {
return Keys.ALT;
}
throw new WebDriverException("Unable to find the keymask... not control or meta?");
}
private void resourceResolverShouldBeIgnoredWhenResolverFactoryIsExecutedInMethodFromDifferentClass(
Event event, List<String> attributesList) {
if (attributesList.containsAll(ATTRIBUTES)) {
String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
try {
SlingHelper.operate(resolverFactory, resolver -> processPackage(resolver, path));
} catch (OperateException e) {
System.out.println("something went wrong");
}
}
}
@Override
public void show(Event e) {
Component origin = (Component)e.target;
if (origin != null) {
Point loc = origin.getLocationOnScreen();
e.x += loc.x;
e.y += loc.y;
execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
}
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
/**
* Adds the specified mnemonic at the specified index.
*/
private void addMnemonic(int index, int mnemonic) {
if (mnemonicToIndexMap == null) {
initMnemonics();
}
mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, Event.ALT_MASK), "setSelectedIndex");
mnemonicToIndexMap.put(new Integer(mnemonic), new Integer(index));
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
@Override
public void show(Event e) {
Component origin = (Component)e.target;
if (origin != null) {
Point loc = origin.getLocationOnScreen();
e.x += loc.x;
e.y += loc.y;
execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
}
}
@Override
@SuppressWarnings("deprecation")
public void show(Event e) {
Component origin = (Component)e.target;
if (origin != null) {
Point loc = origin.getLocationOnScreen();
e.x += loc.x;
e.y += loc.y;
execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
}
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
/**
* Method declaration
*
*
* @param e
* @param x
* @param y
*/
public boolean mouseMove(Event e, int x, int y) {
if (y <= iRowHeight) {
int xb = x;
x += iX - iGridWidth;
int i = iColCount - 1;
for (; i >= 0; i--) {
if (x > -7 && x < 7) {
break;
}
x += iColWidth[i];
}
if (i >= 0) {
if (!bDrag) {
setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
bDrag = true;
iXDrag = xb - iColWidth[i];
iColDrag = i;
}
return true;
}
}
return mouseExit(e, x, y);
}
/**
* Method declaration
*
*
* @param e
* @param x
* @param y
*/
public boolean mouseExit(Event e, int x, int y) {
if (bDrag) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
bDrag = false;
}
return true;
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}
@Override
public void show(Event e) {
Component origin = (Component)e.target;
if (origin != null) {
Point loc = origin.getLocationOnScreen();
e.x += loc.x;
e.y += loc.y;
execute(ptr -> nativeShowPopupMenu(ptr, e.x, e.y));
}
}
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
}