Download Jar. Uses 3874K of libraries. Click here for Pure Java version (8942L/62K).
1 | !7 |
2 | |
3 | static JFrame frame; |
4 | static S imageMD5, text; |
5 | |
6 | sS title = "AI Clipboard"; |
7 | |
8 | p-substance { |
9 | framesBot(); |
10 | frame = showFrame(title); |
11 | |
12 | // TODO: update less often if a non-text is in clipboard |
13 | installTimer(frame, 1000, 0, r { |
14 | update(); |
15 | }); |
16 | hideConsoleIfMainProgram(); |
17 | } |
18 | |
19 | svoid update { |
20 | BufferedImage img = getImageFromClipboard(); |
21 | if (img != null) { |
22 | S md5 = md5OfRGBImage(new RGBImage(img)); |
23 | if (neq(md5, imageMD5)) { |
24 | imageMD5 = md5; |
25 | text = null; |
26 | setFrameContents(frame, jscroll(new ImageSurface(img))); |
27 | setFrameTitle(frame, title + ": " + img.getWidth() + "*" + img.getHeight() + " px image"); |
28 | } |
29 | ret; |
30 | } |
31 | imageMD5 = null; |
32 | S s = getTextFromClipboard(); |
33 | if (s != null) { |
34 | if (neq(text, s)) { |
35 | text = s; |
36 | JComponent x = explainText(s); |
37 | JTextArea ta = typeWriterTextArea(s); |
38 | setFrameContents(frame, x != null ? vsplit(x, ta) : ta); |
39 | setFrameTitle(frame, title + ": " + quote(escapeNewLines(shorten(s, 256)))); |
40 | } |
41 | ret; |
42 | } |
43 | text = null; |
44 | // empty clipboard or unknown contents |
45 | setFrameContents(frame, new JPanel); |
46 | |
47 | Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); |
48 | setFrameTitle(frame, transferable != null ? "Unknown clipboard contents (" + join(", ", mimeTypes(transferable)) + ")" : "Empty clipboard"); |
49 | } |
50 | |
51 | static JComponent explainText(S s) null on exception { |
52 | Collection<S> ids = collectPossibleGlobalIDs(s); |
53 | if (empty(ids)) null; |
54 | new L<S> l; |
55 | aiConceptsMap_clearCache(60); |
56 | for (S id : ids) { |
57 | S name = conceptToName(id); |
58 | if (neq(id, name)) |
59 | l.add(id + " = " + name); |
60 | } |
61 | if (empty(l)) null; |
62 | ret makeBold(jTextArea(lines(l))); |
63 | } |
Began life as a copy of #1006099
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, bvmoasoxxqgd, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga, wtqryiryparv
No comments. add comment
Snippet ID: | #1007441 |
Snippet name: | AI Clipboard (with translation of concept language to english) |
Eternal ID of this version: | #1007441/13 |
Text MD5: | f57eaecf02ef8d2f0fa90a656aba159c |
Transpilation MD5: | 2f6ced2e90df3119ae4a67f9ece1e4fd |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-03-24 11:58:36 |
Source code size: | 1773 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 581 / 1539 |
Version history: | 12 change(s) |
Referenced in: | [show references] |