OSDN Git Service

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