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

426
LINES

< > BotCompany Repo | #1000825 - JavaX Starter - Runnables search, v3 (CURRENT)

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

Uses 3874K of libraries. Click here for Pure Java version (22676L/175K).

1  
// The Runner!
2  
3  
!7
4  
5  
static JFrame frame;
6  
static JList list;
7  
static JTextField tfCmd;
8  
static JLabel status;
9  
static JButton btnReload, btnRun, btnClear;
10  
static S submittedInput;
11  
static JCheckBox cbPrograms;
12  
static TrayIcon trayIcon;
13  
static volatile boolean searching;
14  
static long lastSearch; // time of last search
15  
static bool first; // first of its kind
16  
17  
static JTable lastRunTable;
18  
static ReliableSingleThread thread_lastRun;
19  
20  
static S menuSnippet = #1000880;
21  
static S menuScript;
22  
//sS bigIcon = #1101166, smallIcon = #1101181; // the cat
23  
//sS bigIcon = #1101182, smallIcon = #1101184; // cupid/dizzy cat
24  
  // #1101168 // sitting cat
25  
  // #1003596
26  
sS bigIcon = #1101246, smallIcon = #1101184;
27  
28  
static int searchDelay = 100;
29  
static int maxResults = 100;
30  
static int autoResearchInterval = 30000; // 30 secs
31  
static int topTenLookBack = 100; // look at last 100 program runs
32  
33  
static L<S> actionHistory = synchroList();
34  
35  
!include #1001372 // direct nohupJavax
36  
37  
p {
38  
  try {
39  
    new JFrame().dispose();
40  
  } catch {
41  
    System.out.println("We're headless...");
42  
    // TODO: Something useful.
43  
    System.exit(0);
44  
  }
45  
46  
  awtMain();
47  
}
48  
49  
svoid awtMain {
50  
  becomeBotVMIfFirst();
51  
  autoRestart10Mins();
52  
  //mistAqua();
53  
  //magellan();
54  
  //gemini();
55  
  //emeraldDusk();
56  
  //mistSilver();
57  
  //substanceLAF("Raven");
58  
  //substanceLAF("OfficeSilver2007");
59  
  //substanceLAF("OfficeBlue2007");
60  
  //substanceLAF("OfficeBlack2007");
61  
  substanceLAF("Sahara");
62  
  
63  
  print("First-check.");
64  
  first = empty(sendToAll("JavaX Starter.", "activate"));
65  
  print("  ==> " + first);
66  
    
67  
  swing {
68  
    frame = showFrame();
69  
    moveFrameAround(frame);
70  
  }
71  
  
72  
  updateTitle();
73  
  makeAndroid3("JavaX Starter.");
74  
  
75  
  setFrameIconLater(frame, bigIcon); 
76  
  
77  
  // Show the rays
78  
  // disposeWindowOnClick(showAnimation("#1003828", 3.5));
79  
  
80  
  swing {
81  
    list = new JList;
82  
  
83  
    new PopupMenuHelper {
84  
      void fillMenu() {
85  
        try {
86  
          if (menuScript == null)
87  
            menuScript = loadSnippet(menuSnippet);
88  
            
89  
          JMenuItem mi;
90  
          int idx = list.locationToIndex(point);
91  
          final String item = cast list.getModel().getElementAt(idx);
92  
          list.setSelectedIndex(idx);
93  
          
94  
          L<S> tok = javaTok(menuScript);
95  
          for (int i = 1; i+6 < tok.size(); i += 2)
96  
            if (tok.get(i+2).equals("=") && tok.get(i+4).equals("#")) {
97  
              final S snip = unquote(tok.get(i+6));
98  
              S text = unquote(tok.get(i));
99  
              mi = new JMenuItem(text);
100  
              mi.addActionListener(actionListener {
101  
                runCustom(snip, item);
102  
              });
103  
              menu.add(mi);
104  
            }
105  
        } catch (Throwable e) {
106  
          popup(e);
107  
        }
108  
      }
109  
    }.install(list);
110  
  
111  
    // install double click listener on list    
112  
    onDoubleClick(list, voidfunc(S item) {
113  
      if (nempty(item))
114  
        runCustom("", item);
115  
    });
116  
    
117  
    // install enter key listener on list
118  
    
119  
    onEnter(list, f runSelected);
120  
  
121  
    final ActionListener go = actionListener {
122  
      tfCmd.selectAll();
123  
      search(true);
124  
    };
125  
   
126  
    btnReload = new JButton(isWindows() ? "Reload" : "\u27F3");
127  
    btnReload.setToolTipText("Search again (if our " + autoResearchInterval/1000 + "s update interval is not enough for you)");
128  
    btnReload.addActionListener(go);
129  
  
130  
    btnClear = new JButton("X");
131  
    btnClear.setToolTipText("Show latest");
132  
    btnClear.addActionListener(actionListener { tfCmd.setText(""); });
133  
  
134  
    tfCmd = new JTextField;
135  
    
136  
    cbPrograms = new JCheckBox("Programs", true);
137  
    cbPrograms.setToolTipText("Show only runnable programs (not random text snippets)");
138  
    cbPrograms.addActionListener(go);
139  
    
140  
    JPanel controls = jflow(btnClear, cbPrograms, btnReload);
141  
  
142  
    JPanel north = centerAndEast(
143  
       withLabel("Search term:", tfCmd),
144  
       controls);
145  
    
146  
    btnRun = jbutton("Run", r { main.runSelected() });
147  
    listDependButton(list, btnRun);
148  
    
149  
    status = new JLabel(" ");
150  
    JPanel searchPanel = northCenterAndSouth(north, list,
151  
      centerAndEast(status, btnRun));
152  
  
153  
    tfCmd.addActionListener(go);
154  
    
155  
    frame.addWindowListener(new WindowAdapter() {
156  
      public void windowOpened(WindowEvent e) {
157  
        tfCmd.requestFocus();
158  
      }
159  
      
160  
      public void windowClosing(WindowEvent e) {
161  
        frame.setVisible(false);
162  
      }
163  
      
164  
      public void windowActivated(WindowEvent e) {
165  
        search(false);
166  
      }
167  
    }); 
168  
    
169  
    installTimer(tfCmd, new Runnable() {
170  
      String lastContents;
171  
      boolean autoSearchOn = true;
172  
      
173  
      public void run() {
174  
        updateTitle();
175  
        String text = getInput();
176  
        if (text.equals(lastContents)) {
177  
          if (
178  
            isFocusedWindow(frame) && now() > lastSearch + autoResearchInterval
179  
            
180  
          || (!text.equals(submittedInput) && autoSearchOn && !searching))
181  
            search(false);
182  
        } else
183  
          lastContents = text;
184  
      }
185  
    }, searchDelay);
186  
    
187  
    lastRunTable = sexyTableWithoutDrag();
188  
    onDoubleClickOrEnter(lastRunTable, voidfunc(Int row) {
189  
      Map map = getTableLineAsMap(lastRunTable, row);
190  
      S id = getString(map, "Program ID");
191  
      S args = getString(map, "Arguments");
192  
      runCustom("", id + " " + args);
193  
    });
194  
    
195  
    thread_lastRun = new ReliableSingleThread(r { lastRunTable_update(lastRunTable) });
196  
    thread_lastRun.go();
197  
    
198  
    JTable injectionsTable = jInjectionsTable();
199  
    
200  
    frame.add(jRightTabs("Search", searchPanel, "Last Run Programs", tableWithSearcher(lastRunTable), "Running", injectionsTable));
201  
    frame.setBounds(100, 100, 500, 400);
202  
    frame.setVisible(true);
203  
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
204  
    hideFrameOnMinimize(frame);
205  
    
206  
    addMenu(frame, "Starter",
207  
      "Show Talk Program [Eleutheria]", r { talkProgram() },
208  
      "Your Computer ID: " + computerID(), r {},
209  
      "Update JavaX", r { nohupJavax(#1001639) },
210  
      "Log in", r { nohupJavax(#1000896) },
211  
      "Exit", r-thread { cleanKill() });
212  
      
213  
    thread { addAISuiteMenu(frame, "AI"); }
214  
    
215  
    if (first)
216  
      trayIcon = installTrayIcon("JavaX!", smallIcon, trayPopupMenuItems());
217  
    
218  
    thread "Updating Menu every 10 minutes" {
219  
      sleepMinutes(10);
220  
      while (licensed()) {
221  
        pcall {
222  
          print("Updating menu.");
223  
          updateMenu();
224  
        }
225  
        sleepMinutes(10);
226  
      }
227  
    }
228  
  
229  
    onUserUtterance(voidfunc(S s) { setTextSelectAll(tfCmd, s); search(false); });
230  
    
231  
    if (myVMPort() == 5000)
232  
      /*if (isStefanReichsPC()) // isMultiCore()
233  
        thread "Warming Up Java" {
234  
          loading "Warming Up Java" { warmUpJavaCompiler(20); }
235  
        }*/
236  
    
237  
    hideConsole();
238  
    
239  
    thread "Start Bots" {
240  
      startInternetTrafficCountBot();
241  
      startVMLister_onChange = r {
242  
        L<startVMLister_Data> hidden = startVMLister_hiddenVMs();
243  
        trayIcon.setToolTip("JavaX: " 
244  
          + n(startVMLister_numVMs(), "VM")
245  
          + (empty(hidden) ? "" : " (" + l(hidden) + " hidden)"));
246  
        updateMenu();
247  
      };
248  
      
249  
      if (startVMLister())
250  
        doEvery(60000, f startVMLister_scan);
251  
        
252  
      startBotHere("Compiler Bot", #1007916);
253  
      
254  
      // TODO: restart these bots if multiple runners are started
255  
      // and exited in unfortunate order
256  
    }
257  
  } // swing
258  
  
259  
  search(false);
260  
}
261  
262  
svoid updateTitle {
263  
  S title = "JavaX Starter v3";
264  
  if (isOfflineMode()) title += " [OFFLINE MODE]";
265  
  setFrameTitle(frame, title);
266  
}
267  
268  
svoid updateMenu {
269  
  updateTitle();
270  
  trayIcon.setPopupMenu(makePopupMenu(dropFirst(trayPopupMenuItems())));
271  
}
272  
273  
static O[] trayPopupMenuItems() {
274  
  new L topTenItems;
275  
  pcall {
276  
    L<S> calls = programTopTenWithArgs(topTenLookBack).getTopTen();
277  
    new HashSet<S> ids;
278  
    for (S s : calls)
279  
      ids.add(onlyUntilSpace(s));
280  
    Map<S, S> titles = getSnippetTitles(asList(ids));
281  
    
282  
    for (final S call : calls) {
283  
      S id = onlyUntilSpace(call);
284  
      topTenItems.add(menuItem(id + " [" + lookupSnippetID(titles, id) + "]" + (eq(id, call) ? "" : " " + trim(dropPrefix(id, call))),
285  
        r { runProgram(call); }));
286  
    }
287  
  }
288  
  
289  
  //Menu catMenu = new Menu("Cat (Personal Voice Assistant)");
290  
  //catMenu.add(menuItem("Start Listening", f cat_startListening));
291  
  //catMenu.add(menuItem("Stop Listening", f cat_stopListening));
292  
  
293  
  new L hiddenVMItems;
294  
  L<startVMLister_Data> hiddenVMs = startVMLister_hiddenVMs();
295  
  if (nempty(hiddenVMs)) {
296  
    hiddenVMItems.add("***");
297  
    int i = 0;
298  
    for (final startVMLister_Data vm : hiddenVMs) {
299  
      Menu subMenu = new("Hidden VM " + ++i);
300  
      addMenuItem(subMenu, "Kill", r { killVM(vm.port) }); // TODO: use VM ID
301  
      addMenuItem(subMenu, "Restart", r { restartVM(vm.port) });
302  
      addMenuItem(subMenu, "Show Console", r { send(vm.port, "show console") });
303  
      hiddenVMItems.add(subMenu);
304  
    }
305  
  }
306  
    
307  
  ret flattenArray(
308  
    r { bringUpFrame(); }, // on left click
309  
    toObjectArray(topTenItems),
310  
    toObjectArray(hiddenVMItems),
311  
    "***",
312  
    menuItem("Start Listening", f cat_startListening),
313  
    menuItem("Stop Listening", f cat_stopListening),
314  
    menuItem("Show JavaX Starter", f bringUpFrame),
315  
    menuItem("Show Console", f showConsole),
316  
    menuItem("Show All Consoles", f showAllConsoles),
317  
    menuItem("Restart JavaX Starter", f restart),
318  
    menuItem("Show Talk Program [Eleutheria]", f talkProgram),
319  
    //menuItem("Hide Console", f hideConsole),
320  
    isOfflineMode()
321  
      ? menuItem("Switch to online mode", r { goOnlineMode(); updateMenu(); })
322  
      : menuItem("Switch to offline mode", r { goOfflineMode(); updateMenu(); }),
323  
    menuItem("Update JavaX", r { nohupJavax(#1001639) }),
324  
    menuItem("Exit", r { System.exit(0); }));
325  
}
326  
327  
static S getInput() {
328  
  ret tfCmd.getText().trim();
329  
}
330  
331  
static void search(S cmd, final boolean requestFocus) ctex {
332  
  searching = true;
333  
  try {
334  
    status("Searching " + quote(cmd) + "...");
335  
    if (empty(cmd)) cmd = "_";
336  
    if (cbPrograms.isSelected())
337  
      cmd += " type:runnable-desktop";
338  
    fL<Snippet> snippets = tbSearch_url(tb_mainServer() + "/tb/search.php?q=" + urlencode(cmd) + "&limit=" + maxResults + "&sort=modified&quick=1" + standardCredentials());
339  
340  
    final new DefaultListModel model;
341  
    for (Snippet s : snippets)
342  
      model.addElement(fsI(s.id) + " - " + s.title);
343  
344  
    fS _cmd = cmd;
345  
346  
    awt {
347  
      list.setModel(model);
348  
      status("Found " + model.size() + (model.size() == maxResults ? "+" : "") + (cbPrograms.isSelected() ? " runnable(s)." : " snippet(s)."));
349  
      if (requestFocus)
350  
        tfCmd.requestFocus();
351  
      saveTextFile(programFile("search-results.txt"), struct(litmap(date := now(), query := _cmd, results := snippets)));
352  
    }
353  
  } finally {
354  
    searching = false;
355  
  }
356  
}
357  
358  
static void status(final S s) {
359  
  awt { status.setText(s); }
360  
}
361  
362  
static void runProgram(final S cmd) {
363  
  print("Running " + cmd);
364  
  S msg = format3("*: Running *", now(), cmd);
365  
  actionHistory.add(msg);
366  
  logQuoted("run.log", msg);
367  
  awtLater(1000, r { thread_lastRun.go() });
368  
  
369  
  thread { // new thread so we can see progress messages, e.g. for loading the JavaX jar
370  
    nohupJavax(cmd);
371  
  }
372  
}
373  
374  
static void runHotwired(final S worker, final long id) {
375  
  print("Hotwiring " + worker + " on " + id);
376  
  S msg = format3("*: Hotwiring * on *", now(), worker, id);
377  
  actionHistory.add(msg);
378  
  logQuoted("run.log", msg);
379  
  
380  
  thread {
381  
    _run(worker, new S[] {str(id)}); // TODO: cache code?
382  
  }
383  
}
384  
385  
static void runCustom(S worker, S item) {
386  
  if (item == null) ret;
387  
  int i = item.indexOf(' ');
388  
  if (i >= 0) item = item.substring(0, i);
389  
  long id = parseSnippetID(item);
390  
  print("runCustom: " + id + " [" + worker + "]");
391  
  if (empty(worker))
392  
    runProgram(str(id));
393  
  else
394  
    runHotwired(worker, id);
395  
  minimizeFrame(frame);
396  
}
397  
398  
static void runWithArguments(S item) {
399  
  // TODO: run a dialog for that
400  
}
401  
402  
static void search(final boolean requestFocus) {
403  
  submittedInput = getInput();
404  
  lastSearch = now();
405  
  final String cmd = submittedInput;
406  
  actionHistory.add(format3("*: Searching *", now(), cmd));
407  
  thread {
408  
    search(cmd, requestFocus);
409  
  }  
410  
}
411  
412  
answer {
413  
  if "very quick java *"
414  
    ret format("ok *", structure(callCalc(veryQuickJava(m.unq(0)))));
415  
  if "restart" { restart(); ret "OK"; }
416  
  if "activate" { activateFrame(frame); ret "OK"; }
417  
}
418  
419  
static void runSelected() {
420  
  S item = cast list.getModel().getElementAt(list.getSelectedIndex());
421  
  runCustom("", item);
422  
}
423  
424  
static void bringUpFrame() {
425  
  makeFrameVisible(frame);
426  
}

Author comment

Began life as a copy of #1000794

download  show line numbers  debug dex   

Travelled to 187 computer(s): acumhimkfssw, afbdgwpgxusd, afvcxyesxakz, agtzawvjhpac, agxbjmyenqqu, ahczwtoujzjf, ajlfxifxfcul, alesojohvdrz, anzfkgltbrzg, aoiabmzegqzx, aovkdhyilamm, aqvamacmveew, ayfdnjdhpjha, ayokdxtdmvtg, bhatertpkbcr, bkpbhqsukdzp, bmzxzaunwzbi, btpsnmddmadp, bvmoasoxxqgd, bwoimkvrfqyu, cbybwowwnfue, cfunsshuasjs, chdetcsrkecz, ciwybxsoqrky, cmvcylpgfixq, cscommsljcck, cysqohhbtkwd, dbzfplsxganw, ddnzoavkxhuk, dhtvkmknsjym, dpnavvvsbarw, dyfxnkwhunql, eokynvaqbppf, epdvrbgdoyjy, estmjqchrwzt, etmzoiygucik, etryasgzbotu, fauvpijqivwj, fbfgltocusnr, fehiwqupcyrn, foyxaisvsuws, fqdbqewsovaa, gmoysmmjifsf, gwrvuhgaqvyk, hacelcvcghbr, hftkfnpvpqih, hszllmzzlmie, htvoczylgtdf, hvydpgzngqto, hxnhedgloowk, iavmkmvmshxs, icbjsuppbenm, iesyigxtqvbp, ifztowiwnkjr, ijsbnqcsyaaf, ilscnaqoeozw, imzmzdywqqli, irmadwmeruwu, ishmyahliavo, ishqpsrjomds, jcllbfdqhrgy, jdobfzanukfo, jlatgrcjtklg, jmyaexzvplwz, jogcikdrpftb, jttmaavzamyx, jtubtzbbkimh, kjfvlgrqzszh, kltaiputbqfu, koymiuurghak, krzvwbcyrync, kuyjpjqxmspc, kzsysduheldy, lhdilzshxjzv, liwcxgsjrgqn, lpdgvwnxivlt, lulzaavyztxj, lywzbcoaxhnx, mbsocubsfpek, mdelbdmbyvbi, meaugxdlecrj, mjouhigkdmyk, mmjqhyfnifiw, moomcjjtfopu, movhonzfxxub, mqqgnosmbjvj, nbgitpuheiab, ndzpjzzthwet, ngbrtomqtpjn, nnmtytuibrzp, nruopgnwybjz, nsosnbthvwzj, ntqcuorowftz, nysugtttblhj, nzrhlmtlsyqh, obpsxxvyfitp, odhhsrjjbcgr, oikenkqtkxpn, okhbyavfwahh, omdjrrnzbjjv, omkuifhlbvuf, ompaxoqblvvt, omzkqqnokwlv, onfqjnomoxuw, onxytkatvevr, ozfokkltgguo, picgnzycjide, pjhmbilgegqi, pmilglshkwnf, ppjhyzlbdabe, pwiztjibzslt, pyentgdyhuwx, pzhvpgtvlbxg, qaafgiputhfz, qjimsvlqbazf, qyixvnbsfoum, rbqtzklnwohg, rcljlypqyydo, rjkjhqualmce, rlljfxnwkesy, rsdhgwlghzqg, rwunbfjijphy, sawdedvomwva, sdspifkayxrz, sftlboijnymy, sgthpswjdnle, snaazhdonpnp, soixmzaqppzr, soykzrexxpfe, svvfvzndtrpq, swnlqaquhrsn, teubizvjbppd, tgvutoijlajd, tntrlsqmulic, tpsnldywmnmr, tslmcundralx, tvejysmllsmz, ufrwpbyvgfzh, unoaxrwscvea, unpjazyqkgzd, uttcyjfcncbj, uwnvikuolobj, uysmjrxdxqpw, vaduqbtgckcl, vdyxwxlmubrt, vezddojwiuja, vlidprewgxyg, vlnhzwvsylal, vmiuuieieuib, vmkkswzgqtcz, voixwhikvanr, vpdwwinrgdga, vqftxbmjmmzu, vzdtmrzilvqm, vzpxdoxhqfnw, weqtezgcwmja, wglhsqxgxbdq, wikwqtdvqeud, wltunwwkxhxr, wnvtyfxbogru, wtqryiryparv, wvjjrydmpdin, wwcsgmvlopwy, xbzdlvvdvlsr, xfasiavlzxuf, xfbsdwenvhih, xfcctxexyzdh, xhsrmoityime, xidunzvaqbkw, xinetxnxrdbb, xiskaoettebs, xjxehkwqodvf, xlripclqcsxi, xotiqugfjbsw, xprdwmaupziu, xpvikbxxwzsu, ychswryhhvyu, ycwloxbuypyl, ydilcnlqtmvn, yktzofexzwjw, yscklbrkmvrk, yugkrbstzyuu, zkiihmmqzphi, zluxfztcnsid, znvaruejrphg, zsvsackdotgc, zwfnwkksncev

No comments. add comment

Snippet ID: #1000825
Snippet name: JavaX Starter - Runnables search, v3 (CURRENT)
Eternal ID of this version: #1000825/82
Text MD5: 05609269a5d36f7f5efbeb6370847e46
Transpilation MD5: 96ada3d04d470ae74a480e011d7d0452
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-25 00:12:50
Source code size: 12853 bytes / 426 lines
Pitched / IR pitched: No / No
Views / Downloads: 1608 / 73634
Version history: 81 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1000825 & http://1000825.tinybrain.de