Search in sources :

Example 1 with PopupMenuListener

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) JComponent(javax.swing.JComponent) JToolBar(javax.swing.JToolBar) PopupMenuEvent(javax.swing.event.PopupMenuEvent) GridLayout(java.awt.GridLayout) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) ItemListener(java.awt.event.ItemListener)

Example 2 with PopupMenuListener

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);
    }
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) PopupMenuEvent(javax.swing.event.PopupMenuEvent)

Example 3 with PopupMenuListener

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;
                }
            }
        }
    });
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) PopupMenuEvent(javax.swing.event.PopupMenuEvent) Ref(com.intellij.openapi.util.Ref)

Example 4 with PopupMenuListener

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);
        }
    }
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) PopupMenuEvent(javax.swing.event.PopupMenuEvent) SingleRowPassInfo(com.intellij.ui.tabs.impl.singleRow.SingleRowPassInfo)

Example 5 with PopupMenuListener

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());
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) PopupMenuEvent(javax.swing.event.PopupMenuEvent)

Aggregations

PopupMenuEvent (javax.swing.event.PopupMenuEvent)9 PopupMenuListener (javax.swing.event.PopupMenuListener)9 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 List (java.util.List)2 JComponent (javax.swing.JComponent)2 JPopupMenu (javax.swing.JPopupMenu)2 Ref (com.intellij.openapi.util.Ref)1 SingleRowPassInfo (com.intellij.ui.tabs.impl.singleRow.SingleRowPassInfo)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 GridLayout (java.awt.GridLayout)1 FocusAdapter (java.awt.event.FocusAdapter)1 FocusEvent (java.awt.event.FocusEvent)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 KeyEvent (java.awt.event.KeyEvent)1 MouseEvent (java.awt.event.MouseEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1