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 android by JetBrains.
the class ViewBitmapAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
ClassInstance selectedClassInstance = e.getData(InstancesTreeView.SELECTED_CLASS_INSTANCE);
if (selectedClassInstance == null) {
return;
}
try {
BufferedImage img = BitmapDecoder.getBitmap(new HprofBitmapProvider(selectedClassInstance));
final JComponent comp;
if (img != null) {
comp = ImageEditorManagerImpl.createImageEditorUI(img);
} else {
String errorMessage = AndroidBundle.message("android.profiler.hprof.actions.view.bitmap.fail");
comp = new JLabel(errorMessage, Messages.getErrorIcon(), SwingConstants.CENTER);
}
Project project = e.getData(CommonDataKeys.PROJECT);
JBPopup popup = DebuggerUIUtil.createValuePopup(project, comp, null);
JFrame frame = WindowManager.getInstance().getFrame(project);
Dimension frameSize = frame.getSize();
Dimension size = new Dimension(frameSize.width / 2, frameSize.height / 2);
popup.setSize(size);
popup.show(new RelativePoint(frame, new Point(size.width / 2, size.height / 2)));
} catch (Exception ignored) {
}
}
use of com.intellij.ui.awt.RelativePoint in project android by JetBrains.
the class LintNotificationPanel method showInBestPositionFor.
@NotNull
public JBPopup showInBestPositionFor(@Nullable Project project, @NotNull JComponent component) {
return setupPopup(project, popup -> {
Dimension preferredSize = DimensionService.getInstance().getSize(DIMENSION_KEY, project);
if (preferredSize == null) {
preferredSize = myPanel.getPreferredSize();
}
showInScreenPosition(project, new RelativePoint(component, new Point(component.getWidth() - preferredSize.width, component.getHeight())));
});
}
use of com.intellij.ui.awt.RelativePoint in project intellij-plugins by JetBrains.
the class JstdAssertionFrameworkLineMarkerProvider method showPopup.
private static void showPopup(@NotNull MouseEvent e, @NotNull final PsiElement psiElement, final String displayName) {
final JBList list = new JBList(getAvailableTypes());
list.setCellRenderer(new ListCellRendererWrapper<Type>() {
@Override
public void customize(JList list, Type value, int index, boolean selected, boolean hasFocus) {
setIcon(value.getIcon());
setText(value.getTitle(displayName));
}
});
PopupChooserBuilder builder = new PopupChooserBuilder(list);
JBPopup popup = builder.setMovable(true).setItemChoosenCallback(() -> {
int[] ids = list.getSelectedIndices();
if (ids.length == 0)
return;
Type type = ObjectUtils.tryCast(list.getSelectedValue(), Type.class);
if (type != null) {
if (psiElement.isValid()) {
execute(type.getExecutor(), psiElement);
}
}
}).createPopup();
popup.show(new RelativePoint(e));
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class LiveTemplateSettingsEditor method createShortContextPanel.
private JPanel createShortContextPanel(final boolean allowNoContexts) {
JPanel panel = new JPanel(new BorderLayout());
final JLabel ctxLabel = new JLabel();
final JLabel change = new JLabel();
change.setForeground(PlatformColors.BLUE);
change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
panel.add(ctxLabel, BorderLayout.CENTER);
panel.add(change, BorderLayout.EAST);
final Runnable updateLabel = () -> {
myExpandByCombo.setEnabled(isExpandableFromEditor());
updateHighlighter();
StringBuilder sb = new StringBuilder();
String oldPrefix = "";
for (TemplateContextType type : getApplicableContexts()) {
final TemplateContextType base = type.getBaseContextType();
String ownName = UIUtil.removeMnemonic(type.getPresentableName());
String prefix = "";
if (base != null && !(base instanceof EverywhereContextType)) {
prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": ";
ownName = StringUtil.decapitalize(ownName);
}
if (type instanceof EverywhereContextType) {
ownName = "Other";
}
if (sb.length() > 0) {
sb.append(oldPrefix.equals(prefix) ? ", " : "; ");
}
if (!oldPrefix.equals(prefix)) {
sb.append(prefix);
oldPrefix = prefix;
}
sb.append(ownName);
}
String contexts = "Applicable in " + sb.toString();
change.setText("Change");
final boolean noContexts = sb.length() == 0;
if (noContexts) {
if (!allowNoContexts) {
ctxLabel.setForeground(JBColor.RED);
}
contexts = "No applicable contexts" + (allowNoContexts ? "" : " yet");
ctxLabel.setIcon(AllIcons.General.BalloonWarning);
change.setText("Define");
} else {
ctxLabel.setForeground(UIUtil.getLabelForeground());
ctxLabel.setIcon(null);
}
ctxLabel.setText(StringUtil.first(contexts + ". ", 100, true));
myTemplateOptionsPanel.removeAll();
myTemplateOptionsPanel.add(createTemplateOptionsPanel());
};
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
if (disposeContextPopup())
return false;
final JPanel content = createPopupContextPanel(updateLabel, myContext);
Dimension prefSize = content.getPreferredSize();
if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) {
content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height)));
}
myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup();
myContextPopup.show(new RelativePoint(change, new Point(change.getWidth(), -content.getPreferredSize().height - 10)));
myContextPopup.addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
myLastSize = content.getSize();
}
});
return true;
}
}.installOn(change);
updateLabel.run();
return panel;
}
Aggregations