Source code: emc/animation/emcAnimationFrame.java
1 //******************************************************************************
2 // emcAnimationFrame.java:
3 //
4 //******************************************************************************
5 package emc.animation;
6
7 import java.awt.*;
8 import java.applet.Applet;
9
10
11 //==============================================================================
12 // STANDALONE APPLICATION SUPPORT
13 // This frame class acts as a top-level window in which the applet appears
14 // when it's run as a standalone application.
15 //==============================================================================
16 public class emcAnimationFrame extends Frame
17 {
18 Applet innerApplet = null;
19 Dimension prevSize = null;
20 static int nc_applet_frames = 0;
21 static public boolean in_an_applet = false;
22 static public boolean debug_on = false;
23
24 // emcAnimationFrame constructor
25 //--------------------------------------------------------------------------
26 public emcAnimationFrame(String str, Applet inner_applet)
27 {
28 super (str);
29 innerApplet = inner_applet;
30 prevSize = size();
31 nc_applet_frames++;
32 }
33
34 boolean resizing = false;
35
36 public void resizeInnerApplet()
37 {
38 if(resizing)
39 {
40 return;
41 }
42 resizing = true;
43 Dimension d = size();
44 int new_width = d.width;
45 int new_height = d.height;
46 if(new_width < 640 || new_height < 460)
47 {
48 if(new_width < 640)
49 {
50 new_width = 640;
51 }
52 if(new_height < 460)
53 {
54 new_height = 460;
55 }
56 resize(new_width,new_height);
57 }
58 if(Math.abs(prevSize.width - new_width) > 5 ||
59 Math.abs(prevSize.height - new_height) > 5)
60 {
61 invalidate();
62 if(debug_on)
63 {
64 System.out.println("emcAnimationFrame resizing to "+new_width+"X"+new_height);
65 }
66 removeAll();
67 Insets is = insets();
68 if(is.right < 10)
69 {
70 is.right = 10;
71 }
72 if(is.left < 10)
73 {
74 is.left = 10;
75 }
76 if(is.top < 10)
77 {
78 is.top = 10;
79 }
80 if(is.bottom < 10)
81 {
82 is.bottom = 10;
83 }
84 if(rcs.utils.BrowserInfo.IsNetscapeFourOrLater())
85 {
86 is.bottom += 30;
87 }
88 if(null != innerApplet)
89 {
90 innerApplet.resize(new_width - is.right - is.left,
91 new_height - is.top - is.bottom);
92 add("Center",innerApplet);
93 }
94 validate();
95 repaint();
96 }
97 prevSize = new Dimension(new_width, new_height);
98 resizing = false;
99 }
100
101
102 // The handleEvent() method receives all events generated within the frame
103 // window. You can use this method to respond to window events. To respond
104 // to events generated by menus, buttons, etc. or other controls in the
105 // frame window but not managed by the applet, override the window's
106 // action() method.
107 //--------------------------------------------------------------------------
108 public boolean handleEvent(Event evt)
109 {
110 //System.out.println("evt.id = "+evt.id);
111 switch (evt.id)
112 {
113 // Application shutdown (e.g. user chooses Close from the system menu).
114 //------------------------------------------------------------------
115 case Event.WINDOW_DESTROY:
116 dispose();
117 nc_applet_frames--;
118 if(nc_applet_frames <= 0 && !in_an_applet)
119 {
120 System.exit(0);
121 }
122 return true;
123
124 case Event.WINDOW_MOVED:
125 resizeInnerApplet();
126 return super.handleEvent(evt);
127
128 case Event.WINDOW_DEICONIFY:
129 resizeInnerApplet();
130 return super.handleEvent(evt);
131
132
133 case Event.MOUSE_ENTER:
134 resizeInnerApplet();
135 return super.handleEvent(evt);
136
137 case Event.MOUSE_EXIT:
138 resizeInnerApplet();
139 return super.handleEvent(evt);
140
141
142
143 default:
144 return super.handleEvent(evt);
145 }
146 }
147 }