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:com.diversityarrays.update.UpdateDialog.java

private void openWebpage(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {//from  ww w .ja va2 s .c om
            desktop.browse(uri);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(new JFrame(), e.getMessage(),
                    Msg.ERRTITLE_BROWSER_OPEN_ERROR(getTitle()), JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }

    }
}

From source file:de.pixida.logtest.designer.MainWindow.java

private void createAndAppendHelpMenuItems(final Menu help) {
    final MenuItem visitDocumentation = new MenuItem("Visit Online Documentation");
    visitDocumentation.setGraphic(Icons.getIconGraphics("help"));
    visitDocumentation.setOnAction(event -> {
        Exception ex = null;//from  w w w  .  j  ava 2s.  c o  m
        final String url = "https://github.com/Pixida/logtest/wiki";
        final Desktop desktop = java.awt.Desktop.getDesktop();
        if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
            try {
                desktop.browse(new URI(url));
            } catch (final Exception e) {
                ex = e;
            }
        } else {
            ex = new Exception("Browsing not supported.");
        }
        if (ex != null) {
            ExceptionDialog.showFatalException("Failed to open browser", "Visit us at " + url, ex);
        }
    });

    final MenuItem about = new MenuItem("About " + APP_TITLE);
    about.setGraphic(Icons.getIconGraphics(APP_ICON));
    about.setOnAction(event -> {
        final Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.initStyle(StageStyle.UTILITY);
        alert.setTitle(about.getText());
        alert.setHeaderText(APP_TITLE);
        alert.setContentText("Copyright (C) " + Calendar.getInstance().get(Calendar.YEAR) + " Pixida GmbH\n"
                + "\n" + "This application includes FAMFAMFAM icons (http://www.famfamfam.com).");
        alert.showAndWait();
    });

    help.getItems().addAll(visitDocumentation, about);
}

From source file:fr.vdl.android.holocolors.HoloColorsDialog.java

private void openWebpage(String url) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {/*from w  ww.j  a  v  a2s.co  m*/
            desktop.browse(new URL(url).toURI());
        } catch (Exception e) {
            // no matter, nothing to do
            e.printStackTrace();
        }
    }
}

From source file:dr.app.bss.Utils.java

public static boolean isBrowsingSupported() {
    if (!Desktop.isDesktopSupported()) {
        return false;
    }//ww  w  .j a  v  a 2  s  .  c  o  m
    boolean result = false;
    Desktop desktop = java.awt.Desktop.getDesktop();
    if (desktop.isSupported(Desktop.Action.BROWSE)) {
        result = true;
    }
    return result;

}

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

public boolean authorizeToken() throws Exception {
    String url;//from  www .  j  av a 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 clickOpenTemplateLatLongToUTM(ActionEvent event) throws IOException {
    final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    File file = new File(getClass().getResource("latLongToUTMTemplate.csv").getFile());

    if (desktop != null && desktop.isSupported(Desktop.Action.OPEN)) {
        desktop.open(file);/*w w  w  . j a va 2 s  .  c o  m*/
    } else {
        throw new UnsupportedOperationException("Open action not supported");
    }
}

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

@FXML
private void clickOpenTemplateUTMToLatLong(ActionEvent event) throws IOException {
    final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    File file = new File(getClass().getResource("utmToLatLongTemplate.csv").getFile());

    if (desktop != null && desktop.isSupported(Desktop.Action.OPEN)) {
        desktop.open(file);//from   ww w . jav  a2s.  c  o  m
    } else {
        throw new UnsupportedOperationException("Open action not supported");
    }
}

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

@FXML
private void clickOpenTemplateLatLongToLatLong(ActionEvent event) throws IOException {
    final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    File file = new File(getClass().getResource("latLongToLatLongTemplate.csv").getFile());

    if (desktop != null && desktop.isSupported(Desktop.Action.OPEN)) {
        desktop.open(file);// w  w  w .  ja  va 2  s . co m
    } else {
        throw new UnsupportedOperationException("Open action not supported");
    }
}

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 w  w  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);
        }
    }
}

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

private PopupMenu createMenu() {

    final PopupMenu popup = new PopupMenu();
    startItem = new MenuItem("Start server");
    popup.add(startItem);/*from w w w . j a  v a  2s .c  o  m*/
    startItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.ifPresent(server -> {
                if (server.isStarted()) {
                    showTrayMessage("Server already started", TrayIcon.MessageType.WARNING);
                } else {
                    server.run(new String[] { jettyConfig.toAbsolutePath().toString() }, null);
                    if (server.isStarted()) {
                        showTrayMessage("eXist-db server running on port " + server.getPrimaryPort(),
                                TrayIcon.MessageType.INFO);
                    }
                }
                setServiceState();
            });
        } else if (runningAsService.isPresent()) {
            showTrayMessage("Starting the eXistdb service. Please wait...", TrayIcon.MessageType.INFO);
            if (runningAsService.get().start()) {
                showTrayMessage("eXistdb service started", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Starting eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    stopItem = new MenuItem("Stop server");
    popup.add(stopItem);
    stopItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.get().shutdown();
            setServiceState();
            showTrayMessage("eXist-db stopped", TrayIcon.MessageType.INFO);
        } else if (runningAsService.isPresent()) {
            if (runningAsService.get().stop()) {
                showTrayMessage("eXistdb service stopped", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Stopping eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    popup.addSeparator();
    final MenuItem configItem = new MenuItem("System Configuration");
    popup.add(configItem);
    configItem.addActionListener(e -> EventQueue.invokeLater(() -> {
        configDialog.open(false);
        configDialog.toFront();
        configDialog.repaint();
        configDialog.requestFocus();
    }));

    if (SystemUtils.IS_OS_WINDOWS) {
        canUseServices = true;
    } else {
        isRoot((root) -> canUseServices = root);
    }

    final String requiresRootMsg;
    if (canUseServices) {
        requiresRootMsg = "";
    } else {
        requiresRootMsg = " (requires root)";
    }

    installServiceItem = new MenuItem("Install as service" + requiresRootMsg);

    popup.add(installServiceItem);
    installServiceItem.setEnabled(canUseServices);
    installServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::installAsService));

    uninstallServiceItem = new MenuItem("Uninstall service" + requiresRootMsg);
    popup.add(uninstallServiceItem);
    uninstallServiceItem.setEnabled(canUseServices);
    uninstallServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::uninstallService));

    if (SystemUtils.IS_OS_WINDOWS) {
        showServices = new MenuItem("Show services console");
        popup.add(showServices);
        showServices.addActionListener(e -> SwingUtilities.invokeLater(this::showServicesConsole));
    }
    popup.addSeparator();

    final MenuItem toolbar = new MenuItem("Show tool window");
    popup.add(toolbar);
    toolbar.addActionListener(actionEvent -> EventQueue.invokeLater(() -> {
        utilityPanel.toFront();
        utilityPanel.setVisible(true);
    }));

    MenuItem item;

    if (Desktop.isDesktopSupported()) {
        popup.addSeparator();
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            dashboardItem = new MenuItem("Open Dashboard");
            popup.add(dashboardItem);
            dashboardItem.addActionListener(actionEvent -> dashboard(desktop));
            eXideItem = new MenuItem("Open eXide");
            popup.add(eXideItem);
            eXideItem.addActionListener(actionEvent -> eXide(desktop));
            item = new MenuItem("Open Java Admin Client");
            popup.add(item);
            item.addActionListener(actionEvent -> client());
            monexItem = new MenuItem("Open Monitoring and Profiling");
            popup.add(monexItem);
            monexItem.addActionListener(actionEvent -> monex(desktop));
        }
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            popup.addSeparator();
            item = new MenuItem("Open exist.log");
            popup.add(item);
            item.addActionListener(new LogActionListener());
        }

        popup.addSeparator();
        quitItem = new MenuItem("Quit (and stop server)");
        popup.add(quitItem);
        quitItem.addActionListener(actionEvent -> shutdown(false));

        setServiceState();
    }
    return popup;
}