/* gcjwebplugin - Webbrowser plugin to execute Java (tm) applets. Copyright (C) 2003 Thomas Fitzsimmons 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 Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package gnu.applet; import java.applet.Applet; import gnu.getopt.Getopt; import gnu.getopt.LongOpt; import gnu.java.awt.EmbeddedWindow; import java.awt.Frame; public class AppletViewer extends Frame { String code; String codebase; String archive; String documentbase; String parameters; int width = 200; int height = 200; int xid; Frame frame; Applet applet; AppletLoader loader = new AppletLoader(); AppletViewer () { } void loadApplet () { if (code != null) loader.setCode (code); if (codebase != null) loader.setCodeBase (codebase); if (archive != null) loader.setArchive (archive); if (documentbase != null) loader.setDocumentBase (documentbase); applet = loader.loadApplet(); applet.init(); } void showApplet () { if (frame != null) { System.out.println ("AppletViewer: showing applet"); loader.setFrame (frame); frame.setSize(width,height); frame.show(); } applet.start(); } void parseArgs (String [] args) { LongOpt[] longOptions = new LongOpt[] { new LongOpt ("code", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("codebase", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("archive", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("documentbase", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("parameters", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("width", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("height", LongOpt.REQUIRED_ARGUMENT, null, 0), new LongOpt ("xid", LongOpt.REQUIRED_ARGUMENT, null, 0), }; int optVal; String arg; int longIndex; Getopt opts = new Getopt("appletviewer", args, "", longOptions); while ((optVal = opts.getopt()) != -1) { if (optVal == 0) { longIndex = opts.getLongind(); switch (longIndex) { case 0: code = opts.getOptarg(); break; case 1: codebase = opts.getOptarg(); break; case 2: archive = opts.getOptarg(); break; case 3: documentbase = opts.getOptarg(); break; case 4: // FIXME: Handle multiple parameters. parameters = opts.getOptarg(); break; case 5: width = Integer.parseInt(opts.getOptarg()); break; case 6: height = Integer.parseInt(opts.getOptarg()); break; case 7: xid = Integer.parseInt(opts.getOptarg()); break; } } } if (xid != 0) { System.out.println ("AppletViewer: plugin mode: xid = " + xid); frame = new EmbeddedWindow (xid); } else { System.out.println ("AppletViewer: standalone mode"); frame = this; } System.out.println ("AppletViewer: code: " + code + "\n" + "codebase: " + codebase + "\n" + "archive: " + archive + "\n" + "documentbase: " + documentbase + "\n" + "parameters: " + parameters + "\n" + "width: " + width + "\n" + "height: " + height + "\n"); } public static void main (String[] args) { AppletViewer viewer = new AppletViewer (); viewer.parseArgs(args); viewer.loadApplet(); viewer.showApplet(); } }