Libraryless. Click here for Pure Java version (7959L/57K/196K).
1 | !752 |
2 | |
3 | static L<Map> origData, data; |
4 | static S dir = "/"; |
5 | static JTable table; |
6 | static S ip; |
7 | |
8 | p-substance { |
9 | if (ip == null) ip = gateway(); |
10 | final JTextField tf = jTextField(ip); |
11 | showForm("IP to browse:", tf, r { |
12 | ip = trim(tf.getText()); |
13 | load("dir"); |
14 | browse(dir); |
15 | }); |
16 | } |
17 | |
18 | svoid browse(S path) { |
19 | dir = path; |
20 | save("dir"); |
21 | S s = sendToAwareness(ip, "list directory *", dir); |
22 | origData = (L) safeUnstructure(s); |
23 | data = sortedByField("Name", map(func(Map map) { |
24 | putKeysFirst(renameKeys(map, |
25 | "dir", "Directory?", "m", "Last modified", |
26 | "n", "Name", "l", "File Size (Bytes)"), |
27 | "Name", "Directory?") |
28 | }, origData)); |
29 | |
30 | S title = dir + " [" + ip + "]"; |
31 | bool firstTime = table == null; |
32 | table = showTableWithSearcher(table, data, title); |
33 | |
34 | if (firstTime) { |
35 | onDoubleClickOrEnter(table, voidfunc(int row) { |
36 | Map map = getTableLineAsMap(table, row); |
37 | if (map == null) ret; |
38 | Map map2 = findByField(origData, "n", map.get("Name")); |
39 | print("map2=" + struct(map2)); |
40 | S name = getString(map, "Name"); |
41 | if (isTrue(_get(map2, "dir"))) |
42 | browse(addSlash(dir) + name); |
43 | else |
44 | swingOpenPhoneFile(ip, addSlash(dir) + name); |
45 | }); |
46 | registerKey(getFrame(table), KeyEvent.VK_BACK_SPACE, "Back", r { |
47 | browse(or2(substring(dir, 0, dir.lastIndexOf('/')), "/")); |
48 | }); |
49 | |
50 | tablePopupMenu(table, voidfunc(JPopupMenu menu, int row) { |
51 | Map map = getTableLineAsMap(table, row); |
52 | if (map == null) ret; |
53 | Map map2 = findByField(origData, "n", map.get("Name")); |
54 | print("map2=" + struct(map2)); |
55 | final S name = getString(map, "Name"); |
56 | final S path = addSlash(dir) + name; |
57 | if (!isTrue(_get(map2, "dir"))) |
58 | addMenuItem(menu, "Download File", r { |
59 | thread "Downloading" { |
60 | print("Downloading from phone..."); |
61 | byte[] data = readFileFromPhone(ip, path); |
62 | File f = userHome("Downloads/" + name); |
63 | saveBinaryFile(f, data); |
64 | print("Saved: " + f.getAbsolutePath()); |
65 | } |
66 | }); |
67 | }); |
68 | } |
69 | } |
Began life as a copy of #1004132
download show line numbers debug dex old transpilations
Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, cysqohhbtkwd, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xinetxnxrdbb, xlripclqcsxi, zluxfztcnsid
No comments. add comment
Snippet ID: | #1006135 |
Snippet name: | Remote Machine File Browser [Swing] |
Eternal ID of this version: | #1006135/1 |
Text MD5: | 8e020d691f56addee594f06ba1619eb0 |
Transpilation MD5: | b113b22dcfb90812a680da0c58be75de |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-01-12 03:18:27 |
Source code size: | 2153 bytes / 69 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 537 / 690 |
Referenced in: | [show references] |