Uses 911K of libraries. Click here for Pure Java version (12040L/66K).
1 | !7 |
2 | |
3 | cmodule GeneralDefinitions { |
4 | transient S term; |
5 | transient JPanel stack; |
6 | transient OptionalInputPanel inputPanel; |
7 | transient S listName = generalDefinitions_listName(); |
8 | transient int maxResults = 500; |
9 | |
10 | start { |
11 | dm_useLocallyCopiedMechLists(); |
12 | dm_onTopInput(rstUpdate()); |
13 | } |
14 | |
15 | visualize { |
16 | inputPanel = new OptionalInputPanel(this); |
17 | onEnter(inputPanel.tfInput, r addADefinition); |
18 | stack = dynamicVStack2(); |
19 | ret northCenterAndSouth( |
20 | inputPanel.panel, |
21 | jscroll_trackWidth(stack), |
22 | withMargin(jcenteredbuttons("Add definition...", r addADefinition, "All definitions", r { |
23 | showText("All definitions", |
24 | ai_renderDefinitions( |
25 | values(mechMultiMapPairsCI(listName)), |
26 | values(mechMultiMapPairsCI("Unauthorized Appends | " + listName)))) |
27 | }))); |
28 | } |
29 | |
30 | void update { |
31 | if (stack == null) ret; |
32 | replaceAllComponents(stack, ll(fontSize(17, |
33 | jCenteredMultiLineLabel(makeText(term = inputPanel.input()))))); |
34 | } |
35 | |
36 | S makeText(fS query) { |
37 | if (empty(query)) ret ""; |
38 | MultiMap<S, Pair<S>> map = mechMultiMapPairsCI(listName); |
39 | L<Pair<S>> answers = definitions_dropInvalidatedFromPairs(map.get(query)); |
40 | MultiMap<S, Pair<S>> map2 = mechMultiMapPairsCI("Unauthorized Appends | " + listName); |
41 | L<Pair<S>> answers2 = definitions_dropInvalidatedFromPairs(map2.get(query)); |
42 | S text = trim(ai_renderDefinitions(answers, answers2) |
43 | + "\n" |
44 | + prependIfNempty("Possibly related:\n", lines(concatLists( |
45 | scoredSearch2(maxResults, query, map(func(Pair<S> p) -> S { ai_renderDefinition(p.a, p.b, false) }, listMinusSet(definitions_dropInvalidatedFromPairs(values(map)), answers))), |
46 | scoredSearch2(maxResults, query, map(func(Pair<S> p) -> S { ai_renderDefinition(p.a, p.b, true) }, listMinusSet(definitions_dropInvalidatedFromPairs(values(map2)), answers2))))))); |
47 | |
48 | ret empty(text) ? "No definitions found for " + quote(query) : text; |
49 | } |
50 | |
51 | void addADefinition { |
52 | temp enter(); |
53 | fS t = term; |
54 | final JTextField tfWord = jtextfield(t), tfDefinition = jtextfield(); |
55 | showFormTitled("Add Definition", |
56 | "Word/Phrase:", tfWord, |
57 | "Definition:", tfDefinition, |
58 | rThread { |
59 | S word = gtt(tfWord), def = gtt(tfDefinition); |
60 | Pair<Bool, S> p = generalDefinitions_add(word, def); |
61 | infoBox(p.b); |
62 | if (p.a) updateMe(); |
63 | }); |
64 | requestFocus(tfDefinition); |
65 | } |
66 | } |
Began life as a copy of #1016431
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016466 |
Snippet name: | General Definitions v3 [OK] |
Eternal ID of this version: | #1016466/45 |
Text MD5: | 9326a3e303c1bb59bf866d36e775c376 |
Transpilation MD5: | 2922a47448a243d503de9f722260adbe |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-16 16:21:21 |
Source code size: | 2503 bytes / 66 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 557 / 6061 |
Version history: | 44 change(s) |
Referenced in: | [show references] |