use of com.intellij.openapi.ui.popup.ComponentPopupBuilder in project intellij-community by JetBrains.
the class FindPopupPanel method showUI.
public void showUI() {
if (myBalloon != null && myBalloon.isVisible()) {
return;
}
if (myBalloon != null && !myBalloon.isDisposed()) {
myBalloon.cancel();
}
if (myBalloon == null || myBalloon.isDisposed()) {
final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(this, mySearchComponent);
myBalloon = builder.setProject(myHelper.getProject()).setMovable(true).setResizable(true).setMayBeParent(true).setCancelOnClickOutside(true).setModalContext(false).setRequestFocus(true).setCancelCallback(() -> {
if (!myCanClose.get())
return false;
if (!ApplicationManager.getApplication().isActive())
return false;
List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(this);
if (!popups.isEmpty()) {
for (JBPopup popup : popups) {
popup.cancel();
}
return false;
}
if (myScopeUI.hideAllPopups()) {
return false;
}
DimensionService.getInstance().setSize(SERVICE_KEY, myBalloon.getSize(), myHelper.getProject());
DimensionService.getInstance().setLocation(SERVICE_KEY, myBalloon.getLocationOnScreen(), myHelper.getProject());
return true;
}).createPopup();
Disposer.register(myBalloon, myDisposable);
registerCloseAction(myBalloon);
final Window window = WindowManager.getInstance().suggestParentWindow(myProject);
Component parent = UIUtil.findUltimateParent(window);
RelativePoint showPoint = null;
Point screenPoint = DimensionService.getInstance().getLocation(SERVICE_KEY);
if (screenPoint != null) {
showPoint = new RelativePoint(screenPoint);
}
if (parent != null && showPoint == null) {
int height = UISettings.getInstance().getShowNavigationBar() ? 135 : 115;
if (parent instanceof IdeFrameImpl && ((IdeFrameImpl) parent).isInFullScreen()) {
height -= 20;
}
showPoint = new RelativePoint(parent, new Point((parent.getSize().width - getPreferredSize().width) / 2, height));
}
mySearchComponent.selectAll();
WindowMoveListener windowListener = new WindowMoveListener(this);
myTitleLabel.addMouseListener(windowListener);
myTitleLabel.addMouseMotionListener(windowListener);
Dimension panelSize = getPreferredSize();
Dimension prev = DimensionService.getInstance().getSize(SERVICE_KEY);
if (!myCbPreserveCase.isVisible()) {
panelSize.width += myCbPreserveCase.getPreferredSize().width + 8;
}
panelSize.height *= 2;
if (prev != null && prev.height < panelSize.height)
prev.height = panelSize.height;
myBalloon.setMinimumSize(panelSize);
if (prev == null)
panelSize.height = panelSize.height * 3 / 2;
myBalloon.setSize(prev != null ? prev : panelSize);
if (showPoint != null && showPoint.getComponent() != null) {
myBalloon.show(showPoint);
} else {
myBalloon.showCenteredInCurrentWindow(myProject);
}
}
}
use of com.intellij.openapi.ui.popup.ComponentPopupBuilder in project google-cloud-intellij by GoogleCloudPlatform.
the class RepositorySelector method showPopup.
@Override
public void showPopup(RelativePoint showTarget) {
Optional<CredentialedUser> user = cloudProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(cloudProject.googleUsername());
if (user.isPresent()) {
if (popup == null || popup.isDisposed()) {
panel = new RepositoryPanel();
ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
popup = popupBuilder.createPopup();
}
if (!popup.isVisible()) {
popup.show(showTarget);
}
} else {
panel = new ProjectNotSelectedPanel();
ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
popup = popupBuilder.createPopup();
popup.show(showTarget);
}
}
use of com.intellij.openapi.ui.popup.ComponentPopupBuilder 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());
}
use of com.intellij.openapi.ui.popup.ComponentPopupBuilder in project intellij-community by JetBrains.
the class ShowCoveringTestsAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final DataContext context = e.getDataContext();
final Project project = e.getProject();
LOG.assertTrue(project != null);
final Editor editor = e.getData(CommonDataKeys.EDITOR);
LOG.assertTrue(editor != null);
final CoverageSuitesBundle currentSuite = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
LOG.assertTrue(currentSuite != null);
final File[] traceFiles = getTraceFiles(project);
final Set<String> tests = new HashSet<>();
Runnable runnable = () -> {
for (File traceFile : traceFiles) {
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(traceFile));
extractTests(traceFile, in, tests);
} catch (Exception ex) {
LOG.error(traceFile.getName(), ex);
} finally {
try {
in.close();
} catch (IOException ex) {
LOG.error(ex);
}
}
}
};
if (ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Extract information about tests", false, project)) {
//todo cache them? show nothing found message
final String[] testNames = ArrayUtil.toStringArray(tests);
Arrays.sort(testNames);
if (testNames.length == 0) {
HintManager.getInstance().showErrorHint(editor, "Failed to load covered tests");
return;
}
final List<PsiElement> elements = currentSuite.getCoverageEngine().findTestsByNames(testNames, project);
final ImplementationViewComponent component;
final String title = "Tests covering line " + myClassFQName + ":" + myLineData.getLineNumber();
final ComponentPopupBuilder popupBuilder;
if (!elements.isEmpty()) {
component = new ImplementationViewComponent(PsiUtilCore.toPsiElementArray(elements), 0);
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setDimensionServiceKey(project, "ShowTestsPopup", false).setCouldPin(popup -> {
component.showInUsageView();
popup.cancel();
return false;
});
} else {
component = null;
final JPanel panel = new PanelWithText("Following test" + (testNames.length > 1 ? "s" : "") + " could not be found: " + StringUtil.join(testNames, "<br/>").replace("_", "."));
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
}
final JBPopup popup = popupBuilder.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE).setProject(project).setResizable(true).setMovable(true).setTitle(title).createPopup();
popup.showInBestPositionFor(editor);
if (component != null) {
component.setHint(popup, title);
}
}
}
use of com.intellij.openapi.ui.popup.ComponentPopupBuilder in project intellij-community by JetBrains.
the class ChooseByNamePopup method showList.
@Override
protected void showList() {
final JLayeredPane layeredPane = myTextField.getRootPane().getLayeredPane();
Rectangle bounds = new Rectangle(layeredPane.getLocationOnScreen(), myTextField.getSize());
bounds.y += layeredPane.getHeight();
final Dimension preferredScrollPaneSize = myListScrollPane.getPreferredSize();
int lastVisibleRow = Math.min(myList.getVisibleRowCount(), myList.getModel().getSize()) - 1;
Rectangle visibleBounds = lastVisibleRow < 0 ? null : myList.getCellBounds(0, lastVisibleRow);
preferredScrollPaneSize.height = visibleBounds != null ? visibleBounds.height : UIManager.getFont("Label.font").getSize();
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);
JScrollBar hsb = myListScrollPane.getHorizontalScrollBar();
if (original.width > preferredBounds.width && (!SystemInfo.isMac || hsb.isOpaque())) {
int height = hsb.getPreferredSize().height;
preferredBounds.y -= height;
preferredBounds.height += height;
}
if (original.y > preferredBounds.y) {
int height = original.y - preferredBounds.y;
preferredBounds.y += 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).setLocateWithinScreenBounds(false).setRequestFocus(false).setCancelKeyEnabled(false).setFocusOwners(new JComponent[] { myTextField }).setBelongsToGlobalPopupStack(false).setModalContext(false).setAdText(adText).setMayBeParent(true);
builder.setCancelCallback(() -> 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().getHideNavigationOnFocusLoss() || preferredBounds.width > currentSize.width || preferredBounds.height > currentSize.height) {
myDropdownPopup.setSize(preferredBounds.getSize());
}
}
}
Aggregations