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

64
LINES

< > BotCompany Repo | #1001628 // Find frame with two lists (works e.g. with #1001622, but is slow, updating)

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

Libraryless. Click here for Pure Java version (3232L/22K/74K).

!752

p {
  new StringReceiver receiver;
  
  // inject to all VMs
  inject(receiver, [[
    for (JFrame f : allFrames()) {
      L<JList> lists = findAll(f, JList.class);
      if (l(lists) == 2) {
        print("Yes! " + f.getTitle());
        receiver.add(weakref(f));
      }
    }
  ]]);
  
  print("Frames found: " + structure(receiver.list));
}

static void inject(StringReceiver receiver, S code) {
  // change "receiver.add(" to "sendToLocalBot({port}, ..."
  L<S> tok = javaTok(code);
  jreplace(tok, "receiver.add(",
    "sendToLocalBot(" + receiver.android.port + ","
      + quote("please receive *") + ", ");
  code = join(tok);
  
  // make & transpile program
  S program = run752("p {\n" + code + "\n}");
  
  S programID = createTempProgram(program, "Temp program by " + formatSnippetID(getProgramID()));
  
  // inject to VMs
  L<Injection> injections = injectToAll(programID);
  
  // wait until injections ended
  waitUntilInjectionsDone(injections);

  // release injections (TODO)
  
  // shut down receiver
  receiver.android.dispose();
}

static class StringReceiver {
  L<S> list = synchroList();
  Android3 android;
  
  *() {
    android = new Android3("String Receiver.");
    android.responder = new Responder() {
      S answer(S s, L<S> history) {
        new Matches m;
        if (match3("please receive *", s, m)) {
          list.add(m.unq(0));
          ret "OK.";
        }
        ret null;
      }
    };
    android.useMultiPort = false;
    makeAndroid3(android);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1161 stefan It has to transpile the program in every VM... will be optimized in new translation architecture. 2015-11-01 13:33:30

add comment

Snippet ID: #1001628
Snippet name: Find frame with two lists (works e.g. with #1001622, but is slow, updating)
Eternal ID of this version: #1001628/1
Text MD5: 8a1815702a9b50a1e0ef0900724156fb
Transpilation MD5: e0124a7834f5c46122e39d81a429e0c2
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-17 23:45:32
Source code size: 1576 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 835 / 825
Referenced in: [show references]