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

74
LINES

< > BotCompany Repo | #1035747 // JTargetAndActualSlider

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (12320L) is out of date.

1  
sclass JTargetAndActualSlider extends MetaWithChangeListeners is Swingable {
2  
  new TargetAndActual<Double> data;
3  
  settableWithVar bool showSlider = true;
4  
  settableWithVar bool sliderEnabled = true;
5  
  settableWithVar double min;
6  
  settableWithVar double max = 100;
7  
  settableWithVar int decimalsToShow = 1;
8  
  settableWithVar int widthOfNumbers = 50;
9  
  settableWithVar S unit;
10  
  settableWithVar S description;
11  
  settableWithVar int preferredBarWidth = 50;
12  
  
13  
  // set to false to use ints
14  
  settable bool scaling = true;
15  
16  
  transient JColorBar bar;
17  
  transient JSlider slider;
18  
  transient JLabel lblActual, lblTarget;
19  
  
20  
  *() {}
21  
  *(TargetAndActual<Double> *data) {}
22  
  
23  
  double value() { ret unnull(data.value()); }
24  
  double target() { ret unnull(data.target()); }
25  
26  
  cachedVisualize {
27  
    bar = swing(-> new JColorBar().max(max));
28  
    jPreferWidth(bar, preferredBarWidth);
29  
    if (showSlider) {
30  
      slider = scaling
31  
        ? jLiveValueSlider_double_bothWays(min, max, data.varTarget())
32  
        : jLiveValueSlider_double_noScaling(iround(min), iround(max), data.varTarget());
33  
      jPreferWidth(slider, preferredBarWidth);
34  
    }
35  
    lblActual = jlabel();
36  
    lblTarget = jlabel();
37  
    data.varActual().onChangeAndNow(-> {
38  
      bar.setValue(value());
39  
      setText(lblActual, renderValue(value()));
40  
    });
41  
    data.varTarget().onChangeAndNow(-> {
42  
      setText(lblTarget, renderValue(target()));
43  
    });
44  
      
45  
    varSliderEnabled().onChangeAndNow(-> setEnabled(slider, sliderEnabled));
46  
    
47  
    ret vstack/*WithSpacing*/(
48  
      slider == null ?: westCenterAndEastWithMargin(
49  
        jlabel(spaceCombine("Target", description)), slider,
50  
        jMinWidth(widthOfNumbers, lblTarget)),
51  
      westCenterAndEastWithMargin(
52  
        jlabel(spaceCombine("Actual", description)), bar,
53  
        jMinWidth(widthOfNumbers, lblActual)));
54  
  }
55  
  
56  
  swappable S renderValue(double value) {
57  
    ret spaceCombine(!scaling ? n2(iround(value)) : formatDoubleX(value, decimalsToShow), unit);
58  
  }
59  
  
60  
  JSlider slider() {
61  
    visualize();
62  
    ret slider;
63  
  }
64  
  
65  
  selfType target(double target) {
66  
    data.target(target);
67  
    this;
68  
  }
69  
  
70  
  selfType value(double value) {
71  
    data.value(value);
72  
    this;
73  
  }
74  
}

Author comment

Began life as a copy of #1035746

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035747
Snippet name: JTargetAndActualSlider
Eternal ID of this version: #1035747/29
Text MD5: 22c06f226810d4b9c563952d5feab939
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-29 22:43:56
Source code size: 2267 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 191 / 384
Version history: 28 change(s)
Referenced in: [show references]