1 | sclass ImageChooser extends SingleComponentPanel { |
2 | new ImageSurface is; |
3 | new JTextField tfPath; |
4 | |
5 | *(BufferedImage img) { |
6 | this(); |
7 | setImage(img); |
8 | } |
9 | |
10 | *(RGBImage img) { this(img.getBufferedImage()); } |
11 | |
12 | ifclass PNGFile |
13 | *(PNGFile png) { this(png == null ? null : png.getImage()); } |
14 | endif |
15 | |
16 | *() { |
17 | bindToComponent(this, r { is.zoomToWindow() }); |
18 | is.loadFromClipboard(); |
19 | //setComponent(withLabel("Path to image or snippet ID:", tfPath)); |
20 | setComponent(jMinSize(100, 100, jscroll(is))); |
21 | |
22 | componentPopupMenu(is, voidfunc(JPopupMenu menu) { |
23 | addMenuItem(menu, "Screenshot in 3", r { |
24 | thread "Screenshot in 3" { |
25 | sleep(3000); |
26 | final BufferedImage img = shootScreen2(); |
27 | awt { |
28 | is.setImage(img); |
29 | infoMessage("Screenshot taken (" + img.getWidth() + "*" + img.getHeight() + " px)", 2); |
30 | } |
31 | } |
32 | }); |
33 | |
34 | addMenuItem(menu, "Load snippet or file...", r { |
35 | final new JTextField tf; |
36 | showFormTitled("Load image from snippet or file", |
37 | "Path or snippet ID", tf, |
38 | r { |
39 | is.setImage(loadImage2(tf.getText().trim())); |
40 | is.zoomToDisplaySize(); |
41 | }); |
42 | }); |
43 | }); |
44 | } |
45 | |
46 | bool hasImage() { ret is.getImage() != null && is.getImage().getWidth()*is.getImage().getHeight() > 1; } |
47 | |
48 | BWImage getBWImage() { ret is.getImage() == null ? null : new BWImage(is.getImage()); } |
49 | |
50 | BufferedImage getImage() { ret hasImage() ? is.getImage() : null; } |
51 | |
52 | void setImage(BufferedImage img) { is.setImage(img); is.zoomToWindow(); } |
53 | |
54 | ifclass PNGFile |
55 | PNGFile createPNGFile() { ret hasImage() ? new PNGFile(getImage()) : null; } |
56 | endif |
57 | |
58 | void setTitleForUpload(S title) { is.titleForUpload = title; } |
59 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006063 |
Snippet name: | ImageChooser |
Eternal ID of this version: | #1006063/12 |
Text MD5: | 7dbc51ed1bb79f9f17c5a2ddd44a5ef1 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-09-28 09:46:52 |
Source code size: | 1845 bytes / 59 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 643 / 1433 |
Version history: | 11 change(s) |
Referenced in: | [show references] |