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

69
LINES

< > BotCompany Repo | #1006135 // Remote Machine File Browser [Swing]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (7959L/57K/196K).

!752

static L<Map> origData, data;
static S dir = "/";
static JTable table;
static S ip;

p-substance {
  if (ip == null) ip = gateway();
  final JTextField tf = jTextField(ip);
  showForm("IP to browse:", tf, r {
    ip = trim(tf.getText());
    load("dir");
    browse(dir);
  });
}

svoid browse(S path) {
  dir = path;
  save("dir");
  S s = sendToAwareness(ip, "list directory *", dir);
  origData = (L) safeUnstructure(s);
  data = sortedByField("Name", map(func(Map map) {
    putKeysFirst(renameKeys(map,
      "dir", "Directory?", "m", "Last modified",
      "n", "Name", "l", "File Size (Bytes)"),
      "Name", "Directory?")
  }, origData));
  
  S title = dir + " [" + ip + "]";
  bool firstTime = table == null;
  table = showTableWithSearcher(table, data, title);

  if (firstTime) {
    onDoubleClickOrEnter(table, voidfunc(int row) {
      Map map = getTableLineAsMap(table, row);
      if (map == null) ret;
      Map map2 = findByField(origData, "n", map.get("Name"));
      print("map2=" + struct(map2));
      S name = getString(map, "Name");
      if (isTrue(_get(map2, "dir")))
        browse(addSlash(dir) + name);
      else
        swingOpenPhoneFile(ip, addSlash(dir) + name);
    });
    registerKey(getFrame(table), KeyEvent.VK_BACK_SPACE, "Back", r {
      browse(or2(substring(dir, 0, dir.lastIndexOf('/')), "/"));
    });
    
    tablePopupMenu(table, voidfunc(JPopupMenu menu, int row) {
      Map map = getTableLineAsMap(table, row);
      if (map == null) ret;
      Map map2 = findByField(origData, "n", map.get("Name"));
      print("map2=" + struct(map2));
      final S name = getString(map, "Name");
      final S path = addSlash(dir) + name;
      if (!isTrue(_get(map2, "dir")))
        addMenuItem(menu, "Download File", r {
          thread "Downloading" {
            print("Downloading from phone...");
            byte[] data = readFileFromPhone(ip, path);
            File f = userHome("Downloads/" + name);
            saveBinaryFile(f, data);
            print("Saved: " + f.getAbsolutePath());
          }
        });
    });
  }
}

Author comment

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: 538 / 690
Referenced in: