Package com.sun.j3d.utils.applet

Source Code of com.sun.j3d.utils.applet.JMainFrame

/*     */ package com.sun.j3d.utils.applet;
/*     */
/*     */ import java.applet.Applet;
/*     */ import java.applet.AppletContext;
/*     */ import java.applet.AppletStub;
/*     */ import java.applet.AudioClip;
/*     */ import java.awt.Container;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Image;
/*     */ import java.awt.Label;
/*     */ import java.awt.Toolkit;
/*     */ import java.awt.event.WindowAdapter;
/*     */ import java.awt.event.WindowEvent;
/*     */ import java.awt.image.ImageProducer;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.net.MalformedURLException;
/*     */ import java.net.URL;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Iterator;
/*     */ import java.util.Properties;
/*     */ import java.util.StringTokenizer;
/*     */ import java.util.Vector;
/*     */ import javax.swing.JFrame;
/*     */ import sun.applet.AppletAudioClip;
/*     */
/*     */ public class JMainFrame extends JFrame
/*     */   implements Runnable, AppletStub, AppletContext
/*     */ {
/*  54 */   private String[] args = null;
/*  55 */   private static int instances = 0;
/*     */   private String name;
/*     */   private Applet applet;
/*  58 */   private Label label = null;
/*     */   private Dimension appletSize;
/*     */   private static final String PARAM_PROP_PREFIX = "parameter.";
/*     */
/*     */   public JMainFrame(Applet applet, String[] args, int width, int height)
/*     */   {
/*  64 */     build(applet, args, width, height);
/*     */   }
/*     */   public JMainFrame(Applet applet, String[] args) {
/*  67 */     build(applet, args, -1, -1);
/*     */   }
/*     */
/*     */   public JMainFrame(Applet applet, int width, int height) {
/*  71 */     build(applet, null, width, height);
/*     */   }
/*     */
/*     */   private void build(Applet applet, String[] args, int width, int height) {
/*  75 */     instances += 1;
/*  76 */     this.applet = applet;
/*  77 */     this.args = args;
/*  78 */     applet.setStub(this);
/*  79 */     this.name = applet.getClass().getName();
/*  80 */     setTitle(this.name);
/*     */
/*  83 */     Properties props = System.getProperties();
/*  84 */     props.put("browser", "Acme.MainFrame");
/*  85 */     props.put("browser.version", "11jul96");
/*  86 */     props.put("browser.vendor", "Acme Laboratories");
/*  87 */     props.put("browser.vendor.url", "http://www.acme.com/");
/*     */
/*  90 */     if (args != null) {
/*  91 */       parseArgs(args, props);
/*     */     }
/*     */
/*  95 */     String widthStr = getParameter("width");
/*  96 */     if (widthStr != null)
/*  97 */       width = Integer.parseInt(widthStr);
/*  98 */     String heightStr = getParameter("height");
/*  99 */     if (heightStr != null) {
/* 100 */       height = Integer.parseInt(heightStr);
/*     */     }
/*     */
/* 103 */     if ((width == -1) || (height == -1)) {
/* 104 */       System.err.println("Width and height must be specified.");
/* 105 */       return;
/*     */     }
/*     */
/* 109 */     Container contentPane = getContentPane();
/* 110 */     contentPane.add(applet, "Center");
/*     */
/* 113 */     pack();
/* 114 */     validate();
/* 115 */     this.appletSize = applet.getSize();
/* 116 */     applet.setSize(width, height);
/* 117 */     setVisible(true);
/*     */
/* 122 */     SecurityManager sm = System.getSecurityManager();
/* 123 */     boolean doExit = true;
/* 124 */     if (sm != null) {
/*     */       try {
/* 126 */         sm.checkExit(0);
/*     */       } catch (SecurityException e) {
/* 128 */         doExit = false;
/*     */       }
/*     */     }
/*     */
/* 132 */     boolean _doExit = doExit;
/*     */
/* 135 */     addWindowListener(new WindowAdapter() {
/*     */       private final boolean val$_doExit;
/*     */
/*     */       public void windowClosing(WindowEvent winEvent) {
/* 139 */         if (JMainFrame.this.applet != null) {
/* 140 */           JMainFrame.this.applet.destroy();
/*     */         }
/* 142 */         JMainFrame.this.hide();
/*     */         try {
/* 144 */           JMainFrame.this.dispose();
/*     */         } catch (IllegalStateException e) {
/*     */         }
/* 147 */         if (this.val$_doExit)
/* 148 */           System.exit(0);
/*     */       }
/*     */     });
/* 156 */     new Thread(this).start();
/*     */   }
/*     */
/*     */   private static void parseArgs(String[] args, Properties props)
/*     */   {
/* 163 */     for (int i = 0; i < args.length; i++) {
/* 164 */       String arg = args[i];
/* 165 */       int ind = arg.indexOf('=');
/* 166 */       if (ind == -1)
/* 167 */         props.put("parameter." + arg.toLowerCase(), "");
/*     */       else
/* 169 */         props.put("parameter." + arg.substring(0, ind).toLowerCase(), arg.substring(ind + 1));
/*     */     }
/*     */   }
/*     */
/*     */   public void run()
/*     */   {
/* 179 */     showStatus(this.name + " initializing...");
/* 180 */     this.applet.init();
/* 181 */     validate();
/* 182 */     showStatus(this.name + " starting...");
/* 183 */     this.applet.start();
/* 184 */     validate();
/* 185 */     showStatus(this.name + " running...");
/*     */   }
/*     */
/*     */   public boolean isActive()
/*     */   {
/* 191 */     return true;
/*     */   }
/*     */
/*     */   public URL getDocumentBase()
/*     */   {
/* 196 */     String dir = System.getProperty("user.dir");
/* 197 */     String urlDir = dir.replace(File.separatorChar, '/');
/*     */     try {
/* 199 */       return new URL("file:" + urlDir + "/");
/*     */     } catch (MalformedURLException e) {
/*     */     }
/* 202 */     return null;
/*     */   }
/*     */
/*     */   public URL getCodeBase()
/*     */   {
/* 210 */     String path = System.getProperty("java.class.path");
/* 211 */     Enumeration st = new StringTokenizer(path, ":");
/* 212 */     while (st.hasMoreElements()) {
/* 213 */       String dir = (String)st.nextElement();
/* 214 */       String filename = dir + File.separatorChar + this.name + ".class";
/* 215 */       File file = new File(filename);
/* 216 */       if (file.exists()) {
/* 217 */         String urlDir = dir.replace(File.separatorChar, '/');
/*     */         try {
/* 219 */           return new URL("file:" + urlDir + "/");
/*     */         }
/*     */         catch (MalformedURLException e) {
/* 222 */           return null;
/*     */         }
/*     */       }
/*     */     }
/* 226 */     return null;
/*     */   }
/*     */
/*     */   public String getParameter(String name)
/*     */   {
/* 231 */     return System.getProperty("parameter." + name.toLowerCase());
/*     */   }
/*     */
/*     */   public void appletResize(int width, int height)
/*     */   {
/* 237 */     Dimension frameSize = getSize();
/* 238 */     frameSize.width += width - this.appletSize.width;
/* 239 */     frameSize.height += height - this.appletSize.height;
/* 240 */     setSize(frameSize);
/* 241 */     this.appletSize = this.applet.getSize();
/*     */   }
/*     */
/*     */   public AppletContext getAppletContext() {
/* 245 */     return this;
/*     */   }
/*     */
/*     */   public AudioClip getAudioClip(URL url)
/*     */   {
/* 257 */     return new AppletAudioClip(url);
/*     */   }
/*     */
/*     */   public Image getImage(URL url) {
/* 261 */     Toolkit tk = Toolkit.getDefaultToolkit();
/*     */     try {
/* 263 */       ImageProducer prod = (ImageProducer)url.getContent();
/* 264 */       return tk.createImage(prod);
/*     */     } catch (IOException e) {
/*     */     }
/* 267 */     return null;
/*     */   }
/*     */
/*     */   public Applet getApplet(String name)
/*     */   {
/* 273 */     if (name.equals(this.name))
/* 274 */       return this.applet;
/* 275 */     return null;
/*     */   }
/*     */
/*     */   public Enumeration getApplets()
/*     */   {
/* 280 */     Vector v = new Vector();
/* 281 */     v.addElement(this.applet);
/* 282 */     return v.elements();
/*     */   }
/*     */
/*     */   public void showDocument(URL url)
/*     */   {
/*     */   }
/*     */
/*     */   public void showDocument(URL url, String target)
/*     */   {
/*     */   }
/*     */
/*     */   public void showStatus(String status) {
/* 294 */     if (this.label != null)
/* 295 */       this.label.setText(status);
/*     */   }
/*     */
/*     */   public void setStream(String key, InputStream stream) {
/* 299 */     throw new RuntimeException("Not Implemented");
/*     */   }
/*     */
/*     */   public InputStream getStream(String key)
/*     */   {
/* 304 */     throw new RuntimeException("Not Implemented");
/*     */   }
/*     */
/*     */   public Iterator getStreamKeys()
/*     */   {
/* 309 */     throw new RuntimeException("Not Implemented");
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.utils.applet.JMainFrame
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.utils.applet.JMainFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.