Uses 108K of libraries. Click here for Pure Java version (16089L/113K).
1 | !7 |
2 | |
3 | sclass ClipboardContents > DynSCP { |
4 | S imageMD5, text; |
5 | |
6 | JComponent visualize() { |
7 | ret awtEvery(super.visualize(), 3000, 0, r actualUpdate); |
8 | } |
9 | |
10 | void actualUpdate { |
11 | temp enter(); |
12 | |
13 | Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); |
14 | S mimeTypes = joinWithNewLine(mimeTypes(transferable)); |
15 | |
16 | L<File> f = getFilesFromClipboard(); |
17 | if (nempty(f)) { |
18 | S s = lines(map f2s(f)); |
19 | if (eq(s, getText(componentOfType(JTextArea, getComponent())))) ret; |
20 | setModuleName("Clipboard: " + n2(f, "file")); |
21 | setComponent(typeWriterTextArea(s)); |
22 | ret; |
23 | } |
24 | |
25 | BufferedImage img = getImageFromClipboard(); |
26 | if (img != null) { |
27 | S md5 = md5OfRGBImage(new RGBImage(img)); |
28 | if (neq(md5, imageMD5)) { |
29 | setFields(imageMD5 := md5, text := null); |
30 | setComponent(scrollableImageSurface(img)); |
31 | setModuleName("Clipboard: " + img.getWidth() + "*" + img.getHeight() + " px image"); |
32 | } |
33 | ret; |
34 | } |
35 | |
36 | setField(imageMD5 := null); |
37 | S s = getTextFromClipboard(); |
38 | if (s != null) { |
39 | if (neq(text, s)) { |
40 | setField(text := s); |
41 | setComponent(typeWriterTextArea(mimeTypes + "\n\n" + s)); |
42 | setModuleName("Clipboard: " + quote(escapeNewLines(shorten(s, 256)))); |
43 | } |
44 | ret; |
45 | } |
46 | |
47 | setField(text := null); |
48 | |
49 | // empty clipboard or unknown contents |
50 | setComponent(jpanel()); |
51 | |
52 | setModuleName(transferable != null |
53 | ? "Unknown clipboard contents (" + mimeTypes + ")" |
54 | : "Empty clipboard"); |
55 | } |
56 | } |
Began life as a copy of #1006099
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016902 |
Snippet name: | Clipboard Contents [Dyn Module] |
Eternal ID of this version: | #1016902/10 |
Text MD5: | 4b7a3c32f2bf9c6cd8840b3323be6086 |
Transpilation MD5: | e85a1177774cf62eadfd1e9c1f126fbf |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-10-27 12:37:36 |
Source code size: | 1626 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 415 / 999 |
Version history: | 9 change(s) |
Referenced in: | [show references] |