Source code: rcsdesign/rcsdesignFrame.java
1 //******************************************************************************
2 // rcsdesignFrame.java:
3 //
4 //******************************************************************************
5 package rcsdesign;
6
7 import java.awt.*;
8 import java.awt.event.*;
9 import java.applet.*;
10 import diagapplet.utils.StandAloneApplet;
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 rcsdesignFrame extends Frame implements WindowListener
18 {
19 public static boolean debug_on = false;
20 StandAloneApplet innerApplet = null;
21 Dimension prevSize = null;
22 static int rcsDesign_frames = 0;
23 static public boolean in_an_applet = false;
24 InnerAppletRepainter repainter = null;
25 public boolean ready_for_resizing = false;
26 public static boolean force_it=false;
27
28 // rcsdesignFrame constructor
29 //--------------------------------------------------------------------------
30 public rcsdesignFrame(String str)
31 {
32 super (str);
33 prevSize = getSize();
34 rcsDesign_frames++;
35 addWindowListener(this);
36 }
37
38 boolean inside_manual_resize = false;
39
40 public synchronized void manual_resize(int new_width, int new_height)
41 {
42 inside_manual_resize = true;
43 setSize(new_width, new_height);
44 int tries = 0;
45 if(debug_on)
46 {
47 System.out.println("rcsdesignFrame resizing from "+prevSize.width+"x"+prevSize.height+" to "+new_width+"x"+new_height);
48 }
49 Dimension d = getSize();
50 while(tries < 20 &&
51 d.width != new_width && d.height != new_height)
52 {
53 try
54 {
55 Thread.sleep(50);
56 d = getSize();
57 tries++;
58 setSize(new_width, new_height);
59 if(debug_on)
60 {
61 System.out.println("d = rcsdesignFrame.size() = "+d);
62 }
63 }
64 catch(Exception e)
65 {
66 }
67 }
68 prevSize = new Dimension(new_width, new_height);
69 inside_manual_resize = false;
70 }
71
72 public synchronized void resizeInnerApplet()
73 {
74 if(!ready_for_resizing && !force_it)
75 {
76 if(debug_on)
77 {
78 System.out.println("rcsdesignFrame.resizeInnerApplet(): !ready_for_resizing");
79 }
80 return;
81 }
82 if(inside_manual_resize)
83 {
84 if(debug_on)
85 {
86 System.out.println("rcsdesignFrame.resizeInnerApplet(): !inside_manual_resize");
87 }
88 return;
89 }
90 Dimension d = getSize();
91 if(debug_on)
92 {
93 System.out.println("rcsdesignFrame.resizeInnerApplet() to "+d.width+"x"+d.height);
94 }
95 int new_width = d.width;
96 int new_height = d.height;
97 boolean need_resize = false;
98 if(new_width < 640 || new_height < 480)
99 {
100 if(new_width < 640)
101 {
102 new_width = 640;
103 }
104 if(new_height < 480)
105 {
106 new_height = 480;
107 }
108 need_resize = true;
109 }
110 Toolkit tk = Toolkit.getDefaultToolkit();
111 if(null != tk)
112 {
113 Dimension screen_size = tk.getScreenSize();
114
115 int tries = 0;
116 while(tries < 20 &&
117 (screen_size.height < 1 || screen_size.width < 1))
118 {
119 try
120 {
121 Thread.sleep(50);
122 }
123 catch(Exception e)
124 {
125 e.printStackTrace();
126 }
127 tries++;
128 screen_size = tk.getScreenSize();
129 }
130 if(screen_size.width > 20 && new_width > (screen_size.width-20))
131 {
132 new_width = screen_size.width-20;
133 need_resize = true;
134 }
135 if(screen_size.height > 20 && new_height > (screen_size.height-20))
136 {
137 new_height = screen_size.height-20;
138 need_resize = true;
139 }
140 }
141 if(need_resize)
142 {
143 setSize(new_width,new_height);
144 }
145
146 if(debug_on)
147 {
148 System.out.println("prevSize.width="+prevSize.width);
149 System.out.println("prevSize.height="+prevSize.height);
150 }
151 if(((Math.abs(prevSize.width - new_width) > 35 ||
152 Math.abs(prevSize.height - new_height) > 35)
153 &&
154 (new_width < prevSize.width || prevSize.width < 1000
155 || new_height < prevSize.height || prevSize.height < 800)) ||
156 force_it)
157 {
158 force_it=false;
159 if(null != innerApplet)
160 {
161 if(innerApplet.debug_on)
162 {
163 System.out.println("rcsdesignFrame resizing from "+prevSize.width+"x"+prevSize.height+" to "+new_width+"x"+new_height);
164 }
165 }
166 Insets is = getInsets();
167 setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
168 if(is.right < 10)
169 {
170 is.right = 10;
171 }
172 if(is.left < 10)
173 {
174 is.left = 10;
175 }
176 if(is.top < 10)
177 {
178 is.top = 10;
179 }
180 if(is.bottom < 10)
181 {
182 is.bottom = 10;
183 }
184 if(rcs.utils.BrowserInfo.IsNetscapeFourOrLater())
185 {
186 is.bottom += 30;
187 }
188 if(debug_on)
189 {
190 System.out.println("innerApplet = "+innerApplet);
191 }
192 if(null != innerApplet)
193 {
194 invalidate();
195 removeAll();
196 innerApplet.inside_resizeable_window = true;
197 innerApplet.manual_resize(new_width - is.right - is.left-25,
198 new_height - is.top - is.bottom-15);
199 add("Center",innerApplet);
200 innerApplet.setVisible(true);
201 innerApplet.repaint();
202 repainter = new InnerAppletRepainter(innerApplet,100,1000);
203 repainter.start();
204 }
205 prevSize = getSize();
206 pack();
207 }
208 prevSize = getSize();
209 }
210
211 /*
212 * The functions windowOpened, windowClosing, windowClosed, windowActivated,
213 * windowDeactivated, windowIconified, and windowDeiconified are needed
214 * to implement WindowListener and basically replace handleEvent from JDK 1.0.x
215 *
216 */
217
218 public void windowOpened(WindowEvent evt)
219 {
220 resizeInnerApplet();
221 }
222
223 public void windowClosing(WindowEvent evt)
224 {
225 try
226 {
227 if(null != innerApplet)
228 {
229 innerApplet.startShutdown();
230 }
231 else
232 {
233 dispose();
234 }
235 }
236 catch(Exception e)
237 {
238 e.printStackTrace();
239 }
240 }
241
242 public void windowClosed(WindowEvent evt)
243 {
244 try
245 {
246 rcsDesign_frames--;
247 if(rcsDesign_frames <= 0 && !in_an_applet)
248 {
249 System.exit(0);
250 }
251 }
252 catch(Exception e)
253 {
254 e.printStackTrace();
255 }
256 }
257
258 public void windowIconified(WindowEvent evt)
259 {
260 }
261
262 public void windowDeiconified(WindowEvent evt)
263 {
264 resizeInnerApplet();
265 }
266
267 public void windowActivated(WindowEvent evt)
268 {
269 resizeInnerApplet();
270 }
271
272 public void windowDeactivated(WindowEvent evt)
273 {
274 resizeInnerApplet();
275 }
276 }
277
278
279