private @Nls @NotNull String cutString(@Nls @NotNull String text, double maxWidth) {
      FontMetrics m = getFontMetrics(getFont());
      Graphics g = getGraphics();
      String suffix = ELLIPSIS;

      if (m.getStringBounds(text, g).getWidth() < maxWidth) return text;

      double suffixWidth = m.getStringBounds(suffix, g).getWidth();
      if (suffixWidth >= maxWidth) return suffix;

      for (int i = 1; i < text.length(); i++) {
        if ((m.getStringBounds(text, 0, i, g).getWidth() + suffixWidth) >= maxWidth) {
          return text.substring(0, i - 1) + suffix;
        }
      }
      return text;
    }
private @Nls @NotNull String cutString(@Nls @NotNull String text, double maxWidth)