Libraryless. Click here for Pure Java version (9937L/55K).
static <A extends JComponent> A bindToComponent(A component, Runnable onShow, Runnable onUnShow) { swing { final Var<Bool> flag = new(false); component.addAncestorListener(new AncestorListener { public void ancestorAdded(AncestorEvent event) { if (flag!) print("Warning: bindToComponent logic failure"); flag.set(true); pcallF(onShow); } public void ancestorRemoved(AncestorEvent event) { if (!flag!) print("Warning: bindToComponent logic failure"); flag.set(false); pcallF(onUnShow); } public void ancestorMoved(AncestorEvent event) { } }); if (component.isShowing()) { // Hopefully this matches the AncestorListener logic flag.set(true); pcallF(onShow); } } ret component; } static <A extends JComponent> A bindToComponent(A component, Runnable onShow) { ret bindToComponent(component, onShow, null); } // passing a value from onShow to onUnShow static <A extends JComponent, B> A bindToComponent(A component, IF0<B> onShow, IVF1<B> onUnShow) { new Var<B> b; ret bindToComponent(component, -> b.set(onShow!), -> { try { onUnShow.get(b!); } finally { b.set(null); } }); }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment