List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:com.khepry.utilities.GenericUtilities.java
public static void displayLogFile(String logFilePath, long logSleepMillis, String xsltFilePath, String xsldFilePath) {// w w w . j a v a 2 s . c o m Logger.getLogger("").getHandlers()[0].close(); // only display the log file // if the logSleepMillis property // is greater than zero milliseconds if (logSleepMillis > 0) { try { Thread.sleep(logSleepMillis); File logFile = new File(logFilePath); File xsltFile = new File(xsltFilePath); File xsldFile = new File(xsldFilePath); File tmpFile = File.createTempFile("tmpLogFile", ".xhtml", logFile.getParentFile()); if (logFile.exists()) { if (xsltFile.exists() && xsldFile.exists()) { String xslFilePath; String xslFileName; String dtdFilePath; String dtdFileName; try { xslFileName = new File(logFilePath).getName().replace(".xhtml", ".xsl"); xslFilePath = logFile.getParentFile().toString().concat("/").concat(xslFileName); FileUtils.copyFile(new File(xsltFilePath), new File(xslFilePath)); dtdFileName = new File(logFilePath).getName().replace(".xhtml", ".dtd"); dtdFilePath = logFile.getParentFile().toString().concat("/").concat(dtdFileName); FileUtils.copyFile(new File(xsldFilePath), new File(dtdFilePath)); } catch (IOException ex) { String message = Level.SEVERE.toString().concat(": ").concat(ex.getLocalizedMessage()); Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, message, ex); GenericUtilities.outputToSystemErr(message, logSleepMillis > 0); return; } BufferedWriter bw = Files.newBufferedWriter(Paths.get(tmpFile.getAbsolutePath()), Charset.defaultCharset(), StandardOpenOption.CREATE); List<String> logLines = Files.readAllLines(Paths.get(logFilePath), Charset.defaultCharset()); for (String line : logLines) { if (line.startsWith("<!DOCTYPE log SYSTEM \"logger.dtd\">")) { bw.write("<!DOCTYPE log SYSTEM \"" + dtdFileName + "\">\n"); bw.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslFileName + "\"?>\n"); } else { bw.write(line.concat("\n")); } } bw.write("</log>\n"); bw.close(); } // the following statement is commented out because it's not quite ready for prime-time yet // Files.write(Paths.get(logFilePath), transformLogViaXSLT(logFilePath, xsltFilePath).getBytes(), StandardOpenOption.CREATE); Desktop.getDesktop().open(tmpFile); } else { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, logFilePath, new FileNotFoundException()); } } catch (InterruptedException | IOException ex) { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:net.landora.video.utils.UIUtils.java
public static void openBrowser(String url) { try {/*from w w w . j a v a 2 s . c om*/ Desktop.getDesktop().browse(new URI(url)); return; } catch (Exception ignore) { } List<String> cmd = new ArrayList<String>(); if (SystemUtils.IS_OS_MAC) { cmd.add("open"); } else if (SystemUtils.IS_OS_WINDOWS) { cmd.add("cmd"); cmd.add("/c"); cmd.add("start"); } else { cmd.add("xdg-open"); } cmd.add(url); try { Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()])); } catch (IOException ex) { LoggerFactory.getLogger(UIUtils.class).error("Error opening browsner: " + url, ex); } }
From source file:org.astrojournal.utilities.DesktopBrowse.java
/** * Browse an URI using Java Desktop (not recommended). * /*from ww w . jav a2 s . com*/ * @param uri * the URI to browser * @return true if the command succeeded, false otherwise. */ public static boolean browseJavaDesktop(URI uri) { log.debug("Trying to run Desktop.getDesktop().browse(" + uri.toString() + ")"); try { if (!Desktop.isDesktopSupported()) { log.debug("Java Desktop is not supported on this platform (" + osInfo + ").\n" + "Impossible to browse the URI: " + uri.toString()); return false; } if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { log.debug("Java Desktop does not support the action BROWSER on this platform (" + osInfo + ").\n"); return false; } Desktop.getDesktop().browse(uri); } catch (IOException e) { // Report the stack trace to make visible that something went wrong. log.debug("Java Desktop did not work on this platform (" + osInfo + ")", e); return false; } return true; }
From source file:backend.SoftwareSecurity.java
private void updateSoftware(JSONObject JSON) { System.out.println("Updating software"); String version = JSON.getString("version"); String features = JSON.getString("message"); Prompter.throwSuccess("Update Offers: " + features, "Supreme Shark Bot v " + version + " Now Available"); Prompter.throwSuccess(// www. j a v a2 s . c om "Your web browser will no open with the link to the newest version. If prompted, chose to save the file \nand not open it. Click launch help on the bot home screen once the bot opens for a detailed installation video.", "Update Instructions"); try { Desktop.getDesktop() .browse(new URI("http://supremesharkbot.com:8080/update/?key=" + activationKeyValue)); } catch (Exception e) { Prompter.throwError( "Your browser is not supported for bot updates, please email us at team@supremesharkbot.com for assistance", "Browser Not Supported"); } }
From source file:components.compile.java
/** * Chooses a folder to be used as source for creating a new SPDX * @param request /*w w w . jav a 2s . c om*/ */ public void folder(WebRequest request) { // no support for requests from the browser if (request.requestOrigin == RequestOrigin.BROWSER) { request.setAnswer("Not supported from browser"); return; } String paramString = request.getParameter("folder"); File folder = new File(paramString); try { Desktop.getDesktop().open(folder); } catch (IOException ex) { log.write(is.ERROR, "EX106 Exception: " + ex.getMessage()); } // all done, let's go back request.setAnswer(redirect); }
From source file:edu.ucar.idvbox.DropboxPublisher.java
/** * {@inheritDoc}/*from w w w . j av a 2s .c o m*/ */ @Override public boolean doInitNew() { /* * See https:forums.dropbox.com/topic.php?id=62874 * * Dropbox API lacks a good way of securing the app key/secret pair, * though the user will always have to provide credentials for any file * transfer to dropbox. The theoretical danger is it would be trivial * for someone to grab the app key/secret pair and masquerade as this * plugin application. But again, the user still needs to authenticate * in all cases. Below, using BASE 64 encoding so that the app * key/secret pair is at least not available as clear text. * * Please provide a base 64 encode app key/secret pair from dropbox in a * dropbox.properties file src/resources. Do not store in version * control. */ try { String dropbox_app_key = new String( Base64.decodeBase64(getIdv().getArgsManager().getProperty("dropbox_app_key", null).getBytes())); String dropbox_app_secret = new String(Base64 .decodeBase64(getIdv().getArgsManager().getProperty("dropbox_app_secret", null).getBytes())); AppKeyPair appKeys = new AppKeyPair(dropbox_app_key, dropbox_app_secret); WebAuthSession session = new WebAuthSession(appKeys, AccessType.APP_FOLDER); WebAuthInfo authInfo = session.getAuthInfo(); RequestTokenPair pair = authInfo.requestTokenPair; String url = authInfo.url; Desktop.getDesktop().browse(new URL(url).toURI()); JOptionPane.showMessageDialog(null, "Invoking browser to sign in to Dropbox. Press OK after you have authenticated."); session.retrieveWebAccessToken(pair); api = new DropboxAPI<WebAuthSession>(session); } catch (Exception e) { LogUtil.logException("Dropbox publishing", e); return false; } return true; }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerSaveLayerToSLDAction.java
@Override public void actionPerformed(ActionEvent e) { boolean backup = false; if (styledLayer.getSldFile().exists()) { // if (StylingUtil.isStyleDifferent(styledLayer.getStyle(), // styledLayer.getSldFile())){ // return; // }/*ww w .j ava 2s .c o m*/ try { FileUtils.copyFile(styledLayer.getSldFile(), IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak")); backup = true; } catch (IOException e1) { LOGGER.warn("could not create a backup of the existing .sld", e1); return; } } try { StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile()); StylingUtil.saveStyleToSld(styledLayer.getStyle(), ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true, "AtlasStyler " + ReleaseUtil.getVersionInfo(AtlasStyler.class) + ", Layer:" + styledLayer.getTitle() + ", Export-Mode: PRODUCTION"); Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"), ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") }; int dialogValue = 0; if (backup) { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } else { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } if (dialogValue == JOptionPane.NO_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(styledLayer.getSldFile()); } if (dialogValue == JOptionPane.CANCEL_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile())); } List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile())); if (es.size() > 0) { ExceptionDialog.show(owner, new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid", IOUtil.escapePath(styledLayer.getSldFile())), es.get(0))); } } catch (Exception e1) { LOGGER.error("saveStyleToSLD", e1); ExceptionDialog.show(owner, e1); return; } }
From source file:de.tbuchloh.kiskis.gui.feedback.AbstractSubmitFeedback.java
/** * @param defaultBody/*from w w w.j a v a2 s. c o m*/ * the default bug body * @throws FeedbackException * if the mail program cannot be opened */ public void openMail(String defaultBody) throws FeedbackException { try { final String mailToString = createMailToString(defaultBody); Desktop.getDesktop().mail(new URI(mailToString)); } catch (final IOException e1) { throwFeedbackException(e1, defaultBody); } catch (final URISyntaxException e1) { throwFeedbackException(e1, defaultBody); } }
From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java
private void start() throws Exception { log.info("Starting..."); final TrayIcon trayIcon = new TrayIcon(new ImageIcon(imageDisabledUrl).getImage(), "Ethereum Harmony"); trayIcon.setImageAutoSize(true); // Auto-size icon base on space // doesn't work // Runtime.getRuntime().addShutdownHook(new Thread(() -> closeContext())); executor.submit(() -> {//from www. jav a 2 s . c om try { context = new SpringApplicationBuilder(Application.class).headless(true).web(true).run(); serverPort = Integer.valueOf(context.getEnvironment().getProperty("local.server.port")); log.info("Spring context created at port " + serverPort); trayIcon.setImage(new ImageIcon(imageEnabledUrl).getImage()); setTrayMenu(trayIcon, browserMenu, logsMenu, quitMenu); openBrowser(); } catch (Exception e) { final Throwable cause = DesktopUtil.findCauseFromSpringException(e); showErrorWindow(cause.getMessage(), "Problem running Harmony:\n\n" + ExceptionUtils.getStackTrace(cause)); } }); if (!SystemTray.isSupported()) { log.error("System tray is not supported"); return; } browserMenu.addActionListener(e -> openBrowser()); quitMenu.addActionListener(event -> { log.info("Quit action was requested from tray menu"); trayIcon.setImage(new ImageIcon(imageDisabledUrl).getImage()); setTrayMenu(trayIcon, logsMenu, quitingMenu); closeContext(); System.exit(0); }); logsMenu.addActionListener(event -> { log.info("Logs action was requested from tray menu"); final File logsFile = new File(LOGS_PATH); try { Desktop.getDesktop().open(logsFile); } catch (IOException e) { log.error("Problem opening logs dir", e); } }); setTrayMenu(trayIcon, loadingMenu, logsMenu, quitMenu); }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLExtractorGUI.java
public void actionPerformed(ActionEvent e) { try {/*w w w . j a va 2 s . co m*/ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == jbnFileXML) gc.fileChooser(jtfFileXML, "", "open"); else if (e.getSource() == jbnRunExtractor) { URL template = templateForExcel(); File fileExcelOutput = extract(template); if (fileExcelOutput != null) { log.info("Opening excel file through Desktop: " + fileExcelOutput); Desktop.getDesktop().open(fileExcelOutput); } } else if (e.getSource() == jbnCreateReport) { URL template = getClass().getClassLoader().getResource("ExcelTemplate.xlsx"); File fileExcelOutput = extract(template); if (fileExcelOutput != null) { log.info("Opening report through Desktop: " + fileExcelOutput); String fileName = FilenameUtils.removeExtension(fileExcelOutput.getAbsolutePath()); File filePDFOutput = new File(fileName + ".pdf"); File fileWordOutput = new File(fileName + ".docx"); filePDFOutput.deleteOnExit(); fileWordOutput.deleteOnExit(); new ReportController().createReport(pcDep, fileExcelOutput, filePDFOutput, fileWordOutput, isInternal); gc.openPDF(isInternal, filePDFOutput, this); Desktop.getDesktop().open(fileWordOutput); } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } catch (Throwable throwable) { SwingGUI.handleError(this, throwable); } }