Java Code Examples for javax.swing.JMenuItem#addMouseListener()

The following examples show how to use javax.swing.JMenuItem#addMouseListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpinnerMenu.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void design(JPopupMenu jPopupMenu) {
    for (Type type : spinnerLabel.list) {
        JMenuItem jMenuItem = new JMenuItem(type.toString());
        if (hover)
            jMenuItem.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseEntered(MouseEvent myMouseEvent) {
                    setValue(type);
                }
            });
        jMenuItem.addActionListener(myActionEvent -> {
            if (!type.equals(spinnerLabel.getValue())) // invoke only when different
                setValue(type);
        });
        map.put(type, jMenuItem);
        jPopupMenu.add(jMenuItem);
    }
}
 
Example 2
Source File: InterMenu.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new {@code InterMenu} object.
 *
 * @param inter     originating inter
 * @param relations (non empty) set of inter relations
 */
public InterMenu (final Inter inter,
                  final Set<Relation> relations)
{
    this.inter = inter;

    final Sheet sheet = inter.getSig().getSystem().getSheet();
    menu = new SeparableMenu(new InterAction(inter, null));

    // Title
    menu.add(buildTitle(sheet, inter));
    menu.addSeparator();

    interController = sheet.getInterController();

    for (Relation relation : relations) {
        JMenuItem item = new JMenuItem(new RelationAction(inter, relation));
        item.addMouseListener(relationListener);
        menu.add(item);
    }

    menu.trimSeparator();
}
 
Example 3
Source File: InterMenu.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
private JMenuItem buildTitle (final Sheet sheet,
                              final Inter inter)
{
    JMenuItem title = new JMenuItem("Relations:");
    title.setEnabled(false);
    title.addMouseListener(new AbstractMouseListener()
    {
        @Override
        public void mouseEntered (MouseEvent e)
        {
            sheet.getInterIndex().getEntityService().publish(
                    new EntityListEvent<>(
                            this,
                            SelectionHint.ENTITY_INIT,
                            MouseMovement.PRESSING,
                            inter));
        }
    });

    return title;
}
 
Example 4
Source File: GlyphListMenu.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void updateUserLocation (Rectangle rect)
{
    // We rebuild the menu items on each update, since the set of glyphs is brand new.
    removeAll();

    Collection<Glyph> glyphs = sheet.getGlyphIndex().getSelectedGlyphList();

    if ((glyphs != null) && !glyphs.isEmpty()) {
        UIUtil.insertTitle(this, "Glyphs:");

        for (Glyph glyph : glyphs) {
            ///JMenuItem item = new SampleMenu(glyph, sheet);
            JMenuItem item = new ShapeMenu(glyph, sheet);

            if (!glyph.getGroups().isEmpty()) {
                item.setToolTipText(glyph.getGroups().toString());
            }

            item.addMouseListener(glyphListener);
            add(item);
        }

        setVisible(true);
    } else {
        setVisible(false);
    }

    super.updateUserLocation(rect);
}
 
Example 5
Source File: TribesMenu.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void updateUserLocation (Rectangle rect)
{
    // We rebuild the menu items on each update, since the set of glyphs is brand new.
    removeAll();

    Collection<Glyph> glyphs = sheet.getGlyphIndex().getSelectedGlyphList();

    if ((glyphs != null) && !glyphs.isEmpty()) {
        UIUtil.insertTitle(this, "Tribes:");

        for (Glyph glyph : glyphs) {
            JMenuItem item = new TribeMenu(glyph, sheet);

            if (!glyph.getGroups().isEmpty()) {
                item.setToolTipText(glyph.getGroups().toString());
            }

            item.addMouseListener(glyphListener);
            add(item);
        }

        setVisible(true);
    } else {
        setVisible(false);
    }

    super.updateUserLocation(rect);
}
 
Example 6
Source File: MenuFactory.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private static void addRollOverSoundEffect(JMenuItem menuItem, SoundIdReader soundIdReader) {
	if (soundIdReader == null) {
		throw new IllegalStateException("soundIdReader is null");
	}
	
	menuItem.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseExited(MouseEvent e) {
			soundIdReader.playSoundEffect(SoundIds.ROLLOVER);
		}
	});
}