use of javax.swing.event.PopupMenuEvent in project JMRI by JMRI.
the class RosterGroupsPanel method getButtons.
private JToolBar getButtons() {
JToolBar controls = new JToolBar();
controls.setLayout(new GridLayout(1, 0, 0, 0));
controls.setFloatable(false);
final JToggleButton addGroupBtn = new JToggleButton(new ImageIcon(FileUtil.findURL("resources/icons/misc/gui3/Add.png")), false);
final JToggleButton actGroupBtn = new JToggleButton(new ImageIcon(FileUtil.findURL("resources/icons/misc/gui3/Action.png")), false);
addGroupBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new CreateRosterGroupAction("", scrollPane.getTopLevelAncestor()).actionPerformed(e);
addGroupBtn.setSelected(false);
}
});
actGroupBtn.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ie) {
if (ie.getStateChange() == ItemEvent.SELECTED) {
TreePath g = new TreePath(_model.getPathToRoot(_groups));
if (_tree.getSelectionPath() != null) {
if (_tree.getSelectionPath().getLastPathComponent().toString().equals(Roster.ALLENTRIES)) {
allEntriesMenu.show((JComponent) ie.getSource(), actGroupBtn.getX() - actGroupBtn.getWidth(), actGroupBtn.getY() - allEntriesMenu.getPreferredSize().height);
} else if (g.isDescendant(_tree.getSelectionPath()) && !_tree.getSelectionPath().isDescendant(g)) {
groupsMenu.show((JComponent) ie.getSource(), actGroupBtn.getX() - actGroupBtn.getWidth(), actGroupBtn.getY() - groupsMenu.getPreferredSize().height);
}
}
}
}
});
PopupMenuListener PML = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {
// do nothing
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
actGroupBtn.setSelected(false);
}
@Override
public void popupMenuCanceled(PopupMenuEvent pme) {
actGroupBtn.setSelected(false);
}
};
allEntriesMenu.addPopupMenuListener(PML);
groupsMenu.addPopupMenuListener(PML);
controls.add(addGroupBtn);
controls.add(actGroupBtn);
return controls;
}
use of javax.swing.event.PopupMenuEvent in project gephi by gephi.
the class AbstractPopupAdapter method showPopup.
private void showPopup(int xpos, int ypos, final JPopupMenu popup) {
if ((popup != null) && (popup.getSubElements().length > 0)) {
final PopupMenuListener p = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
popup.removePopupMenuListener(this);
table.requestFocus();
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
};
popup.addPopupMenuListener(p);
popup.show(table, xpos, ypos);
}
}
use of javax.swing.event.PopupMenuEvent in project intellij-community by JetBrains.
the class IntentionHintComponent method recreateMyPopup.
private void recreateMyPopup(@NotNull ListPopupStep step) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (myPopup != null) {
Disposer.dispose(myPopup);
}
myPopup = JBPopupFactory.getInstance().createListPopup(step);
if (myPopup instanceof WizardPopup) {
Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
for (Shortcut shortcut : shortcuts) {
if (shortcut instanceof KeyboardShortcut) {
KeyboardShortcut keyboardShortcut = (KeyboardShortcut) shortcut;
if (keyboardShortcut.getSecondKeyStroke() == null) {
((WizardPopup) myPopup).registerAction("activateSelectedElement", keyboardShortcut.getFirstKeyStroke(), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
myPopup.handleSelect(true);
}
});
}
}
}
}
boolean committed = PsiDocumentManager.getInstance(myFile.getProject()).isCommitted(myEditor.getDocument());
final PsiFile injectedFile = committed ? InjectedLanguageUtil.findInjectedPsiNoCommit(myFile, myEditor.getCaretModel().getOffset()) : null;
final Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
final ScopeHighlighter highlighter = new ScopeHighlighter(myEditor);
final ScopeHighlighter injectionHighlighter = new ScopeHighlighter(injectedEditor);
myPopup.addListener(new JBPopupListener.Adapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
highlighter.dropHighlight();
injectionHighlighter.dropHighlight();
myPopupShown = false;
}
});
myPopup.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(@NotNull ListSelectionEvent e) {
final Object source = e.getSource();
highlighter.dropHighlight();
injectionHighlighter.dropHighlight();
if (source instanceof DataProvider) {
final Object selectedItem = PlatformDataKeys.SELECTED_ITEM.getData((DataProvider) source);
if (selectedItem instanceof IntentionActionWithTextCaching) {
final IntentionAction action = ((IntentionActionWithTextCaching) selectedItem).getAction();
if (action instanceof SuppressIntentionActionFromFix) {
if (injectedFile != null && ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
final PsiElement at = injectedFile.findElementAt(injectedEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
if (container != null) {
injectionHighlighter.highlight(container, Collections.singletonList(container));
}
} else {
final PsiElement at = myFile.findElementAt(myEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
if (container != null) {
highlighter.highlight(container, Collections.singletonList(container));
}
}
}
}
}
}
});
if (myEditor.isOneLineMode()) {
// hide popup on combobox popup show
final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, myEditor.getContentComponent());
if (ancestor != null) {
final JComboBox comboBox = (JComboBox) ancestor;
myOuterComboboxPopupListener = new PopupMenuListenerAdapter() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
hide();
}
};
comboBox.addPopupMenuListener(myOuterComboboxPopupListener);
}
}
Disposer.register(this, myPopup);
Disposer.register(myPopup, new Disposable() {
@Override
public void dispose() {
ApplicationManager.getApplication().assertIsDispatchThread();
}
});
}
use of javax.swing.event.PopupMenuEvent in project intellij-community by JetBrains.
the class JBOptionButton method showPopup.
public void showPopup(final Action actionToSelect, final boolean ensureSelection) {
if (myPopupIsShowing)
return;
myPopupIsShowing = true;
final Point loc = getLocationOnScreen();
final Rectangle screen = ScreenUtil.getScreenRectangle(loc);
final Dimension popupSize = myUnderPopup.getPreferredSize();
final Rectangle intersection = screen.intersection(new Rectangle(new Point(loc.x, loc.y + getHeight()), popupSize));
final boolean above = intersection.height < popupSize.height;
int y = above ? getY() - popupSize.height : getY() + getHeight();
final JPopupMenu popup = above ? myAbovePopup : myUnderPopup;
final Ref<PopupMenuListener> listener = new Ref<>();
listener.set(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
if (popup != null && listener.get() != null) {
popup.removePopupMenuListener(listener.get());
}
SwingUtilities.invokeLater(() -> myPopupIsShowing = false);
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
popup.addPopupMenuListener(listener.get());
popup.show(this, 0, y);
SwingUtilities.invokeLater(() -> {
if (popup == null || !popup.isShowing() || !myPopupIsShowing)
return;
Action selection = actionToSelect;
if (selection == null && myOptions.length > 0 && ensureSelection) {
selection = getAction();
}
if (selection == null)
return;
final MenuElement[] elements = popup.getSubElements();
for (MenuElement eachElement : elements) {
if (eachElement instanceof JMenuItem) {
JMenuItem eachItem = (JMenuItem) eachElement;
if (selection.equals(eachItem.getAction())) {
final MenuSelectionManager mgr = MenuSelectionManager.defaultManager();
final MenuElement[] path = new MenuElement[2];
path[0] = popup;
path[1] = eachItem;
mgr.setSelectedPath(path);
break;
}
}
}
});
}
use of javax.swing.event.PopupMenuEvent in project intellij-community by JetBrains.
the class JBTabsImpl method showMorePopup.
public void showMorePopup(@Nullable final MouseEvent e) {
final SingleRowPassInfo lastLayout = mySingleRowLayout.myLastSingRowLayout;
if (lastLayout == null) {
return;
}
mySingleRowLayout.myMorePopup = new JBPopupMenu();
for (final TabInfo each : getVisibleInfos()) {
if (!mySingleRowLayout.isTabHidden(each))
continue;
final JBMenuItem item = new JBMenuItem(each.getText(), each.getIcon());
item.setForeground(each.getDefaultForeground());
item.setBackground(each.getTabColor());
mySingleRowLayout.myMorePopup.add(item);
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
select(each, true);
}
});
}
mySingleRowLayout.myMorePopup.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
mySingleRowLayout.myMorePopup = null;
}
@Override
public void popupMenuCanceled(final PopupMenuEvent e) {
mySingleRowLayout.myMorePopup = null;
}
});
if (e != null) {
mySingleRowLayout.myMorePopup.show(this, e.getX(), e.getY());
} else {
final Rectangle rect = lastLayout.moreRect;
if (rect != null) {
mySingleRowLayout.myMorePopup.show(this, rect.x, rect.y + rect.height);
}
}
}
Aggregations