private void setupAction() { addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { JPopupMenu popupMenu = menuProvider.getPopupMenu(); if (!popupMenu.isVisible()) { // hack to prevent filter popup from opening itself again // when you click the button to actually close it while it // is open if (System.currentTimeMillis() - lastPopupCloseTime < 250) { return; } popupMenu.addPopupMenuListener(popupListener); for (PopupMenuListener listener : otherListeners) { popupMenu.addPopupMenuListener(listener); } popupMenu.show(DropDownPopupButton.this, 0, DropDownPopupButton.this.getHeight() - 1); popupMenu.requestFocusInWindow(); } } }); }
public void testAddGetRemovePopupMenuListener() { PopupMenuListener listener1 = new ConcretePopupMenuListener(); PopupMenuListener listener2 = new ConcretePopupMenuListener(); PopupMenuListener listener3 = new ConcretePopupMenuListener(); EventListener[] listenersArray = null; listenersArray = popup.getPopupMenuListeners(); int initialValue = listenersArray.length; popup.addPopupMenuListener(listener1); popup.addPopupMenuListener(listener2); popup.addPopupMenuListener(listener2); listenersArray = popup.getPopupMenuListeners(); assertEquals(initialValue + 3, listenersArray.length); popup.removePopupMenuListener(listener1); popup.addPopupMenuListener(listener3); popup.addPopupMenuListener(listener3); listenersArray = popup.getPopupMenuListeners(); assertEquals(initialValue + 4, listenersArray.length); popup.removePopupMenuListener(listener3); popup.removePopupMenuListener(listener3); listenersArray = popup.getPopupMenuListeners(); assertEquals(initialValue + 2, listenersArray.length); popup.removePopupMenuListener(listener2); popup.removePopupMenuListener(listener2); listenersArray = popup.getPopupMenuListeners(); assertEquals(initialValue, listenersArray.length); }
@Nonnull public static MouseListener installPopupHandler(@Nonnull JComponent component, @Nonnull ActionGroup group, String place, @Nonnull ActionManager actionManager, @Nullable PopupMenuListener menuListener) { if (ApplicationManager.getApplication() == null) return new MouseAdapter(){}; PopupHandler popupHandler = new PopupHandler() { public void invokePopup(Component comp, int x, int y) { ActionPopupMenu popupMenu = actionManager.createActionPopupMenu(place, group); popupMenu.setTargetComponent(component); JPopupMenu menu = popupMenu.getComponent(); if (menuListener != null) menu.addPopupMenuListener(menuListener); menu.show(comp, x, y); } }; component.addMouseListener(popupHandler); return popupHandler; }
@Override public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) { lastPopupCloseTime = System.currentTimeMillis(); JPopupMenu jPopupMenu = (JPopupMenu) e.getSource(); jPopupMenu.removePopupMenuListener(this); for (PopupMenuListener otherListener : otherListeners) { jPopupMenu.removePopupMenuListener(otherListener); } }
/** * Maps {@code JPopupMenu.addPopupMenuListener(PopupMenuListener)} * through queue */ public void addPopupMenuListener(final PopupMenuListener popupMenuListener) { runMapping(new MapVoidAction("addPopupMenuListener") { @Override public void map() { ((JPopupMenu) getSource()).addPopupMenuListener(popupMenuListener); } }); }
/** * Maps {@code JPopupMenu.removePopupMenuListener(PopupMenuListener)} * through queue */ public void removePopupMenuListener(final PopupMenuListener popupMenuListener) { runMapping(new MapVoidAction("removePopupMenuListener") { @Override public void map() { ((JPopupMenu) getSource()).removePopupMenuListener(popupMenuListener); } }); }
public void firePopupMenuWillBecomeVisible() { PopupMenuListener[] listeners = list.getListeners(PopupMenuListener.class); PopupMenuEvent e = null; for (int i = listeners.length - 1; i >= 0; i--) { if (e == null) e = new PopupMenuEvent(this); ((PopupMenuListener) listeners[i]).popupMenuWillBecomeVisible(e); } }
public void firePopupMenuWillBecomeInvisible() { PopupMenuListener[] listeners = list.getListeners(PopupMenuListener.class); PopupMenuEvent e = null; for (int i = listeners.length - 1; i >= 0; i--) { if (e == null) e = new PopupMenuEvent(this); ((PopupMenuListener) listeners[i]).popupMenuWillBecomeInvisible(e); } }
public void firePopupMenuCanceled() { PopupMenuListener[] listeners = list.getListeners(PopupMenuListener.class); PopupMenuEvent e = null; for (int i = listeners.length - 1; i >= 0; i--) { if (e == null) e = new PopupMenuEvent(this); ((PopupMenuListener) listeners[i]).popupMenuCanceled(e); } }
protected void firePopupMenuWillBecomeVisible() { Object[] listeners = list.getListenerList(); PopupMenuEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == PopupMenuListener.class) { if (e == null) e = new PopupMenuEvent(this); ((PopupMenuListener) listeners[i + 1]) .popupMenuWillBecomeVisible(e); } } }
protected void firePopupMenuWillBecomeInvisible() { Object[] listeners = list.getListenerList(); PopupMenuEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == PopupMenuListener.class) { if (e == null) e = new PopupMenuEvent(this); ((PopupMenuListener) listeners[i + 1]) .popupMenuWillBecomeInvisible(e); } } }
protected void firePopupMenuCanceled() { Object[] listeners = list.getListenerList(); PopupMenuEvent e = null; for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == PopupMenuListener.class) { if (e == null) e = new PopupMenuEvent(this); ((PopupMenuListener) listeners[i + 1]).popupMenuCanceled(e); } } }
/** * Fires a popupMenuCanceled() event to all <code>PopupMenuListeners</code>. * * Note: This method is intended for use by plaf classes only. */ public void firePopupMenuCanceled() { PopupMenuListener[] listeners = getPopupMenuListeners(); PopupMenuEvent e = new PopupMenuEvent(this); for (int i = 0; i < listeners.length; i++) listeners[i].popupMenuCanceled(e); }
/** * Fires a popupMenuWillBecomeInvisible() event to all * <code>PopupMenuListeners</code>. * * Note: This method is intended for use by plaf classes only. */ public void firePopupMenuWillBecomeInvisible() { PopupMenuListener[] listeners = getPopupMenuListeners(); PopupMenuEvent e = new PopupMenuEvent(this); for (int i = 0; i < listeners.length; i++) listeners[i].popupMenuWillBecomeInvisible(e); }
/** * Fires a popupMenuWillBecomeVisible() event to all * <code>PopupMenuListeners</code>. * * Note: This method is intended for use by plaf classes only. */ public void firePopupMenuWillBecomeVisible() { PopupMenuListener[] listeners = getPopupMenuListeners(); PopupMenuEvent e = new PopupMenuEvent(this); for (int i = 0; i < listeners.length; i++) listeners[i].popupMenuWillBecomeVisible(e); }
/** * This method calls popupMenuWillBecomeVisible() of popup menu's * PopupMenuListeners. This method is invoked just before popup menu * will appear on the screen. */ protected void firePopupMenuWillBecomeVisible() { EventListener[] ll = listenerList.getListeners(PopupMenuListener.class); for (int i = 0; i < ll.length; i++) ((PopupMenuListener) ll[i]).popupMenuWillBecomeVisible(new PopupMenuEvent(this)); }
/** * This method calls popupMenuWillBecomeInvisible() of popup * menu's PopupMenuListeners. This method is invoked just before popup * menu will disappear from the screen */ protected void firePopupMenuWillBecomeInvisible() { EventListener[] ll = listenerList.getListeners(PopupMenuListener.class); for (int i = 0; i < ll.length; i++) ((PopupMenuListener) ll[i]).popupMenuWillBecomeInvisible(new PopupMenuEvent(this)); }
/** * This method calls popupMenuCanceled() of popup menu's PopupMenuListeners. * This method is invoked just before popup menu is cancelled. This happens * when popup menu is closed without selecting any of its menu items. This * usually happens when the top-level window is resized or moved. */ protected void firePopupMenuCanceled() { EventListener[] ll = listenerList.getListeners(PopupMenuListener.class); for (int i = 0; i < ll.length; i++) ((PopupMenuListener) ll[i]).popupMenuCanceled(new PopupMenuEvent(this)); }
/** * This method fires PopupMenuEvent indicating that combo box's popup list * of items will become visible */ protected void firePopupMenuWillBecomeVisible() { PopupMenuListener[] ll = comboBox.getPopupMenuListeners(); for (int i = 0; i < ll.length; i++) ll[i].popupMenuWillBecomeVisible(new PopupMenuEvent(comboBox)); }
/** * This method fires PopupMenuEvent indicating that combo box's popup list * of items will become invisible. */ protected void firePopupMenuWillBecomeInvisible() { PopupMenuListener[] ll = comboBox.getPopupMenuListeners(); for (int i = 0; i < ll.length; i++) ll[i].popupMenuWillBecomeInvisible(new PopupMenuEvent(comboBox)); }
/** * This method fires PopupMenuEvent indicating that combo box's popup list * of items was closed without selection. */ protected void firePopupMenuCanceled() { PopupMenuListener[] ll = comboBox.getPopupMenuListeners(); for (int i = 0; i < ll.length; i++) ll[i].popupMenuCanceled(new PopupMenuEvent(comboBox)); }
/** * Handles cancel requests (ESC key). */ private void cancel() { // Fire popup menu cancelled event. Unfortunately the // firePopupMenuCancelled() is protected in JPopupMenu so we work // around this limitation by fetching the listeners and notifying them // directly. JPopupMenu lastPopup = (JPopupMenu) getLastPopup(); EventListener[] ll = lastPopup.getListeners(PopupMenuListener.class); for (int i = 0; i < ll.length; i++) { PopupMenuEvent ev = new PopupMenuEvent(lastPopup); ((PopupMenuListener) ll[i]).popupMenuCanceled(ev); } // Close the last popup or the whole selection if there's only one // popup left. MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement path[] = msm.getSelectedPath(); if(path.length > 4) { MenuElement newPath[] = new MenuElement[path.length - 2]; System.arraycopy(path,0,newPath,0,path.length-2); MenuSelectionManager.defaultManager().setSelectedPath(newPath); } else msm.clearSelectedPath(); }
/** * Returns the PopupMenuListener for the MonthView popup. Lazily created. * * @return the popupuMenuListener to install on the popup */ protected PopupMenuListener getPopupMenuListener() { if (popupMenuListener == null) { popupMenuListener = createPopupMenuListener(); } return popupMenuListener; }
public void firePopupMenuWillBecomeVisible() { PopupMenuEvent event = new PopupMenuEvent(this); PopupMenuListener[] listeners = getPopupMenuListeners(); for (int i = 0; i < listeners.length; i++) { listeners[i].popupMenuWillBecomeVisible(event); } }