Java Code Examples for javax.swing.JPopupMenu#getInvoker()

The following examples show how to use javax.swing.JPopupMenu#getInvoker() . 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: TabelPanel.java    From aurous-app with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
	final Component c = (Component) e.getSource();
	final JPopupMenu popup = (JPopupMenu) c.getParent();
	final JTable table = (JTable) popup.getInvoker();

	switch (e.getActionCommand()) {
	case "Delete":
		Playlist.getPlaylist().removeSelectedRows(table);
		break;
	case "Play":
		MediaUtils.switchMedia(table);
		break;
	case "Share":
		// System.out.println("Sharing");
		break;
	case "Copy URL":
		MediaUtils.copyMediaURL(table);
		break;
	}
	// System.out.println(table.getSelectedRow() + " : " +
	// table.getSelectedColumn());
}
 
Example 2
Source File: PlayListPanel.java    From aurous-app with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void actionPerformed(final ActionEvent e) {
	final Component c = (Component) e.getSource();
	final JPopupMenu popup = (JPopupMenu) c.getParent();
	final JList<?> list = (JList<?>) popup.getInvoker();
	final Object o = list.getSelectedValue();
	final String playlist = o.toString();
	switch (e.getActionCommand()) {
	case "Delete":
		Playlist.getPlaylist().deletePlayList(list);
		break;
	case "Play":
		ModelUtils.loadPlayList(playlist);
		PlayerFunctions.seekNext();
		break;
	case "Load":
		ModelUtils.loadPlayList(playlist);

		break;
	case "Share":
		// System.out.println("Sharing");
		break;
	}
	// System.out.println(table.getSelectedRow() + " : " +
	// table.getSelectedColumn());
}
 
Example 3
Source File: RMenuItem.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private String buildMenuElementArray(JMenuItem leaf) {
    Vector<JMenuItem> elements = new Vector<JMenuItem>();

    elements.insertElementAt(leaf, 0);
    Component current = leaf.getParent();

    while (current != null) {
        if (current instanceof JPopupMenu) {
            JPopupMenu pop = (JPopupMenu) current;
            current = pop.getInvoker();
        } else if (current instanceof JMenu) {
            JMenu menu = (JMenu) current;
            elements.insertElementAt(menu, 0);
            current = menu.getParent();
        } else if (current instanceof JMenuBar) {
            break;
        } else {
            current = current.getParent();
        }
    }
    mainMenu = elements.get(0);
    JMenuItem parent = null;
    StringBuilder sb = new StringBuilder();
    RComponentFactory finder = new RComponentFactory(omapConfig);
    for (JMenuItem jMenuItem : elements) {
        RComponent rComponent = finder.findRComponent(jMenuItem, null, recorder);
        recorder.recordMenuItem(rComponent);
        String text = JMenuItemJavaElement.getText(JMenuItemJavaElement.getItemText(jMenuItem), jMenuItem,
                parent == null ? new Component[0] : ((JMenu) parent).getMenuComponents());
        parent = jMenuItem;
        sb.append(text).append(">>");
    }
    sb.setLength(sb.length() - 2);
    return sb.toString();
}
 
Example 4
Source File: CopyPastePopupMenu.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
    JMenuItem jmi = (JMenuItem) evt.getSource();
    Container container = jmi.getParent();
    assert(container instanceof JPopupMenu);
    JPopupMenu jpm = (JPopupMenu) container;
    JTextComponent jtf = (JTextComponent) jpm.getInvoker();
    (new CopyClipboardText(null)).toClipboard(jtf.getText());
}
 
Example 5
Source File: CopyPastePopupMenu.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
    JMenuItem jmi = (JMenuItem) evt.getSource();
    Container container = jmi.getParent();
    assert(container instanceof JPopupMenu);
    JPopupMenu jpm = (JPopupMenu) container;
    JTextComponent jtf = (JTextComponent) jpm.getInvoker();
    jtf.setText((new CopyClipboardText(null)).fromClipboard());
}
 
Example 6
Source File: JPopupMenuUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void dynamicChangeToSubmenu(JPopupMenu popup, boolean usedToBeContained) {
    Object invoker = popup.getInvoker();

    if (!(invoker instanceof JMenu)) {
        return;
    }

    JMenu menu = (JMenu) invoker;

    if (!popup.isShowing()) {
        return;
    }

    if (isProblemConfig()) {
        callRefreshLater2(popup, menu);

        return;
    }

    refreshPopup(popup);

    Point p = popup.getLocationOnScreen();
    Dimension popupSize = popup.getPreferredSize();
    Rectangle popupRect = new Rectangle(p, popupSize);
    Rectangle screenRect = getScreenRect();
    boolean willBeContained = isPopupContained(popup);

    if (!screenRect.contains(popupRect)) {
        /*
         * The menu grew off the edge of the screen.
         */
        menu.setPopupMenuVisible(false);
        menu.setPopupMenuVisible(true);
    } else if (usedToBeContained != willBeContained) {
        /*
         * The menu grew off the edge of the containing window.
         * Use the setVisible() hack to change the menu from
         * lightweight to heavyweight.
         */
        popup.setVisible(false);
        popup.setVisible(true);
    }
}
 
Example 7
Source File: PopupMenuPainter.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * @param c
 * @return
 */
private Component getInvoker(JComponent c) {
    JPopupMenu popup = (JPopupMenu) c;
    return popup.getInvoker();
}