1 7 package java.awt; 8 9 import java.awt.peer.MenuComponentPeer; 10 import java.awt.event.ActionEvent ; 11 import java.io.IOException ; 12 import java.io.ObjectInputStream ; 13 import sun.awt.AppContext; 14 import sun.awt.SunToolkit; 15 import javax.accessibility.*; 16 17 30 public abstract class MenuComponent implements java.io.Serializable { 31 32 static { 33 34 Toolkit.loadLibraries(); 35 if (!GraphicsEnvironment.isHeadless()) { 36 initIDs(); 37 } 38 } 39 40 transient MenuComponentPeer peer; 41 transient MenuContainer parent; 42 43 47 transient AppContext appContext; 48 49 58 Font font; 59 60 66 private String name; 67 68 75 private boolean nameExplicitlySet = false; 76 77 82 boolean newEventsOnly = false; 83 84 87 final static String actionListenerK = Component.actionListenerK; 88 final static String itemListenerK = Component.itemListenerK; 89 90 93 private static final long serialVersionUID = -4536902356223894379L; 94 95 98 transient private Object privateKey = new Object (); 99 100 107 public MenuComponent() throws HeadlessException { 108 GraphicsEnvironment.checkHeadless(); 109 appContext = AppContext.getAppContext(); 110 } 111 112 117 String constructComponentName() { 118 return null; } 122 123 129 public String getName() { 130 if (name == null && !nameExplicitlySet) { 131 synchronized(this) { 132 if (name == null && !nameExplicitlySet) 133 name = constructComponentName(); 134 } 135 } 136 return name; 137 } 138 139 145 public void setName(String name) { 146 synchronized(this) { 147 this.name = name; 148 nameExplicitlySet = true; 149 } 150 } 151 152 158 public MenuContainer getParent() { 159 return getParent_NoClientCode(); 160 } 161 final MenuContainer getParent_NoClientCode() { 166 return parent; 167 } 168 169 173 @Deprecated 174 public MenuComponentPeer getPeer() { 175 return peer; 176 } 177 178 184 public Font getFont() { 185 Font font = this.font; 186 if (font != null) { 187 return font; 188 } 189 MenuContainer parent = this.parent; 190 if (parent != null) { 191 return parent.getFont(); 192 } 193 return null; 194 } 195 196 final Font getFont_NoClientCode() { 201 Font font = this.font; 202 if (font != null) { 203 return font; 204 } 205 206 Object parent = this.parent; 211 if (parent != null) { 212 if (parent instanceof Component ) { 213 font = ((Component )parent).getFont_NoClientCode(); 214 } else if (parent instanceof MenuComponent ) { 215 font = ((MenuComponent )parent).getFont_NoClientCode(); 216 } 217 } 218 return font; 219 } 221 222 239 public void setFont(Font f) { 240 font = f; 241 if (peer != null) { 242 peer.setFont(f); 243 } 244 } 245 246 251 public void removeNotify() { 252 synchronized (getTreeLock()) { 253 MenuComponentPeer p = (MenuComponentPeer)this.peer; 254 if (p != null) { 255 Toolkit.getEventQueue().removeSourceEvents(this, true); 256 this.peer = null; 257 p.dispose(); 258 } 259 } 260 } 261 262 272 @Deprecated 273 public boolean postEvent(Event evt) { 274 MenuContainer parent = this.parent; 275 if (parent != null) { 276 parent.postEvent(evt); 277 } 278 return false; 279 } 280 281 285 public final void dispatchEvent(AWTEvent e) { 286 dispatchEventImpl(e); 287 } 288 289 void dispatchEventImpl(AWTEvent e) { 290 EventQueue.setCurrentEventAndMostRecentTime(e); 291 292 Toolkit.getDefaultToolkit().notifyAWTEventListeners(e); 293 294 if (newEventsOnly || 295 (parent != null && parent instanceof MenuComponent && 296 ((MenuComponent )parent).newEventsOnly)) { 297 if (eventEnabled(e)) { 298 processEvent(e); 299 } else if (e instanceof ActionEvent && parent != null) { 300 e.setSource(parent); 301 ((MenuComponent )parent).dispatchEvent(e); 302 } 303 304 } else { Event olde = e.convertToOld(); 306 if (olde != null) { 307 postEvent(olde); 308 } 309 } 310 } 311 312 boolean eventEnabled(AWTEvent e) { 314 return false; 315 } 316 325 protected void processEvent(AWTEvent e) { 326 } 327 328 337 protected String paramString() { 338 String thisName = getName(); 339 return (thisName != null? thisName : ""); 340 } 341 342 346 public String toString() { 347 return getClass().getName() + "[" + paramString() + "]"; 348 } 349 350 356 protected final Object getTreeLock() { 357 return Component.LOCK; 358 } 359 360 370 private void readObject(ObjectInputStream s) 371 throws ClassNotFoundException , IOException , HeadlessException 372 { 373 GraphicsEnvironment.checkHeadless(); 374 s.defaultReadObject(); 375 376 privateKey = new Object (); 377 appContext = AppContext.getAppContext(); 378 } 379 380 383 private static native void initIDs(); 384 385 386 393 394 AccessibleContext accessibleContext = null; 395 396 408 public AccessibleContext getAccessibleContext() { 409 return accessibleContext; 410 } 411 412 420 protected abstract class AccessibleAWTMenuComponent 421 extends AccessibleContext 422 implements java.io.Serializable , AccessibleComponent, 423 AccessibleSelection 424 { 425 428 private static final long serialVersionUID = -4269533416223798698L; 429 430 434 protected AccessibleAWTMenuComponent() { 435 } 436 437 440 448 public AccessibleSelection getAccessibleSelection() { 449 return this; 450 } 451 452 465 public String getAccessibleName() { 466 return accessibleName; 467 } 468 469 484 public String getAccessibleDescription() { 485 return accessibleDescription; 486 } 487 488 495 public AccessibleRole getAccessibleRole() { 496 return AccessibleRole.AWT_COMPONENT; } 498 499 506 public AccessibleStateSet getAccessibleStateSet() { 507 return MenuComponent.this.getAccessibleStateSet(); 508 } 509 510 519 public Accessible getAccessibleParent() { 520 if (accessibleParent != null) { 521 return accessibleParent; 522 } else { 523 MenuContainer parent = MenuComponent.this.getParent(); 524 if (parent instanceof Accessible) { 525 return (Accessible) parent; 526 } 527 } 528 return null; 529 } 530 531 538 public int getAccessibleIndexInParent() { 539 return MenuComponent.this.getAccessibleIndexInParent(); 540 } 541 542 549 public int getAccessibleChildrenCount() { 550 return 0; } 552 553 559 public Accessible getAccessibleChild(int i) { 560 return null; } 562 563 568 public java.util.Locale getLocale() { 569 MenuContainer parent = MenuComponent.this.getParent(); 570 if (parent instanceof Component ) 571 return ((Component )parent).getLocale(); 572 else 573 return java.util.Locale.getDefault(); 574 } 575 576 582 public AccessibleComponent getAccessibleComponent() { 583 return this; 584 } 585 586 587 595 public Color getBackground() { 596 return null; } 598 599 606 public void setBackground(Color c) { 607 } 609 610 616 public Color getForeground() { 617 return null; } 619 620 625 public void setForeground(Color c) { 626 } 628 629 635 public Cursor getCursor() { 636 return null; } 638 639 644 public void setCursor(Cursor cursor) { 645 } 647 648 654 public Font getFont() { 655 return MenuComponent.this.getFont(); 656 } 657 658 663 public void setFont(Font f) { 664 MenuComponent.this.setFont(f); 665 } 666 667 675 public FontMetrics getFontMetrics(Font f) { 676 return null; } 678 679 684 public boolean isEnabled() { 685 return true; } 687 688 693 public void setEnabled(boolean b) { 694 } 696 697 706 public boolean isVisible() { 707 return true; } 709 710 715 public void setVisible(boolean b) { 716 } 718 719 728 public boolean isShowing() { 729 return true; } 731 732 741 public boolean contains(Point p) { 742 return false; } 744 745 751 public Point getLocationOnScreen() { 752 return null; } 754 755 765 public Point getLocation() { 766 return null; } 768 769 772 public void setLocation(Point p) { 773 } 775 776 785 public Rectangle getBounds() { 786 return null; } 788 789 797 public void setBounds(Rectangle r) { 798 } 800 801 812 public Dimension getSize() { 813 return null; } 815 816 822 public void setSize(Dimension d) { 823 } 825 826 838 public Accessible getAccessibleAt(Point p) { 839 return null; } 841 842 847 public boolean isFocusTraversable() { 848 return true; } 850 851 854 public void requestFocus() { 855 } 857 858 864 public void addFocusListener(java.awt.event.FocusListener l) { 865 } 867 868 874 public void removeFocusListener(java.awt.event.FocusListener l) { 875 } 877 878 881 887 public int getAccessibleSelectionCount() { 888 return 0; } 890 891 903 public Accessible getAccessibleSelection(int i) { 904 return null; } 906 907 916 public boolean isAccessibleChildSelected(int i) { 917 return false; } 919 920 930 public void addAccessibleSelection(int i) { 931 } 933 934 942 public void removeAccessibleSelection(int i) { 943 } 945 946 950 public void clearAccessibleSelection() { 951 } 953 954 958 public void selectAllAccessibleSelection() { 959 } 961 962 } 964 970 int getAccessibleIndexInParent() { 971 MenuContainer localParent = parent; 972 if (!(localParent instanceof MenuComponent )) { 973 return -1; 975 } 976 MenuComponent localParentMenu = (MenuComponent )localParent; 977 return localParentMenu.getAccessibleChildIndex(this); 978 } 979 980 987 int getAccessibleChildIndex(MenuComponent child) { 988 return -1; } 990 991 998 AccessibleStateSet getAccessibleStateSet() { 999 AccessibleStateSet states = new AccessibleStateSet(); 1000 return states; 1001 } 1002 1003} 1004 | Popular Tags |