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

65
LINES

< > BotCompany Repo | #1001680 // swing-top 2: Bots table (with sub-bots)

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

Libraryless. Click here for Pure Java version (2617L/17K/61K).

!747
!actionListener {
!awt {
!pcall

m {
  static JTable tbl;
  static int delay = 3000;
  static boolean withVMs = true;
  
  p {
    tbl = showTable("Bots Table");
    getFrame(tbl).setBounds(10, 10, 400, 400);
    
    addTalkButton();

    updateBotList();
    installTimer(tbl, runnable { updateBotList(); }, delay);
  }
  
  static new MonoThread update;
  
  !include #1001434 // MonoThread
  
  static void updateBotList() {
    update.run(runnable {
      new L<L<S>> bots;
      for (ProgramScan.Program p : quickBotScan()) {
        S botName = firstPartOfHelloString(p.helloString);
        boolean isVM = startsWithIgnoreCase(p.helloString, "This is a JavaX VM.");
        boolean shouldRecurse = startsWithIgnoreCase(botName, "Multi-Port") || isVM;
        
        if (withVMs || !isVM)
          bots.add(litlist(botName, "" + p.port));

        if (shouldRecurse) pcall {
          Map<Number, S> subBots = (Map) unstructure(sendToLocalBot(p.port, "list bots"));
          for (Number vport : subBots.keySet())
            bots.add(litlist(subBots.get(vport), p.port + "/" + vport));
        }
      }
      sortByFirstColumn(bots);
      fillTableWithStrings(tbl, bots, "Hello message", "Port");
    });
  }
  
  static void addTalkButton() {
    awt {
      JButton btn = new JButton("Talk to bot");
      btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          pcall {
            S value = getSelectedColumn(tbl, 1);
            if (value != null) {
              startBot("User Request List Bot", "#1001706");
              sendToLocalBot("User Request List Bot", "add *", "talk to bot " + quote(getSelectedColumn(tbl, 1)));
              startBot("Execute \"talk to bot\" commands bot.", "#1001709");
            }
          }
        }
      });
      addToWindow(tbl, btn);
    }
  }
}

Author comment

Began life as a copy of #1001437

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001680
Snippet name: swing-top 2: Bots table (with sub-bots)
Eternal ID of this version: #1001680/1
Text MD5: 75a7e8c65603d76bbd5404b36d40d4ce
Transpilation MD5: 21f7748f8b57a93db32a7d0b795e93cc
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-19 17:17:37
Source code size: 1927 bytes / 65 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 772 / 1096
Referenced in: [show references]