private static void formatStyle(
      final StringBuilder builder, final SimpleTextAttributes attributes) {
    final Color fgColor = attributes.getFgColor();
    final Color bgColor = attributes.getBgColor();
    final int style = attributes.getStyle();

    final int pos = builder.length();
    if (fgColor != null) {
      builder
          .append("color:#")
          .append(Integer.toString(fgColor.getRGB() & 0xFFFFFF, 16))
          .append(';');
    }
    if (bgColor != null) {
      builder
          .append("background-color:#")
          .append(Integer.toString(bgColor.getRGB() & 0xFFFFFF, 16))
          .append(';');
    }
    if ((style & SimpleTextAttributes.STYLE_BOLD) != 0) {
      builder.append("font-weight:bold;");
    }
    if ((style & SimpleTextAttributes.STYLE_ITALIC) != 0) {
      builder.append("font-style:italic;");
    }
    if ((style & SimpleTextAttributes.STYLE_UNDERLINE) != 0) {
      builder.append("text-decoration:underline;");
    } else if ((style & SimpleTextAttributes.STYLE_STRIKEOUT) != 0) {
      builder.append("text-decoration:line-through;");
    }
    if (builder.length() > pos) {
      builder.insert(pos, " style=\"");
      builder.append('"');
    }
  }
 /**
  * When the item is selected then we use default tree's selection foreground. It guaranties
  * readability of selected text in any LAF.
  */
 @Override
 public void append(
     @NotNull @Nls String fragment, @NotNull SimpleTextAttributes attributes, boolean isMainText) {
   if (mySelected && isFocused()) {
     super.append(
         fragment,
         new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeSelectionForeground()),
         isMainText);
   } else if (mySelected && UIUtil.isUnderAquaBasedLookAndFeel()) {
     super.append(
         fragment,
         new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeForeground()),
         isMainText);
   } else {
     super.append(fragment, attributes, isMainText);
   }
 }