4 * Created on 05 October 2001, 15:19
\r
9 package org.tjworld.vista.cid;
\r
13 import java.awt.event.MouseListener;
\r
14 import org.tjworld.components.AnimatedButton;
\r
16 /** Provides a web-based entry into the Vista.CID application
\r
18 * Presents a small (95x95 pixel) animated blinking eye graphic within a web page
\r
19 * that when clicked on brings up the main CID application window (as a frame).
\r
21 * When running as an applet (unless it is signed) VisTA.CID is restricted by the
\r
22 * browser security policy (commonly known as the 'sandbox') from accessing any local file
\r
23 * system resources, or any network resources other than the location it was loaded from.
\r
25 * It passed a reference to itself to the <code>CID(java.applet.Applet a)</code> constructor
\r
26 * so the CID instance can access applet methods such as <code>getCodeBase()</code>.
\r
28 * Because the applet's display area is painted by a single custom component <code>AnimatedButton</code>
\r
29 * the applet itself has no display painting to do.
\r
31 * @version 1.0 10 Oct 2001
\r
35 public class CIDapplet extends javax.swing.JApplet implements Runnable, MouseListener {
\r
36 private Thread animation;
\r
37 private AnimatedButton logo;
\r
38 private int delays[] = {100, 5000, 5000, 5000}; // the animated button frame delays
\r
39 private final String logoBaseName = "vista";
\r
40 private final String logoExtension = ".gif";
\r
41 static private final String logoPathParam = "relativeLogoPath";
\r
42 static private final String logoBGcolour = "backgroundColour";
\r
44 private org.tjworld.vista.cid.CID CIDframe;
\r
46 /** Creates new form CID */
\r
47 public CIDapplet() {
\r
51 /** Retrieves (any) applet parameters and sets sensible default values.
\r
54 * <code><param name="relativeLogoPath" value="media" /></code> Path relative to DocumentBase to find animation GIF images
\r
55 *<code><param name = "backgroundColour" value="#FF00FF" /></code> Colour to use behind transparent areas of the animation frames (default is white: #FFFFFF)
\r
57 public void init() {
\r
58 CIDframe = new org.tjworld.vista.cid.CID(this); // create the main window
\r
60 // find and load each image for the animation frame
\r
61 String bgColour, relPath, prefix;
\r
65 try { // request colour from Browser
\r
66 bgColour = getParameter(logoBGcolour);
\r
67 } catch(NullPointerException e) { // no applet param...
\r
68 bgColour = "#FFFFFF"; // ... so choose a sensible default
\r
71 try { // attempt to convert it from a String to a Color
\r
72 bg = Color.decode(bgColour);
\r
73 } catch(Exception e) { // decode() can throw a NumberFormatException...
\r
74 bg = Color.white; // ... so choose a sensible default if it does
\r
76 setBackground(bg); // set applet's background to match HTML page (hopefully!!)
\r
78 // load the animation frames
\r
79 try { // request optional path from Browser
\r
80 relPath = getParameter(logoPathParam);
\r
81 } catch(NullPointerException e) { // no applet param...
\r
82 relPath = "media/"; // ... so use the default location
\r
85 try { // attempt to create a valid URL by adding the relPath to the DocumentBase URL
\r
86 imURL = new URL(getDocumentBase(), relPath);
\r
87 } catch(Exception e) { // URL constructor can throw a MalformedURLException...
\r
89 try { // ... so default to {DocumentBase}/media/
\r
90 imURL = new URL(getDocumentBase(), "media/"); // has also to be wrapped in a try-catch clause
\r
91 } catch(Exception f) {
\r
92 imURL = null; // initialized to allow compilation, but will cause runtime error!
\r
93 System.err.println("Exception trying to create default URL");
\r
97 prefix = logoBaseName; // can use this line to add in an applet-specific additional relative path element
\r
99 logo = new AnimatedButton(bg, imURL, prefix, logoExtension, delays, 4, this);
\r
100 logo.setSize(64,64);
\r
101 logo.addMouseListener(this);
\r
103 getContentPane().add(logo); // add it to the display
\r
106 public void destroy() {
\r
107 logo.removeMouseListener(this);
\r
110 /** This method is called from within the constructor to
\r
111 * initialize the form.
\r
112 * WARNING: Do NOT modify this code. The content of this method is
\r
113 * always regenerated by the Form Editor.
\r
115 private void initComponents() {//GEN-BEGIN:initComponents
\r
117 getContentPane().setLayout(null);
\r
119 }//GEN-END:initComponents
\r
122 // Variables declaration - do not modify//GEN-BEGIN:variables
\r
123 // End of variables declaration//GEN-END:variables
\r
125 public void update(Graphics g) {
\r
129 public void paint(Graphics g) {
\r
137 public void start() {
\r
138 animation = new Thread(logo);
\r
142 public synchronized void stop() {
\r
146 public void run() {
\r
150 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {
\r
153 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {
\r
156 public void mouseReleased(java.awt.event.MouseEvent mouseEvent) {
\r
159 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {
\r
160 CIDframe.setVisible(CIDframe.isVisible() == true ? false : true);
\r
163 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {
\r