use of com.intellij.openapi.ui.JBPopupMenu in project intellij-community by JetBrains.
the class ActionMenu method getPopupMenu.
@Override
public JPopupMenu getPopupMenu() {
if (mySpecialMenu == null) {
mySpecialMenu = new JBPopupMenu();
mySpecialMenu.setInvoker(this);
popupListener = createWinListener(mySpecialMenu);
ReflectionUtil.setField(JMenu.class, this, JPopupMenu.class, "popupMenu", mySpecialMenu);
}
return super.getPopupMenu();
}
use of com.intellij.openapi.ui.JBPopupMenu in project android by JetBrains.
the class ThemeEditorTable method getPopupMenuAtCell.
private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
if (row < 0 || column < 0) {
return null;
}
TableModel rawModel = getModel();
if (!(rawModel instanceof AttributesTableModel)) {
return null;
}
final AttributesTableModel model = (AttributesTableModel) rawModel;
AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
if (contents instanceof AttributesTableModel.AttributeContents) {
final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
final EditedStyleItem item = attribute.getValue();
if (item == null) {
return null;
}
final JBPopupMenu popupMenu = new JBPopupMenu();
if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goTo(item);
}
});
} else {
final ResourceResolver resolver = myContext.getResourceResolver();
assert resolver != null;
final Project project = myContext.getProject();
final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
final File file = new File(resourceValue.getValue());
final VirtualFileManager manager = VirtualFileManager.getInstance();
final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
if (virtualFile != null) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
}
});
}
}
myJavadocAction.setCurrentItem(item);
popupMenu.add(myJavadocAction);
final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
popupMenu.add(new AbstractAction("Reset value") {
@Override
public void actionPerformed(ActionEvent e) {
selectedStyle.removeAttribute(item.getQualifiedName());
model.fireTableCellUpdated(attribute.getRowIndex(), 0);
}
});
}
return popupMenu;
} else if (contents instanceof AttributesTableModel.ParentAttribute) {
final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
if (parentStyle == null) {
return null;
}
final JBPopupMenu menu = new JBPopupMenu();
menu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goToParent();
}
});
return menu;
}
return null;
}
use of com.intellij.openapi.ui.JBPopupMenu 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.JBPopupMenu 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.JBPopupMenu in project android by JetBrains.
the class DeviceDefinitionList method possiblyShowPopup.
private void possiblyShowPopup(MouseEvent e) {
if (!e.isPopupTrigger()) {
return;
}
Point p = e.getPoint();
int row = myTable.rowAtPoint(p);
int col = myTable.columnAtPoint(p);
if (row != -1 && col != -1) {
JBPopupMenu menu = new JBPopupMenu();
menu.add(createMenuItem(new CloneDeviceAction(this)));
menu.add(createMenuItem(new EditDeviceAction(this)));
menu.add(createMenuItem(new ExportDeviceAction(this)));
menu.add(createMenuItem(new DeleteDeviceAction(this)));
menu.show(myTable, p.x, p.y);
}
}
Aggregations