!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 words = words(input); ai_setLanguage(language); final Map> wordCategories = ai_wordCategoriesWithElements(); form.setComponentAndRevalidateParent(makeForm(pairsToParams(map(words, func(fS word) -> Pair { new L 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)}) ))); })))); } }