Example usage for com.intellij.openapi.ui.popup ComponentPopupBuilder setFocusable

List of usage examples for com.intellij.openapi.ui.popup ComponentPopupBuilder setFocusable

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup ComponentPopupBuilder setFocusable.

Prototype

@NotNull
    ComponentPopupBuilder setFocusable(boolean focusable);

Source Link

Usage

From source file:com.intellij.ide.util.gotoByName.ChooseByNamePopup.java

License:Apache License

@Override
protected void showList() {
    final JLayeredPane layeredPane = myTextField.getRootPane().getLayeredPane();

    Rectangle bounds = new Rectangle(myTextFieldPanel.getLocationOnScreen(), myTextField.getSize());
    bounds.y += myTextFieldPanel.getHeight() + (SystemInfo.isMac ? 3 : 1);

    final Dimension preferredScrollPaneSize = myListScrollPane.getPreferredSize();
    if (myList.getModel().getSize() == 0) {
        preferredScrollPaneSize.height = UIManager.getFont("Label.font").getSize();
    }//from   w  ww . jav  a  2 s  .  c  o m

    preferredScrollPaneSize.width = Math.max(myTextFieldPanel.getWidth(), preferredScrollPaneSize.width);

    Rectangle preferredBounds = new Rectangle(bounds.x, bounds.y, preferredScrollPaneSize.width,
            preferredScrollPaneSize.height);
    Rectangle original = new Rectangle(preferredBounds);

    ScreenUtil.fitToScreen(preferredBounds);
    if (original.width > preferredBounds.width) {
        int height = myListScrollPane.getHorizontalScrollBar().getPreferredSize().height;
        preferredBounds.height += height;
    }

    myListScrollPane.setVisible(true);
    myListScrollPane.setBorder(null);
    String adText = getAdText();
    if (myDropdownPopup == null) {
        ComponentPopupBuilder builder = JBPopupFactory.getInstance()
                .createComponentPopupBuilder(myListScrollPane, myListScrollPane);
        builder.setFocusable(false).setRequestFocus(false).setCancelKeyEnabled(false)
                .setFocusOwners(new JComponent[] { myTextField }).setBelongsToGlobalPopupStack(false)
                .setModalContext(false).setAdText(adText).setMayBeParent(true);
        builder.setCancelCallback(new Computable<Boolean>() {
            @Override
            public Boolean compute() {
                return Boolean.TRUE;
            }
        });
        myDropdownPopup = builder.createPopup();
        myDropdownPopup.setLocation(preferredBounds.getLocation());
        myDropdownPopup.setSize(preferredBounds.getSize());
        myDropdownPopup.show(layeredPane);
    } else {
        myDropdownPopup.setLocation(preferredBounds.getLocation());

        // in 'focus follows mouse' mode, to avoid focus escaping to editor, don't reduce popup size when list size is reduced
        final Dimension currentSize = myDropdownPopup.getSize();
        if (UISettings.getInstance().HIDE_NAVIGATION_ON_FOCUS_LOSS || preferredBounds.width > currentSize.width
                || preferredBounds.height > currentSize.height) {
            myDropdownPopup.setSize(preferredBounds.getSize());
        }
    }
}