| 1 7 package java.awt; 8 9 import java.awt.peer.FramePeer; 10 import java.awt.event.*; 11 import java.util.Vector ; 12 import java.io.Serializable ; 13 import java.io.ObjectOutputStream ; 14 import java.io.ObjectInputStream ; 15 import java.io.IOException ; 16 import sun.awt.AppContext; 17 import sun.awt.SunToolkit; 18 import java.lang.ref.WeakReference ; 19 import javax.accessibility.*; 20 21 114 public class Frame extends Window implements MenuContainer { 115 116 119 120 123 @Deprecated  124 public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; 125 126 127 130 @Deprecated  131 public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR; 132 133 136 @Deprecated  137 public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; 138 139 142 @Deprecated  143 public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR; 144 145 148 @Deprecated  149 public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR; 150 151 154 @Deprecated  155 public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR; 156 157 160 @Deprecated  161 public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR; 162 163 166 @Deprecated  167 public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR; 168 169 172 @Deprecated  173 public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR; 174 175 178 @Deprecated  179 public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR; 180 181 184 @Deprecated  185 public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR; 186 187 190 @Deprecated  191 public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR; 192 193 196 @Deprecated  197 public static final int HAND_CURSOR = Cursor.HAND_CURSOR; 198 199 202 @Deprecated  203 public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR; 204 205 206 212 public static final int NORMAL = 0; 213 214 219 public static final int ICONIFIED = 1; 220 221 228 public static final int MAXIMIZED_HORIZ = 2; 229 230 237 public static final int MAXIMIZED_VERT = 4; 238 239 259 public static final int MAXIMIZED_BOTH = MAXIMIZED_VERT | MAXIMIZED_HORIZ; 260 261 268 Rectangle maximizedBounds; 269 270 271 280 String title = "Untitled"; 281 282 293 transient Image icon; 294 295 303 MenuBar menuBar; 304 305 314 boolean resizable = true; 315 316 328 boolean undecorated = false; 329 330 335 boolean mbManagement = false; 336 337 private int state = NORMAL; 340 341 348 Vector ownedWindows; 349 350 355 transient private WeakReference weakThis; 356 357 private static final String base = "frame"; 358 private static int nameCounter = 0; 359 360 363 private static final long serialVersionUID = 2673458971256075116L; 364 365 static { 366 367 Toolkit.loadLibraries(); 368 if (!GraphicsEnvironment.isHeadless()) { 369 initIDs(); 370 } 371 } 372 373 383 public Frame() throws HeadlessException { 384 this(""); 385 } 386 387 402 public Frame(GraphicsConfiguration gc) { 403 this("", gc); 404 } 405 406 419 public Frame(String title) throws HeadlessException { 420 init(title, null); 421 } 422 423 443 public Frame(String title, GraphicsConfiguration gc) { 444 super(gc); 445 init(title, gc); 446 } 447 448 private void init(String title, GraphicsConfiguration gc) { 449 this.title = title; 450 weakThis = new WeakReference (this); 451 addToFrameList(); 452 SunToolkit.checkAndSetPolicy(this, false); 453 } 454 455 460 protected void finalize() throws Throwable { 461 removeFromFrameList(); 466 super.finalize(); 467 } 468 469 473 String constructComponentName() { 474 synchronized (getClass()) { 475 return base + nameCounter++; 476 } 477 } 478 479 488 public void addNotify() { 489 synchronized (getTreeLock()) { 490 if (peer == null) { 491 peer = getToolkit().createFrame(this); 492 } 493 FramePeer p = (FramePeer)peer; 494 MenuBar menuBar = this.menuBar; 495 if (menuBar != null) { 496 mbManagement = true; 497 menuBar.addNotify(); 498 p.setMenuBar(menuBar); 499 } 500 p.setMaximizedBounds(maximizedBounds); 501 super.addNotify(); 502 } 503 } 504 505 512 public String getTitle() { 513 return title; 514 } 515 516 523 public void setTitle(String title) { 524 String oldTitle = this.title; 525 if (title == null) { 526 title = ""; 527 } 528 529 530 synchronized(this) { 531 this.title = title; 532 FramePeer peer = (FramePeer)this.peer; 533 if (peer != null) { 534 peer.setTitle(title); 535 } 536 } 537 firePropertyChange("title", oldTitle, title); 538 } 539 540 547 public Image getIconImage() { 548 return icon; 549 } 550 551 560 public synchronized void setIconImage(Image image) { 561 this.icon = image; 562 FramePeer peer = (FramePeer)this.peer; 563 if (peer != null) { 564 peer.setIconImage(image); 565 } 566 } 567 568 574 public MenuBar getMenuBar() { 575 return menuBar; 576 } 577 578 585 public void setMenuBar(MenuBar mb) { 586 synchronized (getTreeLock()) { 587 if (menuBar == mb) { 588 return; 589 } 590 if ((mb != null) && (mb.parent != null)) { 591 mb.parent.remove(mb); 592 } 593 if (menuBar != null) { 594 remove(menuBar); 595 } 596 menuBar = mb; 597 if (menuBar != null) { 598 menuBar.parent = this; 599 600 FramePeer peer = (FramePeer)this.peer; 601 if (peer != null) { 602 mbManagement = true; 603 menuBar.addNotify(); 604 if (valid) { 605 invalidate(); 606 } 607 peer.setMenuBar(menuBar); 608 } 609 } 610 } 611 } 612 613 620 public boolean isResizable() { 621 return resizable; 622 } 623 624 630 public void setResizable(boolean resizable) { 631 boolean oldResizable = this.resizable; 632 boolean testvalid = false; 633 634 synchronized (this) { 635 this.resizable = resizable; 636 FramePeer peer = (FramePeer)this.peer; 637 if (peer != null) { 638 peer.setResizable(resizable); 639 testvalid = true; 640 } 641 } 642 643 if (testvalid && valid) { 648 invalidate(); 649 } 650 firePropertyChange("resizable", oldResizable, resizable); 651 } 652 653 654 671 public synchronized void setState(int state) { 672 int current = getExtendedState(); 673 if (state == ICONIFIED && (current & ICONIFIED) == 0) { 674 setExtendedState(current | ICONIFIED); 675 } 676 else if (state == NORMAL && (current & ICONIFIED) != 0) { 677 setExtendedState(current & ~ICONIFIED); 678 } 679 } 680 681 705 public synchronized void setExtendedState(int state) { 706 if ( !isFrameStateSupported( state ) ) { 707 return; 708 } 709 this.state = state; 710 FramePeer peer = (FramePeer)this.peer; 711 if (peer != null) { 712 peer.setState(state); 713 } 714 } 715 private boolean isFrameStateSupported(int state) { 716 if( !getToolkit().isFrameStateSupported( state ) ) { 717 if( ((state & ICONIFIED) != 0) && 722 !getToolkit().isFrameStateSupported( ICONIFIED )) { 723 return false; 724 }else { 725 state &= ~ICONIFIED; 726 } 727 return getToolkit().isFrameStateSupported( state ); 728 } 729 return true; 730 } 731 732 748 public synchronized int getState() { 749 return (getExtendedState() & ICONIFIED) != 0 ? ICONIFIED : NORMAL; 750 } 751 752 753 771 public synchronized int getExtendedState() { 772 FramePeer peer = (FramePeer)this.peer; 773 if (peer != null) { 774 state = peer.getState(); 775 } 776 return state; 777 } 778 779 799 public synchronized void setMaximizedBounds(Rectangle bounds) { 800 this.maximizedBounds = bounds; 801 FramePeer peer = (FramePeer)this.peer; 802 if (peer != null) { 803 peer.setMaximizedBounds(bounds); 804 } 805 } 806 807 816 public Rectangle getMaximizedBounds() { 817 return maximizedBounds; 818 } 819 820 821 834 public void setUndecorated(boolean undecorated) { 835 836 synchronized (getTreeLock()) { 837 if (isDisplayable()) { 838 throw new IllegalComponentStateException ("The frame is displayable."); 839 } 840 this.undecorated = undecorated; 841 } 842 } 843 844 852 public boolean isUndecorated() { 853 return undecorated; 854 } 855 856 862 public void remove(MenuComponent m) { 863 synchronized (getTreeLock()) { 864 if (m == menuBar) { 865 menuBar = null; 866 FramePeer peer = (FramePeer)this.peer; 867 if (peer != null) { 868 mbManagement = true; 869 if (valid) { 870 invalidate(); 871 } 872 peer.setMenuBar(null); 873 m.removeNotify(); 874 } 875 m.parent = null; 876 } else { 877 super.remove(m); 878 } 879 } 880 } 881 882 891 public void removeNotify() { 892 synchronized (getTreeLock()) { 893 FramePeer peer = (FramePeer)this.peer; 894 if (peer != null) { 895 getState(); 897 898 if (menuBar != null) { 899 mbManagement = true; 900 peer.setMenuBar(null); 901 menuBar.removeNotify(); 902 } 903 } 904 super.removeNotify(); 905 } 906 } 907 908 void postProcessKeyEvent(KeyEvent e) { 909 if (menuBar != null && menuBar.handleShortcut(e)) { 910 e.consume(); 911 return; 912 } 913 super.postProcessKeyEvent(e); 914 } 915 916 925 protected String paramString() { 926 String str = super.paramString(); 927 if (title != null) { 928 str += ",title=" + title; 929 } 930 if (resizable) { 931 str += ",resizable"; 932 } 933 getExtendedState(); if (state == NORMAL) { 935 str += ",normal"; 936 } 937 else { 938 if ((state & ICONIFIED) != 0) { 939 str += ",iconified"; 940 } 941 if ((state & MAXIMIZED_BOTH) == MAXIMIZED_BOTH) { 942 str += ",maximized"; 943 } 944 else if ((state & MAXIMIZED_HORIZ) != 0) { 945 str += ",maximized_horiz"; 946 } 947 else if ((state & MAXIMIZED_VERT) != 0) { 948 str += ",maximized_vert"; 949 } 950 } 951 return str; 952 } 953 954 958 @Deprecated  959 public void setCursor(int cursorType) { 960 if (cursorType < DEFAULT_CURSOR || cursorType > MOVE_CURSOR) { 961 throw new IllegalArgumentException ("illegal cursor type"); 962 } 963 setCursor(Cursor.getPredefinedCursor(cursorType)); 964 } 965 966 970 @Deprecated  971 public int getCursorType() { 972 return (getCursor().getType()); 973 } 974 975 981 public static Frame [] getFrames() { 982 synchronized (Frame .class) { 983 Frame realCopy[]; 984 Vector frameList = 985 (Vector )AppContext.getAppContext().get(Frame .class); 986 if (frameList != null) { 987 int fullSize = frameList.size(); 993 int realSize = 0; 994 Frame fullCopy[] = new Frame [fullSize]; 995 996 for (int i = 0; i < fullSize; i++) { 997 fullCopy[realSize] = (Frame ) 998 (((WeakReference ) (frameList.elementAt(i))).get()); 999 1000 if (fullCopy[realSize] != null) { 1001 realSize++; 1002 } 1003 } 1004 |