List of usage examples for java.awt AWTException printStackTrace
public void printStackTrace()
From source file:com.truven.report.reporter.Reporter.java
/** * Save screen shot.// w ww . j a v a 2s . c o m * * @param reportFolderLocation the report folder location * @return the string */ private String saveScreenShot(final String reportFolderLocation) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSS"); String timestamp = sdf.format(date); Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture; String screenShotFile = timestamp + ".png"; String screenShotImgFolder = reportFolderLocation + File.separator + "images"; try { capture = new Robot().createScreenCapture(screenRect); File screenShotImgFolderFile = new File(screenShotImgFolder); if (!screenShotImgFolderFile.exists() && !screenShotImgFolderFile.mkdirs()) { throw new RuntimeException( "Cannot create new folder in location " + screenShotImgFolderFile.getAbsolutePath()); } File screenShotImg = new File(screenShotImgFolder + File.separator + screenShotFile); ImageIO.write(capture, "png", screenShotImg); } catch (IOException e) { e.printStackTrace(); } catch (AWTException e1) { e1.printStackTrace(); } catch (Exception e2) { e2.printStackTrace(); } return screenShotFile; }
From source file:com.chaosting.product.hotkey.Main.java
@PostConstruct public void run() { logger.info("Checking the license..."); String licFile = ClassLoader.getSystemClassLoader().getResource("").getPath() + LIC_FILE_NAME; if (!LicenseUtil.isLicValid(licFile)) { logger.info("The license is expired. The software will exit."); return;/* w w w. j a v a2 s .c o m*/ } logger.info("The license is OK. Checking the required dll..."); String fileName = OSUtil.getOSArch().contains("86") ? "JIntellitype.dll" : "JIntellitype64.dll"; String dllFile = ClassLoader.getSystemClassLoader().getResource("").getPath() + "lib/" + fileName; JIntellitype.setLibraryLocation(dllFile); if (!JIntellitype.isJIntellitypeSupported()) { logger.info("The OS is not Windows or the dll is not found. The software will exit."); return; } JIntellitype jIntellitype = JIntellitype.getInstance(); logger.info("The dll is ready. Parsing the config now..."); final List<Hotkey> hotkeyList = getHotKeyList(); logger.info("Finish parasing config. Registing the hotkey now..."); for (Hotkey hotkey : hotkeyList) { jIntellitype.registerHotKey(hotkey.getIdentifier(), (hotkey.isModShift() == true ? JIntellitype.MOD_SHIFT : 0) + (hotkey.isModControl() == true ? JIntellitype.MOD_CONTROL : 0) + (hotkey.isModWin() == true ? JIntellitype.MOD_WIN : 0) + (hotkey.isModAlt() == true ? JIntellitype.MOD_ALT : 0), (int) hotkey.getKey()); } try { robot = new Robot(); } catch (AWTException e) { e.printStackTrace(); } jIntellitype.addHotKeyListener(new HotkeyListener() { public void onHotKey(int identifier) { for (Hotkey hotkey : hotkeyList) { if (hotkey.getIdentifier() == identifier) { if (hotkey.getGoal().equalsIgnoreCase("exe")) { if (OSUtil.execute(hotkey.getParam())) { logger.info("Executed the " + hotkey.getParam() + " success."); } else { logger.info("Executed the " + hotkey.getParam() + " faild."); } } else if (hotkey.getGoal().equalsIgnoreCase("out")) { int delay = 100; try { delay = Integer.parseInt(properties.getProperty("delay")); } catch (Exception e) { e.printStackTrace(); } robot.delay(delay); for (char c : hotkey.getParam().toCharArray()) { int keycode = convertAsciiInt2KeycodeInt(c); if (keycode == -1) { logger.info("Unsupport character " + c); } else { if ((int) c >= 65 && (int) c <= 90) { robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(keycode); robot.keyRelease(KeyEvent.VK_SHIFT); robot.keyRelease(keycode); } else { robot.keyPress(keycode); robot.keyRelease(keycode); } } } } break; } } } }); logger.info("All the things get ready."); }
From source file:press.gfw.Windows.java
private void initTray() { logo = Toolkit.getDefaultToolkit().getImage("logo.png"); setIconImage(logo);/*from w w w . j a v a2 s. c o m*/ if (!SystemTray.isSupported()) { return; } icon = new TrayIcon(logo, null, null); icon.setImageAutoSize(true); icon.addActionListener(new TrayListener()); tray = SystemTray.getSystemTray(); try { tray.add(icon); } catch (AWTException ex) { log(""); ex.printStackTrace(); } }
From source file:com.pentaho.ctools.issues.cde.CDE417.java
/** * ############################### Test Case 1 ############################### * * Test Case Name: // www.j a v a2 s . co m * Popup Export issues * * Description: * CDE-417 issue, so when user clicks to export chart, popup shown has chart preview. * CDE-424 issue we'll delete the .js file prior to opening the dashboard and saving the dashboard should create * the .js file again and enable exporting. * CDF-448 exporting chart with skip ticks (chart is too small to show all labels) is successful * CDF-502 export chart with array parameters is successful * CDE-514 all charts are available on charts to export property and all elements are available on the data to export property * * Steps: * 424 * 1. Open PUC and click Browse Files * 2. Go to dashboard folder, click countryChart.js file and click Move To Trash * 3. Open created sample and save Dashboard * 514 * 4. Go to Export Component and assert all charts appear on the Chart to Export property * 5. Assert all charts and the table appear on data to export property * * 417/448/502 * 6. Click to export chart, click export, assert chart is shown and assert export works as expected (448 and 502) * 7. Click to export chart2, click export, assert chart is shown and assert export works as expected * * @throws InterruptedException * */ @Test public void tc01_PopupExportComponent_PreviewerRendersChart() throws InterruptedException { this.log.info("tc01_PopupExportComponent_PreviewerRendersChart"); /* * ## Step 1 */ //Show Hidden Files BrowseFiles browser = new BrowseFiles(driver); if (!PUCSettings.SHOWHIDDENFILES) { browser.CheckShowHiddenFiles(); } /* * ## Step 2 */ //String pathChart = "/public/Issues/CDF/CDF-548/chart.js"; //String pathCdfChart = "/public/Issues/CDF/CDF-548/CDF-548_chart.js"; String pathCountryChart = "/public/Issues/CDF/CDF-548/countryChart.js"; String pathCdfCountryChart = "/public/Issues/CDF/CDF-548/CDF-548_countryChart.js"; //boolean fileDeleteChart = browser.DeleteFile( pathChart ); //boolean fileDeleteCdfChart = browser.DeleteFile( pathCdfChart ); boolean fileDeleteCountryChart = browser.DeleteFile(pathCountryChart); boolean fileDeleteCdfCountryChart = browser.DeleteFile(pathCdfCountryChart); //assertTrue( fileDeleteChart ); //assertTrue( fileDeleteCdfChart ); assertTrue(fileDeleteCountryChart); assertTrue(fileDeleteCdfCountryChart); driver.switchTo().defaultContent(); WebDriver frame = driver.switchTo().frame("browser.perspective"); this.elemHelper.WaitForAttributeValue(frame, By.xpath("//div[@id='fileBrowserFiles']/div[2]/div[1]"), "title", "CDF-548.cda"); String nameOfCdf548Wcdf = this.elemHelper.GetAttribute(frame, By.xpath("//div[@id='fileBrowserFiles']/div[2]/div[1]"), "title"); assertEquals("CDF-548.cda", nameOfCdf548Wcdf); /* * ## Step 3 */ // Go to Export Popup Component sample in Edit mode driver.get(baseUrl + "api/repos/%3Apublic%3AIssues%3ACDF%3ACDF-548%3ACDF-548.wcdf/edit"); //Save Dashboard WebElement saveButton = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("Save")); assertNotNull(saveButton); this.elemHelper.Click(driver, By.id("Save")); WebElement saveNotify = this.elemHelper.WaitForElementPresenceAndVisible(driver, By.cssSelector("div.notify-bar-message")); assertNotNull(saveNotify); String saveMessage = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("div.notify-bar-message")); assertEquals("Dashboard saved successfully", saveMessage); /* * ## Step 4 */ //Go to components panel and expand "Others" WebElement componentsPanelButton = this.elemHelper.FindElement(driver, By.cssSelector("div.componentsPanelButton")); assertNotNull(componentsPanelButton); componentsPanelButton.click(); WebElement componentsTable = this.elemHelper.FindElement(driver, By.id("cdfdd-components-components")); assertNotNull(componentsTable); WebElement othersExpander = this.elemHelper.FindElement(driver, By.xpath("//table[@id='table-cdfdd-components-components']//tr[@id='OTHERCOMPONENTS']/td/span")); assertNotNull(othersExpander); othersExpander.click(); //Select Export Popup Component WebElement exportPopupElement = this.elemHelper.FindElement(driver, By.xpath("//table[@id='table-cdfdd-components-components']//td[contains(text(),'exportPopup')]")); assertNotNull(exportPopupElement); exportPopupElement.click(); //Open options for Chart Component to Export and assert "chart" and "countryChart" WebElement chartExportProperty = this.elemHelper.FindElement(driver, By.xpath( "//table[@id='table-cdfdd-components-properties']//td[@title='Id for Chart Component to Export']/../td[2]")); assertNotNull(chartExportProperty); chartExportProperty.click(); WebElement chartExportInput = this.elemHelper.FindElement(driver, By.xpath( "//table[@id='table-cdfdd-components-properties']//td[@title='Id for Chart Component to Export']/../td[2]/form/input")); assertNotNull(chartExportInput); chartExportInput.clear(); Robot robot; try { robot = new Robot(); robot.keyPress(KeyEvent.VK_DOWN); robot.keyRelease(KeyEvent.VK_DOWN); } catch (AWTException e) { e.printStackTrace(); } WebElement chartExportOptions = this.elemHelper.FindElement(driver, By.xpath("//body/ul")); assertNotNull(chartExportOptions); String chartOption1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//body/ul/li/a")); String chartOption2 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//body/ul/li[2]/a")); assertEquals("chart", chartOption1); assertEquals("countryChart", chartOption2); this.elemHelper.Click(driver, By.xpath("//body/ul/li/a")); /* * ## Step 5 */ //Open options for Data Component to Export and assert "table", "chart" and "countryChart" WebElement dataExportProperty = this.elemHelper.FindElement(driver, By.xpath( "//table[@id='table-cdfdd-components-properties']//td[@title='Id for Data Component to Export']/../td[2]")); assertNotNull(dataExportProperty); dataExportProperty.click(); WebElement dataExportInput = this.elemHelper.FindElement(driver, By.xpath( "//table[@id='table-cdfdd-components-properties']//td[@title='Id for Data Component to Export']/../td[2]/form/input")); assertNotNull(dataExportInput); dataExportInput.clear(); Robot robot1; try { robot1 = new Robot(); robot1.keyPress(KeyEvent.VK_DOWN); robot1.keyRelease(KeyEvent.VK_DOWN); } catch (AWTException e) { e.printStackTrace(); } WebElement dataExportOptions = this.elemHelper.FindElement(driver, By.xpath("//body/ul")); assertNotNull(dataExportOptions); String dataOption1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//body/ul/li/a")); String dataOption2 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//body/ul/li[2]/a")); String dataOption3 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//body/ul/li[3]/a")); assertEquals("table", dataOption1); assertEquals("chart", dataOption2); assertEquals("countryChart", dataOption3); /* * ## Step 6 */ driver.get(baseUrl + "api/repos/%3Apublic%3AIssues%3ACDF%3ACDF-548%3ACDF-548.wcdf/generatedContent"); this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); //Click export Button WebElement exportChartButton = this.elemHelper.FindElement(driver, By.xpath("//div[@id='export']/div")); assertNotNull(exportChartButton); exportChartButton.click(); //Assert popup and click Export Chart link WebElement exportChartLink = this.elemHelper.FindElement(driver, By.cssSelector("div.exportElement")); assertNotNull(exportChartLink); exportChartLink.click(); //Assert chart popup WebElement exportChartPopup = this.elemHelper.FindElement(driver, By.id("fancybox-content")); assertNotNull(exportChartPopup); // Check URL of displayed image String chartSRCUrl = this.elemHelper.GetAttribute(driver, By.xpath("//div[@id='fancybox-content']/div/div/div/div[2]/img"), "src"); assertEquals(baseUrl + "plugin/cgg/api/services/draw?outputType=png&script=%2Fpublic%2FIssues%2FCDF%2FCDF-548%2Fchart.js¶mcountries=France¶mcountries=USA¶mwidth=400¶mheight=400", chartSRCUrl); assertEquals(200, HttpUtils.GetResponseCode(chartSRCUrl, "admin", "password")); // Export chart and assert export was successful WebElement chartExportButton = this.elemHelper.FindElement(driver, By.cssSelector("div.exportChartPopupButton.exportChartOkButton")); assertNotNull(chartExportButton); //Click export and assert file is correctly downloaded try { //Delete the existence if exist new File(this.exportFilePath).delete(); //Click to export chartExportButton.click(); //Wait for file to be created in the destination dir DirectoryWatcher dw = new DirectoryWatcher(); dw.WatchForCreate(downloadDir); //Check if the file really exist File exportFile = new File(this.exportFilePath); // assertTrue(exportFile.exists()); //Wait for the file to be downloaded totally for (int i = 0; i < 50; i++) { //we only try 50 times == 5000 ms long nSize = FileUtils.sizeOf(exportFile); //Since the file always contents the same data, we wait for the expected bytes if (nSize >= 10000) { break; } this.log.info("BeforeSleep " + nSize); Thread.sleep(100); } this.log.info("File size :" + FileUtils.sizeOf(exportFile)); //Check if the file downloaded is the expected String md5 = DigestUtils.md5Hex(Files.readAllBytes(exportFile.toPath())); assertEquals(md5, "c8c3ad02461f7b5c8a36ee2aec0eca95"); //The delete file DeleteFile(); } catch (Exception e) { this.log.error(e.getMessage()); } // Close dialog box this.elemHelper.Click(driver, By.id("fancybox-close")); assertTrue(this.elemHelper.WaitForElementNotPresent(driver, By.xpath("//div[@id='fancybox-content']/div/div/div/div/div[1]"))); /* * ## Step 7 */ this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.exportElement")); //Click export Button WebElement exportCountryChartButton = this.elemHelper.FindElement(driver, By.xpath("//div[@id='export2']/div")); assertNotNull(exportCountryChartButton); exportCountryChartButton.click(); //Assert popup and click Export Chart link WebElement exportCountryChartLink = this.elemHelper.FindElement(driver, By.xpath("//div[contains(text(),'Export Chart2')]")); assertNotNull(exportCountryChartLink); exportCountryChartLink.click(); //Assert chart popup WebElement exportCountryChartPopup = this.elemHelper.FindElement(driver, By.id("fancybox-content")); assertNotNull(exportCountryChartPopup); // Check URL of displayed image String countryChartSRCUrl = this.elemHelper.GetAttribute(driver, By.xpath("//div[@id='fancybox-content']/div/div/div/div[2]/img"), "src"); assertEquals(baseUrl + "plugin/cgg/api/services/draw?outputType=svg&script=%2Fpublic%2FIssues%2FCDF%2FCDF-548%2FcountryChart.js¶mwidth=400¶mheight=300", countryChartSRCUrl); assertEquals(200, HttpUtils.GetResponseCode(countryChartSRCUrl, "admin", "password")); // Export chart and assert export was successful WebElement countryChartExportButton = this.elemHelper.FindElement(driver, By.cssSelector("div.exportChartPopupButton.exportChartOkButton")); assertNotNull(countryChartExportButton); //Click export and assert file is correctly downloaded try { //Delete the existence if exist new File(this.exportFilePath2).delete(); //Click to export countryChartExportButton.click(); //Wait for file to be created in the destination dir DirectoryWatcher dw = new DirectoryWatcher(); dw.WatchForCreate(downloadDir); //Check if the file really exist File exportFile = new File(this.exportFilePath2); // assertTrue(exportFile.exists()); //Wait for the file to be downloaded totally for (int i = 0; i < 50; i++) { //we only try 50 times == 5000 ms long nSize = FileUtils.sizeOf(exportFile); //Since the file always contents the same data, we wait for the expected bytes if (nSize >= 30000) { break; } this.log.info("BeforeSleep " + nSize); Thread.sleep(100); } this.log.info("File size :" + FileUtils.sizeOf(exportFile)); //Check if the file downloaded is the expected String md5 = DigestUtils.md5Hex(Files.readAllBytes(exportFile.toPath())); assertEquals(md5, "c0d04625306dd1f32afed115c0bf94be"); //The delete file DeleteFile(); } catch (Exception e) { this.log.error(e.getMessage()); } // Close dialog box this.elemHelper.Click(driver, By.id("fancybox-close")); assertTrue(this.elemHelper.WaitForElementNotPresent(driver, By.xpath("//div[@id='fancybox-content']/div/div/div/div/div[1]"))); }
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 ava 2 s . 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.jaspersoft.studio.property.color.chooser.AdvancedColorWidget.java
/** * Read the color under the mouse position and set it as the current color. This * is done only if JSS or one of its components are focused. It is necessary to control * this dialog and its content because it modal, so every other component of JSS can not be focused *///from w ww .j a va 2 s.co m private void checkColorPicker() { if (!isDisposed() && (getShell().isFocusControl() || checkControlFocused(getShell().getChildren()))) { Robot robot; try { robot = new Robot(); Point pos = Display.getCurrent().getCursorLocation(); java.awt.Color color = robot.getPixelColor(pos.x, pos.y); RGB rgbColor = new RGB(color.getRed(), color.getGreen(), color.getBlue()); colorsSelector.setSelectedColor(rgbColor, false); updateText(rgbColor, rgbColor.getHSB(), null); } catch (AWTException e) { e.printStackTrace(); } } }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createCaptureButton() { JButton capture = new JButton("Capture"); capture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new PngFileFilter()); int result = chooser.showSaveDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".png")) { absolutePath += ".png"; }/*from www .j ava 2 s. c o m*/ try { vv.setDoubleBuffered(false); writeToImageFile(absolutePath); vv.setDoubleBuffered(true); } catch (AWTException e1) { e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } // captureToFile(absolutePath); // writeJPEGImage(absolutePath + ".JPEG"); // captureScreen(absolutePath); } } }); return capture; }
From source file:com.netease.dagger.BrowserEmulator.java
/** * Mimic system-level keyboard event/*from w w w.j a v a 2s .com*/ * * @param keyCode * http://www.cnblogs.com/hsapphire/archive/2009/12/16/1625642.html */ public void pressKeyboard(int keyCode) { pause(stepInterval); Robot rb = null; try { rb = new Robot(); } catch (AWTException e) { e.printStackTrace(); } rb.keyPress(keyCode); // press key rb.delay(100); // delay 100ms rb.keyRelease(keyCode); // release key logger.info("Pressed key with code " + keyCode); }
From source file:com.netease.dagger.BrowserEmulator.java
/** * Hover on the page element/*from w ww. j a v a2 s. c o m*/ * * @param xpath * the element's xpath */ public void mouseOver(String xpath) { pause(stepInterval); expectElementExistOrNot(true, xpath, timeout); // First make mouse out of browser Robot rb = null; try { rb = new Robot(); } catch (AWTException e) { e.printStackTrace(); } rb.mouseMove(0, 0); // Then hover WebElement we = browserCore.findElement(By.xpath(xpath)); if (GlobalSettings.browserCoreType == 2) { try { Actions builder = new Actions(browserCore); builder.moveToElement(we).build().perform(); } catch (Exception e) { e.printStackTrace(); handleFailure("Failed to mouseover " + xpath); } logger.info("Mouseover " + xpath); return; } // Firefox and IE require multiple cycles, more than twice, to cause a // hovering effect if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) { for (int i = 0; i < 5; i++) { Actions builder = new Actions(browserCore); builder.moveToElement(we).build().perform(); } logger.info("Mouseover " + xpath); return; } // Selenium doesn't support the Safari browser if (GlobalSettings.browserCoreType == 4) { Assert.fail("Mouseover is not supported for Safari now"); } Assert.fail("Incorrect browser type"); }