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);
  }
  /** @see javax.swing.plaf.basic.BasicTextUI#uninstallDefaults() */
  protected void uninstallDefaults() {
    JTextComponent c = getComponent();
    SeaGlassContext context = getContext(c, ENABLED);

    // Remove the search border, if present.
    Border border = c.getBorder();

    if (border instanceof TextFieldBorder) {
      c.setBorder(null);
    }

    c.putClientProperty("caretAspectRatio", null);
    c.removeFocusListener(this);

    style.uninstallDefaults(context);
    context.dispose();
    style = null;

    super.uninstallDefaults();
  }
  /**
   * Sea Glass code to support the search JTextField.variant.
   *
   * @param c the JTextField component.
   * @param context the SeaGlassContext.
   * @param prefix the control prefix, e.g. "TextField", "FormattedTextField", or "PasswordField".
   */
  private void updateSearchStyle(JTextComponent c, SeaGlassContext context, String prefix) {
    searchIconWidth = 0;
    Object o = style.get(context, prefix + ".searchIconWidth");

    if (o != null && o instanceof Integer) {
      searchIconWidth = (Integer) o;
    }

    popupIconWidth = 0;
    o = style.get(context, prefix + ".popupIconWidth");
    if (o != null && o instanceof Integer) {
      popupIconWidth = (Integer) o;
    }

    cancelIconWidth = 0;
    o = style.get(context, prefix + ".cancelIconWidth");
    if (o != null && o instanceof Integer) {
      cancelIconWidth = (Integer) o;
    }

    searchLeftInnerMargin = 0;
    o = style.get(context, prefix + ".searchLeftInnerMargin");
    if (o != null && o instanceof Integer) {
      searchLeftInnerMargin = (Integer) o;
    }

    searchRightInnerMargin = 0;
    o = style.get(context, prefix + ".searchRightInnerMargin");
    if (o != null && o instanceof Integer) {
      searchRightInnerMargin = (Integer) o;
    }

    placeholderColor = Color.GRAY;
    o = style.get(context, "placeholderTextColor");
    if (o != null && o instanceof Color) {
      placeholderColor = (Color) o;
    }

    Border border = c.getBorder();

    if (border == null || border instanceof UIResource && !(border instanceof TextFieldBorder)) {
      c.setBorder(createTextFieldBorder(context));
    }

    if (isSearchField.isInState(c)) {
      o = c.getClientProperty("JTextField.Search.PlaceholderText");
      if (o != null && o instanceof String) {
        placeholderText = (String) o;
      } else if (placeholderText != null) {
        placeholderText = null;
      }

      o = c.getClientProperty("JTextField.Search.FindAction");
      if (o != null && o instanceof ActionListener) {
        if (findAction == null) {
          findAction = (ActionListener) o;
        }
      }

      o = c.getClientProperty("JTextField.Search.FindPopup");
      if (o != null && o instanceof JPopupMenu) {
        if (findPopup == null) {
          findPopup = (JPopupMenu) o;
        }
      }

      o = c.getClientProperty("JTextField.Search.CancelAction");
      if (o != null && o instanceof ActionListener) {
        if (cancelAction == null) {
          cancelAction = (ActionListener) o;
        }
      }

      installMouseListeners();
    } else {
      placeholderText = null;

      if (findAction != null) {
        findAction = null;
      }

      if (findPopup != null) {
        findPopup = null;
      }

      if (cancelAction != null) {
        cancelAction = null;
      }

      uninstallMouseListeners();
    }
  }