OSDN Git Service

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