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:mesclasses.view.ConfigStockageController.java

private void openDir(String path) {
    try {/*from www  .  j a  v a2  s.  c  o m*/
        Desktop.getDesktop().open(new File(path));
    } catch (IOException ex) {
        LOG.error("Ouverture du rpertoire : " + path, ex);
    }
}

From source file:Main.java

@Override
public void mouseClicked(MouseEvent e) {
    Element h = getHyperlinkElement(e);
    if (h != null) {
        Object attribute = h.getAttributes().getAttribute(HTML.Tag.A);
        if (attribute instanceof AttributeSet) {
            AttributeSet set = (AttributeSet) attribute;
            String href = (String) set.getAttribute(HTML.Attribute.HREF);
            if (href != null) {
                try {
                    Desktop.getDesktop().browse(new URI(href));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }// w ww . j av  a 2  s.c o m
            }
        }
    }
}

From source file:fridgegameinstaller.installation.java

public void preinstall(int ram, boolean shader) {
    System.out.println("Installing...");

    //check Modpack Update
    progmsg.setText("Checking for Modpack Update...");
    if (true) {/*from  w  w w  .  j  a  v a 2  s .  c  om*/
        progmsg.setText("Locating .minecraft...");
        //set .minecraft location
        System.out.println(DEF.sysos);

        if (DEF.sysos.indexOf("win") >= 0) {
            mcloc = System.getenv("appdata") + "/.minecraft";

        }
        if (DEF.sysos.indexOf("mac") >= 0) {
            mcloc = System.getProperty("user.home") + "/Library/Application Support/minecraft";

        }
        if (DEF.sysos.indexOf("nix") >= 0 || DEF.sysos.indexOf("nux") >= 0 || DEF.sysos.indexOf("aix") > 0) {
            mcloc = System.getProperty("user.home") + "/.minecraft";

        }
        if (mcloc == null) {

            mainFrame.errorMsg("No support for this OS.Try to install manually.", "Error");

        }

        //old Modpack version existing?
        if (checkModpackUpdate()) {
            System.out.println("installing..");
            System.out.println(System.getenv("appdata"));

            uninstall();
            install(ram);
            if (shader) {

                installShader();
            }
            prgbar.setValue(100);
            progmsg.setText("100%");
            mainFrame.errorMsg("Installation finished!", "100%");
            mainFrame.setFormToPostInstallation();
            try {
                String url = "http://www.fridgegame.com/credits";
                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().browse(new URI(url));
                } else {
                    Runtime.getRuntime().exec("xdg-open " + url);
                }
            } catch (URISyntaxException | IOException e) {
                e.printStackTrace();
            }

        } else {

        }

    } else {

        mainFrame.errorMsg(
                "The modpack is up to date.If you want to reinstall it to fix errors delete the fridgegame_version.fg file in your .minecraft",
                "Error");
        mainFrame.setFormToPostInstallation();
    }

}

From source file:org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.help.HelpManager.java

public void openInBrowser(URI uri) {
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {//www  . j  a  v a  2 s  . c  o  m
            desktop.browse(uri);
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
    } else {
        System.err.println("Desktop not supported, cannout open browser");
    }
}

From source file:UIController.java

@FXML
void openWebpage() {
    try {//from   w w w. j a  v a2  s  . co m
        Desktop.getDesktop().browse(new URL(urlString).toURI());
    } catch (IOException | URISyntaxException e) {
    }
}

From source file:clienteescritorio.Grafica.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    try {/* w ww.j a  va2 s.c o  m*/
        String directorio = System.getProperty("user.dir") + "/temporal/";
        String imagen = "grafica.png";
        String so = System.getProperty("os.name");
        System.err.println("El sso " + so);
        File f = new File(directorio + imagen);
        ChartUtilities.saveChartAsPNG(f, chart, 600, 400);
        Runtime run = Runtime.getRuntime();
        if (so.equals("Linux"))
            run.exec("eog " + directorio + imagen);
        else {
            Desktop dt = Desktop.getDesktop();
            dt.open(f);
        }
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(rootPane, "No se pudo guardar la grfica :(, Intntelo ms tarde!");
        ex.printStackTrace();
    }

}

From source file:emailplugin.MailCreator.java

private void mail(final Frame parent, final String content, final String title) {
    // Java 6 desktop API
    boolean sent = false;
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        try {//from  w  w  w.  j  a  va 2s. c  o m
            URI uriMailTo = new URI("mailto", "?body=" + content + "&subject=" + title, null);
            desktop.mail(uriMailTo);
            sent = true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    if (sent) {
        return;
    }

    // fall back to non Java 6 code
    try {
        final String mailTo = "mailto:?body=" + encodeString(content) + "&subject=" + encodeString(title);
        String application;
        String execparam;

        if ((OperatingSystem.isMacOs() || OperatingSystem.isWindows())
                && mSettings.getUseDefaultApplication()) {

            if (OperatingSystem.isMacOs()) {
                application = "/usr/bin/open";
                execparam = mailTo;
            } else {
                application = "rundll32.exe";
                execparam = "url.dll,FileProtocolHandler " + mailTo;
            }

        } else if (StringUtils.isBlank(mSettings.getApplication())) {
            if (OperatingSystem.isOther()) {
                if (!showKdeGnomeDialog(parent)) {
                    return;
                }
                application = mSettings.getApplication();
                execparam = getContentParameter(content);
            } else {
                showNotConfiguredCorrectly(parent);
                return;
            }
        } else {
            application = mSettings.getApplication();
            execparam = getContentParameter(content);
        }

        new ExecutionHandler(execparam, application).execute();

        if (mSettings.getShowEmailOpened()) {
            showEMailOpenedDialog(parent);
        }

    } catch (Exception e) {
        e.printStackTrace();
        int ret = ErrorHandler.handle(
                mLocalizer.msg("ErrorWhileStarting", "Error while starting mail application"), e,
                ErrorHandler.SHOW_YES_NO);

        if (ret == ErrorHandler.YES_PRESSED) {
            MainFrame.getInstance().showSettingsDialog(mPlugin);
        }
    }
}

From source file:es.eucm.eadventure.editor.plugin.vignette.ServerProxy.java

public boolean exportAndShowJson(List<VignetteCharacterPreview> vcps, String json) {
    for (VignetteCharacterPreview vcp : vcps) {
        System.err.println("Sending " + vcp.getName());
        if (!sendBytes(vcp.getImageBytes(), "image/png", vcp.getImageName())) {
            return false;
        }/* w  w  w.  j  ava 2 s.  com*/
    }

    if (!sendBytes(json.getBytes(Charset.forName("UTF-8")), "text/json", "json.json")) {
        return false;
    }

    boolean error = false;
    if (Desktop.isDesktopSupported()) {
        try {
            Desktop.getDesktop()
                    .browse(new URI(serviceURL + "/talk.php?" + "m=" + getMac() + "&f=" + userPath));
        } catch (IOException e) {
            error = true;
            e.printStackTrace();
        } catch (URISyntaxException e) {
            error = true;
            e.printStackTrace();
        }
    }
    return error;
}

From source file:Commander.Main.java

private static void runWebsite(String website) {
    try {/* w w w  .  jav  a  2 s.  co  m*/
        Desktop.getDesktop().browse(URI.create(website));
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.github.cmisbox.ui.UI.java

public void addWatch(String path) {
    final MenuItem mi = new MenuItem(path.replaceAll("/", ""));
    mi.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().open(new File(Config.getInstance().getWatchParent(), mi.getLabel()));
            } catch (IOException e) {
                UI.this.log.error(e);
            }//from w w w.j  a v  a 2 s .c  o  m

        }
    });
    this.popup.add(mi);
}