javax.swing.JPopupMenu#addPopupMenuListener ( )源码实例Demo

下面列出了javax.swing.JPopupMenu#addPopupMenuListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: PopupActionManager.java
JPopupMenu createPopupMenu(Iterator<DockingActionIf> localActions, ActionContext context) {

		if (localActions == null) {
			localActions = IteratorUtils.emptyIterator();
		}

		MenuHandler popupMenuHandler = new PopupMenuHandler(windowManager, context);
		MenuManager menuMgr =
			new MenuManager("Popup", '\0', null, true, popupMenuHandler, menuGroupMap);
		populatePopupMenuActions(localActions, context, menuMgr);
		if (menuMgr.isEmpty()) {
			return null;
		}

		// Popup menu if items are available
		JPopupMenu popupMenu = menuMgr.getPopupMenu();
		popupMenu.addPopupMenuListener(popupMenuHandler);
		return popupMenu;
	}
 
源代码2 项目: netbeans   文件: ButtonPopupSwitcher.java
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    pTable.getSelectionModel().addListSelectionListener( this );

    displayer.getModel().addComplexListDataListener( this );

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);

    popup = new JPopupMenu();
    popup.setBorderPainted( false );
    popup.setBorder( BorderFactory.createEmptyBorder() );
    popup.add( pTable );
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation( locationX, locationY );
    popup.setInvoker( invokingComponent );
    popup.addPopupMenuListener( this );
    popup.setVisible( true );
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
源代码3 项目: netbeans   文件: ButtonPopupSwitcher.java
private void doSelect(JComponent owner) {
    invokingComponent = owner;
    invokingComponent.addMouseListener(this);
    invokingComponent.addMouseMotionListener(this);
    pTable.addMouseListener(this);
    pTable.addMouseMotionListener(this);
    pTable.getSelectionModel().addListSelectionListener( this );

    controller.getTabModel().addComplexListDataListener( this );

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);

    popup = new JPopupMenu();
    popup.setBorderPainted( false );
    popup.setBorder( BorderFactory.createEmptyBorder() );
    popup.add( pTable );
    popup.pack();
    int locationX = x - (int) pTable.getPreferredSize().getWidth();
    int locationY = y + 1;
    popup.setLocation( locationX, locationY );
    popup.setInvoker( invokingComponent );
    popup.addPopupMenuListener( this );
    popup.setVisible( true );
    shown = true;
    invocationTime = System.currentTimeMillis();
}
 
/**
 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
 * specified number of items to display in the scrolling region, the
 * specified scrolling interval, and the specified numbers of items fixed at
 * the top and bottom of the popup menu.
 *
 * @param menu the popup menu
 * @param scrollCount the number of items to display in the scrolling
 * portion
 * @param interval the scroll interval, in milliseconds
 * @param topFixedCount the number of items to fix at the top. May be 0
 * @param bottomFixedCount the number of items to fix at the bottom. May be
 * 0
 * @throws IllegalArgumentException if scrollCount or interval is 0 or
 * negative or if topFixedCount or bottomFixedCount is negative
 */
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
        int topFixedCount, int bottomFixedCount) {
    if (scrollCount <= 0 || interval <= 0) {
        throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
    }
    if (topFixedCount < 0 || bottomFixedCount < 0) {
        throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
    }

    upItem = new MenuScrollItem(MenuIcon.UP, -1);
    downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
    setScrollCount(scrollCount);
    setInterval(interval);
    setTopFixedCount(topFixedCount);
    setBottomFixedCount(bottomFixedCount);

    this.menu = menu;
    menu.addPopupMenuListener(menuListener);
}
 
源代码5 项目: rapidminer-studio   文件: FancyDropDownButton.java
@Override
public void loggedActionPerformed(ActionEvent ae) {
	JPopupMenu popup = getPopupMenu();
	popup.addPopupMenuListener(popupMenuListener);

	int popupPrefHeight = (int) popup.getPreferredSize().getHeight();
	int buttonY = mainButton.getLocationOnScreen().y;

	boolean showOnTop = false;

	GraphicsConfiguration graphicsConf = ApplicationFrame.getApplicationFrame().getGraphicsConfiguration();
	if (graphicsConf != null) {
		int windowHeight = (int) graphicsConf.getBounds().getHeight();
		showOnTop = buttonY + mainButton.getHeight() + popupPrefHeight > windowHeight;
	}

	if (showOnTop) {
		popup.show(mainButton, 0, -popupPrefHeight);
	} else {
		popup.show(mainButton, 0, mainButton.getHeight());
	}
}
 
源代码6 项目: jeveassets   文件: JDropDownButton.java
public JDropDownButton(final String text, final Icon icon, final int popupHorizontalAlignment, final int popupVerticalAlignment) {
	super(text, icon);
	if (popupHorizontalAlignment != LEFT && popupHorizontalAlignment != RIGHT && popupHorizontalAlignment != CENTER) {
		throw new IllegalArgumentException("Must be SwingConstants.RIGHT, SwingConstants.LEFT, or SwingConstants.CENTER");
	}
	if (popupVerticalAlignment != TOP && popupVerticalAlignment != BOTTOM && popupVerticalAlignment != CENTER) {
		throw new IllegalArgumentException("Must be SwingConstants.TOP, SwingConstants.BOTTOM, or SwingConstants.CENTER");
	}

	ListenerClass listener = new ListenerClass();

	this.popupHorizontalAlignment = popupHorizontalAlignment;
	this.popupVerticalAlignment = popupVerticalAlignment;
	this.setText(text);
	this.addMouseListener(listener);
	this.addKeyListener(listener);
	jPopupMenu = new JPopupMenu();
	jPopupMenu.addPopupMenuListener(listener);
	menuScroller = new MenuScroller(jPopupMenu);
}
 
源代码7 项目: megamek   文件: MenuScroller.java
/**
 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
 * specified number of items to display in the scrolling region, the
 * specified scrolling interval, and the specified numbers of items fixed at
 * the top and bottom of the popup menu.
 * 
 * @param menu the popup menu
 * @param scrollCount the number of items to display in the scrolling portion
 * @param interval the scroll interval, in milliseconds
 * @param topFixedCount the number of items to fix at the top.  May be 0
 * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
 * @throws IllegalArgumentException if scrollCount or interval is 0 or
 * negative or if topFixedCount or bottomFixedCount is negative
 */
public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
        int topFixedCount, int bottomFixedCount) {
  if (scrollCount <= 0 || interval <= 0) {
    throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
  }
  if (topFixedCount < 0 || bottomFixedCount < 0) {
    throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
  }

  upItem = new MenuScrollItem(MenuIcon.UP, -1);
  downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
  setScrollCount(scrollCount);
  setInterval(interval);
  setTopFixedCount(topFixedCount);
  setBottomFixedCount(bottomFixedCount);

  this.menu = menu;
  menu.addPopupMenuListener(menuListener);
}
 
源代码8 项目: netbeans   文件: ToolsAction.java
private void fillSubmenu(JPopupMenu pop) {
    if (lastPopup == null) {
        pop.addPopupMenuListener(this);
        lastPopup = pop;

        removeAll();

        Iterator it = generate(toolsAction, false).iterator();

        while (it.hasNext()) {
            java.awt.Component item = (java.awt.Component) it.next();

            if (item == null) {
                addSeparator();
            } else {
                add(item);
            }
        }

        // also work with empty element
        if (getMenuComponentCount() == 0) {
            JMenuItem empty = new JMenuItem(NbBundle.getMessage(ToolsAction.class, "CTL_EmptySubMenu"));
            empty.setEnabled(false);
            add(empty);
        }
    }
}
 
源代码9 项目: netbeans   文件: MainProjectActionWithHistory.java
@Override
public Component getToolbarPresenter() {
   
        JPopupMenu menu = new JPopupMenu();
        JButton button = DropDownButtonFactory.createDropDownButton(
                new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
        final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
        item.setEnabled(isEnabled());

        addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String propName = evt.getPropertyName();
                if ("enabled".equals(propName)) {
                    item.setEnabled((Boolean) evt.getNewValue());
                } else if ("menuText".equals(propName)) {
                    item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
                }
            }
        });

        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainProjectActionWithHistory.this.actionPerformed(e);
            }
        });
       
        org.openide.awt.Actions.connect(button, this);
        menu.addPopupMenuListener(this);
        return button;
    
}
 
源代码10 项目: Logisim   文件: Canvas.java
public void showPopupMenu(JPopupMenu menu, int x, int y) {
	double zoom = getZoomFactor();
	if (zoom != 1.0) {
		x = (int) Math.round(x * zoom);
		y = (int) Math.round(y * zoom);
	}
	myListener.menu_on = true;
	menu.addPopupMenuListener(myListener);
	menu.show(this, x, y);
}
 
源代码11 项目: rapidminer-studio   文件: DropDownButton.java
@Override
public void loggedActionPerformed(ActionEvent ae) {
	JPopupMenu popup = getPopupMenu();
	popup.addPopupMenuListener(popupMenuListener);
	popup.show(mainButton,
			isRightAlign() ? -popup.getPreferredSize().width + mainButton.getWidth() + arrowButton.getWidth() : 0,
			mainButton.getHeight());
}
 
源代码12 项目: karamel   文件: TrayUI.java
public void setJPopupMenu(JPopupMenu menu) {
  if (this.menu != null) {
    this.menu.removePopupMenuListener(popupListener);
  }
  this.menu = menu;
  menu.addPopupMenuListener(popupListener);
}
 
源代码13 项目: android-classyshark   文件: RecentArchivesButton.java
public RecentArchivesButton() {
    super();
    setIcon(GuiMode.getTheme().getRecentIcon());
    setToolTipText("History");
    popup = new JPopupMenu();
    theme.applyTo(popup);
    popup.setLayout(new BoxLayout(popup, BoxLayout.Y_AXIS));
    popup.addPopupMenuListener(new PopupPrintListener());
    buildPopup();

    setBorderPainted(false);
    setFocusPainted(true);
    addMouseListener(new MousePopupListener());
}
 
源代码14 项目: wpcleaner   文件: AbstractPageListPopupListener.java
/**
 * Construct and show popup menu.
 * 
 * @param component Component.
 * @param link Selected page.
 * @param x Position.
 * @param y Position.
 */
private void showPopup(Component component, Page link, int x, int y) {

  // Menu name
  JPopupMenu popup = new JPopupMenu();
  JMenuItem menuItem = new JMenuItem(link.getTitle());
  menuItem.setEnabled(false);
  popup.add(menuItem);

  // Create sub menus
  createPopup(popup, link);

  popup.show(component, x, y);
  popup.addPopupMenuListener(this);
}
 
源代码15 项目: netbeans   文件: DebugMainProjectAction.java
@Override public Component getToolbarPresenter() {
    JPopupMenu menu = new JPopupMenu();
    JButton button = DropDownButtonFactory.createDropDownButton(
            new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
    final JMenuItem item = new JMenuItem(Actions.cutAmpersand((String) delegate.getValue("menuText")));
    item.setEnabled(delegate.isEnabled());

    delegate.addPropertyChangeListener(new PropertyChangeListener() {
        @Override public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("enabled".equals(propName)) {
                item.setEnabled((Boolean)evt.getNewValue());
            } else if ("menuText".equals(propName)) {
                item.setText(Actions.cutAmpersand((String) evt.getNewValue()));
            } else if ("selectedProjects".equals(propName)) {
                Project[] projects = (Project[]) evt.getNewValue();
                if (projects.length == 1) {
                    debugHistorySupport.setSelectedProject(projects[0].getProjectDirectory());
                } else {
                    debugHistorySupport.setSelectedProject(null);
                }
            }
        }
    });

    menu.add(item);
    item.addActionListener(new ActionListener() {
        @Override public void actionPerformed(ActionEvent e) {
            DebugMainProjectAction.this.actionPerformed(e);
        }
    });
    try {
        Action ca = Actions.forID("Debug", "org.netbeans.modules.debugger.ui.actions.ConnectAction");
        JMenuItem item2 = new JMenuItem(Actions.cutAmpersand((String) ca.getValue(NAME)));
        Actions.connect(item2, ca);
        menu.add(item2);
    } catch (Exception nsee) {
        Exceptions.printStackTrace(nsee);
    }

    menu.addPopupMenuListener(this);

    Actions.connect(button, this);
    return button;
}
 
源代码16 项目: nextreports-designer   文件: DropDownButton.java
public void actionPerformed(ActionEvent event) {
	JPopupMenu popup = getPopupMenu();
	popup.addPopupMenuListener(this);
	popup.show(mainButton, 0, mainButton.getHeight());
}