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

130
LINES

< > BotCompany Repo | #1000985 // swing-top - List running programs & bots (old)

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

Libraryless. Click here for Pure Java version (1907L/14K/46K).

1  
!747
2  
!actionListener {
3  
!x619 // standard classes (LetterLayout, CenteredLine)
4  
!multi-line strings
5  
!1000805 // awt {
6  
7  
main {
8  
  static JList list;
9  
  static JTextField tfCmd; // unused
10  
  static JLabel status;
11  
  static JButton btnScan;
12  
  static S ip;
13  
  static int fromPort = 10000, toPort = 10999;
14  
  
15  
  !include #1000804 // ProgramScan
16  
17  
  static S menuSnippet = "#1000910";
18  
  static S menuScript;
19  
  
20  
  !include #1000839 // PopupMenuHelper
21  
  
22  
  psvm {
23  
    if (args.length != 0) ip = args[0];
24  
    
25  
    S title = "Running programs and bots";
26  
    if (ip != null) title += " on " + ip;
27  
    installHelloMessage(title);
28  
    JFrame frame = new JFrame(title);
29  
    
30  
    JPanel panel = new JPanel(new BorderLayout());
31  
    
32  
    list = new JList();
33  
    panel.add(BorderLayout.CENTER, new JScrollPane(list));
34  
    
35  
    new PopupMenuHelper() {
36  
      void fillMenu() {
37  
        try {
38  
          if (menuScript == null)
39  
            menuScript = loadSnippet(menuSnippet);
40  
            
41  
          JMenuItem mi;
42  
          int idx = list.locationToIndex(point);
43  
          final String item = cast list.getModel().getElementAt(idx);
44  
          list.setSelectedIndex(idx);
45  
          
46  
          L<S> tok = javaTok(menuScript);
47  
          for (int i = 1; i+4 < tok.size(); i += 2)
48  
            if (tok.get(i+2).equals("=")) {
49  
              final S snip = unquote(tok.get(i+4));
50  
              S text = unquote(tok.get(i));
51  
              mi = new JMenuItem(text);
52  
              mi.addActionListener(actionListener {
53  
                runCustom(snip, item);
54  
              });
55  
              menu.add(mi);
56  
            }
57  
        } catch (Throwable e) {
58  
          popup(e);
59  
        }
60  
          
61  
      }
62  
    }.install(list);    
63  
    
64  
    tfCmd = new JTextField();
65  
    //panel.add(BorderLayout.SOUTH, tfCmd)
66  
    
67  
    status = new JLabel(" ");
68  
    btnScan = new JButton("Scan again");
69  
    btnScan.addActionListener(actionListener { scan(); });
70  
    JPanel bottom = new JPanel(new BorderLayout());
71  
    bottom.add(BorderLayout.CENTER, status);
72  
    bottom.add(BorderLayout.EAST, btnScan);
73  
    panel.add(BorderLayout.SOUTH, bottom);
74  
    
75  
    /*tfCmd.addActionListener(actionListener {
76  
      tfCmd.selectAll();
77  
      String cmd = tfCmd.getText();
78  
      runCmd(cmd);
79  
    });*/
80  
    
81  
    /*frame.addWindowListener(new WindowAdapter() {
82  
      public void windowOpened(WindowEvent e) {
83  
        tfCmd.requestFocus();
84  
      }
85  
    });*/
86  
  
87  
    frame.add(panel);
88  
    frame.setBounds(100, 100, 500, 400);
89  
    frame.setVisible(true);
90  
    exitOnFrameClose(frame);
91  
92  
    scan();
93  
  }
94  
  
95  
  static void scan() {
96  
    thread {
97  
      status("Scanning " + (ip != null ? ip + " " : "") + " for programs...");
98  
      btnScan.setEnabled(false);
99  
      try {
100  
        if (ip != null) ProgramScan.ip = ip;
101  
        final List<ProgramScan.Program> programs = ProgramScan.scan(fromPort, toPort);
102  
        programs.addAll(ProgramScan.quickBotScan());
103  
        status("Done. " + programs.size() + " programs or bots found.");
104  
        
105  
        awt {
106  
          new DefaultListModel<S> model;
107  
          for (ProgramScan.Program p : programs)
108  
            model.addElement("Port " + p.port + ": " + p.helloString);
109  
          list.setModel(model);
110  
        }
111  
      } catch (Throwable e) {
112  
        e.printStackTrace();
113  
        status("Scan error: " + e);
114  
      }
115  
      btnScan.setEnabled(true);
116  
   }
117  
  }
118  
  
119  
  static void status(final S s) {
120  
    awt { status.setText(s); }
121  
  }
122  
  
123  
  static void runCustom(S worker, S item) {
124  
    item = item.replaceAll("^[^0-9]*", "");
125  
    int i = item.indexOf(":");
126  
    nohupJavax(worker + " " + (ip == null ? "" : ip + " ") + item.substring(0, i) + " by the name of " + quote(item.substring(i+1).trim()));
127  
  }
128  
  
129  
  !include #1001139 // quickBotScan included for technical reasons
130  
}

Author comment

Began life as a copy of #751

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
1137 stefan Use #1001437 instead 2015-10-22 21:12:31

add comment

Snippet ID: #1000985
Snippet name: swing-top - List running programs & bots (old)
Eternal ID of this version: #1000985/1
Text MD5: bae0ffb905d7524a42d4242961b6e2d2
Transpilation MD5: e8361c3454405886bc1cfec0f2c2371f
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-10-22 21:12:46
Source code size: 3845 bytes / 130 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1007 / 1273
Referenced in: [show references]