Search in sources :

Example 51 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class TaskDefaultFavoriteListProvider method showNotePopup.

private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after, final String initText) {
    final JTextArea textArea = new JTextArea(3, 50);
    textArea.setFont(UIUtil.getTreeFont());
    textArea.setText(initText);
    final JBScrollPane pane = new JBScrollPane(textArea);
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setTitle("Comment").setMovable(true).setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    final JComponent content = popup.getContent();
    final AnAction action = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            popup.closeOk(e.getInputEvent());
            unregisterCustomShortcutSet(content);
            after.consume(textArea.getText());
        }
    };
    action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
    ApplicationManager.getApplication().invokeLater(() -> popup.showInCenterOf(tree), ModalityState.NON_MODAL, project.getDisposed());
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 52 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class TabbedContentTabLabel method showPopup.

private void showPopup() {
    IdeEventQueue.getInstance().getPopupManager().closeAllPopups();
    ArrayList<String> names = new ArrayList<String>();
    for (Pair<String, JComponent> tab : myContent.getTabs()) {
        names.add(tab.first);
    }
    final JBList list = new JBList(names);
    list.installCellRenderer(new NotNullFunction<Object, JComponent>() {

        private final JLabel label = new JLabel();

        {
            label.setBorder(new EmptyBorder(UIUtil.getListCellPadding()));
        }

        @NotNull
        @Override
        public JComponent fun(Object dom) {
            label.setText(dom.toString());
            return label;
        }
    });
    final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
        int index = list.getSelectedIndex();
        if (index != -1) {
            myContent.selectContent(index);
        }
    }).createPopup();
    myPopupReference = new WeakReference<JBPopup>(popup);
    popup.showUnderneathOf(this);
}
Also used : ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) JBList(com.intellij.ui.components.JBList) EmptyBorder(javax.swing.border.EmptyBorder) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 53 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class TabbedContentTabLabel method removeNotify.

@Override
public void removeNotify() {
    super.removeNotify();
    JBPopup popup = SoftReference.dereference(myPopupReference);
    if (popup != null) {
        Disposer.dispose(popup);
        myPopupReference = null;
    }
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 54 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class WindowManagerImpl method adjustContainerWindow.

@Override
public void adjustContainerWindow(Component c, Dimension oldSize, Dimension newSize) {
    if (c == null)
        return;
    Window wnd = SwingUtilities.getWindowAncestor(c);
    if (wnd instanceof JWindow) {
        JBPopup popup = (JBPopup) ((JWindow) wnd).getRootPane().getClientProperty(JBPopup.KEY);
        if (popup != null) {
            if (oldSize.height < newSize.height) {
                Dimension size = popup.getSize();
                size.height += newSize.height - oldSize.height;
                popup.setSize(size);
                popup.moveToFitScreen();
            }
        }
    }
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 55 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class JBComboBoxTableCellEditorComponent method initAndShowPopup.

private void initAndShowPopup() {
    myList.removeAll();
    myList.setModel(JBList.createDefaultListModel(myOptions));
    if (myRenderer != null) {
        myList.setCellRenderer(myRenderer);
    }
    final Rectangle rect = myTable.getCellRect(myRow, myColumn, true);
    Point point = new Point(rect.x, rect.y);
    final boolean surrendersFocusOnKeystrokeOldValue = myTable instanceof JBTable ? ((JBTable) myTable).surrendersFocusOnKeyStroke() : myTable.getSurrendersFocusOnKeystroke();
    final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(myList).setItemChoosenCallback(() -> {
        myValue = myList.getSelectedValue();
        final ActionEvent event = new ActionEvent(myList, ActionEvent.ACTION_PERFORMED, "elementChosen");
        for (ActionListener listener : myListeners) {
            listener.actionPerformed(event);
        }
        TableUtil.stopEditing(myTable);
        // on Mac getCellEditorValue() called before myValue is set.
        myTable.setValueAt(myValue, myRow, myColumn);
        // force repaint
        myTable.tableChanged(new TableModelEvent(myTable.getModel(), myRow));
    }).setCancelCallback(() -> {
        TableUtil.stopEditing(myTable);
        return true;
    }).addListener(new JBPopupAdapter() {

        @Override
        public void beforeShown(LightweightWindowEvent event) {
            super.beforeShown(event);
            myTable.setSurrendersFocusOnKeystroke(false);
        }

        @Override
        public void onClosed(LightweightWindowEvent event) {
            myTable.setSurrendersFocusOnKeystroke(surrendersFocusOnKeystrokeOldValue);
            super.onClosed(event);
        }
    }).setMinSize(myWide ? new Dimension(((int) rect.getSize().getWidth()), -1) : null).createPopup();
    popup.show(new RelativePoint(myTable, point));
}
Also used : ActionEvent(java.awt.event.ActionEvent) TableModelEvent(javax.swing.event.TableModelEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBTable(com.intellij.ui.table.JBTable) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) ActionListener(java.awt.event.ActionListener) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

JBPopup (com.intellij.openapi.ui.popup.JBPopup)76 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)20 RelativePoint (com.intellij.ui.awt.RelativePoint)19 JBList (com.intellij.ui.components.JBList)18 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Nullable (org.jetbrains.annotations.Nullable)8 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)7 Ref (com.intellij.openapi.util.Ref)7 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)6 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)6 AbstractPopup (com.intellij.ui.popup.AbstractPopup)6 ActionEvent (java.awt.event.ActionEvent)6 List (java.util.List)6 javax.swing (javax.swing)6 Disposable (com.intellij.openapi.Disposable)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)5