Frame.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /* Frame.java -- AWT toplevel window
  2. Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt;
  32. import java.awt.peer.FramePeer;
  33. import java.awt.peer.WindowPeer;
  34. import java.awt.peer.ContainerPeer;
  35. import java.awt.peer.ComponentPeer;
  36. import java.io.Serializable;
  37. import java.util.Enumeration;
  38. import java.util.Vector;
  39. /**
  40. * This class is a top-level window with a title bar and window
  41. * decorations.
  42. *
  43. * @author Aaron M. Renn (arenn@urbanophile.com)
  44. */
  45. public class Frame extends Window implements MenuContainer, Serializable
  46. {
  47. /*
  48. * Static Variables
  49. */
  50. /**
  51. * Constant for the default cursor.
  52. * Deprecated. replaced by <code>Cursor.DEFAULT_CURSOR</code> instead.
  53. */
  54. public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR;
  55. /**
  56. * Constant for a cross-hair cursor.
  57. * @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead.
  58. */
  59. public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR;
  60. /**
  61. * Constant for a cursor over a text field.
  62. * @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead.
  63. */
  64. public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR;
  65. /**
  66. * Constant for a cursor to display while waiting for an action to complete.
  67. * @deprecated Use <code>Cursor.WAIT_CURSOR</code>.
  68. */
  69. public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR;
  70. /**
  71. * Cursor used over SW corner of window decorations.
  72. * @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead.
  73. */
  74. public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR;
  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. * Cursor used over NW corner of window decorations.
  82. * @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead.
  83. */
  84. public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR;
  85. /**
  86. * Cursor used over NE corner of window decorations.
  87. * @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead.
  88. */
  89. public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR;
  90. /**
  91. * Cursor used over N edge of window decorations.
  92. * @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead.
  93. */
  94. public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR;
  95. /**
  96. * Cursor used over S edge of window decorations.
  97. * @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead.
  98. */
  99. public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR;
  100. /**
  101. * Cursor used over E edge of window decorations.
  102. * @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead.
  103. */
  104. public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR;
  105. /**
  106. * Cursor used over W edge of window decorations.
  107. * @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead.
  108. */
  109. public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR;
  110. /**
  111. * Constant for a hand cursor.
  112. * @deprecated Use <code>Cursor.HAND_CURSOR</code> instead.
  113. */
  114. public static final int HAND_CURSOR = Cursor.HAND_CURSOR;
  115. /**
  116. * Constant for a cursor used during window move operations.
  117. * @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead.
  118. */
  119. public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR;
  120. public static final int ICONIFIED = 1;
  121. public static final int MAXIMIZED_BOTH = 6;
  122. public static final int MAXIMIZED_HORIZ = 2;
  123. public static final int MAXIMIZED_VERT = 4;
  124. public static final int NORMAL = 0;
  125. // Serialization version constant
  126. private static final long serialVersionUID = 2673458971256075116L;
  127. /*************************************************************************/
  128. /*
  129. * Instance Variables
  130. */
  131. /**
  132. * @serial The version of the class data being serialized
  133. * // FIXME: what is this value?
  134. */
  135. private int frameSerializedDataVersion;
  136. /**
  137. * @serial Image used as the icon when this frame is minimized.
  138. */
  139. private Image icon;
  140. /**
  141. * @serial Constant used by the JDK Motif peer set. Not used in
  142. * this implementation.
  143. */
  144. private boolean mbManagement;
  145. /**
  146. * @serial The menu bar for this frame.
  147. */
  148. //private MenuBar menuBar = new MenuBar();
  149. private MenuBar menuBar;
  150. /**
  151. * @serial A list of other top-level windows owned by this window.
  152. */
  153. Vector ownedWindows = new Vector();
  154. /**
  155. * @serial Indicates whether or not this frame is resizable.
  156. */
  157. private boolean resizable = true;
  158. /**
  159. * @serial The state of this frame.
  160. * // FIXME: What are the values here?
  161. */
  162. private int state;
  163. /**
  164. * @serial The title of the frame.
  165. */
  166. private String title = "";
  167. /*************************************************************************/
  168. /*
  169. * Constructors
  170. */
  171. /**
  172. * Initializes a new instance of <code>Frame</code> that is not visible
  173. * and has no title.
  174. */
  175. public
  176. Frame()
  177. {
  178. this("");
  179. }
  180. /*************************************************************************/
  181. /**
  182. * Initializes a new instance of <code>Frame</code> that is not visible
  183. * and has the specified title.
  184. *
  185. * @param title The title of this frame.
  186. */
  187. public
  188. Frame(String title)
  189. {
  190. super();
  191. this.title = title;
  192. }
  193. public
  194. Frame(GraphicsConfiguration gc)
  195. {
  196. super(gc);
  197. }
  198. public
  199. Frame(String title, GraphicsConfiguration gc)
  200. {
  201. super(gc);
  202. setTitle(title);
  203. }
  204. /*************************************************************************/
  205. /*
  206. * Instance Methods
  207. */
  208. /**
  209. * Returns this frame's title string.
  210. *
  211. * @return This frame's title string.
  212. */
  213. public String
  214. getTitle()
  215. {
  216. return(title);
  217. }
  218. /*************************************************************************/
  219. /*
  220. * Sets this frame's title to the specified value.
  221. *
  222. * @param title The new frame title.
  223. */
  224. public synchronized void
  225. setTitle(String title)
  226. {
  227. this.title = title;
  228. if (peer != null)
  229. ((FramePeer) peer).setTitle(title);
  230. }
  231. /*************************************************************************/
  232. /**
  233. * Returns this frame's icon.
  234. *
  235. * @return This frame's icon, or <code>null</code> if this frame does not
  236. * have an icon.
  237. */
  238. public Image
  239. getIconImage()
  240. {
  241. return(icon);
  242. }
  243. /*************************************************************************/
  244. /**
  245. * Sets this frame's icon to the specified value.
  246. *
  247. * @icon The new icon for this frame.
  248. */
  249. public synchronized void
  250. setIconImage(Image icon)
  251. {
  252. this.icon = icon;
  253. if (peer != null)
  254. ((FramePeer) peer).setIconImage(icon);
  255. }
  256. /*************************************************************************/
  257. /**
  258. * Returns this frame's menu bar.
  259. *
  260. * @return This frame's menu bar, or <code>null</code> if this frame
  261. * does not have a menu bar.
  262. */
  263. public MenuBar
  264. getMenuBar()
  265. {
  266. return(menuBar);
  267. }
  268. /*************************************************************************/
  269. /**
  270. * Sets this frame's menu bar.
  271. *
  272. * @param menuBar The new menu bar for this frame.
  273. */
  274. public synchronized void
  275. setMenuBar(MenuBar menuBar)
  276. {
  277. this.menuBar = menuBar;
  278. if (peer != null)
  279. ((FramePeer) peer).setMenuBar(menuBar);
  280. }
  281. /*************************************************************************/
  282. /**
  283. * Tests whether or not this frame is resizable. This will be
  284. * <code>true</code> by default.
  285. *
  286. * @return <code>true</code> if this frame is resizable, <code>false</code>
  287. * otherwise.
  288. */
  289. public boolean
  290. isResizable()
  291. {
  292. return(resizable);
  293. }
  294. /*************************************************************************/
  295. /**
  296. * Sets the resizability of this frame to the specified value.
  297. *
  298. * @param resizable <code>true</code> to make the frame resizable,
  299. * <code>false</code> to make it non-resizable.
  300. */
  301. public synchronized void
  302. setResizable(boolean resizable)
  303. {
  304. this.resizable = resizable;
  305. if (peer != null)
  306. ((FramePeer) peer).setResizable(resizable);
  307. }
  308. /*************************************************************************/
  309. /**
  310. * Returns the cursor type of the cursor for this window. This will
  311. * be one of the constants in this class.
  312. *
  313. * @return The cursor type for this frame.
  314. *
  315. * @deprecated Use <code>Component.getCursor()</code> instead.
  316. */
  317. public int
  318. getCursorType()
  319. {
  320. return(getCursor().getType());
  321. }
  322. /*************************************************************************/
  323. /**
  324. * Sets the cursor for this window to the specified type. The specified
  325. * type should be one of the constants in this class.
  326. *
  327. * @param type The cursor type.
  328. *
  329. * @deprecated. Use <code>Component.setCursor(Cursor)</code> instead.
  330. */
  331. public void
  332. setCursor(int type)
  333. {
  334. setCursor(new Cursor(type));
  335. }
  336. /*************************************************************************/
  337. /**
  338. * Removes the specified component from this frame's menu.
  339. *
  340. * @param menu The menu component to remove.
  341. */
  342. public void
  343. remove(MenuComponent menu)
  344. {
  345. menuBar.remove(menu);
  346. }
  347. /*************************************************************************/
  348. /**
  349. * Notifies this frame that it should create its native peer.
  350. */
  351. public void
  352. addNotify()
  353. {
  354. if (peer == null)
  355. peer = getToolkit ().createFrame (this);
  356. super.addNotify();
  357. }
  358. /*************************************************************************/
  359. /**
  360. * Destroys any resources associated with this frame. This includes
  361. * all components in the frame and all owned toplevel windows.
  362. */
  363. public void
  364. dispose()
  365. {
  366. Enumeration e = ownedWindows.elements();
  367. while(e.hasMoreElements())
  368. {
  369. Window w = (Window)e.nextElement();
  370. w.dispose();
  371. }
  372. super.dispose();
  373. }
  374. /*************************************************************************/
  375. /**
  376. * Returns a debugging string describing this window.
  377. *
  378. * @return A debugging string describing this window.
  379. */
  380. protected String
  381. paramString()
  382. {
  383. return(getClass().getName());
  384. }
  385. public int
  386. getState()
  387. {
  388. /* FIXME: State might have changed in the peer... Must check. */
  389. return state;
  390. }
  391. public static Frame[]
  392. getFrames()
  393. {
  394. //Frame[] array = new Frames[frames.size()];
  395. //return frames.toArray(array);
  396. // see finalize() comment
  397. String msg = "FIXME: can't be implemented without weak references";
  398. throw new UnsupportedOperationException(msg);
  399. }
  400. } // class Frame