Java Code Examples for javax.swing.AbstractButton#isRolloverEnabled()

The following examples show how to use javax.swing.AbstractButton#isRolloverEnabled() . 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: FreeColButtonUI.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {
    LAFUtilities.setProperties(g, c);

    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColButton",
                                    g, c, null);
    }
    super.paint(g, c);

    AbstractButton a = (AbstractButton) c;
    if (a.isRolloverEnabled()) {
        Point p = MouseInfo.getPointerInfo().getLocation();
        SwingUtilities.convertPointFromScreen(p, c);
        boolean rollover = c.contains(p);
        if (rollover) {
            paintButtonPressed(g, (AbstractButton) c);
        }
    }
}
 
Example 2
Source File: RapidLookTools.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Drasw a button in a toolbar.
 *
 * @param b
 *            the button
 * @param g
 *            the graphics instance
 */
public static void drawToolbarButton(Graphics g, AbstractButton b) {
	if (!b.isEnabled()) {
		return;
	}

	if (b.getModel().isSelected() && b.isRolloverEnabled() || b.getModel().isPressed() && b.getModel().isArmed()
			&& b.isRolloverEnabled()) {
		if (b.isContentAreaFilled()) {
			drawButton(b, g, createShapeForButton(b));
		}
		if (b.isBorderPainted()) {
			drawButtonBorder(b, g, createBorderShapeForButton(b));
		}
	} else if (b.getModel().isRollover() && b.isRolloverEnabled()) {
		if (b.isBorderPainted()) {
			drawButtonBorder(b, g, createBorderShapeForButton(b));
		}
	}
}
 
Example 3
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: ButtonBorder.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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);
      }
    }
  }
}
 
Example 5
Source File: LuckRadioIcon.java    From littleluck with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: LuckButtonUI.java    From littleluck with Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 绘制圆角背景, 设置组件偏移实现按钮按下和弹起效果。
 * -------------------------------------------------------------------------------------------------
 * Draw a rounded background.
 * set the component offset to achieve the button press and pop-up effect.
 * </pre>
 *
 * @param g Graphics to paint to
 * @param b AbstractButton painting on
 * @return paint background return true, otherwise return false.
 */
protected void paintBg(Graphics g, AbstractButton b)
{
    if(!checkIsPaintBg(b))
    {
        return;
    }

    int w = b.getWidth();

    int h = b.getHeight();

    Graphics2D g2d = (Graphics2D)g;

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

    if(b.getModel().isPressed() && b.getModel().isArmed())
    {
        // 点击按钮
        // pressed button
        g2d.setColor(btnColorInfo.getPressedColor());
    }
    else if(b.getModel().isRollover() && b.isRolloverEnabled())
    {
        // 鼠标经过
        // mouse enter button
        g2d.setColor(btnColorInfo.getRollverColor());
    }
    else
    {
        g2d.setColor(btnColorInfo.getNormalColor());
    }

    g2d.fillRoundRect(0, 0, w, h, 8, 8);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
 
Example 7
Source File: ButtonBorder.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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);
      }
    }
  }
}
 
Example 8
Source File: NavlinkUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example 9
Source File: ButtonUI.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
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);
		}
	}

}