1 | !759 |
2 | |
3 | concepts. |
4 | |
5 | concept Line { |
6 | S text; |
7 | |
8 | *() {} |
9 | *(S *text) { change(); } |
10 | } |
11 | |
12 | concept UserLine { |
13 | new Ref<Line> line; |
14 | } |
15 | |
16 | concept Action { |
17 | S code; |
18 | } |
19 | |
20 | concept Line2Action { |
21 | new Ref<Line> line; |
22 | new Ref<Action> action; |
23 | } |
24 | |
25 | static JTextField tf; |
26 | static SingleComponentPanel scp; |
27 | static UserLine userLine; |
28 | static SystemAnswer systemAnswer; |
29 | static JTable table; |
30 | static L<Map> tableData; |
31 | |
32 | p-awt { |
33 | //mistAqua(); // GREAT, with rounded buttons/scrollbars |
34 | //emeraldDusk(); // wellll... |
35 | magellan(); // funny, but not that readable |
36 | |
37 | loadAndAutoSaveConcepts(); |
38 | showFrameHidingConsole(jtabs( |
39 | "Console", |
40 | northAndCenter( |
41 | centerAndEast(tf = jCenteredTextField("What is love?"), |
42 | jbutton("Answer...", "answerQ")), |
43 | scp = new SingleComponentPanel(centeredHtmlLabel("Yo!"))), |
44 | "Questions & Answers", |
45 | table = sexyTable())); |
46 | tf.selectAll(); |
47 | tf.requestFocus(); |
48 | setFrameIconLater(tf, "#1005372"); |
49 | |
50 | onEnter(tf, r { |
51 | S s = tf.getText().trim(); |
52 | userLine = userLine(s); |
53 | processUserLine(); |
54 | }); |
55 | |
56 | tablePopupMenu(table, voidfunc(JPopupMenu menu, final int row) { |
57 | final S q = first(getTableLine(table, row)); |
58 | Map map = _get(tableData, row); |
59 | final UserAnswer ua = cast _get(map, "[hidden] ua"); |
60 | |
61 | menu.add(jmenuItem("Answer...", r { |
62 | userLine = uniq(UserLine, text := q); |
63 | answerQ2(); |
64 | })); |
65 | |
66 | menu.add(jmenuItem("Mark solvable", r { |
67 | cset(ua, "solvable", true); |
68 | })); |
69 | |
70 | menu.add(jmenuItem("Un-mark solvable", r { |
71 | cset(ua, "solvable", false); |
72 | })); |
73 | }); |
74 | |
75 | /*registerCtrlKey(table, KeyEvent.VK_PAGE_UP, "Tab Left", r { |
76 | print("lalala"); |
77 | });*/ |
78 | |
79 | awtOnConceptChanges(table, 500, "updateTable"); |
80 | } |
81 | |
82 | svoid answerQ { |
83 | final S s = tf.getText().trim(); |
84 | if (userLine == null || neq(userLine.text, s)) |
85 | userLine = new UserLine(s); |
86 | answerQ2(); |
87 | } |
88 | |
89 | svoid answerQ2 { |
90 | final UserLine _userLine = userLine; |
91 | final new JTextField tfA; |
92 | final JCheckBox cbSolvable = jCheckBox(uniq(SCDefaults).solvable); |
93 | showTitledForm("Answer question", |
94 | "Question", _userLine.text, |
95 | "Answer", tfA, |
96 | "Solvable", cbSolvable, |
97 | r { |
98 | S a = tfA.getText().trim(); |
99 | cnew(UserAnswer, userLine := _userLine, text := a, |
100 | solvable := (uniq(SCDefaults).solvable = isChecked(cbSolvable))); |
101 | print("Answer recorded! " + _userLine.text + " => " + a); |
102 | processUserLine(); |
103 | }); |
104 | } |
105 | |
106 | svoid processUserLine { |
107 | try { |
108 | scp.setComponent(makeComponent()); |
109 | } catch e { |
110 | scp.setComponent(typeWriterTextArea(getStackTrace(e))); |
111 | } |
112 | } |
113 | |
114 | static Component makeComponent() { |
115 | S ua = findUserAnswer(userLine.text); |
116 | if (nempty(ua)) |
117 | ret centeredHtmlLabel(htmlencode(ua)); |
118 | ret yeahDummyAnswer(); |
119 | } |
120 | |
121 | static JComponent yeahDummyAnswer() { |
122 | S answer = "Yeah. " + userLine.text; |
123 | systemAnswer = cnew(SystemAnswer, +userLine, "text", answer); |
124 | ret centeredHtmlLabel(htmlencode(answer)); |
125 | } |
126 | |
127 | svoid updateTable() { |
128 | print("Updating table (c=" + changes + ")"); |
129 | new L<Map> l; |
130 | dataToTable_uneditable(table, tableData = reversedList(l)); |
131 | } |
132 | |
133 | static UserLine userLine(S text) { |
134 | ret cnew(UserLine, line := uniq(Line, +text)); |
135 | } |
Began life as a copy of #1005320
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005444 |
Snippet name: | Action Console [dev.] |
Eternal ID of this version: | #1005444/1 |
Text MD5: | f51d15c39b57d6152131f71b8ad0f5ab |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-11-19 13:51:59 |
Source code size: | 3286 bytes / 135 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 519 / 511 |
Referenced in: | [show references] |