use of javax.swing.event.PopupMenuListener 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.PopupMenuListener 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.PopupMenuListener 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.PopupMenuListener 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);
}
}
}
use of javax.swing.event.PopupMenuListener in project intellij-plugins by JetBrains.
the class DropDownButton method showPopup.
public void showPopup() {
ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu("POPUP", myActionGroup);
JPopupMenu menuComponent = menu.getComponent();
menuComponent.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
myForcePressed = false;
repaint();
}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
repaint();
myForcePressed = true;
menuComponent.show(this, 0, getHeight());
}
Aggregations