Libraryless. Click here for Pure Java version (15174L/108K).
1 | !7 |
2 | |
3 | sclass FilesInDirectory extends DynSCP { |
4 | new DynModuleRef mate; |
5 | S dir; |
6 | L<S> files; |
7 | |
8 | transient JTable table; |
9 | |
10 | File dirObject() { ret newFile(dir); } |
11 | |
12 | JComponent visualize2() { |
13 | if (table == null) { |
14 | table = sexyTable(); |
15 | onDoubleClickOrEnter(table, voidfunc(int row) { |
16 | final File f = newFile(newFile(dir), (S) getTableCell(table, row, 0)); |
17 | if (!f.isDirectory()) ret; |
18 | thread { |
19 | S info = dm_showNewModule("#1015916/DirectoryInfo"); |
20 | call(dm_getModule(info), 'setDir, f); |
21 | call(dm_getModule(info), 'setAllowedToLook, true); |
22 | S files = dm_showNewModule("#1016457/FilesInDirectory"); |
23 | call(dm_getModule(files), 'setMate, info); |
24 | } |
25 | }); |
26 | updateTable(); |
27 | } |
28 | if (mate! == null) ret jcenteredlabel("Need directory"); |
29 | ret table; |
30 | } |
31 | |
32 | void update { |
33 | int oldChangeCount = mate! == null ? -1 : changeCount; |
34 | try { |
35 | if (mate! != null && !dm_moduleStillThere(mate!)) mate.set(null); |
36 | if (mate! == null) |
37 | if (setField(mate := DynModuleRef(print("Mate: ", dm_findMateOfType(this, 'DirectoryInfo))))) |
38 | revisualize2(); |
39 | if (mate == null) ret; |
40 | setField(dir := (S) call(mate!, 'getDir)); |
41 | L<S> files = castCall(mate!, 'getFiles); |
42 | if (this.files != files) setField(+files); |
43 | } finally { |
44 | if (changeCount != oldChangeCount) updateTable(); |
45 | } |
46 | } |
47 | |
48 | void updateTable { |
49 | if (dir == null || table == null) ret with setModuleName("Files in directory"); |
50 | L<File> l = sortFilesByDate( |
51 | fileNamesInDirToFile(new File(dir), files)); |
52 | dataToTable_uneditable(map(func(File f) -> Map { |
53 | litorderedmap( |
54 | "Name" := f.getName(), |
55 | "Size" := f.isDirectory() ? "Directory" : toK(fileSize(f)) + " K") |
56 | }, l), table); |
57 | setModuleName(files == null |
58 | ? "Not allowed to look in directory " + fileName(dirObject()) |
59 | : n2(l, "element") + " in directory " + fileName(dirObject())); |
60 | } |
61 | |
62 | void setMate(S id) { mate.set(id); } |
63 | } |
Began life as a copy of #1016311
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016457 |
Snippet name: | Files In Directory [Dyn Module] |
Eternal ID of this version: | #1016457/24 |
Text MD5: | 63c3e68ae7918a2f58d780c7d5b6ed1a |
Transpilation MD5: | b870327114fcd6d8b05e1f345b128c2f |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-06-19 00:22:35 |
Source code size: | 2090 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 487 / 1170 |
Version history: | 23 change(s) |
Referenced in: | [show references] |