Generated on Fri Oct 6 16:26:43 2006 for Gecode/J by doxygen 1.4.7

BareBonesBrowserLaunch.java

Go to the documentation of this file.
00001 package org.gecode.explorer.swing;
00003 //  Bare Bones Browser Launch                          //
00004 //  Version 1.5                                        //
00005 //  December 10, 2005                                  //
00006 //  Supports: Mac OS X, GNU/Linux, Unix, Windows XP    //
00007 //  Example Usage:                                     //
00008 //     String url = "http://www.centerkey.com/";       //
00009 //     BareBonesBrowserLaunch.openURL(url);            //
00010 //  Public Domain Software -- Free to Use as You Like  //
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 { //assume Unix or Linux
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    }