/** * As of Java 2 platform v 1.4 this method should not be used or overriden. Use the paintText * method which takes the AbstractButton argument. */ protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); int mnemonicIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */ if (model.isEnabled()) { /** * paint the text normally */ g.setColor(b.getForeground()); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); } else { /** * paint the text disabled ** */ g.setColor(b.getBackground().brighter()); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent()); g.setColor(b.getBackground().darker()); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } }
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Icon icon = b.getIcon(); Icon tmpIcon = null; if (icon == null) { return; } Icon selectedIcon = null; /* the fallback icon should be based on the selected state */ if (model.isSelected()) { selectedIcon = (Icon) b.getSelectedIcon(); if (selectedIcon != null) { icon = selectedIcon; } } if (!model.isEnabled()) { if (model.isSelected()) { tmpIcon = (Icon) b.getDisabledSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { tmpIcon = (Icon) b.getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { tmpIcon = (Icon) b.getPressedIcon(); if (tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } } else if (b.isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { tmpIcon = (Icon) b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { tmpIcon = (Icon) b.getRolloverIcon(); } } if (tmpIcon != null) { icon = tmpIcon; } if (model.isPressed() && model.isArmed()) { icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset()); } else { icon.paintIcon(c, g, iconRect.x, iconRect.y); } }
protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) { JButtonLinkA bn = (JButtonLinkA) com; ButtonModel bnModel = bn.getModel(); Color color = bn.getForeground(); Object obj = null; if (bnModel.isEnabled()) { if (bnModel.isPressed()) bn.setForeground(bn.getActiveLinkColor()); else if (bn.isLinkVisited()) bn.setForeground(bn.getVisitedLinkColor()); else bn.setForeground(bn.getLinkColor()); } else { if (bn.getDisabledLinkColor() != null) bn.setForeground(bn.getDisabledLinkColor()); } super.paintText(g, com, rect, s); int behaviour = bn.getLinkBehavior(); boolean drawLine = false; if (behaviour == JButtonLinkA.HOVER_UNDERLINE) { if (bnModel.isRollover()) drawLine = true; } else if (behaviour == JButtonLinkA.ALWAYS_UNDERLINE || behaviour == JButtonLinkA.SYSTEM_DEFAULT) drawLine = true; if (!drawLine) return; FontMetrics fm = g.getFontMetrics(); int x = rect.x + getTextShiftOffset(); int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1; if (bnModel.isEnabled()) { g.setColor(bn.getForeground()); g.drawLine(x, y, (x + rect.width) - 1, y); } else { g.setColor(bn.getBackground().brighter()); g.drawLine(x, y, (x + rect.width) - 1, y); } }
@Override protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Icon icon = b.getIcon(); Icon tmpIcon = null; Icon shadowIcon = null; boolean borderHasPressedCue = borderHasPressedCue(b); if (icon == null) { return; } if (!model.isEnabled()) { if (model.isSelected()) { tmpIcon = (Icon) b.getDisabledSelectedIcon(); } else { tmpIcon = (Icon) b.getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { tmpIcon = (Icon) b.getPressedIcon(); if (tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } else if (icon != null && icon instanceof ImageIcon && !borderHasPressedCue) { // Create an icon on the fly. // Note: This is only needed for borderless buttons, which // have no other way to provide feedback about the pressed // state. tmpIcon = new ImageIcon(HalfbrightFilter.createHalfbrightImage(((ImageIcon) icon).getImage())); shadowIcon = new ImageIcon(ShadowFilter.createShadowImage(((ImageIcon) icon).getImage())); } } else if (b.isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { tmpIcon = b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = b.getSelectedIcon(); } } else { tmpIcon = (Icon) b.getRolloverIcon(); } } else if (model.isSelected()) { tmpIcon = b.getSelectedIcon(); } if (tmpIcon != null) { icon = tmpIcon; } if (model.isPressed() && model.isArmed()) { if (shadowIcon != null) { shadowIcon.paintIcon( c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset() + 1); } icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset()); } else { icon.paintIcon(c, g, iconRect.x, iconRect.y); } }
/** * Method which renders the text of the current button. * * <p> * * @param g Graphics context * @param b Current button to render * @param textRect Bounding rectangle to render the text. * @param text String to render * @since 1.4 */ @Override protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { ButtonModel model = b.getModel(); FontMetrics fm = g.getFontMetrics(); int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1); boolean borderHasPressedCue = borderHasPressedCue(b); /* Draw the Text */ if (model.isPressed() && model.isArmed() && !borderHasPressedCue) { g.setColor(new Color(0xa0000000, true)); QuaquaUtilities.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset() + 1); } if (model.isEnabled()) { /** * paint the text normally */ g.setColor(b.getForeground()); } else { Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground"); g.setColor((c != null) ? c : b.getForeground()); } QuaquaUtilities.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); }
private void updateLook(JButton button) { ButtonModel model = button.getModel(); boolean enabled = model.isEnabled(); if (!enabled) { setLookNormal(button); return; } boolean pressed = model.isPressed(); boolean selected = model.isSelected(); if (pressed || selected) { setLookLowered(button); return; } if ((button == arrow) && popupVisible) { setLookLowered(button); return; } if (rollOver) { setLookRaised(button); return; } if (arrow.getModel().isSelected()) { setLookRaised(button); return; } setLookNormal(button); }
@Override protected void paintText( final Graphics g, final JComponent c, final Rectangle textRect, final String text) { final AbstractButton b = (AbstractButton) c; final ButtonModel model = b.getModel(); final FontMetrics fm = SwingUtils.getFontMetrics(c, g); final int mnemonicIndex = b.getDisplayedMnemonicIndex(); // Drawing text if (model.isEnabled()) { // Normal text g.setColor(b.getForeground()); SwingUtils.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); } else { // Disabled text g.setColor(b.getBackground().brighter()); SwingUtils.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent()); g.setColor(b.getBackground().darker()); SwingUtils.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } }
/** * Renders a text String in Windows without the mnemonic. This is here because the WindowsUI * hiearchy doesn't match the Component heirarchy. All the overriden paintText methods of the * ButtonUI delegates will call this static method. * * <p> * * @param g Graphics context * @param b Current button to render * @param textRect Bounding rectangle to render the text. * @param text String to render */ public static void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text, int textShiftOffset) { ButtonModel model = b.getModel(); FontMetrics fm = g.getFontMetrics(); int mnemIndex = b.getDisplayedMnemonicIndex(); // W2K Feature: Check to see if the Underscore should be rendered. if (WindowsLookAndFeel.isMnemonicHidden() == true) { mnemIndex = -1; } /* Draw the Text */ Color color = b.getForeground(); if (model.isEnabled()) { /** * paint the text normally */ g.setColor(color); BasicGraphicsUtils.drawStringUnderlineCharAt( g, text, mnemIndex, textRect.x + textShiftOffset, textRect.y + fm.getAscent() + textShiftOffset); } else { /** * paint the text disabled ** */ color = UIManager.getColor("Button.disabledForeground"); Color shadow = UIManager.getColor("Button.disabledShadow"); XPStyle xp = XPStyle.getXP(); if (xp != null) { color = xp.getColor("button.pushbutton(disabled).textcolor", color); } else { // Paint shadow only if not XP if (shadow == null) { shadow = b.getBackground().darker(); } g.setColor(shadow); BasicGraphicsUtils.drawStringUnderlineCharAt( g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } if (color == null) { color = b.getBackground().brighter(); } g.setColor(color); BasicGraphicsUtils.drawStringUnderlineCharAt( g, text, mnemIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isEnabled()) { if ((model.isPressed() && model.isArmed()) || model.isSelected()) { Color frameColor = ColorHelper.darker(AbstractLookAndFeel.getToolbarBackgroundColor(), 30); g.setColor(frameColor); g.drawRect(x, y, w - 1, h - 1); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f); g2D.setComposite(alpha); g.setColor(Color.black); g.fillRect(x + 1, y + 1, w - 2, h - 2); g2D.setComposite(composite); } else if (model.isRollover()) { Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor(); Color frameHiColor = ColorHelper.darker(frameColor, 5); Color frameLoColor = ColorHelper.darker(frameColor, 20); JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h); frameHiColor = Color.white; frameLoColor = ColorHelper.brighter(frameLoColor, 60); JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); g2D.setComposite(alpha); g.setColor(Color.white); g.fillRect(x + 2, y + 2, w - 4, h - 4); g2D.setComposite(composite); g.setColor(AbstractLookAndFeel.getFocusColor()); g.drawLine(x + 1, y + 1, x + w - 1, y + 1); g.drawLine(x + 1, y + 2, x + w - 2, y + 2); } else if (model.isSelected()) { Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor(); Color frameHiColor = Color.white; Color frameLoColor = ColorHelper.darker(frameColor, 30); JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h); } } }
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Color fg = button.getForeground(); if (fg instanceof UIResource && button instanceof JButton && ((JButton) button).isDefaultButton()) { final Color selectedFg = UIManager.getColor("Button.darcula.selectedButtonForeground"); if (selectedFg != null) { fg = selectedFg; } } g.setColor(fg); FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g); int mnemonicIndex = button.getDisplayedMnemonicIndex(); if (model.isEnabled()) { SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + metrics.getAscent() + getTextShiftOffset()); } else { g.setColor(UIManager.getColor("Button.darcula.disabledText.shadow")); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, -1, textRect.x + getTextShiftOffset() + 1, textRect.y + metrics.getAscent() + getTextShiftOffset() + 1); g.setColor(UIManager.getColor("Button.disabledText")); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, -1, textRect.x + getTextShiftOffset(), textRect.y + metrics.getAscent() + getTextShiftOffset()); } }
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { ButtonModel model = b.getModel(); FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont()); int mnemIndex; if (JTattooUtilities.getJavaVersion() >= 1.4) { mnemIndex = b.getDisplayedMnemonicIndex(); } else { mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic()); } int offs = 0; if (model.isArmed() && model.isPressed()) { offs = 1; } Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); Color foreground = b.getForeground(); Color background = b.getBackground(); if (background instanceof ColorUIResource) { if (model.isPressed() && model.isArmed()) { foreground = AbstractLookAndFeel.getTheme().getSelectionForegroundColor(); } else if (model.isRollover()) { foreground = AbstractLookAndFeel.getTheme().getRolloverForegroundColor(); } } if (!model.isEnabled()) { foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor(); } if (ColorHelper.getGrayValue(foreground) > 64) { g2D.setColor(Color.black); } else { g2D.setColor(Color.white); } JTattooUtilities.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1); g2D.setComposite(composite); g2D.setColor(foreground); JTattooUtilities.drawStringUnderlineCharAt( b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent()); }
/** * Returns the Icon to use for painting the button. The icon is chosen with respect to the current * state of the button. * * @param b button the icon is associated with * @return an 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; }
protected void paintText(Graphics g, JComponent c, String text, Rectangle textRect) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, textRect); } else { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); int mnemIndex = -1; if (JTattooUtilities.getJavaVersion() >= 1.4) { mnemIndex = b.getDisplayedMnemonicIndex(); } else { mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic()); } Font f = c.getFont(); g.setFont(f); FontMetrics fm = g.getFontMetrics(); if (model.isEnabled()) { Color fc = b.getForeground(); if (AbstractLookAndFeel.getTheme().isTextShadowOn() && ColorHelper.getGrayValue(fc) > 128) { g.setColor(Color.black); JTattooUtilities.drawStringUnderlineCharAt( c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent()); } g.setColor(fc); JTattooUtilities.drawStringUnderlineCharAt( c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } else { g.setColor(Color.black); JTattooUtilities.drawStringUnderlineCharAt( c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent()); g.setColor(AbstractLookAndFeel.getDisabledForegroundColor()); JTattooUtilities.drawStringUnderlineCharAt( c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } } }
public void paint(Graphics g, JComponent comp) { UIUtil.applyRenderingHints(g); JMenu jMenu = (JMenu) comp; ButtonModel buttonmodel = jMenu.getModel(); int mnemonicIndex = jMenu.getDisplayedMnemonicIndex(); Icon icon = getIcon(); Icon allowedIcon = getAllowedIcon(); Insets insets = comp.getInsets(); resetRects(); ourViewRect.setBounds(0, 0, jMenu.getWidth(), jMenu.getHeight()); ourViewRect.x += insets.left; ourViewRect.y += insets.top; ourViewRect.width -= insets.right + ourViewRect.x; ourViewRect.height -= insets.bottom + ourViewRect.y; Font font = g.getFont(); Font font1 = comp.getFont(); g.setFont(font1); FontMetrics fontmetrics = g.getFontMetrics(font1); String s1 = layoutMenuItem( fontmetrics, jMenu.getText(), icon, allowedIcon, arrowIcon, jMenu.getVerticalAlignment(), jMenu.getHorizontalAlignment(), jMenu.getVerticalTextPosition(), jMenu.getHorizontalTextPosition(), ourViewRect, ourIconRect, ourTextRect, ourAcceleratorRect, ourCheckIconRect, ourArrowIconRect, jMenu.getText() != null ? defaultTextIconGap : 0, defaultTextIconGap); Color color2 = g.getColor(); if (comp.isOpaque()) { g.setColor(jMenu.getBackground()); g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight()); if (buttonmodel.isArmed() || buttonmodel.isSelected()) { if (UIUtil.isUnderAquaLookAndFeel()) { myAquaSelectedBackgroundPainter.paintBorder( comp, g, 0, 0, jMenu.getWidth(), jMenu.getHeight()); } else { g.setColor(selectionBackground); if (allowedIcon != null) { g.fillRect(k, 0, jMenu.getWidth() - k, jMenu.getHeight()); } else { g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight()); g.setColor(selectionBackground); } } } g.setColor(color2); } if (allowedIcon != null) { if (buttonmodel.isArmed() || buttonmodel.isSelected()) { g.setColor(selectionForeground); } else { g.setColor(jMenu.getForeground()); } if (useCheckAndArrow()) { allowedIcon.paintIcon(comp, g, ourCheckIconRect.x, ourCheckIconRect.y); } g.setColor(color2); if (menuItem.isArmed()) { drawIconBorder(g); } } if (icon != null) { if (!buttonmodel.isEnabled()) { icon = jMenu.getDisabledIcon(); } else if (buttonmodel.isPressed() && buttonmodel.isArmed()) { icon = jMenu.getPressedIcon(); if (icon == null) { icon = jMenu.getIcon(); } } if (icon != null) { icon.paintIcon(comp, g, ourIconRect.x, ourIconRect.y); } } if (s1 != null && s1.length() > 0) { if (buttonmodel.isEnabled()) { if (buttonmodel.isArmed() || buttonmodel.isSelected()) { g.setColor(selectionForeground); } else { g.setColor(jMenu.getForeground()); } BasicGraphicsUtils.drawStringUnderlineCharAt( g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent()); } else { final Object disabledForeground = UIUtil.getMenuItemDisabledForeground(); if (disabledForeground instanceof Color) { g.setColor((Color) disabledForeground); BasicGraphicsUtils.drawStringUnderlineCharAt( g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent()); } else { g.setColor(jMenu.getBackground().brighter()); BasicGraphicsUtils.drawStringUnderlineCharAt( g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent()); g.setColor(jMenu.getBackground().darker()); BasicGraphicsUtils.drawStringUnderlineCharAt( g, s1, mnemonicIndex, ourTextRect.x - 1, (ourTextRect.y + fontmetrics.getAscent()) - 1); } } } if (arrowIcon != null) { if (buttonmodel.isArmed() || buttonmodel.isSelected()) { g.setColor(selectionForeground); } if (useCheckAndArrow()) { try { if (SystemInfo.isMac && myAquaInvertedArrowIcon != null && (buttonmodel.isArmed() || buttonmodel.isSelected()) && UIUtil.isUnderAquaLookAndFeel()) { myAquaInvertedArrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y); } else if (SystemInfo.isMac && myAquaDisabledArrowIcon != null && !buttonmodel.isEnabled() && UIUtil.isUnderAquaLookAndFeel()) { myAquaDisabledArrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y); } else arrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y); } catch (NullPointerException npe) { // GTKIconFactory$MenuArrowIcon.paintIcon since it doesn't expect to be given a null // instead of SynthContext // http://www.jetbrains.net/jira/browse/IDEADEV-22360 } } } g.setColor(color2); g.setFont(font); }
public void paintIcon(Component c, Graphics g, int x, int y) { if (!JTattooUtilities.isLeftToRight(c)) { x += GAP; } int w = getIconWidth() - GAP; int h = getIconHeight(); AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Graphics2D g2D = (Graphics2D) g; if (button.isEnabled()) { if ((button.isRolloverEnabled() && model.isRollover())) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getRolloverColors(), x + 1, y + 1, w - 1, h - 1); } else { if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getFocusColors(), x + 1, y + 1, w - 1, h - 1); } else { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getCheckBoxColors(), x + 1, y + 1, w - 1, h - 1); } } } else { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getDisabledColors(), x + 1, y + 1, w - 1, h - 1); } Color frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6); Color loFrameColor = ColorHelper.darker(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 50); g.setColor(frameColor); g.drawRect(x, y, w, h); Composite savedComposite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); g2D.setComposite(alpha); g.setColor(loFrameColor); g.drawLine(x + 1, y + 1, x + w - 1, y + 1); g.drawLine(x + 1, y + 1, x + 1, y + h - 1); g2D.setComposite(savedComposite); Icon checkIcon; Icon checkDisabledIcon; Icon checkInverseIcon; if (AbstractLookAndFeel.getTheme().isSmallFontSize()) { checkIcon = SMALL_CHECK_ICON; checkDisabledIcon = SMALL_CHECK_DISABLED_ICON; checkInverseIcon = SMALL_CHECK_INVERSE_ICON; } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) { checkIcon = MEDIUM_CHECK_ICON; checkDisabledIcon = MEDIUM_CHECK_DISABLED_ICON; checkInverseIcon = MEDIUM_CHECK_INVERSE_ICON; } else { checkIcon = LARGE_CHECK_ICON; checkDisabledIcon = LARGE_CHECK_DISABLED_ICON; checkInverseIcon = LARGE_CHECK_INVERSE_ICON; } int xi = x + ((w - checkIcon.getIconWidth()) / 2) + 1; int yi = y + ((h - checkIcon.getIconHeight()) / 2); int gv = ColorHelper.getGrayValue(AbstractLookAndFeel.getButtonForegroundColor()); if (model.isPressed() && model.isArmed()) { Color bc = gv > 128 ? AbstractLookAndFeel.getTheme().getSelectionForegroundColor() : AbstractLookAndFeel.getTheme().getSelectionBackgroundColor(); Color fc = gv > 128 ? ColorHelper.brighter(bc, 20) : ColorHelper.darker(bc, 40); g.setColor(fc); g.drawRect(x + 4, y + 4, w - 8, h - 8); g.setColor(bc); g.fillRect(x + 5, y + 5, w - 9, h - 9); } else if (model.isSelected()) { if (!model.isEnabled()) { checkDisabledIcon.paintIcon(c, g, xi + 1, yi); } else { if (gv > 128) { checkIcon.paintIcon(c, g, xi, yi); } else { checkInverseIcon.paintIcon(c, g, xi + 1, yi + 1); } } } }
public void paintIcon(Component c, Graphics g, int x, int y) { if (!JTattooUtilities.isLeftToRight(c)) { x += GAP; } int w = getIconWidth() - GAP; int h = getIconHeight(); Graphics2D g2D = (Graphics2D) g; AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Color colors[]; if (button.isEnabled()) { if ((button.isRolloverEnabled() && model.isRollover()) || (model.isPressed() && model.isArmed())) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) { colors = AbstractLookAndFeel.getTheme().getFocusColors(); } else { colors = AbstractLookAndFeel.getTheme().getCheckBoxColors(); } } } else { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } Color frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6); Shape savedClip = g.getClip(); Area clipArea = new Area(new Ellipse2D.Double(x, y, w + 1, h + 1)); if (savedClip != null) { clipArea.intersect(new Area(savedClip)); } g2D.setClip(clipArea); JTattooUtilities.fillHorGradient(g, colors, x, y, w, h); g2D.setClip(savedClip); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(frameColor); g.drawOval(x, y, w, h); if (model.isSelected()) { if (model.isEnabled()) { Color fc = AbstractLookAndFeel.getForegroundColor(); if (ColorHelper.getGrayValue(colors[0]) < 128) { if (ColorHelper.getGrayValue(fc) < 128) { g2D.setColor(Color.white); } else { g2D.setColor(fc); } } else { if (ColorHelper.getGrayValue(fc) > 128) { g2D.setColor(Color.black); } else { g2D.setColor(fc); } } } else { g.setColor(AbstractLookAndFeel.getDisabledForegroundColor()); } if (AbstractLookAndFeel.getTheme().isSmallFontSize()) { g2D.fillOval(x + 4, y + 4, w - 7, h - 7); } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) { g2D.fillOval(x + 4, y + 4, w - 7, h - 7); } else { g2D.fillOval(x + 5, y + 5, w - 9, h - 9); } } g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
public void paint(final Graphics g, final JComponent c) { final AnchoredButton button = (AnchoredButton) c; final String text = button.getText(); final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon(); if ((icon == null) && (text == null)) { return; } final FontMetrics fm = button.getFontMetrics(button.getFont()); ourViewInsets = c.getInsets(ourViewInsets); ourViewRect.x = ourViewInsets.left; ourViewRect.y = ourViewInsets.top; final ToolWindowAnchor anchor = button.getAnchor(); // Use inverted height & width if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) { ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right); ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom); } else { ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right); ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom); } ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0; ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0; final String clippedText = SwingUtilities.layoutCompoundLabel( c, fm, text, icon, button.getVerticalAlignment(), button.getHorizontalAlignment(), button.getVerticalTextPosition(), button.getHorizontalTextPosition(), ourViewRect, ourIconRect, ourTextRect, button.getText() == null ? 0 : button.getIconTextGap()); // Paint button's background final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); final ButtonModel model = button.getModel(); final Color background = button.getBackground(); Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null; final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT; if (model.isArmed() && model.isPressed() || model.isSelected()) { g2.setColor(new Color(0, 0, 0, 30)); g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6); g2.setColor(new Color(0, 0, 0, 120)); g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2); g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7); g2.setColor(new Color(0, 0, 0, 40)); g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7); g2.setColor(new Color(255, 255, 255, 110)); g2.drawLine( 3, button.getHeight() - 3, 3 + button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 3); g2.drawLine( 3 + button.getWidth() - (vertical ? 6 : 5), 2, 3 + button.getWidth() - (vertical ? 6 : 5), 3 + button.getHeight() - 7); toBorder = null; } if (toBorder != null) { g.setColor(toBorder); g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6); } AffineTransform tr = null; if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) { tr = g2.getTransform(); if (ToolWindowAnchor.RIGHT == anchor) { if (icon != null) { // do not rotate icon icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x); } g2.rotate(Math.PI / 2); g2.translate(0, -c.getWidth()); } else { if (icon != null) { // do not rotate icon icon.paintIcon( c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight()); } g2.rotate(-Math.PI / 2); g2.translate(-c.getHeight(), 0); } } else { if (icon != null) { icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y); } } // paint text if (text != null) { if (model.isEnabled()) { if (model.isArmed() && model.isPressed() || model.isSelected()) { g.setColor(background); } else { g.setColor(button.getForeground()); } } else { g.setColor(background.darker()); } /* Draw the Text */ if (model.isEnabled()) { /** * paint the text normally */ g.setColor(button.getForeground()); BasicGraphicsUtils.drawString( g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent()); } else { /** * paint the text disabled ** */ if (model.isSelected()) { g.setColor(c.getBackground()); } else { g.setColor(getDisabledTextColor()); } BasicGraphicsUtils.drawString( g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent()); } } if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) { g2.setTransform(tr); } }
protected void paintBackground(Graphics g, AbstractButton b) { if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) { return; } if (!(b.isBorderPainted() && (b.getBorder() instanceof UIResource))) { super.paintBackground(g, b); return; } int width = b.getWidth(); int height = b.getHeight(); ButtonModel model = b.getModel(); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) { if (model.isSelected()) { Color color = ColorHelper.darker(b.getBackground(), 20); g2D.setColor(color); g2D.fillRect(0, 0, width - 1, height - 1); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRect(0, 0, width - 1, height - 1); } else { Color[] colors = null; if (b.getBackground() instanceof ColorUIResource) { if (!model.isEnabled()) { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } else if (b.isRolloverEnabled() && model.isRollover()) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { colors = AbstractLookAndFeel.getTheme().getButtonColors(); } } else { colors = ColorHelper.createColorArr( ColorHelper.brighter(b.getBackground(), 20), ColorHelper.darker(b.getBackground(), 20), 20); } JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRect(0, 0, width - 1, height - 1); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); g2D.setColor(Color.white); g2D.drawRect(1, 1, width - 3, height - 3); } } else if (model.isPressed() && model.isArmed()) { int d = height - 2; Color color = AbstractLookAndFeel.getTheme().getSelectionBackgroundColor(); g2D.setColor(color); g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d); g2D.setColor(ColorHelper.darker(color, 40)); g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); } else if (model.isSelected()) { int d = height - 2; Color color = ColorHelper.darker(b.getBackground(), 20); g2D.setColor(color); g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); } else { int d = height - 2; Color[] colors = null; if (b.getBackground() instanceof ColorUIResource) { if (!model.isEnabled()) { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } else if (b.isRolloverEnabled() && model.isRollover()) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { colors = AbstractLookAndFeel.getTheme().getButtonColors(); } } else { colors = ColorHelper.createColorArr( ColorHelper.brighter(b.getBackground(), 20), ColorHelper.darker(b.getBackground(), 20), 20); } Shape savedClip = g.getClip(); Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d)); clipArea.intersect(new Area(savedClip)); g2D.setClip(clipArea); JTattooUtilities.fillHorGradient(g, colors, 0, 0, width, height); g2D.setClip(savedClip); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); g2D.setColor(Color.white); g2D.drawRoundRect(1, 1, width - 3, height - 3, d - 2, d - 2); } g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); g2D.setComposite(composite); }