Example usage for java.awt Desktop getDesktop

List of usage examples for java.awt Desktop getDesktop

Introduction

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

Prototype

public static synchronized Desktop getDesktop() 

Source Link

Document

Returns the Desktop instance of the current desktop context.

Usage

From source file:ca.sfu.federation.action.ShowHelpWebSiteAction.java

/**
 * Handle action performed event.//from   www  .  j av a  2  s  .  c om
 * @param ae Event
 */
public void actionPerformed(ActionEvent ae) {
    try {
        URI uri = new URI(ApplicationContext.PROJECT_HELP_WEBSITE_URL);
        // open the default web browser for the HTML page
        logger.log(Level.INFO, "Opening desktop browser to {0}", uri.toString());
        Desktop.getDesktop().browse(uri);
    } catch (Exception ex) {
        String stack = ExceptionUtils.getFullStackTrace(ex);
        logger.log(Level.WARNING, "Could not open browser for help web site {0}\n\n{1}",
                new Object[] { ApplicationContext.PROJECT_HELP_WEBSITE_URL, stack });
    }
}

From source file:groovesquid.UpdateCheckThread.java

@Override
public void run() {
    UpdateCheck updateCheck = gson.fromJson(getFile(updateFile), UpdateCheck.class);
    if (updateCheck.getClients() != null)
        Grooveshark.setClients(updateCheck.getClients());

    if (Utils.compareVersions(updateCheck.getVersion(), Main.getVersion()) > 0) {
        if (JOptionPane.showConfirmDialog(null,
                "New version (v" + updateCheck.getVersion()
                        + ") is available! Do you want to download the new version (recommended)?",
                "New version", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
            try {
                Desktop.getDesktop().browse(java.net.URI.create("http://groovesquid.com/#download"));
            } catch (IOException ex) {
                log.log(Level.SEVERE, null, ex);
            }//w w  w.ja  v  a2 s  .  c  o m
        }
    }
}

From source file:au.com.jwatmuff.eventmanager.gui.main.AboutDialog.java

private void open(String filename) {
    try {/*from  w  w  w. j a  v a2s.c om*/
        Desktop.getDesktop().open(new File(filename));
    } catch (IOException e) {
        GUIUtils.displayError(this, "Failed to open file " + filename + ": " + e.getMessage());
    }
}

From source file:com.clank.launcher.swing.SwingHelper.java

/**
 * Opens a system web browser for the given URL.
 *
 * @param url the URL/*w  w w. jav  a2s. c om*/
 * @param parentComponent the component from which to show any errors
 */
public static void openURL(URL url, Component parentComponent) {
    try {
        Desktop.getDesktop().browse(url.toURI());
    } catch (IOException e) {
        showErrorDialog(parentComponent, _("errors.openUrlError", url.toString()), _("errorTitle"));
    } catch (URISyntaxException e) {
    }
}

From source file:net.brtly.monkeyboard.Configuration.java

public boolean openPreferencesFile() {
    Desktop dt = Desktop.getDesktop();
    try {//from  ww w. j a  v  a2s  .  c o m
        dt.open(getPreferencesFile());
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:org.openpythia.dbconnection.MissingJDBCDriverController.java

private void prepareTextArea() {
    view.getEditorPaneMissingJDBCDriver().setContentType("text/html");

    String missingJDBCdriverText = "";

    try {//from w w  w.  j  av  a  2  s .co m
        InputStream inputStream = this.getClass().getResourceAsStream(MISSING_JDBCDRIVER_HTML);
        missingJDBCdriverText = IOUtils.toString(inputStream);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

    view.getEditorPaneMissingJDBCDriver().setText(missingJDBCdriverText);

    view.getEditorPaneMissingJDBCDriver().addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop.getDesktop().browse(evt.getURL().toURI());
                } catch (Exception e) {
                    // If we can't open the URL - for what reason
                    // ever - we ignore it
                }
            }
        }
    });
}

From source file:pl.otros.logview.gui.actions.ChekForNewVersionOnStartupAction.java

@Override
protected void handleNewVersionIsAvailable(final String current, String running) {
    LOGGER.info(String.format("Running version is %s, current is %s", running, current));
    DataConfiguration configuration = getOtrosApplication().getConfiguration();
    String doNotNotifyThisVersion = configuration
            .getString(ConfKeys.VERSION_CHECK_SKIP_NOTIFICATION_FOR_VERSION, "2000-01-01");
    if (current != null && doNotNotifyThisVersion.compareTo(current) > 0) {
        return;/*  w ww  .  j a va2s .  co  m*/
    }
    JPanel message = new JPanel(new GridLayout(4, 1, 4, 4));
    message.add(new JLabel(String.format("New version %s is available", current)));
    JButton button = new JButton("Open download page");
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop()
                        .browse(new URI("https://sourceforge.net/projects/otroslogviewer/files/?source=app"));
            } catch (Exception e1) {
                String msg = "Can't open browser with download page: " + e1.getMessage();
                LOGGER.severe(msg);
                getOtrosApplication().getStatusObserver().updateStatus(msg, StatusObserver.LEVEL_ERROR);
            }
        }
    });
    message.add(button);

    final JCheckBox chboxDoNotNotifyMeAboutVersion = new JCheckBox("Do not notify me about version " + current);
    message.add(chboxDoNotNotifyMeAboutVersion);
    final JCheckBox chboxDoNotCheckVersionOnStart = new JCheckBox("Do not check for new version on startup");
    message.add(chboxDoNotCheckVersionOnStart);

    final JDialog dialog = new JDialog((Frame) null, "New version is available");
    dialog.getContentPane().setLayout(new BorderLayout(5, 5));
    dialog.getContentPane().add(message);

    JPanel jp = new JPanel(new FlowLayout(FlowLayout.CENTER));
    jp.add(new JButton(new AbstractAction("Ok") {

        /**
         * 
         */
        private static final long serialVersionUID = 7930093775785431184L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
            dialog.dispose();
            if (chboxDoNotNotifyMeAboutVersion.isSelected()) {
                LOGGER.fine("Disabling new version notificiation for " + current);
                getOtrosApplication().getConfiguration()
                        .setProperty(ConfKeys.VERSION_CHECK_SKIP_NOTIFICATION_FOR_VERSION, current);
            }
            if (chboxDoNotCheckVersionOnStart.isSelected()) {
                LOGGER.fine("Disabling new version check on start");
                getOtrosApplication().getConfiguration().setProperty(ConfKeys.VERSION_CHECK_ON_STARTUP, false);
            }
        }
    }));
    dialog.getContentPane().add(jp, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setResizable(false);
    GuiUtils.centerOnScreen(dialog);
    dialog.setVisible(true);

}

From source file:ca.osmcanada.osvuploadr.Utils.Helper.java

public static Boolean OpenBrowser(URI uri) {
    try {/*w w  w.  j  ava  2  s .co m*/
        boolean supportsBrowse = true;
        if (!Desktop.isDesktopSupported()) {
            supportsBrowse = false;
            if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                supportsBrowse = false;
            }
        }

        if (supportsBrowse) {
            Desktop.getDesktop().browse(uri);
        } else {
            EnumOS os = getOs();
            if (os.isLinux()) {
                if (runCommand("kde-open", "%s", uri.toString()))
                    return true;
                if (runCommand("gnome-open", "%s", uri.toString()))
                    return true;
                if (runCommand("xdg-open", "%s", uri.toString()))
                    return true;
            }

            if (os.isMac()) {
                if (runCommand("open", "%s", uri.toString()))
                    return true;
            }

            if (os.isWindows()) {
                if (runCommand("explorer.exe", "%s", uri.toString()))
                    return true;
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
    return false;
}

From source file:app.common.X3DViewer.java

/**
 * View an X3D file using an external X3DOM player
 *
 * @param grid/*from   ww w.  j a va2  s .c o m*/
 * @param smoothSteps
 * @param maxDecimateError
 * @throws IOException
 */
public static void viewX3DOM(Grid grid, int smoothSteps, double maxDecimateError) throws IOException {
    // TODO: Make thread safe using tempDir
    String dest = "/tmp/ringpopper/";
    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/ringpopper/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'>");
        GridSaver.writeIsosurfaceMaker(grid, bos, "x3d", smoothSteps, maxDecimateError);

        //            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());
}

From source file:de.micromata.mgc.javafx.SystemService.java

public void openUrlInBrowser(String url) {
    Desktop desktop = null;/*from  ww  w  . j  a  va  2  s .c  o  m*/
    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
    } else {
        GLog.warn(GenomeLogCategory.System, "Launching Browser not supported");
        return;
    }

    if (desktop != null) {
        try {
            desktop.browse(new URI(url));
        } catch (final IOException ex) {
            GLog.error(GenomeLogCategory.System, "Can't launch browser: " + ex.getMessage(),
                    new LogExceptionAttribute(ex));
        } catch (final URISyntaxException ex) {
            GLog.error(GenomeLogCategory.System, "Can't launch browser: " + ex.getMessage(),
                    new LogExceptionAttribute(ex));
        }
    }
}