Uses 9620K of libraries. Click here for Pure Java version (1493L/10K/37K).
!759 lib 1003153 // magic.jar import ma.ma02.*; import drjava.util.*; import net.luaos.tb.remote.ServerConnection; import net.luaos.tb.remote.Snippet; import net.luaos.tb.remote.SnippetTypes; import net.luaos.tb.tb07.PasswordUtil; // That ImageSurface has the selector & the nice zoom stuff import prophecy.common.image.ImageSurface; import prophecy.common.image.RGBImage; p-substance { JFrame frame = showFrame(); hideConsole(); ScreenshotPanel screenshotPanel = new ScreenshotPanel(frame); setFrameContents(frame, screenshotPanel); } sclass ScreenshotPanel extends JPanel { private JButton btnUpload; private JFrame frame; private int defaultDelay = 3000; private ImageSurface imageSurface; private int delayWithFrame = 3000; public ScreenshotPanel(JFrame frame) { this.frame = frame; getContentPane().setLayout(new LetterLayout("B", "I", "I").setBorder(10)); imageSurface = new ImageSurface() { public void setSelection(Rectangle r) { super.setSelection(r); btnUpload.setText(r != null ? "Upload screenshot (selected area)" : "Upload screenshot"); } }; JButton btnShoot = new JButton(new AbstractAction("Shoot!") { public void actionPerformed(ActionEvent actionEvent) { shoot(); } }); btnUpload = new JButton(new AbstractAction("Upload screenshot") { public void actionPerformed(ActionEvent actionEvent) { try { String user = TBDefaultUser.getInAWTContext(); user = TBDefaultUser.askUserNameAWT(user); if (user == null) return; char[] pass = PasswordUtil.readPasswordFromFileOrAWT(user); ServerConnection serverConnection = new ServerConnection(); if (!serverConnection.login(user, pass)) { JOptionPane.showMessageDialog(null, "Could not log in"); return; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BufferedImage image = imageSurface.getImage(); if (imageSurface.getSelection() != null) image = new RGBImage(image).clip(imageSurface.getSelection()).getBufferedImage(); ImageIO.write(image, "png", outputStream); String title = "A screenshot"; title = JOptionPane.showInputDialog(null, "Please enter screenshot title", title); if (title == null) return; Snippet snippet = new Snippet(title, "", SnippetTypes.SN_IMAGE); snippet.isPublic = true; snippet.setBlobData(outputStream.toByteArray(), "png"); try { long id = serverConnection.createSnippet(snippet, true); String msg = "Screen shot uploaded as #" + id + " (http://tinybrain.de/" + id + ")!"; JOptionPane.showMessageDialog(null, msg); } catch (Exception e) { Errors.popup(e); } } catch (Throwable e) { Errors.popup(e); } } }); btnUpload.setEnabled(false); getContentPane().add("B", new Line(btnShoot, btnUpload)); getContentPane().add("I", GUIUtil.withTitle("Screenshot:", new JScrollPane(imageSurface))); } public void shoot() { hideFrame(); SwingTimerHelper.runOnce(getDelay(), new Runnable() { @Override public void run() { try { BufferedImage image; try { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); Robot robot = new Robot(); image = robot.createScreenCapture(screenRectangle); } finally { showFrame(); } imageSurface.setImage(image); imageSurface.zoomToDisplaySize(); btnUpload.setEnabled(true); } catch (Throwable e) { Errors.popup(e); } } }); } private int getDelay() { return frame != null ? delayWithFrame : defaultDelay; } private void hideFrame() { if (frame != null) frame.setVisible(false); } private void showFrame() { if (frame != null) frame.setVisible(true); } private JPanel getContentPane() { return this; } }
Began life as a copy of #1003164
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nnmtytuibrzp, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003836 |
Snippet name: | Screenshot Maker v2 |
Eternal ID of this version: | #1003836/1 |
Text MD5: | 59acfc59428ecb4fb5477507fbceea58 |
Transpilation MD5: | 551812194e9b2495211b4c95c1654601 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-07-28 17:25:27 |
Source code size: | 4325 bytes / 131 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 535 / 688 |
Referenced in: | [show references] |