Transpiled version (2515L) is out of date.
1 | !636 |
2 | !modern // includes string == |
3 | !actionListener { |
4 | !x619 // standard classes (LetterLayout, CenteredLine) |
5 | !multi-line strings |
6 | !awt { |
7 | |
8 | main { |
9 | static JList list; |
10 | static JTextField tfCmd; |
11 | static JLabel status; |
12 | static S submittedInput; |
13 | static int searchDelay = 100; |
14 | static volatile boolean searching; |
15 | |
16 | !include #1000839 // PopupMenuHelper |
17 | |
18 | psvm { |
19 | installHelloMessage("JavaX"); |
20 | JFrame frame; |
21 | try { |
22 | frame = new JFrame("JavaX v3"); |
23 | } catch (HeadlessException e) { |
24 | System.out.println("We're headless..."); |
25 | return; |
26 | } |
27 | |
28 | JPanel panel = new JPanel(new BorderLayout()); |
29 | |
30 | list = new JList(); |
31 | panel.add(BorderLayout.CENTER, new JScrollPane(list)); |
32 | |
33 | new PopupMenuHelper() { |
34 | void fillMenu() { |
35 | JMenuItem mi; |
36 | int idx = list.locationToIndex(point); |
37 | final String item = cast list.getModel().getElementAt(idx); |
38 | list.setSelectedIndex(idx); |
39 | mi = new JMenuItem("RUN! (warning: no questions asked)"); |
40 | mi.addActionListener(actionListener { run(item); }); |
41 | menu.add(mi); |
42 | mi = new JMenuItem("Run with arguments..."); |
43 | mi.addActionListener(actionListener { runWithArguments(item); }); |
44 | menu.add(mi); |
45 | } |
46 | }.install(list); |
47 | |
48 | tfCmd = new JTextField(); |
49 | panel.add(BorderLayout.NORTH, withLabel("Search term:", tfCmd)); |
50 | |
51 | status = new JLabel(" "); |
52 | panel.add(BorderLayout.SOUTH, status); |
53 | |
54 | tfCmd.addActionListener(actionListener { |
55 | tfCmd.selectAll(); |
56 | final String cmd = tfCmd.getText(); |
57 | thread { |
58 | try { |
59 | tfCmd.setEnabled(false); |
60 | search(cmd); |
61 | } finally { |
62 | tfCmd.setEnabled(true); |
63 | } |
64 | } |
65 | }); |
66 | |
67 | frame.addWindowListener(new WindowAdapter() { |
68 | public void windowOpened(WindowEvent e) { |
69 | tfCmd.requestFocus(); |
70 | } |
71 | }); |
72 | |
73 | installTimer(tfCmd, new Runnable() { |
74 | String lastContents; |
75 | boolean autoSearchOn = true; |
76 | |
77 | public void run() { |
78 | String text = tfCmd.getText(); |
79 | if (text.equals(lastContents)) { |
80 | if (!text.equals(submittedInput) && autoSearchOn && !searching) |
81 | doIt(); |
82 | } else |
83 | lastContents = text; |
84 | } |
85 | }, searchDelay); |
86 | |
87 | frame.add(panel); |
88 | frame.setBounds(100, 100, 500, 400); |
89 | frame.setVisible(true); |
90 | exitOnFrameClose(frame); |
91 | |
92 | search(""); |
93 | } |
94 | |
95 | static void search(String cmd) ctex { |
96 | searching = true; |
97 | try { |
98 | status("Searching " + quote(cmd) + "..."); |
99 | if (cmd == "") cmd = "%"; |
100 | S page = loadPage("http://tinybrain.de:8080/tb/search.php?q=" + urlencode(cmd + " type:runnable")); |
101 | Matcher m = Pattern.compile(">(#\\d+)</a> - (.*?)<br>").matcher(page); |
102 | |
103 | final new DefaultListModel<S> model; |
104 | while (m.find()) |
105 | model.addElement(htmldecode(m.group(1) + " - " + m.group(2))); |
106 | |
107 | awt { |
108 | list.setModel(model); |
109 | status("Found " + model.size() + " runnable(s)."); |
110 | tfCmd.requestFocus(); |
111 | } |
112 | } finally { |
113 | searching = false; |
114 | } |
115 | } |
116 | |
117 | static void status(final S s) { |
118 | awt { status.setText(s); } |
119 | } |
120 | |
121 | static void run(S item) { |
122 | int i = item.indexOf(' '); |
123 | if (i >= 0) item = item.substring(0, i); |
124 | long id = parseSnippetID(item); |
125 | print("Running " + id); |
126 | nohupJavax("#1000874".substring(1) + " " + id); |
127 | } |
128 | |
129 | static void runWithArguments(S item) { |
130 | // TODO: run a dialog for that |
131 | } |
132 | |
133 | static void doIt() { |
134 | submittedInput = tfCmd.getText(); |
135 | thread { |
136 | search(submittedInput); |
137 | } |
138 | } |
139 | } |
Began life as a copy of #1000825
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000876 |
Snippet name: | Outdated version of swing-start |
Eternal ID of this version: | #1000876/1 |
Text MD5: | 18a35eeedbeb7673c72cb93c86c8ff65 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-09-13 15:07:12 |
Source code size: | 3741 bytes / 139 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 622 / 725 |
Referenced in: | [show references] |