Example #1
0
 /**
  * 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);
 }
Example #2
0
    private void paintOceanBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = ((AbstractButton) c).getModel();

      g.translate(x, y);
      if (MetalUtils.isToolBarButton(button)) {
        if (model.isEnabled()) {
          if (model.isPressed()) {
            g.setColor(MetalLookAndFeel.getWhite());
            g.fillRect(1, h - 1, w - 1, 1);
            g.fillRect(w - 1, 1, 1, h - 1);
            g.setColor(MetalLookAndFeel.getControlDarkShadow());
            g.drawRect(0, 0, w - 2, h - 2);
            g.fillRect(1, 1, w - 3, 1);
          } else if (model.isSelected() || model.isRollover()) {
            g.setColor(MetalLookAndFeel.getWhite());
            g.fillRect(1, h - 1, w - 1, 1);
            g.fillRect(w - 1, 1, 1, h - 1);
            g.setColor(MetalLookAndFeel.getControlDarkShadow());
            g.drawRect(0, 0, w - 2, h - 2);
          } else {
            g.setColor(MetalLookAndFeel.getWhite());
            g.drawRect(1, 1, w - 2, h - 2);
            g.setColor(UIManager.getColor("Button.toolBarBorderBackground"));
            g.drawRect(0, 0, w - 2, h - 2);
          }
        } else {
          g.setColor(UIManager.getColor("Button.disabledToolBarBorderBackground"));
          g.drawRect(0, 0, w - 2, h - 2);
        }
      } else if (model.isEnabled()) {
        boolean pressed = model.isPressed();
        boolean armed = model.isArmed();

        if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
          g.setColor(MetalLookAndFeel.getControlDarkShadow());
          g.drawRect(0, 0, w - 1, h - 1);
          g.drawRect(1, 1, w - 3, h - 3);
        } else if (pressed) {
          g.setColor(MetalLookAndFeel.getControlDarkShadow());
          g.fillRect(0, 0, w, 2);
          g.fillRect(0, 2, 2, h - 2);
          g.fillRect(w - 1, 1, 1, h - 1);
          g.fillRect(1, h - 1, w - 2, 1);
        } else if (model.isRollover() && button.getClientProperty(NO_BUTTON_ROLLOVER) == null) {
          g.setColor(MetalLookAndFeel.getPrimaryControl());
          g.drawRect(0, 0, w - 1, h - 1);
          g.drawRect(2, 2, w - 5, h - 5);
          g.setColor(MetalLookAndFeel.getControlDarkShadow());
          g.drawRect(1, 1, w - 3, h - 3);
        } else {
          g.setColor(MetalLookAndFeel.getControlDarkShadow());
          g.drawRect(0, 0, w - 1, h - 1);
        }
      } else {
        g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
        g.drawRect(0, 0, w - 1, h - 1);
        if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
          g.drawRect(1, 1, w - 3, h - 3);
        }
      }
    }