javax.swing.AbstractButton#getModel ( )源码实例Demo

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

源代码1 项目: xdm   文件: XDMButtonUI.java
public void paint(Graphics g, JComponent c) {
	try {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		
		AbstractButton b = (AbstractButton) c;
		ButtonModel bm = b.getModel();
		if (bm.isRollover()) {
			paintButtonRollOver(g2, b);
		} else {
			paintButtonNormal(g2, b);
		}
		super.paint(g2, c);
	} catch (Exception e) {
	}
}
 
源代码2 项目: littleluck   文件: LuckButtonUI.java
public void paint(Graphics g, JComponent c)
{
    AbstractButton b = (AbstractButton) c;

    ButtonModel model = b.getModel();

    paintBg(g, (AbstractButton) c);

    // 设置组件偏移,以达到视觉上的按下和弹起效果
    // Set the component offsets to achieve visual depress and bounce
    if(model.isPressed() && model.isArmed() && b.getIcon() == null)
    {
        g.translate(2, 1);
    }

    super.paint(g, c);

    if(model.isPressed() && model.isArmed() && b.getIcon() == null)
    {
        g.translate(-2, -1);
    }
}
 
源代码3 项目: rapidminer-studio   文件: CheckBoxMenuItemIcon.java
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	g.translate(x, y);

	boolean isSelected = model.isSelected();
	boolean isEnabled = model.isEnabled();

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

	// draw check mark
	if (isSelected) {
		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);
	}
	g.translate(-x, -y);
}
 
源代码4 项目: beautyeye   文件: BECheckBoxMenuItemUI.java
public void paintIcon(Component c, Graphics g, int x, int y) 
    	{
    		AbstractButton b = (AbstractButton) c;
    		ButtonModel model = b.getModel();
    		
    		Image selectedImg = __IconFactory__.getInstance().getCheckboxMenuItemSelectedNormalIcon().getImage();
    		boolean isSelected = model.isSelected();
//    		boolean isArmed = model.isArmed();
    		if (isSelected) 
    		{
//    			if(isArmed)
//    				selectedImg = __IconFactory__.getInstance().getCheckboxMenuItemSelectedRoverIcon().getImage();
    		}
    		else
    			selectedImg = __IconFactory__.getInstance().getCheckboxMenuItemNoneIcon().getImage();

    		g.drawImage(selectedImg
    				, x+(usedForVista?5:-4)//* 注意:当用于windows平台专用主类且处于Vista及更高版win时要做不一样的处理哦
    				, y - 3
    				, null);
    	}
 
源代码5 项目: seaglass   文件: SeaGlassButtonUI.java
/**
 * Returns the Icon to use in painting the button.
 *
 * @param  b the button.
 *
 * @return the icon.
 */
protected Icon getIcon(AbstractButton b) {
    Icon        icon  = b.getIcon();
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
        icon = getSynthDisabledIcon(b, icon);
    } else if (model.isPressed() && model.isArmed()) {
        icon = getPressedIcon(b, getSelectedIcon(b, icon));
    } else if (b.isRolloverEnabled() && model.isRollover()) {
        icon = getRolloverIcon(b, getSelectedIcon(b, icon));
    } else if (model.isSelected()) {
        icon = getSelectedIcon(b, icon);
    } else {
        icon = getEnabledIcon(b, icon);
    }

    if (icon == null) {
        return getDefaultIcon(b);
    }

    return icon;
}
 
源代码6 项目: xdm   文件: XDMToolBarButtonUI.java
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel bm = b.getModel();
	if (bm.isRollover()) {
		paintButtonRollOver(g, b);
	} else {
		paintButtonNormal(g, b);
	}
	super.paint(g, c);
}
 
源代码7 项目: netbeans   文件: FlatSlidingButtonUI.java
@Override
protected void paintButtonPressed(Graphics g, AbstractButton b) {
    if (((SlidingButton) b).isBlinkState()) {
        // background already painted
        return;
    }

    ButtonModel bm = b.getModel();
    g.setColor(bm.isPressed() || bm.isArmed() || bm.isSelected() ? selectedBackground : hoverBackground);
    g.fillRect(0, 0, b.getWidth(), b.getHeight());
}
 
源代码8 项目: MikuMikuStudio   文件: ToggleButtonGroup.java
public void remove(AbstractButton b) {
    if (b == null) {
        return;
    }
    buttons.removeElement(b);
    if (b.getModel() == modifiedSelection) {
        modifiedSelection = null;
    }
    b.getModel().setGroup(null);
}
 
源代码9 项目: RipplePower   文件: NavlinkUI.java
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	String text = layout(b, g.getFontMetrics(), b.getWidth(), b.getHeight());

	clearTextShiftOffset();

	if (model.isArmed() && model.isPressed()) {
		paintButtonPressed(g, b);
	} else if (b.isRolloverEnabled() && model.isRollover()) {
		paintButtonPressed(g, b);
	}

	if (b.getIcon() != null) {
		paintIcon(g, c, iconRect);
	}

	if (b.isFocusPainted() && b.isFocusOwner()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
		if (iconRect != null && iconRect.width > 0 && iconRect.height > 0) {
			if (b.getIcon() != null) {
				paintIcon(g, c, iconRect);
			}
		}
	}

	if (text != null && !text.equals("")) {
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g2, textRect);
		} else {
			paintText(g2, b, textRect, text);
		}
	}
}
 
源代码10 项目: 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);
}
 
源代码11 项目: littleluck   文件: LuckCheckboxIcon.java
public void paintIcon(Component c, Graphics g, int x, int y)
{
    AbstractButton btn = (AbstractButton) c;

    ButtonModel model = btn.getModel();

    Image image = getPreImg(c, model);

    if (image != null)
    {
        g.drawImage(image, x, y, getIconWidth(), getIconHeight(), null);
    }
}
 
源代码12 项目: RipplePower   文件: ButtonUI.java
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();
	FontMetrics fm = g.getFontMetrics();
	int mnemIndex = b.getDisplayedMnemonicIndex();
	if (model.isEnabled()) {
		g.setColor(b.getForeground());
	} else {
		g.setColor(getDisabledTextColor());
	}
	BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
 
源代码13 项目: 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);
		}
	}
}
 
源代码14 项目: RipplePower   文件: NavlinkUI.java
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();
	FontMetrics fm = g.getFontMetrics();
	int mnemIndex = b.getDisplayedMnemonicIndex();

	if (model.isEnabled()) {
		g.setColor(b.getForeground());
	} else {
		g.setColor(getDisabledTextColor());
	}
	BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
 
源代码15 项目: 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;
}
 
源代码16 项目: RipplePower   文件: ButtonUI.java
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	String text = layout(b, g.getFontMetrics(), b.getWidth(), b.getHeight());

	clearTextShiftOffset();

	if (!model.isArmed() && !model.isPressed()) {
		paintButtonBackground(g, b);
	}

	if (model.isArmed() && model.isPressed()) {
		paintButtonPressed(g, b);
	} else if (b.isRolloverEnabled() && model.isRollover()) {
		paintButtonPressed(g, b);
	}

	if (b.getIcon() != null) {
		paintIcon(g, c, iconRect);
	}

	if (b.isFocusPainted() && b.isFocusOwner()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
		if (iconRect != null && iconRect.width > 0 && iconRect.height > 0) {
			if (b.getIcon() != null) {
				paintIcon(g, c, iconRect);
			}
		}
	}

	if (text != null && !text.equals("")) {
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g2, textRect);
		} else {
			paintText(g2, b, textRect, text);
		}
	}

}
 
源代码17 项目: settlers-remake   文件: ButtonUiStone.java
@Override
public void paint(Graphics g1, JComponent c) {
	Graphics2D g = DrawHelper.enableAntialiasing(g1);

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

	boolean down;
	if (c instanceof JToggleButton) {
		down = ((JToggleButton) c).isSelected();
	} else {
		down = model.isArmed() && model.isPressed();
	}

	BufferedImage bg;
	BufferedImage[] border;
	float scale = this.scale;

	if (down) {
		border = BORDER_DOWN;
		scale /= 2;
		bg = backgroundImagePressed;
	} else {
		bg = backgroundImage;
		border = BORDER_NORMAL;
	}

	// Draw background
	g.drawImage(bg, 0, 0, c);

	BorderHelper.drawBorder(g1, c, border, scale);

	FontMetrics fm = g.getFontMetrics();
	int y = (b.getHeight() - fm.getAscent() - fm.getDescent()) / 2 + fm.getAscent();
	int x = textPaddingLeftRight;

	if (down) {
		x += 1;
		y += 1;
	}

	g.setFont(c.getFont());

	// draw shadow
	g.setColor(Color.BLACK);
	g.drawString(b.getText(), x + 1, y + 1);
	g.setColor(c.getForeground());
	g.drawString(b.getText(), x, y);
}
 
源代码18 项目: 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);
}
 
源代码19 项目: beautyeye   文件: WinUtils.java
/**
	 * Paint classic text.
	 *
	 * @param b the b
	 * @param g the g
	 * @param x the x
	 * @param y the y
	 * @param text the text
	 * @param mnemIndex the mnem index
	 */
	static void paintClassicText(AbstractButton b, Graphics g, int x, int y,
			String text, int mnemIndex) {
		ButtonModel model = b.getModel();

		/* Draw the Text */
		Color color = b.getForeground();
		if(model.isEnabled()) {
			/*** paint the text normally */
			if(!(b instanceof JMenuItem && model.isArmed()) 
					&& !(b instanceof JMenu && (model.isSelected() || model.isRollover()))) {
				/* We shall not set foreground color for selected menu or
				 * armed menuitem. Foreground must be set in appropriate
				 * Windows* class because these colors passes from
				 * BasicMenuItemUI as protected fields and we can't
				 * reach them from this class */
				g.setColor(b.getForeground());
			}
//			SwingUtilities2.drawStringUnderlineCharAt(b, g,text, mnemIndex, x, y);
			MySwingUtilities2.drawStringUnderlineCharAt(b
					, g,text, mnemIndex, x, y);//* modified by Jack Jiang 为了非公开api的兼容性
		} else {	/*** paint the text disabled ***/
			color        = UIManager.getColor("Button.shadow");
			Color shadow = UIManager.getColor("Button.disabledShadow");
			if(model.isArmed()) {
				color = UIManager.getColor("Button.disabledForeground");
			} else {
				if (shadow == null) {
					shadow = b.getBackground().darker();
				}
				g.setColor(shadow);
//				SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex,
//						x + 1, y + 1);
				MySwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex,
						x + 1, y + 1);//* modified by Jack Jiang 为了非公开api的兼容性
			}
			if (color == null) {
				color = b.getBackground().brighter();
			}
			g.setColor(color);
//			SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
			MySwingUtilities2.drawStringUnderlineCharAt(
					b, g, text, mnemIndex, x, y);//* modified by Jack Jiang 为了非公开api的兼容性
			
		}
	}
 
源代码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;
}