本文整理汇总了Java中javax.swing.ButtonModel.isPressed方法的典型用法代码示例。如果您正苦于以下问题:Java ButtonModel.isPressed方法的具体用法?Java ButtonModel.isPressed怎么用?Java ButtonModel.isPressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.ButtonModel
的用法示例。
在下文中一共展示了ButtonModel.isPressed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paint
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* Paints the Button
*
* @param g
* The graphics
* @param c
* The component
*/
@Override
public void paint(final Graphics g, final JComponent c) {
// super.paint(g, c);
final AbstractButton button = (AbstractButton) c;
button.setRolloverEnabled(true);
final ButtonModel model = button.getModel();
final Rectangle bounds = button.getBounds();
if (model.isPressed() && model.isArmed()) {
g.translate(1, 1);
super.paint(g, c);
g.translate(-1, -1);
downBorder.paintBorder(c, g, 0, 0, bounds.width, bounds.height);
} else if (button.isRolloverEnabled() && model.isRollover()) {
super.paint(g, c);
upBorder.paintBorder(c, g, 0, 0, bounds.width, bounds.height);
} else {
super.paint(g, c);
}
}
示例2: paintIcon
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public void paintIcon(Graphics2D g,ButtonInfo info) {
AbstractButton button = info.button;
Icon icon = button.getIcon();
ButtonModel model = button.getModel();
if(model.isRollover() && button.getRolloverIcon()!=null)
icon = button.getRolloverIcon();
if(model.isPressed() && button.getPressedIcon()!=null)
icon = button.getPressedIcon();
if(model.isSelected() && button.getSelectedIcon()!=null)
icon = button.getSelectedIcon();
if(model.isRollover() && model.isSelected() && button.getRolloverSelectedIcon()!=null)
icon = button.getRolloverSelectedIcon();
if(isEnabled(button)==false && button.getDisabledIcon()!=null)
icon = button.getDisabledIcon();
if(isEnabled(button)==false && model.isSelected() && button.getDisabledIcon()!=null)
icon = button.getDisabledSelectedIcon();
if(icon!=null) {
g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT);
icon.paintIcon(button, g, info.iconRect.x, info.iconRect.y);
}
}
示例3: paint
import javax.swing.ButtonModel; //导入方法依赖的package包/类
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);
}
}
示例4: update
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* If the property <code>ToggleButton.gradient</code> is set, then a gradient
* is painted as background, otherwise the normal superclass behaviour is
* called.
*/
public void update(Graphics g, JComponent c)
{
AbstractButton b = (AbstractButton) c;
ButtonModel m = b.getModel();
if (b.getBackground() instanceof UIResource
&& b.isContentAreaFilled()
&& b.isEnabled() && ! m.isArmed() && ! m.isPressed()
&& UIManager.get(getPropertyPrefix() + "gradient") != null)
{
MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(),
SwingConstants.VERTICAL,
getPropertyPrefix() + "gradient");
paint(g, c);
}
else
super.update(g, c);
}
示例5: paintIcon
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* Paint the icon for this component. Depending on the state of the
* component and the availability of the button's various icon
* properties, this might mean painting one of several different icons.
*
* @param g Graphics context to paint with
* @param c Component to paint the icon of
* @param iconRect Rectangle in which the icon should be painted
*/
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect)
{
AbstractButton b = (AbstractButton) c;
Icon i = currentIcon(b);
if (i != null)
{
ButtonModel m = b.getModel();
if (m.isPressed() && m.isArmed())
{
int offs = getTextShiftOffset();
i.paintIcon(c, g, iconRect.x + offs, iconRect.y + offs);
}
else
i.paintIcon(c, g, iconRect.x, iconRect.y);
}
}
示例6: paintBorder
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
/* 305: */ {
/* 306:369 */ AbstractButton b = (AbstractButton)c;
/* 307:370 */ ButtonModel model = b.getModel();
/* 308:372 */ if (!model.isEnabled()) {
/* 309:373 */ return;
/* 310: */ }
/* 311:375 */ if (!(c instanceof JToggleButton))
/* 312: */ {
/* 313:376 */ if ((model.isRollover()) && ((!model.isPressed()) || (model.isArmed()))) {
/* 314:377 */ super.paintBorder(c, g, x, y, w, h);
/* 315: */ }
/* 316:379 */ return;
/* 317: */ }
/* 318:382 */ if (model.isRollover())
/* 319: */ {
/* 320:383 */ if ((model.isPressed()) && (model.isArmed())) {
/* 321:384 */ PlasticXPUtils.drawPressedButtonBorder(g, x, y, w, h);
/* 322: */ } else {
/* 323:386 */ PlasticXPUtils.drawPlainButtonBorder(g, x, y, w, h);
/* 324: */ }
/* 325: */ }
/* 326:388 */ else if (model.isSelected()) {
/* 327:389 */ PlasticXPUtils.drawPressedButtonBorder(g, x, y, w, h);
/* 328: */ }
/* 329: */ }
示例7: drawCheckMark
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* Draws the check in the check box using the appropriate color based on the
* {@link ButtonModel#isPressed} state. Note that part of the check will be drawn outside
* it's bounds. Because this icon is actually being drawn inside a larger component (a
* {@link javax.swing.JCheckBox}), this shouldn't be an issue.
*/
private void drawCheckMark(Graphics2D graphics, ButtonModel model) {
int x1 = CHECK_BOX_SIZE / 4;
int y1 = CHECK_BOX_SIZE / 3;
int x2 = x1 + CHECK_BOX_SIZE / 6;
int y2 = y1 + CHECK_BOX_SIZE / 4;
int x3 = CHECK_BOX_SIZE - 2;
int y3 = -1;
Color color = model.isPressed() ?
HudPaintingUtils.PRESSED_MARK_COLOR : fontColor;
graphics.setStroke(new BasicStroke(1.65f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
graphics.setColor(color);
graphics.drawLine(x1, y1, x2, y2);
graphics.drawLine(x2, y2, x3, y3);
}
示例8: getIcon
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* 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;
}
示例9: paintBorder
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
/* 278: */ {
/* 279:410 */ AbstractButton button = (AbstractButton)c;
/* 280:411 */ ButtonModel model = button.getModel();
/* 281:413 */ if (model.isEnabled())
/* 282: */ {
/* 283:414 */ boolean isPressed = (model.isPressed()) && (model.isArmed());
/* 284:416 */ if (isPressed) {
/* 285:417 */ PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
/* 286: */ } else {
/* 287:419 */ PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
/* 288: */ }
/* 289: */ }
/* 290: */ else
/* 291: */ {
/* 292:421 */ PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
/* 293: */ }
/* 294: */ }
示例10: paintComponent
import javax.swing.ButtonModel; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int h = getHeight();
int w = getWidth();
int height = getHeight();
ButtonModel model = getModel();
if (model.isRollover()) {
glossyColors = ColorUtils.getInStance().getGlossyColor(
rollOverTheme, height, this);
} else {
glossyColors = ColorUtils.getInStance().getGlossyColor(buttonTheme,
height, this);
}
if (model.isSelected() || model.isPressed()) {
glossyColors = ColorUtils.getInStance().getGlossyColor(
selectedTheme, height, this);
}
glossyBgColor = glossyColors[1];
glossyFgColor = glossyColors[0];
drawShape(g2d, w, h);
g2d.dispose();
super.paintComponent(g);
}
示例11: paintBorder
import javax.swing.ButtonModel; //导入方法依赖的package包/类
public void paintBorder(Component c, Graphics g, int x, int y, int width,
int height) {
if (c instanceof AbstractButton) {
AbstractButton b = (AbstractButton)c;
ButtonModel model = b.getModel();
boolean isPressed;
boolean isRollover;
boolean isEnabled;
isPressed = model.isPressed() && model.isArmed();
isRollover = b.isRolloverEnabled() && model.isRollover();
isEnabled = b.isEnabled();
if (!isEnabled) {
paintDisabled(b, g, x, y, width, height);
} else {
if (isPressed) {
paintPressed(b, g, x, y, width, height);
} else if (isRollover) {
paintRollover(b, g, x, y, width, height);
} else {
paintNormal(b, g, x, y, width, height);
}
}
}
}
示例12: getArrowColor
import javax.swing.ButtonModel; //导入方法依赖的package包/类
protected Color getArrowColor(ButtonModel model)
{
if(model.isPressed())
{
return highlight;
}
return normal;
}
示例13: paintIcon
import javax.swing.ButtonModel; //导入方法依赖的package包/类
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);
}
示例14: update
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* If the property <code>Button.gradient</code> is set, then a gradient is
* painted as background, otherwise the normal superclass behaviour is
* called.
*/
public void update(Graphics g, JComponent c)
{
AbstractButton b = (AbstractButton) c;
if ((b.getBackground() instanceof UIResource)
&& b.isContentAreaFilled() && b.isEnabled())
{
ButtonModel m = b.getModel();
String uiKey = "Button.gradient";
if (! isToolbarButton(b))
{
if (! m.isArmed() && ! m.isPressed() && isDrawingGradient(uiKey))
{
MetalUtils.paintGradient(g, 0, 0, b.getWidth(), b.getHeight(),
SwingConstants.VERTICAL,
uiKey);
paint(g, c);
return;
}
}
else if (m.isRollover() && isDrawingGradient(uiKey))
{
MetalUtils.paintGradient(g, 0, 0, b.getWidth(), b.getHeight(),
SwingConstants.VERTICAL,
uiKey);
paint(g, c);
return;
}
}
// Fallback if we didn't have any of the two above cases.
super.update(g, c);
}
示例15: paintBorder
import javax.swing.ButtonModel; //导入方法依赖的package包/类
/**
* Paints the RadioButtonBorder around a given component.
*
* <p>The Sun implementation always seems to draw exactly
* the same border, irrespective of the state of the button.
* This is rather surprising, but GNU Classpath emulates the
* observable behavior.
*
* @param c the component whose border is to be painted.
* @param g the graphics for painting.
* @param x the horizontal position for painting the border.
* @param y the vertical position for painting the border.
* @param width the width of the available area for painting the border.
* @param height the height of the available area for painting the border.
*
* @see javax.swing.plaf.basic.BasicGraphicsUtils#drawBezel
*/
public void paintBorder(Component c, Graphics g,
int x, int y, int width, int height)
{
AbstractButton button = null;
ButtonModel bmodel = null;
boolean lowered = false;
boolean focused = false;
if (c instanceof AbstractButton)
{
button = (AbstractButton) c;
bmodel = button.getModel();
}
if (bmodel != null)
{
lowered = button.isSelected()
|| (/* mouse inside */ bmodel.isArmed() && bmodel.isPressed());
focused = button.hasFocus() && button.isFocusPainted();
}
if (lowered)
BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,
shadow, darkShadow,
highlight, lightHighlight);
else
BasicGraphicsUtils.drawBezel(g, x, y, width, height,
/* isPressed */ false,
/* isPefault */ focused,
shadow, darkShadow,
highlight, lightHighlight);
}