/**
   * Saves the content of the comment editor as the new comment for the given {@link
   * WorkflowAnnotation}.
   *
   * @param selected the annotation for which the content of the editor pane should be saved as new
   *     comment
   */
  private void saveEdit(final WorkflowAnnotation selected) {
    if (editPane == null) {
      return;
    }
    HTMLDocument document = (HTMLDocument) editPane.getDocument();
    StringWriter writer = new StringWriter();
    try {
      editPane.getEditorKit().write(writer, document, 0, document.getLength());
    } catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
      // should not happen
      LogService.getRoot()
          .log(
              Level.WARNING,
              "com.rapidminer.gui.flow.processrendering.annotations.AnnotationsDecorator.cannot_save");
    }
    String comment = writer.toString();
    comment = AnnotationDrawUtils.removeStyleFromComment(comment);
    Rectangle2D loc = selected.getLocation();
    Rectangle2D newLoc =
        new Rectangle2D.Double(
            loc.getX(),
            loc.getY(),
            editPane.getBounds().getWidth(),
            editPane.getBounds().getHeight());
    selected.setLocation(newLoc);

    boolean overflowing = false;
    int prefHeight =
        AnnotationDrawUtils.getContentHeight(
            AnnotationDrawUtils.createStyledCommentString(comment, selected.getStyle()),
            (int) newLoc.getWidth());
    if (prefHeight > newLoc.getHeight()) {
      overflowing = true;
    }
    selected.setOverflowing(overflowing);

    model.setAnnotationComment(selected, comment);
  }