!7 sclass SnippetSearch extends DynModule { transient JList list; transient JTextField tfCmd; transient JLabel status; transient JButton btnReload; transient S submittedInput; transient volatile boolean searching; int searchDelay = 100; int maxResults = 100; int autoResearchInterval = 30000; // 30 secs *() {} *(VF1 *onSelected) {} JComponent visualize() { list = new JList; //onDoubleClickAndEnter(list, r { ok() }); ActionListener go = actionListener { tfCmd.selectAll(); search(true); }; btnReload = new JButton(isWindows() ? "Reload" : "\u27F3"); btnReload.addActionListener(go); tfCmd = new JTextField; btnOK = listDependentButton(list, "OK", r { ok(); }); JPanel controls = jflow(btnClear, btnReload, btnOK); JPanel north = centerAndEast( withLabel("Search term:", tfCmd), controls); status = new JLabel(" "); JPanel panel = northCenterAndSouth(north, list, status); onEnter(tfCmd, r ok); frame.addWindowListener(new WindowAdapter { public void windowOpened(WindowEvent e) { tfCmd.requestFocus(); } public void windowActivated(WindowEvent e) { search(false); } }); ownTimer(installTimer(tfCmd, new Runnable { String lastContents; boolean autoSearchOn = true; public void run() { String text = getInput(); if (text.equals(lastContents)) { if (now() > lastSearch + autoResearchInterval || (!text.equals(submittedInput) && autoSearchOn && !searching)) search(false); } else lastContents = text; } }, searchDelay)); search(false); ret panel; } S getInput() { ret tfCmd.getText().trim(); } void search(S cmd) { searching = true; try { status("Searching " + quote(cmd) + "..."); if (empty(cmd)) cmd = "_"; if (nempty(forceType)) cmd += " type:" + forceType; L l = tbSearch_url("http://tinybrain.de:8080/tb/search.php?q=" + urlencode(cmd) + "&limit=" + maxResults + "&sort=modified" + standardCredentials()); final new DefaultListModel model; for (Snippet s : l) model.addElement(s.id + " - " + s.title); swing { list.setModel(model); if (model.size() != 0) list.setSelectedIndex(0); status("Found " + model.size() + (model.size() == maxResults ? "+" : "") + " snippet(s)."); } } finally { searching = false; } } void status(final S s) { setText(status, s); } void search() { submittedInput = getInput(); lastSearch = now(); final String cmd = submittedInput; thread { search(cmd); } } }