public @NotNull String trim(@Nullable String text, @NotNull FontMetrics metrics, int availableWidth) {
    if (text == null || availableWidth <= 0) return "";
    trimmed = !isFit(text, metrics, availableWidth);
    if (!trimmed) return text;
    int ellipsisWidth = metrics.stringWidth(ellipsis);
    if (availableWidth <= ellipsisWidth) return ellipsis;
    int width = availableWidth - ellipsisWidth;
    if (alignment == SwingConstants.LEFT) return ellipsis + trimLeft(text, metrics, width);
    if (alignment == SwingConstants.RIGHT) return trimRight(text, metrics, width) + ellipsis;
    String postfix = trimRight(text, metrics, (int)(width * ratio)) + ellipsis;
    return postfix + trimLeft(text, metrics, availableWidth - metrics.stringWidth(postfix));
  }
public @NotNull String trim(@Nullable String text, @NotNull FontMetrics metrics, int availableWidth)