Skip to content

Commit

Permalink
Use Java's built-in functions to open browser URL
Browse files Browse the repository at this point in the history
Also update broken links.

Fixes #482.
  • Loading branch information
garfieldnate committed Jul 19, 2024
1 parent 1acb212 commit 6198d85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,16 @@
//Public Domain Software -- Free to Use as You Like //
/////////////////////////////////////////////////////////

import java.lang.reflect.Method;

import java.awt.Desktop;
import java.net.URI;
public class StartBrowser
{

// private static final String errMsg =
// "Error attempting to launch web browser";

public static void openURL(String url) throws Exception
{
String osName = System.getProperty("os.name");

if (osName.startsWith("Mac OS"))
{
Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL",
String.class);
openURL.invoke(null, url);
}
else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " + url);
else
{ // assume Unix or Linux
String[] browsers = { "firefox", "opera", "konqueror", "epiphany",
"mozilla", "netscape" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++)
if (Runtime.getRuntime().exec(
new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count];
if (browser == null)
throw new Exception("Could not find web browser");
else
Runtime.getRuntime().exec(new String[] { browser, url });
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI(url));
} else {
System.err.println("Opening websites URLs is not supported on this platform or machine");
}
}

Expand Down
12 changes: 6 additions & 6 deletions Java/Debugger/src/edu/umich/soar/debugger/menu/HelpMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ public void actionPerformed(ActionEvent e)
}
};

private final AbstractAction m_Wiki = new AbstractAction(
"Soar Wiki (many topics)")
private final AbstractAction m_CLI = new AbstractAction("Soar and Debugger Command Line Help")
{
@Override
public void actionPerformed(ActionEvent e)
{
open("https://github.com/SoarGroup");
open("https://soar.eecs.umich.edu/reference/CommandLineOptionsForDebuggerAndCLI/");
}
};

private final AbstractAction m_CLI = new AbstractAction("Soar Command Line Help")
private final AbstractAction m_Issues = new AbstractAction(
"Create Issue on GitHub")
{
@Override
public void actionPerformed(ActionEvent e)
{
open("http://soar.eecs.umich.edu/articles/articles/general/73-command-line-help");
open("https://github.com/SoarGroup/Soar/issues");
}
};

Expand All @@ -82,8 +82,8 @@ private BaseMenu makeMenu(Menu parent, String title)
BaseMenu menu = new BaseMenu(parent, title);

menu.add(m_Homepage);
menu.add(m_Wiki);
menu.add(m_CLI);
menu.add(m_Issues);
menu.addSeparator();
menu.add(m_About);

Expand Down

0 comments on commit 6198d85

Please sign in to comment.