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