sclass ImageChooser extends SingleComponentPanel { new ImageSurface is; new JTextField tfPath; *(BufferedImage img) { this(); setImage(img); } *(RGBImage img) { this(img.getBufferedImage()); } ifclass PNGFile *(PNGFile png) { this(png == null ? null : png.getImage()); } endif *() { bindToComponent(this, r { is.zoomToWindow() }); is.loadFromClipboard(); //setComponent(withLabel("Path to image or snippet ID:", tfPath)); setComponent(jMinSize(100, 100, jscroll(is))); componentPopupMenu(is, voidfunc(JPopupMenu menu) { addMenuItem(menu, "Screenshot in 3", r { thread "Screenshot in 3" { sleep(3000); final BufferedImage img = shootScreen2(); awt { is.setImage(img); infoMessage("Screenshot taken (" + img.getWidth() + "*" + img.getHeight() + " px)", 2); } } }); addMenuItem(menu, "Load snippet or file...", r { final new JTextField tf; showFormTitled("Load image from snippet or file", "Path or snippet ID", tf, r { is.setImage(loadImage2(tf.getText().trim())); is.zoomToDisplaySize(); }); }); }); } bool hasImage() { ret is.getImage() != null && is.getImage().getWidth()*is.getImage().getHeight() > 1; } BWImage getBWImage() { ret is.getImage() == null ? null : new BWImage(is.getImage()); } BufferedImage getImage() { ret hasImage() ? is.getImage() : null; } void setImage(BufferedImage img) { is.setImage(img); is.zoomToWindow(); } ifclass PNGFile PNGFile createPNGFile() { ret hasImage() ? new PNGFile(getImage()) : null; } endif void setTitleForUpload(S title) { is.titleForUpload = title; } }