protected void paintComponentBackground(Graphics g) {
   int w = button.getWidth();
   int h = button.getHeight();
   Color top_color = hovered ? (pressed ? pressed_dark_color : hovered_light_color) : light_color;
   Color bottom_color =
       hovered ? (pressed ? pressed_light_color : hovered_dark_color) : dark_color;
   GradientPaint gp = new GradientPaint(1, 1, top_color, 1, h - 2, bottom_color);
   Graphics2D g2d = (Graphics2D) g;
   g2d.setPaint(gp);
   g2d.fillRect(1, 1, w - 2, h - 2);
   g.setColor(Color.white);
   g.drawLine(0, 0, w - 1, 0);
   g.drawLine(0, 0, 0, h - 1);
   g.setColor(border_color);
   g.drawLine(0, h - 1, w - 1, h - 1);
   g.drawLine(w - 1, 0, w - 1, h - 1);
 }
 public void setHovered(boolean hovered) {
   this.hovered = hovered;
   button.repaint();
 }
 public void setPressed(boolean pressed) {
   this.pressed = pressed;
   button.repaint();
 }
 public void mouseReleased(MouseEvent e) {
   setPressed(false);
   button.fireActionPerformed(new ActionEvent(button, 0, button.getText()));
 }
 public void uninstallUI(JComponent c) {
   button.removeMouseListener(this);
   button.removeMouseMotionListener(this);
 }
 public void installUI(JComponent c) {
   button = (CurtainButton) c;
   button.addMouseListener(this);
   button.addMouseMotionListener(this);
 }
 public void paint(Graphics g, JComponent c) {
   paintComponentBackground(g);
   int w = button.getWidth();
   int h = button.getHeight();
   int wd = 0;
   if (button.getIcon() != null) wd += button.getIcon().getIconWidth();
   FontMetrics fm = g.getFontMetrics();
   if (button.getText() != null) wd += fm.stringWidth(button.getText()) + TEXT_ICON_PADDING;
   int x =
       (int) (LEADING_TEXT_PADDING + (w - 2 * LEADING_TEXT_PADDING - wd) * button.getAlignment());
   if (button.getIcon() != null) {
     int y = (h - button.getIcon().getIconHeight()) / 2;
     button.getIcon().paintIcon(button, g, x, y);
     x += button.getIcon().getIconWidth() + TEXT_ICON_PADDING;
   }
   if (button.getText() != null) {
     int y = (h - fm.getHeight()) / 2 + fm.getAscent();
     g.setColor(button.getForeground());
     g.drawString(button.getText(), x, y);
   }
 }