Libraryless. Click here for Pure Java version (2605L/20K/61K).
1 | !636 |
2 | !modern // includes string == |
3 | !actionListener { |
4 | !x619 // standard classes (LetterLayout, CenteredLine) |
5 | !multi-line strings |
6 | !721 // thread { |
7 | !1000805 // awt { |
8 | |
9 | main { |
10 | static JList list; |
11 | static JTextField tfCmd; // unused |
12 | static JLabel status; |
13 | static JButton btnScan; |
14 | |
15 | !include #1000804 // ProgramScan |
16 | |
17 | static S menuSnippet = "#1000910"; |
18 | static S menuScript; |
19 | |
20 | !include #1000839 // PopupMenuHelper |
21 | |
22 | psvm { |
23 | installHelloMessage("Running programs"); |
24 | JFrame frame = new JFrame("Running programs"); |
25 | |
26 | JPanel panel = new JPanel(new BorderLayout()); |
27 | |
28 | list = new JList(); |
29 | panel.add(BorderLayout.CENTER, new JScrollPane(list)); |
30 | |
31 | new PopupMenuHelper() { |
32 | void fillMenu() { |
33 | try { |
34 | if (menuScript == null) |
35 | menuScript = loadSnippet(menuSnippet); |
36 | |
37 | JMenuItem mi; |
38 | int idx = list.locationToIndex(point); |
39 | final String item = cast list.getModel().getElementAt(idx); |
40 | list.setSelectedIndex(idx); |
41 | |
42 | L<S> tok = javaTok(menuScript); |
43 | for (int i = 1; i+4 < tok.size(); i += 2) |
44 | if (tok.get(i+2).equals("=")) { |
45 | final S snip = unquote(tok.get(i+4)); |
46 | S text = unquote(tok.get(i)); |
47 | mi = new JMenuItem(text); |
48 | mi.addActionListener(actionListener { |
49 | runCustom(snip, item); |
50 | }); |
51 | menu.add(mi); |
52 | } |
53 | } catch (Throwable e) { |
54 | popup(e); |
55 | } |
56 | |
57 | } |
58 | }.install(list); |
59 | |
60 | tfCmd = new JTextField(); |
61 | //panel.add(BorderLayout.SOUTH, tfCmd) |
62 | |
63 | status = new JLabel(" "); |
64 | btnScan = new JButton("Scan again"); |
65 | btnScan.addActionListener(actionListener { scan(); }); |
66 | JPanel bottom = new JPanel(new BorderLayout()); |
67 | bottom.add(BorderLayout.CENTER, status); |
68 | bottom.add(BorderLayout.EAST, btnScan); |
69 | panel.add(BorderLayout.SOUTH, bottom); |
70 | |
71 | /*tfCmd.addActionListener(actionListener { |
72 | tfCmd.selectAll(); |
73 | String cmd = tfCmd.getText(); |
74 | runCmd(cmd); |
75 | });*/ |
76 | |
77 | /*frame.addWindowListener(new WindowAdapter() { |
78 | public void windowOpened(WindowEvent e) { |
79 | tfCmd.requestFocus(); |
80 | } |
81 | });*/ |
82 | |
83 | frame.add(panel); |
84 | frame.setBounds(100, 100, 500, 400); |
85 | frame.setVisible(true); |
86 | exitOnFrameClose(frame); |
87 | |
88 | scan(); |
89 | } |
90 | |
91 | static void scan() { |
92 | thread { |
93 | status("Scanning for programs..."); |
94 | btnScan.setEnabled(false); |
95 | try { |
96 | final List<ProgramScan.Program> programs = ProgramScan.scan(); |
97 | status("Done. " + programs.size() + " program(s) found."); |
98 | |
99 | awt { |
100 | new DefaultListModel<S> model; |
101 | for (ProgramScan.Program p : programs) |
102 | model.addElement("Port " + p.port + ": " + p.helloString); |
103 | list.setModel(model); |
104 | } |
105 | } catch (Throwable e) { |
106 | e.printStackTrace(); |
107 | status("Scan error: " + e); |
108 | } |
109 | btnScan.setEnabled(true); |
110 | } |
111 | } |
112 | |
113 | static void status(final S s) { |
114 | awt { status.setText(s); } |
115 | } |
116 | |
117 | static void runCustom(S worker, S item) { |
118 | item = item.replaceAll("^[^0-9]*", ""); |
119 | int i = item.indexOf(":"); |
120 | runCmdWithTerminal(worker + " " + item.substring(0, i) + " by the name of " + quote(item.substring(i+1).trim())); |
121 | } |
122 | } |
Began life as a copy of #1000794
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: | #1000795 |
Snippet name: | swing-top - List running programs (works) |
Eternal ID of this version: | #1000795/1 |
Text MD5: | cfd4c7235d35fa2a0f9035536075ba80 |
Transpilation MD5: | bd202d89754c3da31b469cae7dc8612d |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-09-07 21:58:35 |
Source code size: | 3468 bytes / 122 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 836 / 1262 |
Referenced in: | [show references] |