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).

1  
!747
2  
!actionListener {
3  
!awt {
4  
!pcall
5  
6  
m {
7  
  static JTable tbl;
8  
  static int delay = 3000;
9  
  static boolean withVMs = true;
10  
  
11  
  p {
12  
    tbl = showTable("Bots Table");
13  
    getFrame(tbl).setBounds(10, 10, 400, 400);
14  
    
15  
    addTalkButton();
16  
17  
    updateBotList();
18  
    installTimer(tbl, runnable { updateBotList(); }, delay);
19  
  }
20  
  
21  
  static new MonoThread update;
22  
  
23  
  !include #1001434 // MonoThread
24  
  
25  
  static void updateBotList() {
26  
    update.run(runnable {
27  
      new L<L<S>> bots;
28  
      for (ProgramScan.Program p : quickBotScan()) {
29  
        S botName = firstPartOfHelloString(p.helloString);
30  
        boolean isVM = startsWithIgnoreCase(p.helloString, "This is a JavaX VM.");
31  
        boolean shouldRecurse = startsWithIgnoreCase(botName, "Multi-Port") || isVM;
32  
        
33  
        if (withVMs || !isVM)
34  
          bots.add(litlist(botName, "" + p.port));
35  
36  
        if (shouldRecurse) pcall {
37  
          Map<Number, S> subBots = (Map) unstructure(sendToLocalBot(p.port, "list bots"));
38  
          for (Number vport : subBots.keySet())
39  
            bots.add(litlist(subBots.get(vport), p.port + "/" + vport));
40  
        }
41  
      }
42  
      sortByFirstColumn(bots);
43  
      fillTableWithStrings(tbl, bots, "Hello message", "Port");
44  
    });
45  
  }
46  
  
47  
  static void addTalkButton() {
48  
    awt {
49  
      JButton btn = new JButton("Talk to bot");
50  
      btn.addActionListener(new ActionListener() {
51  
        public void actionPerformed(ActionEvent e) {
52  
          pcall {
53  
            S value = getSelectedColumn(tbl, 1);
54  
            if (value != null) {
55  
              startBot("User Request List Bot", "#1001706");
56  
              sendToLocalBot("User Request List Bot", "add *", "talk to bot " + quote(getSelectedColumn(tbl, 1)));
57  
              startBot("Execute \"talk to bot\" commands bot.", "#1001709");
58  
            }
59  
          }
60  
        }
61  
      });
62  
      addToWindow(tbl, btn);
63  
    }
64  
  }
65  
}

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: 842 / 1192
Referenced in: [show references]