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

The following examples show how to use javax.swing.JMenuItem#getWidth() . 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: SeaGlassRadioButtonMenuItemUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) {
    Point p = e.getPoint();
    if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
        if (e.getID() == MouseEvent.MOUSE_RELEASED) {
            manager.clearSelectedPath();
            item.doClick(0);
            item.setArmed(false);
        } else
            manager.setSelectedPath(path);
    } else if (item.getModel().isArmed()) {
        MenuElement newPath[] = new MenuElement[path.length - 1];
        int i, c;
        for (i = 0, c = path.length - 1; i < c; i++)
            newPath[i] = path[i];
        manager.setSelectedPath(newPath);
    }
}
 
Example 2
Source File: SeaGlassCheckBoxMenuItemUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) {
    Point p = e.getPoint();
    if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
        if (e.getID() == MouseEvent.MOUSE_RELEASED) {
            manager.clearSelectedPath();
            item.doClick(0);
        } else {
            manager.setSelectedPath(path);
        }
    } else if (item.getModel().isArmed()) {
        int c = path.length - 1;
        MenuElement newPath[] = new MenuElement[c];
        for (int i = 0; i < c; i++) {
            newPath[i] = path[i];
        }
        manager.setSelectedPath(newPath);
    }
}
 
Example 3
Source File: SeaGlassGraphicsUtils.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public static void paint(SynthContext context, SynthContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon,
    String acceleratorDelimiter, int defaultTextIconGap, String propertyPrefix) {
    JMenuItem mi = (JMenuItem) context.getComponent();
    SynthStyle style = context.getStyle();
    g.setFont(style.getFont(context));

    Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight());
    boolean leftToRight = SeaGlassLookAndFeel.isLeftToRight(mi);
    applyInsets(viewRect, mi.getInsets(), leftToRight);

    SeaGlassMenuItemLayoutHelper lh = new SeaGlassMenuItemLayoutHelper(context, accContext, mi, checkIcon, arrowIcon, viewRect,
        defaultTextIconGap, acceleratorDelimiter, leftToRight, MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix);
    MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();

    paintMenuItem(g, lh, lr);
}
 
Example 4
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 5
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 6
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 7
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 8
Source File: DropTargetLayer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void drawSubselectedItem(Graphics2D g2, JMenuItem item) {
    Point location = SwingUtilities.convertPoint(item, new java.awt.Point(0, 0), this);
    g2.translate(location.x, location.y);

    int iconGap = item.getIconTextGap();
    int iconLeft = getIconLeft(item);
    int iconWidth = getIconWidth(item);
    int iconHeight = getIconHeight(item);
    int iconTop = (item.getHeight() - iconHeight) / 2;
    int accelWidth = getAcceleratorWidth(item);

    int textWidth = item.getWidth() - iconLeft - iconWidth - iconGap - accelWidth;
    int accelLeft = item.getWidth() - accelWidth;

    // draw bounding boxes
    g2.setColor(Color.LIGHT_GRAY);
    //g2.drawRect(iconLeft, 0, iconWidth-1, item.getHeight()-1);
    //g2.drawRect(textLeft, 0, textWidth-1, item.getHeight()-1);
    //draw the accelerator areaa
    //g2.drawRect(accelLeft, 0, accelWidth - 1, item.getHeight() - 1);

    // draw the selection rectangles
    g2.setStroke(SELECTION_STROKE);
    g2.setColor(SELECTION_COLOR);
    switch (canvas.getCurrentSelectedPortion()) {
        case Icon:
            {
                if (item.getIcon() != null) {
                    g2.drawRect(iconLeft - 1, iconTop - 1, iconWidth + 1, iconHeight + 1);
                }
                break;
            }
        case Text:
            {
                g2.drawRect(iconLeft + iconWidth + iconGap - 1, -1, textWidth + 1, item.getHeight() + 1);
                break;
            }
        case Accelerator:
            {
                if (item instanceof javax.swing.JMenu) {
                    break;
                }
                g2.drawRect(accelLeft - 1, -1, accelWidth + 1, item.getHeight() + 1);
                break;
            }
        case All:
            {
                g2.drawRect(0, 0, item.getWidth() - 1, item.getHeight() - 1);
            }
    }
    g2.translate(-location.x, -location.y);
}
 
Example 9
Source File: DropTargetLayer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static int getAcceleratorLeft(JMenuItem item) {
    return item.getWidth() - getAcceleratorWidth(item);
}
 
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);
    }