Пример #1
0
  protected void paintBackgroundSafely(final Graphics g) {
    final JTextComponent c = getComponent();
    final int width = c.getWidth();
    final int height = c.getHeight();

    // a delegate takes precedence
    if (delegate != null) {
      delegate.paint(c, g, 0, 0, width, height);
      return;
    }

    final boolean isOpaque = c.isOpaque();
    if (!(c.getBorder() instanceof AquaTextFieldBorder)) {
      // developer must have set a custom border
      if (!isOpaque && AquaUtils.hasOpaqueBeenExplicitlySet(c)) return;

      // must fill whole region with background color if opaque
      g.setColor(c.getBackground());
      g.fillRect(0, 0, width, height);
      return;
    }

    // using our own border
    g.setColor(c.getBackground());
    if (isOpaque) {
      g.fillRect(0, 0, width, height);
      return;
    }

    final Insets margin = c.getMargin();
    Insets insets = c.getInsets();

    if (insets == null) insets = new Insets(0, 0, 0, 0);
    if (margin != null) {
      insets.top -= margin.top;
      insets.left -= margin.left;
      insets.bottom -= margin.bottom;
      insets.right -= margin.right;
    }

    // the common case
    final int shrinkage = AquaTextFieldBorder.getShrinkageFor(c, height);
    g.fillRect(
        insets.left - 2,
        insets.top - shrinkage - 1,
        width - insets.right - insets.left + 4,
        height - insets.bottom - insets.top + shrinkage * 2 + 2);
  }