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

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

源代码1 项目: rapidminer-studio   文件: RapidLookTools.java
/**
 * Draws the given button border with the specified shape.
 *
 * @param b
 * @param g
 * @param shape
 */
public static void drawButtonBorder(AbstractButton b, Graphics g, Shape shape) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	boolean darkBorder = Boolean.parseBoolean(String.valueOf(b.getClientProperty(RapidLookTools.PROPERTY_BUTTON_DARK_BORDER)));
	if (darkBorder) {
		if (b.isEnabled()) {
			if (b.hasFocus()) {
				g2.setColor(Colors.BUTTON_BORDER_DARK_FOCUS);
			} else {
				g2.setColor(Colors.BUTTON_BORDER_DARK);
			}
		} else {
			g2.setColor(Colors.BUTTON_BORDER_DARK_DISABLED);
		}
	} else {
		if (b.isEnabled()) {
			if (b.hasFocus()) {
				g2.setColor(Colors.BUTTON_BORDER_FOCUS);
			} else {
				g2.setColor(Colors.BUTTON_BORDER);
			}
		} else {
			g2.setColor(Colors.BUTTON_BORDER_DISABLED);
		}
	}


	g2.draw(shape);
}
 
源代码2 项目: orbit-image-analysis   文件: BasicLinkButtonUI.java
public void paint(Graphics g, JComponent c) {
  AbstractButton b = (AbstractButton)c;
  ButtonModel model = b.getModel();

  FontMetrics fm = g.getFontMetrics();

  Insets i = c.getInsets();

  viewRect.x = i.left;
  viewRect.y = i.top;
  viewRect.width = b.getWidth() - (i.right + viewRect.x);
  viewRect.height = b.getHeight() - (i.bottom + viewRect.y);

  textRect.x = textRect.y = textRect.width = textRect.height = 0;
  iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

  Font f = c.getFont();
  g.setFont(f);

  // layout the text and icon
  String text =
    SwingUtilities.layoutCompoundLabel(
      c,
      fm,
      b.getText(),
      b.getIcon(),
      b.getVerticalAlignment(),
      b.getHorizontalAlignment(),
      b.getVerticalTextPosition(),
      b.getHorizontalTextPosition(),
      viewRect,
      iconRect,
      textRect,
      b.getText() == null ? 0 : b.getIconTextGap());

  clearTextShiftOffset();

  // perform UI specific press action, e.g. Windows L&F shifts text
  if (model.isArmed() && model.isPressed()) {
    paintButtonPressed(g, b);
  }

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

  Composite oldComposite = ((Graphics2D)g).getComposite();

  if (model.isRollover()) {
    ((Graphics2D)g).setComposite(
      AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
  }

  if (text != null && !text.equals("")) {
    View v = (View)c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
      textRect.x += getTextShiftOffset();
      textRect.y += getTextShiftOffset();
      v.paint(g, textRect);
      textRect.x -= getTextShiftOffset();
      textRect.y -= getTextShiftOffset();
    } else {
      paintText(g, b, textRect, text);
    }
  }

  if (b.isFocusPainted() && b.hasFocus()) {
    // paint UI specific focus
    paintFocus(g, b, viewRect, textRect, iconRect);
  }

  ((Graphics2D)g).setComposite(oldComposite);
}
 
源代码3 项目: rapidminer-studio   文件: ToggleButtonUI.java
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;

	Dimension size = b.getSize();
	FontMetrics fm = g.getFontMetrics();

	Insets i = c.getInsets();

	Rectangle viewRect = new Rectangle(size);

	viewRect.x += i.left;
	viewRect.y += i.top;
	viewRect.width -= i.right + viewRect.x;
	viewRect.height -= i.bottom + viewRect.y;

	Rectangle iconRect = new Rectangle();
	Rectangle textRect = new Rectangle();

	Font f = c.getFont();
	g.setFont(f);

	String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(),
			b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect,
			textRect, b.getText() == null ? 0 : b.getIconTextGap());

	g.setColor(b.getBackground());

	if (b.isContentAreaFilled()) {
		if (RapidLookTools.isToolbarButton(b)) {
			RapidLookTools.drawToolbarButton(g, b);
		} else {
			RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
		}
	}

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

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

	if (b.isFocusPainted() && b.hasFocus()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
	}

	if (!RapidLookTools.isToolbarButton(b)) {
		if (b.isBorderPainted()) {
			RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
		}
	}
}