code: private static IRenderingElement recolor(IRenderingElement element, Color color) {
          if (element instanceof ElementGroup) {
              ElementGroup orgGroup = (ElementGroup) element;
              ElementGroup newGroup = new ElementGroup();
              for (IRenderingElement child : orgGroup) {
                  newGroup.add(recolor(child, color));
              }
              return newGroup;
          } else if (element instanceof LineElement) {
              LineElement lineElement = (LineElement) element;
              return new LineElement(lineElement.firstPointX, lineElement.firstPointY, lineElement.secondPointX,
                      lineElement.secondPointY, lineElement.width, color);
          } else if (element instanceof GeneralPath) {
              return ((GeneralPath) element).recolor(color);
          }
          throw new IllegalArgumentException("Cannot highlight rendering element, " + element.getClass());
      }
docs: Recolor a rendering element after it has been generated. Since rendering elements are
  immutable, the input element remains unmodified.
  
  @param element the rendering element
  @param color   the new color
  @return recolored rendering element