Java Code Examples for com.intellij.openapi.ui.popup.JBPopup#getContent()

The following examples show how to use com.intellij.openapi.ui.popup.JBPopup#getContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PopupPositionManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static PositionAdjuster createPositionAdjuster(JBPopup hint) {
  final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  if (focusOwner == null) return null;

  JBPopup popup = PopupUtil.getPopupContainerFor(focusOwner);
  if (popup != null && popup != hint && !popup.isDisposed()) {
    return new PositionAdjuster(popup.getContent());
  }

  final Component existing = discoverPopup(LangDataKeys.POSITION_ADJUSTER_POPUP, focusOwner);
  if (existing != null) {
    return new PositionAdjuster2(existing, discoverPopup(LangDataKeys.PARENT_POPUP, focusOwner));
  }

  return null;
}
 
Example 2
Source File: ComboBox.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void eventDispatched(AWTEvent event) {
  if (event.getID() == WindowEvent.WINDOW_OPENED) {
    final WindowEvent we = (WindowEvent)event;
    final List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(this);
    if (popups != null) {
      for (JBPopup each : popups) {
        if (each.getContent() != null && SwingUtilities.isDescendingFrom(each.getContent(), we.getWindow())) {
          super.setPopupVisible(false);
        }
      }
    }
  }
}
 
Example 3
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Component getPopupAnchor() {
  LookupEx lookup = myManager == null ? null : LookupManager.getActiveLookup(myManager.getEditor());

  if (lookup != null && lookup.getCurrentItem() != null && lookup.getComponent().isShowing()) {
    return lookup.getComponent();
  }
  Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  JBPopup popup = PopupUtil.getPopupContainerFor(focusOwner);
  if (popup != null && popup != myHint && !popup.isDisposed()) {
    return popup.getContent();
  }
  return null;
}
 
Example 4
Source File: PopupPositionManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Component discoverPopup(final Key<JBPopup> datakey, Component focusOwner) {
  if (focusOwner == null) {
    focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  }

  if (focusOwner == null) return null;

  final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
  final JBPopup popup = dataContext.getData(datakey);
  if (popup != null && popup.isVisible() && !popup.isDisposed()) {
    return popup.getContent();
  }

  return null;
}
 
Example 5
Source File: TaskDefaultFavoriteListProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
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(new Runnable() {
    @Override
    public void run() {
      popup.showInCenterOf(tree);
    }
  }, ModalityState.NON_MODAL, project.getDisposed());
}
 
Example 6
Source File: SearchEverywhereManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void calcPositionAndShow(Project project, JBPopup balloon) {
  Point savedLocation = WindowStateService.getInstance(myProject).getLocation(LOCATION_SETTINGS_KEY);

  //for first show and short mode popup should be shifted to the top screen half
  if (savedLocation == null && mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) {
    Window window = project != null ? TargetAWT.to(WindowManager.getInstance().suggestParentWindow(project)) : KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    Component parent = UIUtil.findUltimateParent(window);

    if (parent != null) {
      JComponent content = balloon.getContent();
      Dimension balloonSize = content.getPreferredSize();

      Point screenPoint = new Point((parent.getSize().width - balloonSize.width) / 2, parent.getHeight() / 4 - balloonSize.height / 2);
      SwingUtilities.convertPointToScreen(screenPoint, parent);

      Rectangle screenRectangle = ScreenUtil.getScreenRectangle(screenPoint);
      Insets insets = content.getInsets();
      int bottomEdge = screenPoint.y + mySearchEverywhereUI.getExpandedSize().height + insets.bottom + insets.top;
      int shift = bottomEdge - (int)screenRectangle.getMaxY();
      if (shift > 0) {
        screenPoint.y = Integer.max(screenPoint.y - shift, screenRectangle.y);
      }

      RelativePoint showPoint = new RelativePoint(screenPoint);
      balloon.show(showPoint);
      return;
    }
  }

  if (project != null) {
    balloon.showCenteredInCurrentWindow(project);
  }
  else {
    balloon.showInFocusCenter();
  }
}
 
Example 7
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 4 votes vote down vote up
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;
  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();
}
 
Example 8
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void setSizeAndDimensions(@Nonnull JTable table, @Nonnull JBPopup popup, @Nonnull RelativePoint popupPosition, @Nonnull 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;
  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()) {
    ScrollingUtil.ensureSelectionExists(table);
  }
  table.setSize(rectangle.getSize());
  //table.setPreferredSize(dimension);
  //table.setMaximumSize(dimension);
  //table.setPreferredScrollableViewportSize(dimension);


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

  int footer = footerSize.height;
  int footerBorder = footer == 0 ? 0 : 1;
  Insets insets = ((AbstractPopup)popup).getPopupBorder().getBorderInsets(content);
  rectangle.height += headerSize.height + footer + footerBorder + insets.top + insets.bottom;
  ScreenUtil.fitToScreen(rectangle);
  Dimension newDim = rectangle.getSize();
  window.setBounds(rectangle);
  window.setMinimumSize(newDim);
  window.setMaximumSize(newDim);

  window.validate();
  window.repaint();
}
 
Example 9
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
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;
  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();
}