Search in sources :

Example 41 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class AbstractPopup method relativePointWithDominantRectangle.

private RelativePoint relativePointWithDominantRectangle(final JLayeredPane layeredPane, final Rectangle bounds) {
    Dimension preferredSize = getComponent().getPreferredSize();
    if (myDimensionServiceKey != null) {
        final Dimension dimension = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
        if (dimension != null) {
            preferredSize = dimension;
        }
    }
    final Point leftTopCorner = new Point(bounds.x + bounds.width, bounds.y);
    final Point leftTopCornerScreen = (Point) leftTopCorner.clone();
    SwingUtilities.convertPointToScreen(leftTopCornerScreen, layeredPane);
    final RelativePoint relativePoint;
    if (!ScreenUtil.isOutsideOnTheRightOFScreen(new Rectangle(leftTopCornerScreen.x, leftTopCornerScreen.y, preferredSize.width, preferredSize.height))) {
        relativePoint = new RelativePoint(layeredPane, leftTopCorner);
    } else {
        if (bounds.x > preferredSize.width) {
            relativePoint = new RelativePoint(layeredPane, new Point(bounds.x - preferredSize.width, bounds.y));
        } else {
            // going to cut width
            setDimensionServiceKey(null);
            Rectangle screen = ScreenUtil.getScreenRectangle(leftTopCornerScreen.x, leftTopCornerScreen.y);
            final int spaceOnTheLeft = bounds.x;
            final int spaceOnTheRight = screen.x + screen.width - leftTopCornerScreen.x;
            if (spaceOnTheLeft > spaceOnTheRight) {
                relativePoint = new RelativePoint(layeredPane, new Point(0, bounds.y));
                myComponent.setPreferredSize(new Dimension(spaceOnTheLeft, Math.max(preferredSize.height, JBUI.scale(200))));
            } else {
                relativePoint = new RelativePoint(layeredPane, leftTopCorner);
                myComponent.setPreferredSize(new Dimension(spaceOnTheRight, Math.max(preferredSize.height, JBUI.scale(200))));
            }
        }
    }
    return relativePoint;
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 42 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project android by JetBrains.

the class AbstractDependenciesPanel method createActionsPanel.

@NotNull
protected final JPanel createActionsPanel() {
    JPanel actionsPanel = new JPanel(new BorderLayout());
    DefaultActionGroup actions = new DefaultActionGroup();
    AnAction addDependencyAction = new DumbAwareAction("Add Dependency", "", IconUtil.getAddIcon()) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AbstractPopupAction>(null, getPopupActions()) {

                @Override
                public Icon getIconFor(AbstractPopupAction action) {
                    return action.icon;
                }

                @Override
                public boolean isMnemonicsNavigationEnabled() {
                    return true;
                }

                @Override
                public PopupStep onChosen(AbstractPopupAction action, boolean finalChoice) {
                    return doFinalStep(action::execute);
                }

                @Override
                @NotNull
                public String getTextFor(AbstractPopupAction action) {
                    return "&" + action.index + "  " + action.text;
                }
            });
            popup.show(new RelativePoint(actionsPanel, new Point(0, actionsPanel.getHeight() - 1)));
        }
    };
    actions.add(addDependencyAction);
    List<AnAction> extraToolbarActions = getExtraToolbarActions();
    if (!extraToolbarActions.isEmpty()) {
        actions.addSeparator();
        actions.addAll(extraToolbarActions);
    }
    ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("TOP", actions, true);
    JComponent toolbarComponent = toolbar.getComponent();
    toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
    actionsPanel.add(toolbarComponent, BorderLayout.CENTER);
    return actionsPanel;
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class TestDataNavigationHandler method showNavigationPopup.

private static void showNavigationPopup(final Project project, final List<String> fileNames, final RelativePoint point) {
    List<String> listPaths = new ArrayList<>(fileNames);
    final String CREATE_MISSING_OPTION = "Create Missing Files";
    if (fileNames.size() == 2) {
        VirtualFile file1 = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileNames.get(0));
        VirtualFile file2 = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileNames.get(1));
        if (file1 == null || file2 == null) {
            listPaths.add(CREATE_MISSING_OPTION);
        }
    }
    final JList list = new JBList(ArrayUtil.toStringArray(listPaths));
    list.setCellRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
            String path = (String) value;
            String fileName = PathUtil.getFileName(path);
            if (!fileName.equals(CREATE_MISSING_OPTION)) {
                final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
                setIcon(fileType.getIcon());
            }
            append(String.format("%s (%s)", fileName, PathUtil.getParentPath(path)));
        }
    });
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setItemChoosenCallback(() -> {
        final int[] indices = list.getSelectedIndices();
        if (ArrayUtil.indexOf(indices, fileNames.size()) >= 0) {
            createMissingFiles(project, fileNames);
        } else {
            for (int index : indices) {
                openFileByIndex(project, fileNames, index);
            }
        }
    }).createPopup().show(point);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) RelativePoint(com.intellij.ui.awt.RelativePoint) FileType(com.intellij.openapi.fileTypes.FileType) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 44 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class TestDataNavigationHandler method navigate.

public void navigate(MouseEvent e, final PsiMethod elt) {
    List<String> fileNames = getFileNames(elt);
    if (fileNames == null || fileNames.isEmpty()) {
        return;
    }
    navigate(new RelativePoint(e), fileNames, elt.getProject());
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 45 with RelativePoint

use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.

the class GotoTestDataAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());
    TestDataNavigationHandler.navigate(point, Collections.singletonList(myFilePath), myProject);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

RelativePoint (com.intellij.ui.awt.RelativePoint)127 Project (com.intellij.openapi.project.Project)16 Balloon (com.intellij.openapi.ui.popup.Balloon)15 JBPopup (com.intellij.openapi.ui.popup.JBPopup)15 NotNull (org.jetbrains.annotations.NotNull)15 MouseEvent (java.awt.event.MouseEvent)12 Nullable (org.jetbrains.annotations.Nullable)10 Editor (com.intellij.openapi.editor.Editor)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 PsiElement (com.intellij.psi.PsiElement)8 JBList (com.intellij.ui.components.JBList)8 Disposable (com.intellij.openapi.Disposable)7 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)7 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)7 ArrayList (java.util.ArrayList)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)6 ListPopup (com.intellij.openapi.ui.popup.ListPopup)6 PsiFile (com.intellij.psi.PsiFile)5 HintHint (com.intellij.ui.HintHint)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4