Class Library: Applets
WebApplet. The parent classes for most of EarthStones' applets. Deploys an optional splash panel at startup as well as managing optional registration-checking for evaluation copies of software.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class WebApplet extends Applet implements Runnable |
|
variables | private boolean isFirstCall = true; | Indicates that this is the first call to the preload() method. |
boolean zFirstOnTop = true; | Reflects the implementation of Java's
z-order on the current browser and computing platorm. If set, the first component of any
overlapping components added to a container will appear on top (this is the implementation
in Sun's applet viewer and Internet Explorer running under Windows); otherwise, the last
component added will be on top (the case for Netscape Navigator and for Internet Explorer
on the Macintosh). The value of zFirstOnTop will determine the order in which the background, splash, and dialog panels are added to the applet. |
|
Applet's panels | ||
Panel background; | Panel which will hold all of the applet's panels. |
|
SplashPanel splash; | Splash panel. | |
Panel dialog; | Displays dialog and on-mouseover hints. |
|
DocumentPanel document; | Applet's main panel. | |
Variables used in connection with splash panel | ||
Thread th; | ||
boolean loadSplash = true; | ||
constructors | WebApplet() | The default constructor. |
public void init() | This method is called automatically when
the applet instance is created. It does a number of things to begin the applet's loading: 1) Creates a null layout for the applet. 2) Set's the wait cursor. 3) Reads the loadSplash parameter from the <applet> tag and calls sets the zFirstOnTop variable. 4) Creates an instance of SplashPanel and hides it. 5) Makes the first call to the preload() method which will preload any panels which will be overlapped by the splash and dialog panels if zFirstOnTop is false. 6) Adds the splash and dialog panels to the applet. 7) Calls preload() again. 8) If loadSplash is set, adds the splash panel and calls its startSplash() method which begins loading and running the splash panel in its own thread. Note: Subclass' init() method should first size and position window and then call super.init() to invoke this method. It can then perform any other initialization unique to the applet (e.g., setting the color of the background panel). |
|
public void start() | This method is called automatically when init() finishes. It creates a new Thread object which it associates with this applet and call the thread's start() method. By default, that method calls the threads's run() method, which in turn calls this.run(). | |
public void run() | Calls load(). | |
public void load() | Calls postload(). May be overridden in subclass where load() should have the following structure: preload(); [load the applet's panels into the background panel] [load the default page either by calling loadDefaultPage() or otherwise implementing code which performs the same functions] postload(); Note that unless code equivalent to that in loadDefaultPage() is implemented, any software designated an evaluation copy by setting Web.regCheck will fail to run because it will never allow the user to register a temporary license by presenting the appropriate registration form |
|
public void preload() | This method is called twice and is responsible for calling preloadThis() once, at the appropriate point in the loading sequence, depending upon the value of zFirstOnTop. | |
public void preloadThis() | This method loads the background panel
which holds the applets other panels and will always appear under the splash and dialog
panels regardless of z-order. Note: Because this method sizes the background panel to the dimensions of the applet, the applet itself should be sized in WebApplet subclasses prior to the call super.init() which invokes (eventually) preloadThis(). |
|
public String loadDefaultPage(String pName, boolean scroll, boolean hscroll) | This method loads the default page and
returns its file reference src: 1) If Web.regStatus() == Web.NOT_LICENSED set page source src to that specified by Web.demoReg on the website's server Web.webServer. 2) Otherwise, set src to that specified by the value of the parameter named pName. 3) If the src is not blank, call update(src, scroll, hscroll). 4) Otherwise, set Web.killSplash = true and reset cursor to the default cursor. 5) Return src. |
|
public void postload() | This method should be invoked at the end of subclass load() method to initialize the dialog panel and wait until splash panel is ready to be killed. | |
These next two methods may be overridden in subclasses to update window contents. | ||
public void update(String src, boolean scrl, boolean hscrl) | This method should: 1) Do whatever is necessary to update the content of the document panel to reflect the source file src with vertical and horizontal scrollbars specified by scrl and hscrl. 2) Call documentHasChanged(). This method is not called by most of EarthStones' applets and applications which depend upon subclasses of Web to manage updating of the user-interface. Instead, it is provide to permit an HTML document to update the applet by making a javascript call of the form: appName.update(src, scrl, hscrl). |
|
public synchronized void documentHasChanged() | The default for this method does nothing
and works fine when a Web subclass handles this function. Otherwise, this method should do whatever is necessary to update the context of the window's document panel to reflect a change in content (e.g., changing the footer panel's source file field). |
|
public void destroy() | Before destroying the applet by calling super.destroy(), this method removes its associated Web and Site instances from WebSite's registries. | |
The remaining methods provide services duplicated in the Web class but needed here before the Web instance has been created. | ||
protected boolean zFirstOnTop() | Returns value for zFirstOnTop for this browser and platform as specified above. | |
protected float resolutionFactor() | Returns scaling factor for user's screen resolution = wid/1024.0f where screen resolution = wid x ht pixels. | |
protected Frame getFrame() | Returns the applet's parent window. |
JSite. EarthStones' main applet. Deploys entire website and implements the major user-interface elements: BannerPanel, FooterPanel, GraphicPanel, DocumentPanel, and SplashPanel.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class JSite extends WeApplet | |
variables | Applet's panels | |
BannerPanel banner; | Applet's banner panel | |
FooterPanel footer; | Applet's footer panel | |
DocumentPanel graphic; | Left panel for graphic images | |
methods | public void init() | Calls super.init() sets background color to white. |
public void load() | 1) Set's splash panel's appColor variable. 2) Creates an instance of Web for this applet to manage access to user interface elements. Because a specialized subclass JavaWeb of Web is created here JSite can rely on its built-in update methods to respond to user events. This Web instance is automatically registered with WebSite. 3) Scales applet itself . Applet's elements will be scaled automatically. 4) Loads an instance of BannerPanel into background panel and registers it with applet's web instance as its banner panel. 5) Loads an instance of FooterPanel into background panel and registers it with applet's web instance as its footer panel. 6) Loads an instance of DocumentPanel into background panel and registers it with applet's web instance as its (left-hand) graphic panel. The width of the graphic panel will be reset as need. Its height should be set here by calling DocumentPanel.setHeight(int ht). 7) Loads an instance of DocumentPanel into background panel and registers it with applet's web instance as its (right-hand) document panel. The width of the document panel will be reset as need. Its height should be set here by calling DocumentPanel.setHeight(int ht). 8) Loads the default page. Note that JSite implements the functionality of WebApplet.setDefaultPage() by overriding the usual default if Web.regStatus() == Web.NOT_LICENSED to load Site.section("Home").chapter("Tips").page("02") instead (i.e., demoreg.htm). 9) Calls postload(). |
|
public synchronized void documentHasChanged() | Normally JavaWeb handles all updating of the user interface and the default documentHasChanged() method defined in WebApplet (which does nothing) would be not need to be overridden here. However, in the case of an unlicensed evaluation copy of the software, this method must call footer.update() when the registration form is presented to the user. |
JDoc. Renders an HTML document by implementing DocumentPanel.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class JDoc extends WebApplet | |
variables | Variables used by document panel | |
protected int leftMargin = 0; | ||
protected int rightMargin = 0; | ||
protected int topMargin = 0; | ||
protected int bottomMargin = 0; | ||
protected int scrollMargin = 10; | ||
protected boolean scroll = true; | ||
protected boolean hscroll = false; | ||
protected String source = ""; | ||
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | 1) Call super.init(). 2) Set background color to white. |
public void load() | 1) Adds new document panel to background
panel. 2) Creates an instance of Web for this applet to manage access to user interface elements. Note that it is Web itself that is instantiated here, not a more specialized subclass such as JavaWeb. As a result, JDoc must manage its own updating by providing its own update() methods rather than relying on a Web subclass for this. Web instance is automatically registered with WebSite. 3) Sizes instance of DocumentPanel and registers it with applet's web instance as the main (i.e., non-alternate) document. 4) Reads applet parameters, including scroll and hscroll. 5) Loads the default page by setting source equal to loadDefaultPage("source", scroll, hscroll). 6) Calls postload(). |
|
Applet's update() methods: called either from the HTML page via javascript or by another applet. | ||
public void update(String src, boolean scrl, boolean hscrl) | Creates a new Document object and sets its
calls its setSource() method to set its source variable to the HTML document file src; if
(scrl), provides vertical scroll bar; if (hscrl), provides horizontal scroll bar. Note: If src ends with the file extension .html or .htm, the HTML source will be interpreted and rendered; if it ends with .gif, .jpg, or .jpeg the image file will be displayed with its default dimensions scaled for the viewer's screen resolution; any other files will be treated as plain text files. |
|
public void update(String src, boolean scrl) | Loads HTML document file src; if (scrl), provides vertical scroll bar; provides no horizontal scroll bar (the default). | |
public void update(String src) | Loads HTML document file src; provides vertical scroll bar but no horizontal scroll bar (the defaults). |
JDocViewer. An enhanced version of JDoc. Implements DocumentPanel and DocFooter.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class JDocViewer extends WebApplet | |
variables | Applet's panels | |
Panel fore; | Applet's foreground panel creates colored outline in webpage. | |
Panel banner; | Applet's banner panel. | |
ImagePanel logo, logoText; | Elements of banner panel. | |
DocFooter footer; | Applet's footer panel. | |
Variables used by document panel | ||
protected String source = ""; | ||
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | Calls super.init() and sets color of WebApplet.background to create colored border around panel fore. |
public void load() | 1) Creates, initializes, and adds the panel
fore to the background panel and sizes it to reveal border. 2) Adds a new instance of DocumentPanel to fore. 3) Creates an instance of Web for this applet to manage access to user interface elements. Note that it is Web itself that is instantiated here, not a more specialized subclass such as JavaWeb. As a result, JDoc must manage its own updating by providing its own update() methods rather than relying on a Web subclass for this. Web instance is automatically registered with WebSite. 3) Creates and adds a banner panel. 4) Creates and adds an instance of the private class DocFooter. 5) Sizes instance of DocumentPanel and registers it with applet's web instance as the main (i.e., non-alternate) document. 6) Reads applet parameters 7) Loads the default page by setting source equal to loadDefaultPage("contents", true, false). 8) Calls postload(). |
|
Applet's update() method: called either from the HTML page via javascript or by another applet. | ||
public void update(String src, boolean scrl, boolean hscrl) | Creates a new Document object and sets its
calls its setSource() method to set its source variable to the HTML document file src; if
(scrl), provides vertical scroll bar; if (hscrl), provides horizontal scroll bar. Note: If src ends with the file extension .html or .htm, the HTML source will be interpreted and rendered; if it ends with .gif, .jpg, or .jpeg the image file will be displayed with its default dimensions scaled for the viewer's screen resolution; any other files will be treated as plain text files. |
|
public synchronized void documentHasChanged() | 1) Updates footer's Source text field to
reflect current document. 2) Disables/enables Show button if this is/isnot a CGI results document. |
Banner. A stand-alone implementation of BannerPanel used by HtmlWeb (EarthStones' Version 2 website).
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class Banner extends Applet | |
variables | Applet's panel | |
BannerPanel banner; | The instance of BannerPanel | |
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | 1) Creates an instance of HtmlWeb for this
applet to manage access to user interface elements. Because a specialized subclass HTMLWeb
of Web is created here Banner can rely on its built-in update methods to respond to user
events. Note: The call WebSite.registerWeb() should NOT be made here. This is handled
automatically by HtmlWeb. (The subclass HTMLWeb was used in Version 2 of EarthStones website to manage an interface between its Java and HTML elements. See About this Web Site/A Mostly-Java-Powered Website for more information. There's allot going on under the hood here. By registering this instance of HTMLWeb with WebSite, transparent communication with other applets can be accomplished. See Java Software/Deploying JSite/Inter-Applet Communication Tips for a detailed discussion of how this is achieved along with a working example which uses both Banner and Footer applets.) 2) Loads the default page. |
It is not necessary to define update() methods here because these will be handled by HtmlWeb. | ||
public void preload() | The preloading of certain objects appears
to be necessary to permit javascript calls used in version 2 of EarthStones website. This
method is called by HTMLWeb. See About this Web Site/A Mostly-Java-Powered Website for more information. |
|
public void destroy() | Before destroying applet, removes its Applet, Web, and Site enteries in WebSite's registries. |
Footer. A stand-alone implementation of FooterPanel used by HtmlWeb (EarthStones' Version 2 website).
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class Footer extends Applet | |
variables | private Applet webApp; | A reference to this applet's host applet (see below). |
Applet's panel | ||
FooterPanel banner; | The instance of FooterPanel | |
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | 1) Rather than creating a new instance of
Web here, applet attempts to establish communication with a host applet using the id
parameter which it reads from Footer's applet tag. If successful, the host applet's
instance of Web is shared by Footer, an instance of FooterPanel is created, and it is
registered with the HtmlWeb subclass instance as its footer panel. See Java Software/Deploying JSite/Inter-Applet Communication Tips for a detailed discussion of how this is achieved along with a working example which uses both Banner and Footer applets. 2) Note: it is not necessary to make a show() or update() call here. HtmlWeb handles all of this. |
It is not necessary to define update() methods here because these will be handled by HtmlWeb. | ||
public void preload() | The preloading of certain objects appears
to be necessary to permit javascript calls used in version 2 of EarthStones website. This
method is called by HTMLWeb. See About this Web Site/A Mostly-Java-Powered Website for more information. |
|
public void destroy() | Before destroying applet, remove its Web and Site enteries in WebSite's registries. |
Graphic. An earlier, stand-alone version of GraphicPanel that works with HtmlWeb (EarthStones' Version 2 website) and is loaded by the HTML documents aPage.htm and Graphic_v2.htm. It uses a poling loop to check with HtmlWeb for a new image to be loaded.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class Graphic extends Applet implements Runnable | |
variables | private Applet webApp; | A reference to this applet's host applet (see below). |
private GImage currentState. | The image currently displayed. | |
private Thread th; | Used in poling loop by applet's run() method. | |
Applet's panel | ||
Panel imgPanel; | The instnace of FooterPanel | |
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | 1) Rather than creating a new instance of
Web here, applet attempts to establish communication with a host applet using the id
parameter which it reads from Graphic's applet tag. If successful, the host applet's
instance of Web is shared by Graphic, and the applet itself is registered with the HtmlWeb
subclass instance as its graphic panel (i.e., Graphic graphicApp). See Java Software/Deploying JSite/Inter-Applet Communication Tips for a detailed discussion of how this is achieved along with a working example which uses both Banner and Footer applets. 2) Note: it is not necessary to make a show() or update() call here. HtmlWeb and this applet's run() method handles all of this. |
It is not necessary to define update() methods here because these will be handled by this.run() and by HtmlWeb. | ||
public void start() | The applet's start() method is called automatically when init() finishes execution. This method defines a new thread and calls its start() method. | |
public void run() | The new thread's start() method calls
th.run() which in turn calls this.run() which does the following: 1) Notifies HtmlWeb that it has been (re)loaded. 2) Checks with HtmlWeb for the image associated with its current value of thePage. If this image differs from the applet's own currentState value, the new image is displayed. 3) Sleeps for a few milliseconds and then loops back to 2). |
|
public void destroy() | Before destroying applet, remove its Web and Site enteries in WebSite's registries. |
JImage. A stand-alone implementation of the ImageBox object.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class JImage extends Applet | |
variables | String image; | The image source file; if absolute URL is not specified, assumed to be relative to the HTML document containing the JImage <applet> tag. |
String orient; | Optional parameter specifies image's orientation: portrait (PTR) or landscape (LSC); default is PTR | |
int width, height; | optional parameters specify image's width and height; if omitted, dimensions of 300 x 420 are assumed. | |
float scale; | Optional scale factor for resizing image; default value is 1.00f. | |
String title; | Optional title string which will be printed in bold face and wrapped under image. | |
String desc; | Optional description string printed in plain font face and appended to title string. | |
private GImage img; | A graphic image object. | |
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | 1) Reads applet parameters. 2) Creates and shows ImageBox object. 3) Sizes applet to dimensions of ImageBox. |
JText. A stand-alone implementation of the TextBox object.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; java.util.*; |
|
class declaration | public class JText extends Applet | |
variables | String text; | Text string to be displayed |
int width; | Width of text box | |
Note: The width and height of the applet are set in the applet tag. Their values should be appropriate for the viewer's screen resolution (i.e., already scaled). | ||
methods | public void init() | 1) Reads applet parameters. 2) Creates and shows TextBox object. 3) Sizes applet to dimensions of TextBox. |
SelectRes. A stand-alone implementation of features of EarthStones' AutoResTM technology. This nonvisual utility applet determine's viewer's screen resolution and loads a corresponding file into a specified frame.
package | earthstones | |
import | java.awt.*; java.applet.*; java.net.*; |
|
class declaration | public class SelectRes extends Applet | |
variables | private String aFile = ""; | Base name of file to be displayed (e.g., if base name is myFile.htm, then myFile_1024 will be displayed for 1024x768 screen resolution; if base name is "", then 1024.htm will be displayed for 1024x768 screen resolution) |
private String aFrame = "self"; | Specifies the frame into which the specified link is to be loaded. Must be a valid frame specified with the <frame> tag or be one of the following: blank, to load into a new browser window; parent, to load into the parent of the window containing the link; top to load into the current top window; or self, to load into the link's current window. The literal values blank, etc., may be preceeded by an optional underscore character ("_"). | |
methods | public void init() | 1) Calls sWidth(). 2) Reads applet parameters. 2) Loads file aFile [+ "_"] + sWidth() + ".htm" into frame aFrame. |
public String sWidth() | Uses Java's getToolkit().[cont] getScreenSize().width property to return screen width. |