/[gcjwebplugin]/gcjwebplugin/src/gnu/gcjwebplugin/AppletViewer.java
ViewVC logotype

Diff of /gcjwebplugin/src/gnu/gcjwebplugin/AppletViewer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by fitzsim, Thu Nov 6 06:02:12 2003 UTC revision 1.4 by fitzsim, Fri Nov 7 06:18:59 2003 UTC
# Line 41  import gnu.getopt.Getopt; Line 41  import gnu.getopt.Getopt;
41  import gnu.getopt.LongOpt;  import gnu.getopt.LongOpt;
42  import java.io.*;  import java.io.*;
43  import java.applet.Applet;  import java.applet.Applet;
44    import java.awt.BorderLayout;
45  import java.awt.Frame;  import java.awt.Frame;
46  import java.util.Map;  import java.util.Map;
47  import java.util.HashMap;  import java.util.HashMap;
# Line 48  import java.util.List; Line 49  import java.util.List;
49  import java.util.Iterator;  import java.util.Iterator;
50  import java.util.ArrayList;  import java.util.ArrayList;
51  import java.net.URL;  import java.net.URL;
52    import java.net.URLClassLoader;
53    
54  public class AppletViewer extends Frame  public class AppletViewer extends Frame
55  {  {
56    Applet applet;    Applet applet;
57    AppletLoader loader = new AppletLoader();    AppletTag tag;
58      static List appletTags = new ArrayList ();
59    
60    URL documentbaseURL;    public AppletViewer (AppletTag tag) throws IOException
   
   AppletViewer ()  
61    {    {
62    }      super(tag.documentbase.toString());
63    
64        setLayout(new BorderLayout());
65    
66        this.tag = tag;
67    
68        applet = createApplet(this.tag);
69    
70        addNotify();
71    
72        setSize (tag.dimensions.width, tag.dimensions.height);
73    
74        add (applet, BorderLayout.CENTER);
75    
   void loadApplet ()  
   {  
76      applet.init();      applet.init();
77        applet.validate();
78        applet.start();
79    
80        setVisible( true);          
81    }    }
82    
83    public void show ()    public static Applet createApplet(AppletTag tag)
84    {    {
85      System.err.println ("appletviewer: show applet");      Applet applet = null;
86    
87        try
88          {
89            String code = tag.code;
90            if (code == null)
91              {
92                System.out.println("didn't find code tag");
93                System.exit(-1);
94              }
95            URLClassLoader loader;
96    
97            if (tag.archives != null)
98              loader = new URLClassLoader(tag.archives);
99            else
100              loader = new URLClassLoader(new URL [] { tag.prependCodebase ("") });
101    
102            /* Set the contect loader of the current thread to the applet class loader,
103             * to avoid problems between casting classes loaded by separate class loaders.
104             */
105            Thread.currentThread().setContextClassLoader(loader);
106    
107      loader.setFrame (this);          if (code.endsWith( ".class"))
108              {
109                code = code.substring(0, code.length() - 6);
110              }
111    
112      super.show ();          Class c = loader.loadClass(code);
113            applet = (Applet) c.newInstance();
114    
115      applet.start();        }
116        catch (Exception e)
117          {
118            e.printStackTrace();
119          }
120        return applet;
121    }    }
122    
123    public static void main (String[] args)    public static void main (String[] args)
124      throws IOException      throws IOException
125    {    {
     List appletTags = new ArrayList ();  
     URL documentbase = null;  
   
126      LongOpt[] longOptions = new LongOpt[]      LongOpt[] longOptions = new LongOpt[]
127        {        {
128          new LongOpt ("code",         LongOpt.REQUIRED_ARGUMENT, null, 0),          new LongOpt ("code",         LongOpt.REQUIRED_ARGUMENT, null, 0),
# Line 113  public class AppletViewer extends Frame Line 154  public class AppletViewer extends Frame
154          appletTags.addAll (AppletTag.parseAppletTags (args[i]));          appletTags.addAll (AppletTag.parseAppletTags (args[i]));
155        }        }
156    
     System.out.println ("documentbase: " + documentbase);  
157      System.out.println ("parsed applet tags:");      System.out.println ("parsed applet tags:");
158      for (int i = 0; i < appletTags.size(); i++)      for (int i = 0; i < appletTags.size(); i++)
159        {        {
# Line 173  public class AppletViewer extends Frame Line 213  public class AppletViewer extends Frame
213                          "height: " + tag.dimensions.height);                          "height: " + tag.dimensions.height);
214      */      */
215    
216      AppletViewer viewer = new AppletViewer ();      for (int i = 0; i < appletTags.size(); i++)
217          {
218      viewer.loadApplet ();          AppletViewer viewer = new AppletViewer ((AppletTag) appletTags.get (i));
219      viewer.show ();        }
220    }    }
221  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26