private StringBuilder representResults(List<RecognitionResult> results) { StringBuilder sb = new StringBuilder(); if (results.isEmpty()) { return representEmptyResults(); } String playImgSrc = getClass().getClassLoader().getResource(ImageResourcesEnum.play.getCode()).toString(); sb.append(getI18n().getMessage(TARGET)) .append(html(": <a href=\"play={0,number,#}\">", -1)) .append( html( "<img src=\"{0}\" alt=\"play\" border=\"0\" width=\"24\" height=\"24\" />", playImgSrc)) .append("</a>"); sb.append("<table class=\"resultTable\">"); sb.append("<tr><th>") .append(getI18n().getMessage(SAMPLE_LABEL)) .append("</th><th>") .append(getI18n().getMessage(TOTAL_SCORE)) .append("</th><th>") .append(FEATURE) .append("</th><th>") .append(FEATURE_SCORE) .append("</th><th>") .append(FEATURE_DISTANCE) .append("</th></tr>"); for (RecognitionResult recognitionResult : results) { StringBuilder subTable = new StringBuilder(); int rowsSize = 1; String selectionClass = "notSelected"; if (recognitionResult.getInfo().getId().equals(selectedSampleId)) { selectionClass = "selected"; rowsSize = recognitionResult.getScores().size() + 1; for (Entry<String, Double> scoreEntry : recognitionResult.getScores().entrySet()) { Double distance = recognitionResult.getDetails().getDistances().get(scoreEntry.getKey()); subTable.append("<tr>"); subTable .append(html("<td class=\"{0}\">", selectionClass)) .append(html("<a href=\"show={0}\">", scoreEntry.getKey())) .append(getI18n().getMessage(scoreEntry.getKey())) .append("</a>") .append("</td>") .append(html("<td class=\"{0}\">", selectionClass)) .append(getI18n().getDecimalFormat().format(scoreEntry.getValue())) .append("</td>") .append(html("<td class=\"{0}\">", selectionClass)) .append(getI18n().getDecimalFormat().format(distance)) .append("</td>"); subTable.append("</tr>"); } } sb.append("<tr>"); sb.append(html("<td ROWSPAN=\"{0}\" class=\"{1}\">", rowsSize, selectionClass)); sb.append(html("<a href=\"play={0}\">", recognitionResult.getInfo().getId())) .append( html( "<img src=\"{0}\" alt=\"play\" border=\"0\" width=\"24\" height=\"24\" />", playImgSrc)) .append("</a>") .append(html("<a href=\"show={0}\">", recognitionResult.getInfo().getId())); if (recognitionResult.getInfo().getId().equals(selectedSampleId)) { // collapsed + sb.append("⊟"); } else { // expanded - sb.append("⊞"); } sb.append(recognitionResult.getInfo().getName()).append("</a>"); // show expanded id if (recognitionResult.getInfo().getId().equals(selectedSampleId)) { sb.append("<span>[id=").append(recognitionResult.getInfo().getId()).append("]</span>"); } sb.append("</td>"); sb.append(html("<td ROWSPAN=\"{0}\" class=\"{1}\">", rowsSize, selectionClass)) .append(getI18n().getDecimalFormat().format(recognitionResult.getDistance())) .append("</td>"); // how features are generated if (rowsSize == 1) { sb.append(html("<td class=\"{0}\">", selectionClass)).append("</td>"); sb.append(html("<td class=\"{0}\">", selectionClass)).append("</td>"); sb.append(html("<td class=\"{0}\">", selectionClass)).append("</td>"); } sb.append("</tr>"); sb.append(subTable); } sb.append("</table>"); return sb; }