!7 static JFrame frame; static JTable table; static JTextField tfCmd; static JLabel status; static JButton btnReload, btnClear; static S submittedInput; static volatile boolean searching; static long lastSearch; // time of last search static int searchDelay = 100; static int maxResults = 100; static int autoResearchInterval = 30000; // 30 secs static L actionHistory = synchroList(); p { frame = showFrame(); table = sexyTable(); ActionListener go = actionListener { tfCmd.selectAll(); search(true); }; btnReload = new JButton(isWindows() ? "Reload" : "\u27F3"); btnReload.addActionListener(go); btnClear = new JButton("X"); btnClear.setToolTipText("Show latest"); btnClear.addActionListener(actionListener { tfCmd.setText(""); }); tfCmd = new JTextField; JPanel controls = jflow(btnClear, btnReload); JPanel north = centerAndEast( withLabel("Search term:", tfCmd), controls); /*btnRun = new JButton("Run"); btnRun.addActionListener(actionListener { run(); });*/ status = new JLabel(" "); JPanel panel = northCenterAndSouth(north, table, status); tfCmd.addActionListener(go); frame.addWindowListener(new WindowAdapter { public void windowOpened(WindowEvent e) { tfCmd.requestFocus(); } public void windowActivated(WindowEvent e) { search(false); } }); 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); frame.add(panel); frame.setBounds(100, 100, 500, 400); search(false); } static S getInput() { ret tfCmd.getText().trim(); } static void search(String cmd, final boolean requestFocus) ctex { searching = true; try { status("Searching " + quote(cmd) + "..."); if (empty(cmd)) cmd = "_"; //if (cbAll.isSelected()) //cmd += " type:runnable"; S page = loadPage("http://tinybrain.de:8080/tb/search.php?q=" + urlencode(cmd) + "&limit=" + maxResults + "&sort=modified"); Matcher m = Pattern.compile(">(#\\d+) - (.*?)
").matcher(page); final new L data; while (m.find()) { String title = m.group(2); title = join(dropAllTags(htmlcoarsetok(title))); data.add(litorderedmap("ID - Name", m.group(1) + htmldecode(title), "Type", "?")); } dataToTable_uneditable(table, data); awt { status("Found " + l(data) + (l(data) == maxResults ? "+" : "") + " snippet(s)."); if (requestFocus) tfCmd.requestFocus(); } } finally { searching = false; } } static void status(final S s) { awt { status.setText(s); } } static void search(final boolean requestFocus) { submittedInput = getInput(); lastSearch = now(); final String cmd = submittedInput; actionHistory.add(format3("*: Searching *", now(), cmd)); thread { search(cmd, requestFocus); } }