Package com.sun.j3d.utils.applet

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

/*     */ 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.BorderLayout;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Frame;
/*     */ import java.awt.Image;
/*     */ import java.awt.Label;
/*     */ import java.awt.Toolkit;
/*     */ import java.awt.Window;
/*     */ 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 sun.applet.AppletAudioClip;
/*     */
/*     */ public class MainFrame extends Frame
/*     */   implements Runnable, AppletStub, AppletContext
/*     */ {
/* 119 */   private String[] args = null;
/* 120 */   private static int instances = 0;
/*     */   private String name;
/* 122 */   private boolean barebones = true;
/*     */   private Applet applet;
/* 124 */   private Label label = null;
/*     */   private Dimension appletSize;
/*     */   private static final String PARAM_PROP_PREFIX = "parameter.";
/*     */
/*     */   public MainFrame(Applet applet, String[] args, int width, int height)
/*     */   {
/* 132 */     build(applet, args, width, height);
/*     */   }
/*     */
/*     */   public MainFrame(Applet applet, String[] args)
/*     */   {
/* 137 */     build(applet, args, -1, -1);
/*     */   }
/*     */
/*     */   public MainFrame(Applet applet, int width, int height)
/*     */   {
/* 142 */     build(applet, null, width, height);
/*     */   }
/*     */
/*     */   private void build(Applet applet, String[] args, int width, int height)
/*     */   {
/* 148 */     instances += 1;
/* 149 */     this.applet = applet;
/* 150 */     this.args = args;
/* 151 */     applet.setStub(this);
/* 152 */     this.name = applet.getClass().getName();
/* 153 */     setTitle(this.name);
/*     */
/* 156 */     Properties props = System.getProperties();
/* 157 */     props.put("browser", "Acme.MainFrame");
/* 158 */     props.put("browser.version", "11jul96");
/* 159 */     props.put("browser.vendor", "Acme Laboratories");
/* 160 */     props.put("browser.vendor.url", "http://www.acme.com/");
/*     */
/* 163 */     if (args != null) {
/* 164 */       parseArgs(args, props);
/*     */     }
/*     */
/* 168 */     String widthStr = getParameter("width");
/* 169 */     if (widthStr != null) {
/* 170 */       width = Integer.parseInt(widthStr);
/*     */     }
/*     */
/* 173 */     String heightStr = getParameter("height");
/* 174 */     if (heightStr != null) {
/* 175 */       height = Integer.parseInt(heightStr);
/*     */     }
/*     */
/* 179 */     if ((width == -1) || (height == -1)) {
/* 180 */       System.err.println("Width and height must be specified.");
/* 181 */       return;
/*     */     }
/*     */
/* 185 */     String bonesStr = getParameter("barebones");
/* 186 */     if ((bonesStr != null) && (bonesStr.equals("true"))) {
/* 187 */       this.barebones = true;
/*     */     }
/*     */
/* 191 */     setLayout(new BorderLayout());
/* 192 */     add("Center", applet);
/*     */
/* 195 */     pack();
/* 196 */     validate();
/* 197 */     this.appletSize = applet.getSize();
/* 198 */     applet.setSize(width, height);
/* 199 */     setVisible(true);
/*     */
/* 205 */     SecurityManager sm = System.getSecurityManager();
/* 206 */     boolean doExit = true;
/*     */
/* 208 */     if (sm != null) {
/*     */       try {
/* 210 */         sm.checkExit(0);
/*     */       } catch (SecurityException e) {
/* 212 */         doExit = false;
/*     */       }
/*     */     }
/*     */
/* 216 */     boolean _doExit = doExit;
/*     */
/* 218 */     addWindowListener(new WindowAdapter() { private final boolean val$_doExit;
/*     */
/* 220 */       public void windowClosing(WindowEvent winEvent) { if (MainFrame.this.applet != null) {
/* 221 */           MainFrame.this.applet.destroy();
/*     */         }
/* 223 */         Window w = winEvent.getWindow();
/* 224 */         w.hide();
/*     */         try {
/* 226 */           w.dispose();
/*     */         } catch (IllegalStateException e) {
/*     */         }
/* 229 */         if (this.val$_doExit)
/* 230 */           System.exit(0);
/*     */       }
/*     */     });
/* 237 */     new Thread(this).start();
/*     */   }
/*     */
/*     */   private static void parseArgs(String[] args, Properties props)
/*     */   {
/* 245 */     for (int i = 0; i < args.length; i++) {
/* 246 */       String arg = args[i];
/* 247 */       int ind = arg.indexOf('=');
/* 248 */       if (ind == -1)
/* 249 */         props.put("parameter." + arg.toLowerCase(), "");
/*     */       else
/* 251 */         props.put("parameter." + arg.substring(0, ind).toLowerCase(), arg.substring(ind + 1));
/*     */     }
/*     */   }
/*     */
/*     */   public void run()
/*     */   {
/* 261 */     showStatus(this.name + " initializing...");
/* 262 */     this.applet.init();
/* 263 */     validate();
/* 264 */     showStatus(this.name + " starting...");
/* 265 */     this.applet.start();
/* 266 */     validate();
/* 267 */     showStatus(this.name + " running...");
/*     */   }
/*     */
/*     */   public boolean isActive()
/*     */   {
/* 273 */     return true;
/*     */   }
/*     */
/*     */   public URL getDocumentBase()
/*     */   {
/* 278 */     String dir = System.getProperty("user.dir");
/* 279 */     String urlDir = dir.replace(File.separatorChar, '/');
/*     */     try {
/* 281 */       return new URL("file:" + urlDir + "/"); } catch (MalformedURLException e) {
/*     */     }
/* 283 */     return null;
/*     */   }
/*     */
/*     */   public URL getCodeBase()
/*     */   {
/* 291 */     String path = System.getProperty("java.class.path");
/* 292 */     Enumeration st = new StringTokenizer(path, ":");
/* 293 */     while (st.hasMoreElements()) {
/* 294 */       String dir = (String)st.nextElement();
/* 295 */       String filename = dir + File.separatorChar + this.name + ".class";
/* 296 */       File file = new File(filename);
/* 297 */       if (file.exists()) {
/* 298 */         String urlDir = dir.replace(File.separatorChar, '/');
/*     */         try {
/* 300 */           return new URL("file:" + urlDir + "/");
/*     */         } catch (MalformedURLException e) {
/* 302 */           return null;
/*     */         }
/*     */       }
/*     */     }
/* 306 */     return null;
/*     */   }
/*     */
/*     */   public String getParameter(String name)
/*     */   {
/* 311 */     return System.getProperty("parameter." + name.toLowerCase());
/*     */   }
/*     */
/*     */   public void appletResize(int width, int height)
/*     */   {
/* 317 */     Dimension frameSize = getSize();
/* 318 */     frameSize.width += width - this.appletSize.width;
/* 319 */     frameSize.height += height - this.appletSize.height;
/* 320 */     setSize(frameSize);
/* 321 */     this.appletSize = this.applet.getSize();
/*     */   }
/*     */
/*     */   public AppletContext getAppletContext() {
/* 325 */     return this;
/*     */   }
/*     */
/*     */   public AudioClip getAudioClip(URL url)
/*     */   {
/* 336 */     return new AppletAudioClip(url);
/*     */   }
/*     */
/*     */   public Image getImage(URL url) {
/* 340 */     Toolkit tk = Toolkit.getDefaultToolkit();
/*     */     try {
/* 342 */       ImageProducer prod = (ImageProducer)url.getContent();
/* 343 */       return tk.createImage(prod); } catch (IOException e) {
/*     */     }
/* 345 */     return null;
/*     */   }
/*     */
/*     */   public Applet getApplet(String name)
/*     */   {
/* 351 */     if (name.equals(this.name)) {
/* 352 */       return this.applet;
/*     */     }
/* 354 */     return null;
/*     */   }
/*     */
/*     */   public Enumeration getApplets()
/*     */   {
/* 359 */     Vector v = new Vector();
/* 360 */     v.addElement(this.applet);
/* 361 */     return v.elements();
/*     */   }
/*     */
/*     */   public void showDocument(URL url)
/*     */   {
/*     */   }
/*     */
/*     */   public void showDocument(URL url, String target)
/*     */   {
/*     */   }
/*     */
/*     */   public void showStatus(String status) {
/* 373 */     if (this.label != null)
/* 374 */       this.label.setText(status);
/*     */   }
/*     */
/*     */   public void setStream(String key, InputStream stream)
/*     */   {
/* 379 */     throw new RuntimeException("Not Implemented");
/*     */   }
/*     */
/*     */   public InputStream getStream(String key)
/*     */   {
/* 384 */     throw new RuntimeException("Not Implemented");
/*     */   }
/*     */
/*     */   public Iterator getStreamKeys()
/*     */   {
/* 389 */     throw new RuntimeException("Not Implemented");
/*     */   }
/*     */ }

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

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

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.