Example usage for java.awt Desktop isSupported

List of usage examples for java.awt Desktop isSupported

Introduction

In this page you can find the example usage for java.awt Desktop isSupported.

Prototype

public boolean isSupported(Action action) 

Source Link

Document

Tests whether an action is supported on the current platform.

Usage

From source file:Main.java

public static void main(String[] a) {
    try {/*from  w  w  w . ja v  a  2 s .c o m*/
        URI uri = new URI("http://www.java2s.com");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
            desktop.isSupported(Desktop.Action.PRINT);
        }

        if (desktop != null)
            desktop.browse(uri);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (URISyntaxException use) {
        use.printStackTrace();
    }

}

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);// w w w  . j  a v  a  2  s .  co m
    }
}

From source file:VASSAL.tools.BrowserSupport.java

public static void openURL(String url) {
    ///*  w  w w .ja va  2  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:org.apache.http.examples.me.ClientMultiThreadedExecution.java

public static void runBroswer(String webSite) {
    try {/*from   w ww  .  j  a  va 2  s .  co 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:org.planetcrypto.bitcoin.PlanetCryptoNetworkMethods.java

/**
 * /*from   w  w w . j av  a 2 s . c om*/
 * @param uri URL of Eligius user stats
 */
public static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(uri);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:by.iharkaratkou.TestServlet.java

public static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {//from www  . java2s.c o  m
            desktop.browse(uri);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java

private static void openBrowser(String url) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {//from  w w  w.  j  a va  2 s .co  m
            desktop.browse(URI.create(url));
        } catch (Exception e) {
            log.error("Problem opening browser", e);
        }
    }
}

From source file:context.ui.misc.FileHandler.java

/**
 *
 * @param url/*w  w  w.  j  av  a 2  s.co m*/
 */
public static void openWebpage(String url) {
    try {
        URI uri = new URI(url);
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            desktop.browse(uri);
        }
    } catch (URISyntaxException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.yccheok.jstock.gui.CompanyNews.java

static void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {/*w  ww .  ja  v a  2  s.c  o  m*/
            desktop.browse(uri);
        } catch (Exception e) {
            log.error(null, e);
        }
    }
}

From source file:com.google.oacurl.Login.java

private static void launchBrowser(LoginOptions options, String authorizationUrl) {
    logger.log(Level.INFO, "Redirecting to URL: " + authorizationUrl);

    boolean browsed = false;
    if (options.getBrowser() == null) {
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Action.BROWSE)) {
                try {
                    desktop.browse(URI.create(authorizationUrl));
                    browsed = true;//from www . j  a v a2s . c  o m
                } catch (IOException e) {
                    // In some situations "BROWSE" appears supported but throws an
                    // exception.
                    logger.log(Level.WARNING, "Error opening browser for Desktop#browse(String)",
                            options.isVerbose() ? e : null);
                }
            } else {
                logger.log(Level.WARNING, "java.awt.Desktop BROWSE action not supported.");
            }
        } else {
            logger.log(Level.WARNING, "java.awt.Desktop not supported. You should use Java 1.6.");
        }
    }

    if (!browsed) {
        String browser = options.getBrowser();
        if (browser == null) {
            browser = "google-chrome";
        }

        try {
            Runtime.getRuntime().exec(new String[] { browser, authorizationUrl });
        } catch (IOException e) {
            logger.log(Level.SEVERE,
                    "Error running browser: " + browser + ". "
                            + "Specify a browser with --browser or use --nobrowser to print URL.",
                    options.isVerbose() ? e : null);
            System.exit(-1);
        }
    }
}