javax.swing.ButtonModel#isSelected ( )源码实例Demo

下面列出了javax.swing.ButtonModel#isSelected ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlatLaf   文件: FlatToggleButtonUI.java
@Override
protected Color getBackground( JComponent c ) {
	ButtonModel model = ((AbstractButton)c).getModel();

	if( model.isSelected() ) {
		// in toolbar use same colors for disabled and enabled because
		// we assume that toolbar icon is shown disabled
		boolean toolBarButton = isToolBarButton( c );
		return buttonStateColor( c,
			toolBarButton ? toolbarSelectedBackground : selectedBackground,
			toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
			null, null,
			toolBarButton ? toolbarPressedBackground : pressedBackground );
	}

	return super.getBackground( c );
}
 
源代码2 项目: littleluck   文件: LuckArrowIcon.java
public Image getPreImg(Component c, ButtonModel model)
{
    JMenu menu = (JMenu) c;

    if (menu.getItemCount() > 0)
    {
        if (model.isSelected())
        {
            return getRollverImg();
        }
        else
        {
            return getNormalImg();
        }
    }

    return null;
}
 
源代码3 项目: FlatLaf   文件: FlatMenuUI.java
@Override
protected void paintBackground( Graphics g, Color selectionBackground ) {
	ButtonModel model = menuItem.getModel();
	if( model.isRollover() && !model.isArmed() && !model.isSelected() &&
		model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() )
	{
		g.setColor( deriveBackground( hoverBackground ) );
		g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() );
	} else
		super.paintBackground( g, selectionBackground );
}
 
源代码4 项目: xdm   文件: XDMMenuItemUI.java
@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);
}
 
源代码5 项目: open-ig   文件: ConfigButton.java
@Override
public void paint(Graphics g) {
	Graphics2D g2 = (Graphics2D)g;
	g2.setFont(getFont());
	FontMetrics fm = g2.getFontMetrics();
	
	ButtonModel mdl = getModel();
	String s = getText();
	
	g2.setComposite(AlphaComposite.SrcOver.derive(0.85f));
	if (!mdl.isEnabled()) {
		g2.setColor(new Color(0x808080));
		g2.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
		g2.setColor(new Color(0x000000));
	} else
	if (mdl.isPressed() || mdl.isSelected()) {
		if (mdl.isRollover()) {
			g2.setColor(new Color(0xE0E0E0));
		} else {
			g2.setColor(new Color(0xFFFFFF));
		}
		g2.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
		g2.setColor(new Color(0x000000));
	} else {
		if (mdl.isRollover()) {
			g2.setColor(new Color(0x000000));
		} else {
			g2.setColor(new Color(0x202020));
		}
		g2.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
		g2.setColor(new Color(0xFFFFFFFF));
	}
	int x = (getWidth() - fm.stringWidth(s)) / 2;
	int y = (getHeight() - fm.getHeight()) / 2 + fm.getAscent() + fm.getLeading();
	g2.drawString(s, x, y);
}
 
源代码6 项目: netbeans   文件: StoreGroup.java
/** Stores all models created in the StoreGroup into given
 * EditableProperties.
 * @param editableProperties The properties where to store the
 *        values.
 */
public void store( EditableProperties editableProperties ) {
    for (Map.Entry<String,Object[]> entry : models.entrySet()) {
        String key = entry.getKey();
        Object[] params = entry.getValue();

        if ( params[0] instanceof ButtonModel ) {
            ButtonModel model = (ButtonModel)params[0];
            boolean value = model.isSelected();
            if ( params[2] == Boolean.TRUE ) {
                value = !value;
            }
            editableProperties.setProperty( key, encodeBoolean( value, (Integer)params[1] ) );
        }
        else if ( params[0] instanceof Document && modifiedDocuments.contains(params[0])) {
            Document doc = (Document)params[0];
            String txt;
            try {
                txt = doc.getText(0, doc.getLength());
            } catch (BadLocationException e) {
                txt = ""; // NOI18N
            }                    
            editableProperties.setProperty( key, txt );
        }

    }

}
 
源代码7 项目: snap-desktop   文件: TransferMaskDialog.java
private static Product[] getSelectedProducts(Map<Product, ButtonModel> buttonMap) {
    List<Product> selectedProducts = new ArrayList<Product>(buttonMap.size());
    for (Map.Entry<Product, ButtonModel> entry : buttonMap.entrySet()) {
        Product product = entry.getKey();
        ButtonModel buttonModel = entry.getValue();
        if (buttonModel.isSelected()) {
            selectedProducts.add(product);
        }
    }
    return selectedProducts.toArray(new Product[selectedProducts.size()]);
}
 
源代码8 项目: beautyeye   文件: BEToggleButtonUI.java
/**
     * As of Java 2 platform v 1.4 this method should not be used or overriden.
     * Use the paintText method which takes the AbstractButton argument.
     *
     * @param g the g
     * @param c the c
     * @param textRect the text rect
     * @param text the text
     */
    protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    	AbstractButton b = (AbstractButton) c;                       
    	ButtonModel model = b.getModel();
    	FontMetrics fm = //SwingUtilities2
    					MySwingUtilities2.getFontMetrics(c, g);
    	int mnemonicIndex = b.getDisplayedMnemonicIndex();

    	/* Draw the Text */
    	if(model.isEnabled()) 
    	{
    		//=================== modified by jb2011 START
    		if(model.isSelected())//选中时使用不同的颜色
    			g.setColor(UIManager.getColor(getPropertyPrefix()+"focus"));
    		else
    			/*** paint the text normally */
    			g.setColor(b.getForeground());
    		//=================== modified by jb2011 END
    		
//    		SwingUtilities2 *不要直接调用该类(因为它是sun未公开api,1.5里与1.6及以后版它放在不同的包里,某天它会消失也说不好)
    		MySwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
    				textRect.x + getTextShiftOffset(),
    				textRect.y + fm.getAscent() + getTextShiftOffset());
    	}
    	else 
    	{
    		/*** paint the text disabled ***/
    		g.setColor(b.getBackground().brighter());
    		//SwingUtilities2 *不要直接调用该类(因为它是sun未公开api,1.5里与1.6及以后版它放在不同的包里,某天它会消失也说不好)
    		MySwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
    				textRect.x, textRect.y + fm.getAscent());
    		g.setColor(b.getBackground().darker());
    		//SwingUtilities2 *不要直接调用该类(因为它是sun未公开api,1.5里与1.6及以后版它放在不同的包里,某天它会消失也说不好)
    		MySwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
    				textRect.x - 1, textRect.y + fm.getAscent() - 1);
    	}
    }
 
源代码9 项目: beautyeye   文件: BERadioButtonMenuItemUI.java
/**
     * 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);
    	}
    }
 
源代码10 项目: beautyeye   文件: __UI__.java
public void paintIcon(Component c, Graphics g, int x, int y) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	//选中时
	if(model.isSelected())
	{
		//处于禁用状态
		if(!model.isEnabled())
			g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_disable().getImage(), x, y, null);
		else
		{
			//处于被按住状态
			if(model.isPressed())
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_pressed().getImage(), x, y, null);
			else
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_normal().getImage(), x, y, null);
		}
	}
	//未选中时
	else
	{
		//处于禁用状态
		if(!model.isEnabled())
			g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_unchecked_disable().getImage(), x, y, null);
		else
		{
			//处于被按住状态
			if(model.isPressed())
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_unchecked_pressed().getImage(), x, y, null);
			else
				g.drawImage(__IconFactory__.getInstance().getRadioButtonIcon_unchecked_normal().getImage(), x, y, null);
		}
	}
}
 
源代码11 项目: littleluck   文件: LuckRadioIcon.java
public void paintIcon(Component c, Graphics g, int x, int y)
{
    AbstractButton cb = (AbstractButton) c;

    ButtonModel model = cb.getModel();

    boolean isPressed = (model.isArmed() && model.isPressed());

    boolean isRollver = (model.isRollover() && cb.isRolloverEnabled());

    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    drawOval(g2d, x, y, (isRollver || isPressed));

    if(model.isSelected())
    {
        fillOval(g2d, x, y);
    }
    else if(isRollver && isPressed)
    {
        drawOvalShadow(g2d, x, y);
    }

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
 
源代码12 项目: seaglass   文件: SeaGlassButtonUI.java
/**
 * DOCUMENT ME!
 *
 * @param  b           DOCUMENT ME!
 * @param  defaultIcon DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private Icon getSynthDisabledIcon(AbstractButton b, Icon defaultIcon) {
    ButtonModel model = b.getModel();
    Icon        icon;

    if (model.isSelected()) {
        icon = getIcon(b, b.getDisabledSelectedIcon(), defaultIcon, SynthConstants.DISABLED | SynthConstants.SELECTED);
    } else {
        icon = getIcon(b, b.getDisabledIcon(), defaultIcon, SynthConstants.DISABLED);
    }

    return icon;
}
 
源代码13 项目: rapidminer-studio   文件: MenuUI.java
@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);
}
 
源代码14 项目: rapidminer-studio   文件: RadioButtonIcon.java
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	JRadioButton radioButton = (JRadioButton) c;
	ButtonModel bm = radioButton.getModel();
	int w = c.getWidth();
	int h = c.getHeight();
	if (h < 0 || w < 0) {
		return;
	}

	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_BACKGROUND_DISABLED);
	} else {
		g2.setColor(Colors.RADIOBUTTON_BACKGROUND);
	}
	Shape circle = new Ellipse2D.Double(2, 2, 12, 12);
	g2.fill(circle);

	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);
	circle = new Ellipse2D.Double(1, 1, 14, 14);
	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(4, 4, 9, 9);
		g2.fill(circle);
	}

	g.translate(-x, -y);
}
 
源代码15 项目: openjdk-jdk9   文件: ButtonDemoTest.java
private static String toString(ButtonModel model) {
    return "isArmed = " + model.isArmed()
            + ", isEnabled = " + model.isEnabled()
            + ", isPressed = " + model.isPressed()
            + ", isSelected = " + model.isSelected();
}
 
源代码16 项目: rapidminer-studio   文件: CheckBoxIcon.java
void paintInternally(Component c, Graphics g, int x, int y, ButtonModel bm) {
	boolean isSelected = bm.isSelected();
	boolean isEnabled = bm.isEnabled();
	boolean isPressed = bm.isPressed();

	int w = c.getWidth();
	int h = c.getHeight();
	if (h < 0 || w < 0) {
		return;
	}

	g.translate(x, y);

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

	// drawing outer
	if (!isEnabled) {
		g2.setColor(Colors.CHECKBOX_BORDER_DISABLED);
	} else {
		if (isPressed) {
			g2.setColor(Colors.CHECKBOX_BORDER_FOCUS);
		} else {
			g2.setColor(Colors.CHECKBOX_BORDER);
		}
	}
	g2.drawRect(1, 1, 13, 13);

	// drawing background section
	if (!isEnabled) {
		g.setColor(Colors.CHECKBOX_BACKGROUND_DISABLED);
	} else {
		g2.setColor(Colors.CHECKBOX_BACKGROUND);
	}
	g2.fillRect(2, 2, 12, 12);

	// draw check mark
	if (isSelected) {
		g2.translate(2, 3);
		g2.setStroke(CHECKBOX_STROKE);
		if (isEnabled) {
			g2.setColor(Colors.CHECKBOX_CHECKED);
		} else {
			g2.setColor(Colors.CHECKBOX_CHECKED_DISABLED);
		}
		g2.drawLine(2, 6, 5, 8);
		g2.drawLine(5, 8, 9, 1);
		g2.translate(-2, -3);
	}

	g.translate(-x, -y);
}
 
源代码17 项目: littleluck   文件: LuckRadioIcon.java
public void paintIcon(Component c, Graphics g, int x, int y)
{
    AbstractButton cb = (AbstractButton) c;

    ButtonModel model = cb.getModel();

    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    y = y + 2;

    drawOval(g2d, x, y, model.isArmed());

    if(model.isSelected())
    {
        fillOval(g2d, x, y, model.isArmed());
    }

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
 
源代码18 项目: beautyeye   文件: BEMenuUI.java
/**
     * 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);
    }
 
@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);
}
 
源代码20 项目: seaglass   文件: SeaGlassButtonUI.java
/**
 * Returns the current state of the passed in <code>AbstractButton</code>.
 *
 * @param  c the button component.
 *
 * @return the button's state.
 */
private int getComponentState(JComponent c) {
    int state = ENABLED;

    if (!c.isEnabled()) {
        state = DISABLED;
    }

    if (SeaGlassLookAndFeel.selectedUI == this) {
        return SeaGlassLookAndFeel.selectedUIState | SynthConstants.ENABLED;
    }

    AbstractButton button = (AbstractButton) c;
    ButtonModel    model  = button.getModel();

    if (model.isPressed()) {
        if (model.isArmed()) {
            state = PRESSED;
        } else {
            state = MOUSE_OVER;
        }
    }

    if (model.isRollover()) {
        state |= MOUSE_OVER;
    }

    if (model.isSelected()) {
        state |= SELECTED;
    }

    if (c.isFocusOwner() && button.isFocusPainted()) {
        state |= FOCUSED;
    }

    if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
        state |= DEFAULT;
    }
    
    return state;
}