Libraryless. Click here for Pure Java version (2605L/20K/61K).
!636 !modern // includes string == !actionListener { !x619 // standard classes (LetterLayout, CenteredLine) !multi-line strings !721 // thread { !1000805 // awt { main { static JList list; static JTextField tfCmd; // unused static JLabel status; static JButton btnScan; !include #1000804 // ProgramScan static S menuSnippet = "#1000910"; static S menuScript; !include #1000839 // PopupMenuHelper psvm { installHelloMessage("Running programs"); JFrame frame = new JFrame("Running programs"); JPanel panel = new JPanel(new BorderLayout()); list = new JList(); panel.add(BorderLayout.CENTER, new JScrollPane(list)); new PopupMenuHelper() { void fillMenu() { try { if (menuScript == null) menuScript = loadSnippet(menuSnippet); JMenuItem mi; int idx = list.locationToIndex(point); final String item = cast list.getModel().getElementAt(idx); list.setSelectedIndex(idx); L<S> tok = javaTok(menuScript); for (int i = 1; i+4 < tok.size(); i += 2) if (tok.get(i+2).equals("=")) { final S snip = unquote(tok.get(i+4)); S text = unquote(tok.get(i)); mi = new JMenuItem(text); mi.addActionListener(actionListener { runCustom(snip, item); }); menu.add(mi); } } catch (Throwable e) { popup(e); } } }.install(list); tfCmd = new JTextField(); //panel.add(BorderLayout.SOUTH, tfCmd) status = new JLabel(" "); btnScan = new JButton("Scan again"); btnScan.addActionListener(actionListener { scan(); }); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(BorderLayout.CENTER, status); bottom.add(BorderLayout.EAST, btnScan); panel.add(BorderLayout.SOUTH, bottom); /*tfCmd.addActionListener(actionListener { tfCmd.selectAll(); String cmd = tfCmd.getText(); runCmd(cmd); });*/ /*frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { tfCmd.requestFocus(); } });*/ frame.add(panel); frame.setBounds(100, 100, 500, 400); frame.setVisible(true); exitOnFrameClose(frame); scan(); } static void scan() { thread { status("Scanning for programs..."); btnScan.setEnabled(false); try { final List<ProgramScan.Program> programs = ProgramScan.scan(); status("Done. " + programs.size() + " program(s) found."); awt { new DefaultListModel<S> model; for (ProgramScan.Program p : programs) model.addElement("Port " + p.port + ": " + p.helloString); list.setModel(model); } } catch (Throwable e) { e.printStackTrace(); status("Scan error: " + e); } btnScan.setEnabled(true); } } static void status(final S s) { awt { status.setText(s); } } static void runCustom(S worker, S item) { item = item.replaceAll("^[^0-9]*", ""); int i = item.indexOf(":"); runCmdWithTerminal(worker + " " + item.substring(0, i) + " by the name of " + quote(item.substring(i+1).trim())); } }
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: | 835 / 1261 |
Referenced in: | [show references] |