Libraryless. Click here for Pure Java version (3289L/21K).
1 | sclass JFastLogView_noWrap extends JComponent implements Scrollable { |
2 | LS lines = syncList(); |
3 | bool endsWithNewLine, verbose; |
4 | |
5 | public Dimension getPreferredScrollableViewportSize() { ret getPreferredSize(); } |
6 | |
7 | public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { return 20; } |
8 | |
9 | public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { |
10 | ret (direction == SwingConstants.HORIZONTAL ? visibleRect.width : visibleRect.height)*5/6; |
11 | } |
12 | |
13 | public bool getScrollableTracksViewportWidth() { false; } |
14 | public bool getScrollableTracksViewportHeight() { false; } |
15 | |
16 | public void paint(Graphics g) { |
17 | //if (verbose) _print("JFastLogView_noWrap painting"); |
18 | int w = getWidth(), h = getHeight(); |
19 | g.setColor(getBackground()); |
20 | g.fillRect(0, 0, w, h); |
21 | g.setColor(getForeground()); |
22 | FontMetrics fm = componentFontMetrics(this); |
23 | int fh = fm.getHeight(); |
24 | Rectangle clip = g.getClipBounds(); |
25 | int start, end; |
26 | if (clip == null) { start = 0; end = l(lines); } |
27 | else { |
28 | start = max(0, clip.y/fh); |
29 | end = min(l(lines), idiv_ceil(clip.y+clip.height, fh)); |
30 | } |
31 | //printVars(+start, +end); |
32 | int y = fm.getAscent()+start*fh; |
33 | for (int i = start; i < end; i++) { |
34 | S s = get(lines, i); |
35 | if (s != null) g.drawString(s, 0, y); |
36 | y += fh; |
37 | } |
38 | //if (verbose) _print("JFastLogView_noWrap painted"); |
39 | } |
40 | |
41 | public Dimension getPreferredSize() { |
42 | FontMetrics fm = componentFontMetrics(this); |
43 | if (fm == null) ret new Dimension(50, 50); // not renderable yet |
44 | int fh = fm.getHeight(); |
45 | int w = 0; |
46 | for i over lines: { |
47 | S s = get(lines, i); |
48 | w = max(w, fm.stringWidth(unnull(s))); // TODO: just count chars |
49 | } |
50 | ret new Dimension(w, fh*l(lines)); |
51 | } |
52 | |
53 | *() {} |
54 | *(S text) { setText(text); } |
55 | |
56 | { |
57 | componentPopupMenuItem(this, "Copy full text", r copyFullText); |
58 | } |
59 | |
60 | // API |
61 | |
62 | // returns true if changed |
63 | bool setLines(Collection<S> lines) { |
64 | LS newList = asSyncList(lines); |
65 | if (eq(this.lines, newList)) false; |
66 | this.lines = newList; |
67 | _revalidate(this); |
68 | true; |
69 | } |
70 | |
71 | // returns true if changed |
72 | bool setText(S text) { |
73 | endsWithNewLine = endsWithNewLine(text); |
74 | ret setLines(lines(text)); |
75 | } |
76 | |
77 | void append(S text) { |
78 | if (nempty(text)) setText(getText() + text); |
79 | } |
80 | |
81 | S getText() { |
82 | ret lines_rtrimIf(!endsWithNewLine, cloneList(lines)); |
83 | } |
84 | |
85 | void copyFullText { |
86 | copyTextToClipboard(getText()); |
87 | } |
88 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024202 |
Snippet name: | JFastLogView_noWrap |
Eternal ID of this version: | #1024202/26 |
Text MD5: | 225a024411f869d3c8e1f753156ea8df |
Transpilation MD5: | 23ca11be3dd16e5c502b7c4a27bfc3a2 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-30 23:39:42 |
Source code size: | 2620 bytes / 88 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 462 / 1230 |
Version history: | 25 change(s) |
Referenced in: | [show references] |