1 /* Frame.java -- AWT toplevel window
2 Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
41 import java
.awt
.peer
.FramePeer
;
42 import java
.util
.Enumeration
;
43 import java
.util
.Vector
;
46 * This class is a top-level window with a title bar and window
49 * @author Aaron M. Renn (arenn@urbanophile.com)
51 public class Frame
extends Window
implements MenuContainer
59 * Constant for the default cursor.
60 * @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead.
62 public static final int DEFAULT_CURSOR
= Cursor
.DEFAULT_CURSOR
;
65 * Constant for a cross-hair cursor.
66 * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead.
68 public static final int CROSSHAIR_CURSOR
= Cursor
.CROSSHAIR_CURSOR
;
71 * Constant for a cursor over a text field.
72 * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead.
74 public static final int TEXT_CURSOR
= Cursor
.TEXT_CURSOR
;
77 * Constant for a cursor to display while waiting for an action to complete.
78 * @deprecated Use <code>Cursor.WAIT_CURSOR</code>.
80 public static final int WAIT_CURSOR
= Cursor
.WAIT_CURSOR
;
83 * Cursor used over SW corner of window decorations.
84 * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead.
86 public static final int SW_RESIZE_CURSOR
= Cursor
.SW_RESIZE_CURSOR
;
89 * Cursor used over SE corner of window decorations.
90 * @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead.
92 public static final int SE_RESIZE_CURSOR
= Cursor
.SE_RESIZE_CURSOR
;
95 * Cursor used over NW corner of window decorations.
96 * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead.
98 public static final int NW_RESIZE_CURSOR
= Cursor
.NW_RESIZE_CURSOR
;
101 * Cursor used over NE corner of window decorations.
102 * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead.
104 public static final int NE_RESIZE_CURSOR
= Cursor
.NE_RESIZE_CURSOR
;
107 * Cursor used over N edge of window decorations.
108 * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead.
110 public static final int N_RESIZE_CURSOR
= Cursor
.N_RESIZE_CURSOR
;
113 * Cursor used over S edge of window decorations.
114 * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead.
116 public static final int S_RESIZE_CURSOR
= Cursor
.S_RESIZE_CURSOR
;
119 * Cursor used over E edge of window decorations.
120 * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead.
122 public static final int E_RESIZE_CURSOR
= Cursor
.E_RESIZE_CURSOR
;
125 * Cursor used over W edge of window decorations.
126 * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead.
128 public static final int W_RESIZE_CURSOR
= Cursor
.W_RESIZE_CURSOR
;
131 * Constant for a hand cursor.
132 * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead.
134 public static final int HAND_CURSOR
= Cursor
.HAND_CURSOR
;
137 * Constant for a cursor used during window move operations.
138 * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead.
140 public static final int MOVE_CURSOR
= Cursor
.MOVE_CURSOR
;
142 public static final int ICONIFIED
= 1;
143 public static final int MAXIMIZED_BOTH
= 6;
144 public static final int MAXIMIZED_HORIZ
= 2;
145 public static final int MAXIMIZED_VERT
= 4;
146 public static final int NORMAL
= 0;
148 // Serialization version constant
149 private static final long serialVersionUID
= 2673458971256075116L;
151 /*************************************************************************/
158 * @serial The version of the class data being serialized
159 * // FIXME: what is this value?
161 private int frameSerializedDataVersion
;
164 * @serial Image used as the icon when this frame is minimized.
169 * @serial Constant used by the JDK Motif peer set. Not used in
170 * this implementation.
172 private boolean mbManagement
;
175 * @serial The menu bar for this frame.
177 //private MenuBar menuBar = new MenuBar();
178 private MenuBar menuBar
;
181 * @serial A list of other top-level windows owned by this window.
183 Vector ownedWindows
= new Vector();
186 * @serial Indicates whether or not this frame is resizable.
188 private boolean resizable
= true;
191 * @serial The state of this frame.
192 * // FIXME: What are the values here?
197 * @serial The title of the frame.
199 private String title
= "";
202 * Maximized bounds for this frame.
204 private Rectangle maximizedBounds
;
207 * This field indicates whether the frame is undecorated or not.
209 private boolean undecorated
= false;
211 /*************************************************************************/
218 * Initializes a new instance of <code>Frame</code> that is not visible
227 /*************************************************************************/
230 * Initializes a new instance of <code>Frame</code> that is not visible
231 * and has the specified title.
233 * @param title The title of this frame.
240 // Top-level frames are initially invisible.
245 Frame(GraphicsConfiguration gc
)
252 Frame(String title
, GraphicsConfiguration gc
)
259 /*************************************************************************/
266 * Returns this frame's title string.
268 * @return This frame's title string.
276 /*************************************************************************/
279 * Sets this frame's title to the specified value.
281 * @param title The new frame title.
283 public synchronized void
284 setTitle(String title
)
288 ((FramePeer
) peer
).setTitle(title
);
291 /*************************************************************************/
294 * Returns this frame's icon.
296 * @return This frame's icon, or <code>null</code> if this frame does not
305 /*************************************************************************/
308 * Sets this frame's icon to the specified value.
310 * @icon The new icon for this frame.
312 public synchronized void
313 setIconImage(Image icon
)
317 ((FramePeer
) peer
).setIconImage(icon
);
320 /*************************************************************************/
323 * Returns this frame's menu bar.
325 * @return This frame's menu bar, or <code>null</code> if this frame
326 * does not have a menu bar.
334 /*************************************************************************/
337 * Sets this frame's menu bar.
339 * @param menuBar The new menu bar for this frame.
341 public synchronized void
342 setMenuBar(MenuBar menuBar
)
344 this.menuBar
= menuBar
;
346 ((FramePeer
) peer
).setMenuBar(menuBar
);
349 /*************************************************************************/
352 * Tests whether or not this frame is resizable. This will be
353 * <code>true</code> by default.
355 * @return <code>true</code> if this frame is resizable, <code>false</code>
364 /*************************************************************************/
367 * Sets the resizability of this frame to the specified value.
369 * @param resizable <code>true</code> to make the frame resizable,
370 * <code>false</code> to make it non-resizable.
372 public synchronized void
373 setResizable(boolean resizable
)
375 this.resizable
= resizable
;
377 ((FramePeer
) peer
).setResizable(resizable
);
380 /*************************************************************************/
383 * Returns the cursor type of the cursor for this window. This will
384 * be one of the constants in this class.
386 * @return The cursor type for this frame.
388 * @deprecated Use <code>Component.getCursor()</code> instead.
393 return(getCursor().getType());
396 /*************************************************************************/
399 * Sets the cursor for this window to the specified type. The specified
400 * type should be one of the constants in this class.
402 * @param type The cursor type.
404 * @deprecated Use <code>Component.setCursor(Cursor)</code> instead.
409 setCursor(new Cursor(type
));
412 /*************************************************************************/
415 * Removes the specified component from this frame's menu.
417 * @param menu The menu component to remove.
420 remove(MenuComponent menu
)
422 menuBar
.remove(menu
);
425 /*************************************************************************/
428 * Notifies this frame that it should create its native peer.
434 peer
= getToolkit ().createFrame (this);
438 /*************************************************************************/
441 * Returns a debugging string describing this window.
443 * @return A debugging string describing this window.
448 return(getClass().getName());
451 public static Frame
[]
454 //Frame[] array = new Frames[frames.size()];
455 //return frames.toArray(array);
456 String msg
= "FIXME: can't be implemented without weak references";
457 throw new UnsupportedOperationException(msg
);
460 public void setState (int state
)
462 int current_state
= getExtendedState ();
465 && (current_state
& ICONIFIED
) != 0)
466 setExtendedState (current_state
| ICONIFIED
);
468 if (state
== ICONIFIED
469 && (current_state
& ~ICONIFIED
) == 0)
470 setExtendedState (current_state
& ~ICONIFIED
);
473 public int getState ()
475 /* FIXME: State might have changed in the peer... Must check. */
477 return (state
& ICONIFIED
) != 0 ? ICONIFIED
: NORMAL
;
483 public void setExtendedState (int state
)
491 public int getExtendedState ()
499 public void setMaximizedBounds (Rectangle maximizedBounds
)
501 this.maximizedBounds
= maximizedBounds
;
505 * Returns the maximized bounds of this frame.
507 * @return the maximized rectangle, may be null.
511 public Rectangle
getMaximizedBounds ()
513 return maximizedBounds
;
517 * Returns whether this frame is undecorated or not.
521 public boolean isUndecorated ()
527 * Disables or enables decorations for this frame. This method can only be
528 * called while the frame is not displayable.
530 * @exception IllegalComponentStateException If this frame is displayable.
534 public void setUndecorated (boolean undecorated
)
536 if (!isDisplayable ())
537 throw new IllegalComponentStateException ();
539 this.undecorated
= undecorated
;