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

59
LINES

< > BotCompany Repo | #1009858 // calAddAutoLayoutSwitch

JavaX fragment (include)

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<Bool> calAddAutoLayoutSwitch_center;

static void calAddAutoLayoutSwitch(final Var<CirclesAndLines> cal, final Canvas canvas, final O modifyLayout, final bool on) {
  addToWindow(canvas, calAddAutoLayoutSwitch_make(cal, canvas, modifyLayout, on);
}

static JPanel calAddAutoLayoutSwitch_make(final Var<CirclesAndLines> 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;
  });
}

Author comment

Began life as a copy of #1009856

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1009858
Snippet name: calAddAutoLayoutSwitch
Eternal ID of this version: #1009858/30
Text MD5: 4c6f862f09d74b54476c4d5ac6aa4fe8
Author: stefan
Category: javax / a.i. / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-19 22:33:01
Source code size: 2258 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 459 / 518
Version history: 29 change(s)
Referenced in: [show references]