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

The following examples show how to use javax.swing.JMenuItem#getParent() . 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: 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 2
Source File: DropTargetLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean hasRadioOrCheckSibling(JMenuItem item) {
    if(item.getParent() == null) return false;
    for(Component c : item.getParent().getComponents()) {
        if(c instanceof JRadioButtonMenuItem) return true;
        if(c instanceof JCheckBoxMenuItem) return true;
    }
    return false;
}
 
Example 3
Source File: MenuUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
	JMenu menu = (JMenu) menuItem;
	ButtonModel buttonmodel = menu.getModel();
	int w = menu.getWidth();
	int h = menu.getHeight();
	Color oldColor = g.getColor();
	if (!menu.isContentAreaFilled() || !menu.isOpaque()) {
		// do nothing
	} else {
		if (menu.isTopLevelMenu()) {
			if (buttonmodel.isSelected()) {
				CachedPainter.drawMenuBackground(menuItem, g, 0, 0, w, h);
			} else if (buttonmodel.isRollover() && buttonmodel.isEnabled()) {
				g.setColor(Colors.MENUBAR_BACKGROUND_HIGHLIGHT);
				g.fillRect(0, 0, w, h);
			} else {
				if (menuItem.getParent() instanceof JMenuBar) {
					((MenuBarUI) ((JMenuBar) menuItem.getParent()).getUI()).update(g, menuItem);
				}
			}
		} else {
			if (!menuItem.getModel().isSelected()) {
				RapidLookTools.drawMenuItemFading(menuItem, g);
			} else {
				RapidLookTools.drawMenuItemBackground(g, menuItem);
			}
		}
	}
	g.setColor(oldColor);
}
 
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: SeaGlassMenuItemUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
static Dimension getPreferredMenuItemSize(SeaGlassContext context, SeaGlassContext accContext, boolean useCheckAndArrow, JComponent c,
    Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter) {
    JMenuItem b = (JMenuItem) c;
    Icon icon = (Icon) b.getIcon();
    String text = b.getText();
    KeyStroke accelerator = b.getAccelerator();
    String acceleratorText = "";

    if (accelerator != null) {
        int modifiers = accelerator.getModifiers();
        if (modifiers > 0) {
            acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
            acceleratorText += acceleratorDelimiter;
        }
        int keyCode = accelerator.getKeyCode();
        if (keyCode != 0) {
            acceleratorText += KeyEvent.getKeyText(keyCode);
        } else {
            acceleratorText += accelerator.getKeyChar();
        }
    }

    Font font = context.getStyle().getFont(context);
    FontMetrics fm = b.getFontMetrics(font);
    FontMetrics fmAccel = b.getFontMetrics(accContext.getStyle().getFont(accContext));

    resetRects();

    layoutMenuItem(context, fm, accContext, text, fmAccel, acceleratorText, icon, checkIcon, arrowIcon, b.getVerticalAlignment(), b
        .getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect,
        acceleratorRect, checkIconRect, arrowIconRect, text == null ? 0 : defaultTextIconGap, defaultTextIconGap, useCheckAndArrow);
    // find the union of the icon and text rects
    r.setBounds(textRect);
    r = SwingUtilities.computeUnion(iconRect.x, iconRect.y, iconRect.width, iconRect.height, r);
    // To make the accelerator texts appear in a column,
    // find the widest MenuItem text and the widest accelerator text.

    // Get the parent, which stores the information.
    Container parent = b.getParent();

    if (parent instanceof JPopupMenu) {
        SeaGlassPopupMenuUI popupUI = (SeaGlassPopupMenuUI) SeaGlassLookAndFeel.getUIOfType(((JPopupMenu) parent).getUI(),
            SeaGlassPopupMenuUI.class);

        if (popupUI != null) {
            r.width = popupUI.adjustTextWidth(r.width);

            popupUI.adjustAcceleratorWidth(acceleratorRect.width);

            r.width += popupUI.getMaxAcceleratorWidth();
        }
    } else if (parent != null && !(b instanceof JMenu && ((JMenu) b).isTopLevelMenu())) {
        r.width += acceleratorRect.width;
    }

    if (useCheckAndArrow) {
        // Add in the checkIcon
        r.width += checkIconRect.width;
        r.width += defaultTextIconGap;

        // Add in the arrowIcon
        r.width += defaultTextIconGap;
        r.width += arrowIconRect.width;
    }

    r.width += 2 * defaultTextIconGap;

    Insets insets = b.getInsets();
    if (insets != null) {
        r.width += insets.left + insets.right;
        r.height += insets.top + insets.bottom;
    }

    // if the width is even, bump it up one. This is critical
    // for the focus dash line to draw properly
    if (r.width % 2 == 0) {
        r.width++;
    }

    // if the height is even, bump it up one. This is critical
    // for the text to center properly
    if (r.height % 2 == 0) {
        r.height++;
    }
    return r.getSize();
}
 
Example 7
Source File: SelectTimepointEntry.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent e ) 
{
	if ( chartPanel != null )
	{
		// this might fail horribly, but at the moment it is the only solution
		// as right clicks in the chart are not reported to the mouse-listener
		// if they happen above the line drawings
		try
		{
			final JMenuItem item = (JMenuItem)e.getSource(); 
			final JPopupMenu m = (JPopupMenu)item.getParent();

			// location of the top left pixel of the chartpanel in screen coordinates
			final Point p = chartPanel.getLocationOnScreen();

			// we parse the position of the JPopupMenu on the screen (AAARGH!!!)
			final String output = m.toString();

			final String x = output.substring( output.indexOf( "desiredLocationX" ) );
			final String y = output.substring( output.indexOf( "desiredLocationY" ) );

			System.out.println( "chart: " +p );

			System.out.println( "popup: " + x + ", " + y );

			// and from that we get the relative coordinate in the chartpanel 
			p.x = Integer.parseInt( x.substring( x.indexOf( "=" )+1, x.indexOf( "," ) ) ) - p.x;
			p.y = Integer.parseInt( y.substring( y.indexOf( "=" )+1, y.indexOf( "," ) ) ) - p.y;
			
			// now we transform it into the correct timelapse scale
			final int tp = MouseListenerTimelapse.getChartXLocation( p, chartPanel );
			
			// now find the correct image
			for ( final RegistrationStatistics stat : data )
				if ( stat.getTimePoint() == tp )
				{
					IOFunctions.println( "Selected timepoint: " + tp );
					break;
				}
		}
		catch ( Exception ex ) {}
	}
}
 
Example 8
Source File: FileOpenMenuEntry.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent e ) 
{
	if ( chartPanel != null )
	{
		// this might fail horribly, but at the moment it is the only solution
		// as right clicks in the chart are not reported to the mouse-listener
		// if they happen above the line drawings
		try
		{
			final JMenuItem item = (JMenuItem)e.getSource(); 
			final JPopupMenu m = (JPopupMenu)item.getParent();

			// location of the top left pixel of the chartpanel in screen coordinates
			final Point p = chartPanel.getLocationOnScreen();

			// we parse the position of the JPopupMenu on the screen (AAARGH!!!)
			final String output = m.toString();

			final String x = output.substring( output.indexOf( "desiredLocationX" ) );
			final String y = output.substring( output.indexOf( "desiredLocationY" ) );

			System.out.println( "chart: " +p );

			System.out.println( "popup: " + x + ", " + y );

			// and from that we get the relative coordinate in the chartpanel 
			p.x = Integer.parseInt( x.substring( x.indexOf( "=" )+1, x.indexOf( "," ) ) ) - p.x;
			p.y = Integer.parseInt( y.substring( y.indexOf( "=" )+1, y.indexOf( "," ) ) ) - p.y;
			
			// now we transform it into the correct timelapse scale
			final int tp = MouseListenerTimelapse.getChartXLocation( p, chartPanel );
			
			// now find the correct image
			for ( final RegistrationStatistics stat : data )
				if ( stat.timePoint == tp )
				{
					final Image<FloatType> image = LOCI.openLOCIFloatType( stat.worstView.getAbsolutePath(), new ArrayContainerFactory() );
					ImageJFunctions.show( image );
					break;
				}
		}
		catch ( Exception ex ) {}
	}
}