Example usage for com.intellij.openapi.ui.popup JBPopup getContent

List of usage examples for com.intellij.openapi.ui.popup JBPopup getContent

Introduction

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

Prototype

@NotNull
JComponent getContent();

Source Link

Document

Returns the Swing component contained in the popup.

Usage

From source file:com.antoine.ideaplugin.greenrobot.ShowUsagesAction.java

License:Apache License

private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup,
        @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1)
        myWidth = width;/*from  ww  w.jav a2s .c om*/
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    dimension = rectangle.getSize();
    Point location = window.getLocation();
    if (!location.equals(rectangle.getLocation())) {
        window.setLocation(rectangle.getLocation());
    }

    if (!data.isEmpty()) {
        TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(dimension);
    //table.setPreferredSize(dimension);
    //table.setMaximumSize(dimension);
    //table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight())
            + 4/* invisible borders, margins etc*/;
    Dimension newDim = new Dimension(dimension.width, newHeight);
    window.setSize(newDim);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
}

From source file:com.google.cloud.tools.intellij.login.ui.GoogleLoginAction.java

License:Apache License

/**
 * Opens up the Google Login panel as a popup.
 *///from w w w  .j  a v a2s . co m
private static void showPopup(AnActionEvent event) {
    GoogleLoginUsersPanel usersPanel = new GoogleLoginUsersPanel();
    JComponent source = (JComponent) event.getInputEvent().getSource();
    ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(usersPanel,
            usersPanel.getList());
    JBPopup popup = popupBuilder.createPopup();
    JComponent component = popup.getContent();
    int startingPoint = (int) (source.getWidth() - component.getPreferredSize().getWidth());
    popup.show(new RelativePoint(source, new Point(startingPoint, source.getHeight() - 1)));
}

From source file:com.google.gct.login.ui.GoogleLoginAction.java

License:Apache License

/**
 * Opens up the Google Login panel as a popup.
 *//*from   w w w  . j a v a  2  s.c  o  m*/
private static void showPopup(AnActionEvent e) {
    GoogleLoginUsersPanel usersPanel = new GoogleLoginUsersPanel();
    JComponent source = (JComponent) e.getInputEvent().getSource();
    ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(usersPanel,
            usersPanel.getList());
    JBPopup popup = popupBuilder.createPopup();
    JComponent component = popup.getContent();
    int startingPoint = (int) (source.getWidth() - component.getPreferredSize().getWidth());
    popup.show(new RelativePoint(source, new Point(startingPoint, source.getHeight() - 1)));
}

From source file:com.intellij.find.actions.ShowUsagesAction.java

License:Apache License

private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup,
        @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1)
        myWidth = width;/*from   ww  w .  j a  v a2s .  com*/
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    if (!data.isEmpty()) {
        TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(rectangle.getSize());
    //table.setPreferredSize(dimension);
    //table.setMaximumSize(dimension);
    //table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    rectangle.height += headerSize.height + footerSize.height + 4/* invisible borders, margins etc*/;
    ScreenUtil.fitToScreen(rectangle);
    Dimension newDim = rectangle.getSize();
    window.setBounds(rectangle);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
}

From source file:com.intellij.ide.favoritesTreeView.TaskDefaultFavoriteListProvider.java

License:Apache License

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);//from   w w  w . j ava2s .  c o  m
    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(new Runnable() {
        @Override
        public void run() {
            popup.showInCenterOf(tree);
        }
    }, ModalityState.NON_MODAL, project.getDisposed());
}

From source file:com.intellij.ui.popup.PopupPositionManager.java

License:Apache License

private static Component discoverPopup(final DataKey<JBPopup> datakey, Component focusOwner) {
    if (focusOwner == null) {
        focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    }/*from  w w  w . j  a  v  a2  s  .c om*/

    if (focusOwner == null)
        return null;

    final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
    if (dataContext == null)
        return null;

    final JBPopup popup = datakey.getData(dataContext);
    if (popup != null && popup.isVisible()) {
        return popup.getContent();
    }

    return null;
}

From source file:com.intellij.vcs.log.ui.filter.MultilinePopupBuilder.java

License:Apache License

@NotNull
JBPopup createPopup() {/*  w w w. j a v a2 s  .  c  o  m*/
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(myTextField, BorderLayout.CENTER);
    ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField)
            .setCancelOnClickOutside(true)
            .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish")
            .setRequestFocus(true).setResizable(true).setMayBeParent(true);

    final JBPopup popup = builder.createPopup();
    popup.setMinimumSize(new Dimension(200, 90));
    AnAction okAction = new DumbAwareAction() {
        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            unregisterCustomShortcutSet(popup.getContent());
            popup.closeOk(e.getInputEvent());
        }
    };
    okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent());
    return popup;
}