1. /*
  2. * @(#)Frame.java 1.108 00/04/06
  3. *
  4. * Copyright 1995-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt;
  11. import java.awt.peer.FramePeer;
  12. import java.awt.event.*;
  13. import java.util.Vector;
  14. import java.io.ObjectOutputStream;
  15. import java.io.ObjectInputStream;
  16. import java.io.IOException;
  17. import sun.awt.AppContext;
  18. import java.lang.ref.WeakReference;
  19. import javax.accessibility.*;
  20. /**
  21. * A Frame is a top-level window with a title and a border.
  22. * <p>
  23. * The size of the frame includes any area designated for the
  24. * border. The dimensions of the border area can be obtained
  25. * using the <code>getInsets</code> method, however, since
  26. * these dimensions are platform-dependent, a valid insets
  27. * value cannot be obtained until the frame is made displayable
  28. * by either calling <code>pack</code> or <code>show</code>.
  29. * Since the border area is included in the overall size of the
  30. * frame, the border effectively obscures a portion of the frame,
  31. * constraining the area available for rendering and/or displaying
  32. * subcomponents to the rectangle which has an upper-left corner
  33. * location of <code>(insets.left, insets.top)</code>, and has a size of
  34. * <code>width - (insets.left + insets.right)</code> by
  35. * <code>height - (insets.top + insets.bottom)</code>.
  36. * <p>
  37. * The default layout for a frame is BorderLayout.
  38. * <p>
  39. * In a multi-screen environment, you can create a <code>Frame</code>
  40. * on a different screen device by constructing the <code>Frame</code>
  41. * with {@link Frame(GraphicsConfiguration)} or
  42. * {@link Frame(String title, GraphicsConfiguration)}. The
  43. * <code>GraphicsConfiguration</code> object is one of the
  44. * <code>GraphicsConfiguration</code> objects of the target screen
  45. * device.
  46. * <p>
  47. * In a virtual device multi-screen environment in which the desktop
  48. * area could span multiple physical screen devices, the bounds of all
  49. * configurations are relative to the virtual-coordinate system. The
  50. * origin of the virtual-coordinate system is at the upper left-hand
  51. * corner of the primary physical screen. Depending on the location
  52. * of the primary screen in the virtual device, negative coordinates
  53. * are possible, as shown in the following figure.
  54. * <p>
  55. * <img src="doc-files/MultiScreen.gif">
  56. * ALIGN=center HSPACE=10 VSPACE=7>
  57. * <p>
  58. * In such an environment, when calling <code>setLocation</code>,
  59. * you must pass a virtual coordinate to this method. Similarly,
  60. * calling <code>getLocationOnScreen</code> on a <code>Frame</code>
  61. * returns virtual device coordinates. Call the <code>getBounds</code>
  62. * method of a <code>GraphicsConfiguration</code> to find its origin in
  63. * the virtual coordinate system.
  64. * <p>
  65. * The following code sets the
  66. * location of the <code>Frame</code> at (10, 10) relative
  67. * to the origin of the physical screen of the corresponding
  68. * <code>GraphicsConfiguration</code>. If the bounds of the
  69. * <code>GraphicsConfiguration</code> is not taken into account, the
  70. * <code>Frame</code> location would be set at (10, 10) relative to the
  71. * virtual-coordinate system and would appear on the primary physical
  72. * screen, which might be different from the physical screen of the
  73. * specified <code>GraphicsConfiguration</code>.
  74. *
  75. * <pre>
  76. * Frame f = new Frame(GraphicsConfiguration gc);
  77. * Rectangle bounds = gc.getBounds();
  78. * f.setLocation(10 + bounds.x, 10 + bounds.y);
  79. * </pre>
  80. *
  81. * <p>
  82. * Frames are capable of generating the following types of window events:
  83. * WindowOpened, WindowClosing, WindowClosed, WindowIconified,
  84. * WindowDeiconified, WindowActivated, WindowDeactivated.
  85. *
  86. * @version 1.108, 04/06/00
  87. * @author Sami Shaio
  88. * @see WindowEvent
  89. * @see Window#addWindowListener
  90. * @since JDK1.0
  91. */
  92. public class Frame extends Window implements MenuContainer {
  93. /* Note: These are being obsoleted; programs should use the Cursor class
  94. * variables going forward. See Cursor and Component.setCursor.
  95. */
  96. /**
  97. * @deprecated replaced by <code>Cursor.DEFAULT_CURSOR</code>.
  98. */
  99. public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR;
  100. /**
  101. * @deprecated replaced by <code>Cursor.CROSSHAIR_CURSOR</code>.
  102. */
  103. public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR;
  104. /**
  105. * @deprecated replaced by <code>Cursor.TEXT_CURSOR</code>.
  106. */
  107. public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR;
  108. /**
  109. * @deprecated replaced by <code>Cursor.WAIT_CURSOR</code>.
  110. */
  111. public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR;
  112. /**
  113. * @deprecated replaced by <code>Cursor.SW_RESIZE_CURSOR</code>.
  114. */
  115. public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR;
  116. /**
  117. * @deprecated replaced by <code>Cursor.SE_RESIZE_CURSOR</code>.
  118. */
  119. public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR;
  120. /**
  121. * @deprecated replaced by <code>Cursor.NW_RESIZE_CURSOR</code>.
  122. */
  123. public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR;
  124. /**
  125. * @deprecated replaced by <code>Cursor.NE_RESIZE_CURSOR</code>.
  126. */
  127. public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR;
  128. /**
  129. * @deprecated replaced by <code>Cursor.N_RESIZE_CURSOR</code>.
  130. */
  131. public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR;
  132. /**
  133. * @deprecated replaced by <code>Cursor.S_RESIZE_CURSOR</code>.
  134. */
  135. public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR;
  136. /**
  137. * @deprecated replaced by <code>Cursor.W_RESIZE_CURSOR</code>.
  138. */
  139. public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR;
  140. /**
  141. * @deprecated replaced by <code>Cursor.E_RESIZE_CURSOR</code>.
  142. */
  143. public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR;
  144. /**
  145. * @deprecated replaced by <code>Cursor.HAND_CURSOR</code>.
  146. */
  147. public static final int HAND_CURSOR = Cursor.HAND_CURSOR;
  148. /**
  149. * @deprecated replaced by <code>Cursor.MOVE_CURSOR</code>.
  150. */
  151. public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR;
  152. public static final int NORMAL = 0;
  153. public static final int ICONIFIED = 1;
  154. /**
  155. * This is the title of the frame. It can be changed
  156. * at any time. <code>title</code> can be null and if
  157. * this is the case the <code>title</code> = "".
  158. *
  159. * @serial
  160. * @see getTitle()
  161. * @see setTitle()
  162. */
  163. String title = "Untitled";
  164. /**
  165. * <code>icon</code> is the graphical way we can
  166. * represent the frame.
  167. * <code>icon</code> can be null, but obviously if
  168. * you try to set the icon image <code>icon</code>
  169. * cannot be null.
  170. *
  171. * @serial
  172. * @see getIconImage()
  173. * @see setIconImage()
  174. */
  175. Image icon;
  176. /**
  177. * The frames menubar. If <code>menuBar</code> = null
  178. * the frame will not have a menubar.
  179. *
  180. * @serial
  181. * @see getMenuBar()
  182. * @see setMenuBar()
  183. */
  184. MenuBar menuBar;
  185. /**
  186. * This field indicates whether the the frame is resizable
  187. * This property can be changed at any time.
  188. * <code>resizable</code> will be true if the frame is
  189. * resizable, otherwise it will be false.
  190. *
  191. * @serial
  192. * @see isResizable()
  193. */
  194. boolean resizable = true;
  195. /**
  196. * <code>mbManagement</code> is only used by the Motif implementation.
  197. *
  198. * @serial
  199. */
  200. boolean mbManagement = false; /* used only by the Motif impl. */
  201. private int state = NORMAL;
  202. /*
  203. * The Windows owned by the Frame.
  204. * Note: in 1.2 this has been superceded by Window.ownedWindowList
  205. *
  206. * @serial
  207. * @see java.awt.Window#ownedWindowList
  208. */
  209. Vector ownedWindows;
  210. /*
  211. * We insert a weak reference into the Vector of all Frames
  212. * instead of 'this' so that garbage collection can still take
  213. * place correctly.
  214. */
  215. transient private WeakReference weakThis;
  216. private static final String base = "frame";
  217. private static int nameCounter = 0;
  218. /*
  219. * JDK 1.1 serialVersionUID
  220. */
  221. private static final long serialVersionUID = 2673458971256075116L;
  222. static {
  223. /* ensure that the necessary native libraries are loaded */
  224. Toolkit.loadLibraries();
  225. initIDs();
  226. }
  227. /**
  228. * Constructs a new instance of <code>Frame</code> that is
  229. * initially invisible. The title of the <code>Frame</code>
  230. * is empty.
  231. * @see Component#setSize
  232. * @see Component#setVisible
  233. */
  234. public Frame() {
  235. this("", (GraphicsConfiguration)null);
  236. }
  237. /**
  238. * Create a <code>Frame</code> with the specified
  239. * <code>GraphicsConfiguration</code> of
  240. * a screen device.
  241. * @param gc the <code>GraphicsConfiguration</code>
  242. * of the target screen device. If <code>gc</code>
  243. * is <code>null</code>, the system default
  244. * <code>GraphicsConfiguration</code> is assumed.
  245. * @exception IllegalArgumentException if
  246. * <code>gc</code> is not from a screen device.
  247. * @since 1.3
  248. */
  249. public Frame(GraphicsConfiguration gc) {
  250. this("", gc);
  251. }
  252. /**
  253. * Constructs a new, initially invisible <code>Frame</code> object
  254. * with the specified title.
  255. * @param title the title to be displayed in the frame's border.
  256. * A <code>null</code> value
  257. * is treated as an empty string, "".
  258. * @exception IllegalArgumentException if gc is not from
  259. * a screen device.
  260. * @see java.awt.Component#setSize
  261. * @see java.awt.Component#setVisible
  262. * @see java.awt.GraphicsConfiguration#getBounds
  263. */
  264. public Frame(String title) {
  265. this(title, (GraphicsConfiguration)null);
  266. }
  267. /**
  268. * Constructs a new, initially invisible <code>Frame</code> object
  269. * with the specified title and a
  270. * <code>GraphicsConfiguration</code>.
  271. * @param title the title to be displayed in the frame's border.
  272. * A <code>null</code> value
  273. * is treated as an empty string, "".
  274. * @param gc the <code>GraphicsConfiguration</code>
  275. * of the target screen device. If <code>gc</code> is
  276. * <code>null</code>, the system default
  277. * <code>GraphicsConfiguration</code> is assumed.
  278. * @exception IllegalArgumentException if <code>gc</code>
  279. * is not from a screen device.
  280. * @see java.awt.Component#setSize
  281. * @see java.awt.Component#setVisible
  282. * @see java.awt.GraphicsConfiguration#getBounds
  283. */
  284. public Frame(String title, GraphicsConfiguration gc) {
  285. super(gc);
  286. this.title = title;
  287. weakThis = new WeakReference(this);
  288. addToFrameList();
  289. }
  290. /**
  291. * We have to remove the (hard) reference to weakThis in the
  292. * Vector, otherwise the WeakReference instance will never get
  293. * garbage collected.
  294. */
  295. protected void finalize() throws Throwable {
  296. removeFromFrameList();
  297. super.finalize();
  298. }
  299. /**
  300. * Construct a name for this component. Called by getName() when the
  301. * name is null.
  302. */
  303. String constructComponentName() {
  304. synchronized (getClass()) {
  305. return base + nameCounter++;
  306. }
  307. }
  308. /**
  309. * Makes this Frame displayable by connecting it to
  310. * a native screen resource. Making a frame displayable will
  311. * cause any of its children to be made displayable.
  312. * This method is called internally by the toolkit and should
  313. * not be called directly by programs.
  314. * @see Component#isDisplayable
  315. * @see #removeNotify
  316. */
  317. public void addNotify() {
  318. synchronized (getTreeLock()) {
  319. if (peer == null) {
  320. peer = getToolkit().createFrame(this);
  321. }
  322. MenuBar menuBar = this.menuBar;
  323. if (menuBar != null) {
  324. mbManagement = true;
  325. menuBar.addNotify();
  326. ((FramePeer)peer).setMenuBar(menuBar);
  327. }
  328. super.addNotify();
  329. }
  330. }
  331. /**
  332. * Gets the title of the frame. The title is displayed in the
  333. * frame's border.
  334. * @return the title of this frame, or an empty string ("")
  335. * if this frame doesn't have a title.
  336. * @see java.awt.Frame#setTitle
  337. */
  338. public String getTitle() {
  339. return title;
  340. }
  341. /**
  342. * Sets the title for this frame to the specified string.
  343. * @param title the title to be displayed in the frame's border
  344. * @param title the title to be displayed in the frame's border.
  345. * A <code>null</code> value
  346. * is treated as an empty string, "".
  347. * @see java.awt.Frame#getTitle
  348. */
  349. public synchronized void setTitle(String title) {
  350. this.title = title;
  351. FramePeer peer = (FramePeer)this.peer;
  352. if (peer != null) {
  353. peer.setTitle(title);
  354. }
  355. }
  356. /**
  357. * Gets the image to be displayed in the minimized icon
  358. * for this frame.
  359. * @return the icon image for this frame, or <code>null</code>
  360. * if this frame doesn't have an icon image.
  361. * @see java.awt.Frame#setIconImage
  362. */
  363. public Image getIconImage() {
  364. return icon;
  365. }
  366. /**
  367. * Sets the image to displayed in the minimized icon for this frame.
  368. * Not all platforms support the concept of minimizing a window.
  369. * @param image the icon image to be displayed.
  370. * If this parameter is <code>null</code> then the
  371. * icon image is set to the default image, which may vary
  372. * with platform.
  373. * @see java.awt.Frame#getIconImage
  374. */
  375. public synchronized void setIconImage(Image image) {
  376. this.icon = image;
  377. FramePeer peer = (FramePeer)this.peer;
  378. if (peer != null) {
  379. peer.setIconImage(image);
  380. }
  381. }
  382. /**
  383. * Gets the menu bar for this frame.
  384. * @return the menu bar for this frame, or <code>null</code>
  385. * if this frame doesn't have a menu bar.
  386. * @see java.awt.Frame#setMenuBar
  387. */
  388. public MenuBar getMenuBar() {
  389. return menuBar;
  390. }
  391. /**
  392. * Sets the menu bar for this frame to the specified menu bar.
  393. * @param mb the menu bar being set.
  394. * If this parameter is <code>null</code> then any
  395. * existing menu bar on this frame is removed.
  396. * @see java.awt.Frame#getMenuBar
  397. */
  398. public void setMenuBar(MenuBar mb) {
  399. synchronized (getTreeLock()) {
  400. if (menuBar == mb) {
  401. return;
  402. }
  403. if ((mb != null) && (mb.parent != null)) {
  404. mb.parent.remove(mb);
  405. }
  406. if (menuBar != null) {
  407. remove(menuBar);
  408. }
  409. menuBar = mb;
  410. if (menuBar != null) {
  411. menuBar.parent = this;
  412. FramePeer peer = (FramePeer)this.peer;
  413. if (peer != null) {
  414. mbManagement = true;
  415. menuBar.addNotify();
  416. if (valid) {
  417. invalidate();
  418. }
  419. peer.setMenuBar(menuBar);
  420. }
  421. }
  422. }
  423. }
  424. /**
  425. * Indicates whether this frame is resizable by the user.
  426. * By default, all frames are initially resizable.
  427. * @return <code>true</code> if the user can resize this frame;
  428. * <code>false</code> otherwise.
  429. * @see java.awt.Frame#setResizable
  430. */
  431. public boolean isResizable() {
  432. return resizable;
  433. }
  434. /**
  435. * Sets whether this frame is resizable by the user.
  436. * @param resizable <code>true</code> if this frame is resizable;
  437. * <code>false</code> otherwise.
  438. * @see java.awt.Frame#isResizable
  439. */
  440. public void setResizable(boolean resizable) {
  441. boolean testvalid = false;
  442. synchronized (this) {
  443. this.resizable = resizable;
  444. FramePeer peer = (FramePeer)this.peer;
  445. if (peer != null) {
  446. peer.setResizable(resizable);
  447. testvalid = true;
  448. }
  449. }
  450. // On some platforms, changing the resizable state affects
  451. // the insets of the Frame. If we could, we'd call invalidate()
  452. // from the peer, but we need to guarantee that we're not holding
  453. // the Frame lock when we call invalidate().
  454. if (testvalid && valid) {
  455. invalidate();
  456. }
  457. }
  458. /**
  459. * Sets the state of this frame.
  460. * @param state <code>Frame.ICONIFIED</code> if this frame is in
  461. * iconic state; <code>Frame.NORMAL</code> if this frame is
  462. * in normal state.
  463. * @see java.awt.Frame#getState
  464. */
  465. public synchronized void setState(int state) {
  466. this.state = state;
  467. FramePeer peer = (FramePeer)this.peer;
  468. if (peer != null) {
  469. peer.setState(state);
  470. }
  471. }
  472. /**
  473. * Gets the state of this frame.
  474. * @return <code>Frame.ICONIFIED</code> if frame in iconic state;
  475. * <code>Frame.NORMAL</code> if frame is in normal state.
  476. * @see java.awt.Frame#setState
  477. */
  478. public synchronized int getState() {
  479. FramePeer peer = (FramePeer)this.peer;
  480. if (peer != null) {
  481. state = peer.getState();
  482. }
  483. return state;
  484. }
  485. /**
  486. * Removes the specified menu bar from this frame.
  487. * @param m the menu component to remove.
  488. * If this parameter is <code>null</code> then a
  489. * NullPointerException is thrown and no action
  490. * is taken.
  491. */
  492. public void remove(MenuComponent m) {
  493. synchronized (getTreeLock()) {
  494. if (m == menuBar) {
  495. menuBar = null;
  496. FramePeer peer = (FramePeer)this.peer;
  497. if (peer != null) {
  498. mbManagement = true;
  499. if (valid) {
  500. invalidate();
  501. }
  502. peer.setMenuBar(null);
  503. m.removeNotify();
  504. }
  505. m.parent = null;
  506. } else {
  507. super.remove(m);
  508. }
  509. }
  510. }
  511. /**
  512. * Makes this Frame undisplayable by removing its connection
  513. * to its native screen resource. Making a Frame undisplayable
  514. * will cause any of its children to be made undisplayable.
  515. * This method is called by the toolkit internally and should
  516. * not be called directly by programs.
  517. * @see Component#isDisplayable
  518. * @see #addNotify
  519. */
  520. public void removeNotify() {
  521. synchronized (getTreeLock()) {
  522. FramePeer peer = (FramePeer)this.peer;
  523. if (peer != null) {
  524. // get the latest Frame state before disposing
  525. getState();
  526. if (menuBar != null) {
  527. mbManagement = true;
  528. peer.setMenuBar(null);
  529. menuBar.removeNotify();
  530. }
  531. }
  532. super.removeNotify();
  533. }
  534. }
  535. void postProcessKeyEvent(KeyEvent e) {
  536. if (menuBar != null && menuBar.handleShortcut(e)) {
  537. e.consume();
  538. return;
  539. }
  540. super.postProcessKeyEvent(e);
  541. }
  542. /**
  543. * Returns the parameter String of this Frame.
  544. */
  545. protected String paramString() {
  546. String str = super.paramString();
  547. if (resizable) {
  548. str += ",resizable";
  549. }
  550. if (title != null) {
  551. str += ",title=" + title;
  552. }
  553. return str;
  554. }
  555. /**
  556. * @deprecated As of JDK version 1.1,
  557. * replaced by <code>Component.setCursor(Cursor)</code>.
  558. */
  559. public void setCursor(int cursorType) {
  560. if (cursorType < DEFAULT_CURSOR || cursorType > MOVE_CURSOR) {
  561. throw new IllegalArgumentException("illegal cursor type");
  562. }
  563. setCursor(Cursor.getPredefinedCursor(cursorType));
  564. }
  565. /**
  566. * @deprecated As of JDK version 1.1,
  567. * replaced by <code>Component.getCursor()</code>.
  568. */
  569. public int getCursorType() {
  570. return (getCursor().getType());
  571. }
  572. /**
  573. * Returns an array containing all Frames created by the application.
  574. * If called from an applet, the array will only include the Frames
  575. * accessible by that applet.
  576. * @since 1.2
  577. */
  578. public static Frame[] getFrames() {
  579. synchronized (Frame.class) {
  580. Frame realCopy[];
  581. Vector frameList =
  582. (Vector)AppContext.getAppContext().get(Frame.class);
  583. if (frameList != null) {
  584. // Recall that frameList is actually a Vector of WeakReferences
  585. // and calling get() on one of these references may return
  586. // null. Make two arrays-- one the size of the Vector
  587. // (fullCopy with size fullSize), and one the size of all
  588. // non-null get()s (realCopy with size realSize).
  589. int fullSize = frameList.size();
  590. int realSize = 0;
  591. Frame fullCopy[] = new Frame[fullSize];
  592. for (int i = 0; i < fullSize; i++) {
  593. fullCopy[realSize] = (Frame)
  594. (((WeakReference) (frameList.elementAt(i))).get());
  595. if (fullCopy[realSize] != null) {
  596. realSize++;
  597. }
  598. }
  599. if (fullSize != realSize) {
  600. realCopy = new Frame[realSize];
  601. System.arraycopy(fullCopy, 0, realCopy, 0, realSize);
  602. } else {
  603. realCopy = fullCopy;
  604. }
  605. } else {
  606. realCopy = new Frame[0];
  607. }
  608. return realCopy;
  609. }
  610. }
  611. void addToFrameList() {
  612. synchronized (Frame.class) {
  613. Vector frameList = (Vector)appContext.get(Frame.class);
  614. if (frameList == null) {
  615. frameList = new Vector();
  616. appContext.put(Frame.class, frameList);
  617. }
  618. frameList.addElement(weakThis);
  619. }
  620. }
  621. void removeFromFrameList() {
  622. synchronized (Frame.class) {
  623. Vector frameList = (Vector)appContext.get(Frame.class);
  624. if (frameList != null) {
  625. frameList.removeElement(weakThis);
  626. }
  627. }
  628. }
  629. /* Serialization support. If there's a MenuBar we restore
  630. * its (transient) parent field here. Likewise for top level
  631. * windows that are "owned" by this frame.
  632. */
  633. /**
  634. * Frame Serialized Data Version.
  635. *
  636. * @serial
  637. */
  638. private int frameSerializedDataVersion = 1;
  639. /**
  640. * Writes default serializable fields to stream. Writes
  641. * a list of serializable ItemListener(s) as optional data.
  642. * The non-serializable ItemListner(s) are detected and
  643. * no attempt is made to serialize them.
  644. *
  645. * @serialData Null terminated sequence of 0 or more pairs.
  646. * The pair consists of a String and Object.
  647. * The String indicates the type of object and
  648. * is one of the following :
  649. * itemListenerK indicating and ItemListener object.
  650. *
  651. * @see java.awt.Component.itemListenerK
  652. */
  653. private void writeObject(ObjectOutputStream s)
  654. throws IOException
  655. {
  656. s.defaultWriteObject();
  657. }
  658. /**
  659. * Read the ObjectInputStream and if it isnt null
  660. * add a listener to receive item events fired
  661. * by the Frame.
  662. * Unrecognised keys or values will be Ignored.
  663. * @see removeActionListener()
  664. * @see addActionListener()
  665. */
  666. private void readObject(ObjectInputStream s)
  667. throws ClassNotFoundException, IOException
  668. {
  669. s.defaultReadObject();
  670. if (menuBar != null)
  671. menuBar.parent = this;
  672. // Ensure 1.1 serialized Frames can read & hook-up
  673. // owned windows properly
  674. //
  675. if (ownedWindows != null) {
  676. for (int i = 0; i < ownedWindows.size(); i++) {
  677. connectOwnedWindow((Window) ownedWindows.elementAt(i));
  678. }
  679. ownedWindows = null;
  680. }
  681. weakThis = new WeakReference(this);
  682. addToFrameList();
  683. }
  684. /**
  685. * Initialize JNI field and method IDs
  686. */
  687. private static native void initIDs();
  688. /*
  689. * --- Accessibility Support ---
  690. *
  691. */
  692. /**
  693. * Gets the AccessibleContext associated with this Frame.
  694. * For frames, the AccessibleContext takes the form of an
  695. * AccessibleAWTFrame.
  696. * A new AccessibleAWTFrame instance is created if necessary.
  697. *
  698. * @return an AccessibleAWTFrame that serves as the
  699. * AccessibleContext of this Frame
  700. */
  701. public AccessibleContext getAccessibleContext() {
  702. if (accessibleContext == null) {
  703. accessibleContext = new AccessibleAWTFrame();
  704. }
  705. return accessibleContext;
  706. }
  707. /**
  708. * This class implements accessibility support for the
  709. * <code>Frame</code> class. It provides an implementation of the
  710. * Java Accessibility API appropriate to frame user-interface elements.
  711. */
  712. protected class AccessibleAWTFrame extends AccessibleAWTWindow {
  713. /**
  714. * Get the role of this object.
  715. *
  716. * @return an instance of AccessibleRole describing the role of the
  717. * object
  718. * @see AccessibleRole
  719. */
  720. public AccessibleRole getAccessibleRole() {
  721. return AccessibleRole.FRAME;
  722. }
  723. /**
  724. * Get the state of this object.
  725. *
  726. * @return an instance of AccessibleStateSet containing the current
  727. * state set of the object
  728. * @see AccessibleState
  729. */
  730. public AccessibleStateSet getAccessibleStateSet() {
  731. AccessibleStateSet states = super.getAccessibleStateSet();
  732. if (getFocusOwner() != null) {
  733. states.add(AccessibleState.ACTIVE);
  734. }
  735. if (isResizable()) {
  736. states.add(AccessibleState.RESIZABLE);
  737. }
  738. return states;
  739. }
  740. } // inner class AccessibleAWTFrame
  741. }