Uses 108K of libraries. Click here for Pure Java version (17969L/131K).
1 | !7 |
2 | |
3 | static Class _classMigration_LastImagesInDirectory = ImagesInDirectory; // not implemented yet |
4 | |
5 | sclass ImagesInDirectory extends DynSCP { |
6 | new DynModuleRef mate; |
7 | S dir; |
8 | L<S> allFiles, imageFiles; |
9 | |
10 | transient DynamicHStack buttons; |
11 | transient ButtonImageLoader imageLoader; |
12 | |
13 | File dirObject() { ret newFile(dir); } |
14 | |
15 | JComponent visualize2() { |
16 | if (buttons == null) { buttons = makeNiceButtons(); updateButtons(); } |
17 | if (imageLoader == null) imageLoader = new ButtonImageLoader(buttons); |
18 | if (mate! == null) ret jcenteredlabel("Need directory"); |
19 | ret jHigherScrollPane(jfullcenter(buttons)); |
20 | } |
21 | |
22 | void update { |
23 | lock lock; |
24 | int oldChangeCount = mate! == null ? -1 : changeCount; |
25 | try { |
26 | if (mate! != null && !dm_moduleStillThere(mate!)) mate.set(null); |
27 | if (mate! == null) |
28 | if (setField(mate := DynModuleRef(print("Mate: ", dm_findMateOfType(this, 'DirectoryInfo))))) |
29 | revisualize2(); |
30 | if (mate == null) ret; |
31 | setField(dir := (S) call(mate!, 'getDir)); |
32 | L<S> allFiles = castCall(mate!, 'getFiles); |
33 | if (this.allFiles != allFiles) { |
34 | setField(+allFiles); |
35 | setField(imageFiles := filterOrNull(allFiles, f isImageFileName)); |
36 | } |
37 | } finally { |
38 | if (changeCount != oldChangeCount) updateButtons(); |
39 | } |
40 | } |
41 | |
42 | void updateButtons { |
43 | if (dir == null || buttons == null) ret with setModuleName("Images in directory"); |
44 | L<TextImageAction> l = filesForNiceButtons(sortFilesByDate( |
45 | fileNamesInDirToFile(new File(dir), imageFiles)), f showImage); |
46 | for (final TextImageAction tia : l) |
47 | tia.popupMenuMaker = ImagesInDirectory_popupMenu(this, tia); |
48 | replaceNiceButtons(buttons, l); |
49 | setModuleName(imageFiles == null |
50 | ? "Not allowed to look in directory " + fileName(dirObject()) |
51 | : n2(l, "image") + " in directory " + fileName(dirObject())); |
52 | if (imageLoader != null) imageLoader.update(); |
53 | } |
54 | } |
55 | |
56 | static VF1<JPopupMenu> ImagesInDirectory_popupMenu(ImagesInDirectory m, final TextImageAction tia) { |
57 | // Haha, not even used |
58 | //final WeakReference<ImagesInDirectory> me = new(m); |
59 | ret voidfunc(JPopupMenu menu) { |
60 | addPopupItemsForImageFile(menu, filesForNiceButtons_map.get(tia)) |
61 | }; |
62 | } |
Began life as a copy of #1015916
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1015922 |
Snippet name: | Images In Directory [Dyn Module] |
Eternal ID of this version: | #1015922/43 |
Text MD5: | 3dead63dbe2592c9a3a72b6fc4cfdaa9 |
Transpilation MD5: | af37fd0ba0812afbaa9f4dcd47c26350 |
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-10-23 12:52:50 |
Source code size: | 2288 bytes / 62 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 477 / 1204 |
Version history: | 42 change(s) |
Referenced in: | [show references] |