2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / Frame.java
blobb6a34272449c38b74d0dd3003a4c49d0d8c636f9
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)
9 any later version.
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
19 02111-1307 USA.
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.
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. */
39 package java.awt;
41 import java.awt.peer.FramePeer;
42 import java.util.Enumeration;
43 import java.util.Vector;
45 /**
46 * This class is a top-level window with a title bar and window
47 * decorations.
49 * @author Aaron M. Renn (arenn@urbanophile.com)
51 public class Frame extends Window implements MenuContainer
55 * Static Variables
58 /**
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;
64 /**
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;
70 /**
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;
76 /**
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;
82 /**
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;
88 /**
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;
94 /**
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 /*************************************************************************/
154 * Instance Variables
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.
166 private Image icon;
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?
194 private int state;
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 /*************************************************************************/
214 * Constructors
218 * Initializes a new instance of <code>Frame</code> that is not visible
219 * and has no title.
221 public
222 Frame()
224 this("");
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.
235 public
236 Frame(String title)
238 super();
239 this.title = title;
240 // Top-level frames are initially invisible.
241 visible = false;
244 public
245 Frame(GraphicsConfiguration gc)
247 super(gc);
248 visible = false;
251 public
252 Frame(String title, GraphicsConfiguration gc)
254 super(gc);
255 setTitle(title);
256 visible = false;
259 /*************************************************************************/
262 * Instance Methods
266 * Returns this frame's title string.
268 * @return This frame's title string.
270 public String
271 getTitle()
273 return(title);
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)
286 this.title = title;
287 if (peer != null)
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
297 * have an icon.
299 public Image
300 getIconImage()
302 return(icon);
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)
315 this.icon = icon;
316 if (peer != null)
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.
328 public MenuBar
329 getMenuBar()
331 return(menuBar);
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;
345 if (peer != null)
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>
356 * otherwise.
358 public boolean
359 isResizable()
361 return(resizable);
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;
376 if (peer != null)
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.
390 public int
391 getCursorType()
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.
406 public void
407 setCursor(int type)
409 setCursor(new Cursor(type));
412 /*************************************************************************/
415 * Removes the specified component from this frame's menu.
417 * @param menu The menu component to remove.
419 public void
420 remove(MenuComponent menu)
422 menuBar.remove(menu);
425 /*************************************************************************/
428 * Notifies this frame that it should create its native peer.
430 public void
431 addNotify()
433 if (peer == null)
434 peer = getToolkit ().createFrame (this);
435 super.addNotify();
438 /*************************************************************************/
441 * Returns a debugging string describing this window.
443 * @return A debugging string describing this window.
445 protected String
446 paramString()
448 return(getClass().getName());
451 public static Frame[]
452 getFrames()
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 ();
464 if (state == NORMAL
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;
481 * @since 1.4
483 public void setExtendedState (int state)
485 this.state = state;
489 * @since 1.4
491 public int getExtendedState ()
493 return state;
497 * @since 1.4
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.
509 * @since 1.4
511 public Rectangle getMaximizedBounds ()
513 return maximizedBounds;
517 * Returns whether this frame is undecorated or not.
519 * @since 1.4
521 public boolean isUndecorated ()
523 return undecorated;
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.
532 * @since 1.4
534 public void setUndecorated (boolean undecorated)
536 if (!isDisplayable ())
537 throw new IllegalComponentStateException ();
539 this.undecorated = undecorated;
541 } // class Frame