Source for javax.swing.JInternalFrame

   1: /* JInternalFrame.java --
   2:    Copyright (C) 2002, 2004, 2005, 2006,  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., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 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 javax.swing;
  40: 
  41: import java.awt.BorderLayout;
  42: import java.awt.Component;
  43: import java.awt.Container;
  44: import java.awt.Graphics;
  45: import java.awt.IllegalComponentStateException;
  46: import java.awt.KeyboardFocusManager;
  47: import java.awt.LayoutManager;
  48: import java.awt.Rectangle;
  49: import java.beans.PropertyChangeEvent;
  50: import java.beans.PropertyVetoException;
  51: 
  52: import javax.accessibility.Accessible;
  53: import javax.accessibility.AccessibleContext;
  54: import javax.accessibility.AccessibleRole;
  55: import javax.accessibility.AccessibleValue;
  56: import javax.swing.event.InternalFrameEvent;
  57: import javax.swing.event.InternalFrameListener;
  58: import javax.swing.plaf.DesktopIconUI;
  59: import javax.swing.plaf.InternalFrameUI;
  60: 
  61: /**
  62:  * This class implements a Swing widget that looks and acts like a native
  63:  * frame. The frame can be dragged, resized, closed, etc. Typically,
  64:  * JInternalFrames are placed in JDesktopPanes. The actions that the
  65:  * JInternalFrame performs (maximizing, minimizing, etc.) are performed by a
  66:  * DesktopManager. As with regular frames, components are added by calling
  67:  * frame.getContentPane().add.
  68:  */
  69: public class JInternalFrame extends JComponent implements Accessible,
  70:                                                           WindowConstants,
  71:                                                           RootPaneContainer
  72: {
  73: 
  74:   private static final long serialVersionUID = -5425177187760785402L;
  75: 
  76:   /**
  77:    * Provides the accessibility features for the <code>JInternalFrame</code>
  78:    * component.
  79:    */
  80:   protected class AccessibleJInternalFrame extends AccessibleJComponent
  81:     implements AccessibleValue
  82:   {
  83:     private static final long serialVersionUID = 5931936924175476797L;
  84: 
  85:     /**
  86:      * Creates a new <code>AccessibleJInternalFrame</code> instance.
  87:      */
  88:     protected AccessibleJInternalFrame()
  89:     {
  90:       super();
  91:     }
  92: 
  93:     /**
  94:      * Returns the frame title.
  95:      *
  96:      * @return The frame title.
  97:      */
  98:     public String getAccessibleName()
  99:     {
 100:       return getTitle();
 101:     }
 102: 
 103:     /**
 104:      * Returns the accessible role for the <code>JInternalFrame</code> 
 105:      * component.
 106:      *
 107:      * @return {@link AccessibleRole#INTERNAL_FRAME}.
 108:      */
 109:     public AccessibleRole getAccessibleRole()
 110:     {
 111:       return AccessibleRole.INTERNAL_FRAME;
 112:     }
 113: 
 114:     /**
 115:      * Returns an object that provides access to the current, minimum and 
 116:      * maximum values for the {@link JInternalFrame}.  Since this class 
 117:      * implements {@link AccessibleValue}, it returns itself.
 118:      *
 119:      * @return The accessible value.
 120:      */
 121:     public AccessibleValue getAccessibleValue()
 122:     {
 123:       return this;
 124:     }
 125: 
 126:     /**
 127:      * Returns the current layer for the {@link JInternalFrame} component, 
 128:      * as an {@link Integer}.
 129:      *
 130:      * @return The layer for the {@link JInternalFrame} component.
 131:      */
 132:     public Number getCurrentAccessibleValue()
 133:     {
 134:       return new Integer(getLayer());
 135:     }
 136: 
 137:     /**
 138:      * Returns the maximum permitted accessible value.
 139:      *
 140:      * @return <code>Integer(Integer.MAX_VALUE)</code>.
 141:      */
 142:     public Number getMaximumAccessibleValue()
 143:     {
 144:       return new Integer(Integer.MAX_VALUE);
 145:     }
 146: 
 147:     /**
 148:      * Returns the minimum permitted accessible value.
 149:      *
 150:      * @return <code>Integer(Integer.MIN_VALUE)</code>.
 151:      */
 152:     public Number getMinimumAccessibleValue()
 153:     {
 154:       return new Integer(Integer.MIN_VALUE);
 155:     }
 156: 
 157:     /**
 158:      * Sets the layer for the internal frame.
 159:      *
 160:      * @param n  the layer (see the constants defined in {@link JLayeredPane}).
 161:      *
 162:      * @return <code>true</code> if the value is set, and <code>false</code>
 163:      *         if it was not set.
 164:      */
 165:     public boolean setCurrentAccessibleValue(Number n)
 166:     {
 167:       if (n == null)
 168:         return false;
 169:       setLayer(n.intValue());
 170:       return true;
 171:     }
 172:   }
 173: 
 174:   /**
 175:    * This class represents the JInternalFrame while it is iconified.
 176:    */
 177:   public static class JDesktopIcon extends JComponent implements Accessible
 178:   {
 179:     /**
 180:      * Provides the accessibility features for the <code>JDesktopIcon</code>
 181:      * component.
 182:      */
 183:     protected class AccessibleJDesktopIcon extends AccessibleJComponent
 184:       implements AccessibleValue
 185:     {
 186:       private static final long serialVersionUID = 5035560458941637802L;
 187: 
 188:       /**
 189:        * Creates a new <code>AccessibleJDesktopIcon</code> instance.
 190:        */
 191:       protected AccessibleJDesktopIcon()
 192:       {
 193:         super();
 194:       }
 195: 
 196:       /**
 197:        * Returns the accessible role for the <code>JDesktopIcon</code> 
 198:        * component.
 199:        *
 200:        * @return {@link AccessibleRole#DESKTOP_ICON}.
 201:        */
 202:       public AccessibleRole getAccessibleRole()
 203:       {
 204:         return AccessibleRole.DESKTOP_ICON;
 205:       }
 206: 
 207:       /**
 208:        * Returns an object that provides access to the current, minimum and 
 209:        * maximum values for the {@link JDesktopIcon}.  Since this class 
 210:        * implements {@link AccessibleValue}, it returns itself.
 211:        *
 212:        * @return The accessible value.
 213:        */
 214:       public AccessibleValue getAccessibleValue()
 215:       {
 216:         return this;
 217:       }
 218: 
 219:       /**
 220:        * Returns the current layer for the {@link JInternalFrame} component
 221:        * represented by this <code>JDesktopIcon</code>, as an {@link Integer}.
 222:        *
 223:        * @return The layer.
 224:        */
 225:       public Number getCurrentAccessibleValue()
 226:       {
 227:         return new Integer(frame.getLayer());
 228:       }
 229: 
 230:       /**
 231:        * Returns the maximum permitted accessible value.
 232:        *
 233:        * @return <code>Integer(Integer.MAX_VALUE)</code>.
 234:        */
 235:       public Number getMaximumAccessibleValue()
 236:       {
 237:         return new Integer(Integer.MAX_VALUE);
 238:       }
 239: 
 240:       /**
 241:        * Returns the minimum permitted accessible value.
 242:        *
 243:        * @return <code>Integer(Integer.MIN_VALUE)</code>.
 244:        */
 245:       public Number getMinimumAccessibleValue()
 246:       {
 247:         return new Integer(Integer.MIN_VALUE);
 248:       }
 249: 
 250:       /**
 251:        * Sets the layer for the internal frame represented by this 
 252:        * <code>JDesktopIcon</code> component.
 253:        *
 254:        * @param n  the layer (see the constants defined in 
 255:        *           {@link JLayeredPane}).
 256:        *
 257:        * @return <code>true</code> if the value is set, and <code>false</code>
 258:        *         if it was not set.
 259:        */
 260:       public boolean setCurrentAccessibleValue(Number n)
 261:       {
 262:         if (n == null)
 263:           return false;
 264:         frame.setLayer(n.intValue());
 265:         return true;
 266:       }
 267:     }
 268: 
 269:     private static final long serialVersionUID = 4672973344731387687L;
 270: 
 271:     /** The JInternalFrame this DesktopIcon represents. */
 272:     JInternalFrame frame;
 273: 
 274:     /**
 275:      * Creates a new JDesktopIcon object for representing the given frame.
 276:      *
 277:      * @param f The JInternalFrame to represent.
 278:      */
 279:     public JDesktopIcon(JInternalFrame f)
 280:     {
 281:       frame = f;
 282:       updateUI();
 283:     }
 284: 
 285:   /**
 286:    * Returns the object that provides accessibility features for this
 287:    * <code>JDesktopIcon</code> component.
 288:    *
 289:    * @return The accessible context (an instance of 
 290:    *         {@link AccessibleJDesktopIcon}).
 291:    */
 292:     public AccessibleContext getAccessibleContext()
 293:     {
 294:       if (accessibleContext == null)
 295:         accessibleContext = new AccessibleJDesktopIcon();
 296:       return accessibleContext;
 297:     }
 298: 
 299:     /**
 300:      * This method returns the JDesktopPane this JDesktopIcon is in.
 301:      *
 302:      * @return The JDesktopPane this JDesktopIcon is in.
 303:      */
 304:     public JDesktopPane getDesktopPane()
 305:     {
 306:       JDesktopPane p = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
 307:                                                                         this);
 308:       return p;
 309:     }
 310: 
 311:     /**
 312:      * This method returns the JInternalFrame this JDesktopIcon represents.
 313:      *
 314:      * @return The JInternalFrame this JDesktopIcon represents.
 315:      */
 316:     public JInternalFrame getInternalFrame()
 317:     {
 318:       return frame;
 319:     }
 320: 
 321:     /**
 322:      * This method returns the UI that is responsible for the JDesktopIcon.
 323:      *
 324:      * @return The UI that is responsible for the JDesktopIcon.
 325:      */
 326:     public DesktopIconUI getUI()
 327:     {
 328:       return (DesktopIconUI) ui;
 329:     }
 330: 
 331:     /**
 332:      * This method returns the String identifier that is used to determine
 333:      * which class is used for JDesktopIcon's UI.
 334:      *
 335:      * @return A String identifier for the UI class.
 336:      */
 337:     public String getUIClassID()
 338:     {
 339:       return "DesktopIconUI";
 340:     }
 341: 
 342:     /**
 343:      * This method sets the JInternalFrame that this JDesktopIcon represents.
 344:      *
 345:      * @param f The JInternalFrame that this JDesktopIcon represents.
 346:      */
 347:     public void setInternalFrame(JInternalFrame f)
 348:     {
 349:       frame = f;
 350:     }
 351: 
 352:     /**
 353:      * This method sets the UI used for this JDesktopIcon.
 354:      *
 355:      * @param ui The UI to use.
 356:      */
 357:     public void setUI(DesktopIconUI ui)
 358:     {
 359:       super.setUI(ui);
 360:     }
 361: 
 362:     /**
 363:      * This method restores the UI property to the defaults.
 364:      */
 365:     public void updateUI()
 366:     {
 367:       setUI((DesktopIconUI) UIManager.getUI(this));
 368:     }
 369:   }
 370: 
 371:   /**
 372:    * The property fired in a PropertyChangeEvent when the contentPane property
 373:    * changes.
 374:    */
 375:   public static final String CONTENT_PANE_PROPERTY = "contentPane";
 376: 
 377:   /**
 378:    * The property fired in a PropertyChangeEvent when the frameIcon property
 379:    * changes.
 380:    */
 381:   public static final String FRAME_ICON_PROPERTY = "frameIcon";
 382: 
 383:   /**
 384:    * The property fired in a PropertyChangeEvent when the glassPane property
 385:    * changes.
 386:    */
 387:   public static final String GLASS_PANE_PROPERTY = "glassPane";
 388: 
 389:   /**
 390:    * The property fired in a PropertyChangeEvent when the closed property
 391:    * changes.
 392:    */
 393:   public static final String IS_CLOSED_PROPERTY = "closed";
 394: 
 395:   /**
 396:    * The property fired in a PropertyChangeEvent when the icon property
 397:    * changes.
 398:    */
 399:   public static final String IS_ICON_PROPERTY = "icon";
 400: 
 401:   /**
 402:    * The property fired in a PropertyChangeEvent when the maximum property
 403:    * changes.
 404:    */
 405:   public static final String IS_MAXIMUM_PROPERTY = "maximum";
 406: 
 407:   /**
 408:    * The property fired in a PropertyChangeEvent when the selected property
 409:    * changes.
 410:    */
 411:   public static final String IS_SELECTED_PROPERTY = "selected";
 412: 
 413:   /**
 414:    * The property fired in a PropertyChangeEvent when the layeredPane property
 415:    * changes.
 416:    */
 417:   public static final String LAYERED_PANE_PROPERTY = "layeredPane";
 418: 
 419:   /**
 420:    * The property fired in a PropertyChangeEvent when the jMenuBar property
 421:    * changes.
 422:    */
 423:   public static final String MENU_BAR_PROPERTY = "JMenuBar";
 424: 
 425:   /**
 426:    * The property fired in a PropertyChangeEvent when the rootPane property
 427:    * changes.
 428:    */
 429:   public static final String ROOT_PANE_PROPERTY = "rootPane";
 430: 
 431:   /**
 432:    * The property fired in a PropertyChangeEvent when the title property
 433:    * changes.
 434:    */
 435:   public static final String TITLE_PROPERTY = "title";
 436: 
 437:   /** Whether the JInternalFrame is closable. */
 438:   protected boolean closable;
 439: 
 440:   /** Whether the JInternalFrame can be iconified. */
 441:   protected boolean iconable;
 442: 
 443:   /** Whether the JInternalFrame is closed. */
 444:   protected boolean isClosed;
 445: 
 446:   /** Whether the JInternalFrame has been iconified. */
 447:   protected boolean isIcon;
 448: 
 449:   /** Whether the JInternalFrame has been maximized. */
 450:   protected boolean isMaximum;
 451: 
 452:   /** Whether the JInternalFrame is the active frame. */
 453:   protected boolean isSelected;
 454: 
 455:   /** Whether the JInternalFrame can be maximized. */
 456:   protected boolean maximizable;
 457: 
 458:   /**
 459:    * Whether the JInternalFrame has rootPaneChecking enabled.
 460:    *
 461:    * @specnote Should be false to comply with J2SE 5.0
 462:    */
 463:   protected boolean rootPaneCheckingEnabled = false;
 464: 
 465:   /** Whether the JInternalFrame is resizable. */
 466:   protected boolean resizable;
 467: 
 468:   /**
 469:    * The JDesktopIcon that represents the JInternalFrame while it is
 470:    * iconified.
 471:    */
 472:   protected JDesktopIcon desktopIcon;
 473: 
 474:   /** The icon used in the JMenuBar in the TitlePane. */
 475:   protected Icon frameIcon;
 476: 
 477:   /** The rootPane of the JInternalFrame. */
 478:   protected JRootPane rootPane;
 479: 
 480:   /** The title on the TitlePane of the JInternalFrame. */
 481:   protected String title;
 482: 
 483:   /** The bounds of the JInternalFrame before it was maximized. */
 484:   private transient Rectangle storedBounds;
 485: 
 486:   /** The Component that receives focus by default. */
 487:   private transient Component defaultFocus;
 488: 
 489:   /** The default close action taken, */
 490:   private transient int defaultCloseOperation = DISPOSE_ON_CLOSE;
 491: 
 492:   /** Whether the JInternalFrame has become visible for the very first time. */
 493:   private transient boolean isFirstTimeVisible = true;
 494: 
 495:   /** DOCUMENT ME! */
 496:   private transient boolean wasIcon = false;
 497: 
 498:   /**
 499:    * Creates a new JInternalFrame object that has an empty string for its 
 500:    * title, and is non-resizable, non-maximizable, non-iconifiable, and 
 501:    * non-closable.
 502:    */
 503:   public JInternalFrame()
 504:   {
 505:     this("", false, false, false, false);
 506:   }
 507: 
 508:   /**
 509:    * Creates a new JInternalFrame object with the given title and is
 510:    * non-resizable, non-maximizable, non-iconifiable, and non-closable.
 511:    *
 512:    * @param title The title displayed in the JInternalFrame.
 513:    */
 514:   public JInternalFrame(String title)
 515:   {
 516:     this(title, false, false, false, false);
 517:   }
 518: 
 519:   /**
 520:    * Creates a new JInternalFrame object with the given title and resizable
 521:    * properties. The JInternalFrame is non-maximizable, non-iconifiable, and
 522:    * non-closable.
 523:    *
 524:    * @param title The title displayed in the JInternalFrame.
 525:    * @param resizable Whether the JInternalFrame is resizable.
 526:    */
 527:   public JInternalFrame(String title, boolean resizable)
 528:   {
 529:     this(title, resizable, false, false, false);
 530:   }
 531: 
 532:   /**
 533:    * Creates a new JInternalFrame object with the given title, resizable, and
 534:    * closable properties. The JInternalFrame is non-maximizable and
 535:    * non-iconifiable.
 536:    *
 537:    * @param title The title displayed in the JInternalFrame.
 538:    * @param resizable Whether the JInternalFrame is resizable.
 539:    * @param closable Whether the JInternalFrame is closable.
 540:    */
 541:   public JInternalFrame(String title, boolean resizable, boolean closable)
 542:   {
 543:     this(title, resizable, closable, false, false);
 544:   }
 545: 
 546:   /**
 547:    * Creates a new JInternalFrame object with the given title, resizable,
 548:    * closable and maximizable properties. The JInternalFrame is
 549:    * non-iconifiable.
 550:    *
 551:    * @param title The title displayed in the JInternalFrame.
 552:    * @param resizable Whether the JInternalFrame is resizable.
 553:    * @param closable Whether the JInternalFrame is closable.
 554:    * @param maximizable Whether the JInternalFrame is maximizable.
 555:    */
 556:   public JInternalFrame(String title, boolean resizable, boolean closable,
 557:                         boolean maximizable)
 558:   {
 559:     this(title, resizable, closable, maximizable, false);
 560:   }
 561: 
 562:   /**
 563:    * Creates a new JInternalFrame object with the given title, resizable,
 564:    * closable, maximizable and iconifiable properties.
 565:    *
 566:    * @param title The title displayed in the JInternalFrame.
 567:    * @param resizable Whether the JInternalFrame is resizable.
 568:    * @param closable Whether the JInternalFrame is closable.
 569:    * @param maximizable Whether the JInternalFrame is maximizable.
 570:    * @param iconifiable Whether the JInternalFrame is iconifiable.
 571:    */
 572:   public JInternalFrame(String title, boolean resizable, boolean closable,
 573:                         boolean maximizable, boolean iconifiable)
 574:   {
 575:     this.title = title;
 576:     this.resizable = resizable;
 577:     this.closable = closable;
 578:     this.maximizable = maximizable;
 579:     this.iconable = iconifiable;
 580:     isMaximum = false;
 581:     setRootPane(createRootPane());
 582:     // JInternalFrames are invisible and opaque by default.
 583:     setVisible(false);
 584:     setOpaque(true);
 585:     desktopIcon = new JDesktopIcon(this);
 586:     updateUI();
 587:     setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
 588:   }
 589: 
 590:   /**
 591:    * This method adds Components to this Container. For JInternalFrames,
 592:    * instead of calling add directly on the JInternalFrame, it should be
 593:    * called with JInternalFrame.getContentPane().add. If root pane checking
 594:    * is enabled, calling this method will cause an exception to be thrown.
 595:    *
 596:    * @param comp The Component to add.
 597:    * @param constraints The constraints on the Component added.
 598:    * @param index The position to place the Component.
 599:    *
 600:    * @throws Error DOCUMENT ME!
 601:    */
 602:   protected void addImpl(Component comp, Object constraints, int index)
 603:   {
 604:     // If we're in the initialization stage use super.add. Here we add the
 605:     // rootPane as well as the title bar and other stuff.
 606:     // Otherwise pass the add onto the content pane.
 607:     if (isRootPaneCheckingEnabled())
 608:       getContentPane().add(comp, constraints, index);
 609:     else
 610:       super.addImpl(comp,constraints, index);
 611:   }
 612: 
 613:   /**
 614:    * This method adds an InternalFrameListener to this JInternalFrame.
 615:    *
 616:    * @param l The listener to add.
 617:    */
 618:   public void addInternalFrameListener(InternalFrameListener l)
 619:   {
 620:     listenerList.add(InternalFrameListener.class, l);
 621:   }
 622: 
 623:   /**
 624:    * This method is used to create a root pane for the JInternalFrame. This
 625:    * method is called by the constructors.
 626:    *
 627:    * @return A root pane for the JInternalFrame to use.
 628:    */
 629:   protected JRootPane createRootPane()
 630:   {
 631:     return new JRootPane();
 632:   }
 633: 
 634:   /**
 635:    * This method makes this JInternalFrame invisible, unselected and closed.
 636:    * If this JInternalFrame is not closed already, it will fire an
 637:    * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
 638:    * doesn't give vetoable listeners a chance to veto and it will not fire an
 639:    * INTERNAL_FRAME_CLOSING event.
 640:    */
 641:   public void dispose()
 642:   {
 643:     if (isVisible())
 644:       setVisible(false);
 645:     if (isSelected())
 646:       {
 647:         try
 648:           {
 649:             setSelected(false);
 650:           }
 651:         catch (PropertyVetoException e)
 652:           {
 653:             // Do nothing if they don't want to be unselected.
 654:           }
 655:       }
 656:     if (! isClosed)
 657:       {
 658:         firePropertyChange(IS_CLOSED_PROPERTY, Boolean.FALSE, Boolean.TRUE);
 659:         isClosed = true;
 660:       }
 661:     fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
 662:   }
 663: 
 664:   /**
 665:    * This method is used for closing this JInternalFrame. It fires an
 666:    * INTERNAL_FRAME_CLOSING event and then performs the action specified by
 667:    * the default close operation.
 668:    */
 669:   public void doDefaultCloseAction()
 670:   {
 671:     fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
 672:     switch (getDefaultCloseOperation())
 673:       {
 674:       case HIDE_ON_CLOSE:
 675:         setVisible(false);
 676:         break;
 677:       case DISPOSE_ON_CLOSE:
 678:         dispose();
 679:         break;
 680:       }
 681:   }
 682: 
 683:   /**
 684:    * This method fires an InternalFrameEvent to the listeners.
 685:    *
 686:    * @param id The type of event being fired. See InternalFrameEvent.
 687:    */
 688:   protected void fireInternalFrameEvent(int id)
 689:   {
 690:     Object[] ifListeners = listenerList.getListenerList();
 691:     InternalFrameEvent evt = new InternalFrameEvent(this, id);
 692:     switch (id)
 693:       {
 694:       case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
 695:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 696:       {
 697:         if (ifListeners[i] == InternalFrameListener.class)
 698:           ((InternalFrameListener) ifListeners[i + 1])
 699:           .internalFrameClosing(evt);
 700:       }
 701:     break;
 702:       case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
 703:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 704:       {
 705:         if (ifListeners[i] == InternalFrameListener.class)
 706:           ((InternalFrameListener) ifListeners[i + 1])
 707:           .internalFrameActivated(evt);
 708:       }
 709:     break;
 710:       case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
 711:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 712:       {
 713:         if (ifListeners[i] == InternalFrameListener.class)
 714:           ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt);
 715:       }
 716:     break;
 717:       case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
 718:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 719:       {
 720:         if (ifListeners[i] == InternalFrameListener.class)
 721:           ((InternalFrameListener) ifListeners[i + 1])
 722:           .internalFrameDeactivated(evt);
 723:       }
 724:     break;
 725:       case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
 726:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 727:       {
 728:         if (ifListeners[i] == InternalFrameListener.class)
 729:           ((InternalFrameListener) ifListeners[i + 1])
 730:           .internalFrameDeiconified(evt);
 731:       }
 732:     break;
 733:       case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
 734:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 735:       {
 736:         if (ifListeners[i] == InternalFrameListener.class)
 737:           ((InternalFrameListener) ifListeners[i + 1])
 738:           .internalFrameIconified(evt);
 739:       }
 740:     break;
 741:       case InternalFrameEvent.INTERNAL_FRAME_OPENED:
 742:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 743:       {
 744:         if (ifListeners[i] == InternalFrameListener.class)
 745:           ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt);
 746:       }
 747:     break;
 748:       }
 749:   }
 750: 
 751:   /**
 752:    * Returns the object that provides accessibility features for this
 753:    * <code>JInternalFrame</code> component.
 754:    *
 755:    * @return The accessible context (an instance of 
 756:    *     {@link AccessibleJInternalFrame}).
 757:    */
 758:   public AccessibleContext getAccessibleContext()
 759:   {
 760:     if (accessibleContext == null)
 761:       accessibleContext = new AccessibleJInternalFrame();
 762:     return accessibleContext;
 763:   }
 764: 
 765:   /**
 766:    * This method returns the Content Pane for this JInternalFrame.
 767:    *
 768:    * @return The Content Pane for this JInternalFrame.
 769:    */
 770:   public Container getContentPane()
 771:   {
 772:     return getRootPane().getContentPane();
 773:   }
 774: 
 775:   /**
 776:    * Returns a code for the default action taken when this 
 777:    * <code>JInternalFrame</code> is closed.
 778:    *
 779:    * @return The action code (usually one of 
 780:    *     {@link WindowConstants#DO_NOTHING_ON_CLOSE}, 
 781:    *     {@link WindowConstants#HIDE_ON_CLOSE}, or 
 782:    *     {@link WindowConstants#DISPOSE_ON_CLOSE}).
 783:    * 
 784:    * @see #setDefaultCloseOperation(int)
 785:    * @see #doDefaultCloseAction()
 786:    */
 787:   public int getDefaultCloseOperation()
 788:   {
 789:     return defaultCloseOperation;
 790:   }
 791: 
 792:   /**
 793:    * Returns the <code>JDesktopIcon</code> that represents this 
 794:    * <code>JInternalFrame</code> while it is iconified.
 795:    *
 796:    * @return The desktop icon component.
 797:    */
 798:   public JDesktopIcon getDesktopIcon()
 799:   {
 800:     return desktopIcon;
 801:   }
 802: 
 803:   /**
 804:    * This method searches this JInternalFrame ancestors for an instance of
 805:    * JDesktopPane. If one is found, it is returned. If none is found, then it
 806:    * will search the JDesktopIcon for a JDesktopPane.
 807:    *
 808:    * @return The JDesktopPane that this JInternalFrame belongs to.
 809:    */
 810:   public JDesktopPane getDesktopPane()
 811:   {
 812:     JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
 813:                                                                           this);
 814:     if (value == null && desktopIcon != null)
 815:       value = desktopIcon.getDesktopPane();
 816:     return value;
 817:   }
 818: 
 819:   /**
 820:    * This method returns null because this must always be the root of a focus
 821:    * traversal.
 822:    *
 823:    * @return always null
 824:    *
 825:    * @since 1.4
 826:    */
 827:   public final Container getFocusCycleRootAncestor()
 828:   {
 829:     // as defined.
 830:     return null;
 831:   }
 832: 
 833:   /**
 834:    * This method returns the child Component that will receive focus if this
 835:    * JInternalFrame is selected.
 836:    *
 837:    * @return The child Component that will receive focus.
 838:    */
 839:   public Component getFocusOwner()
 840:   {
 841:     if (isSelected())
 842:       {
 843:     Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
 844:     if (SwingUtilities.isDescendingFrom(focus, this))
 845:       {
 846:         defaultFocus = focus;
 847:         return focus;
 848:       }
 849:       }
 850:     return null;
 851:   }
 852: 
 853:   /**
 854:    * This method returns the Frame Icon (the icon used in the JInternalFrame
 855:    * TitlePane and iconified frame).
 856:    *
 857:    * @return The Frame Icon.
 858:    */
 859:   public Icon getFrameIcon()
 860:   {
 861:     return frameIcon;
 862:   }
 863: 
 864:   /**
 865:    * This method returns the Glass Pane used with this JInternalFrame.
 866:    *
 867:    * @return The Glass Pane used with this JInternalFrame.
 868:    */
 869:   public Component getGlassPane()
 870:   {
 871:     return getRootPane().getGlassPane();
 872:   }
 873: 
 874:   /**
 875:    * This method returns an array of InternalFrameListeners that are listening
 876:    * to this JInternalFrame.
 877:    *
 878:    * @return An array of InternalFrameListeners that are listening to this
 879:    *         JInternalFrame.
 880:    */
 881:   public InternalFrameListener[] getInternalFrameListeners()
 882:   {
 883:     return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class);
 884:   }
 885: 
 886:   /**
 887:    * This method returns the JMenuBar for this JInternalFrame.
 888:    *
 889:    * @return The JMenuBar for this JInternalFrame.
 890:    */
 891:   public JMenuBar getJMenuBar()
 892:   {
 893:     return getRootPane().getJMenuBar();
 894:   }
 895: 
 896:   /**
 897:    * This method returns the layer that this JInternalFrame resides in.
 898:    *
 899:    * @return The layer that this JInternalFrame resides in.
 900:    */
 901:   public int getLayer()
 902:   {
 903:     return JLayeredPane.getLayer(this);
 904:   }
 905: 
 906:   /**
 907:    * This method returns the LayeredPane for this JInternalFrame.
 908:    *
 909:    * @return The LayeredPane for this JInternalFrame.
 910:    */
 911:   public JLayeredPane getLayeredPane()
 912:   {
 913:     return getRootPane().getLayeredPane();
 914:   }
 915: 
 916:   /**
 917:    * This method is deprecated. This method returns the JMenuBar for this
 918:    * JInternalFrame.
 919:    *
 920:    * @return The JMenuBar for this JInternalFrame.
 921:    *
 922:    * @deprecated 1.0.3
 923:    */
 924:   public JMenuBar getMenuBar()
 925:   {
 926:     return getJMenuBar();
 927:   }
 928: 
 929:   /**
 930:    * This method returns the child Component that will receive focus when the
 931:    * JInternalFrame is selected. If the JInternalFrame is selected, this
 932:    * method returns getFocusOwner(). Otherwise, it will return the child
 933:    * Component that most recently requested focus. If that is null, then the
 934:    * initial focus Component is returned. If that is null, then the default
 935:    * focus component is returned.
 936:    *
 937:    * @return The most recent focus owner.
 938:    */
 939:   public Component getMostRecentFocusOwner()
 940:   {
 941:     if (isSelected())
 942:       return getFocusOwner();