| 1 7 8 package javax.swing; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 13 import java.beans.PropertyVetoException ; 14 import java.beans.PropertyChangeEvent ; 15 import java.util.EventListener ; 16 17 import javax.swing.border.Border ; 18 import javax.swing.event.InternalFrameEvent ; 19 import javax.swing.event.InternalFrameListener ; 20 import javax.swing.plaf.*; 21 22 import javax.accessibility.*; 23 24 import java.io.ObjectOutputStream ; 25 import java.io.ObjectInputStream ; 26 import java.io.IOException ; 27 28 29 90 public class JInternalFrame extends JComponent implements 91 Accessible, WindowConstants , 92 RootPaneContainer  93 { 94 98 private static final String uiClassID = "InternalFrameUI"; 99 100 109 protected JRootPane rootPane; 110 111 121 protected boolean rootPaneCheckingEnabled = false; 122 123 124 protected boolean closable; 125 126 protected boolean isClosed; 127 128 protected boolean maximizable; 129 133 protected boolean isMaximum; 134 140 protected boolean iconable; 141 145 protected boolean isIcon; 146 147 protected boolean resizable; 148 149 protected boolean isSelected; 150 151 protected Icon frameIcon; 152 153 protected String title; 154 158 protected JDesktopIcon desktopIcon; 159 160 private boolean opened; 161 162 private Rectangle normalBounds = null; 163 164 private int defaultCloseOperation = DISPOSE_ON_CLOSE; 165 166 172 private Component lastFocusOwner; 173 174 175 public final static String CONTENT_PANE_PROPERTY = "contentPane"; 176 177 public final static String MENU_BAR_PROPERTY = "JMenuBar"; 178 179 public final static String TITLE_PROPERTY = "title"; 180 181 public final static String LAYERED_PANE_PROPERTY = "layeredPane"; 182 183 public final static String ROOT_PANE_PROPERTY = "rootPane"; 184 185 public final static String GLASS_PANE_PROPERTY = "glassPane"; 186 187 public final static String FRAME_ICON_PROPERTY = "frameIcon"; 188 189 193 public final static String IS_SELECTED_PROPERTY = "selected"; 194 195 public final static String IS_CLOSED_PROPERTY = "closed"; 196 197 public final static String IS_MAXIMUM_PROPERTY = "maximum"; 198 199 public final static String IS_ICON_PROPERTY = "icon"; 200 201 202 206 public JInternalFrame() { 207 this("", false, false, false, false); 208 } 209 210 219 public JInternalFrame(String title) { 220 this(title, false, false, false, false); 221 } 222 223 231 public JInternalFrame(String title, boolean resizable) { 232 this(title, resizable, false, false, false); 233 } 234 235 244 public JInternalFrame(String title, boolean resizable, boolean closable) { 245 this(title, resizable, closable, false, false); 246 } 247 248 258 public JInternalFrame(String title, boolean resizable, boolean closable, 259 boolean maximizable) { 260 this(title, resizable, closable, maximizable, false); 261 } 262 263 274 public JInternalFrame(String title, boolean resizable, boolean closable, 275 boolean maximizable, boolean iconifiable) { 276 277 setRootPane(createRootPane()); 278 getGlassPane().setVisible(true); 279 setLayout(new BorderLayout()); 280 this.title = title; 281 this.resizable = resizable; 282 this.closable = closable; 283 this.maximizable = maximizable; 284 isMaximum = false; 285 this.iconable = iconifiable; 286 isIcon = false; 287 setVisible(false); 288 setRootPaneCheckingEnabled(true); 289 desktopIcon = new JDesktopIcon(this); 290 updateUI(); 291 sun.awt.SunToolkit.checkAndSetPolicy(this, true); 292 } 293 294 299 protected JRootPane createRootPane() { 300 return new JRootPane (); 301 } 302 303 309 public InternalFrameUI getUI() { 310 return (InternalFrameUI)ui; 311 } 312 313 322 public void setUI(InternalFrameUI ui) { 323 boolean checkingEnabled = isRootPaneCheckingEnabled(); 324 try { 325 setRootPaneCheckingEnabled(false); 326 super.setUI(ui); 327 } 328 finally { 329 setRootPaneCheckingEnabled(checkingEnabled); 330 } 331 } 332 333 341 public void updateUI() { 342 setUI((InternalFrameUI)UIManager.getUI(this)); 343 invalidate(); 344 if (desktopIcon != null) { 345 desktopIcon.updateUIWhenHidden(); 346 } 347 } 348 349 353 void updateUIWhenHidden() { 354 setUI((InternalFrameUI)UIManager.getUI(this)); 355 invalidate(); 356 Component[] children = getComponents(); 357 if (children != null) { 358 for(int i = 0; i < children.length; i++) { 359 SwingUtilities.updateComponentTreeUI(children[i]); 360 } 361 } 362 } 363 364 365 377 public String getUIClassID() { 378 return uiClassID; 379 } 380 381 393 protected boolean isRootPaneCheckingEnabled() { 394 return rootPaneCheckingEnabled; 395 } 396 397 413 protected void setRootPaneCheckingEnabled(boolean enabled) { 414 rootPaneCheckingEnabled = enabled; 415 } 416 417 436 protected void addImpl(Component comp, Object constraints, int index) { 437 if(isRootPaneCheckingEnabled()) { 438 getContentPane().add(comp, constraints, index); 439 } 440 else { 441 super.addImpl(comp, constraints, index); 442 } 443 } 444 445 455 public void remove(Component comp) { 456 int oldCount = getComponentCount(); 457 super.remove(comp); 458 if (oldCount == getComponentCount()) { 459 getContentPane().remove(comp); 460 } 461 } 462 463 464 474 public void setLayout(LayoutManager manager) { 475 if(isRootPaneCheckingEnabled()) { 476 getContentPane().setLayout(manager); 477 } 478 else { 479 super.setLayout(manager); 480 } 481 } 482 483 484 488 497 @Deprecated  498 public JMenuBar getMenuBar() { 499 return getRootPane().getMenuBar(); 500 } 501 502 510 public JMenuBar getJMenuBar() { 511 return getRootPane().getJMenuBar(); 512 } 513 514 522 @Deprecated  523 public void setMenuBar(JMenuBar m) { 524 JMenuBar oldValue = getMenuBar(); 525 getRootPane().setJMenuBar(m); 526 firePropertyChange(MENU_BAR_PROPERTY, oldValue, m); 527 } 528 529 540 public void setJMenuBar(JMenuBar m){ 541 JMenuBar oldValue = getMenuBar(); 542 getRootPane().setJMenuBar(m); 543 firePropertyChange(MENU_BAR_PROPERTY, oldValue, m); 544 } 545 546 551 public Container getContentPane() { 552 return getRootPane().getContentPane(); 553 } 554 555 556 571 public void setContentPane(Container c) { 572 Container oldValue = getContentPane(); 573 getRootPane().setContentPane(c); 574 firePropertyChange(CONTENT_PANE_PROPERTY, oldValue, c); 575 } 576 577 584 public JLayeredPane getLayeredPane() { 585 return getRootPane().getLayeredPane(); 586 } 587 588 602 public void setLayeredPane(JLayeredPane layered) { 603 JLayeredPane oldValue = getLayeredPane(); 604 getRootPane().setLayeredPane(layered); 605 firePropertyChange(LAYERED_PANE_PROPERTY, oldValue, layered); 606 } 607 608 614 public Component getGlassPane() { 615 return getRootPane().getGlassPane(); 616 } 617 618 629 public void setGlassPane(Component glass) { 630 Component oldValue = getGlassPane(); 631 getRootPane().setGlassPane(glass); 632 firePropertyChange(GLASS_PANE_PROPERTY, oldValue, glass); 633 } 634 635 641 public JRootPane getRootPane() { 642 return rootPane; 643 } 644 645 646 657 protected void setRootPane(JRootPane root) { 658 if(rootPane != null) { 659 remove(rootPane); 660 } 661 JRootPane oldValue = getRootPane(); 662 rootPane = root; 663 if(rootPane != null) { 664 boolean checkingEnabled = isRootPaneCheckingEnabled(); 665 try { 666 setRootPaneCheckingEnabled(false); 667 add(rootPane, BorderLayout.CENTER); 668 } 669 finally { 670 setRootPaneCheckingEnabled(checkingEnabled); 671 } 672 } 673 firePropertyChange(ROOT_PANE_PROPERTY, oldValue, root); 674 } 675 676 685 public void setClosable(boolean b) { 686 Boolean oldValue = closable ? Boolean.TRUE : Boolean.FALSE; 687 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 688 closable = b; 689 firePropertyChange("closable", oldValue, newValue); 690 } 691 692 697 public boolean isClosable() { 698 return closable; 699 } 700 701 705 public boolean isClosed() { 706 return isClosed; 707 } 708 709 752 public void setClosed(boolean b) throws PropertyVetoException { 753 if (isClosed == b) { 754 return; 755 } 756 757 Boolean oldValue = isClosed ? Boolean.TRUE : Boolean.FALSE; 758 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 759 if (b) { 760 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); 761 } 762 fireVetoableChange(IS_CLOSED_PROPERTY, oldValue, newValue); 763 isClosed = b; 764 firePropertyChange(IS_CLOSED_PROPERTY, oldValue, newValue); 765 if (isClosed) { 766 dispose(); 767 } else if (!opened) { 768 770 } 773 } 774 775 786 public void setResizable(boolean b) { 787 Boolean oldValue = resizable ? Boolean.TRUE : Boolean.FALSE; 788 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 789 resizable = b; 790 firePropertyChange("resizable", oldValue, newValue); 791 } 792 793 799 public boolean isResizable() { 800 return isMaximum ? false : resizable; 802 } 803 804 818 public void setIconifiable(boolean b) { 819 Boolean oldValue = iconable ? Boolean.TRUE : Boolean.FALSE; 820 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 821 iconable = b; 822 firePropertyChange("iconable", oldValue, newValue); 823 } 824 825 833 public boolean isIconifiable() { 834 return iconable; 835 } 836 837 842 public boolean isIcon() { 843 return isIcon; 844 } 845 846 867 public void setIcon(boolean b) throws PropertyVetoException { 868 if (isIcon == b) { 869 return; 870 } 871 872 878 firePropertyChange("ancestor", null, getParent()); 879 880 Boolean oldValue = isIcon ? Boolean.TRUE : Boolean.FALSE; 881 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 882 fireVetoableChange(IS_ICON_PROPERTY, oldValue, newValue); 883 isIcon = b; 884 firePropertyChange(IS_ICON_PROPERTY, oldValue, newValue); 885 if (b) 886 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED); 887 else 888 fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED); 889 } 890 891 905 public void setMaximizable(boolean b) { 906 Boolean oldValue = maximizable ? Boolean.TRUE : Boolean.FALSE; 907 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 908 maximizable = b; 909 firePropertyChange("maximizable", oldValue, newValue); 910 } 911 912 918 public boolean isMaximizable() { 919 return maximizable; 920 } 921 922 927 public boolean isMaximum() { 928 return isMaximum; 929 } 930 931 947 public void setMaximum(boolean b) throws PropertyVetoException { 948 if (isMaximum == b) { 949 return; 950 } 951 952 Boolean oldValue = isMaximum ? Boolean.TRUE : Boolean.FALSE; 953 Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; 954 fireVetoableChange(IS_MAXIMUM_PROPERTY, oldValue, newValue); 955 958 isMaximum = b; 959 firePropertyChange(IS_MAXIMUM_PROPERTY, oldValue, newValue); 960 } 961 962 968 public String getTitle() { 969 return title; 970 } 971 972 983 public void setTitle(String title) { 984 String oldValue = this.title; 985 this.title = title; 986 firePropertyChange(TITLE_PROPERTY, oldValue, title); 987 } 988 989 |