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

The following examples show how to use javax.swing.JMenuItem#getModel() . 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: XDMMenuUI.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
	ButtonModel model = menuItem.getModel();
	Color oldColor = g.getColor();
	if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
		paintButtonPressed(g, menuItem);
	} else {
		g.setColor(this.colorBg);
		// g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
		// g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());//(0,
		// 0, gap + 1, menuItem.getHeight());
		// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
		// if (menuItem.getIcon() != null) {
		// int gap = menuItem.getIcon().getIconWidth() + 2;
		// g.setColor(this.darkColor);
		// g.drawLine(gap, 0, gap, menuItem.getHeight());
		// g.setColor(this.lightColor);
		// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
		// }
	}
	g.setColor(oldColor);
}
 
Example 2
Source File: SeaGlassGraphicsUtils.java    From seaglass with Apache License 2.0 6 votes vote down vote up
static void paintIcon(Graphics g, SeaGlassMenuItemLayoutHelper lh,
                      MenuItemLayoutHelper.LayoutResult lr) {
    if (lh.getIcon() != null) {
        Icon icon;
        JMenuItem mi = lh.getMenuItem();
        ButtonModel model = mi.getModel();
        if (!model.isEnabled()) {
            icon = mi.getDisabledIcon();
        } else if (model.isPressed() && model.isArmed()) {
            icon = mi.getPressedIcon();
            if (icon == null) {
                // Use default icon
                icon = mi.getIcon();
            }
        } else {
            icon = mi.getIcon();
        }

        if (icon != null) {
            Rectangle iconRect = lr.getIconRect();
            SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x,
                    iconRect.y, iconRect.width, iconRect.height);
        }
    }
}
 
Example 3
Source File: XDMMenuItemUI.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
	ButtonModel model = menuItem.getModel();
	Color oldColor = g.getColor();
	int menuWidth = menuItem.getWidth();
	int menuHeight = menuItem.getHeight();

	Color bgc = (Color) menuItem.getClientProperty("bgColor");
	if (bgc != null) {
		g.setColor(bgc);
	} else {
		g.setColor(colorBg);
	}
	g.fillRect(0, 0, menuWidth, menuHeight);

	if (model.isArmed()
			|| (menuItem instanceof JMenu && model.isSelected())) {
		paintButtonPressed(g, menuItem);
	} else {
		// if (menuItem.getIcon() != null) {
		// int gap = menuItem.getIcon().getIconWidth() + 2;
		// g.setColor(this.darkColor);
		// g.drawLine(gap, 0, gap, menuItem.getHeight());
		// g.setColor(this.lightColor);
		// g.drawLine(gap + 1, 0, gap + 1, menuItem.getHeight());
		// }
	}

	if (menuItem instanceof JCheckBoxMenuItem) {
		if (((JCheckBoxMenuItem) menuItem).isSelected()) {
			// chkIcon.paintIcon(menuItem, g, 5, 5);
		}
	}

	g.setColor(oldColor);
}
 
Example 4
Source File: StayOpenPopupMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void performAction(StayOpen item, int modifiers) {
    JMenuItem i = item.getItem();
    
    // Skip disabled items
    if (!item.getItem().isEnabled()) return;
    
    // Handle toggle items
    if (i.getModel() instanceof JToggleButton.ToggleButtonModel)
        i.setSelected(!i.isSelected());
    
    // Invoke item action
    item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED,
                         item.getItem().getActionCommand(),
                         EventQueue.getMostRecentEventTime(), modifiers));
}
 
Example 5
Source File: StayOpenPopupMenu.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static void performAction(StayOpen item, int modifiers) {
    JMenuItem i = item.getItem();
    
    // Skip disabled items
    if (!item.getItem().isEnabled()) return;
    
    // Handle toggle items
    if (i.getModel() instanceof JToggleButton.ToggleButtonModel)
        i.setSelected(!i.isSelected());
    
    // Invoke item action
    item.actionPerformed(new ActionEvent(item, ActionEvent.ACTION_PERFORMED,
                         item.getItem().getActionCommand(),
                         EventQueue.getMostRecentEventTime(), modifiers));
}
 
Example 6
Source File: RapidLookTools.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void drawMenuItemBackground(Graphics g, JMenuItem menuItem) {
	Color oldColor = g.getColor();
	ButtonModel model = menuItem.getModel();
	int w = menuItem.getWidth();
	int h = menuItem.getHeight();

	if (model.isArmed() || model.isSelected() && menuItem instanceof JMenu) {
		g.setColor(Colors.MENU_ITEM_BACKGROUND_SELECTED);
		g.fillRect(0, 0, w, h);
	} else if (!(menuItem instanceof JMenu && ((JMenu) menuItem).isTopLevelMenu())) {
		drawMenuItemFading(menuItem, g);
	}
	g.setColor(oldColor);
}
 
Example 7
Source File: BEMenuItemUI.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
{
	// see parent!
	ButtonModel model = menuItem.getModel();
	Color oldColor = g.getColor();
	int menuWidth = menuItem.getWidth();
	int menuHeight = menuItem.getHeight();
	
	Graphics2D g2 = (Graphics2D)g;
	
	if (model.isArmed()
			|| (menuItem instanceof JMenu && model.isSelected()))
	{
		//菜单项的样式绘制(用NinePatch图来填充)
		__Icon9Factory__.getInstance().getBgIcon_ItemSelected()
				.draw(g2, 0, 0, menuWidth, menuHeight);
	}
	else
	{
		if(!enforceTransparent)
		{
			g.setColor(menuItem.getBackground());
			g.fillRect(0, 0, menuWidth, menuHeight);
		}
	}
	g.setColor(oldColor);
}
 
Example 8
Source File: BERadioButtonMenuItemUI.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
     * Draws the background of the menu item.
     * 
     * @param g the paint graphics
     * @param menuItem menu item to be painted
     * @param bgColor selection background color
     * @since 1.4
     */
    protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) 
    {
    	ButtonModel model = menuItem.getModel();
    	Color oldColor = g.getColor();
    	int menuWidth = menuItem.getWidth();
    	int menuHeight = menuItem.getHeight();

    	if(menuItem.isOpaque()) 
    	{
    		if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) 
    		{
    			g.setColor(bgColor);
    			g.fillRect(0,0, menuWidth, menuHeight);
    		} 
    		else 
    		{
    			g.setColor(menuItem.getBackground());
    			g.fillRect(0,0, menuWidth, menuHeight);
    		}
    		g.setColor(oldColor);
    	}
    	else if (model.isArmed() || (menuItem instanceof JMenu &&
    			model.isSelected())) 
    	{
//    		g.setColor(bgColor);
//    		g.fillRect(0,0, menuWidth, menuHeight);
//    		g.setColor(oldColor);
    		
    		//由jb2011改用NinePatch图来填充
			__Icon9Factory__.getInstance().getBgIcon_ItemSelected()
				.draw((Graphics2D)g, 0, 0, menuWidth, menuHeight);
    	}
    }
 
Example 9
Source File: RadioButtonMenuItemIcon.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	JMenuItem b = (JMenuItem) c;
	ButtonModel bm = b.getModel();

	g.translate(x, y);

	boolean isSelected = bm.isSelected();
	boolean isEnabled = bm.isEnabled();
	boolean isPressed = bm.isPressed();

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

	// drawing background section
	if (!isEnabled) {
		g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
	} else {
		if (isPressed) {
			g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
		} else {
			g2.setColor(Colors.RADIOBUTTON_BORDER);
		}
	}
	g2.setStroke(RADIO_STROKE);
	Shape circle = new Ellipse2D.Double(0, 0, 9, 9);
	g2.draw(circle);

	// drawing sphere
	if (isSelected) {
		if (isEnabled) {
			g2.setColor(Colors.RADIOBUTTON_CHECKED);
		} else {
			g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
		}
		circle = new Ellipse2D.Double(3, 3, 4, 4);
		g2.fill(circle);
	}

	g.translate(-x, -y);
}
 
Example 10
Source File: BECheckBoxMenuItemUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
protected  void paintBackground(Graphics g, JMenuItem menuItem, 
            Color bgColor) 
    {
//        if (WindowsMenuItemUI.isVistaPainting()) {
//            WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
//            return;
//        }
//        super.paintBackground(g, menuItem, bgColor);
     // see parent!
		ButtonModel model = menuItem.getModel();
		Color oldColor = g.getColor();
		int menuWidth = menuItem.getWidth();
		int menuHeight = menuItem.getHeight();
		
		Graphics2D g2 = (Graphics2D)g;
		
		if (model.isArmed()
				|| (menuItem instanceof JMenu && model.isSelected()))
		{
			g.setColor(bgColor);
			
			__Icon9Factory__.getInstance().getBgIcon_ItemSelected()
				.draw(g2, 0, 0, menuWidth, menuHeight);
			
//			/****** 选中的背景样式现在是渐变加圆角填充了,impled by js */
//			NLLookAndFeel.setAntiAliasing(g2, true);
//			//矩形填充
//			Paint oldpaint = g2.getPaint();
//			GradientPaint gp = new GradientPaint(0, 0
//					,GraphicHandler.getColor(bgColor, 35, 35, 35)
//					,0, menuHeight,bgColor
//	                );
//			g2.setPaint(gp);
//			g.fillRoundRect(0, 0, menuWidth, menuHeight,5,5);
//			g2.setPaint(oldpaint);
//			NLLookAndFeel.setAntiAliasing(g2, false);
		}
		else
		{
			if(!enforceTransparent)
			{
				g.setColor(menuItem.getBackground());
				g.fillRect(0, 0, menuWidth, menuHeight);
			}
		}
		g.setColor(oldColor);
    }
 
Example 11
Source File: BEMenuUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
     * Method which renders the text of the current menu item.
     * <p>
     * @param g Graphics context
     * @param menuItem Current menu item to render
     * @param textRect Bounding rectangle to render the text.
     * @param text String to render
     * @since 1.4
     */
    protected void paintText(Graphics g, JMenuItem menuItem,
    		Rectangle textRect, String text) 
    {
    	//================= commet by Jack Jiang START
//    	if (WindowsMenuItemUI.isVistaPainting()) {
//    		WindowsMenuItemUI.paintText(accessor, g, menuItem, textRect, text);
//    		return;
//    	}
    	//================= commet by Jack Jiang END
    	JMenu menu = (JMenu)menuItem;
    	ButtonModel model = menuItem.getModel();
    	Color oldColor = g.getColor();

    	// Only paint rollover if no other menu on menubar is selected
    	boolean paintRollover = model.isRollover();
    	if (paintRollover && menu.isTopLevelMenu()) {
    		MenuElement[] menus = ((JMenuBar)menu.getParent()).getSubElements();
    		for (int i = 0; i < menus.length; i++) {
    			if (((JMenuItem)menus[i]).isSelected()) {
    				paintRollover = false;
    				break;
    			}
    		}
    	}

    	if ((model.isSelected() && 
    							(
//    							WindowsLookAndFeel.isClassicWindows() ||
    							!menu.isTopLevelMenu())) 
    			||
    			(
//    					BEXPStyle.getXP() != null && 
    					(paintRollover ||model.isArmed() ||model.isSelected())
    			)
    	) 
    	{
    		g.setColor(selectionForeground); // Uses protected field.
    	}

    	//================= add by Jack Jiang START
    	//特殊处理顶级菜单项(就是直接放在JMenuBar上的那一层),使之在被选中或rover等状态时保持黑色(或其它颜色)
    	//,目的是为了配合整个菜单项的L&F效果,并没有过多的用途,此颜色可提取作为UIManager的自定义属性哦
    	if(menu.isTopLevelMenu())
    		g.setColor(new Color(35,35,35));//用MaxOS X的经典黑
    	//================= add by Jack Jiang END
    	
//    	WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
    	WinUtils.paintText(g, menuItem, textRect, text, 0);
    	
    	g.setColor(oldColor);
    }