Transpiled version (24651L) is out of date.
sclass JG22Labels extends MetaWithChangeListeners { settableWithVar bool showCount = true; settableWithVar bool allowCreation = true; settableWithVar L<G22Label> labels; transient JLabel lblInfo = jlabel(); transient JPanel line = jline(); transient ReliableSingleThread rstUpdate = new(r _update); transient settableWithVar JG22Label creating; cachedVisualize { varLabels().onChangeAndNow(rstUpdate); varCreating().onChangeAndNow(rstUpdate); ret borderless(jscrollHorizontal(line)); } void _update { var labels = labels(); removeAllComponents(line); if (showCount) { setText(lblInfo, nLabels(labels) + (empty(labels) ? "" : ":")); line.add(lblInfo); } fOr (label : labels) line.add(makeLabelComponent(label)); if (creating != null) line.add(creating); else if (allowCreation) line.add(jimageButtonScaledToWidth(16, #1103069, "Add a label", r _addALabel)); revalidate(line); } JG22Label makeLabelComponent(G22Label label) { var lbl = new JG22Label(label); componentPopupMenuItem(lbl.jLabel, "Remove label", rThread { removeLabel(label) }); ret lbl; } bool containsLabel(S text) { ret containsPred(labels, lbl -> lbl.textIs(text)); } swappable void addLabel(S text) {} swappable void removeLabel(G22Label label) {} void _addALabel { new JG22Label lbl; lbl.onDoneEditing(text -> { if (!containsLabel(text)) { print("Adding label: " + text); addLabel(text); } else infoBox("Label already contained"); creating(null); }); focusOnFirstShowVerbose(lbl.focusablePart()); creating(lbl); } }
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: | 633 / 842 | 
| Version history: | 21 change(s) | 
| Referenced in: | [show references] |