/** Returns the current state of the passed in <code>AbstractButton</code>. */ private int getComponentState(JComponent c) { int state = ENABLED; if (!c.isEnabled()) { state = DISABLED; } if (SynthLookAndFeel.getSelectedUI() == this) { return SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED; } AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isPressed()) { if (model.isArmed()) { state = PRESSED; } else { state = MOUSE_OVER; } } if (model.isRollover()) { state |= MOUSE_OVER; } if (model.isSelected()) { state |= SELECTED; } if (c.isFocusOwner() && button.isFocusPainted()) { state |= FOCUSED; } if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) { state |= DEFAULT; } return state; }
/** * 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; }
/** * If necessary paints the background of the component, then invokes <code>paint</code>. * * @param g Graphics to paint to * @param c JComponent painting on * @throws NullPointerException if <code>g</code> or <code>c</code> is null * @see javax.swing.plaf.ComponentUI#update * @see javax.swing.plaf.ComponentUI#paint * @since 1.5 */ public void update(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; if ((c.getBackground() instanceof UIResource) && button.isContentAreaFilled() && c.isEnabled()) { ButtonModel model = button.getModel(); if (!MetalUtils.isToolBarButton(c)) { if (!model.isArmed() && !model.isPressed() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } else if (model.isRollover() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } super.update(g, c); }