/* * Screenshot.bsh - Take a screenshot of your desktop save it * as a png file if you want. * * version 1.0 Sep 6, 2005 * @author Delvin Johnson, delvinj@gmail.com */ import java.awt.image.BufferedImage; void openDialog() throws AWTException { BufferedImage screen = new java.awt.Robot().createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); JScrollPane sp = new JScrollPane(new JLabel(new ImageIcon(screen))); sp.getHorizontalScrollBar().setUnitIncrement(12); sp.getVerticalScrollBar().setUnitIncrement(12); JDialog dialog = new JDialog(jEdit.getActiveView(), "ScreenShot", false); dialog.getContentPane().add(sp); JPanel bottom = new JPanel(new FlowLayout(FlowLayout.CENTER,2,2)); JButton save = new JButton("Save"); save.setMnemonic('S'); save.addActionListener(this); bottom.add(save); save.addKeyListener(this); sp.addKeyListener(this); dialog.getContentPane().add(bottom, BorderLayout.SOUTH); public void actionPerformed(ActionEvent e) { try { int ii = 0; String [] sel = GUIUtilities.showVFSFileDialog( jEdit.getActiveView(), null, org.gjt.sp.jedit.browser.VFSBrowser.SAVE_DIALOG, true); if(sel != null && sel.length > 0) { File outf = new File(sel[0]); if(outf.exists()) { Macros.message(jEdit.getActiveView(), "File exists, please choose another!"); } else { javax.imageio.ImageIO.write(screen, "png", outf); Macros.message(jEdit.getActiveView(), "Saved " + outf.getAbsolutePath()); } } } catch(Exception x) { Macros.message(jEdit.getActiveView(), x.toString()); } } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ESCAPE) { dialog.setVisible(false); dialog.dispose(); screen = null; } } public void keyTyped(KeyEvent e) { } dialog.setSize(480, 420); dialog.setLocationRelativeTo(null); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } ActionListener myListener = new ActionListener() { public void actionPerformed(ActionEvent e) { openDialog(); } }; void doScreenShot() { int delay = 1; String input = Macros.input( jEdit.getActiveView(), "Delay? (0-12)", "1"); if(input == null) return; try { delay = Integer.parseInt(input); } catch(Exception x) { } if(delay > 4) delay = 4; if(delay < 0) delay = 0; javax.swing.Timer timer = new javax.swing.Timer(delay * 1000, myListener); timer.setRepeats(false); timer.start(); } doScreenShot(); // javax.swing.Timer t = new javax.swing.Timer(1200, new ActionListener() { // public void actionPerformed(ActionEvent e) { // doScreenShot(); // } // }); // t.setRepeats(false); // t.start();