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


Java EventQueue.getCurrentEvent方法代码示例

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


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

示例1: trySendEnterToDialog

import java.awt.EventQueue; //导入方法依赖的package包/类
private void trySendEnterToDialog() {
    //        System.err.println("SendEnterToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        JRootPane jrp = getRootPane();

        if (jrp != null) {
            JButton b = jrp.getDefaultButton();

            if ((b != null) && b.isEnabled()) {
                b.doClick();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:EditablePropertyDisplayer.java

示例2: trySendEnterToDialog

import java.awt.EventQueue; //导入方法依赖的package包/类
private void trySendEnterToDialog(BaseTable bt) {
    //        System.err.println("SendEnterToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        JRootPane jrp = bt.getRootPane();

        if (jrp != null) {
            JButton b = jrp.getDefaultButton();

            if ((b != null) && b.isEnabled()) {
                b.doClick();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:BaseTable.java

示例3: actionPerformed

import java.awt.EventQueue; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
    setFocusCycleRoot(false);

    try {
        Container con = BaseTable.this.getFocusCycleRootAncestor();

        if (con != null) {
            Component target = BaseTable.this;

            if (getParent() instanceof JViewport) {
                target = getParent().getParent();

                if (target == con) {
                    target = BaseTable.this;
                }
            }

            EventObject eo = EventQueue.getCurrentEvent();
            boolean backward = false;

            if (eo instanceof KeyEvent) {
                backward = ((((KeyEvent) eo).getModifiers() & KeyEvent.SHIFT_MASK) != 0) &&
                    ((((KeyEvent) eo).getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0);
            }

            Component to = backward ? con.getFocusTraversalPolicy().getComponentAfter(con, BaseTable.this)
                                    : con.getFocusTraversalPolicy().getComponentAfter(con, BaseTable.this);

            if (to == BaseTable.this) {
                to = backward ? con.getFocusTraversalPolicy().getFirstComponent(con)
                              : con.getFocusTraversalPolicy().getLastComponent(con);
            }

            to.requestFocus();
        }
    } finally {
        setFocusCycleRoot(true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:BaseTable.java

示例4: drainEventQueue

import java.awt.EventQueue; //导入方法依赖的package包/类
/** Drain the event queue.  ONLY CALL THIS METHOD FROM THE EVENT DISPATCH
 * THREAD OR IT WILL DO BAD THINGS! */
private static void drainEventQueue() throws Exception {
    AWTEvent evt = EventQueue.getCurrentEvent();
    //Dispatch any events that the code that just ran may have generated,
    //so dialogs appear, things get focus and paint, stuff like that
    while (Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent() != null) {
        //do fetch this every time, its value can change
        EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        evt = queue.getNextEvent();
        dispatchEvent(queue, evt);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ExtTestCase.java

示例5: postInAwtAndWaitOutsideAwt

import java.awt.EventQueue; //导入方法依赖的package包/类
static void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception {
        // pendig to better implementation
        SwingUtilities.invokeLater (run);
//        Thread.sleep (10);
        while (EventQueue.getCurrentEvent () != null) {
//            Thread.sleep (10);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:DialogDisplayerImplTest.java

示例6: fireActionPerformed

import java.awt.EventQueue; //导入方法依赖的package包/类
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @see EventListenerList
 */
protected void fireActionPerformed(String command) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    long mostRecentEventTime = EventQueue.getMostRecentEventTime();
    int modifiers = 0;
    AWTEvent currentEvent = EventQueue.getCurrentEvent();
    if (currentEvent instanceof InputEvent) {
        modifiers = ((InputEvent)currentEvent).getModifiers();
    } else if (currentEvent instanceof ActionEvent) {
        modifiers = ((ActionEvent)currentEvent).getModifiers();
    }
    ActionEvent e = null;
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==ActionListener.class) {
            // Lazily create the event:
            if (e == null) {
                e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
                                    command, mostRecentEventTime,
                                    modifiers);
            }
            ((ActionListener)listeners[i+1]).actionPerformed(e);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:JFileChooser.java

示例7: fireActionPerformed

import java.awt.EventQueue; //导入方法依赖的package包/类
/**
 * Notifies all listeners that have registered interest for
 * notification on this event type. The event instance
 * is lazily created using the <code>command</code> parameter.
 *
 * @param command a string that may specify a command associated with
 *                the event
 * @see EventListenerList
 */
@SuppressWarnings("deprecation")
protected void fireActionPerformed(String command) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    long mostRecentEventTime = EventQueue.getMostRecentEventTime();
    int modifiers = 0;
    AWTEvent currentEvent = EventQueue.getCurrentEvent();
    if (currentEvent instanceof InputEvent) {
        modifiers = ((InputEvent)currentEvent).getModifiers();
    } else if (currentEvent instanceof ActionEvent) {
        modifiers = ((ActionEvent)currentEvent).getModifiers();
    }
    ActionEvent e = null;
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==ActionListener.class) {
            // Lazily create the event:
            if (e == null) {
                e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
                                    command, mostRecentEventTime,
                                    modifiers);
            }
            ((ActionListener)listeners[i+1]).actionPerformed(e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:JFileChooser.java

示例8: trySendEscToDialog

import java.awt.EventQueue; //导入方法依赖的package包/类
/** Transmits escape sequence to dialog */
private void trySendEscToDialog() {
    if (isTableUI()) {
        //let the table decide, don't be preemptive
        return;
    }

    //        System.err.println("SendEscToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        ActionMap am = getRootPane().getActionMap();

        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Object key = imp.get(escape);

        if (key != null) {
            Action a = am.get(key);

            if (a != null) {
                if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N
                    System.err.println("Action bound to escape key is " + a); //NOI18N
                }

                String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY);

                if (commandKey == null) {
                    commandKey = "cancel"; //NOI18N
                }

                a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:EditablePropertyDisplayer.java

示例9: replaceInner

import java.awt.EventQueue; //导入方法依赖的package包/类
protected final void replaceInner() {
    inReplaceInner = true;

    try {
        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        boolean hadFocus = isEnabled() &&
            ((focusOwner == this) || isAncestorOf(focusOwner) ||
            ((getInplaceEditor() != null) && getInplaceEditor().isKnownComponent(focusOwner)));

        //Figure out if a combo popup was open, so we can re-open it.
        //If we're processing a mouse event, close it because that's
        //the normal behavior of a popup.  We want arrow keyboard events
        //to not trigger closing of the popup if they caused a change
        //to a value that is marked as invalid
        boolean wasComboPopup = hadFocus && focusOwner instanceof JComboBox &&
            ((JComboBox) focusOwner).isPopupVisible() &&
            (EventQueue.getCurrentEvent() instanceof KeyEvent &&
            ((((KeyEvent) EventQueue.getCurrentEvent()).getKeyCode() == KeyEvent.VK_UP) ||
            (((KeyEvent) EventQueue.getCurrentEvent()).getKeyCode() == KeyEvent.VK_DOWN)));

        //            System.err.println("REPLACE INNER - " + prop.getDisplayName() + " focus:" + hadFocus);
        if (hadFocus) {
            //We don't want focus to jump to another component and back
            KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
        }

        setInplaceEditor(createInplaceEditor());

        if (hadFocus) {
            requestFocus();

            //At this point the focus owner is still null, the event is queued - 
            if (wasComboPopup) {
                //We have to let the request focus on the event queue get
                //processed before this can be done, or the component will
                //not yet be laid out and the popup will be 1 pixel wide
                SwingUtilities.invokeLater(
                    new Runnable() {
                        public void run() {
                            InplaceEditor ied = getInplaceEditor();
                            ied = PropUtils.findInnermostInplaceEditor(ied);

                            JComponent c = ied.getComponent();

                            if (c instanceof JComboBox && c.isShowing()) {
                                ((JComboBox) c).showPopup();
                            }
                        }
                    }
                );
            }
        }

        revalidate();
        repaint();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        inReplaceInner = false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:EditorPropertyDisplayer.java

示例10: trySendEscToDialog

import java.awt.EventQueue; //导入方法依赖的package包/类
private void trySendEscToDialog(JTable jt) {
    //        System.err.println("SendEscToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        InputMap imp = jt.getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        ActionMap am = jt.getRootPane().getActionMap();

        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Object key = imp.get(escape);

        if (key != null) {
            Action a = am.get(key);

            if (a != null) {
                if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N
                    System.err.println("Action bound to escape key is " + a); //NOI18N
                }

                //Actions registered with deprecated registerKeyboardAction will
                //need this lookup of the action command
                String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY);

                if (commandKey == null) {
                    commandKey = "cancel"; //NOI18N
                }

                a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:BaseTable.java

示例11: actionPerformed

import java.awt.EventQueue; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    setFocusCycleRoot(false);
    try {
        Container con = ETable.this.getFocusCycleRootAncestor();
        if (con != null) {
            /*
            Component target = ETable.this;
            if (getParent() instanceof JViewport) {
                target = getParent().getParent();
                if (target == con) {
                    target = ETable.this;
                }
            }
            */

            EventObject eo = EventQueue.getCurrentEvent();
            boolean backward = false;
            if (eo instanceof KeyEvent) {
                backward = 
                    (((KeyEvent) eo).getModifiers() 
                    & KeyEvent.SHIFT_MASK) 
                    != 0 && (((KeyEvent) eo).getModifiersEx() & 
                    KeyEvent.SHIFT_DOWN_MASK) != 0;
            }

            Component c = ETable.this;
            Component to;
            Container parentWithFTP = null;
            do {
                FocusTraversalPolicy ftp = con.getFocusTraversalPolicy();
                to = backward ? ftp.getComponentBefore(con, c)
                              : ftp.getComponentAfter(con, c);


                if (to == ETable.this) {
                    to = backward ? ftp.getFirstComponent(con)
                                  : ftp.getLastComponent(con);
                }
                if (to == ETable.this) {
                    parentWithFTP = con.getParent();
                    if (parentWithFTP != null) {
                        parentWithFTP = parentWithFTP.getFocusCycleRootAncestor();
                    }
                    if (parentWithFTP != null) {
                        c = con;
                        con = parentWithFTP;
                    }
                }
            } while (to == ETable.this && parentWithFTP != null);
            if (to != null) {
                to.requestFocus();
            }
        }
    } finally {
        setFocusCycleRoot(true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:ETable.java

示例12: actionPerformed

import java.awt.EventQueue; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("actionCommand='" + evt.getActionCommand() //NOI18N
                + "', modifiers=" + evt.getModifiers() //NOI18N
                + ", when=" + evt.getWhen() //NOI18N
                + ", paramString='" + evt.paramString() + "'"); //NOI18N
    }
    
    if (target == null) {
        return;
    }

    BaseKit kit = Utilities.getKit(target);
    if (kit == null) {
        return;
    }

    BaseDocument doc = Utilities.getDocument(target);
    if (doc == null) {
        return;
    }

    // changed as reponse to #250157: other events may get fired during
    // the course of key binding processing and if an event is processed
    // as nested (i.e. hierarchy change resulting from a component retracting from the screen),
    // thie following test would fail.
    AWTEvent maybeKeyEvent = EventQueue.getCurrentEvent();
    KeyStroke keyStroke = null;
    
    if (maybeKeyEvent instanceof KeyEvent) {
        keyStroke = KeyStroke.getKeyStrokeForEvent((KeyEvent) maybeKeyEvent);
    }

    // try simple keystorkes first
    MimePath mimeType = MimePath.parse(NbEditorUtilities.getMimeType(target));
    MacroDescription macro = null;
    if (keyStroke != null) {
        macro = findMacro(mimeType, keyStroke);
    } else {
        LOG.warning("KeyStroke could not be created for event " + maybeKeyEvent);
    }
    if (macro == null) {
        // if not found, try action command, which should contain complete multi keystroke
        KeyStroke[] shortcut = KeyStrokeUtils.getKeyStrokes(evt.getActionCommand());
        if (shortcut != null) {
            macro = findMacro(mimeType, shortcut);
        } else {
            LOG.warning("KeyStroke could not be created for action command " + evt.getActionCommand());
        }
    }

    if (macro == null) {
        error(target, "macro-not-found", KeyStrokeUtils.getKeyStrokeAsText(keyStroke)); // NOI18N
        return;
    }

    if (!runningActions.add(macro.getName())) { // this macro is already running, beware of loops
        error(target, "macro-loop", macro.getName()); // NOI18N
        return;
    }
    try {
        runMacro(target, doc, kit, macro);
    } finally {
        runningActions.remove(macro.getName());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:MacroDialogSupport.java


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