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

59
LINES

< > BotCompany Repo | #1009858 // calAddAutoLayoutSwitch

JavaX fragment (include)

1  
static void calAddAutoLayoutSwitch(CirclesAndLines cal, final Canvas canvas, O modifyLayout, bool on) {
2  
  calAddAutoLayoutSwitch(new Var(cal), canvas, modifyLayout, on);
3  
}
4  
5  
static double calAddAutoLayoutSwitch_scale = 100;
6  
static new ThreadLocal<Bool> calAddAutoLayoutSwitch_center;
7  
8  
static void calAddAutoLayoutSwitch(final Var<CirclesAndLines> cal, final Canvas canvas, final O modifyLayout, final bool on) {
9  
  addToWindow(canvas, calAddAutoLayoutSwitch_make(cal, canvas, modifyLayout, on);
10  
}
11  
12  
static JPanel calAddAutoLayoutSwitch_make(final Var<CirclesAndLines> cal, final Canvas canvas, final O modifyLayout, final bool on) {
13  
  final bool center = boolOptParam(calAddAutoLayoutSwitch_center);
14  
15  
  ret swing(func -> JPanel {
16  
    // dummy for getting desiredLength
17  
    CALSpringLayout _layout = new CALSpringLayout(cal!);
18  
    if (l(cal->circles) <= 2) _layout.desiredLength = 0.45;
19  
    callF(modifyLayout, _layout);
20  
    
21  
    final JCheckBox cb = jcheckbox("Auto-Layout", on);
22  
    final JButton btnNew = jbutton("Scramble", r {
23  
      cal_scramble(cal!);
24  
      updateCanvas(canvas);
25  
    });
26  
    final JCheckBox cb2 = jcheckbox("Center", center);
27  
    final JSpinner lineLength = setSpinnerStepSize(5, jspinner(iround(_layout.desiredLength*calAddAutoLayoutSwitch_scale), 1, 50));
28  
    JPanel panel = jcenteredline(cb, btnNew, cb2, jlabel("Line length:"), lineLength);
29  
    awtCalcEvery2(canvas, 100, new Runnable {
30  
      CALSpringLayout layout;
31  
      CirclesAndLines lastCAL = cal!;
32  
      bool lastOn;
33  
      
34  
      public void run() {
35  
        bool x = false;
36  
        bool on = isChecked(cb);
37  
        if (on) {
38  
          if (cal! != lastCAL || layout == null) {
39  
            lastCAL = cal!;
40  
            layout = new CALSpringLayout(cal!);
41  
            layout.center = false;
42  
            callF(modifyLayout, layout);
43  
          }
44  
          layout.desiredLength = intFromSpinner(lineLength)/calAddAutoLayoutSwitch_scale;
45  
          if (!lastOn) layout.clear();
46  
          layout.step();
47  
          x = true;
48  
        }
49  
        lastOn = on;
50  
        if (isChecked(cb2)) {
51  
          calCenterStepwise(cal!, 0.1);
52  
          x = true;
53  
        }
54  
        if (x) updateCanvas(canvas);
55  
      }
56  
    });
57  
    ret panel;
58  
  });
59  
}

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: 460 / 519
Version history: 29 change(s)
Referenced in: [show references]