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

The following examples show how to use com.intellij.openapi.ui.popup.JBPopup#show() . 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: PsiElementListNavigator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void openTargets(MouseEvent e,
                               NavigatablePsiElement[] targets,
                               String title,
                               final String findUsagesTitle,
                               ListCellRenderer listRenderer,
                               @Nullable BackgroundUpdaterTask listUpdaterTask) {
  JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask);
  if (popup != null) {
    RelativePoint point = new RelativePoint(e);
    if (listUpdaterTask != null) {
      runActionAndListUpdaterTask(() -> popup.show(point), listUpdaterTask);
    }
    else {
      popup.show(point);
    }
  }
}
 
Example 2
Source File: TimeTrackerWidget.java    From DarkyenusTimeTracker with The Unlicense 5 votes vote down vote up
private void popupSettings() {
    final TimeTrackerPopupContent content = new TimeTrackerPopupContent(service, (patternFieldType) -> {
        if (patternFieldType == null) {
            setPopupState(PopupState.VISIBLE_LOST_FOCUS);
        } else if (patternFieldType == TimeTrackerPopupContent.PatternField.WIDGET) {
            setPopupState(PopupState.VISIBLE_WIDGET_PATTERN_FOCUS);
        } else if (patternFieldType == TimeTrackerPopupContent.PatternField.GIT) {
            setPopupState(PopupState.VISIBLE_GIT_PATTERN_FOCUS);
        }
    });

    final ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null);
    popupBuilder.setCancelOnClickOutside(true);
    popupBuilder.setFocusable(true);
    popupBuilder.setRequestFocus(true);
    popupBuilder.setShowBorder(true);
    popupBuilder.setShowShadow(true);
    final JBPopup popup = popupBuilder.createPopup();
    content.popup = popup;

    final Rectangle visibleRect = TimeTrackerWidget.this.getVisibleRect();
    final Dimension preferredSize = content.getPreferredSize();
    final RelativePoint point = new RelativePoint(TimeTrackerWidget.this, new Point(visibleRect.x+visibleRect.width - preferredSize.width, visibleRect.y - (preferredSize.height + 15)));
    popup.show(point);

    popup.addListener(new JBPopupListener() {
        @Override
        public void onClosed(@NotNull LightweightWindowEvent event) {
            setPopupState(PopupState.HIDDEN);
        }
    });

    // Not sure if needed, but sometimes the popup is not clickable for some mysterious reason
    // and it stopped happening when this was added
    content.requestFocus();
    setPopupState(PopupState.VISIBLE);
}
 
Example 3
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static boolean showPopupIfNeedTo(@NotNull JBPopup popup,
    @NotNull RelativePoint popupPosition) {
  if (!popup.isDisposed() && !popup.isVisible()) {
    popup.show(popupPosition);
    return true;
  } else {
    return false;
  }
}
 
Example 4
Source File: CommentBalloonBuilder.java    From Crucible4IDEA with MIT License 5 votes vote down vote up
public static void showBalloon(@NotNull CommentsTree balloonContent) {
  JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(balloonContent, balloonContent)
    .setResizable(true)
    .setTitle("Comments")
    .setMovable(true)
    .createPopup();

  final PointerInfo pointerInfo = MouseInfo.getPointerInfo();
  final Point targetPoint = pointerInfo.getLocation();
  popup.show(new RelativePoint(targetPoint));
}
 
Example 5
Source File: GoToChangePopupBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  JBPopup popup = createPopup(e);

  InputEvent event = e.getInputEvent();
  if (event instanceof MouseEvent) {
    popup.show(new RelativePoint((MouseEvent)event));
  }
  else {
    popup.showInBestPositionFor(e.getDataContext());
  }
}
 
Example 6
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(mySettingsPanel, myFontSizeSlider).createPopup();
  setFontSizeSliderSize(getQuickDocFontSize());
  mySettingsPanel.setVisible(true);
  Point location = MouseInfo.getPointerInfo().getLocation();
  popup.show(new RelativePoint(new Point(location.x - mySettingsPanel.getPreferredSize().width / 2, location.y - mySettingsPanel.getPreferredSize().height / 2)));
}
 
Example 7
Source File: NavigationGutterIconRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public void navigate(@Nullable final MouseEvent event, @Nullable final PsiElement elt) {
  final List<PsiElement> list = getTargetElements();
  if (list.isEmpty()) {
    if (myEmptyText != null) {
      if (event != null) {
        final JComponent label = HintUtil.createErrorLabel(myEmptyText);
        label.setBorder(IdeBorderFactory.createEmptyBorder(2, 7, 2, 7));
        JBPopupFactory.getInstance().createBalloonBuilder(label)
          .setFadeoutTime(3000)
          .setFillColor(HintUtil.ERROR_COLOR)
          .createBalloon()
          .show(new RelativePoint(event), Balloon.Position.above);
      }
    }
    return;
  }
  if (list.size() == 1) {
    PsiNavigateUtil.navigate(list.iterator().next());
  }
  else {
    if (event != null) {
      final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilCore.toPsiElementArray(list), myCellRenderer.compute(), myPopupTitle);
      popup.show(new RelativePoint(event));
    }
  }
}
 
Example 8
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean showPopupIfNeedTo(@Nonnull JBPopup popup, @Nonnull RelativePoint popupPosition) {
  if (!popup.isDisposed() && !popup.isVisible()) {
    popup.show(popupPosition);
    return true;
  }
  else {
    return false;
  }
}
 
Example 9
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 10
Source File: SwingValidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showPopup(JComponent awtComponent, ComponentPopupBuilder popupBuilder, Dimension popupSize) {
  Insets i = awtComponent.getInsets();
  Point point = new Point(JBUIScale.scale(40), i.top - JBUIScale.scale(6) - popupSize.height);
  RelativePoint popupLocation = new RelativePoint(awtComponent, point);

  JBPopup popup = popupBuilder.createPopup();
  popup.show(popupLocation);

  myLastPopup = new WeakReference<>(popup);
}
 
Example 11
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static boolean showPopupIfNeedTo(@NotNull JBPopup popup, @NotNull RelativePoint popupPosition) {
  if (!popup.isDisposed() && !popup.isVisible()) {
    popup.show(popupPosition);
    return true;
  }
  else {
    return false;
  }
}