!7 static int topTenSize = 1000, maxImages = 1000; static MultiSetAndTopTen mstt; // holds md5 static SS comments; p-subst { autoRestart(); comments = persistentHashMap("Comments"); mstt = new MultiSetAndTopTen( l_persistentTreeMap("Images + count"), l_persistentList("Top Ten")); mstt.maxEntries = maxImages; mstt.setTopTenSize(topTenSize); thread "Collect" { repeat with sleep 10 { deleteUnusedImages(); collectIt(); } } showButtons( "Top " + topTenSize, f showTopTen, "Clear", rThread(f clearIt), "Current Screen", rThread(f currentScreen)); } svoid collectIt { print("Collecting..."); lock dbLock(); long time = sysNow(); BWImage img = shootScreenBW(); L segments = autoSegment(img); for (Rect r : segments) { RGBImage clip = img.clip(r).toRGB(); S md5 = rgbMD5(clip); mstt.add(md5); File f = imgFile(md5); if (!f.exists()) savePNG(f, clip); } print(n(segments, "segment") + " on screen. " + n(mstt.numEntries(), "image") + " in DB. " + n(mstt.numOccurrences(), "occurrence") + ". DB size: " + toM(guessClusteredDirSize(programDir())) + " MB"); done2(time); } static File imgFile(S md5) { ret screenClipFileForMD5(md5); } svoid showTopTen { final L data = map(mstt.topTen(), func(S md5) { litorderedmap( "Image" := loadBufferedImageOpt(imgFile(md5)), "Comment" := unnull(comments.get(md5)), "MD5" := md5, "Occurrences" := mstt.get(md5)) }); final JTable table = setRowHeight(40, showTable(data, "Top " + l(data))); tablePopupMenuItemAndDoubleClick(table, "Comment...", voidfunc(final Int row) { fS md5 = getString(data.get(row), "MD5"); final JTextField tf = jtextfield(comments.get(md5)); showFormTitled("Comment image " + md5, //"MD5", md5, "Image", new ImageChooser(loadBufferedImage(imgFile(md5))), "Comment", tf, r { S text = getTextTrim(tf); comments.put(md5, nullIfEmpty(text)); ((DefaultTableModel) table.getModel()).setValueAt(text, row, 1); }); }); } // Keep all images commented on & all in top 1000 svoid deleteUnusedImages { Set set = ciSet(); set.addAll(mstt.entries()); set.addAll(keys(comments)); for (File f : filesEndingWith(screenClipsDir(), ".png")) if (!set.contains(toLower(dropSuffix(".png", f.getName())))) { print("Deleting " + f); f.delete(); } } svoid clearIt { lock dbLock(); mstt.clear(); } svoid currentScreen { clearIt(); collectIt(); showTopTen(); }