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.

static void fillJMenu(final JMenu m, O... x) {
  //ifdef fillJMenu_debug
  //print("fillJMenu " + m);
  //endifdef
  if (x == null) ret;
  for i over x: {
    O o = x[i], y = get(x, i+1);
    if (o instanceof L)
      fillJMenu(m, asArray((L) o));
    else if (isMenuSeparatorIndicator(o)) {
      if (menuItemCount(m) != 0) // auto-skip separator if at top
        m.addSeparator();
    }
    ifclass LiveValue
    else if (o instanceof LiveValue && o/LiveValue.getType() == S.class && isRunnableX(y)) {
      final LiveValue<S> lv = cast o;
      final JMenuItem mi = jmenuItem(or2(unCurlyBracket(lv!), "..."), y);
      bindLiveValueListenerToComponent(mi, lv, r {
        S s = lv!;
        if (isCurlyBracketed(s)) {
          setEnabled(mi, false);
          s = unCurlyBracket(s);
        } else
          setEnabled(mi, true);
        setText(mi, s);
        revalidate(m);
      });
      print("bound live value " + lv + " to menu item " + mi);
      m.add(mi);
      ++i;
    }
    endif
    else if (o instanceof S && isRunnableX(y)) {
      m.add(jmenuItem((S) o, y));
      ++i;
    } else if (o instanceof JMenuItem)
      m.add((JMenuItem) o); // "call" might use wrong method
    else if (o instanceof S || o instanceof Action || o instanceof Component)
      call(m, "add", o);
    else if (o == null && y instanceof Runnable)
      ++i; // text == null => disabled item
    else if (o != null)
      print("Unknown menu item: " + o);
  }
}

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: 552 / 646
Version history: 22 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1015890 - fillJPopupMenu - see fillJMenu