Java 类java.awt.DefaultKeyboardFocusManager 实例源码

项目:swingx    文件:CompoundFocusListenerIssues.java   
/**
 * 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);
            }
        }
    });
}
项目:freeVM    文件:KeyboardFocusManagerTest.java   
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();
}
项目:freeVM    文件:WindowTest.java   
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();
    }
项目:freeVM    文件:KeyboardFocusManagerTest.java   
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();
    }
项目:OpenJSharp    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:jdk8u-jdk    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:jdk8u_jdk    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:lookaside_java-1.8.0-openjdk    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:infobip-open-jdk-8    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:jdk8u-dev-jdk    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:OLD-OpenJDK8    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:openjdk-jdk7u-jdk    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);
项目:openjdk-icedtea7    文件:AWTAccessor.java   
public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e);