use of com.intellij.openapi.actionSystem.AnActionEvent 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);
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class CloudAccountSelectionEditor method onNewButton.
private void onNewButton() {
if (myCloudTypes.size() == 1) {
createAccount(ContainerUtil.getFirstItem(myCloudTypes));
return;
}
DefaultActionGroup group = new DefaultActionGroup();
for (final ServerType<?> cloudType : myCloudTypes) {
group.add(new AnAction(cloudType.getPresentableName(), cloudType.getPresentableName(), cloudType.getIcon()) {
@Override
public void actionPerformed(AnActionEvent e) {
createAccount(cloudType);
}
});
}
JBPopupFactory.getInstance().createActionGroupPopup("New Account", group, DataManager.getInstance().getDataContext(myMainPanel), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false).showUnderneathOf(myNewButton);
}
use of com.intellij.openapi.actionSystem.AnActionEvent 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.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class FrameDiffTool method show.
public void show(DiffRequest request) {
Collection hints = request.getHints();
boolean shouldOpenDialog = shouldOpenDialog(hints);
if (shouldOpenDialog) {
final DialogBuilder builder = new DialogBuilder(request.getProject());
DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true);
if (diffPanel == null) {
Disposer.dispose(builder);
return;
}
final Runnable onOkRunnable = request.getOnOkRunnable();
if (onOkRunnable != null) {
builder.setOkOperation(() -> {
builder.getDialogWrapper().close(0);
onOkRunnable.run();
});
} else {
builder.removeAllActions();
}
builder.setCenterPanel(diffPanel.getComponent());
builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
builder.setTitle(request.getWindowTitle());
builder.setDimensionServiceKey(request.getGroupKey());
new AnAction() {
public void actionPerformed(final AnActionEvent e) {
builder.getDialogWrapper().close(0);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
showDiffDialog(builder, hints);
} else {
final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper, true);
if (diffPanel == null) {
Disposer.dispose(frameWrapper);
return;
}
frameWrapper.setTitle(request.getWindowTitle());
DiffUtil.initDiffFrame(diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
new AnAction() {
public void actionPerformed(final AnActionEvent e) {
frameWrapper.getFrame().dispose();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
frameWrapper.show();
}
}
use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.
the class MultiLevelDiffTool method show.
@Override
public void show(DiffRequest request) {
Collection hints = request.getHints();
boolean shouldOpenDialog = FrameDiffTool.shouldOpenDialog(hints);
if (shouldOpenDialog) {
final DialogBuilder builder = new DialogBuilder(request.getProject());
final CompositeDiffPanel diffPanel = createPanel(request, builder.getWindow(), builder);
if (diffPanel == null) {
Disposer.dispose(builder);
return;
}
final Runnable onOkRunnable = request.getOnOkRunnable();
if (onOkRunnable != null) {
builder.setOkOperation(() -> {
builder.getDialogWrapper().close(0);
onOkRunnable.run();
});
} else {
builder.removeAllActions();
}
builder.setCenterPanel(diffPanel.getComponent());
builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
builder.setTitle(request.getWindowTitle());
builder.setDimensionServiceKey(request.getGroupKey());
new AnAction() {
public void actionPerformed(final AnActionEvent e) {
builder.getDialogWrapper().close(0);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
diffPanel.setDiffRequest(request);
FrameDiffTool.showDiffDialog(builder, hints);
} else {
final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
final CompositeDiffPanel diffPanel = createPanel(request, frameWrapper.getFrame(), frameWrapper);
if (diffPanel == null) {
Disposer.dispose(frameWrapper);
return;
}
frameWrapper.setTitle(request.getWindowTitle());
diffPanel.setDiffRequest(request);
DiffUtil.initDiffFrame(request.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
new AnAction() {
public void actionPerformed(final AnActionEvent e) {
Disposer.dispose(frameWrapper);
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
frameWrapper.show();
}
}
Aggregations