Search in sources :

Example 6 with ComboPopup

use of javax.swing.plaf.basic.ComboPopup in project intellij-community by JetBrains.

the class IdeEventQueue method _dispatchEvent.

public void _dispatchEvent(@NotNull AWTEvent e, boolean typeAheadFlushing) {
    if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        DnDManagerImpl dndManager = (DnDManagerImpl) DnDManager.getInstance();
        if (dndManager != null) {
            dndManager.setLastDropHandler(null);
        }
    }
    myEventCount++;
    if (processAppActivationEvents(e))
        return;
    if (!typeAheadFlushing) {
        fixStickyFocusedComponents(e);
    }
    if (!myPopupManager.isPopupActive()) {
        enterSuspendModeIfNeeded(e);
    }
    myKeyboardBusy = e instanceof KeyEvent || myKeyboardEventsPosted.get() > myKeyboardEventsDispatched.get();
    if (e instanceof KeyEvent) {
        if (e.getID() == KeyEvent.KEY_RELEASED && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_SHIFT) {
            myMouseEventDispatcher.resetHorScrollingTracker();
        }
    }
    if (!typeAheadFlushing && typeAheadDispatchToFocusManager(e)) {
        LOG.debug("Typeahead dispatch for event ", e);
        return;
    }
    if (e instanceof WindowEvent) {
        ActivityTracker.getInstance().inc();
    }
    if (e instanceof MouseWheelEvent) {
        final MenuElement[] selectedPath = MenuSelectionManager.defaultManager().getSelectedPath();
        if (selectedPath.length > 0 && !(selectedPath[0] instanceof ComboPopup)) {
            ((MouseWheelEvent) e).consume();
            Component component = selectedPath[0].getComponent();
            if (component instanceof JBPopupMenu) {
                ((JBPopupMenu) component).processMouseWheelEvent((MouseWheelEvent) e);
            }
            return;
        }
    }
    // Process "idle" and "activity" listeners
    if (e instanceof KeyEvent || e instanceof MouseEvent) {
        ActivityTracker.getInstance().inc();
        synchronized (myLock) {
            myIdleRequestsAlarm.cancelAllRequests();
            for (Runnable idleListener : myIdleListeners) {
                final MyFireIdleRequest request = myListener2Request.get(idleListener);
                if (request == null) {
                    LOG.error("There is no request for " + idleListener);
                } else {
                    myIdleRequestsAlarm.addRequest(request, request.getTimeout(), ModalityState.NON_MODAL);
                }
            }
            if (KeyEvent.KEY_PRESSED == e.getID() || KeyEvent.KEY_TYPED == e.getID() || MouseEvent.MOUSE_PRESSED == e.getID() || MouseEvent.MOUSE_RELEASED == e.getID() || MouseEvent.MOUSE_CLICKED == e.getID()) {
                addIdleTimeCounterRequest();
                for (Runnable activityListener : myActivityListeners) {
                    activityListener.run();
                }
            }
        }
    }
    if (myPopupManager.isPopupActive() && myPopupManager.dispatch(e)) {
        if (myKeyEventDispatcher.isWaitingForSecondKeyStroke()) {
            myKeyEventDispatcher.setState(KeyState.STATE_INIT);
        }
        return;
    }
    if (dispatchByCustomDispatchers(e))
        return;
    if (e instanceof InputMethodEvent) {
        if (SystemInfo.isMac && myKeyEventDispatcher.isWaitingForSecondKeyStroke()) {
            return;
        }
    }
    if (e instanceof ComponentEvent && myWindowManager != null) {
        myWindowManager.dispatchComponentEvent((ComponentEvent) e);
    }
    if (e instanceof KeyEvent) {
        if (mySuspendMode || !myKeyEventDispatcher.dispatchKeyEvent((KeyEvent) e)) {
            defaultDispatchEvent(e);
        } else {
            ((KeyEvent) e).consume();
            defaultDispatchEvent(e);
        }
    } else if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        if (IdeMouseEventDispatcher.patchClickCount(me) && me.getID() == MouseEvent.MOUSE_CLICKED) {
            final MouseEvent toDispatch = new MouseEvent(me.getComponent(), me.getID(), System.currentTimeMillis(), me.getModifiers(), me.getX(), me.getY(), 1, me.isPopupTrigger(), me.getButton());
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> dispatchEvent(toDispatch));
        }
        if (!myMouseEventDispatcher.dispatchMouseEvent(me)) {
            defaultDispatchEvent(e);
        }
    } else {
        defaultDispatchEvent(e);
    }
}
Also used : JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) DnDManagerImpl(com.intellij.ide.dnd.DnDManagerImpl) ComboPopup(javax.swing.plaf.basic.ComboPopup)

Example 7 with ComboPopup

use of javax.swing.plaf.basic.ComboPopup in project intellij-community by JetBrains.

the class FixedComboBoxEditor method getComboboxPopup.

@Nullable
private static ComboPopup getComboboxPopup(final JComboBox comboBox) {
    final ComboBoxUI ui = comboBox.getUI();
    ComboPopup popup = null;
    if (ui instanceof BasicComboBoxUI) {
        popup = ReflectionUtil.getField(BasicComboBoxUI.class, ui, ComboPopup.class, "popup");
    }
    return popup;
}
Also used : ComboPopup(javax.swing.plaf.basic.ComboPopup) BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI) ComboBoxUI(javax.swing.plaf.ComboBoxUI) BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ComboPopup

use of javax.swing.plaf.basic.ComboPopup in project intellij-community by JetBrains.

the class IdeKeyEventDispatcher method dispatchKeyEvent.

/**
   * @return {@code true} if and only if the passed event is already dispatched by the
   * {@code IdeKeyEventDispatcher} and there is no need for any other processing of the event.
   */
public boolean dispatchKeyEvent(final KeyEvent e) {
    if (myDisposed)
        return false;
    KeyboardLayoutUtil.storeAsciiForChar(e);
    if (e.isConsumed()) {
        return false;
    }
    if (isSpeedSearchEditing(e)) {
        return false;
    }
    // http://www.jetbrains.net/jira/browse/IDEADEV-12372
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            myLeftCtrlPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT;
        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
            myLeftCtrlPressed = false;
        }
    } else if (e.getKeyCode() == KeyEvent.VK_ALT) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            myRightAltPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT;
        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
            myRightAltPressed = false;
        }
    }
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = focusManager.getFocusOwner();
    // shortcuts should not work in shortcut setup fields
    if (focusOwner instanceof ShortcutTextField) {
        return false;
    }
    if (focusOwner instanceof JTextComponent && ((JTextComponent) focusOwner).isEditable()) {
        if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyCode() != KeyEvent.VK_ESCAPE) {
            MacUIUtil.hideCursor();
        }
    }
    MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
    MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
    if (selectedPath.length > 0) {
        if (!(selectedPath[0] instanceof ComboPopup)) {
            // The following couple of lines of code is a PATCH!!!
            // It is needed to ignore ENTER KEY_TYPED events which sometimes can reach editor when an action
            // is invoked from main menu via Enter key.
            setState(KeyState.STATE_PROCESSED);
            setPressedWasProcessed(true);
            return false;
        }
    }
    // Keymap shortcuts (i.e. not local shortcuts) should work only in:
    // - main frame
    // - floating focusedWindow
    // - when there's an editor in contexts
    Window focusedWindow = focusManager.getFocusedWindow();
    boolean isModalContext = focusedWindow != null && isModalContext(focusedWindow);
    //EA-39114
    if (ApplicationManager.getApplication() == null)
        return false;
    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null)
        return false;
    DataContext dataContext = dataManager.getDataContext();
    myContext.setDataContext(dataContext);
    myContext.setFocusOwner(focusOwner);
    myContext.setModalContext(isModalContext);
    myContext.setInputEvent(e);
    try {
        if (getState() == KeyState.STATE_INIT) {
            return inInitState();
        } else if (getState() == KeyState.STATE_PROCESSED) {
            return inProcessedState();
        } else if (getState() == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) {
            return inWaitForSecondStrokeState();
        } else if (getState() == KeyState.STATE_SECOND_STROKE_IN_PROGRESS) {
            return inSecondStrokeInProgressState();
        } else if (getState() == KeyState.STATE_KEY_GESTURE_PROCESSOR) {
            return myKeyGestureProcessor.process();
        } else {
            throw new IllegalStateException("state = " + getState());
        }
    } finally {
        myContext.clear();
    }
}
Also used : ShortcutTextField(com.intellij.openapi.keymap.impl.ui.ShortcutTextField) JTextComponent(javax.swing.text.JTextComponent) DataManager(com.intellij.ide.DataManager) ComboPopup(javax.swing.plaf.basic.ComboPopup) JTextComponent(javax.swing.text.JTextComponent)

Aggregations

ComboPopup (javax.swing.plaf.basic.ComboPopup)8 ComboBoxUI (javax.swing.plaf.ComboBoxUI)2 BasicComboBoxUI (javax.swing.plaf.basic.BasicComboBoxUI)2 Nullable (org.jetbrains.annotations.Nullable)2 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 DataManager (com.intellij.ide.DataManager)1 DnDManagerImpl (com.intellij.ide.dnd.DnDManagerImpl)1 Editor (com.intellij.openapi.editor.Editor)1 ShortcutTextField (com.intellij.openapi.keymap.impl.ui.ShortcutTextField)1 Project (com.intellij.openapi.project.Project)1 JBPopupMenu (com.intellij.openapi.ui.JBPopupMenu)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 Field (java.lang.reflect.Field)1 BasicComboPopup (javax.swing.plaf.basic.BasicComboPopup)1 JTextComponent (javax.swing.text.JTextComponent)1