Download Jar. Libraryless. Click here for Pure Java version (9707L/72K).
!7 static LPair<IntRange> arrows = synchroList(); p-experiment { S text = lines(sentencesAfterLines_withPeriodOnly(mechList_raw("Simple Wikipedia: Peafowl"))); //jtextpane(text) JTextPane tp = swing(func -> JTextPane { ret new JTextPane { public void paint(Graphics _g) { Graphics2D g = cast _g; super.paint(g); pcall { Color arrowColor = colorWithAlpha(Color.red, 0.3); S text = getText(); for (Pair<IntRange> p : cloneList(arrows)) { Rect r1 = textComponent_substringRect(this, p.a); Rect r2 = textComponent_substringRect(this, p.b); if (r1 != null && r2 != null) { fillRect(g, r1, colorWithAlpha(Color.green, 0.2)); fillRect(g, r2, colorWithAlpha(Color.red, 0.2)); //drawArrowBetweenRects(g, r1, r2, arrowColor); drawArrowBetweenPoints(g, centerOfRect(r1), centerOfRect(r2), arrowColor); } else if (r1 != null) drawText(g, "?", centerTextInRect(g.getFontMetrics(), "?", r1), arrowColor); } } } }; }); setTextCaret0(tp, text); L<S> tok = javaTok(text); addPair(arrows, tokenToCharRange(tok, indexOfIC(tok, "it")), tokenToCharRange(tok, indexOfIC(tok, "peafowl"))); Set<S> set = mechSetCI("Backreferencing words"); Set<IntRange> have = asHashSet(firstOfPairs(arrows)); for (int i = 1; i < l(tok); i += 2) if (set.contains(tok.get(i)) && !arrows.contains(tokenToCharRange(tok, i))) addPair(arrows, tokenToCharRange(tok, i), null); // show question mark showFrame(setFontSize(30, tp)); hideConsole(); }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1015599 |
Snippet name: | Show text with arrows Spike [OK] |
Eternal ID of this version: | #1015599/28 |
Text MD5: | 8fff16a8fd383d3c922a556ba461a36e |
Transpilation MD5: | c5d3dc9424d5d1ffb63bebae05d2a4ff |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-08 23:36:22 |
Source code size: | 1725 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 438 / 1218 |
Version history: | 27 change(s) |
Referenced in: | [show references] |