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

61
LINES

< > BotCompany Repo | #1017339 // Categories For Each Word [Dyn Module, OK]

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

Uses 911K of libraries. Click here for Pure Java version (15653L/87K).

!7

cmodule Categories {
  InputChooser inputChooser = new(this);
  S language = 'english;
  transient SingleComponentPanel form;

  start {
    dm_useLocalMechListCopies();
    onChange(r { inputChooser.forceUpdate() }); // if language change
    dm_afterVisualize(r { inputChooser.forceUpdate() });
  }

  visualize {
    ret northAndCenter(wrap(inputChooser),
      withTopMargin(northAndCenter(jcenteredline(withLabel("Language:", dm_fieldComboBox('language, ll("English", "German")))),
      /*jfullcenter*//*jscroll_trackWidth*/(form = singleComponentPanel()))));
  }
  
  void update {
    if (form == null || !inputChooser.update()) ret;
    S input = inputChooser.input();
    L<S> words = words(input);
    ai_setLanguage(language);
    
    final Map<S, Set<S>> wordCategories = ai_wordCategoriesWithElements();

    form.setComponentAndRevalidateParent(makeForm(pairsToParams(map(words,
      func(fS word) -> Pair<O> {
        new L<S> cats;
        for (S cat : keys(wordCategories))
          if (contains(wordCategories.get(cat), word))
            cats.add(cat);
            
        if (empty(cats) && dm_isShowingAndOSInForeground())
          dm_toFront(); // uncategorized word - go to front
            
        final JComboBox cb = jcombobox(keys(wordCategories));
        comboBoxSelectIndex(cb, 0);
        
        ret (Pair) pair(
          // quoted word
          setFontSize(18, jRightAlignedLabel(quote(word))),
          
          centerAndEastWithMargin(
            // known categories
            jlabel(or2(joinWithComma(cats), "-")),
            
            jline(
              // combo box for add/remove category
              cb,
              jbutton("Add", rThread {
                assertEquals("Language!", language, ai_language());
                addToMechList(first(ai_mechListNamesForAngleBracketCategory(selectedItem(cb))), word);
                inputChooser.forceUpdate()
              }),
              // TODO jbutton("Remove", rThread { removeFromMechList(first(ai_mechListNamesForAngleBracketCategory(selectedItem(cb))), word)})
          )));
      }))));
  }
}

Author comment

Began life as a copy of #1017001

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: #1017339
Snippet name: Categories For Each Word [Dyn Module, OK]
Eternal ID of this version: #1017339/26
Text MD5: 74233ee18db7256f4369d6bee9270333
Transpilation MD5: 63849785eb53a1cdd9ef6e2fbe18892d
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-08 13:27:29
Source code size: 2180 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 473 / 6514
Version history: 25 change(s)
Referenced in: