Uses 3874K of libraries. Click here for Pure Java version (7134L/50K/177K).
1 | !7 |
2 | |
3 | static JFrame frame; |
4 | static JList list; |
5 | static JTextField tfCmd; |
6 | static JLabel status; |
7 | static JButton btnReload, btnRun, btnClear; |
8 | static S submittedInput; |
9 | static volatile boolean searching; |
10 | static long lastSearch; // time of last search |
11 | |
12 | static int searchDelay = 100; |
13 | static int maxResults = 100; |
14 | static int autoResearchInterval = 30000; // 30 secs |
15 | |
16 | static L<S> actionHistory = synchroList(); |
17 | |
18 | p-substance { |
19 | frame = showFrame(); |
20 | list = new JList; |
21 | |
22 | ActionListener go = actionListener { |
23 | tfCmd.selectAll(); |
24 | search(true); |
25 | }; |
26 | |
27 | btnReload = new JButton(isWindows() ? "Reload" : "\u27F3"); |
28 | btnReload.addActionListener(go); |
29 | |
30 | btnClear = new JButton("X"); |
31 | btnClear.setToolTipText("Show latest"); |
32 | btnClear.addActionListener(actionListener { tfCmd.setText(""); }); |
33 | |
34 | tfCmd = new JTextField; |
35 | |
36 | JPanel controls = jflow(btnClear, btnReload); |
37 | |
38 | JPanel north = centerAndEast( |
39 | withLabel("Search term:", tfCmd), |
40 | controls); |
41 | |
42 | /*btnRun = new JButton("Run"); |
43 | btnRun.addActionListener(actionListener { |
44 | run(); |
45 | });*/ |
46 | |
47 | status = new JLabel(" "); |
48 | JPanel panel = northCenterAndSouth(north, list, status); |
49 | |
50 | tfCmd.addActionListener(go); |
51 | |
52 | frame.addWindowListener(new WindowAdapter { |
53 | public void windowOpened(WindowEvent e) { |
54 | tfCmd.requestFocus(); |
55 | } |
56 | |
57 | public void windowActivated(WindowEvent e) { |
58 | search(false); |
59 | } |
60 | }); |
61 | |
62 | installTimer(tfCmd, new Runnable() { |
63 | String lastContents; |
64 | boolean autoSearchOn = true; |
65 | |
66 | public void run() { |
67 | String text = getInput(); |
68 | if (text.equals(lastContents)) { |
69 | if (now() > lastSearch + autoResearchInterval || |
70 | (!text.equals(submittedInput) && autoSearchOn && !searching)) |
71 | search(false); |
72 | } else |
73 | lastContents = text; |
74 | } |
75 | }, searchDelay); |
76 | |
77 | frame.add(panel); |
78 | frame.setBounds(100, 100, 500, 400); |
79 | |
80 | search(false); |
81 | } |
82 | |
83 | static S getInput() { |
84 | ret tfCmd.getText().trim(); |
85 | } |
86 | |
87 | static void search(String cmd, final boolean requestFocus) ctex { |
88 | searching = true; |
89 | try { |
90 | status("Searching " + quote(cmd) + "..."); |
91 | if (empty(cmd)) cmd = "_"; |
92 | //if (cbAll.isSelected()) |
93 | //cmd += " type:runnable"; |
94 | S page = loadPage("http://tinybrain.de:8080/tb/search.php?q=" + urlencode(cmd) + "&limit=" + maxResults + "&sort=modified"); |
95 | Matcher m = Pattern.compile(">(#\\d+)</a> - (.*?)<br>").matcher(page); |
96 | |
97 | final new DefaultListModel model; |
98 | while (m.find()) { |
99 | String title = m.group(2); |
100 | title = join(dropAllTags(htmlcoarsetok(title))); |
101 | model.addElement(htmldecode(m.group(1) + " - " + title)); |
102 | } |
103 | |
104 | awt { |
105 | list.setModel(model); |
106 | status("Found " + model.size() + (model.size() == maxResults ? "+" : "") + " snippet(s)."); |
107 | if (requestFocus) |
108 | tfCmd.requestFocus(); |
109 | } |
110 | } finally { |
111 | searching = false; |
112 | } |
113 | } |
114 | |
115 | static void status(final S s) { |
116 | awt { status.setText(s); } |
117 | } |
118 | |
119 | static void search(final boolean requestFocus) { |
120 | submittedInput = getInput(); |
121 | lastSearch = now(); |
122 | final String cmd = submittedInput; |
123 | actionHistory.add(format3("*: Searching *", now(), cmd)); |
124 | thread { |
125 | search(cmd, requestFocus); |
126 | } |
127 | } |
Began life as a copy of #1000825
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: | #1004469 |
Snippet name: | Simple Snippet Search |
Eternal ID of this version: | #1004469/5 |
Text MD5: | 85d842c1d8ef92fa0553ad9f3b5e3724 |
Transpilation MD5: | 8e4037f4affd8c7a4ff8a5256ec714cf |
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:51:29 |
Source code size: | 3293 bytes / 127 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 589 / 692 |
Version history: | 4 change(s) |
Referenced in: | [show references] |