List of usage examples for java.awt Desktop isDesktopSupported
public static boolean isDesktopSupported()
From source file:Main.java
/** * Opens the given website in the default browser, or show a message saying * that no default browser could be accessed. *///from w w w.ja v a2 s . co m public static void browse(Component parent, String uri) { boolean error = false; if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { try { Desktop.getDesktop().browse(new URI(uri)); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } catch (IOException ex) { error = true; } } else { error = true; } if (error) { String msg = "Impossible to open the default browser from the application.\nSorry."; JOptionPane.showMessageDialog(parent, msg); } }
From source file:Main.java
/** * Opens the given website in the default browser, or shows a message saying * that no default browser could be accessed. *///from w w w . j a v a 2 s . co m public static void browse(String url, Component msgParent) { boolean error = false; if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { try { Desktop.getDesktop().browse(new URI(url)); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } catch (IOException ex) { error = true; } } else { error = true; } if (error) { String msg = "Impossible to open the default browser from the application.\nSorry."; JOptionPane.showMessageDialog(msgParent, msg); } }
From source file:Main.java
private static void openWebpage(URI uri) throws IOException { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri);// ww w .j av a2s . c o m } }
From source file:org.jdal.system.SystemUtils.java
public static void open(byte[] data, String extension) { if (data != null && Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); File file;/* w w w. j a v a 2 s . c o m*/ try { file = File.createTempFile("tmp", "." + extension); file.deleteOnExit(); FileUtils.writeByteArrayToFile(file, data); desktop.open(file); } catch (IOException e) { String message = "No ha sido posible abrir el fichero"; JOptionPane.showMessageDialog(null, message, "Error de datos", JOptionPane.ERROR_MESSAGE); } } }
From source file:org.jdal.system.SystemUtils.java
public static void open(File file) { if (Desktop.isDesktopSupported()) try {// w w w. j av a 2 s . c om Desktop.getDesktop().open(file); } catch (IOException e) { log.error(e); } }
From source file:com.net2plan.utils.HTMLUtils.java
/** * Opens a browser for the given {@code URI}. It is supposed to avoid issues with KDE systems. * * @param uri URI to browse//from w w w . j a v a 2 s. c o m */ public static void browse(URI uri) { try { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(uri); return; } else if (SystemUtils.IS_OS_UNIX && (new File("/usr/bin/xdg-open").exists() || new File("/usr/local/bin/xdg-open").exists())) { new ProcessBuilder("xdg-open", uri.toString()).start(); return; } throw new UnsupportedOperationException( "Your operating system does not support launching browser from Net2Plan"); } catch (IOException | UnsupportedOperationException e) { throw new RuntimeException(e); } }
From source file:VASSAL.tools.BrowserSupport.java
public static void openURL(String url) { ////from w ww. ja va2 s . c o m // This method is irritatingly complex, because: // * There is no java.awt.Desktop in Java 1.5. // * java.awt.Desktop seems not to work sometimes on Windows. // * BrowserLauncher failes sometimes on Linux, and isn't supported // anymore. // if (!SystemUtils.IS_JAVA_1_5) { if (Desktop.isDesktopSupported()) { final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(new URI(url)); return; } catch (IOException e) { // We ignore this on Windows, because Desktop seems flaky if (!SystemUtils.IS_OS_WINDOWS) { ReadErrorDialog.error(e, url); return; } } catch (IllegalArgumentException e) { ErrorDialog.bug(e); return; } catch (URISyntaxException e) { ErrorDialog.bug(e); return; } } } } if (browserLauncher != null) { browserLauncher.openURLinBrowser(url); } else { ErrorDialog.show("BrowserSupport.unable_to_launch", url); } }
From source file:de.mendelson.comm.as2.client.HTMLPanel.java
/** Creates new form HTMLPanel */ public HTMLPanel() { initComponents();/*from w w w.j a va 2 s .c om*/ if (Desktop.isDesktopSupported()) { this.jEditorPane.addHyperlinkListener(this); } }
From source file:vazkii.psi.client.core.helper.SharingHelper.java
public static void uploadAndShare(String title, String export) { String url = uploadImage(title, export); try {//from w ww . java 2 s . c om String contents = "## " + title + " \n" + "### [Image + Code](" + url + ")\n" + "(to get the code click the link, RES won't show it)\n" + "\n" + "---" + "\n" + "*REPLACE THIS WITH A DESCRIPTION OF YOUR SPELL \n" + "Make sure you read the rules before posting. Look on the sidebar: https://www.reddit.com/r/psispellcompendium/ \n" + "Delete this part before you submit.*"; String encodedContents = URLEncoder.encode(contents, "UTF-8"); String encodedTitle = URLEncoder.encode(title, "UTF-8"); String redditUrl = "https://www.reddit.com/r/psispellcompendium/submit?title=" + encodedTitle + "&text=" + encodedContents; if (Desktop.isDesktopSupported()) Desktop.getDesktop().browse(new URI(redditUrl)); } catch (Exception e) { e.printStackTrace(); } }
From source file:natalia.dymnikova.util.IsDesktop.java
@Override public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) { return Desktop.isDesktopSupported(); }