Example usage for java.awt Desktop browse

List of usage examples for java.awt Desktop browse

Introduction

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

Prototype

public void browse(URI uri) throws IOException 

Source Link

Document

Launches the default browser to display a URI .

Usage

From source file:de.ks.text.AsciiDocEditor.java

@FXML
void showHelp() {
    String title = Localized.get("help");
    title = StringUtils.remove(title, "_");

    new Thread(() -> {
        Desktop desktop = Desktop.getDesktop();
        URI uri = URI.create("http://powerman.name/doc/asciidoc");
        try {//w  w w  . j a  v  a  2  s.  co  m
            desktop.browse(uri);
        } catch (IOException e) {
            log.error("Could not browse {}", uri, e);
        }
    }).start();
}

From source file:com.k42b3.neodym.oauth.Oauth.java

public boolean authorizeToken() throws Exception {
    String url;//from ww  w  .  j a va 2 s  . c  o m

    if (this.provider.getAuthorizationUrl().indexOf('?') == -1) {
        url = this.provider.getAuthorizationUrl() + "?oauth_token=" + this.token;
    } else {
        url = this.provider.getAuthorizationUrl() + "&oauth_token=" + this.token;
    }

    URI authUrl = new URI(url);

    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();

        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            desktop.browse(authUrl);
        } else {
            JOptionPane.showMessageDialog(null, "Visit the following URL: " + authUrl);
        }
    } else {
        JOptionPane.showMessageDialog(null, "Visit the following URL: " + authUrl);
    }

    verificationCode = JOptionPane.showInputDialog("Please enter the verification Code");

    return true;
}

From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java

@FXML
private void clickGithubMenuItem(ActionEvent event) {
    final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;

    try {/*from  w ww  .j a v  a  2  s  .  co m*/
        URI uri = new URI("https://github.com/CIRDLES/Ambapo");
        Desktop dt = Desktop.getDesktop();
        dt.browse(uri);
    } catch (IOException | URISyntaxException ex) {
    }
}

From source file:de.evaluationtool.gui.EvaluationFrameActionListener.java

private void browse(String url) throws URISyntaxException, IOException {
    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
    java.net.URI uri = null;/*from ww w. java2s . co  m*/
    uri = new java.net.URI(url);
    desktop.browse(uri);
}

From source file:org.domainmath.gui.FileTreePanel.java

/**
 * Opening selected contents using external application.
 * @param file /*from ww  w .  ja v  a 2  s .c  o  m*/
 */
private void openOutSide(File file) {
    try {
        URI uri = Paths.get(file.getAbsolutePath()).toUri();
        Desktop desktop = Desktop.getDesktop();
        desktop.browse(uri);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.fratello.longevity.smooth.AppGUI.java

private void openWebPage(String urlName) {
    try {/*from w  w  w .jav  a  2  s  . c  o m*/
        URL u = new URL(urlName);
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE))
            desktop.browse(u.toURI());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e2) {
        e2.printStackTrace();
    }
}

From source file:org.exist.launcher.Launcher.java

protected void eXide(Desktop desktop) {
    utilityPanel.setStatus("Opening dashboard in browser ...");
    final int port = jetty.isPresent() ? jetty.get().getPrimaryPort() : 8080;
    try {//from w ww .  java2 s.co m
        final URI url = new URI("http://localhost:" + port + "/exist/apps/eXide/");
        desktop.browse(url);
    } catch (final URISyntaxException e) {
        if (isSystemTraySupported()) {
            trayIcon.displayMessage(null, "Failed to open URL", TrayIcon.MessageType.ERROR);
        }
        utilityPanel.setStatus("Unable to launch browser");
    } catch (final IOException e) {
        if (isSystemTraySupported()) {
            trayIcon.displayMessage(null, "Failed to open URL", TrayIcon.MessageType.ERROR);
        }
        utilityPanel.setStatus("Unable to launch browser");
    }
}

From source file:org.exist.launcher.Launcher.java

protected void dashboard(Desktop desktop) {
    utilityPanel.setStatus("Opening dashboard in browser ...");
    final int port = jetty.isPresent() ? jetty.get().getPrimaryPort() : 8080;
    try {/*ww w  .j  a  v a  2s .  c  o m*/
        final URI url = new URI("http://localhost:" + port + "/exist/apps/dashboard/");
        desktop.browse(url);
    } catch (final URISyntaxException e) {
        if (isSystemTraySupported()) {
            trayIcon.displayMessage(null, "Failed to open URL", TrayIcon.MessageType.ERROR);
        }
        utilityPanel.setStatus("Unable to launch browser");
    } catch (final IOException e) {
        if (isSystemTraySupported()) {
            trayIcon.displayMessage(null, "Failed to open URL", TrayIcon.MessageType.ERROR);
        }
        utilityPanel.setStatus("Unable to launch browser");
    }
}

From source file:org.exist.launcher.Launcher.java

protected void monex(Desktop desktop) {
    utilityPanel.setStatus("Opening Monitoring and Profiling in browser ...");
    final int port = jetty.isPresent() ? jetty.get().getPrimaryPort() : 8080;
    try {/*  ww  w.  j ava 2  s.  c o  m*/
        final URI url = new URI("http://localhost:" + port + "/exist/apps/monex/");
        desktop.browse(url);
    } catch (final URISyntaxException e) {
        if (isSystemTraySupported()) {
            trayIcon.displayMessage(null, "Failed to open URL", TrayIcon.MessageType.ERROR);
        }
        utilityPanel.setStatus("Unable to launch browser");
    } catch (final IOException e) {
        if (isSystemTraySupported()) {
            trayIcon.displayMessage(null, "Failed to open URL", TrayIcon.MessageType.ERROR);
        }
        utilityPanel.setStatus("Unable to launch browser");
    }
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

/**
 * Displays the file specified by the supplied URL. If the URL specifies a
 * remote file, the file will be downloaded first. The thread will block
 * while the download occurs.//from  ww  w  . j  a v a  2  s  . co  m
 * 
 * @param fileURL
 *            A URL pointing to the file of interest
 * @param description
 *            A description of the file
 * @param desktop
 *            A reference to the AWT Desktop
 * @throws Exception
 *             If an unrecoverable error occurred while downloading or
 *             displaying the file.
 */
public static void displayFileFromURL(URL fileURL, String description, Desktop desktop) throws Exception {
    String fileName = fileURL.getFile();

    if (fileName.toLowerCase().endsWith(".rtf")) {
        File file = Utils.saveURLToTempFile(fileURL, "Intkey", 30000);
        String rtfSource = FileUtils.readFileToString(file, "cp1252"); // RTF
                                                                       // must
                                                                       // always
                                                                       // be
                                                                       // read
                                                                       // as
                                                                       // windows
                                                                       // cp1252
                                                                       // encoding
        RtfReportDisplayDialog dlg = new RtfReportDisplayDialog(getMainFrame(), new SimpleRtfEditorKit(null),
                rtfSource, description);
        ((SingleFrameApplication) Application.getInstance()).show(dlg);
    } else if (fileName.toLowerCase().endsWith(".html")) {
        if (desktop == null || !desktop.isSupported(Desktop.Action.BROWSE)) {
            throw new UnsupportedOperationException("Desktop is null or browse not supported");
        }
        desktop.browse(fileURL.toURI());
    } else if (fileName.toLowerCase().endsWith(".ink")) {
        File file = Utils.saveURLToTempFile(fileURL, "Intkey", 30000);
        Utils.launchIntkeyInSeparateProcess(System.getProperty("user.dir"), file.getAbsolutePath());
    } else if (fileName.toLowerCase().endsWith(".wav")) {
        AudioPlayer.playClip(fileURL);
    } else {
        // Open a http link that does not point to a .rtf, .ink or .wav in
        // the browser
        if (fileURL.getProtocol().equalsIgnoreCase("http")) {
            if (desktop == null || !desktop.isSupported(Desktop.Action.BROWSE)) {
                throw new UnsupportedOperationException("Desktop is null or browse not supported");
            }
            desktop.browse(fileURL.toURI());
        } else {
            if (desktop == null || !desktop.isSupported(Desktop.Action.OPEN)) {
                throw new UnsupportedOperationException("Desktop is null or open not supported");
            }
            File file = Utils.saveURLToTempFile(fileURL, "Intkey", 30000);
            desktop.open(file);
        }
    }
}