use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class PopupPositionManager method discoverPopup.
private static Component discoverPopup(final DataKey<JBPopup> datakey, Component focusOwner) {
if (focusOwner == null) {
focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
}
if (focusOwner == null)
return null;
final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
if (dataContext == null)
return null;
final JBPopup popup = datakey.getData(dataContext);
if (popup != null && popup.isVisible()) {
return popup.getContent();
}
return null;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ChangeGoToChangePopupAction method createPopup.
@NotNull
@Override
protected JBPopup createPopup(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null)
project = ProjectManager.getInstance().getDefaultProject();
Ref<JBPopup> popup = new Ref<>();
ChangesBrowser cb = new MyChangesBrowser(project, getChanges(), getCurrentSelection(), popup);
popup.set(JBPopupFactory.getInstance().createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent()).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true).setCancelOnWindowDeactivation(true).setCancelOnOtherWindowOpen(true).setMovable(true).setCancelKeyEnabled(true).setCancelOnClickOutside(true).setDimensionServiceKey(project, "Diff.GoToChangePopup", false).createPopup());
return popup.get();
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class InjectLanguageAction method doChooseLanguageToInject.
public static boolean doChooseLanguageToInject(Editor editor, final Processor<Injectable> onChosen) {
final List<Injectable> injectables = getAllInjectables();
final JList list = new JBList(injectables);
list.setCellRenderer(new ColoredListCellRendererWrapper<Injectable>() {
@Override
protected void doCustomize(JList list, Injectable language, int index, boolean selected, boolean hasFocus) {
setIcon(language.getIcon());
append(language.getDisplayName());
String description = language.getAdditionalDescription();
if (description != null) {
append(description, SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
}
});
Dimension minSize = new JLabel(PlainTextLanguage.INSTANCE.getDisplayName(), EmptyIcon.ICON_16, SwingConstants.LEFT).getMinimumSize();
minSize.height *= 4;
list.setMinimumSize(minSize);
JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(() -> {
Injectable value = (Injectable) list.getSelectedValue();
if (value != null) {
onChosen.process(value);
PropertiesComponent.getInstance().setValue(LAST_INJECTED_LANGUAGE, value.getId());
}
}).setFilteringEnabled(language -> ((Injectable) language).getDisplayName()).setMinSize(minSize).createPopup();
final String lastInjected = PropertiesComponent.getInstance().getValue(LAST_INJECTED_LANGUAGE);
if (lastInjected != null) {
Injectable injectable = ContainerUtil.find(injectables, injectable1 -> lastInjected.equals(injectable1.getId()));
list.setSelectedValue(injectable, true);
}
popup.showInBestPositionFor(editor);
return true;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ManageRecentProjectsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Disposable disposable = Disposer.newDisposable();
NewRecentProjectPanel panel = new NewRecentProjectPanel(disposable);
JList list = UIUtil.findComponentOfType(panel, JList.class);
JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list).setTitle("Recent Projects").setFocusable(true).setRequestFocus(true).setMayBeParent(true).setMovable(true).createPopup();
Disposer.register(popup, disposable);
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
popup.showCenteredInCurrentWindow(project);
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class SliderSelectorAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final JPanel result = new JPanel(new BorderLayout());
final JLabel label = new JLabel(myConfiguration.getSelectText());
label.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 0));
JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(label, BorderLayout.NORTH);
final Dictionary dictionary = myConfiguration.getDictionary();
final Enumeration elements = dictionary.elements();
final JSlider slider = new JSlider(SwingConstants.HORIZONTAL, myConfiguration.getMin(), myConfiguration.getMax(), myConfiguration.getSelected()) {
Integer myWidth = null;
@Override
public Dimension getPreferredSize() {
final Dimension size = super.getPreferredSize();
if (myWidth == null) {
myWidth = 10;
final FontMetrics fm = getFontMetrics(getFont());
while (elements.hasMoreElements()) {
String text = ((JLabel) elements.nextElement()).getText();
myWidth += fm.stringWidth(text + "W");
}
}
return new Dimension(myWidth, size.height);
}
};
slider.setMinorTickSpacing(1);
slider.setPaintTicks(true);
slider.setPaintTrack(true);
slider.setSnapToTicks(true);
UIUtil.setSliderIsFilled(slider, true);
slider.setPaintLabels(true);
slider.setLabelTable(dictionary);
if (!myConfiguration.isShowOk()) {
result.add(wrapper, BorderLayout.WEST);
result.add(slider, BorderLayout.CENTER);
} else {
result.add(wrapper, BorderLayout.WEST);
result.add(slider, BorderLayout.CENTER);
}
final Runnable saveSelection = () -> {
int value = slider.getModel().getValue();
myConfiguration.getResultConsumer().consume(value);
};
final Ref<JBPopup> popupRef = new Ref<>(null);
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(result, slider).setMovable(true).setCancelOnWindowDeactivation(true).setCancelKeyEnabled(myConfiguration.isShowOk()).setKeyboardActions(Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveSelection.run();
popupRef.get().closeOk(null);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)))).createPopup();
popupRef.set(popup);
if (myConfiguration.isShowOk()) {
final JButton done = new JButton("Done");
final JBPanel doneWrapper = new JBPanel(new BorderLayout());
doneWrapper.add(done, BorderLayout.NORTH);
result.add(doneWrapper, BorderLayout.EAST);
done.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveSelection.run();
popup.closeOk(null);
}
});
} else {
popup.setFinalRunnable(saveSelection);
}
InputEvent inputEvent = e.getInputEvent();
show(e, result, popup, inputEvent);
}
Aggregations