Libraryless. Click here for Pure Java version (13509L/78K).
1 | sclass G22SnPSelector > MetaWithChangeListeners is Swingable { |
2 | settable new SnPSettings settings; |
3 | |
4 | // show powers of two in colors selector or all numbers? |
5 | settableWithVar bool powerOfTwoColors = false; |
6 | |
7 | // show powers of two in pixelRows selector or all numbers? |
8 | settableWithVar bool powerOfTwoPixelRows = true; |
9 | |
10 | settable int maxPixelRows = 512; |
11 | |
12 | settableWithVar bool allowDecolorizerSelection; |
13 | settableWithVar bool showDecolorizerSelection; |
14 | |
15 | JLabel lblColors; |
16 | SingleComponentPanel scpDecolorizer = scp(); |
17 | |
18 | *() {} |
19 | *(SnPSettings *settings) {} |
20 | |
21 | SnPSettings get() { ret settings; } |
22 | |
23 | cachedVisualize { |
24 | var colors = jListSpinner(colorsList(), settings.colors); |
25 | main onChange(colors, -> { |
26 | settings.colors = intFromSpinner(colors); |
27 | change(); |
28 | }); |
29 | |
30 | varPowerOfTwoColors().onChange(-> |
31 | spinnerSetNumberList(colors, colorsList()); |
32 | |
33 | swing { |
34 | var menuItem = jLiveValueCheckBoxMenuItem("Only show powers of two", varPowerOfTwoColors()); |
35 | new JPopupMenu menu; |
36 | menu.add(menuItem); |
37 | colors.setComponentPopupMenu(menu); |
38 | } |
39 | |
40 | var pixelRows = jListSpinner(pixelRowsList(), settings.pixelRows); |
41 | main onChange(pixelRows, -> { |
42 | settings.pixelRows = intFromSpinner(pixelRows); |
43 | change(); |
44 | }); |
45 | |
46 | varPowerOfTwoPixelRows().onChange(-> |
47 | spinnerSetNumberList(pixelRows, pixelRowsList()); |
48 | |
49 | swing { |
50 | var menuItem = jLiveValueCheckBoxMenuItem("Only show powers of two", varPowerOfTwoPixelRows()); |
51 | new JPopupMenu menu; |
52 | menu.add(menuItem); |
53 | pixelRows.setComponentPopupMenu(menu); |
54 | } |
55 | |
56 | lblColors = jSimpleLabel(" colors "); |
57 | bindChangeListenerToComponent(this, lblColors, |
58 | -> toolTip(lblColors, makeToolTip())); |
59 | |
60 | L controls = ll( |
61 | colors, |
62 | lblColors, |
63 | scpDecolorizer, |
64 | jSimpleLabel("@ "), |
65 | pixelRows, |
66 | jlabel(" p")); |
67 | |
68 | if (allowDecolorizerSelection) { |
69 | varShowDecolorizerSelection().onChangeAndNow(l0 updateDecolorizerView); |
70 | controls.add(horizontalStrut(3)); |
71 | controls.add(jPopDownButton_noText( |
72 | jLiveValueCheckBoxMenuItem("Select channel", varShowDecolorizerSelection()) |
73 | )); |
74 | } |
75 | |
76 | var vis = hstack(controls); |
77 | bindChangeListenerToComponent(settings, vis, l0 change); |
78 | ret vis; |
79 | } |
80 | |
81 | L<Int> colorsList() { |
82 | ret powerOfTwoColors |
83 | ? powersOfTwoUpTo(2, 256) |
84 | : virtualCountList_incl(2, 256); |
85 | } |
86 | |
87 | L<Int> pixelRowsList() { |
88 | ret powerOfTwoPixelRows |
89 | ? powersOfTwoUpTo(maxPixelRows) |
90 | : virtualCountList_incl(1, maxPixelRows); |
91 | } |
92 | |
93 | S makeToolTip() { |
94 | long pixels = area(sixteenToNine_p(settings.pixelRows)); |
95 | int colorBits = numberOfBitsNeededToRepresentNOptions(settings.colors); |
96 | int bytes = iceil_div(pixels*colorBits, 8); |
97 | ret "Information per frame: " + nBytes(bytes) +" (assuming a 16:9 aspect ratio)"; |
98 | } |
99 | |
100 | L<Decolorizer> decolorizerList() { |
101 | ret ll( |
102 | new Decolorizer.Simple, |
103 | new Decolorizer.Red, |
104 | new Decolorizer.Green, |
105 | new Decolorizer.Blue |
106 | ); |
107 | } |
108 | |
109 | void updateDecolorizerView { |
110 | if (!showDecolorizerSelection) { |
111 | scpDecolorizer.clear(); |
112 | settings.decolorizer(null); |
113 | } else { |
114 | if (settings.decolorizer == null) |
115 | settings.decolorizer(new Decolorizer.Simple); |
116 | scpDecolorizer.set(hstack( |
117 | jlabel("from channel "), |
118 | bindComboBoxToVar(settings.varDecolorizer(), |
119 | jTypedComboBox(decolorizerList())), |
120 | horizontalStrut(3) |
121 | )); |
122 | } |
123 | } |
124 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034936 |
Snippet name: | G22SnPSelector |
Eternal ID of this version: | #1034936/21 |
Text MD5: | 5e824282e57011df15853f4837e062c1 |
Transpilation MD5: | 340f37daff87a1c46bb2c5972750932c |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-04-30 14:08:22 |
Source code size: | 3655 bytes / 124 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 200 / 375 |
Version history: | 20 change(s) |
Referenced in: | [show references] |