home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / applet / AppletViewerPanel.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  3.2 KB  |  130 lines

  1. /*
  2.  * @(#)AppletViewerPanel.java    1.4 96/04/08
  3.  *
  4.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.applet;
  21.  
  22. import java.util.*;
  23. import java.io.*;
  24. import java.net.URL;
  25. import java.net.MalformedURLException;
  26. import java.awt.*;
  27. import java.applet.*;
  28. import java.awt.image.MemoryImageSource;
  29. import java.awt.image.ColorModel;
  30.  
  31.  
  32. /**
  33.  * Sample applet panel class. The panel manages and manipulates the
  34.  * applet as it is being loaded. It forks a seperate thread in a new
  35.  * thread group to call the applet's init(), start(), stop(), and
  36.  * destroy() methods.
  37.  *
  38.  * @version     1.4, 04/08/96
  39.  * @author     Arthur van Hoff
  40.  */
  41. class AppletViewerPanel extends AppletPanel {
  42.     /**
  43.      * The document url.
  44.      */
  45.     URL documentURL;
  46.  
  47.     /**
  48.      * The base url.
  49.      */
  50.     URL baseURL;
  51.  
  52.     /**
  53.      * The attributes of the applet.
  54.      */
  55.     Hashtable atts;
  56.  
  57.     /**
  58.      * Construct an applet viewer and start the applet.
  59.      */
  60.     AppletViewerPanel(URL documentURL, Hashtable atts) {
  61.     this.documentURL = documentURL;
  62.     this.atts = atts;
  63.  
  64.     String att = getParameter("zipbase");
  65.     if (att != null) {
  66.         if (!att.endsWith("/")) {
  67.         try {
  68.             baseURL = new URL(documentURL, att);
  69.         } catch (MalformedURLException e) {
  70.         }
  71.         }
  72.     }
  73.     if (baseURL == null) {
  74.         att = getParameter("codebase");
  75.         if (att != null) {
  76.         if (!att.endsWith("/")) {
  77.             att += "/";
  78.         }
  79.         try {
  80.             baseURL = new URL(documentURL, att);
  81.         } catch (MalformedURLException e) {
  82.         }
  83.         }
  84.     }
  85.     if (baseURL == null) {
  86.         String file = documentURL.getFile();
  87.         int i = file.lastIndexOf('/');
  88.         if (i > 0 && i < file.length() - 1) {
  89.         try {
  90.             baseURL = new URL(documentURL, file.substring(0, i + 1));
  91.         } catch (MalformedURLException e) {
  92.         }
  93.         }
  94.     }
  95.     
  96.     // when all is said & done, baseURL shouldn't be null
  97.     if (baseURL == null)
  98.         baseURL = documentURL;
  99.     }
  100.  
  101.     /**
  102.      * Get an applet parameter.
  103.      */
  104.     public String getParameter(String name) {
  105.     return (String)atts.get(name.toLowerCase());
  106.     }
  107.  
  108.     /**
  109.      * Get the document url.
  110.      */
  111.     public URL getDocumentBase() {
  112.     return documentURL;
  113.     }
  114.  
  115.     /**
  116.      * Get the base url.
  117.      */
  118.     public URL getCodeBase() {
  119.     return baseURL;
  120.     }
  121.  
  122.     /**
  123.      * Get the applet context. For now this is
  124.      * also implemented by the AppletPanel class.
  125.      */
  126.     public AppletContext getAppletContext() {
  127.     return (AppletContext)getParent();
  128.     }
  129. }
  130.