static void calAddAutoLayoutSwitch(CirclesAndLines cal, final Canvas canvas, O modifyLayout, bool on) { calAddAutoLayoutSwitch(new Var(cal), canvas, modifyLayout, on); } static double calAddAutoLayoutSwitch_scale = 100; static new ThreadLocal calAddAutoLayoutSwitch_center; static void calAddAutoLayoutSwitch(final Var cal, final Canvas canvas, final O modifyLayout, final bool on) { addToWindow(canvas, calAddAutoLayoutSwitch_make(cal, canvas, modifyLayout, on); } static JPanel calAddAutoLayoutSwitch_make(final Var cal, final Canvas canvas, final O modifyLayout, final bool on) { final bool center = boolOptParam(calAddAutoLayoutSwitch_center); ret swing(func -> JPanel { // dummy for getting desiredLength CALSpringLayout _layout = new CALSpringLayout(cal!); if (l(cal->circles) <= 2) _layout.desiredLength = 0.45; callF(modifyLayout, _layout); final JCheckBox cb = jcheckbox("Auto-Layout", on); final JButton btnNew = jbutton("Scramble", r { cal_scramble(cal!); updateCanvas(canvas); }); final JCheckBox cb2 = jcheckbox("Center", center); final JSpinner lineLength = setSpinnerStepSize(5, jspinner(iround(_layout.desiredLength*calAddAutoLayoutSwitch_scale), 1, 50)); JPanel panel = jcenteredline(cb, btnNew, cb2, jlabel("Line length:"), lineLength); awtCalcEvery2(canvas, 100, new Runnable { CALSpringLayout layout; CirclesAndLines lastCAL = cal!; bool lastOn; public void run() { bool x = false; bool on = isChecked(cb); if (on) { if (cal! != lastCAL || layout == null) { lastCAL = cal!; layout = new CALSpringLayout(cal!); layout.center = false; callF(modifyLayout, layout); } layout.desiredLength = intFromSpinner(lineLength)/calAddAutoLayoutSwitch_scale; if (!lastOn) layout.clear(); layout.step(); x = true; } lastOn = on; if (isChecked(cb2)) { calCenterStepwise(cal!, 0.1); x = true; } if (x) updateCanvas(canvas); } }); ret panel; }); }