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

45
LINES

< > BotCompany Repo | #1004035 // fillJMenu

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (3236L) is out of date.

1  
static void fillJMenu(final JMenu m, O... x) {
2  
  //ifdef fillJMenu_debug
3  
  //print("fillJMenu " + m);
4  
  //endifdef
5  
  if (x == null) ret;
6  
  for i over x: {
7  
    O o = x[i], y = get(x, i+1);
8  
    if (o instanceof L)
9  
      fillJMenu(m, asArray((L) o));
10  
    else if (isMenuSeparatorIndicator(o)) {
11  
      if (menuItemCount(m) != 0) // auto-skip separator if at top
12  
        m.addSeparator();
13  
    }
14  
    ifclass LiveValue
15  
    else if (o instanceof LiveValue && o/LiveValue.getType() == S.class && isRunnableX(y)) {
16  
      final LiveValue<S> lv = cast o;
17  
      final JMenuItem mi = jmenuItem(or2(unCurlyBracket(lv!), "..."), y);
18  
      bindLiveValueListenerToComponent(mi, lv, r {
19  
        S s = lv!;
20  
        if (isCurlyBracketed(s)) {
21  
          setEnabled(mi, false);
22  
          s = unCurlyBracket(s);
23  
        } else
24  
          setEnabled(mi, true);
25  
        setText(mi, s);
26  
        revalidate(m);
27  
      });
28  
      print("bound live value " + lv + " to menu item " + mi);
29  
      m.add(mi);
30  
      ++i;
31  
    }
32  
    endif
33  
    else if (o instanceof S && isRunnableX(y)) {
34  
      m.add(jmenuItem((S) o, y));
35  
      ++i;
36  
    } else if (o instanceof JMenuItem)
37  
      m.add((JMenuItem) o); // "call" might use wrong method
38  
    else if (o instanceof S || o instanceof Action || o instanceof Component)
39  
      call(m, "add", o);
40  
    else if (o == null && y instanceof Runnable)
41  
      ++i; // text == null => disabled item
42  
    else if (o != null)
43  
      print("Unknown menu item: " + o);
44  
  }
45  
}

Author comment

Began life as a copy of #1003659

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004035
Snippet name: fillJMenu
Eternal ID of this version: #1004035/23
Text MD5: 3661d0958a42827ecfbe83b7c7933b76
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-19 20:15:17
Source code size: 1502 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 635 / 759
Version history: 22 change(s)
Referenced in: [show references]