Download Jar. Libraryless. Click here for Pure Java version (9707L/72K).
1 | !7 |
2 | |
3 | static LPair<IntRange> arrows = synchroList(); |
4 | |
5 | p-experiment { |
6 | S text = lines(sentencesAfterLines_withPeriodOnly(mechList_raw("Simple Wikipedia: Peafowl"))); |
7 | //jtextpane(text) |
8 | JTextPane tp = swing(func -> JTextPane { |
9 | ret new JTextPane { |
10 | public void paint(Graphics _g) { |
11 | Graphics2D g = cast _g; |
12 | super.paint(g); |
13 | |
14 | pcall { |
15 | Color arrowColor = colorWithAlpha(Color.red, 0.3); |
16 | S text = getText(); |
17 | for (Pair<IntRange> p : cloneList(arrows)) { |
18 | Rect r1 = textComponent_substringRect(this, p.a); |
19 | Rect r2 = textComponent_substringRect(this, p.b); |
20 | if (r1 != null && r2 != null) { |
21 | fillRect(g, r1, colorWithAlpha(Color.green, 0.2)); |
22 | fillRect(g, r2, colorWithAlpha(Color.red, 0.2)); |
23 | //drawArrowBetweenRects(g, r1, r2, arrowColor); |
24 | drawArrowBetweenPoints(g, centerOfRect(r1), centerOfRect(r2), arrowColor); |
25 | } else if (r1 != null) |
26 | drawText(g, "?", centerTextInRect(g.getFontMetrics(), "?", r1), arrowColor); |
27 | } |
28 | } |
29 | } |
30 | }; |
31 | }); |
32 | setTextCaret0(tp, text); |
33 | |
34 | L<S> tok = javaTok(text); |
35 | addPair(arrows, |
36 | tokenToCharRange(tok, indexOfIC(tok, "it")), |
37 | tokenToCharRange(tok, indexOfIC(tok, "peafowl"))); |
38 | |
39 | Set<S> set = mechSetCI("Backreferencing words"); |
40 | Set<IntRange> have = asHashSet(firstOfPairs(arrows)); |
41 | for (int i = 1; i < l(tok); i += 2) |
42 | if (set.contains(tok.get(i)) && !arrows.contains(tokenToCharRange(tok, i))) |
43 | addPair(arrows, tokenToCharRange(tok, i), null); // show question mark |
44 | |
45 | showFrame(setFontSize(30, tp)); |
46 | |
47 | hideConsole(); |
48 | } |
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: | 439 / 1220 |
Version history: | 27 change(s) |
Referenced in: | [show references] |