package org.broad.igv.util;

import java.util.List;
import java.util.Map;

public class FormatUtils {

    private static final int MAX_CHARS_PER_LINE = 50;

    public static void printHtml(Map<String, String> map, StringBuffer buffer, int max) {

        if (map == null || map.isEmpty()) return;

        int count = 0;
        buffer.append("<br>");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String value = entry.getValue();

            buffer.append("<b>" + entry.getKey() + "</b>");
            buffer.append(":&nbsp;");
            String ts = lineWrapString(value, MAX_CHARS_PER_LINE);

            buffer.append(ts);
            buffer.append("<br/>");
            count++;

            if (++count > max) {
                buffer.append("...");
                break;
            }

        }
    }

    private static String lineWrapString(String input, int maxCharsPerLine) {
        int lines = input.length() / maxCharsPerLine + 1;
        if (lines == 1) return input;

        String result = input.substring(0, maxCharsPerLine);
        for (int lineNum = 1; lineNum < lines; lineNum++) {
            int start = lineNum * maxCharsPerLine;
            int end = Math.min(start + maxCharsPerLine, input.length());
            result += "<br/>" + input.substring(start, end);
        }
        return result;
    }


}

@@ -577,18 +577,205 @@
 tring ts
- =
+;%0A            if (value.startsWith(%22https://%22)) %7B%0A                ts = %22%3Ca href='%22 + value + %22'%3E%22 + value + %22%3C/a%3E%22;%0A            %7D else %7B%0A                ts = value.startsWith(%22%3C%22) ? value :
  lineWra
@@ -809,16 +809,30 @@
 R_LINE);
+%0A            %7D
 %0A%0A      

Create hyperlinks for feature attribute values that start with "https://"