/* Javier Kohen's Java Framework Classes. Copyright (C) 2001 Javier Kohen <jkohen at tough.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package ar.com.jkohen.applet; import java.applet.*; import java.awt.Image; import java.awt.Toolkit; import java.lang.reflect.*; import java.net.*; import java.text.MessageFormat; import java.util.Enumeration; import java.io.InputStream; import java.io.IOException; import ar.com.jkohen.applet.NewAudioClip; /** * This class implements AppletContext interface in a simple way, suitable to allow Applet instances to run as command-line applications. * * @author <a href="mailto:jkohen@tough.com">Javier Kohen</a> */ public class SimpleAppletContext implements AppletContext { private static String path = null; public Applet getApplet(String name) { return(null); } public Enumeration getApplets() { return(null); } public AudioClip getAudioClip(URL url) { try { return((AudioClip)(new NewAudioClip(url))); } catch (Exception e) {} return(null); } public Image getImage(URL url) { return(Toolkit.getDefaultToolkit().getImage(url)); } public static void setPath(String path) { SimpleAppletContext.path = path; } public void showDocument(URL url) { try { /* A first try on Mac Os 9 */ Class UtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); Method openURL = UtilsClass.getMethod("openURL", new Class[] { String.class }); openURL.invoke(null, new Object[] { url.toString() }); } catch (Exception e1) { try { String cmd = MessageFormat.format(SimpleAppletContext.path, new Object[] { url.toString() }); Process p = Runtime.getRuntime().exec(cmd); } catch (Exception e2) { System.err.println(e2); } } } public void showDocument(URL url, String target) { showDocument(url); } public void showStatus(String status) { } public void setStream(String k, InputStream s) throws IOException { } public InputStream getStream(String k) { return(null); } public java.util.Iterator getStreamKeys() { return(null); } }