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

63
LINES

< > BotCompany Repo | #1016457 // Files In Directory [Dyn Module]

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

Libraryless. Click here for Pure Java version (15174L/108K).

!7

sclass FilesInDirectory extends DynSCP {
  new DynModuleRef mate;
  S dir;
  L<S> files;
  
  transient JTable table;

  File dirObject() { ret newFile(dir); }
  
  JComponent visualize2() {
    if (table == null) {
      table = sexyTable();
      onDoubleClickOrEnter(table, voidfunc(int row) {
        final File f = newFile(newFile(dir), (S) getTableCell(table, row, 0));
        if (!f.isDirectory()) ret;
        thread {
          S info = dm_showNewModule("#1015916/DirectoryInfo");
          call(dm_getModule(info), 'setDir, f);
          call(dm_getModule(info), 'setAllowedToLook, true);
          S files = dm_showNewModule("#1016457/FilesInDirectory");
          call(dm_getModule(files), 'setMate, info);
        }
      });
      updateTable();
    }
    if (mate! == null) ret jcenteredlabel("Need directory");
    ret table;
  }
  
  void update {
    int oldChangeCount = mate! == null ? -1 : changeCount;
    try {
      if (mate! != null && !dm_moduleStillThere(mate!)) mate.set(null);
      if (mate! == null)
        if (setField(mate := DynModuleRef(print("Mate: ", dm_findMateOfType(this, 'DirectoryInfo)))))
          revisualize2();
      if (mate == null) ret;
      setField(dir := (S) call(mate!, 'getDir));
      L<S> files = castCall(mate!, 'getFiles);
      if (this.files != files) setField(+files);
    } finally {
      if (changeCount != oldChangeCount) updateTable();
    }
  }
  
  void updateTable {
    if (dir == null || table == null) ret with setModuleName("Files in directory");
    L<File> l = sortFilesByDate(
      fileNamesInDirToFile(new File(dir), files));
    dataToTable_uneditable(map(func(File f) -> Map {
      litorderedmap(
        "Name" := f.getName(),
        "Size" := f.isDirectory() ? "Directory" : toK(fileSize(f)) + " K")
    }, l), table);
    setModuleName(files == null
      ? "Not allowed to look in directory " + fileName(dirObject())
      : n2(l, "element") + " in directory " + fileName(dirObject()));
  }
  
  void setMate(S id) { mate.set(id); }
}

Author comment

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: 488 / 1171
Version history: 23 change(s)
Referenced in: #1016457 - Files In Directory [Dyn Module]