Search in sources :

Example 1 with ComboPopup

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

the class PopupUtil method isComboPopupKeyEvent.

public static boolean isComboPopupKeyEvent(@NotNull ComponentEvent event, @NotNull JComboBox comboBox) {
    final Component component = event.getComponent();
    if (!comboBox.isPopupVisible() || component == null)
        return false;
    ComboPopup popup = ReflectionUtil.getField(comboBox.getUI().getClass(), comboBox.getUI(), ComboPopup.class, "popup");
    return popup != null && SwingUtilities.isDescendingFrom(popup.getList(), component);
}
Also used : ComboPopup(javax.swing.plaf.basic.ComboPopup)

Example 2 with ComboPopup

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

the class TreeInplaceEditor method eventDispatched.

@Override
public void eventDispatched(AWTEvent event) {
    if (!isShown()) {
        return;
    }
    MouseEvent mouseEvent = (MouseEvent) event;
    if (mouseEvent.getClickCount() == 0 && !(event instanceof MouseWheelEvent)) {
        return;
    }
    final int id = mouseEvent.getID();
    if (id != MouseEvent.MOUSE_PRESSED && id != MouseEvent.MOUSE_RELEASED && id != MouseEvent.MOUSE_CLICKED && id != MouseEvent.MOUSE_WHEEL) {
        return;
    }
    final Component sourceComponent = mouseEvent.getComponent();
    final Point originalPoint = mouseEvent.getPoint();
    final Editor editor = getEditor();
    if (editor == null)
        return;
    Project project = editor.getProject();
    LookupImpl activeLookup = project != null ? (LookupImpl) LookupManager.getInstance(project).getActiveLookup() : null;
    if (activeLookup != null) {
        final Point lookupPoint = SwingUtilities.convertPoint(sourceComponent, originalPoint, activeLookup.getComponent());
        if (activeLookup.getComponent().getBounds().contains(lookupPoint)) {
            //mouse click inside lookup
            return;
        } else {
            //hide popup on mouse position changed
            activeLookup.hide();
        }
    }
    // do not cancel editing if we click in editor popup
    final List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(myInplaceEditorComponent);
    for (JBPopup popup : popups) {
        if (SwingUtilities.isDescendingFrom(sourceComponent, popup.getContent())) {
            return;
        }
    }
    final Point point = SwingUtilities.convertPoint(sourceComponent, originalPoint, myInplaceEditorComponent);
    if (myInplaceEditorComponent.contains(point)) {
        return;
    }
    final Component componentAtPoint = SwingUtilities.getDeepestComponentAt(sourceComponent, originalPoint.x, originalPoint.y);
    for (Component comp = componentAtPoint; comp != null; comp = comp.getParent()) {
        if (comp instanceof ComboPopup) {
            if (id != MouseEvent.MOUSE_WHEEL) {
                doPopupOKAction();
            }
            return;
        }
    }
    if (id != MouseEvent.MOUSE_RELEASED) {
        // do not cancel on release outside of the component
        cancelEditing();
    }
}
Also used : Project(com.intellij.openapi.project.Project) LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) ComboPopup(javax.swing.plaf.basic.ComboPopup) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 3 with ComboPopup

use of javax.swing.plaf.basic.ComboPopup in project android by JetBrains.

the class GradleEditorComboBoxEditor method getComboboxPopup.

@Nullable
private static ComboPopup getComboboxPopup(final JComboBox comboBox) {
    final ComboBoxUI ui = comboBox.getUI();
    ComboPopup popup = null;
    if (ui instanceof BasicComboBoxUI) {
        try {
            final Field popupField = BasicComboBoxUI.class.getDeclaredField("popup");
            popupField.setAccessible(true);
            popup = (ComboPopup) popupField.get(ui);
        } catch (NoSuchFieldException e1) {
            popup = null;
        } catch (IllegalAccessException e1) {
            popup = null;
        }
    }
    return popup;
}
Also used : Field(java.lang.reflect.Field) 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 4 with ComboPopup

use of javax.swing.plaf.basic.ComboPopup in project android by JetBrains.

the class NlEnumEditorFixture method showPopup.

public NlEnumEditorFixture showPopup() {
    assertThat(myCombo).isNotNull();
    myCombo.isPopupVisible();
    myCombo.showPopup();
    ComboPopup popup = myCombo.getPopup();
    assertThat(popup).isNotNull();
    setFocusedComponent(popup.getList());
    assertThat(myCombo.isPopupVisible()).isTrue();
    return this;
}
Also used : ComboPopup(javax.swing.plaf.basic.ComboPopup) BasicComboPopup(javax.swing.plaf.basic.BasicComboPopup)

Example 5 with ComboPopup

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

the class XDebuggerTreeInplaceEditor method doPopupOKAction.

@Override
protected void doPopupOKAction() {
    ComboPopup popup = myExpressionEditor.getComboBox().getPopup();
    if (popup != null && popup.isVisible()) {
        Object value = popup.getList().getSelectedValue();
        if (value != null) {
            myExpressionEditor.setExpression((XExpression) value);
        }
    }
    doOKAction();
}
Also used : ComboPopup(javax.swing.plaf.basic.ComboPopup)

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