Java Code Examples for java.awt.Robot

The following are top voted examples for showing how to use java.awt.Robot. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: SetShapeTest.java   Source Code and License 27 votes vote down vote up
public static void main(String[] args) throws Exception {
    createUI();
    Robot robot = new Robot();
    robot.waitForIdle();
    Rectangle rect = window.getBounds();
    rect.x += rect.width - 10;
    rect.y += rect.height - 10;
    robot.delay(1000);
    Color c = robot.getPixelColor(rect.x, rect.y);
    try {
        if (!c.equals(Color.RED)) {
            throw new RuntimeException("Test Failed");
        }
    } finally {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                background.dispose();
                window.dispose();
            }
        });
    }
}
 
Example 2
Project: jdk8u-jdk   File: MissingDragExitEventTest.java   Source Code and License 8 votes vote down vote up
public static void main(final String[] args) throws Exception {
    try {
        final Robot r = new Robot();
        r.setAutoDelay(50);
        r.mouseMove(100, 100);
        Util.waitForIdle(r);

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                initAndShowUI();
            }
        });

        final Point inside = new Point(frame.getLocationOnScreen());
        inside.translate(20, SIZE / 2);
        final Point outer = new Point(inside);
        outer.translate(-40, 0);
        r.mouseMove(inside.x, inside.y);
        r.mousePress(InputEvent.BUTTON1_MASK);
        try {
            for (int i = 0; i < 3; ++i) {
                Util.mouseMove(r, inside, outer);
                Util.mouseMove(r, outer, inside);
            }
        } finally {
            r.mouseRelease(InputEvent.BUTTON1_MASK);
        }
        sleep();

        if (FAILED || !MOUSE_ENTERED || !MOUSE_ENTERED_DT || !MOUSE_EXIT
                || !MOUSE_EXIT_TD) {
            throw new RuntimeException("Failed");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }
}
 
Example 3
Project: openjdk-jdk10   File: bug8017284.java   Source Code and License 8 votes vote down vote up
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            frame.setSize(500, 500);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            tabbedPane = new JTabbedPane();

            for (int i = 0; i < TAB_COUNT; i++) {
                tabbedPane.add("Header " + i, new JLabel("Content: " + i));
            }

            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
            frame.setVisible(true);
        });

        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            for (int j = 0; j < ITERATIONS; j++) {
                for (int i = 0; i < TAB_COUNT; i++) {
                    tabbedPane.setTitleAt(i, getHtmlText(j * TAB_COUNT + i));
                }
            }
        });
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> frame.dispose());
    }
 
Example 4
Project: ScreenCut   File: ScreenCut.java   Source Code and License 7 votes vote down vote up
/**
 * Creates new form ScreenCut
 *
 * @param parent
 * @param modal
 */
public ScreenCut(java.awt.Frame parent, boolean modal) {
    initComponents();
    addMouseListener(this);
    addMouseMotionListener(this);
    toolbar.setVisible(false);
    panel.setVisible(false);
    text.setVisible(false);
    try {
        robot = new Robot();
        screen = new Rectangle(tool.getScreenSize());
        setSize(screen.width, screen.height);
        bgimg = robot.createScreenCapture(screen);
        cur = tool.createCustomCursor(tool.createImage(getClass().getResource("/cur.png")), new Point(0, 0), "cur");
        setCursor(cur);
        ButtonGroup bg = new ButtonGroup();
        bg.add(size1);
        bg.add(size2);
        bg.add(size3);
        initActionListener(panel.getComponents());
        initActionListener(toolbar.getComponents());
    } catch (AWTException ex) {
        Logger.getLogger(ScreenCut.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 5
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 7 votes vote down vote up
public void singleClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 6
Project: openjdk-jdk10   File: JSplitPaneOverlapping.java   Source Code and License 7 votes vote down vote up
@Override
protected boolean performTest() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                splitterLoc = sp2.getLocationOnScreen();
                Point leftLoc = sp1.getLocationOnScreen();
                leftLoc.translate(sp1.getWidth(), 0);
                splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Where is splitter?");
    }
    // run robot
    Robot robot = Util.createRobot();
    robot.setAutoDelay(ROBOT_DELAY);

    robot.mouseMove(splitterLoc.x, splitterLoc.y);
    Util.waitForIdle(robot);

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);
    Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);
    System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);
    if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {
        fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    clickAndBlink(robot, splitterLoc);

    return clicked;
}
 
Example 7
Project: openjdk-jdk10   File: KeyCharTest.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {


        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.waitForIdle();


        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        robot.waitForIdle();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
Example 8
Project: jdk8u-jdk   File: MenuItemIconTest.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 9
Project: openjdk-jdk10   File: DeadKeySystemAssertionDialog.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        frame.setVisible(true);
        robot.waitForIdle();

        textField.requestFocus();
        robot.waitForIdle();

        // Check that the system assertion dialog does not block Java
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        frame.setVisible(false);
        frame.dispose();
    }
 
Example 10
Project: openjdk-jdk10   File: MissingCharsKorean.java   Source Code and License 6 votes vote down vote up
private static void enterInput(Robot robotKeyInput, int keyInputs[][]) {
    for (int i = 0; i < keyInputs.length; i++) {
        String strKeyInput = "KeyPress=>";
        final int noOfKeyInputs = keyInputs[i].length;
        for (int j = 0; j < noOfKeyInputs; j++) {
            robotKeyInput.keyPress(keyInputs[i][j]);
            strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
        }

        strKeyInput += "KeyRelease=>";
        for (int j = noOfKeyInputs - 1; j >= 0; j--) {
            robotKeyInput.keyRelease(keyInputs[i][j]);
            strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
        }
        System.out.println(strKeyInput);
    }
}
 
Example 11
Project: jdk8u-jdk   File: KeyCharTest.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
Example 12
Project: ChessBot   File: ImageUtils.java   Source Code and License 6 votes vote down vote up
public static BufferedImage captureImage() {
    try {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        Robot rt = new Robot();
        BufferedImage img = rt.createScreenCapture(
                new Rectangle(DesktopScreenRecorder.CAPTURE_1_X, 
                        DesktopScreenRecorder.CAPTURE_1_Y, 
                        DesktopScreenRecorder.CAPTURE_2_X, 
                        DesktopScreenRecorder.CAPTURE_2_Y));
        
        return img;
    } catch (Exception e) {
        UIUtils.popupError(e, "ImageUtils::writeImage");
    }
    return null;
}
 
Example 13
Project: openjdk-jdk10   File: bug7055065.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowUI();
        }
    });

    robot.waitForIdle();
    clickCell(robot, 1, 1);
    Util.hitKeys(robot, KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE,
            KeyEvent.VK_BACK_SPACE);

    robot.waitForIdle();
    clickColumnHeader(robot, 1);

    robot.waitForIdle();
    clickColumnHeader(robot, 1);
}
 
Example 14
Project: openjdk-jdk10   File: ActionEventTest.java   Source Code and License 6 votes vote down vote up
public ActionEventTest() {
    try {
        robot = new Robot();
        robot.setAutoDelay(100);
        robot.setAutoWaitForIdle(true);
    } catch(AWTException e) {
        throw new RuntimeException(e.getMessage());
    }

    list = new List(1, false);
    list.add("0");
    add(list);
    setSize(400,400);
    setLayout(new FlowLayout());
    pack();
    setVisible(true);
}
 
Example 15
Project: openjdk-jdk10   File: OverScrollTest.java   Source Code and License 6 votes vote down vote up
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textArea = new TextArea(2, 10);
    textArea.setSize(300, 100);
    textArea.setText("123456 789123");
    mainFrame.add(textArea);
    mainFrame.setVisible(true);
    textArea.requestFocusInWindow();
}
 
Example 16
Project: voicemenu   File: Event_TransformationMenu.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(@NotNull String pattern) {

  try {
    Robot r = new Robot();
    r.keyPress(157);
    r.keyPress(90);

    r.keyRelease(90);
    r.keyRelease(157);

  } catch (AWTException e) {
    e.printStackTrace();
  }
  SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
  SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);

}
 
Example 17
Project: openjdk-jdk10   File: SelectAllFilesFilterTest.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SwingUtilities.invokeLater(SelectAllFilesFilterTest::createAndShowGUI);

        while (fileChooser == null) {
            Thread.sleep(100);
        }

        Robot robot = new Robot();
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            comboBox = findComboBox(fileChooser);
            comboBox.setSelectedIndex(0);
        });
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            int selectedIndex = comboBox.getSelectedIndex();
            fileChooser.setVisible(false);

            if (selectedIndex != 0) {
                throw new RuntimeException("Select All file filter is not selected!");
            }
        });
    }
 
Example 18
Project: openjdk-jdk10   File: Test6505027.java   Source Code and License 6 votes vote down vote up
public void press() throws AWTException {
    Point point = this.table.getCellRect(1, 1, false).getLocation();
    SwingUtilities.convertPointToScreen(point, this.table);

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.mouseMove(point.x + 1, point.y + 1);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example 19
Project: jdk8u-jdk   File: SetEnabledPerformance.java   Source Code and License 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> createAndShowGUI());
    final Robot robot = new Robot();
    robot.waitForIdle();
    robot.mouseMove(frame.getX() + 15, frame.getY() + 300);
    robot.waitForIdle();
    SwingUtilities.invokeAndWait(() -> {
        long m = System.currentTimeMillis();
        for (final Component comp : frame.getComponents()) {
            comp.setEnabled(false);
        }
        m = System.currentTimeMillis() - m;
        System.err.println("Disabled in " + m + " ms");
        frame.dispose();
        // we should be much faster, but leaves 1000 for the slow systems
        if (m > 1000) {
            throw new RuntimeException("Too slow");
        }
    });
}
 
Example 20
Project: openjdk-jdk10   File: bug8133039.java   Source Code and License 6 votes vote down vote up
private static void testPopupAction() throws Exception {

        SwingUtilities.invokeAndWait(bug8133039::createAndShowGUI);

        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        if (ACTION_ACCEPTED_CALLS != 1) {
            throw new RuntimeException("Method accept is not invoked!");
        }

        if (ACTION_PERFORMED_CALLS != 1) {
            throw new RuntimeException("Method actionPerformed is not invoked!");
        }

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        if (ACTION_ACCEPTED_CALLS != 2) {
            throw new RuntimeException("Method accept is not invoked!");
        }

        if (ACTION_PERFORMED_CALLS != 1) {
            throw new RuntimeException("Method actionPerformed is invoked twice!");
        }
    }
 
Example 21
Project: jdk8u-jdk   File: WindowsLeak.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot r = new Robot();
    for (int i = 0; i < 100; i++) {
        Frame f = new Frame();
        f.pack();
        f.dispose();
    }
    r.waitForIdle();

    Disposer.addRecord(new Object(), () -> disposerPhantomComplete = true);

    while (!disposerPhantomComplete) {
        Util.generateOOME();
    }

    Vector<WeakReference<Window>> windowList =
                    (Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class);

    if (windowList != null && !windowList.isEmpty()) {
        throw new RuntimeException("Test FAILED: Window list is not empty: " + windowList.size());
    }

    System.out.println("Test PASSED");
}
 
Example 22
Project: openjdk-jdk10   File: InputVerifierTest2.java   Source Code and License 6 votes vote down vote up
static void mouseClickOnComp(Robot r, Component comp) {
    Point loc = comp.getLocationOnScreen();
    loc.x += comp.getWidth() / 2;
    loc.y += comp.getHeight() / 2;
    r.mouseMove(loc.x, loc.y);
    r.delay(10);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.delay(10);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example 23
Project: incubator-netbeans   File: AntSanityTest.java   Source Code and License 5 votes vote down vote up
/**
 * Using AWT robot presses and immediately releases certain key.
 * @param code Code of the key to be pressed.
 */
private void pressKey(int code) {
    try {
        Robot robot = new Robot();
        robot.keyPress(code);
        robot.keyRelease(code);
    } catch (AWTException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 24
Project: jdk8u-jdk   File: MultiResolutionSplashTest.java   Source Code and License 5 votes vote down vote up
static void testFocus() throws Exception {

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.keyPress(KeyEvent.VK_B);
        robot.keyRelease(KeyEvent.VK_B);
        robot.waitForIdle();

        frame.dispose();

        if(!textField.getText().equals("ab")){
            throw new RuntimeException("Focus is lost!");
        }
    }
 
Example 25
Project: incubator-netbeans   File: Find.java   Source Code and License 5 votes vote down vote up
/** Performs simple test of Find
 * @param args the command line arguments
 */
public static void main(String args[]) {
    new Find().verify();
    System.out.println("Find verification finished.");
    try {
        Robot robot=new Robot();
        System.out.println("Start delay.");
        robot.delay(2000);
        System.out.println("Delayed");
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.delay(1);
        robot.keyPress(KeyEvent.VK_F);
        robot.delay(20);
        robot.keyRelease(KeyEvent.VK_F);
        robot.delay(1);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        System.out.println("1");
        robot.waitForIdle();
        System.out.println("2");
        Find.find("aaa",robot);
        System.out.println("3");
        
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 26
Project: phoenix.webui.framework   File: SeleniumHover.java   Source Code and License 5 votes vote down vote up
@Override
public void hover(Element ele)
{
	WebElement webEle = searchStrategyUtils.findStrategy(WebElement.class, ele).search(ele);
	if(webEle == null)
	{
		logger.warn("can not found element.");
		return;
	}
	
	if(!(ele instanceof FileUpload))
	{
		Dimension size = webEle.getSize();
		Point loc = webEle.getLocation();
		int toolbarHeight = engine.getToolbarHeight();
		int x = size.getWidth() / 2 + loc.getX();
		int y = size.getHeight() / 2 + loc.getY() + toolbarHeight;
		
		try
		{
			new Robot().mouseMove(x, y);
		}
		catch (AWTException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
Example 27
Project: phoenix.webui.framework   File: AwtKeyboard.java   Source Code and License 5 votes vote down vote up
@Override
public void enter()
{
	try
	{
		Robot robot = new Robot();
		robot.keyPress(KeyEvent.VK_ENTER);
		robot.keyRelease(KeyEvent.VK_ENTER);
	}
	catch (AWTException e)
	{
		e.printStackTrace();
	}
}
 
Example 28
Project: jdk8u-jdk   File: SelectionInvisibleTest.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        toolkit.realSync();

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
Example 29
Project: openjdk-jdk10   File: TransparencyTest.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsDevice.WindowTranslucency mode = GraphicsDevice.WindowTranslucency.TRANSLUCENT;
        boolean translucencyCheck = gd.isWindowTranslucencySupported(mode);
        if(!translucencyCheck) {
            return;
    }

        Robot robot = new Robot();
        // create a GUI
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                createAndShowGUI();
            }
        });
        robot.waitForIdle();
        Color opaque = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100);

        // set Dialog Opacity
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                dialog.setOpacity(OPACITY);
            }
        });
        robot.waitForIdle();

        // iconify frame
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                frame.setExtendedState(JFrame.ICONIFIED);
            }
        });
        robot.waitForIdle();

        // deiconify frame
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                frame.setExtendedState(JFrame.NORMAL);
            }
        });
        robot.waitForIdle();

        Color transparent = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100);
        if (transparent.equals(opaque)) {
            frame.dispose();
            throw new RuntimeException("JDialog transparency lost "
                    + "upon iconify/deiconify sequence");
        }
        frame.dispose();
    }
 
Example 30
Project: phoenix.webui.framework   File: AwtMouse.java   Source Code and License 5 votes vote down vote up
@Override
public void click()
{
	try
	{
		Robot robot = new Robot();
		robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
		robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
	}
	catch (AWTException e)
	{
		e.printStackTrace();
	}
}
 
Example 31
Project: openjdk-jdk10   File: MissingCharsKorean.java   Source Code and License 5 votes vote down vote up
private static void glyphTest() {
    try {
        Robot robotKeySimulator = new Robot();
        performTasks(robotKeySimulator);
    } catch (AWTException e) {
        System.err.print("Creation Of Robot Failed : " + e.getMessage());
        testPassed = false;
    }
}
 
Example 32
Project: openjdk-jdk10   File: MaximizedToUnmaximized.java   Source Code and License 5 votes vote down vote up
static void testFrame(boolean isUndecorated) throws Exception {
    Frame frame = new Frame();
    try {
        Robot robot = new Robot();
        robot.setAutoDelay(100);

        frame.setUndecorated(isUndecorated);
        GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
        int x = bounds.x + insets.left;
        int y = bounds.y + insets.top;
        int width = bounds.width - insets.left - insets.right;
        int height = bounds.height - insets.top - insets.bottom;
        Rectangle rect = new Rectangle(x, y, width, height);
        frame.pack();
        frame.setBounds(rect);
        frame.setVisible(true);
        robot.waitForIdle();
        robot.delay(500);

        if (frame.getWidth() <= width / 2
                || frame.getHeight() <= height / 2) {
            throw new RuntimeException("Frame size is small!");
        }

        if (!isUndecorated && frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
            throw new RuntimeException("Frame state does not equal"
                    + " MAXIMIZED_BOTH!");
        }
    } finally {
        frame.dispose();
    }
}
 
Example 33
Project: marathonv5   File: JavaAgent.java   Source Code and License 5 votes vote down vote up
@Override public byte[] getScreenShot() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        BufferedImage bufferedImage;
        Dimension windowSize = Toolkit.getDefaultToolkit().getScreenSize();
        bufferedImage = new Robot().createScreenCapture(new Rectangle(0, 0, windowSize.width, windowSize.height));
        ImageIO.write(bufferedImage, "png", baos);
    } catch (AWTException e) {
        e.printStackTrace();
    }
    return baos.toByteArray();
}
 
Example 34
Project: openjdk-jdk10   File: bug4846413.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                createAndShowGUI();
            }
        });

        robot.waitForIdle();

        Point movePoint = getButtonPoint();
        robot.mouseMove(movePoint.x, movePoint.y);
        robot.waitForIdle();

        long timeout = System.currentTimeMillis() + 9000;
        while (!isTooltipAdded && (System.currentTimeMillis() < timeout)) {
            try {Thread.sleep(500);} catch (Exception e) {}
        }

        checkToolTip();
    }
 
Example 35
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 5 votes vote down vote up
private void checkAltClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    tclear();
    Point locationButton = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension sizeButton = EventQueueWait.call_noexc(button, "getSize");
    Point locationTextArea = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension sizeTextArea = EventQueueWait.call_noexc(actionsArea, "getSize");

    Robot robot = new Robot();
    robot.setAutoDelay(10);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.mouseMove(locationButton.x + sizeButton.width / 2 + 1, locationButton.y + sizeButton.height / 2 + 1);
    robot.mouseMove(locationButton.x + sizeButton.width / 2, locationButton.y + sizeButton.height / 2);
    robot.keyPress(KeyEvent.VK_ALT);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.mouseMove(locationTextArea.x + sizeTextArea.width / 2, locationTextArea.y + sizeTextArea.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = weTextArea.getText();
    tclear();
    System.err.println("================================");
    System.err.println(expected);
    System.err.println("=================================");
    new Actions(driver).moveToElement(weButton).keyDown(Keys.ALT).click().keyUp(Keys.ALT).moveToElement(weTextArea).perform();
    AssertJUnit.assertEquals(expected, weTextArea.getText());
}
 
Example 36
Project: openjdk-jdk10   File: MultiScreenLocationTest.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
Example 37
Project: openjdk-jdk10   File: MutterMaximizeTest.java   Source Code and License 5 votes vote down vote up
private static Thread startRegTest(final Frame f) {
    Thread robot = new Thread(new Runnable() {
        public void run() {
            Robot r = Util.createRobot();
            dragWindow(f, 100, 100, r);
            // wait for the location to be set.
            sleepFor(2000);

            final Point l2 = f.getLocationOnScreen();

            // double click should maximize the frame
            doubleClick(r);

            // wait for location again.
            sleepFor(2000);
            final Point l3 = f.getLocationOnScreen();
            if (l3.equals(l2)) {
                throw new RuntimeException("Bad location after maximize. Window location has not moved");
            }
        }
    });
    return robot;
}
 
Example 38
Project: openjdk-jdk10   File: SelectEditTableCell.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    robot.delay(2000);
    UIManager.LookAndFeelInfo[] lookAndFeelArray
            = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
        executeCase(lookAndFeelItem.getClassName());
    }

}
 
Example 39
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 5 votes vote down vote up
public void exitedGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_EXITED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");

    String expected = t.getText();
    tclear();
    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).moveToElement(t).keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
}
 
Example 40
Project: openjdk-jdk10   File: ActionEventTest.java   Source Code and License 5 votes vote down vote up
public ActionEventTest() {
    try {
        robot = new Robot();
    } catch(AWTException e) {
        throw new RuntimeException(e.getMessage());
    }

    button = new Button("ClickMe");
    button.setEnabled(true);

    instructions = new TextArea(10, 50);
    instructions.setText(
    " This is a manual test\n" +
    " Keep the Alt, Shift & Ctrl Keys pressed &\n" +
    " Click 'ClickMe' button with left mouse button\n" +
    " Test exits automatically after mouse click.");

    add(button);
    add(instructions);
    setSize(400,400);
    setLayout(new FlowLayout());
    pack();
    setVisible(true);
    robot.waitForIdle();

    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            int md = ae.getModifiers();
            int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                    | ActionEvent.SHIFT_MASK;

            isProgInterruption = true;
            mainThread.interrupt();
            if ((md & expectedMask) != expectedMask) {
                throw new RuntimeException("Action Event modifiers"
                    + " are not set correctly.");
            }
        }
    });
}
 
Example 41
Project: openjdk-jdk10   File: RobotCrash.java   Source Code and License 5 votes vote down vote up
public void robotKeyPressTest() throws Exception {

        SwingUtilities.invokeAndWait(() -> {
            frame = new Frame();
            frame.setSize(300, 300);
            frame.setVisible(true);
        });

        Robot robot = new Robot();
        robot.waitForIdle();
        Point pt = frame.getLocationOnScreen();
        robot.mouseMove(((int) pt.getX() + frame.getWidth()) / 2,
                ((int) pt.getY() + frame.getHeight()) / 2);
        robot.waitForIdle();
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.waitForIdle();
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            frame.dispose();
        });
    }
 
Example 42
Project: marathonv5   File: NativeEventsTest.java   Source Code and License 5 votes vote down vote up
public void rightClickGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_CLICKED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).contextClick().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 43
Project: jdk8u-jdk   File: bug4524490.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
        }
    });

    toolkit.realSync();

    if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_L);
    }
    checkFocus();
}
 
Example 44
Project: jdk8u-jdk   File: DrawImageBilinear.java   Source Code and License 5 votes vote down vote up
private static void doCapture(Component test) {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    // Grab the screen region
    try {
        Robot robot = new Robot();
        Point pt1 = test.getLocationOnScreen();
        Rectangle rect =
            new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
        capture = robot.createScreenCapture(rect);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 45
Project: openjdk-jdk10   File: JemmyExt.java   Source Code and License 5 votes vote down vote up
public static void waitImageIsStill(Robot rob, ComponentOperator operator) {
    operator.waitState(new ComponentChooser() {

        private BufferedImage previousImage = null;
        private int index = 0;
        private final StrictImageComparator sComparator = new StrictImageComparator();

        @Override
        public boolean checkComponent(Component comp) {
            BufferedImage currentImage = capture(rob, operator);
            save(currentImage, "waitImageIsStill" + index + ".png");
            index++;
            boolean compareResult = previousImage == null ? false : sComparator.compare(currentImage, previousImage);
            previousImage = currentImage;
            return compareResult;
        }

        @Override
        public String getDescription() {
            return "Image of " + operator + " is still";
        }
    });
}
 
Example 46
Project: openjdk-jdk10   File: PopupMenuTest.java   Source Code and License 5 votes vote down vote up
public static void main(String s[]) throws Exception {
    PopupMenuTest obj = new PopupMenuTest();
    obj.createUI();
    robot = new Robot();
    robot.waitForIdle();
    robot.delay(1000);
    obj.exectuteTest();
    obj.dispose();
    if (isLightWeight) {
        throw new RuntimeException("Test Failed");
    }
}
 
Example 47
Project: openjdk-jdk10   File: CustomComboBoxFocusTest.java   Source Code and License 5 votes vote down vote up
public CustomComboBoxFocusTest() {
    frame = new JFrame(System.getProperty("java.version"));

    try {
        robot = new Robot(frame.getGraphicsConfiguration().getDevice());

    } catch (AWTException e) {
        throw new RuntimeException("Test failed.", e);
    }
}
 
Example 48
Project: jdk8u-jdk   File: TestBadBreak.java   Source Code and License 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    robot = new Robot();
    final BufferedImage bi1 = new BufferedImage(200, 90, TYPE_INT_ARGB);
    final BufferedImage bi2 = new BufferedImage(200, 90, TYPE_INT_ARGB);
    test(withCombiningDiaeresis, bi1);
    test(withoutCombiningDiaeresis, bi2);
    for (int x = 0; x < bi1.getWidth(); ++x) {
        for (int y = 0; y < bi1.getHeight(); ++y) {
            if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
                ImageIO.write(bi1, "png", new File("image1.png"));
                ImageIO.write(bi2, "png", new File("image2.png"));
                throw new RuntimeException("Wrong color");
            }
        }
    }
}
 
Example 49
Project: Dayflower-Path-Tracer   File: AbstractApplication.java   Source Code and License 5 votes vote down vote up
private static Robot doCreateRobot() {
	try {
		return new Robot();
	} catch(final AWTException e) {
		throw new UnsupportedOperationException(e);
	}
}
 
Example 50
Project: jdk8u-jdk   File: PaintNativeOnUpdate.java   Source Code and License 5 votes vote down vote up
public static void main(final String[] args) throws AWTException {
    final Frame frame = new Frame();
    final Component label = new PaintNativeOnUpdate();
    frame.setBackground(Color.RED);
    frame.add(label);
    frame.setSize(300, 300);
    frame.setUndecorated(true);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    label.repaint();// first paint
    sleep();
    label.repaint();// incremental paint
    sleep();

    Robot robot = new Robot();
    robot.setAutoDelay(50);
    Point point = label.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
                                      point.y + label.getHeight() / 2);
    if (!color.equals(Color.GREEN)) {
        System.err.println("Expected color = " + Color.GREEN);
        System.err.println("Actual color = " + color);
        throw new RuntimeException();
    }
    frame.dispose();
}
 
Example 51
Project: geomapapp   File: XMLJTreeDialog.java   Source Code and License 5 votes vote down vote up
public void mouseClicked(MouseEvent e) {
	if (SwingUtilities.isRightMouseButton(e)) {
		try {
			Robot robot = new java.awt.Robot();
			robot.mousePress(InputEvent.BUTTON1_MASK);
			robot.mouseRelease(InputEvent.BUTTON1_MASK);
		} catch (AWTException ex) {
			System.out.println(ex);
		}
	}
}
 
Example 52
Project: allure-java   File: Stepdefs.java   Source Code and License 5 votes vote down vote up
@Attachment(type = "image/png", fileExtension = "png", value = "att")
public byte[] attach() {
    try {
        BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "png", baos);
        baos.flush();
        byte[] imageInByte = baos.toByteArray();
        baos.close();
        return imageInByte;
    } catch (AWTException | IOException e) {
        return null;
    }
}
 
Example 53
Project: openjdk-jdk10   File: AutoScrollOnSelectAndAppend.java   Source Code and License 5 votes vote down vote up
public AutoScrollOnSelectAndAppend() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException("Robot Creation Failed.");
    }
    frame = new Frame();
    frame.setSize(200, 200);
    frame.setLayout(new FlowLayout());

    textArea = new TextArea(5, 20);
    composeTextArea();
    frame.add(textArea);

    buttonHoldFocus = new Button("HoldFocus");
    frame.add(buttonHoldFocus);

    frame.setVisible(true);
    robot.waitForIdle();

    // Move mouse cursor on first row of text area.
    Point loc = textArea.getLocationOnScreen();
    robot.mouseMove(loc.x + 8, loc.y + 8);
    robot.waitForIdle();
}
 
Example 54
Project: openjdk-jdk10   File: EditPadTest.java   Source Code and License 5 votes vote down vote up
@BeforeClass
public static void setUpEditorPadTest() {
    if (!GraphicsEnvironment.isHeadless()) {
        try {
            robot = new Robot();
            robot.setAutoWaitForIdle(true);
            robot.setAutoDelay(DELAY);
        } catch (AWTException e) {
            throw new ExceptionInInitializerError(e);
        }
    }
}
 
Example 55
Project: openjdk-jdk10   File: bug6495920.java   Source Code and License 5 votes vote down vote up
public void firstShowPopup() throws Exception {
    Point point = this.panel.getLocation();
    SwingUtilities.convertPointToScreen(point, this.panel);

    robot = new Robot(); // initialize shared static field first time
    robot.mouseMove(point.x + 1, point.y + 1);
    robot.mousePress(InputEvent.BUTTON3_MASK);
    Thread.currentThread().setUncaughtExceptionHandler(this);
    robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT
}
 
Example 56
Project: openjdk-jdk10   File: bug6219960.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    SwingUtilities.invokeAndWait(bug6219960::createAndShowGUI);
    robot.waitForIdle();
    showModal("The tooltip should be showing. Press ok with mouse. And don't move it.");
    robot.waitForIdle();
    showModal("Now press ok and move the mouse inside the table (don't leave it).");
    robot.waitForIdle();
}
 
Example 57
Project: PengueeBot   File: Action.java   Source Code and License 5 votes vote down vote up
public Action() {
	try {
		screen = Data.screenObject;
		bot = new Robot();
	} catch (AWTException e) {
		e.printStackTrace();
	}
}
 
Example 58
Project: openjdk-jdk10   File: bug8136998.java   Source Code and License 5 votes vote down vote up
public bug8136998() throws AWTException {
    robot = new Robot();
    robot.setAutoDelay(200);
}
 
Example 59
Project: openjdk-jdk10   File: CloseOnMouseClickPropertyTest.java   Source Code and License 5 votes vote down vote up
private static void test(TestItem item) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(50);
        SwingUtilities.invokeAndWait(() -> createAndShowGUI(item));
        robot.waitForIdle();

        Point point = getClickPoint(true);
        robot.mouseMove(point.x, point.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();

        point = getClickPoint(false);
        robot.mouseMove(point.x, point.y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            JMenuItem menuItem = menu.getItem(0);
            boolean isShowing = menuItem.isShowing();
            frame.dispose();
            if (isShowing ^ item.doNotCloseOnMouseClick()) {
                throw new RuntimeException("Property is not taken into account!");
            }
        });
    }
 
Example 60
Project: jdk8u-jdk   File: InputContextMemoryLeakTest.java   Source Code and License 5 votes vote down vote up
public static void init() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame();
            frame.setLayout(new FlowLayout());
            JPanel p1 = new JPanel();
            button = new JButton("Test");
            p1.add(button);
            frame.add(p1);
            text = new WeakReference<JTextField>(new JTextField("Text"));
            p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
            p.get().add(text.get());
            frame.add(p.get());
            frame.setBounds(500, 400, 200, 200);
            frame.setVisible(true);
        }
    });

    Util.focusComponent(text.get(), 500);
    Util.clickOnComp(button, new Robot());
    //References to objects testes for memory leak are stored in Util.
    //Need to clean them
    Util.cleanUp();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.remove(p.get());
        }
    });

    Util.waitForIdle(null);
    //After the next caret blink it automatically TextField references
    Thread.sleep(text.get().getCaret().getBlinkRate() * 2);
    Util.waitForIdle(null);
    assertGC();
}