@Override
  public Dimension getPreferredSize() {
    final Dimension size = super.getPreferredSize();

    Map<Boolean, List<AdditionalIcon>> map = new HashMap<>();
    for (AdditionalIcon myAdditionalIcon : myAdditionalIcons) {
      if (myAdditionalIcon.getAvailable()) {
        map.computeIfAbsent(myAdditionalIcon.getAfterText(), k -> new SmartList<>()).add(myAdditionalIcon);
      }
    }

    boolean additionalIconsOnly = StringUtil.isEmptyOrSpaces(getText()) && getIcon() == null;
    int left = JBUI.scale(DEFAULT_HORIZONTAL_INSET);
    int right = left;
    int iconsGap = JBUI.scale(ICONS_GAP);
    if (additionalIconsOnly) {
      left = iconsGap;
      right = iconsGap;
    }

    if (map.get(false) != null) {
      int iconWidth = iconsGap;

      for (AdditionalIcon icon : map.get(false)) {
        icon.setX(iconWidth);
        iconWidth += icon.getIconWidth() + iconsGap;
      }

      left = iconWidth;
    }

    int rightIconWidth = 0;
    if (map.get(true) != null) {
      if (additionalIconsOnly) {
        for (AdditionalIcon icon : map.get(true)) {
          icon.setX(left + rightIconWidth);
          rightIconWidth += icon.getIconWidth() + iconsGap;
        }
        rightIconWidth -= iconsGap;
      }
      else {
        right = iconsGap + JBUIScale.scale(4);
        int offset = size.width - JBUIScale.scale(4);

        for (AdditionalIcon icon : map.get(true)) {
          icon.setX(offset + rightIconWidth);
          rightIconWidth += icon.getIconWidth() + iconsGap;
        }
      }
    }

    myBorder.setBorderInsets(0, left, 0, right);
    myIconWithInsetsWidth = rightIconWidth + right + left;

    if (ExperimentalUI.isNewUI()) {
      JBInsets insets = JBUI.CurrentTheme.ToolWindow.headerTabLeftRightInsets();
      insets.left = Math.max(left, insets.left);
      myBorder.setBorderInsets(insets);
      myIconWithInsetsWidth = rightIconWidth + right + left;
    }

    return new Dimension(rightIconWidth + size.width, size.height);
  }
@Override
  public Dimension getPreferredSize()