Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

56
LINES

< > BotCompany Repo | #1015916 // Directory Info [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (14390L/101K).

1  
!7
2  
3  
sclass DirectoryInfo extends DynModule {
4  
  S dir;
5  
  bool allowedToLook;
6  
  Bool exists, isFile;
7  
  L<S> filesContained; // this should be an immutable list b/c of listeners
8  
  
9  
  transient JComboBox comboBox;
10  
  
11  
  File dirObject() { ret newFile(dir); }
12  
  
13  
  void start {
14  
    ownTimer(doEvery(2.0, r fullUpdate)); // TODO: watch service
15  
  }
16  
  
17  
  JComponent visualize() {
18  
    if (dir == null)
19  
      ret jcenteredbutton("Select directory...", r {
20  
        selectDir("Select directory to show", voidfunc(File dir) {
21  
          setDir(dir);
22  
        });
23  
      });
24  
      
25  
    if (comboBox == null)
26  
      comboBox = yesNoComboBox(allowedToLook,
27  
        voidfunc(bool b) { setField(allowedToLook := b) });
28  
        
29  
    ret makeForm(
30  
      "Directory" := dir,
31  
      allowedToLook := comboBox,
32  
      +exists,
33  
      +isFile,
34  
      "Elements contained", filesContained == null ? "Unknown" : l(filesContained));
35  
  }
36  
  
37  
  void fullUpdate { updateMe(); }
38  
  
39  
  void update {
40  
    temp enter();
41  
    if (dir != null && allowedToLook) {
42  
      File dirObject = dirObject();
43  
      setField(exists := dirObject.isDirectory());
44  
      setField(isFile := dirObject.isFile());
45  
      if (setField(filesContained := listFileNames(dirObject)))
46  
        revisualize();
47  
    } else
48  
      if (setFields(exists := null, isFile := null, filesContained := null)) revisualize();
49  
  }
50  
  
51  
  // API for other modules
52  
  S getDir() { ret dir; }
53  
  void setDir(File dir) { setField(dir := f2s(dir)); revisualize(); }
54  
  L<S> getFiles() { ret filesContained; }
55  
  void setAllowedToLook(bool b) { setField(allowedToLook := b); }
56  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga

No comments. add comment

Snippet ID: #1015916
Snippet name: Directory Info [Dyn Module]
Eternal ID of this version: #1015916/33
Text MD5: bed015bcd35b2f97935b4fe7fc6243cf
Transpilation MD5: 3d3c2fda3b1a7a4a7d9105cddd0c255f
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:23:55
Source code size: 1632 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 485 / 70619
Version history: 32 change(s)
Referenced in: [show references]