use of com.intellij.openapi.ui.JBMenuItem in project intellij-community by JetBrains.
the class TabbedLanguageCodeStylePanel method fillPredefined.
private void fillPredefined(JMenuItem parentMenu) {
for (final PredefinedCodeStyle predefinedCodeStyle : myPredefinedCodeStyles) {
JMenuItem predefinedItem = new JBMenuItem(predefinedCodeStyle.getName());
parentMenu.add(predefinedItem);
predefinedItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
applyPredefinedStyle(predefinedCodeStyle.getName());
}
});
}
}
use of com.intellij.openapi.ui.JBMenuItem in project intellij-community by JetBrains.
the class DaemonEditorPopup method invokePopup.
@Override
public void invokePopup(final Component comp, final int x, final int y) {
if (ApplicationManager.getApplication() == null)
return;
final JRadioButtonMenuItem errorsFirst = createRadioButtonMenuItem(EditorBundle.message("errors.panel.go.to.errors.first.radio"));
errorsFirst.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DaemonCodeAnalyzerSettings.getInstance().NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST = errorsFirst.isSelected();
}
});
final JPopupMenu popupMenu = new JBPopupMenu();
popupMenu.add(errorsFirst);
final JRadioButtonMenuItem next = createRadioButtonMenuItem(EditorBundle.message("errors.panel.go.to.next.error.warning.radio"));
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DaemonCodeAnalyzerSettings.getInstance().NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST = !next.isSelected();
}
});
popupMenu.add(next);
ButtonGroup group = new ButtonGroup();
group.add(errorsFirst);
group.add(next);
popupMenu.addSeparator();
final JMenuItem hLevel = new JBMenuItem(EditorBundle.message("customize.highlighting.level.menu.item"));
popupMenu.add(hLevel);
final boolean isErrorsFirst = DaemonCodeAnalyzerSettings.getInstance().NEXT_ERROR_ACTION_GOES_TO_ERRORS_FIRST;
errorsFirst.setSelected(isErrorsFirst);
next.setSelected(!isErrorsFirst);
hLevel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final PsiFile psiFile = myPsiFile;
if (psiFile == null)
return;
final HectorComponent component = new HectorComponent(psiFile);
final Dimension dimension = component.getPreferredSize();
Point point = new Point(x, y);
component.showComponent(new RelativePoint(comp, new Point(point.x - dimension.width, point.y)));
}
});
final JBCheckboxMenuItem previewCheckbox = new JBCheckboxMenuItem(IdeBundle.message("checkbox.show.editor.preview.popup"), UISettings.getInstance().getShowEditorToolTip());
popupMenu.addSeparator();
popupMenu.add(previewCheckbox);
previewCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
UISettings.getInstance().setShowToolWindowsNumbers(previewCheckbox.isSelected());
UISettings.getInstance().fireUISettingsChanged();
}
});
PsiFile file = myPsiFile;
if (file != null && DaemonCodeAnalyzer.getInstance(myPsiFile.getProject()).isHighlightingAvailable(file)) {
popupMenu.show(comp, x, y);
}
}
use of com.intellij.openapi.ui.JBMenuItem in project android by JetBrains.
the class VariantsComboBox method createPopupMenu.
@NotNull
protected JPopupMenu createPopupMenu() {
JPopupMenu menu = new JBPopupMenu();
Border existingBorder = menu.getBorder();
if (existingBorder != null) {
menu.setBorder(BorderFactory.createCompoundBorder(existingBorder, VARIANT_MENU_BORDER));
} else {
menu.setBorder(VARIANT_MENU_BORDER);
}
menu.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
int nElements = myModel.getSize();
for (int i = 0; i < nElements; i++) {
final Object element = myModel.getElementAt(i);
JMenuItem item = new JBMenuItem(element.toString());
item.setFont(ThemeEditorUtils.scaleFontForAttribute(item.getFont()));
item.setBorder(VARIANT_ITEM_BORDER);
if (i == 0) {
// Pre-select the first element
item.setArmed(true);
}
item.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Object selectedItem = myModel.getSelectedItem();
if (selectedItem != null) {
fireItemSelectionChanged(new ItemEvent(VariantsComboBox.this, ItemEvent.ITEM_STATE_CHANGED, selectedItem, ItemEvent.DESELECTED));
}
myModel.setSelectedItem(element);
fireModelUpdated();
fireItemSelectionChanged(new ItemEvent(VariantsComboBox.this, ItemEvent.ITEM_STATE_CHANGED, element, ItemEvent.SELECTED));
}
});
menu.add(item);
}
if (!myActions.isEmpty()) {
if (nElements > 0) {
menu.addSeparator();
}
for (Action action : myActions) {
JMenuItem newMenuItem = new JBMenuItem(action);
newMenuItem.setFont(ThemeEditorUtils.scaleFontForAttribute(newMenuItem.getFont()));
newMenuItem.setBackground(VARIANT_MENU_BACKGROUND_COLOR);
newMenuItem.setBorder(VARIANT_ITEM_BORDER);
menu.add(newMenuItem);
}
}
return menu;
}
use of com.intellij.openapi.ui.JBMenuItem in project intellij-community by JetBrains.
the class TabbedLanguageCodeStylePanel method fillLanguages.
private void fillLanguages(JComponent parentMenu) {
Language[] languages = LanguageCodeStyleSettingsProvider.getLanguagesWithCodeStyleSettings();
@SuppressWarnings("UnnecessaryFullyQualifiedName") java.util.List<JMenuItem> langItems = new ArrayList<>();
for (final Language lang : languages) {
if (!lang.equals(getDefaultLanguage())) {
final String langName = LanguageCodeStyleSettingsProvider.getLanguageName(lang);
JMenuItem langItem = new JBMenuItem(langName);
langItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
applyLanguageSettings(lang);
}
});
langItems.add(langItem);
}
}
Collections.sort(langItems, (item1, item2) -> item1.getText().compareToIgnoreCase(item2.getText()));
for (JMenuItem langItem : langItems) {
parentMenu.add(langItem);
}
}
use of com.intellij.openapi.ui.JBMenuItem in project android by JetBrains.
the class ManifestPanel method createPopupMenu.
private void createPopupMenu() {
myPopup = new JBPopupMenu();
JMenuItem gotoItem = new JBMenuItem("Go to Declaration");
gotoItem.addActionListener(e -> {
TreePath treePath = myTree.getSelectionPath();
final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
if (node != null) {
goToDeclaration(node.getUserObject());
}
});
myPopup.add(gotoItem);
myRemoveItem = new JBMenuItem("Remove");
myRemoveItem.addActionListener(e -> {
TreePath treePath = myTree.getSelectionPath();
final ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
new WriteCommandAction.Simple(myFacet.getModule().getProject(), "Removing manifest tag", ManifestUtils.getMainManifest(myFacet)) {
@Override
protected void run() throws Throwable {
ManifestUtils.toolsRemove(ManifestUtils.getMainManifest(myFacet), node.getUserObject());
}
}.execute();
});
myPopup.add(myRemoveItem);
MouseListener ml = new MouseAdapter() {
@Override
public void mousePressed(@NotNull MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopup(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopup(e);
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
if (treePath != null) {
ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
Node attribute = node.getUserObject();
if (attribute instanceof Attr) {
goToDeclaration(attribute);
}
}
}
}
private void handlePopup(@NotNull MouseEvent e) {
TreePath treePath = myTree.getPathForLocation(e.getX(), e.getY());
if (treePath == null || e.getSource() == myDetails) {
// Use selection instead
treePath = myTree.getSelectionPath();
}
if (treePath != null) {
ManifestTreeNode node = (ManifestTreeNode) treePath.getLastPathComponent();
myRemoveItem.setEnabled(canRemove(node.getUserObject()));
myPopup.show(e.getComponent(), e.getX(), e.getY());
}
}
};
myTree.addMouseListener(ml);
myDetails.addMouseListener(ml);
}
Aggregations