!include #1003380 // Chat sclass BotChat { Chat chat; O dialogBot, backend; JTextArea thoughtsArea; *(O dialogBot) { this(dialogBot, null); } *(O _dialogBot, O backend) { if (!isSubstanceLAF()) blueSteel(); if (backend is a S) backend = run((S) backend); this.backend = backend; dialogBot = _dialogBot; //callOpt(dialogBot, "noRewind"); swingAndWait(r { thoughtsArea = new JTextArea; chat = new Chat; chat.logFile = getProgramFile("log.txt"); chat.onEnter_post = r { try { fire(E.q(chat.input())); } catch e { postError(e); } }; updateThoughts(); JFrame frame = showFrame(/*"Chat with " +*/ programTitle(), hgrid(chat, withTitle("Thoughts", thoughtsArea))); setFrameWidth(frame, 800); chat.requestFocus(); }); } void postIt(final L<E> l) { try { for (int i = 0; i < l(l); i++) { E e = l.get(i); if (e.a()) chatAppend("Bot: " + e.a + "\n"); else if (e.state()) { chatAppend("[" + e.state + "]\n"); final int _i = i+1; final Runnable l8r = r { awt { postIt(subList(l, _i)); } }; if (isNewStyleBackend(backend)) { class TheBF implements BF { bool working, unknown; S value; pvoid working() { working = true; } pvoid done() { l8r.run(); } pvoid value(O o) { value = str(o); } pvoid unknown() { unknown = true; } }; new TheBF bf; O exportedBF = proxy(_getClass(backend, "main.BF"), bf); print("Calling backend"); call(backend, "action", e.state, exportedBF); if (bf.unknown) { print("Warning: Action unknown to backend: " + e.state); } if (bf.working) { print("Backend working"); break; } if (bf.value != null) fire(E.state("result is " + bf.value)); } else { if ((bool) call(backend, "action", e.state, l8r)) break; } } } updateThoughts(); } catch e { postError(e); } } void chatAppend(S s) { if (hideLine(s)) ret; chat.append(s); } // hide boring stuff bool hideLine(S s) { ret s.startsWith("[") && (matchStart("bot pauses", s) || matchStart("get", s)); } void postError(Throwable e) { chat.append("= ERROR =\n" + getStackTrace(e) + "= ERROR =\n"); } void updateThoughts() { S s; try { s = (S) callOpt(dialogBot, "thoughts"); } catch e { s = getStackTrace(e); } if (empty(s)) s = "No thoughts in " + getClassName(dialogBot); //print("Thoughts: " + s); thoughtsArea.setText(s); } void preset(S line) { chat.setInput(line); } void fire(E e) { call(dialogBot, "take", e); postIt(slurp(dialogBot, "getSingleOutput")); } }
Began life as a copy of #1003416
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003499 |
Snippet name: | class BotChat - Swing-based bot chat with dialog bot + backend (current) |
Eternal ID of this version: | #1003499/1 |
Text MD5: | 05143784b7243cf1bf77bb904b04dc67 |
Author: | stefan |
Category: | javax / talking robots |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-07-19 16:48:45 |
Source code size: | 3205 bytes / 123 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 737 / 2092 |
Referenced in: | #1003494 - What's the date, bot?! #1003509 - Sag mir das Datum, Bot #1003527 - Generic Bot Chat #1003872 - Integrating #759 in One Program #1003874 - Backup of #759 Before Integration #1004091 - 759 with new loadClasses (spike) #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |