1 | /* Frame.java -- AWT toplevel window
|
---|
2 | Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
6 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA.
|
---|
20 |
|
---|
21 | Linking this library statically or dynamically with other modules is
|
---|
22 | making a combined work based on this library. Thus, the terms and
|
---|
23 | conditions of the GNU General Public License cover the whole
|
---|
24 | combination.
|
---|
25 |
|
---|
26 | As a special exception, the copyright holders of this library give you
|
---|
27 | permission to link this library with independent modules to produce an
|
---|
28 | executable, regardless of the license terms of these independent
|
---|
29 | modules, and to copy and distribute the resulting executable under
|
---|
30 | terms of your choice, provided that you also meet, for each linked
|
---|
31 | independent module, the terms and conditions of the license of that
|
---|
32 | module. An independent module is a module which is not derived from
|
---|
33 | or based on this library. If you modify this library, you may extend
|
---|
34 | this exception to your version of the library, but you are not
|
---|
35 | obligated to do so. If you do not wish to do so, delete this
|
---|
36 | exception statement from your version. */
|
---|
37 |
|
---|
38 |
|
---|
39 | package java.awt;
|
---|
40 |
|
---|
41 | import java.awt.peer.FramePeer;
|
---|
42 | import java.awt.peer.WindowPeer;
|
---|
43 | import java.awt.peer.ContainerPeer;
|
---|
44 | import java.awt.peer.ComponentPeer;
|
---|
45 | import java.io.Serializable;
|
---|
46 | import java.util.Enumeration;
|
---|
47 | import java.util.Vector;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * This class is a top-level window with a title bar and window
|
---|
51 | * decorations.
|
---|
52 | *
|
---|
53 | * @author Aaron M. Renn (arenn@urbanophile.com)
|
---|
54 | */
|
---|
55 | public class Frame extends Window implements MenuContainer, Serializable
|
---|
56 | {
|
---|
57 |
|
---|
58 | /*
|
---|
59 | * Static Variables
|
---|
60 | */
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Constant for the default cursor.
|
---|
64 | * Deprecated. replaced by <code>Cursor.DEFAULT_CURSOR</code> instead.
|
---|
65 | */
|
---|
66 | public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Constant for a cross-hair cursor.
|
---|
70 | * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead.
|
---|
71 | */
|
---|
72 | public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR;
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Constant for a cursor over a text field.
|
---|
76 | * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead.
|
---|
77 | */
|
---|
78 | public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR;
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Constant for a cursor to display while waiting for an action to complete.
|
---|
82 | * @deprecated Use <code>Cursor.WAIT_CURSOR</code>.
|
---|
83 | */
|
---|
84 | public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR;
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Cursor used over SW corner of window decorations.
|
---|
88 | * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead.
|
---|
89 | */
|
---|
90 | public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Cursor used over SE corner of window decorations.
|
---|
94 | * @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead.
|
---|
95 | */
|
---|
96 | public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR;
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Cursor used over NW corner of window decorations.
|
---|
100 | * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead.
|
---|
101 | */
|
---|
102 | public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR;
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Cursor used over NE corner of window decorations.
|
---|
106 | * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead.
|
---|
107 | */
|
---|
108 | public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR;
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Cursor used over N edge of window decorations.
|
---|
112 | * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead.
|
---|
113 | */
|
---|
114 | public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Cursor used over S edge of window decorations.
|
---|
118 | * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead.
|
---|
119 | */
|
---|
120 | public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR;
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Cursor used over E edge of window decorations.
|
---|
124 | * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead.
|
---|
125 | */
|
---|
126 | public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR;
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Cursor used over W edge of window decorations.
|
---|
130 | * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead.
|
---|
131 | */
|
---|
132 | public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR;
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Constant for a hand cursor.
|
---|
136 | * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead.
|
---|
137 | */
|
---|
138 | public static final int HAND_CURSOR = Cursor.HAND_CURSOR;
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Constant for a cursor used during window move operations.
|
---|
142 | * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead.
|
---|
143 | */
|
---|
144 | public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR;
|
---|
145 |
|
---|
146 | public static final int ICONIFIED = 1;
|
---|
147 | public static final int MAXIMIZED_BOTH = 6;
|
---|
148 | public static final int MAXIMIZED_HORIZ = 2;
|
---|
149 | public static final int MAXIMIZED_VERT = 4;
|
---|
150 | public static final int NORMAL = 0;
|
---|
151 |
|
---|
152 | // Serialization version constant
|
---|
153 | private static final long serialVersionUID = 2673458971256075116L;
|
---|
154 |
|
---|
155 | /*************************************************************************/
|
---|
156 |
|
---|
157 | /*
|
---|
158 | * Instance Variables
|
---|
159 | */
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * @serial The version of the class data being serialized
|
---|
163 | * // FIXME: what is this value?
|
---|
164 | */
|
---|
165 | private int frameSerializedDataVersion;
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * @serial Image used as the icon when this frame is minimized.
|
---|
169 | */
|
---|
170 | private Image icon;
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * @serial Constant used by the JDK Motif peer set. Not used in
|
---|
174 | * this implementation.
|
---|
175 | */
|
---|
176 | private boolean mbManagement;
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * @serial The menu bar for this frame.
|
---|
180 | */
|
---|
181 | //private MenuBar menuBar = new MenuBar();
|
---|
182 | private MenuBar menuBar;
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * @serial A list of other top-level windows owned by this window.
|
---|
186 | */
|
---|
187 | Vector ownedWindows = new Vector();
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * @serial Indicates whether or not this frame is resizable.
|
---|
191 | */
|
---|
192 | private boolean resizable = true;
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * @serial The state of this frame.
|
---|
196 | * // FIXME: What are the values here?
|
---|
197 | */
|
---|
198 | private int state;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * @serial The title of the frame.
|
---|
202 | */
|
---|
203 | private String title = "";
|
---|
204 |
|
---|
205 | /*************************************************************************/
|
---|
206 |
|
---|
207 | /*
|
---|
208 | * Constructors
|
---|
209 | */
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Initializes a new instance of <code>Frame</code> that is not visible
|
---|
213 | * and has no title.
|
---|
214 | */
|
---|
215 | public
|
---|
216 | Frame()
|
---|
217 | {
|
---|
218 | this("");
|
---|
219 | }
|
---|
220 |
|
---|
221 | /*************************************************************************/
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * Initializes a new instance of <code>Frame</code> that is not visible
|
---|
225 | * and has the specified title.
|
---|
226 | *
|
---|
227 | * @param title The title of this frame.
|
---|
228 | */
|
---|
229 | public
|
---|
230 | Frame(String title)
|
---|
231 | {
|
---|
232 | super();
|
---|
233 | this.title = title;
|
---|
234 | }
|
---|
235 |
|
---|
236 | public
|
---|
237 | Frame(GraphicsConfiguration gc)
|
---|
238 | {
|
---|
239 | super(gc);
|
---|
240 | }
|
---|
241 |
|
---|
242 | public
|
---|
243 | Frame(String title, GraphicsConfiguration gc)
|
---|
244 | {
|
---|
245 | super(gc);
|
---|
246 | setTitle(title);
|
---|
247 | }
|
---|
248 |
|
---|
249 | /*************************************************************************/
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * Instance Methods
|
---|
253 | */
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Returns this frame's title string.
|
---|
257 | *
|
---|
258 | * @return This frame's title string.
|
---|
259 | */
|
---|
260 | public String
|
---|
261 | getTitle()
|
---|
262 | {
|
---|
263 | return(title);
|
---|
264 | }
|
---|
265 |
|
---|
266 | /*************************************************************************/
|
---|
267 |
|
---|
268 | /*
|
---|
269 | * Sets this frame's title to the specified value.
|
---|
270 | *
|
---|
271 | * @param title The new frame title.
|
---|
272 | */
|
---|
273 | public synchronized void
|
---|
274 | setTitle(String title)
|
---|
275 | {
|
---|
276 | this.title = title;
|
---|
277 | if (peer != null)
|
---|
278 | ((FramePeer) peer).setTitle(title);
|
---|
279 | }
|
---|
280 |
|
---|
281 | /*************************************************************************/
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Returns this frame's icon.
|
---|
285 | *
|
---|
286 | * @return This frame's icon, or <code>null</code> if this frame does not
|
---|
287 | * have an icon.
|
---|
288 | */
|
---|
289 | public Image
|
---|
290 | getIconImage()
|
---|
291 | {
|
---|
292 | return(icon);
|
---|
293 | }
|
---|
294 |
|
---|
295 | /*************************************************************************/
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * Sets this frame's icon to the specified value.
|
---|
299 | *
|
---|
300 | * @icon The new icon for this frame.
|
---|
301 | */
|
---|
302 | public synchronized void
|
---|
303 | setIconImage(Image icon)
|
---|
304 | {
|
---|
305 | this.icon = icon;
|
---|
306 | if (peer != null)
|
---|
307 | ((FramePeer) peer).setIconImage(icon);
|
---|
308 | }
|
---|
309 |
|
---|
310 | /*************************************************************************/
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Returns this frame's menu bar.
|
---|
314 | *
|
---|
315 | * @return This frame's menu bar, or <code>null</code> if this frame
|
---|
316 | * does not have a menu bar.
|
---|
317 | */
|
---|
318 | public MenuBar
|
---|
319 | getMenuBar()
|
---|
320 | {
|
---|
321 | return(menuBar);
|
---|
322 | }
|
---|
323 |
|
---|
324 | /*************************************************************************/
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Sets this frame's menu bar.
|
---|
328 | *
|
---|
329 | * @param menuBar The new menu bar for this frame.
|
---|
330 | */
|
---|
331 | public synchronized void
|
---|
332 | setMenuBar(MenuBar menuBar)
|
---|
333 | {
|
---|
334 | this.menuBar = menuBar;
|
---|
335 | if (peer != null)
|
---|
336 | ((FramePeer) peer).setMenuBar(menuBar);
|
---|
337 | }
|
---|
338 |
|
---|
339 | /*************************************************************************/
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * Tests whether or not this frame is resizable. This will be
|
---|
343 | * <code>true</code> by default.
|
---|
344 | *
|
---|
345 | * @return <code>true</code> if this frame is resizable, <code>false</code>
|
---|
346 | * otherwise.
|
---|
347 | */
|
---|
348 | public boolean
|
---|
349 | isResizable()
|
---|
350 | {
|
---|
351 | return(resizable);
|
---|
352 | }
|
---|
353 |
|
---|
354 | /*************************************************************************/
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Sets the resizability of this frame to the specified value.
|
---|
358 | *
|
---|
359 | * @param resizable <code>true</code> to make the frame resizable,
|
---|
360 | * <code>false</code> to make it non-resizable.
|
---|
361 | */
|
---|
362 | public synchronized void
|
---|
363 | setResizable(boolean resizable)
|
---|
364 | {
|
---|
365 | this.resizable = resizable;
|
---|
366 | if (peer != null)
|
---|
367 | ((FramePeer) peer).setResizable(resizable);
|
---|
368 | }
|
---|
369 |
|
---|
370 | /*************************************************************************/
|
---|
371 |
|
---|
372 | /**
|
---|
373 | * Returns the cursor type of the cursor for this window. This will
|
---|
374 | * be one of the constants in this class.
|
---|
375 | *
|
---|
376 | * @return The cursor type for this frame.
|
---|
377 | *
|
---|
378 | * @deprecated Use <code>Component.getCursor()</code> instead.
|
---|
379 | */
|
---|
380 | public int
|
---|
381 | getCursorType()
|
---|
382 | {
|
---|
383 | return(getCursor().getType());
|
---|
384 | }
|
---|
385 |
|
---|
386 | /*************************************************************************/
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Sets the cursor for this window to the specified type. The specified
|
---|
390 | * type should be one of the constants in this class.
|
---|
391 | *
|
---|
392 | * @param type The cursor type.
|
---|
393 | *
|
---|
394 | * @deprecated. Use <code>Component.setCursor(Cursor)</code> instead.
|
---|
395 | */
|
---|
396 | public void
|
---|
397 | setCursor(int type)
|
---|
398 | {
|
---|
399 | setCursor(new Cursor(type));
|
---|
400 | }
|
---|
401 |
|
---|
402 | /*************************************************************************/
|
---|
403 |
|
---|
404 | /**
|
---|
405 | * Removes the specified component from this frame's menu.
|
---|
406 | *
|
---|
407 | * @param menu The menu component to remove.
|
---|
408 | */
|
---|
409 | public void
|
---|
410 | remove(MenuComponent menu)
|
---|
411 | {
|
---|
412 | menuBar.remove(menu);
|
---|
413 | }
|
---|
414 |
|
---|
415 | /*************************************************************************/
|
---|
416 |
|
---|
417 | /**
|
---|
418 | * Notifies this frame that it should create its native peer.
|
---|
419 | */
|
---|
420 | public void
|
---|
421 | addNotify()
|
---|
422 | {
|
---|
423 | if (peer == null)
|
---|
424 | peer = getToolkit ().createFrame (this);
|
---|
425 | super.addNotify();
|
---|
426 | }
|
---|
427 |
|
---|
428 | /*************************************************************************/
|
---|
429 |
|
---|
430 | /**
|
---|
431 | * Destroys any resources associated with this frame. This includes
|
---|
432 | * all components in the frame and all owned toplevel windows.
|
---|
433 | */
|
---|
434 | public void
|
---|
435 | dispose()
|
---|
436 | {
|
---|
437 | Enumeration e = ownedWindows.elements();
|
---|
438 | while(e.hasMoreElements())
|
---|
439 | {
|
---|
440 | Window w = (Window)e.nextElement();
|
---|
441 | w.dispose();
|
---|
442 | }
|
---|
443 |
|
---|
444 | super.dispose();
|
---|
445 | }
|
---|
446 |
|
---|
447 | /*************************************************************************/
|
---|
448 |
|
---|
449 | /**
|
---|
450 | * Returns a debugging string describing this window.
|
---|
451 | *
|
---|
452 | * @return A debugging string describing this window.
|
---|
453 | */
|
---|
454 | protected String
|
---|
455 | paramString()
|
---|
456 | {
|
---|
457 | return(getClass().getName());
|
---|
458 | }
|
---|
459 |
|
---|
460 | public int
|
---|
461 | getState()
|
---|
462 | {
|
---|
463 | /* FIXME: State might have changed in the peer... Must check. */
|
---|
464 |
|
---|
465 | return state;
|
---|
466 | }
|
---|
467 |
|
---|
468 | public static Frame[]
|
---|
469 | getFrames()
|
---|
470 | {
|
---|
471 | //Frame[] array = new Frames[frames.size()];
|
---|
472 | //return frames.toArray(array);
|
---|
473 |
|
---|
474 | // see finalize() comment
|
---|
475 | String msg = "FIXME: can't be implemented without weak references";
|
---|
476 | throw new UnsupportedOperationException(msg);
|
---|
477 | }
|
---|
478 |
|
---|
479 | } // class Frame
|
---|
480 |
|
---|