Beispiel #1
0
 private String hashable(List<ImgMatch> imgMatches) {
   StringBuilder b = new StringBuilder();
   for (ImgMatch x : imgMatches) {
     b.append(x.text() + "\n");
   }
   return b.toString();
 }
Beispiel #2
0
  public void addNewAnnotations(HashMap<String, MsgAnnotation> annotations) throws Exception {
    HashSet<String> newMsgStrs = new HashSet<String>();
    for (String msgstr : annotations.keySet()) {
      if (!matchedMsgStrs.contains(msgstr)) {
        matchedMsgStrs.add(msgstr);
        newMsgStrs.add(msgstr);
      }
    }
    final HashMap<String, Integer> numOccurrencesOfSources = new HashMap<String, Integer>();
    // gnome-mouse-properties => #of times it occurs on the current screenshot
    for (String msgidblock : this.msgidblocks) {
      String msgfsrc = msgsrc.msgSourceConciseFromMsgIdBlock(msgidblock);
      if (!numOccurrencesOfSources.containsKey(msgfsrc)) numOccurrencesOfSources.put(msgfsrc, 0);
      String msgstr = msgsrc.textFromMsgIdBlock(msgidblock);
      if (annotations.keySet().contains(msgstr)) {
        numOccurrencesOfSources.put(msgfsrc, numOccurrencesOfSources.get(msgfsrc) + 1);
      }
    }

    List<List<String>> msgsGroupedBySource = msgsrc.groupByMsgSouce(msgidblocks);
    Collections.sort(
        msgsGroupedBySource,
        new Comparator<List<String>>() {

          @Override
          public int compare(List<String> o1, List<String> o2) {
            try {
              String src1 = msgsrc.msgSourceConciseFromMsgIdBlock(o1.get(0));
              String src2 = msgsrc.msgSourceConciseFromMsgIdBlock(o2.get(0));
              return numOccurrencesOfSources.get(src2) - numOccurrencesOfSources.get(src1);
            } catch (Exception e) {
              return 0;
            }
          }
        });

    // String curMsgSource = "";
    // String curMsgSourceFound = "";
    StringBuilder msgsToBeFound = new StringBuilder();
    msgsToBeFound.append("<html><body>");
    msgsToBeFound.append("<h3>Messages Not Found:</h3>");
    StringBuilder msgsFound = new StringBuilder();
    msgsFound.append("<html><body>");
    msgsFound.append("<h3>Messages Found:</h3>");
    // for (String msgidblock : msgsrc.splitIntoMsgIdBlocks()) {
    for (List<String> msgidblockGroup : msgsGroupedBySource) {
      String msgsource = msgsrc.msgSourceConciseFromMsgIdBlock(msgidblockGroup.get(0));
      msgsFound.append("<p><b>" + msgsource + "</b></p>\n");
      msgsToBeFound.append("<p><b>" + msgsource + "</b></p>\n");
      for (String msgidblock : msgidblockGroup) {
        String msgstr = msgsrc.textFromMsgIdBlock(msgidblock);
        if (msgstr.isEmpty()) continue;
        if (matchedMsgStrs.contains(msgstr)) {
          if (newMsgStrs.contains(msgstr)) {
            msgsFound.append("<p bgcolor='#FFFF00'>" + msgstr + "</p>\n");
          } else if (annotations.keySet().contains(msgstr)) {
            msgsFound.append("<p bgcolor='#00FFFF'>" + msgstr + "</p>\n");
          } else {
            msgsFound.append("<p>" + msgstr + "</p>\n");
          }
        } else {
          msgsToBeFound.append("<p>" + msgstr + "</p>\n");
        }
      }
    }
    /*
      String msgstr = msgsrc.textFromMsgIdBlock(msgidblock);
    	if (msgstr.isEmpty())
    		continue;
    	String msgsource = msgsrc.msgSourceConciseFromMsgIdBlock(msgidblock);
    	if (matchedMsgStrs.contains(msgstr)) {
        	if (!msgsource.isEmpty() && !msgsource.equals(curMsgSourceFound)) {
        		curMsgSourceFound = msgsource;
        		msgsFound.append("<p><b>" + msgsource + "</b></p>\n");
        	}
        	if (newMsgStrs.contains(msgstr)) {
            	msgsFound.append("<p bgcolor='#FFFF00'>" + msgstr + "</p>\n");
        	} else {
            	msgsFound.append("<p>" +  msgstr + "</p>\n");
        	}
    	} else {
    		if (!msgsource.isEmpty() && !msgsource.equals(curMsgSource)) {
        		curMsgSource = msgsource;
        		msgsToBeFound.append("<p><b>" + msgsource + "</b></p>\n");
        	}
    		msgsToBeFound.append("<p>" + msgstr + "</p>\n");
    	}
    }
    */
    msgsToBeFound.append("</body></html>");
    msgsFound.append("</body></html>");
    textArea.setContentType("text/html");
    textArea.setText(msgsToBeFound.toString());
    textAreaSeen.setContentType("text/html");
    textAreaSeen.setText(msgsFound.toString());
    updateMatchCount();
  }