Libraryless. Click here for Pure Java version (8141L/58K/209K).
!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<S> 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+)</a> - (.*?)<br>").matcher(page); final new L<Map> 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); } }
Began life as a copy of #1004469
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004472 |
Snippet name: | Snippet Search With Table [dev.] |
Eternal ID of this version: | #1004472/3 |
Text MD5: | 17e30a8bce70b3f497aa2c61535a0e8d |
Transpilation MD5: | 78ee291284d6fa160162499ca77ba662 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-05-04 09:48:13 |
Source code size: | 3313 bytes / 129 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 557 / 648 |
Version history: | 2 change(s) |
Referenced in: | -