List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:com.simplexrepaginator.RepaginateFrame.java
protected JMenuBar createMenuBar() { JMenuBar mb = new JMenuBar(); JMenu m;/* ww w. j a va 2 s .c om*/ m = new JMenu("File"); m.add(new AbstractAction("Select Input") { @Override public void actionPerformed(ActionEvent e) { input.doClick(); } }); m.add(new AbstractAction("Select Output") { @Override public void actionPerformed(ActionEvent e) { output.doClick(); } }); m.add(new UpdateCheckerAction()); m.add(new AbstractAction("Exit") { @Override public void actionPerformed(ActionEvent arg0) { dispose(); } }); mb.add(m); m = new JMenu("Help"); m.add(new AbstractAction("Website") { @Override public void actionPerformed(ActionEvent e) { try { URL url = new URL("http://www.simplexrepaginator.com/"); Desktop.getDesktop().browse(url.toURI()); } catch (IOException ioe) { } catch (URISyntaxException urise) { } } }); m.add(new AbstractAction("About") { @Override public void actionPerformed(ActionEvent e) { String license; try { license = IOUtils.toString(RepaginateFrame.class.getResource("LICENSE.txt")); } catch (IOException ioe) { license = "An error occured reading the license file:\n" + ioe; } JOptionPane.showMessageDialog(RepaginateFrame.this, license); } }); mb.add(m); return mb; }
From source file:smsapp.utils.Utils.java
public static void browseFileLocation(String folderName) { File f = new File(folderName + "" + File.separator + ""); Desktop dt = Desktop.getDesktop(); try {//from ww w. j a va 2s . com dt.open(f); } catch (IOException ex) { Logger.getLogger(ControllerWhatsapp.class.getName()).log(Level.SEVERE, null, ex); ex.printStackTrace(); } System.out.println("Done."); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopExportDisplay.java
private void openFileAction(String finalFileName, ExportDataProvider dataProvider) { File destFile = null;/*from ww w . ja v a 2s. co m*/ try { destFile = File.createTempFile("get_" + FilenameUtils.getBaseName(finalFileName), "." + getFileExt(finalFileName)); } catch (IOException e) { String message = messages.getMessage(DesktopExportDisplay.class, "export.tempFileError"); getFrame().getWindowManager().showNotification(message, Frame.NotificationType.WARNING); } if (destFile != null) { if (Desktop.isDesktopSupported() && saveFile(dataProvider, destFile)) { try { Desktop.getDesktop().open(destFile); } catch (IOException ex) { String message = messages.getMessage(DesktopExportDisplay.class, "export.openError"); getFrame().getWindowManager().showNotification(message, Frame.NotificationType.WARNING); } } } }
From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java
protected void open(final File file) { if (logger.isDebugEnabled()) { logger.debug("File name {} exists {}, read {}, write {}, execute {}", new Object[] { file.getAbsolutePath(), file.exists(), file.canRead(), file.canWrite(), file.canExecute() }); }// ww w. ja v a 2 s .c o m try { Desktop.getDesktop().open(file); } catch (Throwable t) { if (isMac()) { File file_app = newFile(file.getAbsolutePath() + ".app"); try { Desktop.getDesktop().open(file_app); } catch (Throwable tt) { handleOpenError(file, t); } } else { handleOpenError(file, t); } } }
From source file:spartanfinal.ProcessFiles.java
public void openFile(File file) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { for (Desktop.Action action : Desktop.Action.values()) { }/*from w w w .ja v a 2 s.c o m*/ try { desktop.open(file); } catch (Exception t) { String[] commands = { "cmd.exe", "/c", "start", "\"test\"", "\"" + file.getAbsolutePath() + "\"" }; try { Process p = Runtime.getRuntime().exec(commands); p.waitFor(); } catch (Exception l) { } } } else { } }
From source file:osu.beatmapdownloader.JFrame.java
public void apiHelp() { String text = "More Info"; L_apiHelp.setText("<html><a href=\"\">" + text + "</a></html>"); L_apiHelp.setCursor(new Cursor(Cursor.HAND_CURSOR)); L_apiHelp.addMouseListener(new MouseAdapter() { @Override/*from w w w. j a v a 2 s . c om*/ public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("https://osu.ppy.sh/p/api")); } catch (URISyntaxException | IOException ex) { } } }); }
From source file:org.apache.http.examples.me.ClientMultiThreadedExecution.java
public static void runBroswer(String webSite) { try {/* w w w .j a va 2 s . c o m*/ Desktop desktop = Desktop.getDesktop(); if (desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) { URI uri = new URI(webSite); desktop.browse(uri); } } catch (IOException ex) { ex.printStackTrace(); } catch (URISyntaxException ex) { ex.printStackTrace(); } }
From source file:io.bitsquare.common.util.Utilities.java
public static void openURI(URI uri) throws IOException { if (!isLinux() && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(uri); } else {/*from ww w . ja v a2s. c o m*/ // Maybe Application.HostServices works in those cases? // HostServices hostServices = getHostServices(); // hostServices.showDocument(uri.toString()); // On Linux Desktop is poorly implemented. // See https://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform if (!DesktopUtil.browse(uri)) throw new IOException("Failed to open URI: " + uri.toString()); } }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ContentExists.java
private void btnViewContentActionPerformed(final java.awt.event.ActionEvent evt) { final Desktop desktop = Desktop.getDesktop(); try {/* w w w . j av a2s . c om*/ final StringBuilder url = new StringBuilder(); url.append(theContentAggregatorURL); if (!theContentAggregatorURL.endsWith("?")) { url.append("?"); } url.append("system="); url.append(cmsSystem); url.append("&id="); url.append(theCmsID); desktop.browse(new URI(url.toString())); } catch (IOException ex) { //This error can occur if the default browser isn't set up properly. //It mostly occurs when the URL has been successfully opened, but it // can also happen when the URL has NOT been opened. // This makes it hard to determine whether it is actually an error or not // As the more common occurrence is a successful outcome we don't // want to pop up a message box, so just log the error instead. LOG.error("Error loading form parameters", ex); } catch (Exception ex) { final String header = "Error occurred"; final String message = "An error occurred when viewing content\n" + ex.getMessage(); JOptionPane.showMessageDialog(this, message, header, JOptionPane.ERROR_MESSAGE); } }
From source file:app.common.X3DViewer.java
/** * View an X3D file using an external X3DOM player * * @param filename//from w w w . j ava 2 s . co m * @throws IOException */ public static void viewX3DOM(String[] filename, float[] pos) throws IOException { // TODO: Make thread safe using tempDir String dest = "/tmp/"; File dir = new File(dest); dir.mkdirs(); String pf = "x3dom/x3dom.css"; String dest_pf = dest + pf; File dest_file = new File(dest_pf); File src_file = new File("src/html/" + pf); if (!dest_file.exists()) { System.out.println("Copying file: " + src_file + " to dir: " + dest); FileUtils.copyFile(src_file, dest_file, true); } pf = "x3dom/x3dom.js"; dest_pf = dest + pf; dest_file = new File(dest_pf); src_file = new File("src/html/" + pf); if (!dest_file.exists()) { System.out.println("Copying file: " + src_file + " to dir: " + dest); FileUtils.copyFile(src_file, dest_file, true); } File f = new File("/tmp/out.xhtml"); FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bos = new BufferedOutputStream(fos); PrintStream ps = new PrintStream(bos); try { ps.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); ps.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); ps.println("<head>"); ps.println("<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />"); ps.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); ps.println("<title>Ring Popper Demo</title>"); // ps.println("<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>"); ps.println("<link rel='stylesheet' type='text/css' href='x3dom/x3dom.css'></link>"); ps.println("</head>"); ps.println("<body>"); ps.println("<p class='case'>"); ps.println( "<X3D profile='Immersive' showLog='true' showStats='true' version='3.0' height='600px' width='600px' y='0px' x='0px'>"); // had to turn of isStaticHierarchy // ps.println("<Scene isStaticHierarchy=\"true\" sortTrans=\"false\" doPickPass=\"false\" frustumCulling=\"false\">"); ps.println("<Scene sortTrans=\"false\" doPickPass=\"false\" frustumCulling=\"false\">"); // ps.println("<Scene>"); ps.println("<Background skyColor=\"1 1 1\" />"); if (pos != null) { ps.println("<Viewpoint position='" + pos[0] + " " + pos[1] + " " + pos[2] + "' />"); } for (int i = 0; i < filename.length; i++) { if (filename[i] != null) { ps.println("<Inline url='" + filename[i] + "' />"); } } ps.println("</Scene>"); ps.println("</X3D>"); // ps.println("<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>"); ps.println("<script type='text/javascript' src='x3dom/x3dom.js'></script>"); ps.println("</p>"); ps.println("</body></html>"); } finally { bos.flush(); bos.close(); fos.close(); } Desktop.getDesktop().browse(f.toURI()); }