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.util.Enumeration;
43 import java.util.Vector;
44 
45 /**
46   * This class is a top-level window with a title bar and window
47   * decorations.
48   *
49   * @author Aaron M. Renn (arenn@urbanophile.com)
50   */
51 public class Frame extends Window implements MenuContainer
52 {
53 
54 /*
55  * Static Variables
56  */
57 
58 /**
59   * Constant for the default cursor.
60   * @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead.
61   */
62 public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR;
63 
64 /**
65   * Constant for a cross-hair cursor.
66   * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead.
67   */
68 public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR;
69 
70 /**
71   * Constant for a cursor over a text field.
72   * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead.
73   */
74 public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR;
75 
76 /**
77   * Constant for a cursor to display while waiting for an action to complete.
78   * @deprecated Use <code>Cursor.WAIT_CURSOR</code>.
79   */
80 public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR;
81 
82 /**
83   * Cursor used over SW corner of window decorations.
84   * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead.
85   */
86 public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR;
87 
88 /**
89   * Cursor used over SE corner of window decorations.
90   * @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead.
91   */
92 public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR;
93 
94 /**
95   * Cursor used over NW corner of window decorations.
96   * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead.
97   */
98 public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR;
99 
100 /**
101   * Cursor used over NE corner of window decorations.
102   * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead.
103   */
104 public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR;
105 
106 /**
107   * Cursor used over N edge of window decorations.
108   * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead.
109   */
110 public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR;
111 
112 /**
113   * Cursor used over S edge of window decorations.
114   * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead.
115   */
116 public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR;
117 
118 /**
119   * Cursor used over E edge of window decorations.
120   * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead.
121   */
122 public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR;
123 
124 /**
125   * Cursor used over W edge of window decorations.
126   * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead.
127   */
128 public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR;
129 
130 /**
131   * Constant for a hand cursor.
132   * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead.
133   */
134 public static final int HAND_CURSOR = Cursor.HAND_CURSOR;
135 
136 /**
137   * Constant for a cursor used during window move operations.
138   * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead.
139   */
140 public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR;
141 
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;
147 
148 // Serialization version constant
149 private static final long serialVersionUID = 2673458971256075116L;
150 
151 /*************************************************************************/
152 
153 /*
154  * Instance Variables
155  */
156 
157 /**
158   * @serial The version of the class data being serialized
159   * // FIXME: what is this value?
160   */
161 private int frameSerializedDataVersion;
162 
163 /**
164   * @serial Image used as the icon when this frame is minimized.
165   */
166 private Image icon;
167 
168 /**
169   * @serial Constant used by the JDK Motif peer set.  Not used in
170   * this implementation.
171   */
172 private boolean mbManagement;
173 
174 /**
175   * @serial The menu bar for this frame.
176   */
177 //private MenuBar menuBar = new MenuBar();
178 private MenuBar menuBar;
179 
180 /**
181   * @serial A list of other top-level windows owned by this window.
182   */
183 Vector ownedWindows = new Vector();
184 
185 /**
186   * @serial Indicates whether or not this frame is resizable.
187   */
188 private boolean resizable = true;
189 
190 /**
191   * @serial The state of this frame.
192   * // FIXME: What are the values here?
193   */
194 private int state;
195 
196 /**
197   * @serial The title of the frame.
198   */
199 private String title = "";
200 
201   /**
202    * Maximized bounds for this frame.
203    */
204   private Rectangle maximizedBounds;
205 
206   /**
207    * This field indicates whether the frame is undecorated or not.
208    */
209   private boolean undecorated = false;
210 
211 /*************************************************************************/
212 
213 /*
214  * Constructors
215  */
216 
217 /**
218   * Initializes a new instance of <code>Frame</code> that is not visible
219   * and has no title.
220   */
221 public
Frame()222 Frame()
223 {
224   this("");
225 }
226 
227 /*************************************************************************/
228 
229 /**
230   * Initializes a new instance of <code>Frame</code> that is not visible
231   * and has the specified title.
232   *
233   * @param title The title of this frame.
234   */
235 public
Frame(String title)236 Frame(String title)
237 {
238   super();
239   this.title = title;
240   // Top-level frames are initially invisible.
241   visible = false;
242 }
243 
244 public
Frame(GraphicsConfiguration gc)245 Frame(GraphicsConfiguration gc)
246 {
247   super(gc);
248   visible = false;
249 }
250 
251 public
Frame(String title, GraphicsConfiguration gc)252 Frame(String title, GraphicsConfiguration gc)
253 {
254   super(gc);
255   setTitle(title);
256   visible = false;
257 }
258 
259 /*************************************************************************/
260 
261 /*
262  * Instance Methods
263  */
264 
265 /**
266   * Returns this frame's title string.
267   *
268   * @return This frame's title string.
269   */
270 public String
getTitle()271 getTitle()
272 {
273   return(title);
274 }
275 
276 /*************************************************************************/
277 
278 /*
279  * Sets this frame's title to the specified value.
280  *
281  * @param title The new frame title.
282  */
283 public synchronized void
setTitle(String title)284 setTitle(String title)
285 {
286   this.title = title;
287   if (peer != null)
288     ((FramePeer) peer).setTitle(title);
289 }
290 
291 /*************************************************************************/
292 
293 /**
294   * Returns this frame's icon.
295   *
296   * @return This frame's icon, or <code>null</code> if this frame does not
297   * have an icon.
298   */
299 public Image
getIconImage()300 getIconImage()
301 {
302   return(icon);
303 }
304 
305 /*************************************************************************/
306 
307 /**
308   * Sets this frame's icon to the specified value.
309   *
310   * @icon The new icon for this frame.
311   */
312 public synchronized void
setIconImage(Image icon)313 setIconImage(Image icon)
314 {
315   this.icon = icon;
316   if (peer != null)
317     ((FramePeer) peer).setIconImage(icon);
318 }
319 
320 /*************************************************************************/
321 
322 /**
323   * Returns this frame's menu bar.
324   *
325   * @return This frame's menu bar, or <code>null</code> if this frame
326   * does not have a menu bar.
327   */
328 public MenuBar
getMenuBar()329 getMenuBar()
330 {
331   return(menuBar);
332 }
333 
334 /*************************************************************************/
335 
336 /**
337   * Sets this frame's menu bar.
338   *
339   * @param menuBar The new menu bar for this frame.
340   */
341 public synchronized void
setMenuBar(MenuBar menuBar)342 setMenuBar(MenuBar menuBar)
343 {
344   this.menuBar = menuBar;
345   if (peer != null)
346     ((FramePeer) peer).setMenuBar(menuBar);
347 }
348 
349 /*************************************************************************/
350 
351 /**
352   * Tests whether or not this frame is resizable.  This will be
353   * <code>true</code> by default.
354   *
355   * @return <code>true</code> if this frame is resizable, <code>false</code>
356   * otherwise.
357   */
358 public boolean
isResizable()359 isResizable()
360 {
361   return(resizable);
362 }
363 
364 /*************************************************************************/
365 
366 /**
367   * Sets the resizability of this frame to the specified value.
368   *
369   * @param resizable <code>true</code> to make the frame resizable,
370   * <code>false</code> to make it non-resizable.
371   */
372 public synchronized void
setResizable(boolean resizable)373 setResizable(boolean resizable)
374 {
375   this.resizable = resizable;
376   if (peer != null)
377     ((FramePeer) peer).setResizable(resizable);
378 }
379 
380 /*************************************************************************/
381 
382 /**
383   * Returns the cursor type of the cursor for this window.  This will
384   * be one of the constants in this class.
385   *
386   * @return The cursor type for this frame.
387   *
388   * @deprecated Use <code>Component.getCursor()</code> instead.
389   */
390 public int
getCursorType()391 getCursorType()
392 {
393   return(getCursor().getType());
394 }
395 
396 /*************************************************************************/
397 
398 /**
399   * Sets the cursor for this window to the specified type.  The specified
400   * type should be one of the constants in this class.
401   *
402   * @param type The cursor type.
403   *
404   * @deprecated Use <code>Component.setCursor(Cursor)</code> instead.
405   */
406 public void
setCursor(int type)407 setCursor(int type)
408 {
409   setCursor(new Cursor(type));
410 }
411 
412 /*************************************************************************/
413 
414 /**
415   * Removes the specified component from this frame's menu.
416   *
417   * @param menu The menu component to remove.
418   */
419 public void
remove(MenuComponent menu)420 remove(MenuComponent menu)
421 {
422   menuBar.remove(menu);
423 }
424 
425 /*************************************************************************/
426 
427 /**
428   * Notifies this frame that it should create its native peer.
429   */
430 public void
addNotify()431 addNotify()
432 {
433   if (peer == null)
434     peer = getToolkit ().createFrame (this);
435   super.addNotify();
436 }
437 
438 /*************************************************************************/
439 
440 /**
441   * Returns a debugging string describing this window.
442   *
443   * @return A debugging string describing this window.
444   */
445 protected String
paramString()446 paramString()
447 {
448   return(getClass().getName());
449 }
450 
451 public static Frame[]
getFrames()452 getFrames()
453 {
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);
458 }
459 
setState(int state)460   public void setState (int state)
461   {
462     int current_state = getExtendedState ();
463 
464     if (state == NORMAL
465         && (current_state & ICONIFIED) != 0)
466       setExtendedState (current_state | ICONIFIED);
467 
468     if (state == ICONIFIED
469         && (current_state & ~ICONIFIED) == 0)
470       setExtendedState (current_state & ~ICONIFIED);
471   }
472 
getState()473   public int getState ()
474   {
475     /* FIXME: State might have changed in the peer... Must check. */
476 
477     return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL;
478   }
479 
480   /**
481    * @since 1.4
482    */
setExtendedState(int state)483   public void setExtendedState (int state)
484   {
485     this.state = state;
486   }
487 
488   /**
489    * @since 1.4
490    */
getExtendedState()491   public int getExtendedState ()
492   {
493     return state;
494   }
495 
496   /**
497    * @since 1.4
498    */
setMaximizedBounds(Rectangle maximizedBounds)499   public void setMaximizedBounds (Rectangle maximizedBounds)
500   {
501     this.maximizedBounds = maximizedBounds;
502   }
503 
504   /**
505    * Returns the maximized bounds of this frame.
506    *
507    * @return the maximized rectangle, may be null.
508    *
509    * @since 1.4
510    */
getMaximizedBounds()511   public Rectangle getMaximizedBounds ()
512   {
513     return maximizedBounds;
514   }
515 
516   /**
517    * Returns whether this frame is undecorated or not.
518    *
519    * @since 1.4
520    */
isUndecorated()521   public boolean isUndecorated ()
522   {
523     return undecorated;
524   }
525 
526   /**
527    * Disables or enables decorations for this frame. This method can only be
528    * called while the frame is not displayable.
529    *
530    * @exception IllegalComponentStateException If this frame is displayable.
531    *
532    * @since 1.4
533    */
setUndecorated(boolean undecorated)534   public void setUndecorated (boolean undecorated)
535   {
536     if (!isDisplayable ())
537       throw new IllegalComponentStateException ();
538 
539     this.undecorated = undecorated;
540   }
541 } // class Frame
542 
543