本文整理汇总了Java中java.awt.DefaultKeyboardFocusManager类的典型用法代码示例。如果您正苦于以下问题:Java DefaultKeyboardFocusManager类的具体用法?Java DefaultKeyboardFocusManager怎么用?Java DefaultKeyboardFocusManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultKeyboardFocusManager类属于java.awt包,在下文中一共展示了DefaultKeyboardFocusManager类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testKeyboardFocusManager
import java.awt.DefaultKeyboardFocusManager; //导入依赖的package包/类
/**
* Test that listener copes with change of keyboardFocusManager.
*
* Not yet implemented.
*
* @throws InterruptedException
* @throws InvocationTargetException
*/
@Test
public void testKeyboardFocusManager() throws InterruptedException, InvocationTargetException {
// This test will not work in a headless configuration.
if (GraphicsEnvironment.isHeadless()) {
LOG.fine("cannot run test - headless environment");
return;
}
JXDatePicker picker = getRealizedDatePicker();
final KeyboardFocusManager oldManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Component focusOwner = oldManager.getPermanentFocusOwner();
assertFalse("sanity: initial focus must not be in picker",
SwingXUtilities.isDescendingFrom(focusOwner, picker));
CompoundFocusListener l = new CompoundFocusListener(picker);
final PropertyChangeReport report = new PropertyChangeReport();
l.addPropertyChangeListener(report);
KeyboardFocusManager customManager = new DefaultKeyboardFocusManager();
KeyboardFocusManager.setCurrentKeyboardFocusManager(customManager);
LOG.info("after custom? ");
picker.requestFocusInWindow();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
assertEquals(1, report.getEventCount("focused"));
} finally {
KeyboardFocusManager.setCurrentKeyboardFocusManager(oldManager);
}
}
});
}
示例2: testKeyboardFocusManager_addKeyEventPostProcessor
import java.awt.DefaultKeyboardFocusManager; //导入依赖的package包/类
public Result testKeyboardFocusManager_addKeyEventPostProcessor() {
MyKeyboardFocusManager keyEvPostProcessor = new MyKeyboardFocusManager();
DefaultKeyboardFocusManager dkfm = new DefaultKeyboardFocusManager();
dkfm.addKeyEventPostProcessor(keyEvPostProcessor);
/* Implicit call of MyKeyboardFocusManager#postProcessKeyEvent */
dkfm.dispatchKeyEvent(provideKeyEvent(0, KeyEvent.VK_SPACE, ' '));
if (keyEvPostProcessor.postProcessKeyEventCalled == false) {
return failed("\nMyKeyboardFocusManager#postProcessKeyEvent has "
+ "not been called");
}
return passed();
}
示例3: testWindow_getMostRecentFocusOwner
import java.awt.DefaultKeyboardFocusManager; //导入依赖的package包/类
public Result testWindow_getMostRecentFocusOwner() {
/* There is only one Panel within this window */
if (wnd.getComponents().length <= 0 || wnd.getComponents().length > 1) {
return failed("\n Wrong number of components in window");
}
/*
* In order for Window to become focusable it is required to show Frame
* see javadoc for Component.requestFocusInWindow() method
*/
frm.setVisible(true);
wnd.setVisible(true);
sleep(getPaintTimeout());
boolean isWindowFocusable = wnd.isFocusableWindow();
if (isWindowFocusable == false) {
return failed("\nFor some reason window can't gain focus");
}
sleep(getPaintTimeout());
/* Gain btnDoNothing instance */
Button btn = (Button) ((Container) wnd.getComponents()[0])
.getComponents()[0];
btn.requestFocus();
waitEventQueueToClear();
/* this must be btnClose */
Button mostRecentFocusOwner = (Button) wnd.getMostRecentFocusOwner();
sleep(getPaintTimeout());
if (mostRecentFocusOwner.getLabel().equals(btnClose.getLabel()) == false) {
return failed("\ngetMostRecentFocusOwner() returned wrong component");
}
/* Clears focus from all elements */
DefaultKeyboardFocusManager dkfm = new DefaultKeyboardFocusManager();
sleep(getPaintTimeout());
/*
* If no child Component has ever requested focus, and this is a
* non-focusable Window, Window#getMostRecentFocusOwnernull returns
* null.
*/
dkfm.clearGlobalFocusOwner();
wnd.dispose();
wnd.setVisible(false);
waitEventQueueToClear();
sleep(getPaintTimeout());
if (wnd.getMostRecentFocusOwner() != null) {
return failed("\ngetMostRecentFocusOwner() did not return null");
}
frm.dispose();
wnd.dispose();
return passed();
}
示例4: testKeyboardFocusManager_clearGlobalFocusOwner
import java.awt.DefaultKeyboardFocusManager; //导入依赖的package包/类
public Result testKeyboardFocusManager_clearGlobalFocusOwner() {
frm.setVisible(true);
/* Get instance of btnClose button */
Button btn = (Button) ((Container) frm.getComponents()[0])
.getComponents()[0];
btn.requestFocus();
MyKeyboardFocusManager keyEvPostProcessor = new MyKeyboardFocusManager();
DefaultKeyboardFocusManager dkfm = new DefaultKeyboardFocusManager();
dkfm.addKeyEventPostProcessor(keyEvPostProcessor);
Robot robo = null;
try {
robo = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
/* Move mouse to the btn (btnClose) */
robo.mouseMove(btn.getX() - 5, btn.getY() - 5);
componentEventFocusLost = false;
/*
* This sleep is required because drawing of the GUI components on Linux
* PCs can be very slow
*/
sleep(getPaintTimeout());
waitEventQueueToClear();
/* FOCUS_LOST event must be sent to btn (btnClose) */
dkfm.clearGlobalFocusOwner();
waitEventQueueToClear();
sleep(getPaintTimeout());
if (componentEventFocusLost == false) {
return failed("\nThe component failed to recieve a FOCUS_LOST event");
}
/* reset the actionPerformed flag */
actionPerformed = false;
/*
* Click button, the button must not be clicked and "actionPerformed"
* flag should not be set
*/
robo.keyPress(KeyEvent.VK_ENTER);
robo.keyRelease(KeyEvent.VK_ENTER);
waitEventQueueToClear();
// System.out.println("actionPerformed: " + componentEventFocusLost);
// System.out.println("componentEventFocusLost: "
// + componentEventFocusLost);
if (actionPerformed) {
return failed("\nAfter calling clearGlobalFocusOwner() \"the native "
+ "windowing system will discard all user-generated "
+ "KeyEvents\" in our keyPress and keyRelease occured on "
+ "a button");
}
return passed();
}
示例5: consumeNextKeyTyped
import java.awt.DefaultKeyboardFocusManager; //导入依赖的package包/类
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);