Source code: emc/gui/NCappletFrame.java
1 //******************************************************************************
2 // NCappletFrame.java:
3 //
4 //******************************************************************************
5 package emc.gui;
6
7 import java.awt.*;
8 import java.awt.event.*;
9 import java.applet.Applet;
10
11
12 //==============================================================================
13 // STANDALONE APPLICATION SUPPORT
14 // This frame class acts as a top-level window in which the applet appears
15 // when it's run as a standalone application.
16 //==============================================================================
17 class NCappletFrame extends Frame implements WindowListener
18 {
19 Applet innerApplet = null;
20 Dimension prevSize = null;
21 static int nc_applet_frames = 0;
22 static public boolean in_an_applet = false;
23 static public boolean debug_on = false;
24
25 // NCappletFrame constructor
26 //--------------------------------------------------------------------------
27 public NCappletFrame(String str, Applet inner_applet)
28 {
29 super (str);
30 innerApplet = inner_applet;
31 prevSize = getSize();
32 nc_applet_frames++;
33 // Disable any unneccessary EVENTS
34 enableEvents(AWTEvent.ACTION_EVENT_MASK |
35 AWTEvent.ADJUSTMENT_EVENT_MASK |
36 AWTEvent.ADJUSTMENT_EVENT_MASK |
37 AWTEvent.COMPONENT_EVENT_MASK |
38 AWTEvent.CONTAINER_EVENT_MASK |
39 AWTEvent.FOCUS_EVENT_MASK |
40 AWTEvent.ITEM_EVENT_MASK |
41 AWTEvent.KEY_EVENT_MASK |
42 AWTEvent.MOUSE_EVENT_MASK |
43 AWTEvent.MOUSE_MOTION_EVENT_MASK |
44 AWTEvent.TEXT_EVENT_MASK |
45 AWTEvent.WINDOW_EVENT_MASK);
46
47 disableEvents(AWTEvent.ACTION_EVENT_MASK |
48 AWTEvent.ADJUSTMENT_EVENT_MASK |
49 AWTEvent.ADJUSTMENT_EVENT_MASK |
50 AWTEvent.COMPONENT_EVENT_MASK |
51 AWTEvent.CONTAINER_EVENT_MASK |
52 AWTEvent.FOCUS_EVENT_MASK |
53 AWTEvent.ITEM_EVENT_MASK |
54 AWTEvent.KEY_EVENT_MASK |
55 AWTEvent.MOUSE_EVENT_MASK |
56 AWTEvent.MOUSE_MOTION_EVENT_MASK |
57 AWTEvent.TEXT_EVENT_MASK |
58 AWTEvent.WINDOW_EVENT_MASK);
59
60
61 addWindowListener(this);
62 }
63
64 boolean resizing = false;
65
66 public void resizeInnerApplet()
67 {
68 if(resizing)
69 {
70 return;
71 }
72 resizing = true;
73 Dimension d = getSize();
74 int new_width = d.width;
75 int new_height = d.height;
76 if(new_width < 640 || new_height < 460)
77 {
78 if(new_width < 640)
79 {
80 new_width = 640;
81 }
82 if(new_height < 460)
83 {
84 new_height = 460;
85 }
86 setSize(new_width,new_height);
87 }
88 if(Math.abs(prevSize.width - new_width) > 5 ||
89 Math.abs(prevSize.height - new_height) > 5)
90 {
91 invalidate();
92 if(debug_on)
93 {
94 System.out.println("NCappletFrame resizing to "+new_width+"X"+new_height);
95 }
96 removeAll();
97 Insets is = getInsets();
98 if(is.right < 10)
99 {
100 is.right = 10;
101 }
102 if(is.left < 10)
103 {
104 is.left = 10;
105 }
106 if(is.top < 10)
107 {
108 is.top = 10;
109 }
110 if(is.bottom < 10)
111 {
112 is.bottom = 10;
113 }
114 if(rcs.utils.BrowserInfo.IsNetscapeFourOrLater())
115 {
116 is.bottom += 30;
117 }
118 if(null != innerApplet)
119 {
120 innerApplet.resize(new_width - is.right - is.left,
121 new_height - is.top - is.bottom);
122 add("Center",innerApplet);
123 }
124 validate();
125 repaint();
126 }
127 prevSize = new Dimension(new_width, new_height);
128 resizing = false;
129 }
130
131
132 /*
133 * The functions windowOpened, windowClosing, windowClosed, windowActivated,
134 * windowDeactivated, windowIconified, and windowDeiconified are needed
135 * to implement WindowListener and basically replace handleEvent from JDK 1.0.x
136 *
137 */
138
139 public void windowOpened(WindowEvent evt)
140 {
141 resizeInnerApplet();
142 }
143
144 public void windowClosing(WindowEvent evt)
145 {
146 try
147 {
148 if(null != innerApplet)
149 {
150 innerApplet.stop();
151 innerApplet = null;
152 removeAll();
153 }
154 }
155 catch(Exception e)
156 {
157 e.printStackTrace();
158 }
159 try
160 {
161 dispose();
162 }
163 catch(Exception e)
164 {
165 e.printStackTrace();
166 }
167 }
168
169 public void windowClosed(WindowEvent evt)
170 {
171 try
172 {
173 nc_applet_frames--;
174 if(nc_applet_frames <= 0 && !in_an_applet)
175 {
176 System.exit(0);
177 }
178 }
179 catch(Exception e)
180 {
181 e.printStackTrace();
182 }
183 }
184
185 public void windowIconified(WindowEvent evt)
186 {
187 }
188
189 public void windowDeiconified(WindowEvent evt)
190 {
191 resizeInnerApplet();
192 }
193
194 public void windowActivated(WindowEvent evt)
195 {
196 resizeInnerApplet();
197 }
198
199 public void windowDeactivated(WindowEvent evt)
200 {
201 resizeInnerApplet();
202 }
203 }