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).

!7

sclass GeneralDefinitions extends DynModule {
  transient S term;
  transient JPanel stack;
  transient JTextField tfInput;
  transient JCheckBox cbInput;
  transient S listName = "General definitions (long list)";

  JComponent visualize() {
    tfInput = jcenteredtextfield();
    cbInput = jcheckbox();
    stack = dynamicVStack2();
    onChangeAndNow(cbInput, r { setEnabled(tfInput, isChecked(cbInput)); updateMe(); });
    main.onChange(tfInput, r { if (isChecked(cbInput)) updateMe() });
    ret northCenterAndSouth(
      westAndCenter(cbInput, tfInput),
      stack, 
      withMargin(jcenteredbutton("Add definition...", r {
        fS t = term;
        inputText("Definition for: " + t, voidfunc(S def) {
          addToMechMap(listName, litmap(t, def));
          infoBox("Definition added: " + t + " = " + def);
          updateMe();
        });
      })));
  }
  
  void update {
    if (stack == null) ret;
    bool myInput = isChecked(cbInput);
    fS s = trim(myInput ? getText(tfInput) : dm_getInterestingString());
    if (!myInput) setText(tfInput, s);
    term = s;
    S text = makeText(s);
    replaceAllComponents(stack, ll(fontSize(17, jCenteredMultiLineLabel(text))));
  }
  
  S makeText(fS s) {
    S text = "";
    if (empty(s)) ret text;
    MultiMap<S> map = mechMultiMapCI(listName);
    L<S> answers = map.get(s);
    MultiMap<S> map2 = mechMultiMapCI("Unauthorized Appends | " + listName);
    L<S> answers2 = map2.get(s);
    if (empty(answers) && empty(answers2))
      ret "No definitions found for " + quote(s);
      
    ret lines(concatLists(
      map(answers, func(S a) -> S { s + " = " + a }),
      map(answers2, func(S a) -> S { s + " " + unicode_questionedEquals() + " " + a })
    ));
  }
}

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: 342 / 597
Version history: 24 change(s)
Referenced in: [show references]