Search in sources :

Example 6 with Desktop

use of java.awt.Desktop in project libgdx by libgdx.

the class JglfwNet method openURI.

public boolean openURI(String uri) {
    boolean result = false;
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(new URI(uri));
                result = true;
            } catch (Exception e) {
                Gdx.app.error("JglfwNet", "Unable to open URI:" + uri, e);
            }
        }
    }
    return result;
}
Also used : Desktop(java.awt.Desktop) URI(java.net.URI) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 7 with Desktop

use of java.awt.Desktop in project javatari by ppeccin.

the class JComboBoxNim method officialWebPageAction.

private void officialWebPageAction() {
    if (!Desktop.isDesktopSupported())
        return;
    try {
        Desktop desktop = Desktop.getDesktop();
        if (!desktop.isSupported(Desktop.Action.BROWSE))
            return;
        closeAction();
        desktop.browse(new URI(Parameters.OFFICIAL_WEBSITE));
    } catch (Exception e) {
    // Give up
    }
}
Also used : Desktop(java.awt.Desktop) URI(java.net.URI) ROMFormatUnsupportedException(org.javatari.atari.cartridge.ROMFormatUnsupportedException) IOException(java.io.IOException)

Example 8 with Desktop

use of java.awt.Desktop in project javatari by ppeccin.

the class JComboBoxNim method twitterPageAction.

private void twitterPageAction() {
    if (!Desktop.isDesktopSupported())
        return;
    try {
        Desktop desktop = Desktop.getDesktop();
        if (!desktop.isSupported(Desktop.Action.BROWSE))
            return;
        closeAction();
        desktop.browse(new URI(Parameters.TWITTER_WEBPAGE));
    } catch (Exception e) {
    // Give up
    }
}
Also used : Desktop(java.awt.Desktop) URI(java.net.URI) ROMFormatUnsupportedException(org.javatari.atari.cartridge.ROMFormatUnsupportedException) IOException(java.io.IOException)

Example 9 with Desktop

use of java.awt.Desktop in project jadx by skylot.

the class Link method browse.

private void browse() {
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Action.BROWSE)) {
            try {
                desktop.browse(new java.net.URI(url));
                return;
            } catch (IOException e) {
                LOG.debug("Open url error", e);
            } catch (URISyntaxException e) {
                LOG.debug("Open url error", e);
            }
        }
    }
    try {
        String os = System.getProperty("os.name").toLowerCase();
        if (os.contains("win")) {
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
            return;
        }
        if (os.contains("mac")) {
            Runtime.getRuntime().exec("open " + url);
            return;
        }
        Map<String, String> env = System.getenv();
        if (env.get("BROWSER") != null) {
            Runtime.getRuntime().exec(env.get("BROWSER") + " " + url);
            return;
        }
    } catch (Exception e) {
        LOG.debug("Open url error", e);
    }
    showUrlDialog();
}
Also used : Desktop(java.awt.Desktop) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 10 with Desktop

use of java.awt.Desktop in project pcgen by PCGen.

the class JIcon method launchFile.

/**
	 *  Launches a file into the appropriate program for the OS we are running on
	 */
protected void launchFile() {
    if (plugin.isRecognizedFileType(launch)) {
        plugin.loadRecognizedFileType(launch);
    } else {
        boolean opened = false;
        // Use desktop if available
        if (Desktop.isDesktopSupported()) {
            Desktop d = Desktop.getDesktop();
            if (d.isSupported(Desktop.Action.OPEN)) {
                try {
                    d.open(launch);
                    opened = true;
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        if (!opened) {
            // Unix
            if (SystemUtils.IS_OS_UNIX) {
                String openCmd;
                if (SystemUtils.IS_OS_MAC_OSX) {
                    // From the command line, the open command acts as if the argument was double clicked from the finder
                    // (see: man open)
                    openCmd = "/usr/bin/open";
                } else {
                    // Tries freedesktop.org xdg-open. Quite often installed on Linux/BSD
                    openCmd = "xdg-open";
                }
                String filePath = launch.getAbsolutePath();
                String[] args = { openCmd, filePath };
                Logging.debugPrintLocalised("Runtime.getRuntime().exec: [{0}] [{1}]", args[0], args[1]);
                try {
                    Runtime.getRuntime().exec(args);
                } catch (IOException e) {
                    Logging.errorPrint(e.getMessage(), e);
                }
            }
            //Windows
            if (SystemUtils.IS_OS_WINDOWS) {
                try {
                    String start = (" rundll32 url.dll,FileProtocolHandler file://" + launch.getAbsoluteFile());
                    Runtime.getRuntime().exec(start);
                } catch (Exception e) {
                    Logging.errorPrint(e.getMessage(), e);
                }
            }
        }
    }
}
Also used : Desktop(java.awt.Desktop) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

Desktop (java.awt.Desktop)13 IOException (java.io.IOException)10 URI (java.net.URI)6 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 ROMFormatUnsupportedException (org.javatari.atari.cartridge.ROMFormatUnsupportedException)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 FileNotFoundException (java.io.FileNotFoundException)1 StringWriter (java.io.StringWriter)1 SocketException (java.net.SocketException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 BadLocationException (javax.swing.text.BadLocationException)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1