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;
}
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;
}
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);
}
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());
}
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);
}
Aggregations