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

54
LINES

< > BotCompany Repo | #1016357 // General Definitions [Dyn Module, old]

JavaX source code (Dynamic Module) [tags: archive use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (8340L/60K).

1  
!7
2  
3  
sclass GeneralDefinitions extends DynModule {
4  
  transient S term;
5  
  transient JPanel stack;
6  
  transient JTextField tfInput;
7  
  transient JCheckBox cbInput;
8  
  transient S listName = "General definitions (long list)";
9  
10  
  JComponent visualize() {
11  
    tfInput = jcenteredtextfield();
12  
    cbInput = jcheckbox();
13  
    stack = dynamicVStack2();
14  
    onChangeAndNow(cbInput, r { setEnabled(tfInput, isChecked(cbInput)); updateMe(); });
15  
    main.onChange(tfInput, r { if (isChecked(cbInput)) updateMe() });
16  
    ret northCenterAndSouth(
17  
      westAndCenter(cbInput, tfInput),
18  
      stack, 
19  
      withMargin(jcenteredbutton("Add definition...", r {
20  
        fS t = term;
21  
        inputText("Definition for: " + t, voidfunc(S def) {
22  
          addToMechMap(listName, litmap(t, def));
23  
          infoBox("Definition added: " + t + " = " + def);
24  
          updateMe();
25  
        });
26  
      })));
27  
  }
28  
  
29  
  void update {
30  
    if (stack == null) ret;
31  
    bool myInput = isChecked(cbInput);
32  
    fS s = trim(myInput ? getText(tfInput) : dm_getInterestingString());
33  
    if (!myInput) setText(tfInput, s);
34  
    term = s;
35  
    S text = makeText(s);
36  
    replaceAllComponents(stack, ll(fontSize(17, jCenteredMultiLineLabel(text))));
37  
  }
38  
  
39  
  S makeText(fS s) {
40  
    S text = "";
41  
    if (empty(s)) ret text;
42  
    MultiMap<S> map = mechMultiMapCI(listName);
43  
    L<S> answers = map.get(s);
44  
    MultiMap<S> map2 = mechMultiMapCI("Unauthorized Appends | " + listName);
45  
    L<S> answers2 = map2.get(s);
46  
    if (empty(answers) && empty(answers2))
47  
      ret "No definitions found for " + quote(s);
48  
      
49  
    ret lines(concatLists(
50  
      map(answers, func(S a) -> S { s + " = " + a }),
51  
      map(answers2, func(S a) -> S { s + " " + unicode_questionedEquals() + " " + a })
52  
    ));
53  
  }
54  
}

Author comment

Began life as a copy of #1016348

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): cfunsshuasjs, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1016357
Snippet name: General Definitions [Dyn Module, old]
Eternal ID of this version: #1016357/25
Text MD5: 7df1e27070ac33910ee7a57707334ccb
Transpilation MD5: 27614921f9a5dc514be9991743d6bf0c
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2018-06-19 14:59:20
Source code size: 1795 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 418 / 686
Version history: 24 change(s)
Referenced in: [show references]