Example usage for java.awt Robot Robot

List of usage examples for java.awt Robot Robot

Introduction

In this page you can find the example usage for java.awt Robot Robot.

Prototype

public Robot() throws AWTException 

Source Link

Document

Constructs a Robot object in the coordinate system of the primary screen.

Usage

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * Creates a new instance.//ww w . jav a  2s  .c o  m
 *
 * @param factory
 *            The Robot factory instance.
 * @throws RobotException
 *             If the AWT-Robot cannot be created.
 */
public RobotJavaFXImpl(RobotFactoryJavaFXImpl factory) throws RobotException {
    try {
        m_robot = new Robot();
        m_robot.setAutoWaitForIdle(true);
        m_robot.setAutoDelay(0);
    } catch (AWTException awte) {
        log.error(awte);
        m_robot = null;
        throw new RobotException(awte);
    } catch (SecurityException se) {
        log.error(se);
        m_robot = null;
        throw new RobotException(se);
    }
    m_interceptor = factory.getRobotEventInterceptor();
    m_mouseMotionTracker = factory.getMouseMotionTracker();
    m_queuer = factory.getEventThreadQueuer();
}

From source file:io.github.dsheirer.gui.SDRTrunk.java

/**
 * Initialize the contents of the frame.
 *///w ww. ja  v  a 2  s.  c  o m
private void initGUI() {
    mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]"));

    /**
     * Setup main JFrame window
     */
    mTitle = SystemProperties.getInstance().getApplicationName();
    mMainGui.setTitle(mTitle);
    mMainGui.setBounds(100, 100, 1280, 800);
    mMainGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set preferred sizes to influence the split
    mSpectralPanel.setPreferredSize(new Dimension(1280, 300));
    mControllerPanel.setPreferredSize(new Dimension(1280, 500));

    mSplitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);
    mSplitPane.setDividerSize(5);
    mSplitPane.add(mSpectralPanel);
    mSplitPane.add(mControllerPanel);

    mBroadcastStatusVisible = SystemProperties.getInstance().get(PROPERTY_BROADCAST_STATUS_VISIBLE, false);

    //Show broadcast status panel when user requests - disabled by default
    if (mBroadcastStatusVisible) {
        mSplitPane.add(getBroadcastStatusPanel());
    }

    mMainGui.add(mSplitPane, "cell 0 0,span,grow");

    /**
     * Menu items
     */
    JMenuBar menuBar = new JMenuBar();
    mMainGui.setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings");
    logFilesMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().open(getHomePath().toFile());
            } catch (Exception e) {
                mLog.error("Couldn't open file explorer");

                JOptionPane.showMessageDialog(mMainGui,
                        "Can't launch file explorer - files are located at: " + getHomePath().toString(),
                        "Can't launch file explorer", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    fileMenu.add(logFilesMenu);

    JMenuItem settingsMenu = new JMenuItem("Icon Manager");
    settingsMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            mIconManager.showEditor(mMainGui);
        }
    });
    fileMenu.add(settingsMenu);

    fileMenu.add(new JSeparator());

    JMenuItem exitMenu = new JMenuItem("Exit");
    exitMenu.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    fileMenu.add(exitMenu);

    JMenu viewMenu = new JMenu("View");

    viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel));

    menuBar.add(viewMenu);

    JMenuItem screenCaptureItem = new JMenuItem("Screen Capture");

    screenCaptureItem.setMnemonic(KeyEvent.VK_C);
    screenCaptureItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));

    screenCaptureItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Robot robot = new Robot();

                final BufferedImage image = robot.createScreenCapture(mMainGui.getBounds());

                SystemProperties props = SystemProperties.getInstance();

                Path capturePath = props.getApplicationFolder("screen_captures");

                if (!Files.exists(capturePath)) {
                    try {
                        Files.createDirectory(capturePath);
                    } catch (IOException e) {
                        mLog.error("Couldn't create 'screen_captures' " + "subdirectory in the "
                                + "SDRTrunk application directory", e);
                    }
                }

                String filename = TimeStamp.getTimeStamp("_") + "_screen_capture.png";

                final Path captureFile = capturePath.resolve(filename);

                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ImageIO.write(image, "png", captureFile.toFile());
                        } catch (IOException e) {
                            mLog.error("Couldn't write screen capture to " + "file [" + captureFile.toString()
                                    + "]", e);
                        }
                    }
                });
            } catch (AWTException e) {
                mLog.error("Exception while taking screen capture", e);
            }
        }
    });

    menuBar.add(screenCaptureItem);
}

From source file:jdroidremote.ServerFrame.java

private void initObjects() {
    try {//from ww  w. jav  a  2  s.c  o m
        robot = new Robot();
    } catch (AWTException ex) {
        Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Filter3dTest.java

/**
 * Sets whether realtive mouse mode is on or not. For relative mouse mode,
 * the mouse is "locked" in the center of the screen, and only the changed
 * in mouse movement is measured. In normal mode, the mouse is free to move
 * about the screen.//ww  w  .j  av  a2 s .c o  m
 */
public void setRelativeMouseMode(boolean mode) {
    if (mode == isRelativeMouseMode()) {
        return;
    }

    if (mode) {
        try {
            robot = new Robot();
            recenterMouse();
        } catch (AWTException ex) {
            // couldn't create robot!
            robot = null;
        }
    } else {
        robot = null;
    }
}

From source file:com.limegroup.gnutella.gui.notify.AnimatedWindow.java

private void prepareAnimation(Point location) {
    if (animationImage != null) {
        // already have an image, this could be the case if a hide animation
        // is started while a show animation is still in progress or the
        // other//from  w  w  w.  ja  va 2 s  .  c  o m
        // way around
        return;
    }

    // reset window to original size to capture all content
    pack();
    Dimension size = getSize();

    if (mode.needsBackgroundImage() && backgroundImage == null) {
        try {
            Robot robot = new Robot();
            backgroundImage = robot.createScreenCapture(new Rectangle(location, size));
        } catch (AWTException e) {
            LOG.warn("Could not capture background image", e);
            backgroundImage = null;
        }
    }

    animationImage = getGraphicsConfiguration().createCompatibleImage(size.width, size.height);
    Graphics grahpics = animationImage.getGraphics();
    getContentPane().paint(grahpics);
    grahpics.dispose();
}

From source file:com.willwinder.universalgcodesender.model.GUIBackend.java

private void keepAwake() {
    logger.log(Level.INFO, "Moving the mouse location slightly to keep the computer awake.");
    try {//from w  w  w .  ja v a 2 s  .  c o m
        Robot hal = new Robot();
        Point pObj = MouseInfo.getPointerInfo().getLocation();
        hal.mouseMove(pObj.x + 1, pObj.y + 1);
        hal.mouseMove(pObj.x - 1, pObj.y - 1);
        pObj = MouseInfo.getPointerInfo().getLocation();
        logger.log(Level.INFO, pObj.toString() + "x>>" + pObj.x + "  y>>" + pObj.y);
    } catch (AWTException | NullPointerException ex) {
        Logger.getLogger(GUIBackend.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:PNGDecoder.java

/** Static method performing screen capture into PNG image format file with given fileName.
 * @param rect Rectangle of screen to be captured
 * @param mode image color mode//from ww w  . ja v a 2 s.  c  o  m
 * @param fileName file name for screen capture PNG image file */
public static void captureScreen(Rectangle rect, String fileName, byte mode) {
    try {
        BufferedImage capture = new Robot().createScreenCapture(rect);
        BufferedOutputStream file = new BufferedOutputStream(new FileOutputStream(fileName));
        PNGEncoder encoder = new PNGEncoder(file, mode);
        encoder.encode(capture);
    } catch (AWTException awte) {
        awte.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:de.mycrobase.jcloudapp.Main.java

private BufferedImage takeScreenshot() {
    try {/*  w w w .  j a  va  2 s.co m*/
        Robot robot = new Robot();
        Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        return robot.createScreenCapture(captureSize);
    } catch (AWTException ex) {
        System.out.println(ex);
    }
    return null;
}

From source file:org.executequery.gui.editor.QueryEditorTextPanel.java

/**
 * Shifts the text on the current line or the currently
 * selected text to the right one TAB./*w w  w. j  a va2s.  co m*/
 */
public void shiftTextRight() {

    if (getSelectedText() == null) {

        int start = queryPane.getCurrentRowStart();
        queryPane.shiftTextRight(start);

    } else { // simulate a tab key for selected text

        try {

            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_TAB);

        } catch (AWTException e) {

            e.printStackTrace();
        }

    }
}

From source file:com.seleniumtests.driver.CustomEventFiringWebDriver.java

/**
 * Take screenshot of the desktop and put it in a file
 * Do not expose this method because we need to check that we have a graphical environment. 
 *//*  w  w w . j  ava 2  s .  c o  m*/
private static BufferedImage captureDesktopToBuffer() {

    Rectangle screenRect = getScreensRectangle();
    try {
        return new Robot().createScreenCapture(screenRect);
    } catch (AWTException e) {
        throw new ScenarioException("Cannot capture image", e);
    }

    //      Integer screenWidth = defaultGraphicDevice.getDisplayMode().getWidth();
    //      Integer screenHeight = defaultGraphicDevice.getDisplayMode().getHeight();
    //      
    //      // Capture the screen shot of the area of the screen defined by the rectangle
    //      try {
    //         return new Robot().createScreenCapture(new Rectangle(screenWidth, screenHeight));
    //      } catch (AWTException e) {
    //         throw new ScenarioException("Cannot capture image", e);
    //      }
}