Source for javax.swing.JInternalFrame

   1: /* JInternalFrame.java --
   2:    Copyright (C) 2002, 2004, 2005  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.Component;
  42: import java.awt.Container;
  43: import java.awt.Graphics;
  44: import java.awt.KeyboardFocusManager;
  45: import java.awt.LayoutManager;
  46: import java.awt.Rectangle;
  47: import java.beans.PropertyVetoException;
  48: 
  49: import javax.accessibility.Accessible;
  50: import javax.accessibility.AccessibleContext;
  51: import javax.accessibility.AccessibleRole;
  52: import javax.accessibility.AccessibleValue;
  53: import javax.swing.event.InternalFrameEvent;
  54: import javax.swing.event.InternalFrameListener;
  55: import javax.swing.plaf.DesktopIconUI;
  56: import javax.swing.plaf.InternalFrameUI;
  57: 
  58: /**
  59:  * This class implements a Swing widget that looks and acts like a native
  60:  * frame. The frame can be dragged, resized, closed, etc. Typically,
  61:  * JInternalFrames are placed in JDesktopPanes. The actions that the
  62:  * JInternalFrame performs (maximizing, minimizing, etc.) are performed by a
  63:  * DesktopManager. As with regular frames, components are added by calling
  64:  * frame.getContentPane().add.
  65:  */
  66: public class JInternalFrame extends JComponent implements Accessible,
  67:                                                           WindowConstants,
  68:                                                           RootPaneContainer
  69: {
  70:   /** DOCUMENT ME! */
  71:   private static final long serialVersionUID = -5425177187760785402L;
  72: 
  73:   /**
  74:    * DOCUMENT ME!
  75:    */
  76:   protected class AccessibleJInternalFrame extends AccessibleJComponent
  77:     implements AccessibleValue
  78:   {
  79:     private static final long serialVersionUID = 5931936924175476797L;
  80: 
  81:     /**
  82:      * Creates a new AccessibleJInternalFrame object.
  83:      */
  84:     protected AccessibleJInternalFrame()
  85:     {
  86:       super();
  87:     }
  88: 
  89:     /**
  90:      * DOCUMENT ME!
  91:      *
  92:      * @return DOCUMENT ME!
  93:      */
  94:     public String getAccessibleName()
  95:     {
  96:       return null;
  97:     }
  98: 
  99:     /**
 100:      * DOCUMENT ME!
 101:      *
 102:      * @return DOCUMENT ME!
 103:      */
 104:     public AccessibleRole getAccessibleRole()
 105:     {
 106:       return null;
 107:     }
 108: 
 109:     /**
 110:      * DOCUMENT ME!
 111:      *
 112:      * @return DOCUMENT ME!
 113:      */
 114:     public AccessibleValue getAccessibleValue()
 115:     {
 116:       return null;
 117:     }
 118: 
 119:     /**
 120:      * DOCUMENT ME!
 121:      *
 122:      * @return DOCUMENT ME!
 123:      */
 124:     public Number getCurrentAccessibleValue()
 125:     {
 126:       return null;
 127:     }
 128: 
 129:     /**
 130:      * DOCUMENT ME!
 131:      *
 132:      * @return DOCUMENT ME!
 133:      */
 134:     public Number getMaximumAccessibleValue()
 135:     {
 136:       return null;
 137:     }
 138: 
 139:     /**
 140:      * DOCUMENT ME!
 141:      *
 142:      * @return DOCUMENT ME!
 143:      */
 144:     public Number getMinimumAccessibleValue()
 145:     {
 146:       return null;
 147:     }
 148: 
 149:     /**
 150:      * DOCUMENT ME!
 151:      *
 152:      * @param n DOCUMENT ME!
 153:      *
 154:      * @return DOCUMENT ME!
 155:      */
 156:     public boolean setCurrentAccessibleValue(Number n)
 157:     {
 158:       return false;
 159:     }
 160:   }
 161: 
 162:   /**
 163:    * This class represents the JInternalFrame while it is iconified.
 164:    */
 165:   public static class JDesktopIcon extends JComponent implements Accessible
 166:   {
 167:     /**
 168:      * DOCUMENT ME!
 169:      */
 170:     protected class AccessibleJDesktopIcon extends AccessibleJComponent
 171:       implements AccessibleValue
 172:     {
 173:       private static final long serialVersionUID = 5035560458941637802L;
 174: 
 175:       /**
 176:        * Creates a new AccessibleJDesktopIcon object.
 177:        */
 178:       protected AccessibleJDesktopIcon()
 179:       {
 180:     super();
 181:       }
 182: 
 183:       /**
 184:        * DOCUMENT ME!
 185:        *
 186:        * @return DOCUMENT ME!
 187:        */
 188:       public AccessibleRole getAccessibleRole()
 189:       {
 190:     return null;
 191:       }
 192: 
 193:       /**
 194:        * DOCUMENT ME!
 195:        *
 196:        * @return DOCUMENT ME!
 197:        */
 198:       public AccessibleValue getAccessibleValue()
 199:       {
 200:     return null;
 201:       }
 202: 
 203:       /**
 204:        * DOCUMENT ME!
 205:        *
 206:        * @return DOCUMENT ME!
 207:        */
 208:       public Number getCurrentAccessibleValue()
 209:       {
 210:     return null;
 211:       }
 212: 
 213:       /**
 214:        * DOCUMENT ME!
 215:        *
 216:        * @return DOCUMENT ME!
 217:        */
 218:       public Number getMaximumAccessibleValue()
 219:       {
 220:     return null;
 221:       }
 222: 
 223:       /**
 224:        * DOCUMENT ME!
 225:        *
 226:        * @return DOCUMENT ME!
 227:        */
 228:       public Number getMinimumAccessibleValue()
 229:       {
 230:     return null;
 231:       }
 232: 
 233:       /**
 234:        * DOCUMENT ME!
 235:        *
 236:        * @param n DOCUMENT ME!
 237:        *
 238:        * @return DOCUMENT ME!
 239:        */
 240:       public boolean setCurrentAccessibleValue(Number n)
 241:       {
 242:     return false;
 243:       }
 244:     }
 245: 
 246:     private static final long serialVersionUID = 4672973344731387687L;
 247: 
 248:     /** The JInternalFrame this DesktopIcon represents. */
 249:     JInternalFrame frame;
 250: 
 251:     /**
 252:      * Creates a new JDesktopIcon object for representing the given frame.
 253:      *
 254:      * @param f The JInternalFrame to represent.
 255:      */
 256:     public JDesktopIcon(JInternalFrame f)
 257:     {
 258:       frame = f;
 259:       updateUI();
 260:     }
 261: 
 262:     /**
 263:      * DOCUMENT ME!
 264:      *
 265:      * @return DOCUMENT ME!
 266:      */
 267:     public AccessibleContext getAccessibleContext()
 268:     {
 269:       if (accessibleContext == null)
 270:     accessibleContext = new AccessibleJDesktopIcon();
 271:       return accessibleContext;
 272:     }
 273: 
 274:     /**
 275:      * This method returns the JDesktopPane this JDesktopIcon is in.
 276:      *
 277:      * @return The JDesktopPane this JDesktopIcon is in.
 278:      */
 279:     public JDesktopPane getDesktopPane()
 280:     {
 281:       JDesktopPane p = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
 282:                                                                         this);
 283:       return p;
 284:     }
 285: 
 286:     /**
 287:      * This method returns the JInternalFrame this JDesktopIcon represents.
 288:      *
 289:      * @return The JInternalFrame this JDesktopIcon represents.
 290:      */
 291:     public JInternalFrame getInternalFrame()
 292:     {
 293:       return frame;
 294:     }
 295: 
 296:     /**
 297:      * This method returns the UI that is responsible for the JDesktopIcon.
 298:      *
 299:      * @return The UI that is responsible for the JDesktopIcon.
 300:      */
 301:     public DesktopIconUI getUI()
 302:     {
 303:       return (DesktopIconUI) ui;
 304:     }
 305: 
 306:     /**
 307:      * This method returns the String identifier that is used to determine
 308:      * which class is used for JDesktopIcon's UI.
 309:      *
 310:      * @return A String identifier for the UI class.
 311:      */
 312:     public String getUIClassID()
 313:     {
 314:       return "DesktopIconUI";
 315:     }
 316: 
 317:     /**
 318:      * This method sets the JInternalFrame that this JDesktopIcon represents.
 319:      *
 320:      * @param f The JInternalFrame that this JDesktopIcon represents.
 321:      */
 322:     public void setInternalFrame(JInternalFrame f)
 323:     {
 324:       frame = f;
 325:     }
 326: 
 327:     /**
 328:      * This method sets the UI used for this JDesktopIcon.
 329:      *
 330:      * @param ui The UI to use.
 331:      */
 332:     public void setUI(DesktopIconUI ui)
 333:     {
 334:       super.setUI(ui);
 335:     }
 336: 
 337:     /**
 338:      * This method restores the UI property to the defaults.
 339:      */
 340:     public void updateUI()
 341:     {
 342:       setUI((DesktopIconUI) UIManager.getUI(this));
 343:     }
 344:   }
 345: 
 346:   /**
 347:    * The property fired in a PropertyChangeEvent when the contentPane property
 348:    * changes.
 349:    */
 350:   public static final String CONTENT_PANE_PROPERTY = "contentPane";
 351: 
 352:   /**
 353:    * The property fired in a PropertyChangeEvent when the frameIcon property
 354:    * changes.
 355:    */
 356:   public static final String FRAME_ICON_PROPERTY = "frameIcon";
 357: 
 358:   /**
 359:    * The property fired in a PropertyChangeEvent when the glassPane property
 360:    * changes.
 361:    */
 362:   public static final String GLASS_PANE_PROPERTY = "glassPane";
 363: 
 364:   /**
 365:    * The property fired in a PropertyChangeEvent when the closed property
 366:    * changes.
 367:    */
 368:   public static final String IS_CLOSED_PROPERTY = "closed";
 369: 
 370:   /**
 371:    * The property fired in a PropertyChangeEvent when the icon property
 372:    * changes.
 373:    */
 374:   public static final String IS_ICON_PROPERTY = "icon";
 375: 
 376:   /**
 377:    * The property fired in a PropertyChangeEvent when the maximum property
 378:    * changes.
 379:    */
 380:   public static final String IS_MAXIMUM_PROPERTY = "maximum";
 381: 
 382:   /**
 383:    * The property fired in a PropertyChangeEvent when the selected property
 384:    * changes.
 385:    */
 386:   public static final String IS_SELECTED_PROPERTY = "selected";
 387: 
 388:   /**
 389:    * The property fired in a PropertyChangeEvent when the layeredPane property
 390:    * changes.
 391:    */
 392:   public static final String LAYERED_PANE_PROPERTY = "layeredPane";
 393: 
 394:   /**
 395:    * The property fired in a PropertyChangeEvent when the jMenuBar property
 396:    * changes.
 397:    */
 398:   public static final String MENU_BAR_PROPERTY = "JMenuBar";
 399: 
 400:   /**
 401:    * The property fired in a PropertyChangeEvent when the rootPane property
 402:    * changes.
 403:    */
 404:   public static final String ROOT_PANE_PROPERTY = "rootPane";
 405: 
 406:   /**
 407:    * The property fired in a PropertyChangeEvent when the title property
 408:    * changes.
 409:    */
 410:   public static final String TITLE_PROPERTY = "title";
 411: 
 412:   /** Whether the JInternalFrame is closable. */
 413:   protected boolean closable;
 414: 
 415:   /** Whether the JInternalFrame can be iconified. */
 416:   protected boolean iconable;
 417: 
 418:   /** Whether the JInternalFrame is closed. */
 419:   protected boolean isClosed;
 420: 
 421:   /** Whether the JInternalFrame has been iconified. */
 422:   protected boolean isIcon;
 423: 
 424:   /** Whether the JInternalFrame has been maximized. */
 425:   protected boolean isMaximum;
 426: 
 427:   /** Whether the JInternalFrame is the active frame. */
 428:   protected boolean isSelected;
 429: 
 430:   /** Whether the JInternalFrame can be maximized. */
 431:   protected boolean maximizable;
 432: 
 433:   /**
 434:    * Whether the JInternalFrame has rootPaneChecking enabled.
 435:    *
 436:    * @specnote Should be false to comply with J2SE 5.0
 437:    */
 438:   protected boolean rootPaneCheckingEnabled = false;
 439: 
 440:   /** Whether the JInternalFrame is resizable. */
 441:   protected boolean resizable;
 442: 
 443:   /**
 444:    * The JDesktopIcon that represents the JInternalFrame while it is
 445:    * iconified.
 446:    */
 447:   protected JDesktopIcon desktopIcon;
 448: 
 449:   /** The icon used in the JMenuBar in the TitlePane. */
 450:   protected Icon frameIcon;
 451: 
 452:   /** The rootPane of the JInternalFrame. */
 453:   protected JRootPane rootPane;
 454: 
 455:   /** The title on the TitlePane of the JInternalFrame. */
 456:   protected String title;
 457: 
 458:   /** The bounds of the JInternalFrame before it was maximized. */
 459:   private transient Rectangle storedBounds;
 460: 
 461:   /** The Component that receives focus by default. */
 462:   private transient Component defaultFocus;
 463: 
 464:   /** The default close action taken, */
 465:   private transient int defaultCloseOperation = DISPOSE_ON_CLOSE;
 466: 
 467:   /** Whether the JInternalFrame has become visible for the very first time. */
 468:   private transient boolean isFirstTimeVisible = true;
 469: 
 470:   /**
 471:    * Whether the JInternalFrame is in the transition from being a maximized
 472:    * frame back to a regular sized frame.
 473:    */
 474:   private transient boolean maxTransition = false;
 475: 
 476:   /** DOCUMENT ME! */
 477:   private transient boolean wasIcon = false;
 478: 
 479:   /**
 480:    * Creates a new JInternalFrame object that has no title, and is
 481:    * non-resizable, non-maximizable, non-iconifiable, and non-closable.
 482:    */
 483:   public JInternalFrame()
 484:   {
 485:     this(null, false, false, false, false);
 486:   }
 487: 
 488:   /**
 489:    * Creates a new JInternalFrame object with the given title and is
 490:    * non-resizable, non-maximizable, non-iconifiable, and non-closable.
 491:    *
 492:    * @param title The title displayed in the JInternalFrame.
 493:    */
 494:   public JInternalFrame(String title)
 495:   {
 496:     this(title, false, false, false, false);
 497:   }
 498: 
 499:   /**
 500:    * Creates a new JInternalFrame object with the given title and resizable
 501:    * properties. The JInternalFrame is non-maximizable, non-iconifiable, and
 502:    * non-closable.
 503:    *
 504:    * @param title The title displayed in the JInternalFrame.
 505:    * @param resizable Whether the JInternalFrame is resizable.
 506:    */
 507:   public JInternalFrame(String title, boolean resizable)
 508:   {
 509:     this(title, resizable, false, false, false);
 510:   }
 511: 
 512:   /**
 513:    * Creates a new JInternalFrame object with the given title, resizable, and
 514:    * closable properties. The JInternalFrame is non-maximizable and
 515:    * non-iconifiable.
 516:    *
 517:    * @param title The title displayed in the JInternalFrame.
 518:    * @param resizable Whether the JInternalFrame is resizable.
 519:    * @param closable Whether the JInternalFrame is closable.
 520:    */
 521:   public JInternalFrame(String title, boolean resizable, boolean closable)
 522:   {
 523:     this(title, resizable, closable, false, false);
 524:   }
 525: 
 526:   /**
 527:    * Creates a new JInternalFrame object with the given title, resizable,
 528:    * closable and maximizable properties. The JInternalFrame is
 529:    * non-iconifiable.
 530:    *
 531:    * @param title The title displayed in the JInternalFrame.
 532:    * @param resizable Whether the JInternalFrame is resizable.
 533:    * @param closable Whether the JInternalFrame is closable.
 534:    * @param maximizable Whether the JInternalFrame is maximizable.
 535:    */
 536:   public JInternalFrame(String title, boolean resizable, boolean closable,
 537:                         boolean maximizable)
 538:   {
 539:     this(title, resizable, closable, maximizable, false);
 540:   }
 541: 
 542:   /**
 543:    * Creates a new JInternalFrame object with the given title, resizable,
 544:    * closable, maximizable and iconifiable properties.
 545:    *
 546:    * @param title The title displayed in the JInternalFrame.
 547:    * @param resizable Whether the JInternalFrame is resizable.
 548:    * @param closable Whether the JInternalFrame is closable.
 549:    * @param maximizable Whether the JInternalFrame is maximizable.
 550:    * @param iconifiable Whether the JInternalFrame is iconifiable.
 551:    */
 552:   public JInternalFrame(String title, boolean resizable, boolean closable,
 553:                         boolean maximizable, boolean iconifiable)
 554:   {
 555:     this.title = title;
 556:     this.resizable = resizable;
 557:     this.closable = closable;
 558:     this.maximizable = maximizable;
 559:     this.iconable = iconifiable;
 560:     storedBounds = new Rectangle();
 561:     setRootPane(createRootPane());
 562:     updateUI();
 563:     setRootPaneCheckingEnabled(true); // Done the init stage, now adds go to content pane.
 564:   }
 565: 
 566:   /**
 567:    * This method adds Components to this Container. For JInternalFrames,
 568:    * instead of calling add directly on the JInternalFrame, it should be
 569:    * called with JInternalFrame.getContentPane().add. If root pane checking
 570:    * is enabled, calling this method will cause an exception to be thrown.
 571:    *
 572:    * @param comp The Component to add.
 573:    * @param constraints The constraints on the Component added.
 574:    * @param index The position to place the Component.
 575:    *
 576:    * @throws Error DOCUMENT ME!
 577:    */
 578:   protected void addImpl(Component comp, Object constraints, int index)
 579:   {
 580:     // If we're in the initialization stage use super.add. Here we add the
 581:     // rootPane as well as the title bar and other stuff.
 582:     // Otherwise pass the add onto the content pane.
 583:     if (isRootPaneCheckingEnabled())
 584:       getContentPane().add(comp, constraints, index);
 585:     else
 586:       super.addImpl(comp,constraints, index);
 587:   }
 588: 
 589:   /**
 590:    * This method adds an InternalFrameListener to this JInternalFrame.
 591:    *
 592:    * @param l The listener to add.
 593:    */
 594:   public void addInternalFrameListener(InternalFrameListener l)
 595:   {
 596:     listenerList.add(InternalFrameListener.class, l);
 597:   }
 598: 
 599:   /**
 600:    * This method is used to create a root pane for the JInternalFrame. This
 601:    * method is called by the constructors.
 602:    *
 603:    * @return A root pane for the JInternalFrame to use.
 604:    */
 605:   protected JRootPane createRootPane()
 606:   {
 607:     return new JRootPane();
 608:   }
 609: 
 610:   /**
 611:    * This method makes this JInternalFrame invisible, unselected and closed.
 612:    * If this JInternalFrame is not closed already, it will fire an
 613:    * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it
 614:    * doesn't give vetoable listeners a chance to veto and it will not fire an
 615:    * INTERNAL_FRAME_CLOSING event.
 616:    */
 617:   public void dispose()
 618:   {
 619:     hide();
 620:     JDesktopPane pane = getDesktopPane();
 621:     if (pane != null)
 622:       pane.setSelectedFrame(null);
 623:     else
 624:       {
 625:     try
 626:       {
 627:         setSelected(false);
 628:       }
 629:     catch (PropertyVetoException e)
 630:       {
 631:         // Do nothing if they don't want to be unselected.
 632:       }
 633:       }
 634:     isClosed = true;
 635:     fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
 636:     removeNotify();
 637:   }
 638: 
 639:   /**
 640:    * This method is used for closing this JInternalFrame. It fires an
 641:    * INTERNAL_FRAME_CLOSING event and then performs the action specified by
 642:    * the default close operation.
 643:    */
 644:   public void doDefaultCloseAction()
 645:   {
 646:     fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
 647:     switch (getDefaultCloseOperation())
 648:       {
 649:       case HIDE_ON_CLOSE:
 650:     hide();
 651:     break;
 652:       case DISPOSE_ON_CLOSE:
 653:     dispose();
 654:     break;
 655:       }
 656:   }
 657: 
 658:   /**
 659:    * This method fires an InternalFrameEvent to the listeners.
 660:    *
 661:    * @param id The type of event being fired. See InternalFrameEvent.
 662:    */
 663:   protected void fireInternalFrameEvent(int id)
 664:   {
 665:     Object[] ifListeners = listenerList.getListenerList();
 666:     InternalFrameEvent evt = new InternalFrameEvent(this, id);
 667:     switch (id)
 668:       {
 669:       case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
 670:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 671:       {
 672:         if (ifListeners[i] == InternalFrameListener.class)
 673:           ((InternalFrameListener) ifListeners[i + 1])
 674:           .internalFrameClosing(evt);
 675:       }
 676:     break;
 677:       case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
 678:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 679:       {
 680:         if (ifListeners[i] == InternalFrameListener.class)
 681:           ((InternalFrameListener) ifListeners[i + 1])
 682:           .internalFrameActivated(evt);
 683:       }
 684:     break;
 685:       case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
 686:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 687:       {
 688:         if (ifListeners[i] == InternalFrameListener.class)
 689:           ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt);
 690:       }
 691:     break;
 692:       case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
 693:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 694:       {
 695:         if (ifListeners[i] == InternalFrameListener.class)
 696:           ((InternalFrameListener) ifListeners[i + 1])
 697:           .internalFrameDeactivated(evt);
 698:       }
 699:     break;
 700:       case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
 701:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 702:       {
 703:         if (ifListeners[i] == InternalFrameListener.class)
 704:           ((InternalFrameListener) ifListeners[i + 1])
 705:           .internalFrameDeiconified(evt);
 706:       }
 707:     break;
 708:       case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
 709:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 710:       {
 711:         if (ifListeners[i] == InternalFrameListener.class)
 712:           ((InternalFrameListener) ifListeners[i + 1])
 713:           .internalFrameIconified(evt);
 714:       }
 715:     break;
 716:       case InternalFrameEvent.INTERNAL_FRAME_OPENED:
 717:     for (int i = ifListeners.length - 2; i >= 0; i -= 2)
 718:       {
 719:         if (ifListeners[i] == InternalFrameListener.class)
 720:           ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt);
 721:       }
 722:     break;
 723:       }
 724:   }
 725: 
 726:   /**
 727:    * DOCUMENT ME!
 728:    *
 729:    * @return DOCUMENT ME!
 730:    */
 731:   public AccessibleContext getAccessibleContext()
 732:   {
 733:     if (accessibleContext == null)
 734:       accessibleContext = new AccessibleJInternalFrame();
 735:     return accessibleContext;
 736:   }
 737: 
 738:   /**
 739:    * This method returns the Content Pane for this JInternalFrame.
 740:    *
 741:    * @return The Content Pane for this JInternalFrame.
 742:    */
 743:   public Container getContentPane()
 744:   {
 745:     return getRootPane().getContentPane();
 746:   }
 747: 
 748:   /**
 749:    * This method returns the default action taken when this JInternalFrame is
 750:    * closed.
 751:    *
 752:    * @return The default action taken when this JInternalFrame is closed.
 753:    */
 754:   public int getDefaultCloseOperation()
 755:   {
 756:     return defaultCloseOperation;
 757:   }
 758: 
 759:   /**
 760:    * This method returns the JDesktopIcon that represents this JInternalFrame
 761:    * while it is iconified.
 762:    *
 763:    * @return The JDesktopIcon that represents this JInternalFrame while it is
 764:    *         iconified.
 765:    */
 766:   public JDesktopIcon getDesktopIcon()
 767:   {
 768:     if (desktopIcon == null)
 769:       desktopIcon = new JDesktopIcon(this);
 770:     return desktopIcon;
 771:   }
 772: 
 773:   /**
 774:    * This method searches this JInternalFrame ancestors for an instance of
 775:    * JDesktopPane. If one is found, it is returned. If none is found, then it
 776:    * will search the JDesktopIcon for a JDesktopPane.
 777:    *
 778:    * @return The JDesktopPane that this JInternalFrame belongs to.
 779:    */
 780:   public JDesktopPane getDesktopPane()
 781:   {
 782:     JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
 783:                                                                           this);
 784:     if (value == null && desktopIcon != null)
 785:       value = desktopIcon.getDesktopPane();
 786:     return value;
 787:   }
 788: 
 789:   /**
 790:    * This method returns null because this must always be the root of a focus
 791:    * traversal.
 792:    *
 793:    * @return always null
 794:    *
 795:    * @since 1.4
 796:    */
 797:   public final Container getFocusCycleRootAncestor()
 798:   {
 799:     // as defined.
 800:     return null;
 801:   }
 802: 
 803:   /**
 804:    * This method returns the child Component that will receive focus if this
 805:    * JInternalFrame is selected.
 806:    *
 807:    * @return The child Component that will receive focus.
 808:    */
 809:   public Component getFocusOwner()
 810:   {
 811:     if (isSelected())
 812:       {
 813:     Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
 814:     if (SwingUtilities.isDescendingFrom(focus, this))
 815:       {
 816:         defaultFocus = focus;
 817:         return focus;
 818:       }
 819:       }
 820:     return null;
 821:   }
 822: 
 823:   /**
 824:    * This method returns the Frame Icon (the icon used in the JInternalFrame
 825:    * TitlePane and iconified frame).
 826:    *
 827:    * @return The Frame Icon.
 828:    */
 829:   public Icon getFrameIcon()
 830:   {
 831:     return frameIcon;
 832:   }
 833: 
 834:   /**
 835:    * This method returns the Glass Pane used with this JInternalFrame.
 836:    *
 837:    * @return The Glass Pane used with this JInternalFrame.
 838:    */
 839:   public Component getGlassPane()
 840:   {
 841:     return getRootPane().getGlassPane();
 842:   }
 843: 
 844:   /**
 845:    * This method returns an array of InternalFrameListeners that are listening
 846:    * to this JInternalFrame.
 847:    *
 848:    * @return An array of InternalFrameListeners that are listening to this
 849:    *         JInternalFrame.
 850:    */
 851:   public InternalFrameListener[] getInternalFrameListeners()
 852:   {
 853:     return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class);
 854:   }
 855: 
 856:   /**
 857:    * This method returns the JMenuBar for this JInternalFrame.
 858:    *
 859:    * @return The JMenuBar for this JInternalFrame.
 860:    */
 861:   public JMenuBar getJMenuBar()
 862:   {
 863:     return getRootPane().getJMenuBar();
 864:   }
 865: 
 866:   /**
 867:    * This method returns the layer that this JInternalFrame resides in.
 868:    *
 869:    * @return The layer that this JInternalFrame resides in.
 870:    */
 871:   public int getLayer()
 872:   {
 873:     JDesktopPane pane = getDesktopPane();
 874:     if (pane != null)
 875:       // The cast here forces the call to the instance method getLayer()
 876:       // instead of the static method (this would lead to infinite
 877:       // recursion).
 878:       return pane.getLayer((Component) this);
 879:     return -1;
 880:   }
 881: 
 882:   /**
 883:    * This method returns the LayeredPane for this JInternalFrame.
 884:    *
 885:    * @return The LayeredPane for this JInternalFrame.
 886:    */
 887:   public JLayeredPane getLayeredPane()
 888:   {
 889:     return getRootPane().getLayeredPane();
 890:   }
 891: 
 892:   /**
 893:    * This method is deprecated. This method returns the JMenuBar for this
 894:    * JInternalFrame.
 895:    *
 896:    * @return The JMenuBar for this JInternalFrame.
 897:    *
 898:    * @deprecated 1.0.3
 899:    */
 900:   public JMenuBar getMenuBar()
 901:   {
 902:     return getJMenuBar();
 903:   }
 904: 
 905:   /**
 906:    * This method returns the child Component that will receive focus when the
 907:    * JInternalFrame is selected. If the JInternalFrame is selected, this
 908:    * method returns getFocusOwner(). Otherwise, it will return the child
 909:    * Component that most recently requested focus. If that is null, then the
 910:    * initial focus Component is returned. If that is null, then the default
 911:    * focus component is returned.
 912:    *
 913:    * @return The most recent focus owner.
 914:    */
 915:   public Component getMostRecentFocusOwner()
 916:   {
 917:     if (isSelected())
 918:       return getFocusOwner();
 919:     else
 920:       return defaultFocus;
 921:   }
 922: 
 923:   /**
 924:    * This method returns the bounds of the JInternalFrame if it is not
 925:    * maximized. If it is maximized, it returns the bounds of the
 926:    * JInternalFrame before it was maximized (the bounds that it will be
 927:    * restored to).
 928:    *
 929:    * @return A Rectangle that contains this JInternalFrame's normal bounds (or
 930:    *         just its bounds if it is not maximized).
 931:    */
 932:   public Rectangle getNormalBounds()
 933:   {
 934:     if (! isMaximum() && ! maxTransition)
 935:       return getBounds();
 936:     else
 937:       return storedBounds;
 938:   }
 939: 
 940:   /**
 941:    * This method returns the Root Pane for this JInternalFrame.
 942:    *
 943:    * @return The Root Pane for this JInternalFrame.
 944:    */
 945:   public JRootPane getRootPane()
 946:   {
 947:     return rootPane;
 948:   }
 949: 
 950:   /**
 951:    * This method sets the title of the JInternalFrame.
 952:    *
 953:    * @return The String displayed in the TitlePane of this JInternalFrame.
 954:    */
 955:   public String getTitle()
 956:   {
 957:     return title;
 958:   }
 959: 
 960:   /**
 961:    * This method returns the UI used to represent the JInternalFrame.
 962:    *
 963:    * @return The UI used to represent the JInternalFrame.
 964:    */
 965:   public InternalFrameUI getUI()
 966:   {
 967:     return (InternalFrameUI) ui;
 968:   }
 969: 
 970:   /**
 971:    * This method returns a String identifier that is used to determine which
 972:    * class acts as the JInternalFrame's UI.
 973:    *
 974:    * @return A String identifier to determine a UI class.
 975:    */
 976:   public String getUIClassID()
 977:   {
 978:     return "InternalFrameUI";
 979:   }
 980: 
 981:   /**
 982:    * This method returns null.
 983:    *
 984:    * @return null.
 985:    */
 986:   public final String getWarningString()
 987:   {
 988:     // as defined.
 989:     return null;
 990:   }
 991: 
 992:   /**
 993:    * This method deselects this JInternalFrame and hides it.
 994:    */
 995:   public void hide()
 996:   {
 997:     JDesktopPane pane = getDesktopPane();
 998:     if (pane != null)
 999:       pane.setSelectedFrame(null);
1000:     else
1001:       {
1002:     try
1003:       {
1004:         setSelected(false);
1005:       }
1006:     catch (PropertyVetoException e)
1007:       {
1008:         // Do nothing.
1009:       }
1010:       }
1011:     super.hide();
1012:   }
1013: 
1014:   /**
1015:    * This method returns whether this JInternalFrame is closable.
1016:    *
1017:    * @return Whether this JInternalFrame is closable.
1018:    */
1019:   public boolean isClosable()
1020:   {
1021:     return closable;
1022:   }
1023: 
1024:   /**
1025:    * This method returns whether this JInternalFrame has been closed.
1026:    *
1027:    * @return Whether this JInternalFrame is closed.
1028:    */
1029:   public boolean isClosed()
1030:   {
1031:     return isClosed;
1032:   }
1033: 
1034:   /**
1035:    * This must always return true.
1036:    *
1037:    * @return always true
1038:    *
1039:    * @since 1.4
1040:    */
1041:   public final boolean isFocusCycleRoot()
1042:   {
1043:     return true;
1044:   }
1045: 
1046:   /**
1047:    * This method returns whether this JInternalFrame is currently iconified.
1048:    *
1049:    * @return Whether this JInternalFrame is currently iconified.
1050:    */
1051:   public boolean isIcon()
1052:   {
1053:     return isIcon;
1054:   }
1055: 
1056:   /**
1057:    * This method returns whether the JInternalFrame can be iconified.
1058:    *
1059:    * @return Whether the JInternalFrame can be iconified.
1060:    */
1061:   public boolean isIconifiable()
1062:   {
1063:     return iconable;
1064:   }
1065: 
1066:   /**
1067:    * This method returns whether this JInternalFrame can be maximized.
1068:    *
1069:    * @return Whether this JInternalFrame can be maximized.
1070:    */
1071:   public boolean isMaximizable()
1072:   {
1073:     return maximizable;
1074:   }
1075: 
1076:   /**
1077:    * This method returns whether this JInternalFrame is currently maximized.
1078:    *
1079:    * @return Whether this JInternalFrame is maximized.
1080:    */
1081:   public boolean isMaximum()
1082:   {
1083:     return isMaximum;
1084:   }
1085: 
1086:   /**
1087:    * This method returns whether this JInternalFrame is resizable.
1088:    *
1089:    * @return Whether this JInternalFrame is resizable.
1090:    */
1091:   public boolean isResizable()
1092:   {
1093:     return resizable;
1094:   }
1095: 
1096:   /**
1097:    * This method returns whether root pane checking is enabled. If root pane
1098:    * checking is enabled, then calls to addImpl and setLayout will throw
1099:    * exceptions.
1100:    *
1101:    * @return Whether root pane checking is enabled.
1102:    */
1103:   protected boolean isRootPaneCheckingEnabled()
1104:   {
1105:     return rootPaneCheckingEnabled;
1106:   }
1107: 
1108:   /**
1109:    * This method returns whether this JInternalFrame is selected.
1110:    *
1111:    * @return Whether this JInternalFrame is selected.
1112:    */
1113:   public boolean isSelected()
1114:   {
1115:     return isSelected;
1116:   }
1117: 
1118:   /**
1119:    * A helper method that moves this JInternalFrame to the back if the parent
1120:    * is a JLayeredPane.
1121:    */
1122:   public void moveToBack()
1123:   {
1124:     if (getParent() instanceof JLayeredPane)
1125:       ((JLayeredPane) getParent()).moveToBack(this);
1126:   }
1127: 
1128:   /**
1129:    * A helper method that moves this JInternalFrame to the front if the parent
1130:    * is a JLayeredPane.
1131:    */
1132:   public void moveToFront()
1133:   {
1134:     if (getParent() instanceof JLayeredPane)
1135:       ((JLayeredPane) getParent()).moveToFront(this);
1136:   }
1137: 
1138:   /**
1139:    * This method causes the children of this JInternalFrame to be laid out.
1140:    * Before it begins, if this JInternalFrame is an icon, then it will be
1141:    * deiconified. If it is maximized, then it will be restored. If either
1142:    * operation fails, then this method will return.
1143:    */
1144:   public void pack()
1145:   {
1146:     try
1147:       {
1148:     if (isIcon())
1149:       setIcon(false);
1150:     else if (isMaximum())
1151:       setMaximum(false);
1152:       }
1153:     catch (PropertyVetoException e)
1154:       {
1155:     // Do nothing if they don't want to be restored first.
1156:       }
1157:     setSize(getPreferredSize());
1158:   }
1159: 
1160:   /**
1161:    * This method is overridden to allow for speedier painting while this
1162:    * JInternalFramme is being dragged.
1163:    *
1164:    * @param g The Graphics object to paint with.
1165:    */
1166:   protected void paintComponent(Graphics g)
1167:   {
1168:     super.paintComponent(g);
1169:   }
1170: 
1171:   /**
1172:    * This method returns a String describing this JInternalFrame.
1173:    *
1174:    * @return A String describing this JInternalFrame.
1175:    */
1176:   protected String paramString()
1177:   {
1178:     return super.paramString();
1179:   }
1180: 
1181:   /**
1182:    * This method removes the given Component from the Container.
1183:    *
1184:    * @param comp The Component to remove.
1185:    */
1186:   public void remove(Component comp)
1187:   {
1188:     // If we're removing the root pane, use super.remove.  Otherwise
1189:     // pass it on to the content pane instead.
1190:     if (comp==rootPane)
1191:       super.remove(comp);
1192:     else
1193:       getContentPane().remove(comp);
1194:   }
1195: 
1196:   /**
1197:    * This method removes an InternalFrameListener from this JInternalFrame.
1198:    *
1199:    * @param l The listener to remove.
1200:    */
1201:   public void removeInternalFrameListener(InternalFrameListener l)
1202:   {
1203:     listenerList.remove(InternalFrameListener.class, l);
1204:   }
1205: 
1206:   /**
1207:    * This method resizes and positions this JInternalFrame. It also forces a
1208:    * relayout of the Container.
1209:    *
1210:    * @param x The x position of this JInternalFrame.
1211:    * @param y The y position of this JInternalFrame.
1212:    * @param width The width of this JInternalFrame.
1213:    * @param height The height of this JInternalFrame.
1214:    */
1215:   public void reshape(int x, int y, int width, int height)
1216:   {
1217:     super.reshape(x, y, width, height);
1218:     revalidate();
1219:   }
1220: 
1221:   /**
1222:    * This method gives focus to the last child Component that had focus. This
1223:    * is used by the UI when this JInternalFrame is activated.
1224:    */
1225:   public void restoreSubcomponentFocus()
1226:   {
1227:     Component c = getMostRecentFocusOwner();
1228:     if (c != null)
1229:       c.requestFocus();
1230:   }
1231: 
1232:   /**
1233:    * This method sets whether this JInternalFrame can be closed.
1234:    *
1235:    * @param b Whether this JInternalFrame can be closed.
1236:    */
1237:   public void setClosable(boolean b)
1238:   {
1239:     closable = b;
1240:   }
1241: 
1242:   /**
1243:    * This method closes the JInternalFrame if the given boolean is true. If it
1244:    * is false, then the result of this method is unspecified. If the
1245:    * JInternalFrame is closed, this method does nothing. This method will
1246:    * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto
1247:    * listeners to cancel the close. If no listener vetoes the change, the
1248:    * closed property is set to true and the JInternalFrame is hidden and
1249:    * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED
1250:    * event.
1251:    *
1252:    * @param b Whether the JInternalFrame will be closed.
1253:    *
1254:    * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1255:    */
1256:   public void setClosed(boolean b) throws PropertyVetoException
1257:   {
1258:     if (b && ! isClosed())
1259:       {
1260:     fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
1261:     fireVetoableChange(IS_CLOSED_PROPERTY, false, true);
1262: 
1263:     isClosed = b;
1264: 
1265:     firePropertyChange(IS_CLOSED_PROPERTY, false, true);
1266:     fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
1267:       }
1268:   }
1269: 
1270:   /**
1271:    * This method sets the Container to be used as a Content Pane for this
1272:    * JInternalFrame.
1273:    *
1274:    * @param c The Container to use as a Content Pane.
1275:    */
1276:   public void setContentPane(Container c)
1277:   {
1278:     if (c != getContentPane())
1279:       {
1280:     Container old = getContentPane();
1281:     getRootPane().setContentPane(c);
1282:     firePropertyChange(CONTENT_PANE_PROPERTY, old, c);
1283:       }
1284:   }
1285: 
1286:   /**
1287:    * This method sets the action taken when this JInternalFrame is closed.
1288:    *
1289:    * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or
1290:    *        DISPOSE_ON_CLOSE.
1291:    *
1292:    * @throws Error If the given operation is not one of the allowed modes.
1293:    */
1294:   public void setDefaultCloseOperation(int operation)
1295:   {
1296:     /* Reference implementation allows invalid operations to be specified.
1297:        In that case, behaviour defaults to DO_NOTHING_ON_CLOSE.
1298:        processWindowEvent handles the behaviour. getDefaultCloseOperation
1299:        must return the invalid operator code. */
1300:     defaultCloseOperation = operation;
1301:   }
1302: 
1303:   /**
1304:    * This method sets the JDesktopIcon that represents this JInternalFrame
1305:    * while it is iconified.
1306:    *
1307:    * @param d The JDesktopIcon that represents this JInternalFrame while it is
1308:    *        iconified.
1309:    */
1310:   public void setDesktopIcon(JDesktopIcon d)
1311:   {
1312:     d.setInternalFrame(this);
1313:     desktopIcon = d;
1314:   }
1315: 
1316:   /**
1317:    * This method does nothing because this must be the root of a focus
1318:    * traversal cycle.
1319:    *
1320:    * @param focusCycleRoot Not used.
1321:    */
1322:   public final void setFocusCycleRoot(boolean focusCycleRoot)
1323:   {
1324:     // Do nothing
1325:   }
1326: 
1327:   /**
1328:    * This method sets the Icon to be used in two places. The first is icon
1329:    * that is painted at the top left corner of the JInternalFrame when it is
1330:    * not iconified (clicking on that icon will activate the TitlePane
1331:    * JMenuBar). When the JInternalFrame is iconified, it will be the icon
1332:    * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame
1333:    * will use a Look and Feel default.
1334:    *
1335:    * @param icon The Icon used in the TitlePane JMenuBar and iconified frames.
1336:    */
1337:   public void setFrameIcon(Icon icon)
1338:   {
1339:     if (icon != frameIcon)
1340:       {
1341:     Icon old = frameIcon;
1342:     frameIcon = icon;
1343:     firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon);
1344:       }
1345:   }
1346: 
1347:   /**
1348:    * This method sets the Glass Pane used with this JInternalFrame.
1349:    *
1350:    * @param glass The Glass Pane to use with this JInternalFrame.
1351:    */
1352:   public void setGlassPane(Component glass)
1353:   {
1354:     if (glass != getGlassPane())
1355:       {
1356:     Component old = getGlassPane();
1357:     getRootPane().setGlassPane(glass);
1358:     firePropertyChange(GLASS_PANE_PROPERTY, old, glass);
1359:       }
1360:   }
1361: 
1362:   /**
1363:    * This method iconifies or deiconifies this JInternalFrame given the
1364:    * boolean argument. If the JInternalFrame becomes iconified, it will fire
1365:    * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes
1366:    * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event.
1367:    *
1368:    * @param b Whether this JInternalFrame is to be iconified or deiconified.
1369:    *
1370:    * @throws PropertyVetoException DOCUMENT ME!
1371:    */
1372:   public void setIcon(boolean b) throws PropertyVetoException
1373:   {
1374:     if (b != isIcon())
1375:       {
1376:     fireVetoableChange(IS_ICON_PROPERTY, b, isIcon);
1377: 
1378:     isIcon = b;
1379: 
1380:     firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon);
1381:     if (b)
1382:       fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
1383:     else
1384:       fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
1385:       }
1386:   }
1387: 
1388:   /**
1389:    * This method sets whether the JInternalFrame can be iconified. (This means
1390:    * that the JInternalFrame can be turned into an icon if minimized).
1391:    *
1392:    * @param b Whether the JInternalFrame can be iconified.
1393:    */
1394:   public void setIconifiable(boolean b)
1395:   {
1396:     iconable = b;
1397:   }
1398: 
1399:   /**
1400:    * This method sets the JMenuBar to be used with this JInternalFrame.
1401:    *
1402:    * @param b The JMenuBar to be used with this JInternalFrame.
1403:    */
1404:   public void setJMenuBar(JMenuBar b)
1405:   {
1406:     getRootPane().setJMenuBar(b);
1407:   }
1408: 
1409:   /**
1410:    * A helper method that set the layer that this JInternalFrame resides in.
1411:    * Using this version of the method means that the user should not set it
1412:    * to values that are already defined in JLayeredPane. If predefined values
1413:    * are to be used, the user should use the setLayer(Integer) version.
1414:    *
1415:    * @param layer The layer to place this JInternalFrame in.
1416:    */
1417:   public void setLayer(int layer)
1418:   {
1419:     setLayer(new Integer(layer));
1420:   }
1421: 
1422:   /**
1423:    * A helper method that sets the layer that this JInternalFrame resides in.
1424:    * Calling this version of the method should use layer values that are
1425:    * already defined in JLayeredPane.
1426:    *
1427:    * @param layer The layer to place this JInternalFrame in.
1428:    */
1429:   public void setLayer(Integer layer)
1430:   {
1431:     JDesktopPane p = getDesktopPane();
1432:     if (p != null)
1433:       {
1434:     int pos = p.getPosition(this);
1435:     p.setLayer(this, layer.intValue(), pos);
1436:       }
1437:   }
1438: 
1439:   /**
1440:    * This method sets the JLayeredPane to use with this JInternalFrame.
1441:    *
1442:    * @param layered The JLayeredPane to use as a layeredPane.
1443:    */
1444:   public void setLayeredPane(JLayeredPane layered)
1445:   {
1446:     if (layered != getLayeredPane())
1447:       {
1448:     JLayeredPane old = getLayeredPane();
1449:     getRootPane().setLayeredPane(layered);
1450:     firePropertyChange(LAYERED_PANE_PROPERTY, old, layered);
1451:       }
1452:   }
1453: 
1454:   /**
1455:    * This method sets whether the JInternalFrame can be maximized.
1456:    *
1457:    * @param b Whether this JInternalFrame can be maximized.
1458:    */
1459:   public void setMaximizable(boolean b)
1460:   {
1461:     maximizable = b;
1462:   }
1463: 
1464:   /**
1465:    * This method sets the Layout Manager used in the JInternalFrame. SetLayout
1466:    * should not be called on the JInternalFrame directly. Instead, it should
1467:    * be called with JInternalFrame.getContentPane().setLayout. Calls to this
1468:    * method with root pane checking enabled will cause exceptions to be
1469:    * thrown.
1470:    *
1471:    * @param manager The Layout Manager to be used with the JInternalFrame.
1472:    *
1473:    * @throws Error If rootPaneChecking is enabled.
1474:    */
1475:   public void setLayout(LayoutManager manager)
1476:   {
1477:     // Check if we're in initialization stage.  If so, call super.setLayout
1478:     // otherwise, valid calls go to the content pane.
1479:     if (isRootPaneCheckingEnabled())
1480:       getContentPane().setLayout(manager);
1481:     else
1482:       super.setLayout(manager);
1483:   }
1484: 
1485:   /**
1486:    * This method sets the JInternalFrame to maximized (if the given argument
1487:    * is true) or restores the JInternalFrame to its normal bounds otherwise.
1488:    *
1489:    * @param b Whether this JInteralFrame will be maximized or restored.
1490:    *
1491:    * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1492:    */
1493:   public void setMaximum(boolean b) throws PropertyVetoException
1494:   {
1495:     if (b != isMaximum())
1496:       {
1497:     fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum);
1498:     isMaximum = b;
1499:     if (b)
1500:       setNormalBounds(getBounds());
1501:     maxTransition = ! b;
1502:     firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum);
1503:     maxTransition = false;
1504:       }
1505:   }
1506: 
1507:   /**
1508:    * This method is deprecated. This method sets the JMenuBar used with this
1509:    * JInternalFrame.
1510:    *
1511:    * @param m The JMenuBar to use with this JInternalFrame.
1512:    *
1513:    * @deprecated 1.0.3
1514:    */
1515:   public void setMenuBar(JMenuBar m)
1516:   {
1517:     setJMenuBar(m);
1518:   }
1519: 
1520:   /**
1521:    * This method sets the bounds that this JInternalFrame will be restored to.
1522:    *
1523:    * @param r The bounds that this JInternalFrame will be restored to.
1524:    */
1525:   public void setNormalBounds(Rectangle r)
1526:   {
1527:     storedBounds.setBounds(r.x, r.y, r.width, r.height);
1528:   }
1529: 
1530:   /**
1531:    * This method sets whether the JInternalFrame can be resized by a user
1532:    * action (like dragging at the frame borders).
1533:    *
1534:    * @param b Whether this JInternalFramer can be resized.
1535:    */
1536:   public void setResizable(boolean b)
1537:   {
1538:     resizable = b;
1539:   }
1540: 
1541:   /**
1542:    * This method sets the Root Pane for this JInternalFrame.
1543:    *
1544:    * @param root The Root Pane for this JInternalFrame.
1545:    */
1546:   protected void setRootPane(JRootPane root)
1547:   {
1548:     if (rootPane != null)
1549:       remove(rootPane);
1550: 
1551:     rootPane = root;
1552:     add(root);
1553:   }
1554: 
1555:   /**
1556:    * This method sets whether root pane checking is enabled. If root pane
1557:    * checking is enabled, then calls to addImpl and setLayout will throw
1558:    * exceptions.
1559:    *
1560:    * @param enabled Whether root pane checking is enabled.
1561:    */
1562:   protected void setRootPaneCheckingEnabled(boolean enabled)
1563:   {
1564:     rootPaneCheckingEnabled = enabled;
1565:   }
1566: 
1567:   /**
1568:    * This method sets whether this JInternalFrame is the selected frame in the
1569:    * JDesktopPane (or other container). When selected, a JInternalFrame will
1570:    * have focus and paint its TitlePane differently (usually a different
1571:    * colour). If this method selects the frame, this JInternalFrame will fire
1572:    * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will
1573:    * fire an INTERNAL_FRAME_DEACTIVATED event.
1574:    *
1575:    * @param selected Whether this JInternalFrame will become selected or
1576:    *        deselected.
1577:    *
1578:    * @throws PropertyVetoException If a VetoableChangeListener vetoes the change.
1579:    */
1580:   public void setSelected(boolean selected) throws PropertyVetoException
1581:   {
1582:     if (selected != isSelected())
1583:       {
1584:     fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected);
1585: 
1586:     if (! selected)
1587:       defaultFocus = getMostRecentFocusOwner();
1588: 
1589:     isSelected = selected;
1590: 
1591:     if (selected)
1592:       restoreSubcomponentFocus();
1593: 
1594:     firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected);
1595: 
1596:     if (isSelected)
1597:       fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
1598:     else
1599:       fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
1600:       }
1601:   }
1602: 
1603:   /**
1604:    * This method sets the title displayed in the TitlePane of this
1605:    * JInternalFrame.
1606:    *
1607:    * @param title The title displayed.
1608:    */
1609:   public void setTitle(String title)
1610:   {
1611:     if (title == null && this.title == null)
1612:       return;
1613:     if (title == null || this.title == null || ! this.title.equals(title))
1614:       {
1615:     String old = title;
1616:     this.title = title;
1617:     firePropertyChange(TITLE_PROPERTY, old, this.title);
1618:       }
1619:   }
1620: 
1621:   /**
1622:    * This method displays the JInternalFrame. If it is not visible, this
1623:    * method will bring this JInternalFrame to the front, make it visible and
1624:    * select it. If this is the first time this JInternalFrame is made
1625:    * visible, an INTERNAL_FRAME_OPENED event will be fired.
1626:    */
1627:   public void show()
1628:   {
1629:     if (! isVisible())
1630:       {
1631:     super.show();
1632: 
1633:     JDesktopPane pane = getDesktopPane();
1634:     if (pane != null)
1635:       pane.setSelectedFrame(this);
1636:     else
1637:       {
1638:         try
1639:           {
1640:         setSelected(true);
1641:           }
1642:         catch (PropertyVetoException e)
1643:           {
1644:         // Do nothing. if they don't want to be selected.
1645:           }
1646:       }
1647:     if (isFirstTimeVisible)
1648:       {
1649:         isFirstTimeVisible = false;
1650:         fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
1651:       }
1652:       }
1653:   }
1654: 
1655:   /**
1656:    * This method is used to set the UI responsible for the JInternalFrame.
1657:    *
1658:    * @param ui The UI responsible for the JInternalFrame.
1659:    */
1660:   public void setUI(InternalFrameUI ui)
1661:   {
1662:     // We must temporarily go into init mode so that the UI can directly
1663:     // manipulate the JInternalFrame.
1664:     boolean old = isRootPaneCheckingEnabled();
1665:     setRootPaneCheckingEnabled(false);
1666:     super.setUI(ui);
1667:     setRootPaneCheckingEnabled(old);
1668:   }
1669: 
1670:   /**
1671:    * This method causes the JInternalFrame to be brough to back in the
1672:    * z-order.
1673:    */
1674:   public void toBack()
1675:   {
1676:     moveToBack();
1677:   }
1678: 
1679:   /**
1680:    * This method causes the JInternalFrame to be brought to front in the
1681:    * z-order.
1682:    */
1683:   public void toFront()
1684:   {
1685:     moveToFront();
1686:   }
1687: 
1688:   /**
1689:    * This method resets the UI to the Look and Feel defaults.
1690:    */
1691:   public void updateUI()
1692:   {
1693:     // We must go into the init stage when updating the UI, so the UI can
1694:     // set layout and components directly on the internal frame, not its
1695:     // content pane.
1696:     boolean old = isRootPaneCheckingEnabled();
1697:     setRootPaneCheckingEnabled(false);
1698:     setUI((InternalFrameUI) UIManager.getUI(this));
1699:     setRootPaneCheckingEnabled(old);
1700:   }
1701: 
1702:   /**
1703:    * This helper method allows JInternalFrames to signal that they were
1704:    * iconned for the first time.
1705:    *
1706:    * @param b Whether the JInternalFrame was iconned.
1707:    * @param ID The identifier of the property change event to fire if the
1708:    *        JInternalFrame is iconned for the first time.
1709:    */
1710:   void setWasIcon(boolean b, String ID)
1711:   {
1712:     if (b && ! wasIcon)
1713:       {
1714:     wasIcon = b;
1715:     firePropertyChange(ID, ! b, b);
1716:       }
1717:   }
1718: 
1719:   /**
1720:    * This helper method returns whether the JInternalFrame has been iconned
1721:    * once already.
1722:    *
1723:    * @return Whether the JInternalFrame has been iconned once already.
1724:    */
1725:   boolean getWasIcon()
1726:   {
1727:     return wasIcon;
1728:   }
1729: 
1730:   /**
1731:    * This method is a convenience method to fire vetoable property changes.
1732:    *
1733:    * @param name The identifier of the property change.
1734:    * @param oldValue The old value.
1735:    * @param newValue The new value.
1736:    *
1737:    * @throws PropertyVetoException Fired if a vetoable change listener vetoes
1738:    *         the change.
1739:    */
1740:   private void fireVetoableChange(String name, boolean oldValue,
1741:                                   boolean newValue)
1742:                            throws PropertyVetoException
1743:   {
1744:     super.fireVetoableChange(name, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
1745:   }
1746: }