public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(new NimbusLookAndFeel()); Robot robot = new Robot(); robot.setAutoDelay(50); SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { createAndShowGUI(); } }); toolkit.realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { Component previewPanel = Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel"); point = previewPanel.getLocationOnScreen(); } }); point.translate(5, 5); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); }
public static void requestFocus(Project project, final boolean useRobot) { JFrame frame = WindowManager.getInstance().getFrame(project); // the only reliable way I found to bring it to the top boolean aot = frame.isAlwaysOnTop(); frame.setAlwaysOnTop(true); frame.setAlwaysOnTop(aot); int frameState = frame.getExtendedState(); if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) { // restore the frame if it is minimized frame.setExtendedState(frameState ^ Frame.ICONIFIED); } frame.toFront(); frame.requestFocus(); if (useRobot && runningOnWindows7()) { try { // remember the last location of mouse final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation(); // simulate a mouse click on title bar of window Robot robot = new Robot(); robot.mouseMove(frame.getX(), frame.getY()); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // move mouse to old location robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY()); } catch (Exception ex) { // just ignore exception, or you can handle it as you want } finally { frame.setAlwaysOnTop(false); } } }
public static void main(String... args) throws Exception { Robot robot = new Robot(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { popup = new JPopupMenu(); popup.add(new JMenuItem("item")); popup.setVisible(true); } }); robot.waitForIdle(); if (!popup.isShowing()) { throw new RuntimeException("Where is my popup ?"); } SwingUtilities.invokeAndWait( new Runnable() { public void run() { popup.setVisible(false); popup.removeAll(); popup.setVisible(true); } }); robot.waitForIdle(); if (popup.isShowing()) { throw new RuntimeException("Empty popup is shown"); } popup.setVisible(false); }
// Set if the application is in editing mode based on the state of the shift key public void setEditingMode() { try { Robot robot = new Robot(); robot.keyRelease(KeyEvent.VK_SHIFT); } catch (AWTException e) { e.printStackTrace(); } }
public static void main(String s[]) { // Getting save directory String saveDir; if (s.length > 0) { saveDir = s[0]; } else { saveDir = JOptionPane.showInputDialog( null, "Please enter directory where " + "the images is/will be saved\n\n" + "Also possible to specifiy as argument 1 when " + "running this program.", "l:\\webcamtest"); } String layout = ""; if (s.length > 1) { layout = s[1]; } // Move mouse to the point 5000,5000 px (out of the screen) Robot rob; try { rob = new Robot(); rob.setAutoDelay(500); // 0,5 s rob.mouseMove(5000, 5000); } catch (AWTException e) { e.printStackTrace(); } // Make the main window JFrame frame = new JFrame(); frame.setAlwaysOnTop(true); frame.setTitle( "Webcam capture and imagefading - " + "Vitenfabrikken Jærmuseet - " + "made by Hallvard Nygård - " + "Vitenfabrikken.no / Jaermuseet.no"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true); WebcamCaptureAndFadePanel panel = new WebcamCaptureAndFadePanel(saveDir, layout); frame.getContentPane().add(panel); frame.addKeyListener(panel); frame.pack(); frame.setVisible(true); }
public TransparentWindow(BufferedImage img, int x, int y) { image = img; try { Robot robot = new Robot(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); screen = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height)); } catch (AWTException e) { throw new Error(e); } setBounds(x, y, img.getWidth(), img.getHeight()); setVisible(true); buffer = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); graphics = (Graphics2D) buffer.getGraphics(); }
private void moveMousePointerOnButton(final JButton button) { Application application = ApplicationManager.getApplication(); if (application != null && application.hasComponent(UISettings.class)) { if (button != null && UISettings.getInstance().MOVE_MOUSE_ON_DEFAULT_BUTTON) { Point p = button.getLocationOnScreen(); Rectangle r = button.getBounds(); try { Robot robot = new Robot(); robot.mouseMove(p.x + r.width / 2, p.y + r.height / 2); } catch (AWTException e) { LOG.warn(e); } } } }
/** Do screen capture and save it as image */ private static void captureScreenAndSave() { try { Robot robot = new Robot(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height); System.out.println("About to screen capture - " + rectangle); java.awt.image.BufferedImage image = robot.createScreenCapture(rectangle); javax.imageio.ImageIO.write(image, "jpg", new java.io.File("ScreenImage.jpg")); robot.delay(3000); } catch (Throwable t) { System.out.println("WARNING: Exception thrown while screen capture!"); t.printStackTrace(); } }
public static void main(String[] s) { JFrame frame = new JFrame("A test frame"); JPanel outputBox = new JPanel(); JButton jButton = new JButton(); frame.setSize(200, 200); frame.addMouseWheelListener( new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { System.out.println("Wheel moved on FRAME : " + e); actualEvents++; } }); outputBox.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { System.out.println("MousePressed on OUTBOX : " + e); } }); frame.add(outputBox); outputBox.add(jButton); frame.setVisible(true); Util.waitForIdle(robot); Util.pointOnComp(jButton, robot); Util.waitForIdle(robot); for (int i = 0; i < MOVE_COUNT; i++) { robot.mouseWheel(1); robot.delay(10); } for (int i = 0; i < MOVE_COUNT; i++) { robot.mouseWheel(-1); robot.delay(10); } Util.waitForIdle(robot); // Not fair to check for multiplier 4 as it's not specified actual number of WheelEvents // result in a single wheel rotation. if (actualEvents != EXPECTED_COUNT) { AbstractTest.fail( "Expected events count: " + EXPECTED_COUNT + " Actual events count: " + actualEvents); } }
/** * Boom! Head shot! * * @return the screen shot */ private static Image screenShot(Dimension ss) { try { if (robot == null) robot = new Robot(); return robot.createScreenCapture(new Rectangle(0, 0, ss.width, ss.height)); } catch (Exception e) { return null; } }
public static void main(String[] args) throws Throwable { Robot robot = new Robot(); robot.setAutoDelay(250); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { JFrame frame = new JFrame("Test"); frame.setContentPane(createPanel(frame)); frame.setJMenuBar(createMenuBar()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); robot.waitForIdle(); // Change the default button to // force a call to BasicRootPaneUI.updateDefaultButtonBindings() Util.hitKeys(robot, KeyEvent.VK_TAB); // If the bug exists, then as soon as the menu appears, // the VK_ENTER, VK_DOWN, VK_UP and VK_ESC will have no // effect. Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_ENTER); robot.waitForIdle(); checkAction(); Util.hitMnemonics(robot, KeyEvent.VK_U); Util.hitKeys(robot, KeyEvent.VK_DOWN); Util.hitKeys(robot, KeyEvent.VK_ENTER); robot.waitForIdle(); checkAction(); }
public void init() { try { robot = new Robot(); robot.setAutoDelay(50); } catch (AWTException e) { throw new RuntimeException("Error: unable to create robot", e); } // Create instructions for the user here, as well as set up // the environment -- set the layout manager, add buttons, // etc. this.setLayout(new BorderLayout()); Sysout.createDialogWithInstructions( new String[] {"Automatic test. Simply wait until it's done."}); }
public static void main(String[] args) throws Exception { final bug6274267 test = new bug6274267(); Robot robot = new Robot(); try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { test.setupUI1(); } }); robot.waitForIdle(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test.setupUI2(); } }); test.test(); } finally { if (test.frame != null) { test.frame.dispose(); } } }
public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Robot robot = new Robot(); robot.setAutoDelay(20); SwingUtilities.invokeAndWait( new Runnable() { public void run() { // just to quickly grab a column model JTable table = new JTable(10, 5); header = new JTableHeader(table.getColumnModel()); checkColumn(0, "A"); JFrame frame = new JFrame("standalone header"); frame.add(header); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); robot.waitForIdle(); Point point = header.getLocationOnScreen(); robot.mouseMove(point.x + 3, point.y + 3); robot.mousePress(InputEvent.BUTTON1_MASK); for (int i = 0; i < header.getWidth() - 3; i++) { robot.mouseMove(point.x + i, point.y + 3); } robot.mouseRelease(InputEvent.BUTTON1_MASK); SwingUtilities.invokeAndWait( new Runnable() { public void run() { TableColumnModel model = header.getColumnModel(); checkColumn(model.getColumnCount() - 1, "A"); } }); }
void test() { robot.waitForIdle(); if (!text.isFocusOwner()) { robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5); robot.delay(100); robot.mousePress(MouseEvent.BUTTON1_MASK); robot.delay(100); robot.mouseRelease(MouseEvent.BUTTON1_MASK); int iter = 10; while (!text.isFocusOwner() && iter-- > 0) { robot.delay(200); } if (iter <= 0) { Sysout.println("Test: text field couldn't be focused!"); return; } } robot.keyPress(KeyEvent.VK_A); robot.delay(100); robot.keyRelease(KeyEvent.VK_A); robot.waitForIdle(); String charA = text.getText(); System.err.println("Test: character typed with VK_A: " + charA); robot.keyPress(KeyEvent.VK_BACK_SPACE); robot.delay(100); robot.keyRelease(KeyEvent.VK_BACK_SPACE); robot.waitForIdle(); if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) { robot.keyPress(KeyEvent.VK_CONTROL); } robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_F); robot.delay(100); robot.keyRelease(KeyEvent.VK_F); robot.keyRelease(KeyEvent.VK_ALT); if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) { robot.keyRelease(KeyEvent.VK_CONTROL); } robot.waitForIdle(); String string = text.getText(); robot.keyPress(KeyEvent.VK_I); robot.delay(100); robot.keyRelease(KeyEvent.VK_I); robot.waitForIdle(); Sysout.println("Test: character typed after mnemonic key press: " + text.getText()); if (!text.getText().equals(string)) { throw new RuntimeException("Test failed!"); } robot.keyPress(KeyEvent.VK_A); robot.delay(100); robot.keyRelease(KeyEvent.VK_A); robot.waitForIdle(); System.err.println("Test: chracter typed with VK_A: " + text.getText()); if (!charA.equals(text.getText())) { throw new RuntimeException("Test failed!"); } Sysout.println("Test passed."); }
public static void main(String[] args) throws Throwable { sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test = new TaskbarPositionTest(); } }); // Use Robot to automate the test Robot robot; robot = new Robot(); robot.setAutoDelay(125); // 1 - menu Util.hitMnemonics(robot, KeyEvent.VK_1); toolkit.realSync(); isPopupOnScreen(menu1.getPopupMenu(), screenBounds); // 2 menu with sub menu robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_RIGHT); Util.hitMnemonics(robot, KeyEvent.VK_S); toolkit.realSync(); isPopupOnScreen(menu2.getPopupMenu(), screenBounds); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); // Focus should go to non editable combo box toolkit.realSync(); Thread.sleep(500); robot.keyPress(KeyEvent.VK_DOWN); // How do we check combo boxes? // Editable combo box robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); // combo1.getUI(); // Popup from Text field robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_CONTROL); // Popup from a mouse click. Point pt = new Point(2, 2); SwingUtilities.convertPointToScreen(pt, panel); robot.mouseMove((int) pt.getX(), (int) pt.getY()); robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); toolkit.realSync(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { test.setLocation(-30, 100); combo1.addPopupMenuListener(new ComboPopupCheckListener()); combo1.requestFocus(); } }); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyRelease(KeyEvent.VK_ESCAPE); toolkit.realSync(); Thread.sleep(500); }
public static void main(String[] args) throws Exception { if (!OS.contains("mac")) { System.out.println("The test is applicable only to Mac OS X. Passed"); return; } // Move the mouse out, because it could interfere with the test. Robot r = Util.createRobot(); Util.waitForIdle(r); r.mouseMove(0, 0); Util.waitForIdle(r); SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { createAndShowGUI(); } }); // Move the mouse away from the frame and check the View-base full screen mode Util.waitForIdle(r); r.mouseMove(500, 500); Util.waitForIdle(r); mouseEnterCount = 0; SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .setFullScreenWindow(frame); } }); Util.waitForIdle(r); if (mouseEnterCount != 1) { throw new RuntimeException("No MouseEntered event for view-base full screen. Failed."); } SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .setFullScreenWindow(null); } }); // Test native full screen support Util.waitForIdle(r); Point fullScreenButtonPos = frame.getLocation(); fullScreenButtonPos.translate(frame.getWidth() - 10, 10); r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y); mouseEnterCount = 0; // Cant use waitForIdle for full screen transition. int waitCount = 0; while (!windowEnteringFullScreen) { r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); Thread.sleep(100); if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed"); } waitCount = 0; while (!windowEnteredFullScreen) { Thread.sleep(200); if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed"); } if (mouseEnterCount != 1) { throw new RuntimeException("No MouseEntered event for native full screen. Failed."); } }
public ScreenShotWindow() throws AWTException { // 获取屏幕尺寸 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); this.setBounds(0, 0, d.width, d.height); // 截取屏幕 Robot robot = new Robot(); image = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height)); this.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { // 鼠标松开时记录结束点坐标,并隐藏操作窗口 orgx = e.getX(); orgy = e.getY(); if (tools != null) { tools.setVisible(false); } } @Override public void mouseReleased(MouseEvent e) { // 鼠标松开时,显示操作窗口 if (tools == null) { tools = new ToolsWindow(ScreenShotWindow.this, e.getX(), e.getY()); } else { tools.setLocation(e.getX(), e.getY()); } tools.setVisible(true); tools.toFront(); } }); this.addMouseMotionListener( new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { // 鼠标拖动时,记录坐标并重绘窗口 endx = e.getX(); endy = e.getY(); // 临时图像,用于缓冲屏幕区域放置屏幕闪烁 Image tempImage2 = createImage(ScreenShotWindow.this.getWidth(), ScreenShotWindow.this.getHeight()); Graphics g = tempImage2.getGraphics(); g.drawImage(tempImage, 0, 0, null); int x = Math.min(orgx, endx); int y = Math.min(orgy, endy); int width = Math.abs(endx - orgx) + 1; int height = Math.abs(endy - orgy) + 1; // 加上1防止width或height0 g.setColor(Color.BLUE); g.drawRect(x - 1, y - 1, width + 1, height + 1); // 减1加1都了防止图片矩形框覆盖掉 saveImage = image.getSubimage(x, y, width, height); g.drawImage(saveImage, x, y, null); ScreenShotWindow.this.getGraphics().drawImage(tempImage2, 0, 0, ScreenShotWindow.this); } }); }
public void takeScreenshot(boolean flag) { BufferedImage bufferedimage; try { Robot robot = new Robot(); Point point = getLocationOnScreen(); Rectangle rectangle = new Rectangle(point.x, point.y, getWidth(), getHeight()); bufferedimage = robot.createScreenCapture(rectangle); } catch (Throwable throwable) { JOptionPane.showMessageDialog( frame, "An error occured while trying to create a screenshot!", "Screenshot Error", 0); return; } String s = null; try { s = getNearestScreenshotFilename(); } catch (IOException ioexception) { if (flag) { JOptionPane.showMessageDialog( frame, "A screenshot directory does not exist, and could not be created!", "No Screenshot Directory", 0); return; } } if (s == null && flag) { JOptionPane.showMessageDialog( frame, "There are too many screenshots in the screenshot directory!\n" + "Delete some screen\n" + "shots and try again.", "Screenshot Directory Full", 0); return; } if (!flag) { final JFileChooser fileChooser = new JFileChooser(); final JDialog fileDialog = createFileChooserDialog(fileChooser, "Save Screenshot", this); final BufferedImage si = bufferedimage; JFileChooser _tmp = fileChooser; fileChooser.setFileSelectionMode(0); fileChooser.addChoosableFileFilter(new imageFileFilter()); fileChooser.setCurrentDirectory(new File("C:/.hack3rClient/Scre/")); fileChooser.setSelectedFile(new File(s)); JFileChooser _tmp1 = fileChooser; fileChooser.setDialogType(1); fileChooser.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionevent) { String s1 = actionevent.getActionCommand(); if (s1.equals("ApproveSelection")) { File file = fileChooser.getSelectedFile(); if (file != null && file.isFile()) { int i = JOptionPane.showConfirmDialog( frame, (new StringBuilder()) .append(file.getAbsolutePath()) .append(" already exists.\n" + "Do you want to replace it?") .toString(), "Save Screenshot", 2); if (i != 0) { return; } } try { ImageIO.write(si, "png", file); // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client"); // JOptionPane.showMessageDialog(frame,"Screenshot Taken"); } catch (IOException ioexception2) { JOptionPane.showMessageDialog( frame, "An error occured while trying to save the screenshot!\n" + "Please make sure you have\n" + " write access to the screenshot directory.", "Screenshot Error", 0); } fileDialog.dispose(); } else if (s1.equals("CancelSelection")) { fileDialog.dispose(); } } { } }); fileDialog.setVisible(true); } else { try { ImageIO.write( bufferedimage, "png", new File((new StringBuilder()).append("C:/.hack3rClient/Scre/").append(s).toString())); JOptionPane.showMessageDialog( frame, "Image has been saved to C:/.hack3rclient/Scre. You can view your images by pushing File>View Images in the menu dropdowns.", "Screenshot manager", JOptionPane.INFORMATION_MESSAGE); // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client"); // JOptionPane.showMessageDialog(frame,"Screenshot taken."); } catch (IOException ioexception1) { JOptionPane.showMessageDialog( frame, "An error occured while trying to save the screenshot!\n" + "Please make sure you have\n" + " write access to the screenshot directory.", "Screenshot Error", 0); } } }
/** * Runs a sample test procedure * * @param robot the robot attached to the screen device */ public static void runTest(Robot robot) { // simulate a space bar press robot.keyPress(' '); robot.keyRelease(' '); // simulate a tab key followed by a space robot.delay(2000); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyPress(' '); robot.keyRelease(' '); // simulate a mouse click over the rightmost button robot.delay(2000); robot.mouseMove(200, 50); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); // capture the screen and show the resulting image robot.delay(2000); BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 400, 300)); ImageFrame frame = new ImageFrame(image); frame.setVisible(true); }
public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(350); SwingUtilities.invokeAndWait( new Runnable() { public void run() { createAndShowGUI(); } }); robot.waitForIdle(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { spane.requestFocus(); sbar.setValue(sbar.getMaximum()); } }); robot.waitForIdle(); Point point = getClickPoint(0.5, 0.5); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.waitForIdle(); SwingUtilities.invokeAndWait( new Runnable() { public void run() { final int oldValue = sbar.getValue(); sbar.addAdjustmentListener( new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { if (e.getValue() >= oldValue) { passed = false; } do_test = true; } }); } }); robot.waitForIdle(); point = getClickPoint(0.5, 0.2); robot.mouseMove(point.x, point.y); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.waitForIdle(); if (!do_test || !passed) { throw new Exception("The scrollbar moved with incorrect direction"); } }
/** * Starts the program * * @param args the standard arguments. If "competition" is one of them, then the SmartDashboard * will be in competition mode * @see main#inCompetition() inCompetition() */ public static void main(final String[] args) { // Present a loading bar (it will only show up if this is going slowly) final ProgressMonitor monitor = new ProgressMonitor( null, "Loading SmartDashboard", "Initializing internal code...", 0, 1000); // Search the filesystem for extensions (49%) FileSniffer.findExtensions(monitor, 0, 490); ArgParser argParser = new ArgParser(args, true, true, new String[] {"ip"}); inCompetition = argParser.hasFlag("competition"); boolean customIP = false; if (argParser.hasValue("ip")) { Robot.setHost(argParser.getValue("ip")); customIP = true; } final boolean useTeamNumber = !customIP; try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { try { monitor.setProgress(500); monitor.setNote("Setting Theme"); try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); } } } catch (Exception e) { } // Initialize GUI DashboardFrame frame = new DashboardFrame(inCompetition); monitor.setProgress(600); monitor.setNote("Getting Team Number"); IntegerProperty team = frame.getPrefs().team; while (team.getValue() <= 0) { team.setValue(JOptionPane.showInputDialog("Input Team Number")); } if (useTeamNumber) { Robot.setTeam(frame.getPrefs().team.getValue()); } frame.pack(); frame.setVisible(true); monitor.setProgress(750); monitor.setNote("Loading From Save"); // Load File file = new File(frame.getPrefs().saveFile.getValue()); if (file.exists()) { frame.load(file.getPath()); } monitor.setProgress(1000); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }); } catch (Exception ex) { ex.printStackTrace(); System.exit(2); } }
public static void main(String[] args) throws Exception { robot = new Robot(); robot.setAutoDelay(50); try { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { createAndShowGUI(); } }); robot.waitForIdle(); checkFocusOwner(textField); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.waitForIdle(); checkFocusOwner(button); robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); robot.waitForIdle(); checkFocusOwner(textField); robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); robot.waitForIdle(); checkFocusOwner(button); } finally { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (frame != null) { frame.dispose(); } } }); } System.out.println("Test Passed!"); }
public void start() { menu.setMnemonic('f'); submenu.setMnemonic('m'); menu.add(submenu); submenu.add(item); bar.add(menu); frame.setJMenuBar(bar); frame.pack(); item.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Sysout.println(e.toString()); synchronized (activated) { activated.set(true); activated.notifyAll(); } } }); frame.setVisible(true); Util.waitForIdle(robot); boolean isMacOSX = (OSInfo.getOSType() == OSInfo.OSType.MACOSX); if (isMacOSX) { robot.keyPress(KeyEvent.VK_CONTROL); robot.delay(20); } robot.keyPress(KeyEvent.VK_ALT); robot.delay(20); robot.keyPress(KeyEvent.VK_F); robot.delay(20); robot.keyRelease(KeyEvent.VK_F); robot.delay(20); robot.keyRelease(KeyEvent.VK_ALT); if (isMacOSX) { robot.keyRelease(KeyEvent.VK_CONTROL); robot.delay(20); } Util.waitForIdle(robot); robot.keyPress(KeyEvent.VK_M); robot.delay(20); robot.keyRelease(KeyEvent.VK_M); Util.waitForIdle(robot); robot.keyPress(KeyEvent.VK_SPACE); robot.delay(20); robot.keyRelease(KeyEvent.VK_SPACE); Util.waitForIdle(robot); if (!Util.waitForCondition(activated, 2000)) { throw new TestFailedException("a submenu wasn't activated by mnemonic key press"); } Sysout.println("Test passed."); }
/** * Updates the background. Makes a new screen capture at the given coordiantes. * * @param x The x coordinate. * @param y The y coordinate. */ public void updateBackground(int x, int y) { this.background = robot.createScreenCapture( new Rectangle(x, y, x + this.window.getWidth(), y + this.window.getHeight())); }