BareBonesBrowserLaunch.java
Go to the documentation of this file.00001 package org.gecode.explorer.swing;
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 import java.lang.reflect.Method;
00014 import javax.swing.JOptionPane;
00015
00016 public class BareBonesBrowserLaunch {
00017
00018 private static final String errMsg = "Error attempting to launch web browser";
00019
00020 public static void openURL(String url) {
00021 String osName = System.getProperty("os.name");
00022 try {
00023 if (osName.startsWith("Mac OS")) {
00024 Class fileMgr = Class.forName("com.apple.eio.FileManager");
00025 Method openURL = fileMgr.getDeclaredMethod("openURL",
00026 new Class[] {String.class});
00027 openURL.invoke(null, new Object[] {url});
00028 }
00029 else if (osName.startsWith("Windows"))
00030 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
00031 else {
00032 String[] browsers = {
00033 "konqueror", "firefox", "opera", "epiphany", "mozilla", "netscape" };
00034 String browser = null;
00035 for (int count = 0; count < browsers.length && browser == null; count++)
00036 if (Runtime.getRuntime().exec(
00037 new String[] {"which", browsers[count]}).waitFor() == 0)
00038 browser = browsers[count];
00039 if (browser == null)
00040 throw new Exception("Could not find web browser");
00041 else
00042 Runtime.getRuntime().exec(new String[] {browser, url});
00043 }
00044 }
00045 catch (Exception e) {
00046 JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage());
00047 }
00048 }
00049
00050 }