Transpiled version (24651L) is out of date.
1 | sclass JG22Labels extends MetaWithChangeListeners { |
2 | settableWithVar bool showCount = true; |
3 | settableWithVar bool allowCreation = true; |
4 | settableWithVar L<G22Label> labels; |
5 | |
6 | transient JLabel lblInfo = jlabel(); |
7 | transient JPanel line = jline(); |
8 | transient ReliableSingleThread rstUpdate = new(r _update); |
9 | transient settableWithVar JG22Label creating; |
10 | |
11 | cachedVisualize { |
12 | varLabels().onChangeAndNow(rstUpdate); |
13 | varCreating().onChangeAndNow(rstUpdate); |
14 | ret borderless(jscrollHorizontal(line)); |
15 | } |
16 | |
17 | void _update { |
18 | var labels = labels(); |
19 | |
20 | removeAllComponents(line); |
21 | if (showCount) { |
22 | setText(lblInfo, nLabels(labels) + (empty(labels) ? "" : ":")); |
23 | line.add(lblInfo); |
24 | } |
25 | |
26 | fOr (label : labels) |
27 | line.add(makeLabelComponent(label)); |
28 | |
29 | if (creating != null) |
30 | line.add(creating); |
31 | else if (allowCreation) |
32 | line.add(jimageButtonScaledToWidth(16, #1103069, "Add a label", r _addALabel)); |
33 | |
34 | revalidate(line); |
35 | } |
36 | |
37 | JG22Label makeLabelComponent(G22Label label) { |
38 | var lbl = new JG22Label(label); |
39 | componentPopupMenuItem(lbl.jLabel, "Remove label", rThread { removeLabel(label) }); |
40 | ret lbl; |
41 | } |
42 | |
43 | bool containsLabel(S text) { |
44 | ret containsPred(labels, lbl -> lbl.textIs(text)); |
45 | } |
46 | |
47 | swappable void addLabel(S text) {} |
48 | swappable void removeLabel(G22Label label) {} |
49 | |
50 | void _addALabel { |
51 | new JG22Label lbl; |
52 | lbl.onDoneEditing(text -> { |
53 | if (!containsLabel(text)) { |
54 | print("Adding label: " + text); |
55 | addLabel(text); |
56 | } else |
57 | infoBox("Label already contained"); |
58 | creating(null); |
59 | }); |
60 | focusOnFirstShowVerbose(lbl.focusablePart()); |
61 | creating(lbl); |
62 | } |
63 | } |
Began life as a copy of #1034502
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034504 |
Snippet name: | JG22Labels - visualize a row of image recognition labels [dev.] |
Eternal ID of this version: | #1034504/22 |
Text MD5: | 37d92b3468153463ab7f5d31513fbe08 |
Author: | stefan |
Category: | javax / gazelle v / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-10 03:50:01 |
Source code size: | 1777 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 192 / 362 |
Version history: | 21 change(s) |
Referenced in: | [show references] |