public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   if (((JToolBar) c).isFloatable()) {
     Graphics2D g2D = (Graphics2D) g;
     Composite savedComposite = g2D.getComposite();
     AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
     g2D.setComposite(alpha);
     if (((JToolBar) c).getOrientation() == HORIZONTAL) {
       if (!JTattooUtilities.isLeftToRight(c)) {
         x += w - 15;
       }
       g.setColor(Color.white);
       g.drawLine(x + 3, y + 4, x + 3, h - 5);
       g.drawLine(x + 6, y + 3, x + 6, h - 4);
       g.drawLine(x + 9, y + 4, x + 9, h - 5);
       g.setColor(shadow);
       g.drawLine(x + 4, y + 4, x + 4, h - 5);
       g.drawLine(x + 7, y + 3, x + 7, h - 4);
       g.drawLine(x + 10, y + 4, x + 10, h - 5);
     } else {
       // vertical
       g.setColor(Color.white);
       g.drawLine(x + 3, y + 3, w - 4, y + 3);
       g.drawLine(x + 3, y + 6, w - 4, y + 6);
       g.drawLine(x + 3, y + 9, w - 4, y + 9);
       g.setColor(shadow);
       g.drawLine(x + 3, y + 4, w - 4, y + 4);
       g.drawLine(x + 3, y + 7, w - 4, y + 7);
       g.drawLine(x + 3, y + 10, w - 4, y + 10);
     }
     g2D.setComposite(savedComposite);
   }
 }
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   Color logoColor = AbstractLookAndFeel.getMenuSelectionBackgroundColor();
   Color borderColorLo = AbstractLookAndFeel.getFrameColor();
   Color borderColorHi =
       ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40);
   g.setColor(logoColor);
   if (JTattooUtilities.isLeftToRight(c)) {
     int dx = getBorderInsets(c).left;
     g.fillRect(x, y, dx - 1, h - 1);
     paintLogo(c, g, x, y, w, h);
     // - highlight
     g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getMenuBackgroundColor(), 40));
     g.drawLine(x + dx, y + 1, x + w - 2, y + 1);
     g.setColor(borderColorHi);
     g.drawLine(x + 1, y, x + 1, y + h - 2);
     // - outer frame
     g.setColor(borderColorLo);
     if (isMenuBarPopup(c)) {
       // top
       g.drawLine(x + dx - 1, y, x + w, y);
       // left
       g.drawLine(x, y, x, y + h - 1);
       // bottom
       g.drawLine(x, y + h - 1, x + w, y + h - 1);
       // right
       g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
     } else {
       g.drawRect(x, y, w - 1, h - 1);
     }
     // - logo separator
     g.drawLine(x + dx - 1, y + 1, x + dx - 1, y + h - 1);
   } else {
     int dx = getBorderInsets(c).right;
     g.fillRect(x + w - dx, y, dx, h - 1);
     paintLogo(c, g, x, y, w, h);
     // - highlight
     g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getMenuBackgroundColor(), 40));
     g.drawLine(x + 1, y + 1, x + w - dx - 1, y + 1);
     g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
     // - outer frame
     g.setColor(borderColorLo);
     if (isMenuBarPopup(c)) {
       // top
       g.drawLine(x, y, x + w - dx, y);
       // left
       g.drawLine(x, y, x, y + h - 1);
       // bottom
       g.drawLine(x, y + h - 1, x + w, y + h - 1);
       // right
       g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
     } else {
       g.drawRect(x, y, w - 1, h - 1);
     }
     // - logo separator
     g.drawLine(x + w - dx, y + 1, x + w - dx, y + h - 1);
   }
 }
 public Insets getBorderInsets(Component c) {
   if (hasLogo(c)) {
     if (JTattooUtilities.isLeftToRight(c)) {
       return new Insets(
           leftLogoInsets.top,
           leftLogoInsets.left,
           leftLogoInsets.bottom + shadowSize,
           leftLogoInsets.right + shadowSize);
     } else {
       return new Insets(
           rightLogoInsets.top,
           rightLogoInsets.left,
           rightLogoInsets.bottom + shadowSize,
           rightLogoInsets.right + shadowSize);
     }
   } else {
     return new Insets(
         insets.top, insets.left, insets.bottom + shadowSize, insets.right + shadowSize);
   }
 }
    public void layoutDefault(Container c) {
      boolean leftToRight = JTattooUtilities.isLeftToRight(frame);

      int spacing = getHorSpacing();
      int w = getWidth();
      int h = getHeight();

      // assumes all buttons have the same dimensions these dimensions include the borders
      int buttonHeight = h - getVerSpacing();
      int buttonWidth = buttonHeight + 10;

      int x = leftToRight ? w - spacing : 0;
      int y = Math.max(0, ((h - buttonHeight) / 2) - 1);

      if (frame.isClosable()) {
        x += leftToRight ? -buttonWidth : spacing;
        closeButton.setBounds(x, y, buttonWidth, buttonHeight);
        if (!leftToRight) {
          x += buttonWidth;
        }
      }

      if (frame.isMaximizable() && !isPalette) {
        x += leftToRight ? -spacing - buttonWidth : spacing;
        maxButton.setBounds(x, y, buttonWidth, buttonHeight);
        if (!leftToRight) {
          x += buttonWidth;
        }
      }

      if (frame.isIconifiable() && !isPalette) {
        x += leftToRight ? -spacing - buttonWidth : spacing;
        iconButton.setBounds(x, y, buttonWidth, buttonHeight);
        if (!leftToRight) {
          x += buttonWidth;
        }
      }

      buttonsWidth = leftToRight ? w - x : x;
    }
 public Insets getBorderInsets(Component c) {
   Insets insets = new Insets(2, 2, 2, 2);
   if (((JToolBar) c).isFloatable()) {
     if (((JToolBar) c).getOrientation() == HORIZONTAL) {
       if (JTattooUtilities.isLeftToRight(c)) {
         insets.left = 15;
       } else {
         insets.right = 15;
       }
     } else {
       insets.top = 15;
     }
   }
   Insets margin = ((JToolBar) c).getMargin();
   if (margin != null) {
     insets.left += margin.left;
     insets.top += margin.top;
     insets.right += margin.right;
     insets.bottom += margin.bottom;
   }
   return insets;
 }
    public void paintLogo(Component c, Graphics g, int x, int y, int w, int h) {
      if (hasLogo(c)) {
        Graphics2D g2D = (Graphics2D) g;

        Font savedFont = g2D.getFont();
        g.setFont(logoFont);
        FontMetrics fm = JTattooUtilities.getFontMetrics((JComponent) c, g, c.getFont());
        String logo =
            JTattooUtilities.getClippedText(
                AbstractLookAndFeel.getTheme().getLogoString(), fm, h - 16);

        AffineTransform savedTransform = g2D.getTransform();

        Color fc = getLogoColorHi();
        Color bc = getLogoColorLo();

        if (JTattooUtilities.isLeftToRight(c)) {
          g2D.translate(fm.getAscent() + 1, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        } else {
          g2D.translate(w - shadowSize - 4, h - shadowSize - 4);
          g2D.rotate(Math.toRadians(-90));
          g2D.setColor(bc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 0, 1);
          g2D.setColor(fc);
          JTattooUtilities.drawString((JComponent) c, g, logo, 1, 0);
        }

        g2D.setTransform(savedTransform);
        g2D.setFont(savedFont);
      }
    }
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      Graphics2D g2D = (Graphics2D) g;
      Composite savedComposite = g2D.getComposite();
      AlphaComposite alpha =
          AlphaComposite.getInstance(
              AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
      g2D.setComposite(alpha);
      Color logoColor = AbstractLookAndFeel.getTheme().getMenuSelectionBackgroundColor();
      Color borderColorLo = AbstractLookAndFeel.getFrameColor();
      Color borderColorHi =
          ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40);
      g.setColor(logoColor);
      if (JTattooUtilities.isLeftToRight(c)) {
        int dx = getBorderInsets(c).left;
        g.fillRect(x, y, dx - 1, h - 1 - shadowSize);
        paintLogo(c, g, x, y, w, h);
        // - highlight
        g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getMenuBackgroundColor(), 40));
        g.drawLine(x + dx, y + 1, x + w - shadowSize - 2, y + 1);
        g.setColor(borderColorHi);
        g.drawLine(x + 1, y, x + 1, y + h - shadowSize - 2);
        // - outer frame
        g.setColor(borderColorLo);
        if (isMenuBarPopup(c)) {
          // top
          g.drawLine(x + dx - 1, y, x + w - shadowSize - 1, y);
          // left
          g.drawLine(x, y, x, y + h - shadowSize - 1);
          // bottom
          g.drawLine(x, y + h - shadowSize - 1, x + w - shadowSize - 1, y + h - shadowSize - 1);
          // right
          g.drawLine(x + w - shadowSize - 1, y + 1, x + w - shadowSize - 1, y + h - shadowSize - 1);
        } else {
          g.drawRect(x, y, w - shadowSize - 1, h - shadowSize - 1);
        }
        // - logo separator
        g.drawLine(x + dx - 1, y + 1, x + dx - 1, y + h - shadowSize - 1);
      } else {
        int dx = getBorderInsets(c).right - shadowSize;
        g.fillRect(x + w - dx - shadowSize, y, dx - 1, h - 1 - shadowSize);
        paintLogo(c, g, x, y, w, h);
        // - highlight
        g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getMenuBackgroundColor(), 40));
        g.drawLine(x + 1, y + 1, x + w - dx - shadowSize - 1, y + 1);
        g.drawLine(x + 1, y + 1, x + 1, y + h - shadowSize - 2);
        // - outer frame
        g.setColor(borderColorLo);
        if (isMenuBarPopup(c)) {
          // top
          g.drawLine(x, y, x + w - dx - shadowSize, y);
          // left
          g.drawLine(x, y, x, y + h - shadowSize - 1);
          // bottom
          g.drawLine(x, y + h - shadowSize - 1, x + w - shadowSize - 1, y + h - shadowSize - 1);
          // right
          g.drawLine(x + w - shadowSize - 1, y, x + w - shadowSize - 1, y + h - shadowSize - 1);
        } else {
          g.drawRect(x, y, w - shadowSize - 1, h - shadowSize - 1);
        }
        // - logo separator
        g.drawLine(x + w - dx - shadowSize, y + 1, x + w - dx - shadowSize, y + h - shadowSize - 1);
      }

      // paint the shadow
      g2D.setColor(AbstractLookAndFeel.getTheme().getShadowColor());
      float alphaValue = 0.4f;
      for (int i = 0; i < shadowSize; i++) {
        alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaValue);
        g2D.setComposite(alpha);
        g.drawLine(
            x + w - shadowSize + i,
            y + shadowSize,
            x + w - shadowSize + i,
            y + h - shadowSize - 1 + i);
        g.drawLine(
            x + shadowSize, y + h - shadowSize + i, x + w - shadowSize + i, y + h - shadowSize + i);
        alphaValue -= (alphaValue / 2);
      }

      g2D.setComposite(savedComposite);
    }
    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 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);
          }
        }
      }
    }