!7 static SingleComponentPanel scp; static int startIndex; concept Sentence { S text; S action; } p-substance { unswing { db(); indexConceptField(Sentence, "text"); L sentences = toLinesFullTrim(loadSnippet(#1008606)); sentences = notStartingWith("\"", sentences); time { makeUniqueConcepts(Sentence, "text", sentences); } } showFrame(centerAndSouth(scp = new SingleComponentPanel, withTopMargin(20, jcenteredline( jbutton("Prev", r { makePanel(max(startIndex-10, 0)) }), jbutton("Next", r { if (startIndex+10 < countConcepts(Sentence)) makePanel(startIndex+10) }), jbutton("Random", r { makePanel(random(countConcepts(Sentence))/10*10) }))))); makePanel(0); } svoid makePanel(int startIndex) { main.startIndex = startIndex; JPanel panel = gridLayoutPanel_trackWidth_evenlySpacedCols(2); panel.add(jlabel("Sentence")); panel.add(jlabel("Action")); for (final Sentence s : takeFirst(10, dropFirst(startIndex, list(Sentence)))) { final JTextField tfText = jtextfield_caretLeft(s.text); panel.add(tfText); new Matches m; if (jmatch("subject=* (*/*)", s.action, m)) pcall { int from = parseInt($2), len = parseInt($3); tfText.select(from, from+len); } bool hasAction = nempty(s.action); final JTextField tf = jtextfield(or2(s.action, "screw it")); final new Var reviseBtn, okBtn; okBtn.set(jbutton("OK", r { cset(s, action := getTextTrim(tf)); disableTextField(tf); replaceComponent(okBtn!, reviseBtn!); })); reviseBtn.set(jbutton("Revise", r { cset(s, action := null); enableTextField(tf); replaceComponent(reviseBtn!, okBtn!); })); if (hasAction) disableTextField(tf); panel.add(centerAndEast(tf, hasAction ? reviseBtn! : okBtn!)); onCaret(tfText, r { int i = trimIndexRight(s.text, tfText.getSelectionStart()); int j = trimIndexLeft(s.text, tfText.getSelectionEnd()); if (j > i && s.action == null) tf.setText("subject=" + quote(substring(s.text, i, j)) + " (" + i + "/" + (j-i) + ")"); }); } scp.setComponent(jscroll(panel)); }