Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.utils.BrowserLaunch.java

Here you can find all the information about the file org.dgpf.gui.utils.BrowserLaunch.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Mirko Dietrich
 * 
 * E-Mail           : mirkodietrich@hrz.uni-kassel.de
 * Creation Date    : Jul 20, 2006 11:58:56 AM
 * Original Filename: org.dgpf.gui.DGPFBrowserLaunch.java
 * Version          : 1.0
 * Last modification: Jul 20, 2006
 * Last modified by : Mirko Dietrich
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */


package org.dgpf.gui.utils;

import java.lang.reflect.Method;

import javax.swing.JOptionPane;


/**
 * Launch a browser and open an URL. This class is intended to work with
 * the following operating systems:
 * <ul>
 * <li>Mac OS X</li>
 * <li>Microsoft Windows</li>
 * <li>GNU/Linux</li>
 * <li>other Unix flavors</li>
 * </ul>
 * 
 * @author Mirko Dietrich
 */

public class BrowserLaunch
  {
  /**
   * Browsers to try on GNU/Linux or other unices.
   */

  private static final String[] BROWSERS = { "firefox""mozilla",
      "opera""konqueror""epiphany""netscape" };

  /**
   * Open the specified URL in a browser.
   * 
   * @param p_url
   *          to open.
   */

  public static void openURL(String p_url)
    {
    String l_osName = System.getProperty("os.name");
    try
      {
      if(l_osName.startsWith("Mac OS"))
        {
        Class l_fileMgr = Class.forName("com.apple.eio.FileManager");
        Method l_openURL = l_fileMgr.getDeclaredMethod("openURL",
            new Class[] { String.class });
        l_openURL.invoke(null, new Object[] { p_url });
        }
      else
        if(l_osName.startsWith("Windows"))
          Runtime.getRuntime().exec(
              "rundll32 url.dll,FileProtocolHandler " + p_url);
        else
          { // assume Unix or Linux
          String l_browser = null;
          for(int count = 0; count < BROWSERS.length && l_browser == null; count++)
            if(Runtime.getRuntime().exec(
                new String[] { "which", BROWSERS[count] }).waitFor() == 0)
              l_browser = BROWSERS[count];
          if(l_browser == null){
            throw new Exception(LanguageSwitcher
                .getString("msgb_no_browser_found"));
          }
          Runtime.getRuntime().exec(new String[] { l_browser, p_url });
          }
      }
    catch(Exception e)
      {
      JOptionPane.showMessageDialog(null, e.getLocalizedMessage());
      }
    }
  }

File Information:

file name:BrowserLaunch.java
package:org.dgpf.gui.utils
qualified name:org.dgpf.gui.utils.BrowserLaunch.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gui/utils/BrowserLaunch.java
size:2.979 KB (3051 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-09-24 23:47:04 GMT+0000
last access: 2017-11-23 05:17:55 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-23 05:17:55 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo