static void fillJMenu(JMenu m, O... x) { 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 (eqOneOf(o, "***", "---", "===", "")) m.addSeparator(); ifclass LiveValue else if (o instanceof LiveValue && o/LiveValue.getType() == S.class && isRunnableX(y)) { final LiveValue lv = cast o; final JMenuItem mi = jmenuItem("", y); lv.onChange(r { setText(mi, lv!) } ); // TODO: weak reference setText(mi, lv!); m.add(mi); } 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 print("Unknown menu item: " + o); } }