Visual Color Imbalance Detector: Reconstructed project directories and files
[VistaCID.git] / org / tjworld / vista / CID / CIDapplet.java
1 /*\r
2         * CIDapplet.java\r
3         *\r
4         * Created on 05 October 2001, 15:19\r
5         * $Header: $\r
6         * \r
7         * $History: $\r
8         */\r
9 package org.tjworld.vista.cid;\r
10 \r
11 import java.net.*;\r
12 import java.awt.*;\r
13 import java.awt.event.MouseListener;\r
14 import org.tjworld.components.AnimatedButton;\r
15 \r
16 /** Provides a web-based entry into the Vista.CID application\r
17         *\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
20         *\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
24         *\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
27         * \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
30         *\r
31         * @version 1.0 10 Oct 2001\r
32         * @author  TJ\r
33         * @see CID\r
34         */\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
43         \r
44         private org.tjworld.vista.cid.CID CIDframe;\r
45         \r
46         /** Creates new form CID */\r
47         public CIDapplet() {\r
48                 initComponents();\r
49  }\r
50         \r
51         /** Retrieves (any) applet parameters and sets sensible default values.\r
52                 *\r
53                 * Parameters:\r
54                 * <code>&ltparam name="relativeLogoPath" value="media" /&gt</code> Path relative to DocumentBase to find animation GIF images\r
55                 *<code>&ltparam name = "backgroundColour" value="#FF00FF" /&gt</code> Colour to use behind transparent areas of the animation frames (default is white: #FFFFFF)\r
56                 */\r
57  public void init() {\r
58                 CIDframe = new org.tjworld.vista.cid.CID(this); // create the main window\r
59 \r
60                 // find and load each image for the animation frame\r
61                 String bgColour, relPath, prefix;\r
62                 URL imURL;\r
63                 Color bg;\r
64                 \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
69                 }\r
70                 \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
75                 }\r
76                 setBackground(bg); // set applet's background to match HTML page (hopefully!!)\r
77                 \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
83                 }\r
84 \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
88 \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
94                         }\r
95                 }\r
96 \r
97                 prefix = logoBaseName; // can use this line to add in an applet-specific additional relative path element\r
98 \r
99   logo = new AnimatedButton(bg, imURL, prefix, logoExtension, delays, 4, this);\r
100                 logo.setSize(64,64);\r
101                 logo.addMouseListener(this);\r
102                 \r
103                 getContentPane().add(logo); // add it to the display\r
104  }\r
105         \r
106         public void destroy() {\r
107                 logo.removeMouseListener(this);\r
108         }\r
109         \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
114                 */\r
115         private void initComponents() {//GEN-BEGIN:initComponents\r
116                 \r
117                 getContentPane().setLayout(null);\r
118                 \r
119         }//GEN-END:initComponents\r
120                                 \r
121                                 \r
122         // Variables declaration - do not modify//GEN-BEGIN:variables\r
123         // End of variables declaration//GEN-END:variables\r
124 \r
125         public void update(Graphics g) {\r
126                 paint(g);\r
127         }\r
128         \r
129         public void paint(Graphics g) {\r
130                 logo.repaint();\r
131         }\r
132         \r
133  /*\r
134                 *\r
135                 */\r
136         \r
137         public void start() {\r
138                 animation = new Thread(logo);\r
139                 animation.start();\r
140         }\r
141 \r
142         public synchronized void stop() {\r
143                 animation = null;\r
144         }\r
145         \r
146  public void run() {\r
147                 while(true) {}\r
148         }\r
149 \r
150         public void mousePressed(java.awt.event.MouseEvent mouseEvent) {\r
151         }\r
152         \r
153         public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {\r
154         }\r
155         \r
156         public void mouseReleased(java.awt.event.MouseEvent mouseEvent) {\r
157         }\r
158         \r
159         public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {\r
160                 CIDframe.setVisible(CIDframe.isVisible() == true ? false : true);\r
161         }\r
162         \r
163         public void mouseExited(java.awt.event.MouseEvent mouseEvent) {\r
164         }\r
165 }