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


Java ComponentPeer.handleEvent方法代码示例

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


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

示例1: dispatchKeyEvent

import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
/**
 * Called by <code>dispatchEvent</code> if no other
 * KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or
 * if no other KeyEventDispatchers are registered. If the event has not
 * been consumed, its target is enabled, and the focus owner is not null,
 * this method dispatches the event to its target. This method will also
 * subsequently dispatch the event to all registered
 * KeyEventPostProcessors. After all this operations are finished,
 * the event is passed to peers for processing.
 * <p>
 * In all cases, this method returns <code>true</code>, since
 * DefaultKeyboardFocusManager is designed so that neither
 * <code>dispatchEvent</code>, nor the AWT event dispatcher, should take
 * further action on the event in any situation.
 *
 * @param e the KeyEvent to be dispatched
 * @return <code>true</code>
 * @see Component#dispatchEvent
 */
public boolean dispatchKeyEvent(KeyEvent e) {
    Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();

    if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
        if (!e.isConsumed()) {
            Component comp = e.getComponent();
            if (comp != null && comp.isEnabled()) {
                redispatchEvent(comp, e);
            }
        }
    }
    boolean stopPostProcessing = false;
    java.util.List<KeyEventPostProcessor> processors = getKeyEventPostProcessors();
    if (processors != null) {
        for (java.util.Iterator<KeyEventPostProcessor> iter = processors.iterator();
             !stopPostProcessing && iter.hasNext(); )
        {
            stopPostProcessing = iter.next().
                        postProcessKeyEvent(e);
        }
    }
    if (!stopPostProcessing) {
        postProcessKeyEvent(e);
    }

    // Allow the peer to process KeyEvent
    Component source = e.getComponent();
    ComponentPeer peer = source.getPeer();

    if (peer == null || peer instanceof LightweightPeer) {
        // if focus owner is lightweight then its native container
        // processes event
        Container target = source.getNativeContainer();
        if (target != null) {
            peer = target.getPeer();
        }
    }
    if (peer != null) {
        peer.handleEvent(e);
    }

    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:63,代码来源:DefaultKeyboardFocusManager.java

示例2: preDispatchKeyEvent

import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
private boolean preDispatchKeyEvent(KeyEvent ke) {
    if (((AWTEvent) ke).isPosted) {
        Component focusOwner = getFocusOwner();
        ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
    }
    if (ke.getSource() == null) {
        return true;
    }

    // Explicitly set the key event timestamp here (not in Component.dispatchEventImpl):
    // - A key event is anyway passed to this method which starts its actual dispatching.
    // - If a key event is put to the type ahead queue, its time stamp should not be registered
    //   until its dispatching actually starts (by this method).
    EventQueue.setCurrentEventAndMostRecentTime(ke);

    /**
     * Fix for 4495473.
     * This fix allows to correctly dispatch events when native
     * event proxying mechanism is active.
     * If it is active we should redispatch key events after
     * we detected its correct target.
     */
    if (KeyboardFocusManager.isProxyActive(ke)) {
        Component source = (Component)ke.getSource();
        Container target = source.getNativeContainer();
        if (target != null) {
            ComponentPeer peer = target.getPeer();
            if (peer != null) {
                peer.handleEvent(ke);
                /**
                 * Fix for 4478780 - consume event after it was dispatched by peer.
                 */
                ke.consume();
            }
        }
        return true;
    }

    java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers();
    if (dispatchers != null) {
        for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator();
             iter.hasNext(); )
         {
             if (iter.next().
                 dispatchKeyEvent(ke))
             {
                 return true;
             }
         }
    }
    return dispatchKeyEvent(ke);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:DefaultKeyboardFocusManager.java

示例3: dispatchKeyEvent

import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
/**
 * Called by {@code dispatchEvent} if no other
 * KeyEventDispatcher in the dispatcher chain dispatched the KeyEvent, or
 * if no other KeyEventDispatchers are registered. If the event has not
 * been consumed, its target is enabled, and the focus owner is not null,
 * this method dispatches the event to its target. This method will also
 * subsequently dispatch the event to all registered
 * KeyEventPostProcessors. After all this operations are finished,
 * the event is passed to peers for processing.
 * <p>
 * In all cases, this method returns {@code true}, since
 * DefaultKeyboardFocusManager is designed so that neither
 * {@code dispatchEvent}, nor the AWT event dispatcher, should take
 * further action on the event in any situation.
 *
 * @param e the KeyEvent to be dispatched
 * @return {@code true}
 * @see Component#dispatchEvent
 */
public boolean dispatchKeyEvent(KeyEvent e) {
    Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();

    if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
        if (!e.isConsumed()) {
            Component comp = e.getComponent();
            if (comp != null && comp.isEnabled()) {
                redispatchEvent(comp, e);
            }
        }
    }
    boolean stopPostProcessing = false;
    java.util.List<KeyEventPostProcessor> processors = getKeyEventPostProcessors();
    if (processors != null) {
        for (java.util.Iterator<KeyEventPostProcessor> iter = processors.iterator();
             !stopPostProcessing && iter.hasNext(); )
        {
            stopPostProcessing = iter.next().
                        postProcessKeyEvent(e);
        }
    }
    if (!stopPostProcessing) {
        postProcessKeyEvent(e);
    }

    // Allow the peer to process KeyEvent
    Component source = e.getComponent();
    ComponentPeer peer = source.peer;

    if (peer == null || peer instanceof LightweightPeer) {
        // if focus owner is lightweight then its native container
        // processes event
        Container target = source.getNativeContainer();
        if (target != null) {
            peer = target.peer;
        }
    }
    if (peer != null) {
        peer.handleEvent(e);
    }

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:63,代码来源:DefaultKeyboardFocusManager.java

示例4: preDispatchKeyEvent

import java.awt.peer.ComponentPeer; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private boolean preDispatchKeyEvent(KeyEvent ke) {
    if (((AWTEvent) ke).isPosted) {
        Component focusOwner = getFocusOwner();
        ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
    }
    if (ke.getSource() == null) {
        return true;
    }

    // Explicitly set the key event timestamp here (not in Component.dispatchEventImpl):
    // - A key event is anyway passed to this method which starts its actual dispatching.
    // - If a key event is put to the type ahead queue, its time stamp should not be registered
    //   until its dispatching actually starts (by this method).
    EventQueue.setCurrentEventAndMostRecentTime(ke);

    /**
     * Fix for 4495473.
     * This fix allows to correctly dispatch events when native
     * event proxying mechanism is active.
     * If it is active we should redispatch key events after
     * we detected its correct target.
     */
    if (KeyboardFocusManager.isProxyActive(ke)) {
        Component source = (Component)ke.getSource();
        Container target = source.getNativeContainer();
        if (target != null) {
            ComponentPeer peer = target.peer;
            if (peer != null) {
                peer.handleEvent(ke);
                /**
                 * Fix for 4478780 - consume event after it was dispatched by peer.
                 */
                ke.consume();
            }
        }
        return true;
    }

    java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers();
    if (dispatchers != null) {
        for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator();
             iter.hasNext(); )
         {
             if (iter.next().
                 dispatchKeyEvent(ke))
             {
                 return true;
             }
         }
    }
    return dispatchKeyEvent(ke);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:54,代码来源:DefaultKeyboardFocusManager.java


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