Java Code Examples for javax.swing.AbstractButton#hasFocus()
The following examples show how to use
javax.swing.AbstractButton#hasFocus() .
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: RapidLookTools.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * 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); }
Example 2
Source File: BasicLinkButtonUI.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
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); }
Example 3
Source File: ToggleButtonUI.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@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)); } } }