1 7 package java.awt; 8 9 import java.io.PrintStream ; 10 import java.io.PrintWriter ; 11 import java.util.Vector ; 12 import java.util.Locale ; 13 import java.util.EventListener ; 14 import java.util.Iterator ; 15 import java.util.HashSet ; 16 import java.util.Set ; 17 import java.util.Collections ; 18 import java.awt.peer.ComponentPeer; 19 import java.awt.peer.ContainerPeer; 20 import java.awt.peer.LightweightPeer; 21 import java.awt.image.BufferStrategy ; 22 import java.awt.image.ImageObserver ; 23 import java.awt.image.ImageProducer ; 24 import java.awt.image.ColorModel ; 25 import java.awt.image.VolatileImage ; 26 import java.awt.event.*; 27 import java.awt.datatransfer.Transferable ; 28 import java.awt.dnd.DnDConstants ; 29 import java.awt.dnd.DragSource ; 30 import java.awt.dnd.DragSourceContext ; 31 import java.awt.dnd.DragSourceListener ; 32 import java.awt.dnd.InvalidDnDOperationException ; 33 import java.io.Serializable ; 34 import java.io.ObjectOutputStream ; 35 import java.io.ObjectInputStream ; 36 import java.io.IOException ; 37 import java.beans.PropertyChangeListener ; 38 import java.beans.PropertyChangeSupport ; 39 import java.awt.event.InputMethodListener ; 40 import java.awt.event.InputMethodEvent ; 41 import java.awt.im.InputContext ; 42 import java.awt.im.InputMethodRequests ; 43 import java.awt.dnd.DropTarget ; 44 import java.lang.reflect.InvocationTargetException ; 45 import java.lang.reflect.Method ; 46 import javax.accessibility.*; 47 import java.awt.GraphicsConfiguration ; 48 import java.security.AccessController ; 49 import java.security.PrivilegedAction ; 50 import javax.accessibility.*; 51 52 import java.util.logging.*; 53 54 import sun.security.action.GetPropertyAction; 55 import sun.awt.AppContext; 56 import sun.awt.SunToolkit; 57 import sun.awt.ConstrainableGraphics; 58 import sun.awt.DebugHelper; 59 import sun.awt.WindowClosingListener; 60 import sun.awt.WindowClosingSupport; 61 import sun.awt.GlobalCursorManager; 62 import sun.awt.dnd.SunDropTargetEvent; 63 import sun.awt.im.CompositionArea; 64 65 import sun.font.FontManager; 66 67 157 public abstract class Component implements ImageObserver , MenuContainer , 158 Serializable 159 { 160 161 private static final Logger focusLog = Logger.getLogger("java.awt.focus.Component"); 162 private static final Logger log = Logger.getLogger("java.awt.Component"); 163 170 transient ComponentPeer peer; 171 172 177 transient Container parent; 178 179 183 transient AppContext appContext; 184 185 191 int x; 192 193 199 int y; 200 201 207 int width; 208 209 215 int height; 216 217 225 Color foreground; 226 227 235 Color background; 236 237 245 Font font; 246 247 251 Font peerFont; 252 253 261 Cursor cursor; 262 263 270 Locale locale; 271 272 283 transient GraphicsConfiguration graphicsConfig = null; 284 285 293 transient BufferStrategy bufferStrategy = null; 294 295 303 boolean ignoreRepaint = false; 304 305 313 boolean visible = true; 314 315 323 boolean enabled = true; 324 325 335 boolean valid = false; 336 337 345 DropTarget dropTarget; 346 347 351 Vector popups; 352 353 361 private String name; 362 363 373 private boolean nameExplicitlySet = false; 374 375 383 private boolean focusable = true; 384 385 private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0; 386 private static final int FOCUS_TRAVERSABLE_DEFAULT = 1; 387 private static final int FOCUS_TRAVERSABLE_SET = 2; 388 389 395 private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN; 396 397 410 Set [] focusTraversalKeys; 411 412 private static final String [] focusTraversalKeyPropertyNames = { 413 "forwardFocusTraversalKeys", 414 "backwardFocusTraversalKeys", 415 "upCycleFocusTraversalKeys", 416 "downCycleFocusTraversalKeys" 417 }; 418 419 431 private boolean focusTraversalKeysEnabled = true; 432 433 438 static final Object LOCK = new AWTTreeLock(); 439 static class AWTTreeLock {} 440 441 447 Dimension minSize; 448 449 452 boolean minSizeSet; 453 454 460 Dimension prefSize; 461 462 465 boolean prefSizeSet; 466 467 472 Dimension maxSize; 473 474 477 boolean maxSizeSet; 478 479 484 transient ComponentOrientation componentOrientation 485 = ComponentOrientation.UNKNOWN; 486 487 498 boolean newEventsOnly = false; 499 transient ComponentListener componentListener; 500 transient FocusListener focusListener; 501 transient HierarchyListener hierarchyListener; 502 transient HierarchyBoundsListener hierarchyBoundsListener; 503 transient KeyListener keyListener; 504 transient MouseListener mouseListener; 505 transient MouseMotionListener mouseMotionListener; 506 transient MouseWheelListener mouseWheelListener; 507 transient InputMethodListener inputMethodListener; 508 509 transient RuntimeException windowClosingException = null; 510 511 512 final static String actionListenerK = "actionL"; 513 final static String adjustmentListenerK = "adjustmentL"; 514 final static String componentListenerK = "componentL"; 515 final static String containerListenerK = "containerL"; 516 final static String focusListenerK = "focusL"; 517 final static String itemListenerK = "itemL"; 518 final static String keyListenerK = "keyL"; 519 final static String mouseListenerK = "mouseL"; 520 final static String mouseMotionListenerK = "mouseMotionL"; 521 final static String mouseWheelListenerK = "mouseWheelL"; 522 final static String textListenerK = "textL"; 523 final static String ownedWindowK = "ownedL"; 524 final static String windowListenerK = "windowL"; 525 final static String inputMethodListenerK = "inputMethodL"; 526 final static String hierarchyListenerK = "hierarchyL"; 527 final static String hierarchyBoundsListenerK = "hierarchyBoundsL"; 528 final static String windowStateListenerK = "windowStateL"; 529 final static String windowFocusListenerK = "windowFocusL"; 530 531 545 long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK; 546 547 private static final DebugHelper dbg = DebugHelper.create(Component .class); 548 549 553 static boolean isInc; 554 static int incRate; 555 static { 556 557 Toolkit.loadLibraries(); 558 559 if (!GraphicsEnvironment.isHeadless()) { 560 initIDs(); 561 } 562 563 String s = (String ) java.security.AccessController.doPrivileged( 564 new GetPropertyAction("awt.image.incrementaldraw")); 565 isInc = (s == null || s.equals("true")); 566 567 s = (String ) java.security.AccessController.doPrivileged( 568 new GetPropertyAction("awt.image.redrawrate")); 569 incRate = (s != null) ? Integer.parseInt(s) : 100; 570 } 571 572 577 public static final float TOP_ALIGNMENT = 0.0f; 578 579 586 public static final float CENTER_ALIGNMENT = 0.5f; 587 588 593 public static final float BOTTOM_ALIGNMENT = 1.0f; 594 595 600 public static final float LEFT_ALIGNMENT = 0.0f; 601 602 607 public static final float RIGHT_ALIGNMENT = 1.0f; 608 609 612 private static final long serialVersionUID = -7644114512714619750L; 613 614 624 private PropertyChangeSupport changeSupport; 625 626 boolean isPacked = false; 627 628 631 transient private Object privateKey = new Object (); 632 633 639 private int boundsOp = ComponentPeer.DEFAULT_OPERATION; 640 641 645 int getBoundsOp() { 646 assert Thread.holdsLock(getTreeLock()); 647 return boundsOp; 648 } 649 650 void setBoundsOp(int op) { 651 assert Thread.holdsLock(getTreeLock()); 652 if (op == ComponentPeer.RESET_OPERATION) { 653 boundsOp = ComponentPeer.DEFAULT_OPERATION; 654 } else 655 if (boundsOp == ComponentPeer.DEFAULT_OPERATION) { 656 boundsOp = op; 657 } 658 } 659 660 667 protected Component() { 668 appContext = AppContext.getAppContext(); 669 } 670 671 void initializeFocusTraversalKeys() { 672 focusTraversalKeys = new Set [3]; 673 } 674 675 679 String constructComponentName() { 680 return null; } 684 685 691 public String getName() { 692 if (name == null && !nameExplicitlySet) { 693 synchronized(this) { 694 if (name == null && !nameExplicitlySet) 695 name = constructComponentName(); 696 } 697 } 698 return name; 699 } 700 701 708 public void setName(String name) { 709 String oldName; 710 synchronized(this) { 711 oldName = this.name; 712 this.name = name; 713 nameExplicitlySet = true; 714 } 715 firePropertyChange("name", oldName, name); 716 } 717 718 723 public Container getParent() { 724 return getParent_NoClientCode(); 725 } 726 727 final Container getParent_NoClientCode() { 732 return parent; 733 } 734 735 740 @Deprecated 741 public ComponentPeer getPeer() { 742 return peer; 743 } 744 745 753 754 public synchronized void setDropTarget(DropTarget dt) { 755 if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt))) 756 return; 757 758 DropTarget old; 759 760 if ((old = dropTarget) != null) { 761 if (peer != null) dropTarget.removeNotify(peer); 762 763 DropTarget t = dropTarget; 764 765 dropTarget = null; 766 767 try { 768 t.setComponent(null); 769 } catch (IllegalArgumentException iae) { 770 } 772 } 773 774 776 if ((dropTarget = dt) != null) { 777 try { 778 dropTarget.setComponent(this); 779 if (peer != null) dropTarget.addNotify(peer); 780 } catch (IllegalArgumentException iae) { 781 if (old != null) { 782 try { 783 old.setComponent(this); 784 if (peer != null) dropTarget.addNotify(peer); 785 } catch (IllegalArgumentException iae1) { 786 } 788 } 789 } 790 } 791 } 792 793 797 798 public synchronized DropTarget getDropTarget() { return dropTarget; } 799 800 815 public GraphicsConfiguration getGraphicsConfiguration() { 816 synchronized(getTreeLock()) { 817 if (graphicsConfig != null) { 818 return graphicsConfig; 819 } else if (getParent() != null) { 820 return getParent().getGraphicsConfiguration(); 821 } else { 822 return null; 823 } 824 } 825 } 826 827 833 void resetGC() { 834 synchronized(getTreeLock()) { 835 graphicsConfig = null; 836 } 837 } 838 839 842 void setGCFromPeer() { 843 synchronized(getTreeLock()) { 844 if (peer != null) { graphicsConfig = peer.getGraphicsConfiguration(); 847 } else { 848 graphicsConfig = null; 849 } 850 } 851 } 852 853 857 void checkGD(String stringID) { 858 if (graphicsConfig != null) { 859 if (!graphicsConfig.getDevice().getIDstring().equals(stringID)) { 860 throw new IllegalArgumentException ( 861 "adding a container to a container on a different GraphicsDevice"); 862 } 863 } 864 } 865 866 872 public final Object getTreeLock() { 873 return LOCK; 874 } 875 876 884 public Toolkit getToolkit() { 885 return getToolkitImpl(); 886 } 887 888 892 final Toolkit getToolkitImpl() { 893 ComponentPeer peer = this.peer; 894 if ((peer != null) && ! (peer instanceof LightweightPeer)){ 895 return peer.getToolkit(); 896 } 897 Container parent = this.parent; 898 if (parent != null) { 899 return parent.getToolkitImpl(); 900 } 901 return Toolkit.getDefaultToolkit(); 902 } 903 904 917 public boolean isValid() { 918 return (peer != null) && valid; 919 } 920 921 945 public boolean isDisplayable() { 946 return getPeer() != null; 947 } 948 949 959 public boolean isVisible() { 960 return visible; 961 } 962 963 969 boolean isRecursivelyVisible() { 970 return visible && (parent == null || parent.isRecursivelyVisible()); 971 } 972 973 977 Point pointRelativeToComponent(Point absolute) { 978 Point compCoords = getLocationOnScreen(); 979 return new Point (absolute.x - compCoords.x, 980 absolute.y - compCoords.y); 981 } 982 983 992 Component findUnderMouseInWindow(PointerInfo pi) { 993 if (!isShowing()) { 994 return null; 995 } 996 Window win = getContainingWindow(); 997 if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) { 998 return null; 999 } 1000 final boolean INCLUDE_DISABLED = true; 1001 Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation()); 1002 Component inTheSameWindow = win.findComponentAt(relativeToWindow.x, 1003 relativeToWindow.y, 1004 INCLUDE_DISABLED); 1005 return inTheSameWindow; 1006 } 1007 1008 1035 public Point getMousePosition() throws HeadlessException { 1036 if (GraphicsEnvironment.isHeadless()) { 1037 throw new HeadlessException (); 1038 } 1039 1040 PointerInfo pi = (PointerInfo )java.security.AccessController.doPrivileged( 1041 new java.security.PrivilegedAction () { 1042 public Object run() { 1043 return MouseInfo.getPointerInfo(); 1044 } 1045 } 1046 ); 1047 1048 synchronized (getTreeLock()) { 1049 Component inTheSameWindow = findUnderMouseInWindow(pi); 1050 if (!isSameOrAncestorOf(inTheSameWindow, true)) { 1051 return null; 1052 } 1053 return pointRelativeToComponent(pi.getLocation()); 1054 } 1055 } 1056 1057 1060 boolean isSameOrAncestorOf(Component comp, boolean allowChildren) { 1061 return comp == this; 1062 } 1063 1064 1073 public boolean isShowing() { 1074 if (visible && (peer != null)) { 1075 Container parent = this.parent; 1076 return (parent == null) || parent.isShowing(); 1077 } 1078 return false; 1079 } 1080 1081 1091 public boolean isEnabled() { 1092 return isEnabledImpl(); 1093 } 1094 1095 1099 final boolean isEnabledImpl() { 1100 return enabled; 1101 } 1102 1103 1117 public void setEnabled(boolean b) { 1118 enable(b); 1119 } 1120 1121 1125 @Deprecated 1126 public void enable() { 1127 if (!enabled) { 1128 synchronized (getTreeLock()) { 1129 enabled = true; 1130 ComponentPeer peer = this.peer; 1131 if (peer != null) { 1132 peer.enable(); 1133 if (visible) { 1134 updateCursorImmediately(); 1135 } 1136 } 1137 } 1138 if (accessibleContext != null) { 1139 accessibleContext.firePropertyChange( 1140 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 1141 null, AccessibleState.ENABLED); 1142 } 1143 } 1144 } 1145 1146 1150 @Deprecated 1151 public void enable(boolean b) { 1152 if (b) { 1153 enable(); 1154 } else { 1155 disable(); 1156 } 1157 } 1158 1159 1163 @Deprecated 1164 public void disable() { 1165 if (enabled) { 1166 KeyboardFocusManager.clearMostRecentFocusOwner(this); 1167 synchronized (getTreeLock()) { 1168 enabled = false; 1169 if (isFocusOwner()) { 1170 autoTransferFocus(false); 1175 } 1176 ComponentPeer peer = this.peer; 1177 if (peer != null) { 1178 peer.disable(); 1179 if (visible) { 1180 updateCursorImmediately(); 1181 } 1182 } 1183 } 1184 if (accessibleContext != null) { 1185 accessibleContext.firePropertyChange( 1186 AccessibleContext.ACCESSIBLE_STATE_PROPERTY, 1187 null, AccessibleState.ENABLED); 1188 } 1189 } 1190 } 1191 1192 1200 public boolean isDoubleBuffered() { 1201 return false; 1202 } 1203 1204 1216 public void enableInputMethods(boolean enable) { 1217 if (enable) { 1218 if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) 1219 return; 1220 1221 if (isFocusOwner()) { 1225 InputContext inputContext = getInputContext(); 1226 if (inputContext != null) { 1227 FocusEvent focusGainedEvent = 1228 new FocusEvent(this, FocusEvent.FOCUS_GAINED); 1229 inputContext.dispatchEvent(focusGainedEvent); 1230 } 1231 } 1232 1233 eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK; 1234 } else { 1235 if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) { 1236 InputContext inputContext = getInputContext(); 1237 if (inputContext != null) { 1238 inputContext.endComposition(); 1239 inputContext.removeNotify(this); 1240 } 1241 } 1242 eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK; 1243 } 1244 } 1245 1246 1254 public void setVisible(boolean b) { 1255 show(b); 1256 } 1257 1258 1262 @Deprecated 1263 public void show() { 1264 if (!visible) { 1265 synchronized (getTreeLock()) { 1266 visible = true; 1267 ComponentPeer peer = this.peer; 1268 if (peer != null) { 1269 peer.show(); 1270 createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, 1271 this, parent, 1272 HierarchyEvent.SHOWING_CHANGED, 1273 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); 1274 if (peer instanceof LightweightPeer) { 1275 repaint(); 1276 } 1277 updateCursorImmediately(); 1278 } 1279 1280 if (componentListener != null || 1281 (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || 1282 Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { 1283 ComponentEvent e = new ComponentEvent(this, 1284 ComponentEvent.COMPONENT_SHOWN); 1285 Toolkit.getEventQueue().postEvent(e); 1286 } 1287 } 1288 Container parent = this.parent; 1289 if (parent != null) { 1290 parent.invalidate(); 1291 } 1292 } 1293 } 1294 1295 1299 @Deprecated 1300 public void show(boolean b) { 1301 if (b) { 1302 show(); 1303 } else { 1304 hide(); 1305 } 1306 } 1307 1308 boolean containsFocus() { 1309 return isFocusOwner(); 1310 } 1311 1312 void clearMostRecentFocusOwnerOnHide() { 1313 KeyboardFocusManager.clearMostRecentFocusOwner(this); 1314 } 1315 1316 void clearCurrentFocusCycleRootOnHide() { 1317 1318 } 1319 1320 1324 @Deprecated 1325 public void hide() { 1326 isPacked = false; 1327 1328 if (visible) { 1329 clearCurrentFocusCycleRootOnHide(); 1330 clearMostRecentFocusOwnerOnHide(); 1331 synchronized (getTreeLock()) { 1332 visible = false; 1333 if (containsFocus()) { 1334 autoTransferFocus(true); 1335 } 1336 ComponentPeer peer = this.peer; 1337 if (peer != null) { 1338 peer.hide(); 1339 createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, 1340 this, parent, 1341 HierarchyEvent.SHOWING_CHANGED, 1342 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)); 1343 if (peer instanceof LightweightPeer) { 1344 repaint(); 1345 } 1346 updateCursorImmediately(); 1347 } 1348 if (componentListener != null || 1349 (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || 1350 Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) { 1351 ComponentEvent e = new ComponentEvent(this, 1352 ComponentEvent.COMPONENT_HIDDEN); 1353 Toolkit.getEventQueue().postEvent(e); 1354 } 1355 } 1356 Container parent = this.parent; 1357 if (parent != null) { 1358 parent.invalidate(); 1359 } 1360 } 1361 } 1362 1363 1373 public Color getForeground() { 1374 Color foreground = this.foreground; 1375 if (foreground != null) { 1376 return foreground; 1377 } 1378 Container parent = this.parent; 1379 return (parent != null) ? parent.getForeground() : null; 1380 } 1381 1382 1391 public void setForeground(Color c) { 1392 Color oldColor = foreground; 1393 ComponentPeer peer = this.peer; 1394 foreground = c; 1395 if (peer != null) { 1396 c = getForeground(); 1397 if (c != null) { 1398 peer.setForeground(c); 1399 } 1400 } 1401 firePropertyChange("foreground", oldColor, c); 1404 } 1405 1406 1415 public boolean isForegroundSet() { 1416 return (foreground != null); 1417 } 1418 1419 1427 public Color getBackground() { 1428 Color background = this.background; 1429 if (background != null) { 1430 return background; 1431 } 1432 Container parent = this.parent; 1433 return (parent != null) ? parent.getBackground() : null; 1434 } 1435 1436 1451 public void setBackground(Color c) { 1452 Color oldColor = background; 1453 ComponentPeer peer = this.peer; 1454 background = c; 1455 if (peer != null) { 1456 c = getBackground(); 1457 if (c != null) { 1458 peer.setBackground(c); 1459 } 1460 } 1461 firePropertyChange("background", oldColor, c); 1464 } 1465 1466 1475 public boolean isBackgroundSet() { 1476 return (background != null); 1477 } 1478 1479 1486 public Font getFont() { 1487 return getFont_NoClientCode(); 1488 } 1489 1490 final Font getFont_NoClientCode() { 1495 Font font = this.font; 1496 if (font != null) { 1497 return font; 1498 } 1499 Container parent = this.parent; 1500 return (parent != null) ? parent.getFont_NoClientCode() : null; 1501 } 1502 1503 1513 public void setFont(Font f) { 1514 Font oldFont, newFont; 1515 synchronized(getTreeLock()) { 1516 synchronized (this) { 1517 oldFont = font; 1518 newFont = font = f; 1519 } 1520 ComponentPeer peer = this.peer; 1521 if (peer != null) { 1522 f = getFont(); 1523 if (f != null) { 1524 peer.setFont(f); 1525 peerFont = f; 1526 } 1527 } 1528 } 1529 firePropertyChange("font", oldFont, newFont); 1532 1533 if (valid) { 1535 invalidate(); 1536 } 1537 } 1538 1539 1548 public boolean isFontSet() { 1549 return (font != null); 1550 } 1551 1552 1563 public Locale getLocale() { 1564 Locale locale = this.locale; 1565 if (locale != null) { 1566 return locale; 1567 } 1568 Container parent = this.parent; 1569 1570 if (parent == null) { 1571 throw new IllegalComponentStateException ("This component must have a parent in order to determine its locale"); 1572 } else { 1573 return parent.getLocale(); 1574 } 1575 } 1576 1577 1583 public void setLocale(Locale l) { 1584 Locale oldValue = locale; 1585 locale = l; 1586 1587 firePropertyChange("locale", oldValue, l); 1590 1591 if (valid) { 1593 invalidate(); 1594 } 1595 } 1596 1597 1606 public ColorModel getColorModel() { 1607 ComponentPeer peer = this.peer; 1608 if ((peer != null) && ! (peer instanceof LightweightPeer)) { 1609 return peer.getColorModel(); 1610 } else if (GraphicsEnvironment.isHeadless()) { 1611 return ColorModel.getRGBdefault(); 1612 } return getToolkit().getColorModel(); 1614 } 1615 1616 1636 public Point getLocation() { 1637 return location(); 1638 } 1639 1640 1652 public Point getLocationOnScreen() { 1653 synchronized (getTreeLock()) { 1654 return getLocationOnScreen_NoTreeLock(); 1655 } 1656 } 1657 1658 1662 final Point getLocationOnScreen_NoTreeLock() { 1663 1664 if (peer != null && isShowing()) { 1665 if (peer instanceof LightweightPeer) { 1666 Container host = getNativeContainer(); 1669 Point pt = host.peer.getLocationOnScreen(); 1670 for(Component c = this; c != host; c = c.getParent()) { 1671 pt.x += c.x; 1672 pt.y += c.y; 1673 } 1674 return pt; 1675 } else { 1676 Point pt = peer.getLocationOnScreen(); 1677 return pt; 1678 } 1679 } else { 1680 throw new IllegalComponentStateException ("component must be showing on the screen to determine its location"); 1681 } 1682 } 1683 1684 1685 1689 @Deprecated 1690 public Point location() { 1691 return new Point (x, y); 1692 } 1693 1694 1706 public void setLocation(int x, int y) { 1707 move(x, y); 1708 } 1709 1710 1714 @Deprecated 1715 public void move(int x, int y) { 1716 synchronized(getTreeLock()) { 1717 setBoundsOp(ComponentPeer.SET_LOCATION); 1718 setBounds(x, y, width, height); 1719 } 1720 } 1721 1722 1733 public void setLocation(Point p) { 1734 setLocation(p.x, p.y); 1735 } 1736 1737 1749 public Dimension getSize() { 1750 return size(); 1751 } 1752 1753 1757 @Deprecated 1758 public Dimension size() { 1759 return new Dimension (width, height); 1760 } 1761 1762 1771 public void setSize(int width, int height) { 1772 resize(width, height); 1773 } 1774 1775 1779 @Deprecated 1780 public void resize(int width, int height) { 1781 synchronized(getTreeLock()) { 1782 setBoundsOp(ComponentPeer.SET_SIZE); 1783 setBounds(x, y, width, height); 1784 } 1785 } 1786 1787 1796 public void setSize(Dimension d) { 1797 resize(d); 1798 } 1799 1800 1804 @Deprecated 1805 public void resize(Dimension d) { 1806 setSize(d.width, d.height); 1807 } 1808 1809 1819 public Rectangle getBounds() { 1820 return bounds(); 1821 } 1822 1823 1827 @Deprecated 1828 public Rectangle bounds() { 1829 return new Rectangle (x, y, width, height); 1830 } 1831 1832 1848 public void setBounds(int x, int y, int width, int height) { 1849 reshape(x, y, width, height); 1850 } 1851 1852 1856 @Deprecated 1857 public void reshape(int x, int y, int width, int height) { 1858 synchronized (getTreeLock()) { 1859 try { 1860 setBoundsOp(ComponentPeer.SET_BOUNDS); 1861 boolean resized = (this.width != width) || (this.height != height); 1862 boolean moved = (this.x != x) || (this.y != y); 1863 if (!resized && !moved) { 1864 return; 1865 } 1866 int oldX = this.x; 1867 int oldY = this.y; 1868 int oldWidth = this.width; 1869 int oldHeight = this.height; 1870 this.x = x; 1871 this.y = y; 1872 this.width = width; 1873 this.height = height; 1874 1875 if (resized) { 1876 isPacked = false; 1877 } 1878 1879 if (peer != null) { 1880 if (!(peer instanceof LightweightPeer)) { 1882 reshapeNativePeer(x, y, width, height, getBoundsOp()); 1883 resized = (oldWidth != this.width) || (oldHeight != this.height); 1885 moved = (oldX != this.x) || (oldY != this.y); 1886 } 1887 1888 if (resized) { 1889 invalidate(); 1890 } 1891 if (parent != null && parent.valid) { 1892 parent.invalidate(); 1893 } 1894 } 1895 notifyNewBounds(resized, moved); 1896 repaintParentIfNeeded(oldX, oldY, oldWidth, oldHeight); 1897 } finally { 1898 setBoundsOp(ComponentPeer.RESET_OPERATION); 1899 } 1900 } 1901 } 1902 1903 private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth, 1904 int oldHeight) 1905 { 1906 if (parent != null && peer instanceof LightweightPeer && isShowing()) { 1907 parent.repaint(oldX, oldY, oldWidth, oldHeight); 1909 repaint(); 1911 } 1912 } 1913 1914 private void reshapeNativePeer(int x, int y, int width, int height, int op) { 1915 int nativeX = x; 1918 int nativeY = y; 1919 for (Component c = parent; 1920 (c != null) && (c.peer instanceof LightweightPeer); 1921 c = c.parent) 1922 { 1923 nativeX += c.x; 1924 nativeY += c.y; 1925 } 1926 peer.setBounds(nativeX, nativeY, width, height, op); 1927 } 1928 1929 1930 private void notifyNewBounds(boolean resized, boolean moved) { 1931 if (componentListener != null 1932 || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 1933 || Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) 1934 { 1935 if (resized) { 1936 ComponentEvent e = new ComponentEvent(this, 1937 ComponentEvent.COMPONENT_RESIZED); 1938 Toolkit.getEventQueue().postEvent(e); 1939 } 1940 if (moved) { 1941 ComponentEvent e = new ComponentEvent(this, 1942 ComponentEvent.COMPONENT_MOVED); 1943 Toolkit.getEventQueue().postEvent(e); 1944 } 1945 } else 1946 if (this instanceof Container && ((Container )this).ncomponents > 0) { 1948 boolean enabledOnToolkit = 1949 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); 1950 if (resized) { 1953 ((Container )this).createChildHierarchyEvents( 1954 HierarchyEvent.ANCESTOR_RESIZED, 0, enabledOnToolkit); 1955 } 1956 if (moved) { 1957 ((Container )this).createChildHierarchyEvents( 1958 HierarchyEvent.ANCESTOR_MOVED, 0, enabledOnToolkit); 1959 } 1960 } 1961 } 1962 1963 1977 public void setBounds(Rectangle r) { 1978 setBounds(r.x, r.y, r.width, r.height); 1979 } 1980 1981 1982 1992 public int getX() { 1993 return x; 1994 } 1995 1996 1997 2007 public int getY() { 2008 return y; 2009 } 2010 2011 2012 2022 public int getWidth() { 2023 return width; 2024 } 2025 2026 2027 2037 public int getHeight() { 2038 return height; 2039 } 2040 2041 2052 public Rectangle getBounds(Rectangle rv) { 2053 if (rv == null) { 2054 return new Rectangle (getX(), getY(), getWidth(), getHeight()); 2055 } 2056 else { 2057 rv.setBounds(getX(), getY(), getWidth(), getHeight()); 2058 return rv; 2059 } 2060 } 2061 2062 2072 public Dimension getSize(Dimension rv) { 2073 if (rv == null) { 2074 return new Dimension (getWidth(), getHeight()); 2075 } 2076 else { 2077 rv.setSize(getWidth(), getHeight()); 2078 return rv; 2079 } 2080 } 2081 2082 2093 public Point getLocation(Point rv) { 2094 if (rv == null) { 2095 return new Point (getX(), getY()); 2096 } 2097 else { 2098 rv.setLocation(getX(), getY()); 2099 return rv; 2100 } 2101 } 2102 2103 2122 public boolean isOpaque() { 2123 if (getPeer() == null) { 2124 return false; 2125 } 2126 else { 2127 return !isLightweight(); 2128 } 2129 } 2130 2131 2132 2148 public boolean isLightweight() { 2149 return getPeer() instanceof LightweightPeer; 2150 } 2151 2152 2153 2164 public void setPreferredSize(Dimension preferredSize) { 2165 Dimension old; 2166 if (prefSizeSet) { 2170 old = this.prefSize; 2171 } 2172 else { 2173 old = null; 2174 } 2175 this.prefSize = preferredSize; 2176 prefSizeSet = (preferredSize != null); 2177 firePropertyChange("preferredSize", old, preferredSize); 2178 } 2179 2180 2181 2189 public boolean isPreferredSizeSet() { 2190 return prefSizeSet; 2191 } 2192 2193 2194 2200 public Dimension getPreferredSize() { 2201 return preferredSize(); 2202 } 2203 2204 2205 2209 @Deprecated 2210 public Dimension preferredSize() { 2211 2214 Dimension dim = prefSize; 2215 if (dim == null || !(isPreferredSizeSet() || isValid())) { 2216 synchronized (getTreeLock()) { 2217 prefSize = (peer != null) ? 2218 peer.preferredSize() : 2219 getMinimumSize(); 2220 dim = prefSize; 2221 } 2222 } 2223 return new Dimension (dim); 2224 } 2225 2226 2237 public void setMinimumSize(Dimension minimumSize) { 2238 Dimension old; 2239 if (minSizeSet) { 2243 old = this.minSize; 2244 } 2245 else { 2246 old = null; 2247 } 2248 this.minSize = minimumSize; 2249 minSizeSet = (minimumSize != null); 2250 firePropertyChange("minimumSize", old, minimumSize); 2251 } 2252 2253 2261 public boolean isMinimumSizeSet() { 2262 return minSizeSet; 2263 } 2264 2265 2271 public Dimension getMinimumSize() { 2272 return minimumSize(); 2273 } 2274 2275 2279 @Deprecated 2280 public Dimension minimumSize() { 2281 2284 Dimension dim = minSize; 2285 if (dim == null || !(isMinimumSizeSet() || isValid())) { 2286 synchronized (getTreeLock()) { 2287 minSize = (peer != null) ? 2288 peer.minimumSize() : 2289 size(); 2290 dim = minSize; 2291 } 2292 } 2293 return new Dimension (dim); 2294 } 2295 2296 2308 public void setMaximumSize(Dimension maximumSize) { 2309 Dimension old; 2313 if (maxSizeSet) { 2314 old = this.maxSize; 2315 } 2316 else { 2317 old = null; 2318 } 2319 this.maxSize = maximumSize; 2320 maxSizeSet = (maximumSize != null); 2321 firePropertyChange("maximumSize", old, maximumSize); 2322 } 2323 2324 2332 public boolean isMaximumSizeSet() { 2333 return maxSizeSet; 2334 } 2335 2336 2343 public Dimension getMaximumSize() { 2344 if (isMaximumSizeSet()) { 2345 return new Dimension (maxSize); 2346 } 2347 return new Dimension (Short.MAX_VALUE, Short.MAX_VALUE); 2348 } 2349 2350 2357 public float getAlignmentX() { 2358 return CENTER_ALIGNMENT; 2359 } 2360 2361 2368 public float getAlignmentY() { 2369 return CENTER_ALIGNMENT; 2370 } 2371 2372 2379 public void doLayout() { 2380 layout(); 2381 } 2382 2383 2387 @Deprecated 2388 public void layout() { 2389 } 2390 2391 2400 public void validate() { 2401 if (!valid) { 2402 synchronized (getTreeLock()) { 2403 ComponentPeer peer = this.peer; 2404 if (!valid && peer != null) { 2405 Font newfont = getFont(); 2406 Font oldfont = peerFont; 2407 if (newfont != oldfont && (oldfont == null 2408 || !oldfont.equals(newfont))) { 2409 peer.setFont(newfont); 2410 peerFont = newfont; 2411 } 2412 peer.layout(); 2413 } 2414 } 2415 valid = true; 2416 } 2417 } 2418 2419 2428 public void invalidate() { 2429 synchronized (getTreeLock()) { 2430 2434 valid = false; 2435 if (!isPreferredSizeSet()) { 2436 prefSize = null; 2437 } 2438 if (!isMinimumSizeSet()) { 2439 minSize = null; 2440 } 2441 if (!isMaximumSizeSet()) { 2442 maxSize = null; 2443 } 2444 if (parent != null && parent.valid) { 2445 parent.invalidate(); 2446 } 2447 } 2448 } 2449 2450 2459 public Graphics getGraphics() { 2460 if (peer instanceof LightweightPeer) { 2461 if (parent == null) return null; 2465 Graphics g = parent.getGraphics(); 2466 if (g == null) return null; 2467 if (g instanceof ConstrainableGraphics) { 2468 ((ConstrainableGraphics) g).constrain(x, y, width, height); 2469 } else { 2470 g.translate(x,y); 2471 g.setClip(0, 0, width, height); 2472 } 2473 g.setFont(getFont()); 2474 return g; 2475 } else { 2476 ComponentPeer peer = this.peer; 2477 return (peer != null) ? peer.getGraphics() : null; 2478 } 2479 } 2480 2481 2482 2483 static java.util.Hashtable metrics = new java.util.Hashtable (); 2484 2495 public FontMetrics getFontMetrics(Font font) { 2496 boolean altCompFonts = FontManager.maybeUsingAlternateCompositeFonts(); 2497 FontMetrics result; 2498 2499 2500 if (altCompFonts) { 2501 result = null; 2502 } else { 2503 result = (FontMetrics ) metrics.get(font); 2504 } 2505 if (result != null) { 2506 return result; 2507 } 2508 if (sun.font.FontManager.usePlatformFontMetrics()) { 2510 if (peer != null && 2511 !(peer instanceof LightweightPeer)) { 2512 result = peer.getFontMetrics(font); 2513 if (!altCompFonts) { 2514 metrics.put(font, result); 2515 } 2516 return result; 2517 } 2518 } 2519 if (parent != null) { 2520 Graphics g = parent.getGraphics(); 2525 if (g != null) { 2526 try { 2527 result = g.getFontMetrics(font); 2528 if (!altCompFonts) { 2529 metrics.put(font, result); 2530 } 2531 return result; 2532 } finally { 2533 g.dispose(); 2534 } 2535 } 2536 } 2537 2538 result = getToolkit().getFontMetrics(font); 2539 if (!altCompFonts) { 2540 metrics.put(font, result); 2541 } 2542 return result; 2543 } 2544 2545 2567 public void setCursor(Cursor cursor) { 2568 this.cursor = cursor; 2569 updateCursorImmediately(); 2570 } 2571 2572 2576 final void updateCursorImmediately() { 2577 if (peer instanceof LightweightPeer) { 2578 Container nativeContainer = getNativeContainer(); 2579 2580 if (nativeContainer == null) return; 2581 2582 ComponentPeer cPeer = nativeContainer.getPeer(); 2583 2584 if (cPeer != null) { 2585 cPeer.updateCursorImmediately(); 2586 } 2587 } else if (peer != null) { 2588 peer.updateCursorImmediately(); 2589 } 2590 } 2591 2592 2600 public Cursor getCursor() { 2601 Cursor cursor = this.cursor; 2602 if (cursor != null) { 2603 return cursor; 2604 } 2605 Container parent = this.parent; 2606 if (parent != null) { 2607 return parent.getCursor(); 2608 } else { 2609 return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); 2610 } 2611 } 2612 2613 2622 public boolean isCursorSet() { 2623 return (cursor != null); 2624 } 2625 2626 2650 public void paint(Graphics g) { 2651 } 2652 2653 2686 public void update(Graphics g) { 2687 paint(g); 2688 } 2689 2690 2702 public void paintAll(Graphics g) { 2703 if (isShowing()) { 2704 GraphicsCallback.PeerPaintCallback.getInstance(). 2705 runOneComponent(this, new Rectangle (0, 0, width, height), 2706 g, g.getClip(), 2707 GraphicsCallback.LIGHTWEIGHTS | 2708 GraphicsCallback.HEAVYWEIGHTS); 2709 } 2710 } 2711 2712 2718 void lightweightPaint(Graphics g) { 2719 paint(g); 2720 } 2721 2722 2725 void paintHeavyweightComponents(Graphics g) { 2726 } 2727 2728 2746 public void repaint() { 2747 repaint(0, 0, 0, width, height); 2748 } 2749 2750 2765 public void repaint(long tm) { 2766 repaint(tm, 0, 0, width, height); 2767 } 2768 2769 2789 public void repaint(int x, int y, int width, int height) { 2790 repaint(0, x, y, width, height); 2791 } 2792 2793 2815 public void repaint(long tm, int x, int y, int width, int height) { 2816 if (this.peer instanceof LightweightPeer) { 2817 if (parent != null) { 2822 int px = this.x + ((x < 0) ? 0 : x); 2823 int py = this.y + ((y < 0) ? 0 : y); 2824 int pwidth = (width > this.width) ? this.width : width; 2825 int pheight = (height > this.height) ? this.height : height; 2826 parent.repaint(tm, px, py, pwidth, pheight); 2827 } 2828 } else { 2829 if (isVisible() && (this.peer != null) && 2830 (width > 0) && (height > 0)) { 2831 PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE, 2832 new Rectangle (x, y, width, height)); 2833 Toolkit.getEventQueue().postEvent(e); 2834 } 2835 } 2836 } 2837 2838 2854 public void print(Graphics g) { 2855 paint(g); 2856 } 2857 2858 2869 public void printAll(Graphics g) { 2870 if (isShowing()) { 2871 GraphicsCallback.PeerPrintCallback.getInstance(). 2872 runOneComponent(this, new Rectangle (0, 0, width, height), 2873 g, g.getClip(), 2874 GraphicsCallback.LIGHTWEIGHTS | 2875 GraphicsCallback.HEAVYWEIGHTS); 2876 } 2877 } 2878 2879 2885 void lightweightPrint(Graphics g) { 2886 print(g); 2887 } 2888 2889 2892 void printHeavyweightComponents(Graphics g) { 2893 } 2894 2895 2941 public boolean imageUpdate(Image img, int infoflags, 2942 int x, int y, int w, int h) { 2943 int rate = -1; 2944 if ((infoflags & (FRAMEBITS|ALLBITS)) != 0) { 2945 rate = 0; 2946 } else if ((infoflags & SOMEBITS) != 0) { 2947 if (isInc) { 2948 rate = incRate; 2949 if (rate < 0) { 2950 rate = 0; 2951 } 2952 } 2953 } 2954 if (rate >= 0) { 2955 repaint(rate, 0, 0, width, height); 2956 } 2957 return (infoflags & (ALLBITS|ABORT)) == 0; 2958 } 2959 2960 2966 public Image createImage(ImageProducer producer) { 2967 ComponentPeer peer = this.peer; 2968 if ((peer != null) && ! (peer instanceof LightweightPeer)) { 2969 return peer.createImage(producer); 2970 } 2971 return getToolkit().createImage(producer); 2972 } 2973 2974 2988 public Image createImage(int width, int height) { 2989 ComponentPeer peer = this.peer; 2990 if (peer instanceof LightweightPeer) { 2991 if (parent != null) { return parent.createImage(width, height); } 2992 else { return null;} 2993 } else { 2994 return (peer != null) ? peer.createImage(width, height) : null; 2995 } 2996 } 2997 2998 3013 public VolatileImage createVolatileImage(int width, int height) { 3014 ComponentPeer peer = this.peer; 3015 if (peer instanceof LightweightPeer) { 3016 if (parent != null) { 3017 return parent.createVolatileImage(width, height); 3018 } 3019 else { return null;} 3020 } else { 3021 return (peer != null) ? 3022 peer.createVolatileImage(width, height) : null; 3023 } 3024 } 3025 3026 3041 public VolatileImage createVolatileImage(int width, int height, 3042 ImageCapabilities caps) throws AWTException { 3043 return createVolatileImage(width, height); 3045 } 3046 3047 3059 public boolean prepareImage(Image image, ImageObserver observer) { 3060 return prepareImage(image, -1, -1, observer); 3061 } 3062 3063 3081 public boolean prepareImage(Image image, int width, int height, 3082 ImageObserver observer) { 3083 ComponentPeer peer = this.peer; 3084 if (peer instanceof LightweightPeer) { 3085 return (parent != null) 3086 ? parent.prepareImage(image, width, height, observer) 3087 : getToolkit().prepareImage(image, width, height, observer); 3088 } else { 3089 return (peer != null) 3090 ? peer.prepareImage(image, width, height, observer) 3091 : getToolkit().prepareImage(image, width, height, observer); 3092 } 3093 } 3094 3095 3117 public int checkImage(Image image, ImageObserver observer) { 3118 return checkImage(image, -1, -1, observer); 3119 } 3120 3121 3153 public int checkImage(Image image, int width, int height, 3154 ImageObserver observer) { 3155 ComponentPeer peer = this.peer; 3156 if (peer instanceof LightweightPeer) { 3157 return (parent != null) 3158 ? parent.checkImage(image, width, height, observer) 3159 : getToolkit().checkImage(image, width, height, observer); 3160 } else { 3161 return (peer != null) 3162 ? peer.checkImage(image, width, height, observer) 3163 : getToolkit().checkImage(image, width, height, observer); 3164 } 3165 } 3166 3167 3186 void createBufferStrategy(int numBuffers) { 3187 BufferCapabilities bufferCaps; 3188 if (numBuffers > 1) { 3189 bufferCaps = new BufferCapabilities ( 3191 new ImageCapabilities (true), new ImageCapabilities (true), 3192 BufferCapabilities.FlipContents.UNDEFINED); 3193 try { 3194 createBufferStrategy(numBuffers, bufferCaps); 3195 return; } catch (AWTException e) { 3197 } 3199 } 3200 bufferCaps = new BufferCapabilities ( 3202 new ImageCapabilities (true), new ImageCapabilities (true), null); 3203 try { 3204 createBufferStrategy(numBuffers, bufferCaps); 3205 return; } catch (AWTException e) { 3207 } 3209 bufferCaps = new BufferCapabilities ( 3211 new ImageCapabilities (false), new ImageCapabilities (false), null); 3212 try { 3213 createBufferStrategy(numBuffers, bufferCaps); 3214 return; } catch (AWTException e) { 3216 } 3218 throw new InternalError ("Could not create a buffer strategy"); 3221 } 3222 3223 3243 void createBufferStrategy(int numBuffers, 3244 BufferCapabilities caps) throws AWTException { 3245 if (numBuffers < 1) { 3247 throw new IllegalArgumentException ( 3248 "Number of buffers must be at least 1"); 3249 } 3250 if (caps == null) { 3251 throw new IllegalArgumentException ("No capabilities specified"); 3252 } 3253 if (bufferStrategy instanceof FlipBufferStrategy) { 3255 ((FlipBufferStrategy)bufferStrategy).destroyBuffers(); 3256 } 3257 if (numBuffers == 1) { 3258 bufferStrategy = new SingleBufferStrategy(caps); 3259 } else { 3260 if (caps.isPageFlipping()) { 3262 bufferStrategy = new FlipBufferStrategy(numBuffers, caps); 3263 } else { 3264 bufferStrategy = new BltBufferStrategy(numBuffers, caps); 3265 } 3266 } 3267 } 3268 3269 3275 BufferStrategy getBufferStrategy() { 3276 if (bufferStrategy == null) { 3277 createBufferStrategy(1); 3278 } 3279 return bufferStrategy; 3280 } 3281 3282 3287 Image getBackBuffer() { 3288 if (bufferStrategy != null) { 3289 if (bufferStrategy instanceof BltBufferStrategy) { 3290 BltBufferStrategy bltBS = (BltBufferStrategy)bufferStrategy; 3291 return bltBS.getBackBuffer(); 3292 } else if (bufferStrategy instanceof FlipBufferStrategy) { 3293 FlipBufferStrategy flipBS = (FlipBufferStrategy)bufferStrategy; 3294 return flipBS.getBackBuffer(); 3295 } 3296 } 3297 return null; 3298 } 3299 3300 3309 protected class FlipBufferStrategy extends BufferStrategy { 3310 3313 protected int numBuffers; 3317 protected BufferCapabilities caps; 3321 protected Image drawBuffer; 3325 protected VolatileImage drawVBuffer; 3330 protected boolean validatedContents; 3332 3344 protected FlipBufferStrategy(int numBuffers, BufferCapabilities caps) 3345 throws AWTException { 3346 if (!(Component.this instanceof Window ) && 3347 !(Component.this instanceof Canvas )) { 3348 throw new ClassCastException ( 3349 "Component must be a Canvas or Window"); 3350 } 3351 this.numBuffers = numBuffers; 3352 this.caps = caps; 3353 createBuffers(numBuffers, caps); 3354 } 3355 3356 3372 protected void createBuffers(int numBuffers, BufferCapabilities caps) 3373 throws AWTException { 3374 if (numBuffers < 2) { 3375 throw new IllegalArgumentException ( 3376 "Number of buffers cannot be less than two"); 3377 } else if (peer == null) { 3378 throw new IllegalStateException ( 3379 "Component must have a valid peer"); 3380 } else if (caps == null || !caps.isPageFlipping()) { 3381 throw new IllegalArgumentException ( 3382 "Page flipping capabilities must be specified"); 3383 } else { 3384 peer.createBuffers(numBuffers, caps); 3385 } 3386 } 3387 3388 3393 protected Image getBackBuffer() { 3394 if (peer != null) { 3395 Image drawBuffer = peer.getBackBuffer(); 3396 if (drawBuffer instanceof VolatileImage ) { 3397 drawVBuffer = (VolatileImage )drawBuffer; 3398 } 3399 revalidate(); 3400 return drawBuffer; 3401 } else { 3402 throw new IllegalStateException ( 3403 "Component must have a valid peer"); 3404 } 3405 } 3406 3407 3418 protected void flip(BufferCapabilities.FlipContents flipAction) { 3419 if (peer != null) { 3420 peer.flip(flipAction); 3421 } else { 3422 throw new IllegalStateException ( 3423 "Component must have a valid peer"); 3424 } 3425 } 3426 3427 3430 protected void destroyBuffers() { 3431 if (peer != null) { 3432 peer.destroyBuffers(); 3433 } else { 3434 throw new IllegalStateException ( 3435 "Component must have a valid peer"); 3436 } 3437 } 3438 3439 3442 public BufferCapabilities getCapabilities() { 3443 return caps; 3444 } 3445 3446 3452 public Graphics getDrawGraphics() { 3453 if (drawBuffer == null) { 3454 drawBuffer = getBackBuffer(); 3456 if (drawBuffer instanceof VolatileImage ) { 3457 drawVBuffer = (VolatileImage )drawBuffer; 3458 } 3459 } 3460 revalidate(); 3461 return drawBuffer.getGraphics(); 3462 } 3463 3464 3467 protected void revalidate() { 3468 if (drawVBuffer != null) { 3474 validatedContents = (drawVBuffer.validate( 3475 getGraphicsConfiguration()) == VolatileImage.IMAGE_RESTORED); 3476 } else { 3477 validatedContents = false; 3478 } 3479 } 3480 3481 3485 public boolean contentsLost() { 3486 if (drawVBuffer == null) { 3487 return false; 3488 } 3489 return drawVBuffer.contentsLost(); 3490 } 3491 3492 3496 public boolean contentsRestored() { 3497 return validatedContents; 3498 } 3499 3500 3504 public void show() { 3505 flip(caps.getFlipContents()); 3506 } 3507 3508 } 3510 3516 protected class BltBufferStrategy extends BufferStrategy { 3517 3518 3521 protected BufferCapabilities caps; 3525 protected VolatileImage [] backBuffers; 3530 protected boolean validatedContents; 3534 protected int width; 3535 protected int height; 3536 3537 3542 protected BltBufferStrategy(int numBuffers, BufferCapabilities caps) { 3543 this.caps = caps; 3544 createBackBuffers(numBuffers - 1); 3545 } 3546 3547 3550 protected void createBackBuffers(int numBuffers) { 3551 if (numBuffers == 0) { 3552 backBuffers = null; 3553 } else { 3554 width = getWidth(); 3555 height = getHeight(); 3556 backBuffers = new VolatileImage [numBuffers]; 3557 for (int i = 0; i < numBuffers; i++) { 3558 backBuffers[i] = createVolatileImage(width, height); 3559 } 3560 } 3561 } 3562 3563 3566 public BufferCapabilities getCapabilities() { 3567 return caps; 3568 } 3569 3570 3573 public Graphics getDrawGraphics() { 3574 revalidate(); 3575 Image backBuffer = getBackBuffer(); 3576 if (backBuffer == null) { 3577 return getGraphics(); 3578 } 3579 return backBuffer.getGraphics(); 3580 } 3581 3582 3586 Image getBackBuffer() { 3587 if (backBuffers != null) { 3588 return backBuffers[backBuffers.length - 1]; 3589 } else { 3590 return null; 3591 } 3592 } 3593 3594 3597 public void show() { 3598 if (backBuffers == null) { 3599 return; 3600 } 3601 3602 Graphics g = getGraphics(); 3603 try { 3604 for (int i = 0; i < backBuffers.length; i++) { 3605 g.drawImage(backBuffers[i], 0, 0, Component.this); 3606 g.dispose(); 3607 g = null; 3608 g = backBuffers[i].getGraphics(); 3609 } 3610 } finally { 3611 if (g != null) { 3612 g.dispose(); 3613 } 3614 } 3615 } 3616 3617 3620 protected void revalidate() { 3621 if (backBuffers == null) { 3622 validatedContents = false; 3623 } else if (getWidth() != width || getHeight() != height) { 3624 createBackBuffers(backBuffers.length); 3625 validatedContents = true; 3626 } else { 3627 validatedContents = 3628 (backBuffers[backBuffers.length - 1].validate( 3629 getGraphicsConfiguration()) 3630 == VolatileImage.IMAGE_RESTORED); 3631 } 3633 } 3634 3635 3639 public boolean contentsLost() { 3640 if (width < getWidth() || height < getHeight()) { 3641 return true; 3642 } else { 3643 return backBuffers[backBuffers.length - 1].contentsLost(); 3644 } 3645 } 3646 3647 3651 public boolean contentsRestored() { 3652 return validatedContents; 3653 } 3654 3655 } 3657 3666 private class SingleBufferStrategy extends BufferStrategy { 3667 3668 private BufferCapabilities caps; 3669 3670 public SingleBufferStrategy(BufferCapabilities caps) { 3671 this.caps = caps; 3672 } 3673 public BufferCapabilities getCapabilities() { 3674 return caps; 3675 } 3676 public Graphics getDrawGraphics() { 3677 return getGraphics(); 3678 } 3679 public boolean contentsLost() { 3680 return false; 3682 } 3683 public boolean contentsRestored() { 3684 return false; 3686 } 3687 public void show() { 3688 } 3690 } 3692 3709 public void setIgnoreRepaint(boolean ignoreRepaint) { 3710 this.ignoreRepaint = ignoreRepaint; 3711 } 3712 3713 3720 public boolean getIgnoreRepaint() { 3721 return ignoreRepaint; 3722 } 3723 3724 3733 public boolean contains(int x, int y) { 3734 return inside(x, y); 3735 } 3736 3737 3741 @Deprecated 3742 public boolean inside(int x, int y) { 3743 return (x >= 0) && (x < width) && (y >= 0) && (y < height); 3744 } 3745 3746 3754 public boolean contains(Point p) { 3755 return contains(p.x, p.y); 3756 } 3757 3758 3779 public Component getComponentAt(int x, int y) { 3780 return locate(x, y); 3781 } 3782 3783 3787 @Deprecated 3788 public Component locate(int x, int y) { 3789 return contains(x, y) ? this : null; 3790 } 3791 3792 3799 public Component getComponentAt(Point p) { 3800 return getComponentAt(p.x, p.y); 3801 } 3802 3803 3807 @Deprecated 3808 public void deliverEvent(Event e) { 3809 postEvent(e); 3810 } 3811 3812 3818 public final void dispatchEvent(AWTEvent e) { 3819 dispatchEventImpl(e); 3820 } 3821 3822 void dispatchEventImpl(AWTEvent e) { 3823 int id = e.getID(); 3824 3825 AppContext compContext = appContext; 3827 if (compContext != null && !compContext.equals(AppContext.getAppContext())) { 3828 log.fine("Event " + e + " is being dispatched on the wrong AppContext"); 3829 } 3830 3831 3834 EventQueue.setCurrentEventAndMostRecentTime(e); 3835 3836 3840 3841 if (e instanceof SunDropTargetEvent) { 3842 ((SunDropTargetEvent)e).dispatch(); 3843 return; 3844 } 3845 3846 if (!e.focusManagerIsDispatching) { 3847 if (e.isPosted) { 3850 e = KeyboardFocusManager.retargetFocusEvent(e); 3851 e.isPosted = true; 3852 } 3853 3854 if (KeyboardFocusManager.getCurrentKeyboardFocusManager(). 3858 dispatchEvent(e)) 3859 { 3860 return; 3861 } 3862 } 3863 if (e instanceof FocusEvent && focusLog.isLoggable(Level.FINE)) { 3864 focusLog.fine("" + e); 3865 } 3866 if (id == MouseEvent.MOUSE_WHEEL && 3872 (!eventTypeEnabled(id)) && 3873 (peer != null && !peer.handlesWheelScrolling()) && 3874 (dispatchMouseWheelToAncestor((MouseWheelEvent)e))) 3875 { 3876 return; 3877 } 3878 3879 3882 Toolkit toolkit = Toolkit.getDefaultToolkit(); 3883 toolkit.notifyAWTEventListeners(e); 3884 3885 3886 3890 if (!e.isConsumed()) { 3891 if (e instanceof java.awt.event.KeyEvent ) { 3892 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 3893 processKeyEvent(this, (KeyEvent)e); 3894 if (e.isConsumed()) { 3895 return; 3896 } 3897 } 3898 } 3899 3900 3903 if (areInputMethodsEnabled()) { 3904 if(((e instanceof InputMethodEvent ) && !(this instanceof CompositionArea)) 3909 || 3910 (e instanceof InputEvent) || (e instanceof FocusEvent)) { 3915 InputContext inputContext = getInputContext(); 3916 3917 3918 if (inputContext != null) { 3919 inputContext.dispatchEvent(e); 3920 if (e.isConsumed()) { 3921 if (e instanceof FocusEvent && focusLog.isLoggable(Level.FINER)) { 3922 focusLog.finer("3579: Skipping " + e); 3923 } 3924 return; 3925 } 3926 } 3927 } 3928 } else { 3929 if (id == FocusEvent.FOCUS_GAINED) { 3933 InputContext inputContext = getInputContext(); 3934 if (inputContext != null && inputContext instanceof sun.awt.im.InputContext) { 3935 ((sun.awt.im.InputContext)inputContext).disableNativeIM(); 3936 } 3937 } 3938 } 3939 3940 3941 3944 switch(id) { 3945 3950 case KeyEvent.KEY_PRESSED: 3951 case KeyEvent.KEY_RELEASED: 3952 Container p = (Container )((this instanceof Container ) ? this : parent); 3953 if (p != null) { 3954 p.preProcessKeyEvent((KeyEvent)e); 3955 if (e.isConsumed()) { 3956 return; 3957 } 3958 } 3959 break; 3960 3961 case WindowEvent.WINDOW_CLOSING: 3962 if (toolkit instanceof WindowClosingListener) { 3963 windowClosingException = ((WindowClosingListener) 3964 toolkit).windowClosingNotify((WindowEvent)e); 3965 if (checkWindowClosingException()) { 3966 return; 3967 } 3968 } 3969 break; 3970 3971 default: 3972 break; 3973 } 3974 3975 3978 if (newEventsOnly) { 3979 if (eventEnabled(e)) { 3984 processEvent(e); 3985 } 3986 } else if (id == MouseEvent.MOUSE_WHEEL) { 3987 autoProcessMouseWheel((MouseWheelEvent)e); 3991 } else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) { 3992 Event olde = e.convertToOld(); 3996 if (olde != null) { 3997 int key = olde.key; 3998 int modifiers = olde.modifiers; 3999 4000 postEvent(olde); 4001 if (olde.isConsumed()) { 4002 e.consume(); 4003 } 4004 switch(olde.id) { 4008 case Event.KEY_PRESS: 4009 case Event.KEY_RELEASE: 4010 case Event.KEY_ACTION: 4011 case Event.KEY_ACTION_RELEASE: 4012 if (olde.key != key) { 4013 ((KeyEvent)e).setKeyChar(olde.getKeyEventChar()); 4014 } 4015 if (olde.modifiers != modifiers) { 4016 ((KeyEvent)e).setModifiers(olde.modifiers); 4017 } 4018 break; 4019 default: 4020 break; 4021 } 4022 } 4023 } 4024 4025 4029 if (id == WindowEvent.WINDOW_CLOSING && !e.isConsumed()) { 4030 if (toolkit instanceof WindowClosingListener) { 4031 windowClosingException = 4032 ((WindowClosingListener)toolkit). 4033 windowClosingDelivered((WindowEvent)e); 4034 if (checkWindowClosingException()) { 4035 return; 4036 } 4037 } 4038 } 4039 4040 4046 if (!(e instanceof KeyEvent)) { 4047 ComponentPeer tpeer = peer; 4048 if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) { 4049 Component source = (Component )e.getSource(); 4052 if (source != null) { 4053 Container target = source.getNativeContainer(); 4054 if (target != null) { 4055 tpeer = target.getPeer(); 4056 } 4057 } 4058 } 4059 if (tpeer != null) { 4060 tpeer.handleEvent(e); 4061 } 4062 } 4063 } 4065 4070 void autoProcessMouseWheel(MouseWheelEvent e) {} 4071 4072 4078 boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) { 4079 int newX, newY; 4080 newX = e.getX() + getX(); newY = e.getY() + getY(); MouseWheelEvent newMWE; 4085 4086 if (dbg.on) { 4087 dbg.println("Component.dispatchMouseWheelToAncestor"); 4088 dbg.println("orig event src is of " + e.getSource().getClass()); 4089 } 4090 4091 4094 synchronized (getTreeLock()) { 4095 Container anc = getParent(); 4096 while (anc != null && !anc.eventEnabled(e)) { 4097 newX += anc.getX(); 4099 newY += anc.getY(); 4100 4101 if (!(anc instanceof Window )) { 4102 anc = anc.getParent(); 4103 } 4104 else { 4105 break; 4106 } 4107 } 4108 4109 if (dbg.on) dbg.println("new event src is " + anc.getClass()); 4110 4111 if (anc != null && anc.eventEnabled(e)) { 4112 4115 newMWE = new MouseWheelEvent(anc, e.getID(), 4117 e.getWhen(), 4118 e.getModifiers(), 4119 newX, newY, e.getClickCount(), 4122 e.isPopupTrigger(), 4123 e.getScrollType(), 4124 e.getScrollAmount(), 4125 e.getWheelRotation()); 4126 ((AWTEvent )e).copyPrivateDataInto(newMWE); 4127 anc.dispatchEventImpl(newMWE); 4128 } 4129 } 4130 return true; 4131 } 4132 4133 boolean checkWindowClosingException() { 4134 if (windowClosingException != null) { 4135 if (this instanceof Dialog ) { 4136 ((Dialog )this).interruptBlocking(); 4137 } else { 4138 windowClosingException.fillInStackTrace(); 4139 windowClosingException.printStackTrace(); 4140 windowClosingException = null; 4141 } 4142 return true; 4143 } 4144 return false; 4145 } 4146 4147 boolean areInputMethodsEnabled() { 4148 return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) && 4152 ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null); 4153 } 4154 4155 boolean eventEnabled(AWTEvent e) { 4157 return eventTypeEnabled(e.id); 4158 } 4159 4160 boolean eventTypeEnabled(int type) { 4161 switch(type) { 4162 case ComponentEvent.COMPONENT_MOVED: 4163 case ComponentEvent.COMPONENT_RESIZED: 4164 case ComponentEvent.COMPONENT_SHOWN: 4165 case ComponentEvent.COMPONENT_HIDDEN: 4166 if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 || 4167 componentListener != null) { 4168 return true; 4169 } 4170 break; 4171 case FocusEvent.FOCUS_GAINED: 4172 case FocusEvent.FOCUS_LOST: 4173 if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 || 4174 focusListener != null) { 4175 return true; 4176 } 4177 break; 4178 case KeyEvent.KEY_PRESSED: 4179 case KeyEvent.KEY_RELEASED: 4180 case KeyEvent.KEY_TYPED: 4181 if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || 4182 keyListener != null) { 4183 return true; 4184 } 4185 break; 4186 case MouseEvent.MOUSE_PRESSED: 4187 case MouseEvent.MOUSE_RELEASED: 4188 case MouseEvent.MOUSE_ENTERED: 4189 case MouseEvent.MOUSE_EXITED: 4190 case MouseEvent.MOUSE_CLICKED: 4191 if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 || 4192 mouseListener != null) { 4193 return true; 4194 } 4195 break; 4196 case MouseEvent.MOUSE_MOVED: 4197 case MouseEvent.MOUSE_DRAGGED: 4198 if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 || 4199 mouseMotionListener != null) { 4200 return true; 4201 } 4202 break; 4203 case MouseEvent.MOUSE_WHEEL: 4204 if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 || 4205 mouseWheelListener != null) { 4206 return true; 4207 } 4208 break; 4209 case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: 4210 case InputMethodEvent.CARET_POSITION_CHANGED: 4211 if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 || 4212 inputMethodListener != null) { 4213 return true; 4214 } 4215 break; 4216 case HierarchyEvent.HIERARCHY_CHANGED: 4217 if ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || 4218 hierarchyListener != null) { 4219 return true; 4220 } 4221 break; 4222 case HierarchyEvent.ANCESTOR_MOVED: 4223 case HierarchyEvent.ANCESTOR_RESIZED: 4224 if ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 || 4225 hierarchyBoundsListener != null) { 4226 return true; 4227 } 4228 break; 4229 case ActionEvent.ACTION_PERFORMED: 4230 if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0) { 4231 return true; 4232 } 4233 break; 4234 case TextEvent.TEXT_VALUE_CHANGED: 4235 if ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0) { 4236 return true; 4237 } 4238 break; 4239 case ItemEvent.ITEM_STATE_CHANGED: 4240 if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0) { 4241 return true; 4242 } 4243 break; 4244 case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: 4245 if ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0) { 4246 return true; 4247 } 4248 break; 4249 default: 4250 break; 4251 } 4252 if (type > AWTEvent.RESERVED_ID_MAX) { 4256 return true; 4257 } 4258 return false; 4259 } 4260 4261 4265 @Deprecated 4266 public boolean postEvent(Event e) { 4267 ComponentPeer peer = this.peer; 4268 4269 if (handleEvent(e)) { 4270 e.consume(); 4271 return true; 4272 } 4273 4274 Component parent = this.parent; 4275 int eventx = e.x; 4276 int eventy = e.y; 4277 if (parent != null) { 4278 e.translate(x, y); 4279 if (parent.postEvent(e)) { 4280 e.consume(); 4281 return true; 4282 } 4283 e.x = eventx; 4285 e.y = eventy; 4286 } 4287 return false; 4288 } 4289 4290 4292 4305 public synchronized void addComponentListener(ComponentListener l) { 4306 if (l == null) { 4307 return; 4308 } 4309 componentListener = AWTEventMulticaster.add(componentListener, l); 4310 newEventsOnly = true; 4311 } 4312 4313 4327 public synchronized void removeComponentListener(ComponentListener l) { 4328 if (l == null) { 4329 return; 4330 } 4331 componentListener = AWTEventMulticaster.remove(componentListener, l); 4332 } 4333 4334 4346 public synchronized ComponentListener[] getComponentListeners() { 4347 return (ComponentListener[]) (getListeners(ComponentListener.class)); 4348 } 4349 4350 4363 public synchronized void addFocusListener(FocusListener l) { 4364 if (l == null) { 4365 return; 4366 } 4367 focusListener = AWTEventMulticaster.add(focusListener, l); 4368 newEventsOnly = true; 4369 4370 if (peer instanceof LightweightPeer) { 4373 parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK); 4374 } 4375 } 4376 4377 4392 public synchronized void removeFocusListener(FocusListener l) { 4393 if (l == null) { 4394 return; 4395 } 4396 focusListener = AWTEventMulticaster.remove(focusListener, l); 4397 } 4398 4399 4411 public synchronized FocusListener[] getFocusListeners() { 4412 return (FocusListener[]) (getListeners(FocusListener.class)); 4413 } 4414 4415 4429 public void addHierarchyListener(HierarchyListener l) { 4430 if (l == null) { 4431 return; 4432 } 4433 boolean notifyAncestors; 4434 synchronized (this) { 4435 notifyAncestors = 4436 (hierarchyListener == null && 4437 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0); 4438 hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l); 4439 notifyAncestors = (notifyAncestors && hierarchyListener != null); 4440 newEventsOnly = true; 4441 } 4442 if (notifyAncestors) { 4443 synchronized (getTreeLock()) { 4444 adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK, 4445 1); 4446 } 4447 } 4448 } 4449 4450 4465 public void removeHierarchyListener(HierarchyListener l) { 4466 if (l == null) { 4467 return; 4468 } 4469 boolean notifyAncestors; 4470 synchronized (this) { 4471 notifyAncestors = 4472 (hierarchyListener != null && 4473 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0); 4474 hierarchyListener = 4475 AWTEventMulticaster.remove(hierarchyListener, l); 4476 notifyAncestors = (notifyAncestors && hierarchyListener == null); 4477 } 4478 if (notifyAncestors) { 4479 synchronized (getTreeLock()) { 4480 adjustListeningChildrenOnParent(AWTEvent.HIERARCHY_EVENT_MASK, 4481 -1); 4482 } 4483 } 4484 } 4485 4486 4498 public synchronized HierarchyListener[] getHierarchyListeners() { 4499 return (HierarchyListener[])(getListeners(HierarchyListener.class)); 4500 } 4501 4502 4516 public void addHierarchyBoundsListener(HierarchyBoundsListener l) { 4517 if (l == null) { 4518 return; 4519 } 4520 boolean notifyAncestors; 4521 synchronized (this) { 4522 notifyAncestors = 4523 (hierarchyBoundsListener == null && 4524 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0); 4525 hierarchyBoundsListener = 4526 AWTEventMulticaster.add(hierarchyBoundsListener, l); 4527 notifyAncestors = (notifyAncestors && 4528 hierarchyBoundsListener != null); 4529 newEventsOnly = true; 4530 } 4531 if (notifyAncestors) { 4532 synchronized (getTreeLock()) { 4533 adjustListeningChildrenOnParent( 4534 AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1); 4535 } 4536 } 4537 } 4538 4539 4554 public void removeHierarchyBoundsListener(HierarchyBoundsListener l) { 4555 if (l == null) { 4556 return; 4557 } 4558 boolean notifyAncestors; 4559 synchronized (this) { 4560 notifyAncestors = 4561 (hierarchyBoundsListener != null && 4562 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0); 4563 hierarchyBoundsListener = 4564 AWTEventMulticaster.remove(hierarchyBoundsListener, l); 4565 notifyAncestors = (notifyAncestors && 4566 hierarchyBoundsListener == null); 4567 } 4568 if (notifyAncestors) { 4569 synchronized (getTreeLock()) { 4570 adjustListeningChildrenOnParent( 4571 AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, -1); 4572 } 4573 } 4574 } 4575 4576 int numListening(long mask) { 4578 if (dbg.on) { 4579 dbg.assertion(mask == AWTEvent.HIERARCHY_EVENT_MASK || 4581 mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); 4582 } 4583 if ((mask == AWTEvent.HIERARCHY_EVENT_MASK && 4584 (hierarchyListener != null || 4585 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) || 4586 (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK && 4587 (hierarchyBoundsListener != null || 4588 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0))) { 4589 return 1; 4590 } else { 4591 return 0; 4592 } 4593 } 4594 4595 int countHierarchyMembers() { 4597 return 1; 4598 } 4599 int createHierarchyEvents(int id, Component changed, 4601 Container changedParent, long changeFlags, 4602 boolean enabledOnToolkit) { 4603 switch (id) { 4604 case HierarchyEvent.HIERARCHY_CHANGED: 4605 if (hierarchyListener != null || 4606 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || 4607 enabledOnToolkit) { 4608 HierarchyEvent e = new HierarchyEvent(this, id, changed, 4609 changedParent, 4610 changeFlags); 4611 dispatchEvent(e); 4612 return 1; 4613 } 4614 break; 4615 case HierarchyEvent.ANCESTOR_MOVED: 4616 case HierarchyEvent.ANCESTOR_RESIZED: 4617 if (dbg.on) { 4618 dbg.assertion(changeFlags == 0); 4619 } 4620 if (hierarchyBoundsListener != null || 4621 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 || 4622 enabledOnToolkit) { 4623 HierarchyEvent e = new HierarchyEvent(this, id, changed, 4624 changedParent); 4625 dispatchEvent(e); 4626 return 1; 4627 } 4628 break; 4629 default: 4630 if (dbg.on) { 4631 dbg.assertion(false); 4632 } 4633 break; 4634 } 4635 return 0; 4636 } 4637 4638 4650 public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners() { 4651 return (HierarchyBoundsListener[]) 4652 (getListeners(HierarchyBoundsListener.class)); 4653 } 4654 4655 4660 void adjustListeningChildrenOnParent(long mask, int num) { 4661 if (parent != null) { 4662 parent.adjustListeningChildren(mask, num); 4663 } 4664 } 4665 4666 4678 public synchronized void addKeyListener(KeyListener l) { 4679 if (l == null) { 4680 return; 4681 } 4682 keyListener = AWTEventMulticaster.add(keyListener, l); 4683 newEventsOnly = true; 4684 4685 if (peer instanceof LightweightPeer) { 4688 parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK); 4689 } 4690 } 4691 4692 4707 public synchronized void removeKeyListener(KeyListener l) { 4708 if (l == null) { 4709 return; 4710 } 4711 keyListener = AWTEventMulticaster.remove(keyListener, l); 4712 } 4713 4714 4726 public synchronized KeyListener[] getKeyListeners() { 4727 return (KeyListener[]) (getListeners(KeyListener.class)); 4728 } 4729 4730 4743 public synchronized void addMouseListener(MouseListener l) { 4744 if (l == null) { 4745 return; 4746 } 4747 mouseListener = AWTEventMulticaster.add(mouseListener,l); 4748 newEventsOnly = true; 4749 4750 if (peer instanceof LightweightPeer) { 4753 parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK); 4754 } 4755 } 4756 4757 4772 public synchronized void removeMouseListener(MouseListener l) { 4773 if (l == null) { 4774 return; 4775 } 4776 mouseListener = AWTEventMulticaster.remove(mouseListener, l); 4777 } 4778 4779 4791 public synchronized MouseListener[] getMouseListeners() { 4792 return (MouseListener[]) (getListeners(MouseListener.class)); 4793 } 4794 4795 4808 public synchronized void addMouseMotionListener(MouseMotionListener l) { 4809 if (l == null) { 4810 return; 4811 } 4812 mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l); 4813 newEventsOnly = true; 4814 4815 if (peer instanceof LightweightPeer) { 4818 parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); 4819 } 4820 } 4821 4822 4837 public synchronized void removeMouseMotionListener(MouseMotionListener l) { 4838 if (l == null) { 4839 return; 4840 } 4841 mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l); 4842 } 4843 4844 4856 public synchronized MouseMotionListener[] getMouseMotionListeners() { 4857 return (MouseMotionListener[]) (getListeners(MouseMotionListener.class)); 4858 } 4859 4860 4878 public synchronized void addMouseWheelListener(MouseWheelListener l) { 4879 if (l == null) { 4880 return; 4881 } 4882 mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener,l); 4883 newEventsOnly = true; 4884 4885 dbg.println("Component.addMouseWheelListener(): newEventsOnly = " + newEventsOnly); 4886 4887 if (peer instanceof LightweightPeer) { 4890 parent.proxyEnableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK); 4891 } 4892 } 4893 4894 4908 public synchronized void removeMouseWheelListener(MouseWheelListener l) { 4909 if (l == null) { 4910 return; 4911 } 4912 mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l); 4913 } 4914 4915 4927 public synchronized MouseWheelListener[] getMouseWheelListeners() { 4928 return (MouseWheelListener[]) (getListeners(MouseWheelListener.class)); 4929 } 4930 4931 4948 public synchronized void addInputMethodListener(InputMethodListener l) { 4949 if (l == null) { 4950 return; 4951 } 4952 inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l); 4953 newEventsOnly = true; 4954 } 4955 4956 4971 public synchronized void removeInputMethodListener(InputMethodListener l) { 4972 if (l == null) { 4973 return; 4974 } 4975 inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l); 4976 } 4977 4978 4990 public synchronized InputMethodListener [] getInputMethodListeners() { 4991 return (InputMethodListener []) (getListeners(InputMethodListener .class)); 4992 } 4993 4994 5036 public <T extends EventListener > T[] getListeners(Class <T> listenerType) { 5037 EventListener l = null; 5038 if (listenerType == ComponentListener.class) { 5039 l = componentListener; 5040 } else if (listenerType == FocusListener.class) { 5041 l = focusListener; 5042 } else if (listenerType == HierarchyListener.class) { 5043 l = hierarchyListener; 5044 } else if (listenerType == HierarchyBoundsListener.class) { 5045 l = hierarchyBoundsListener; 5046 } else if (listenerType == KeyListener.class) { 5047 l = keyListener; 5048 } else if (listenerType == MouseListener.class) { 5049 l = mouseListener; 5050 } else if (listenerType == MouseMotionListener.class) { 5051 l = mouseMotionListener; 5052 } else if (listenerType == MouseWheelListener.class) { 5053 l = mouseWheelListener; 5054 } else if (listenerType == InputMethodListener .class) { 5055 l = inputMethodListener; 5056 } else if (listenerType == PropertyChangeListener .class) { 5057 return (T[])getPropertyChangeListeners(); 5058 } 5059 return AWTEventMulticaster.getListeners(l, listenerType); 5060 } 5061 5062 5074 public InputMethodRequests getInputMethodRequests() { 5075 return null; 5076 } 5077 5078 5089 public InputContext getInputContext() { 5090 Container parent = this.parent; 5091 if (parent == null) { 5092 return null; 5093 } else { 5094 return parent.getInputContext(); 5095 } 5096 } 5097 5098 5115 protected final void enableEvents(long eventsToEnable) { 5116 long notifyAncestors = 0; 5117 synchronized (this) { 5118 if ((eventsToEnable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && 5119 hierarchyListener == null && 5120 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) == 0) { 5121 notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK; 5122 } 5123 if ((eventsToEnable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 && 5124 hierarchyBoundsListener == null && 5125 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) == 0) { 5126 notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK; 5127 } 5128 eventMask |= eventsToEnable; 5129 newEventsOnly = true; 5130 } 5131 5132 if (peer instanceof LightweightPeer) { 5135 parent.proxyEnableEvents(eventMask); 5136 } 5137 if (notifyAncestors != 0) { 5138 synchronized (getTreeLock()) { 5139 adjustListeningChildrenOnParent(notifyAncestors, 1); 5140 } 5141 } 5142 } 5143 5144 5151 protected final void disableEvents(long eventsToDisable) { 5152 long notifyAncestors = 0; 5153 synchronized (this) { 5154 if ((eventsToDisable & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && 5155 hierarchyListener == null && 5156 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0) { 5157 notifyAncestors |= AWTEvent.HIERARCHY_EVENT_MASK; 5158 } 5159 if ((eventsToDisable & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK)!=0 && 5160 hierarchyBoundsListener == null && 5161 (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0) { 5162 notifyAncestors |= AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK; 5163 } 5164 eventMask &= ~eventsToDisable; 5165 } 5166 if (notifyAncestors != 0) { 5167 synchronized (getTreeLock()) { 5168 adjustListeningChildrenOnParent(notifyAncestors, -1); 5169 } 5170 } 5171 } 5172 5173 5199 protected AWTEvent coalesceEvents(AWTEvent existingEvent, 5200 AWTEvent newEvent) { 5201 int id = existingEvent.getID(); 5202 if (dbg.on) { 5203 dbg.assertion(id == newEvent.getID() && 5204 existingEvent.getSource().equals(newEvent.getSource())); 5205 } 5206 5207 switch (id) { 5208 case Event.MOUSE_MOVE: 5209 case Event.MOUSE_DRAG: { 5210 MouseEvent e = (MouseEvent)existingEvent; 5211 if (e.getModifiers() == ((MouseEvent)newEvent).getModifiers()) { 5212 return newEvent; 5215 } 5216 break; 5217 } 5218 case PaintEvent.PAINT: 5219 case PaintEvent.UPDATE: { 5220 if(peer != null && !(peer instanceof LightweightPeer)) { 5221 return newEvent; 5223 } 5224 PaintEvent existingPaintEvent = (PaintEvent) existingEvent; 5227 PaintEvent newPaintEvent = (PaintEvent) newEvent; 5228 Rectangle existingRect = existingPaintEvent.getUpdateRect(); 5229 Rectangle newRect = newPaintEvent.getUpdateRect(); 5230 5231 if (dbg.on) { 5232 dbg.println("Component::coalesceEvents : newEvent : nullPeer : x = " + 5233 newRect.x + " y = " + newRect.y + " width = " + newRect.width + 5234 " height = " + newRect.height); 5235 } 5236 5237 if (existingRect.contains(newRect)) { 5238 return existingEvent; 5239 } 5240 if (newRect.contains(existingRect)) { 5241 return newEvent; 5242 } 5243 5244 break; 5245 } 5246 } 5247 5248 return null; 5249 } 5250 5251 5271 protected void processEvent(AWTEvent e) { 5272 if (e instanceof FocusEvent) { 5273 processFocusEvent((FocusEvent)e); 5274 5275 } else if (e instanceof MouseEvent) { 5276 switch(e.getID()) { 5277 case MouseEvent.MOUSE_PRESSED: 5278 case MouseEvent.MOUSE_RELEASED: 5279 case MouseEvent.MOUSE_CLICKED: 5280 case MouseEvent.MOUSE_ENTERED: 5281 case MouseEvent.MOUSE_EXITED: 5282 processMouseEvent((MouseEvent)e); 5283 break; 5284 case MouseEvent.MOUSE_MOVED: 5285 case MouseEvent.MOUSE_DRAGGED: 5286 processMouseMotionEvent((MouseEvent)e); 5287 break; 5288 case MouseEvent.MOUSE_WHEEL: 5289 processMouseWheelEvent((MouseWheelEvent)e); 5290 break; 5291 } 5292 5293 } else if (e instanceof KeyEvent) { 5294 processKeyEvent((KeyEvent)e); 5295 5296 } else if (e instanceof ComponentEvent) { 5297 processComponentEvent((ComponentEvent)e); 5298 } else if (e instanceof InputMethodEvent ) { 5299 processInputMethodEvent((InputMethodEvent )e); 5300 } else if (e instanceof HierarchyEvent) { 5301 switch (e.getID()) { 5302 case HierarchyEvent.HIERARCHY_CHANGED: 5303 processHierarchyEvent((HierarchyEvent)e); 5304 break; 5305 case HierarchyEvent.ANCESTOR_MOVED: 5306 case HierarchyEvent.ANCESTOR_RESIZED: 5307 processHierarchyBoundsEvent((HierarchyEvent)e); 5308 break; 5309 } 5310 } 5311 } 5312 5313 5337 protected void processComponentEvent(ComponentEvent e) { 5338 ComponentListener listener = componentListener; 5339 if (listener != null) { 5340 int id = e.getID(); 5341 switch(id) { 5342 case ComponentEvent.COMPONENT_RESIZED: 5343 listener.componentResized(e); 5344 break; 5345 case ComponentEvent.COMPONENT_MOVED: 5346 listener.componentMoved(e); 5347 break; 5348 case ComponentEvent.COMPONENT_SHOWN: 5349 listener.componentShown(e); 5350 break; 5351 case ComponentEvent.COMPONENT_HIDDEN: 5352 listener.componentHidden(e); 5353 break; 5354 } 5355 } 5356 } 5357 5358 5400 protected void processFocusEvent(FocusEvent e) { 5401 FocusListener listener = focusListener; 5402 if (listener != null) { 5403 int id = e.getID(); 5404 switch(id) { 5405 case FocusEvent.FOCUS_GAINED: 5406 listener.focusGained(e); 5407 break; 5408 case FocusEvent.FOCUS_LOST: 5409 listener.focusLost(e); 5410 break; 5411 } 5412 } 5413 } 5414 5415 5466 protected void processKeyEvent(KeyEvent e) { 5467 KeyListener listener = keyListener; 5468 if (listener != null) { 5469 int id = e.getID(); 5470 switch(id) { 5471 case KeyEvent.KEY_TYPED: 5472 listener.keyTyped(e); 5473 break; 5474 case KeyEvent.KEY_PRESSED: 5475 listener.keyPressed(e); 5476 break; 5477 case KeyEvent.KEY_RELEASED: 5478 listener.keyReleased(e); 5479 break; 5480 } 5481 } 5482 } 5483 5484 5508 protected void processMouseEvent(MouseEvent e) { 5509 MouseListener listener = mouseListener; 5510 if (listener != null) { 5511 int id = e.getID(); 5512 switch(id) { 5513 case MouseEvent.MOUSE_PRESSED: 5514 listener.mousePressed(e); 5515 break; 5516 case MouseEvent.MOUSE_RELEASED: 5517 listener.mouseReleased(e); 5518 break; 5519 case MouseEvent.MOUSE_CLICKED: 5520 listener.mouseClicked(e); 5521 break; 5522 case MouseEvent.MOUSE_EXITED: 5523 listener.mouseExited(e); 5524 break; 5525 case MouseEvent.MOUSE_ENTERED: 5526 listener.mouseEntered(e); 5527 break; 5528 } 5529 } 5530 } 5531 5532 5556 protected void processMouseMotionEvent(MouseEvent e) { 5557 MouseMotionListener listener = mouseMotionListener; 5558 if (listener != null) { 5559 int id = e.getID(); 5560 switch(id) { 5561 case MouseEvent.MOUSE_MOVED: 5562 listener.mouseMoved(e); 5563 break; 5564 case MouseEvent.MOUSE_DRAGGED: 5565 listener.mouseDragged(e); 5566 break; 5567 } 5568 } 5569 } 5570 5571 5599 protected void processMouseWheelEvent(MouseWheelEvent e) { 5600 MouseWheelListener listener = mouseWheelListener; 5601 if (listener != null) { 5602 int id = e.getID(); 5603 switch(id) { 5604 case MouseEvent.MOUSE_WHEEL: 5605 listener.mouseWheelMoved(e); 5606 break; 5607 } 5608 } 5609 } 5610 5611 boolean postsOldMouseEvents() { 5612 return false; 5613 } 5614 5615 5639 protected void processInputMethodEvent(InputMethodEvent e) { 5640 InputMethodListener listener = inputMethodListener; 5641 if (listener != null) { 5642 int id = e.getID(); 5643 switch (id) { 5644 case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: 5645 listener.inputMethodTextChanged(e); 5646 break; 5647 case InputMethodEvent.CARET_POSITION_CHANGED: 5648 listener.caretPositionChanged(e); 5649 break; 5650 } 5651 } 5652 } 5653 5654 5678 protected void processHierarchyEvent(HierarchyEvent e) { 5679 HierarchyListener listener = hierarchyListener; 5680 if (listener != null) { 5681 int id = e.getID(); 5682 switch (id) { 5683 case HierarchyEvent.HIERARCHY_CHANGED: 5684 listener.hierarchyChanged(e); 5685 break; 5686 } 5687 } 5688 } 5689 5690 5714 protected void processHierarchyBoundsEvent(HierarchyEvent e) { 5715 HierarchyBoundsListener listener = hierarchyBoundsListener; 5716 if (listener != null) { 5717 int id = e.getID(); 5718 switch (id) { 5719 case HierarchyEvent.ANCESTOR_MOVED: 5720 listener.ancestorMoved(e); 5721 break; 5722 case HierarchyEvent.ANCESTOR_RESIZED: 5723 listener.ancestorResized(e); 5724 break; 5725 } 5726 } 5727 } 5728 5729 5733 @Deprecated 5734 public boolean handleEvent(Event evt) { 5735 switch (evt.id) { 5736 case Event.MOUSE_ENTER: 5737 return mouseEnter(evt, evt.x, evt.y); 5738 5739 case Event.MOUSE_EXIT: 5740 return mouseExit(evt, evt.x, evt.y); 5741 5742 case Event.MOUSE_MOVE: 5743 return mouseMove(evt, evt.x, evt.y); 5744 5745 case Event.MOUSE_DOWN: 5746 return mouseDown(evt, evt.x, evt.y); 5747 5748 case Event.MOUSE_DRAG: 5749 return mouseDrag(evt, evt.x, evt.y); 5750 5751 case Event.MOUSE_UP: 5752 return mouseUp(evt, evt.x, evt.y); 5753 5754 case Event.KEY_PRESS: 5755 case Event.KEY_ACTION: 5756 return keyDown(evt, evt.key); 5757 5758 case Event.KEY_RELEASE: 5759 case Event.KEY_ACTION_RELEASE: 5760 return keyUp(evt, evt.key); 5761 5762 case Event.ACTION_EVENT: 5763 return action(evt, evt.arg); 5764 case Event.GOT_FOCUS: 5765 return gotFocus(evt, evt.arg); 5766 case Event.LOST_FOCUS: 5767 return lostFocus(evt, evt.arg); 5768 } 5769 return false; 5770 } 5771 5772 5776 @Deprecated 5777 public boolean mouseDown(Event evt, int x, int y) { 5778 return false; 5779 } 5780 5781 5785 @Deprecated 5786 public boolean mouseDrag(Event evt, int x, int y) { 5787 return false; 5788 } 5789 5790 5794 @Deprecated 5795 public boolean mouseUp(Event evt, int x, int y) { 5796 return false; 5797 } 5798 5799 5803 @Deprecated 5804 public boolean mouseMove(Event evt, int x, int y) { 5805 return false; 5806 } 5807 5808 5812 @Deprecated 5813 public boolean mouseEnter(Event evt, int x, int y) { 5814 return false; 5815 } 5816 5817 5821 @Deprecated 5822 public boolean mouseExit(Event evt, int x, int y) { 5823 return false; 5824 } 5825 5826 5830 @Deprecated 5831 public boolean keyDown(Event evt, int key) { 5832 return false; 5833 } 5834 5835 5839 @Deprecated 5840 public boolean keyUp(Event evt, int key) { 5841 return false; 5842 } 5843 5844 5849 @Deprecated 5850 public boolean action(Event evt, Object what) { 5851 return false; 5852 } 5853 5854 5863 public void addNotify() { 5864 synchronized (getTreeLock()) { 5865 ComponentPeer peer = this.peer; 5866 if (peer == null || peer instanceof LightweightPeer){ 5867 if (peer == null) { 5868 this.peer = peer = getToolkit().createComponent(this); 5871 } 5872 5873 if (parent != null) { 5878 long mask = 0; 5879 if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) { 5880 mask |= AWTEvent.MOUSE_EVENT_MASK; 5881 } 5882 if ((mouseMotionListener != null) || 5883 ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) { 5884 mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK; 5885 } 5886 if ((mouseWheelListener != null ) || 5887 ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0)) { 5888 mask |= AWTEvent.MOUSE_WHEEL_EVENT_MASK; 5889 } 5890 if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) { 5891 mask |= AWTEvent.FOCUS_EVENT_MASK; 5892 } 5893 if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) { 5894 mask |= AWTEvent.KEY_EVENT_MASK; 5895 } 5896 if (mask != 0) { 5897 parent.proxyEnableEvents(mask); 5898 } 5899 } 5900 } else { 5901 Container parent = this.parent; 5904 if (parent != null && parent.peer instanceof LightweightPeer) { 5905 nativeInLightFixer = new NativeInLightFixer(); 5906 } 5907 } 5908 invalidate(); 5909 5910 int npopups = (popups != null? popups.size() : 0); 5911 for (int i = 0 ; i < npopups ; i++) { 5912 PopupMenu popup = (PopupMenu )popups.elementAt(i); 5913 popup.addNotify(); 5914 } 5915 5916 if (dropTarget != null) dropTarget.addNotify(peer); 5917 5918 peerFont = getFont(); 5919 5920 if (parent != null && parent.peer != null) { 5922 ContainerPeer parentContPeer = (ContainerPeer) parent.peer; 5923 if (parentContPeer instanceof LightweightPeer 5927 && ! (peer instanceof LightweightPeer)) 5928 { 5929 Container hwParent = getNativeContainer(); 5930 if (hwParent != null && hwParent.peer != null) { 5931 parentContPeer = (ContainerPeer) hwParent.peer; 5932 } 5933 } 5934 if (parentContPeer.isRestackSupported()) { 5935 parentContPeer.restack(); 5936 } 5937 } 5938 5939 if (hierarchyListener != null || 5940 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || 5941 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) { 5942 HierarchyEvent e = 5943 new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED, 5944 this, parent, 5945 HierarchyEvent.DISPLAYABILITY_CHANGED | 5946 ((isRecursivelyVisible()) 5947 ? HierarchyEvent.SHOWING_CHANGED 5948 : 0)); 5949 dispatchEvent(e); 5950 } 5951 } 5952 } 5953 5954 5967 public void removeNotify() { 5968 KeyboardFocusManager.clearMostRecentFocusOwner(this); 5969 if (KeyboardFocusManager.getCurrentKeyboardFocusManager(). 5970 getPermanentFocusOwner() == this) 5971 { 5972 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 5973 setGlobalPermanentFocusOwner(null); 5974 } 5975 5976 synchronized (getTreeLock()) { 5977 if (isFocusOwner() && !nextFocusHelper()) { 5978 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 5979 clearGlobalFocusOwner(); 5980 } 5981 5982 int npopups = (popups != null? popups.size() : 0); 5983 for (int i = 0 ; i < npopups ; i++) { 5984 PopupMenu popup = (PopupMenu )popups.elementAt(i); 5985 popup.removeNotify(); 5986 } 5987 if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) { 5991 InputContext inputContext = getInputContext(); 5992 if (inputContext != null) { 5993 inputContext.removeNotify(this); 5994 } 5995 } 5996 5997 ComponentPeer p = peer; 5998 if (p != null) { 5999 6000 if (bufferStrategy instanceof FlipBufferStrategy) { 6001 ((FlipBufferStrategy)bufferStrategy).destroyBuffers(); 6002 } 6003 6004 if (dropTarget != null) dropTarget.removeNotify(peer); 6005 6006 if (visible) { 6008 p.hide(); 6009 } 6010 6011 peer = null; peerFont = null; 6013 6014 Toolkit.getEventQueue().removeSourceEvents(this, false); 6015 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 6016 discardKeyEvents(this); 6017 6018 p.dispose(); 6019 } 6020 6021 if (hierarchyListener != null || 6022 (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 || 6023 Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK)) { 6024 HierarchyEvent e = 6025 new HierarchyEvent(this, HierarchyEvent.HIERARCHY_CHANGED, 6026 this, parent, 6027 HierarchyEvent.DISPLAYABILITY_CHANGED | 6028 ((isRecursivelyVisible()) 6029 ? HierarchyEvent.SHOWING_CHANGED 6030 : 0)); 6031 dispatchEvent(e); 6032 } 6033 } 6034 } 6035 6036 6040 @Deprecated 6041 public boolean gotFocus(Event evt, Object what) { 6042 return false; 6043 } 6044 6045 6049 @Deprecated 6050 public boolean lostFocus(Event evt, Object what) { 6051 return false; 6052 } 6053 6054 6064 @Deprecated 6065 public boolean isFocusTraversable() { 6066 if (isFocusTraversableOverridden == FOCUS_TRAVERSABLE_UNKNOWN) { 6067 isFocusTraversableOverridden = FOCUS_TRAVERSABLE_DEFAULT; 6068 } 6069 return focusable; 6070 } 6071 6072 6080 public boolean isFocusable() { 6081 return isFocusTraversable(); 6082 } 6083 6084 6094 public void setFocusable(boolean focusable) { 6095 boolean oldFocusable; 6096 synchronized (this) { 6097 oldFocusable = this.focusable; 6098 this.focusable = focusable; 6099 } 6100 isFocusTraversableOverridden = FOCUS_TRAVERSABLE_SET; 6101 6102 firePropertyChange("focusable", oldFocusable, focusable); 6103 if (oldFocusable && !focusable) { 6104 if (isFocusOwner()) { 6105 autoTransferFocus(true); 6106 } 6107 KeyboardFocusManager.clearMostRecentFocusOwner(this); 6108 } 6109 } 6110 6111 final boolean isFocusTraversableOverridden() { 6112 return (isFocusTraversableOverridden != FOCUS_TRAVERSABLE_DEFAULT); 6113 } 6114 6115 6185 public void setFocusTraversalKeys(int id, 6186 Set <? extends AWTKeyStroke > keystrokes) 6187 { 6188 if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) { 6189 throw new IllegalArgumentException ("invalid focus traversal key identifier"); 6190 } 6191 6192 setFocusTraversalKeys_NoIDCheck(id, keystrokes); 6193 } 6194 6195 6221 public Set <AWTKeyStroke > getFocusTraversalKeys(int id) { 6222 if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) { 6223 throw new IllegalArgumentException ("invalid focus traversal key identifier"); 6224 } 6225 6226 return getFocusTraversalKeys_NoIDCheck(id); 6227 } 6228 6229 final void setFocusTraversalKeys_NoIDCheck(int id, Set keystrokes) { 6235 Set oldKeys; 6236 6237 synchronized (this) { 6238 if (focusTraversalKeys == null) { 6239 initializeFocusTraversalKeys(); 6240 } 6241 6242 if (keystrokes != null) { 6243 for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) { 6244 Object obj = iter.next(); 6245 6246 if (obj == null) { 6247 throw new IllegalArgumentException ("cannot set null focus traversal key"); 6248 } 6249 6250 AWTKeyStroke keystroke = (AWTKeyStroke )obj; 6253 6254 if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) { 6255 throw new IllegalArgumentException ("focus traversal keys cannot map to KEY_TYPED events"); 6256 } 6257 6258 for (int i = 0; i < focusTraversalKeys.length; i++) { 6259 if (i == id) { 6260 continue; 6261 } 6262 6263 if (getFocusTraversalKeys_NoIDCheck(i).contains(keystroke)) 6264 { 6265 throw new IllegalArgumentException ("focus traversal keys must be unique for a Component"); 6266 } 6267 } 6268 } 6269 } 6270 6271 oldKeys = focusTraversalKeys[id]; 6272 focusTraversalKeys[id] = (keystrokes != null) 6273 ? Collections.unmodifiableSet(new HashSet (keystrokes)) 6274 : null; 6275 } 6276 6277 firePropertyChange(focusTraversalKeyPropertyNames[id], oldKeys, 6278 keystrokes); 6279 } 6280 final Set getFocusTraversalKeys_NoIDCheck(int id) { 6281 Set keystrokes = (focusTraversalKeys != null) 6283 ? focusTraversalKeys[id] 6284 : null; 6285 6286 if (keystrokes != null) { 6287 return keystrokes; 6288 } else { 6289 Container parent = this.parent; 6290 if (parent != null) { 6291 return parent.getFocusTraversalKeys(id); 6292 } else { 6293 return KeyboardFocusManager.getCurrentKeyboardFocusManager(). 6294 getDefaultFocusTraversalKeys(id); 6295 } 6296 } 6297 } 6298 6299 6317 public boolean areFocusTraversalKeysSet(int id) { 6318 if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH - 1) { 6319 throw new IllegalArgumentException ("invalid focus traversal key identifier"); 6320 } 6321 6322 return (focusTraversalKeys != null && focusTraversalKeys[id] != null); 6323 } 6324 6325 6341 public void setFocusTraversalKeysEnabled(boolean 6342 focusTraversalKeysEnabled) { 6343 boolean oldFocusTraversalKeysEnabled; 6344 synchronized (this) { 6345 oldFocusTraversalKeysEnabled = this.focusTraversalKeysEnabled; 6346 this.focusTraversalKeysEnabled = focusTraversalKeysEnabled; 6347 } 6348 firePropertyChange("focusTraversalKeysEnabled", 6349 oldFocusTraversalKeysEnabled, 6350 focusTraversalKeysEnabled); 6351 } 6352 6353 6366 public boolean getFocusTraversalKeysEnabled() { 6367 return focusTraversalKeysEnabled; 6368 } 6369 6370 6398 public void requestFocus() { 6399 requestFocusHelper(false, true); 6400 } 6401 6402 6455 protected boolean requestFocus(boolean temporary) { 6456 return requestFocusHelper(temporary, true); 6457 } 6458 6459 6496 public boolean requestFocusInWindow() { 6497 return requestFocusHelper(false, false); 6498 } 6499 6500 6552 protected boolean requestFocusInWindow(boolean temporary) { 6553 return requestFocusHelper(temporary, false); 6554 } 6555 6556 final boolean requestFocusHelper(boolean temporary, 6557 boolean focusedWindowChangeAllowed) { 6558 if (isFocusable() && isVisible()) { 6559 ComponentPeer peer = this.peer; 6560 if (peer != null) { 6561 boolean recursivelyInvisible = false; 6562 Component window = this; 6563 while (!(window instanceof Window )) { 6564 if (!window.isVisible()) { 6565 recursivelyInvisible = true; 6566 } 6567 window = window.parent; 6568 } 6569 if (window == null || !((Window )window).isFocusableWindow()) { 6570 focusLog.finest("FAIL 1"); 6571 return false; 6572 } 6573 6574 KeyboardFocusManager.setMostRecentFocusOwner(this); 6576 6577 if (recursivelyInvisible) { 6578 focusLog.finest("FAIL 1.5"); 6579 return false; 6580 } 6581 6582 Component heavyweight = (peer instanceof LightweightPeer) 6583 ? getNativeContainer() : this; 6584 if (heavyweight == null || !heavyweight.isVisible()) { 6585 focusLog.finest("FAIL 2"); 6586 return false; 6587 } 6588 peer = heavyweight.peer; 6589 if (peer == null) { 6590 focusLog.finest("FAIL 3"); 6591 return false; 6592 } 6593 6594 long time = EventQueue.getMostRecentEventTime(); 6596 boolean success = peer.requestFocus 6597 (this, temporary, focusedWindowChangeAllowed, time); 6598 if (!success) { 6599 KeyboardFocusManager.getCurrentKeyboardFocusManager 6600 (appContext).dequeueKeyEvents(time, this); 6601 focusLog.finest("FAIL 4"); 6602 } else { 6603 if (focusLog.isLoggable(Level.FINEST)) focusLog.finest("Pass for " + this); 6604 } 6605 return success; 6606 } 6607 } 6608 focusLog.finest("FAIL 5"); 6609 return false; 6610 } 6611 6612 final void autoTransferFocus(boolean clearOnFailure) { 6613 Component toTest = KeyboardFocusManager. 6614 getCurrentKeyboardFocusManager().getFocusOwner(); 6615 if (toTest != this) { 6616 if (toTest != null) { 6617 toTest.autoTransferFocus(clearOnFailure); 6618 } 6619 return; 6620 } 6621 6622 if ( KeyboardFocusManager.hasFocusRequests() ){ 6623 return; 6624 } 6625 6626 6629 if (!(isDisplayable() && isVisible() && isEnabled() && isFocusable())) { 6630 doAutoTransfer(clearOnFailure); 6631 return; 6632 } 6633 6634 toTest = getParent(); 6635 6636 while (toTest != null && !(toTest instanceof Window )) { 6637 if (!(toTest.isDisplayable() && toTest.isVisible() && 6638 (toTest.isEnabled() || toTest.isLightweight()))) { 6639 doAutoTransfer(clearOnFailure); 6640 return; 6641 } 6642 toTest = toTest.getParent(); 6643 } 6644 } 6645 private void doAutoTransfer(boolean clearOnFailure) { 6646 if (clearOnFailure) { 6647 if (!nextFocusHelper()) { 6648 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 6649 clearGlobalFocusOwner(); 6650 } 6651 } else { 6652 transferFocus(); 6653 } 6654 } 6655 6656 6662 public void transferFocus() { 6663 nextFocus(); 6664 } 6665 6666 6680 public Container getFocusCycleRootAncestor() { 6681 Container rootAncestor = this.parent; 6682 while (rootAncestor != null && !rootAncestor.isFocusCycleRoot()) { 6683 rootAncestor = rootAncestor.parent; 6684 } 6685 return rootAncestor; 6686 } 6687 6688 6700 public boolean isFocusCycleRoot(Container container) { 6701 Container rootAncestor = getFocusCycleRootAncestor(); 6702 return (rootAncestor == container); 6703 } 6704 6705 6709 @Deprecated 6710 public void nextFocus() { 6711 nextFocusHelper(); 6712 } 6713 6714 boolean nextFocusHelper() { 6715 Container rootAncestor = getFocusCycleRootAncestor(); 6716 Component comp = this; 6717 while (rootAncestor != null && 6718 !(rootAncestor.isShowing() && 6719 rootAncestor.isFocusable() && 6720 rootAncestor.isEnabled())) 6721 { 6722 comp = rootAncestor; 6723 rootAncestor = comp.getFocusCycleRootAncestor(); 6724 } 6725 if (rootAncestor != null) { 6726 FocusTraversalPolicy policy = 6727 rootAncestor.getFocusTraversalPolicy(); 6728 Component toFocus = policy.getComponentAfter(rootAncestor, comp); 6729 if (toFocus == null) { 6730 toFocus = policy.getDefaultComponent(rootAncestor); 6731 } 6732 if (toFocus != null) { 6733 if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Next component " + toFocus); 6734 boolean res = toFocus.requestFocus(false); 6735 if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Request focus returned " + res); 6736 return res; 6737 } 6738 } 6739 return false; 6740 } 6741 6742 6748 public void transferFocusBackward() { 6749 Container rootAncestor = getFocusCycleRootAncestor(); 6750 Component comp = this; 6751 while (rootAncestor != null && 6752 !(rootAncestor.isShowing() && 6753 rootAncestor.isFocusable() && 6754 rootAncestor.isEnabled())) 6755 { 6756 comp = rootAncestor; 6757 rootAncestor = comp.getFocusCycleRootAncestor(); 6758 } 6759 if (rootAncestor != null) { 6760 FocusTraversalPolicy policy = 6761 rootAncestor.getFocusTraversalPolicy(); 6762 Component toFocus = policy.getComponentBefore(rootAncestor, comp); 6763 if (toFocus == null) { 6764 toFocus = policy.getDefaultComponent(rootAncestor); 6765 } 6766 if (toFocus != null) { 6767 toFocus.requestFocus(); 6768 } 6769 } 6770 } 6771 6772 6785 public void transferFocusUpCycle() { 6786 Container rootAncestor; 6787 for (rootAncestor = getFocusCycleRootAncestor(); 6788 rootAncestor != null && !(rootAncestor.isShowing() && 6789 rootAncestor.isFocusable() && 6790 rootAncestor.isEnabled()); 6791 rootAncestor = rootAncestor.getFocusCycleRootAncestor()) { 6792 } 6793 6794 if (rootAncestor != null) { 6795 Container rootAncestorRootAncestor = 6796 rootAncestor.getFocusCycleRootAncestor(); 6797 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 6798 setGlobalCurrentFocusCycleRoot( 6799 (rootAncestorRootAncestor != null) 6800 ? rootAncestorRootAncestor 6801 : rootAncestor); 6802 rootAncestor.requestFocus(); 6803 } else { 6804 Container window = 6805 (this instanceof Container ) ? ((Container )this) : getParent(); 6806 while (window != null && !(window instanceof Window )) { 6807 window = window.getParent(); 6808 } 6809 if (window != null) { 6810 Component toFocus = window.getFocusTraversalPolicy(). 6811 getDefaultComponent(window); 6812 if (toFocus != null) { 6813 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 6814 setGlobalCurrentFocusCycleRoot(window); 6815 toFocus.requestFocus(); 6816 } 6817 } 6818 } 6819 } 6820 6821 6830 public boolean hasFocus() { 6831 return (KeyboardFocusManager.getCurrentKeyboardFocusManager(). 6832 getFocusOwner() == this); 6833 } 6834 6835 6843 public boolean isFocusOwner() { 6844 return hasFocus(); 6845 } 6846 6847 6853 public synchronized void add(PopupMenu popup) { 6854 if (popup.parent != null) { 6855 popup.parent.remove(popup); 6856 } 6857 if (popups == null) { 6858 popups = new Vector (); 6859 } 6860 popups.addElement(popup); 6861 popup.parent = this; 6862 6863 if (peer != null) { 6864 if (popup.peer == null) { 6865 popup.addNotify(); 6866 } 6867 } 6868 } 6869 6870 6876 public synchronized void remove(MenuComponent popup) { 6877 if (popups != null) { 6878 int index = popups.indexOf(popup); 6879 if (index >= 0) { 6880 PopupMenu pmenu = (PopupMenu )popup; 6881 if (pmenu.peer != null) { 6882 pmenu.removeNotify(); 6883 } 6884 pmenu.parent = null; 6885 popups.removeElementAt(index); 6886 if (popups.size() == 0) { 6887 popups = null; 6888 } 6889 } 6890 } 6891 } 6892 6893 6903 protected String paramString() { 6904 String thisName = getName(); 6905 String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height; 6906 if (!valid) { 6907 str += ",invalid"; 6908 } 6909 if (!visible) { 6910 str += ",hidden"; 6911 } 6912 if (!enabled) { 6913 str += ",disabled"; 6914 } 6915 return str; 6916 } 6917 6918 6923 public String toString() { 6924 return getClass().getName() + "[" + paramString() + "]"; 6925 } 6926 6927 6933 public void list() { 6934 list(System.out, 0); 6935 } 6936 6937 6943 public void list(PrintStream out) { 6944 list(out, 0); 6945 } 6946 6947 6955 public void list(PrintStream out, int indent) { 6956 for (int i = 0 ; i < indent ; i++) { 6957 out.print(" "); 6958 } 6959 out.println(this); 6960 } 6961 6962 6967 public void list(PrintWriter out) { 6968 list(out, 0); 6969 } 6970 6971 6979 public void list(PrintWriter out, int indent) { 6980 for (int i = 0 ; i < indent ; i++) { 6981 out.print(" "); 6982 } 6983 out.println(this); 6984 } 6985 6986 6990 Container getNativeContainer() { 6991 Container p = parent; 6992 while (p != null && p.peer instanceof LightweightPeer) { 6993 p = p.getParent(); 6994 } 6995 return p; 6996 } 6997 6998 7032 public synchronized void addPropertyChangeListener( 7033 PropertyChangeListener listener) { 7034 if (listener == null) { 7035 return; 7036 } 7037 if (changeSupport == null) { 7038 changeSupport = new PropertyChangeSupport (this); 7039 } 7040 changeSupport.addPropertyChangeListener(listener); 7041 } 7042 7043 7056 public synchronized void removePropertyChangeListener( 7057 PropertyChangeListener listener) { 7058 if (listener == null || changeSupport == null) { 7059 return; 7060 } 7061 changeSupport.removePropertyChangeListener(listener); 7062 } 7063 7064 7078 public synchronized PropertyChangeListener [] getPropertyChangeListeners() { 7079 if (changeSupport == null) { 7080 return new PropertyChangeListener [0]; 7081 } 7082 return changeSupport.getPropertyChangeListeners(); 7083 } 7084 7085 7116 public synchronized void addPropertyChangeListener( 7117 String propertyName, 7118 PropertyChangeListener listener) { 7119 if (listener == null) { 7120 return; 7121 } 7122 if (changeSupport == null) { 7123 changeSupport = new PropertyChangeSupport (this); 7124 } 7125 changeSupport.addPropertyChangeListener(propertyName, listener); 7126 } 7127 7128 7144 public synchronized void removePropertyChangeListener( 7145 String propertyName, 7146 PropertyChangeListener listener) { 7147 if (listener == null || changeSupport == null) { 7148 return; 7149 } 7150 changeSupport.removePropertyChangeListener(propertyName, listener); 7151 } 7152 7153 7167 public synchronized PropertyChangeListener [] getPropertyChangeListeners( 7168 String propertyName) { 7169 if (changeSupport == null) { 7170 return new PropertyChangeListener [0]; 7171 } 7172 return changeSupport.getPropertyChangeListeners(propertyName); 7173 } 7174 7175 7185 protected void firePropertyChange(String propertyName, 7186 Object oldValue, Object newValue) { 7187 PropertyChangeSupport changeSupport = this.changeSupport; 7188 if (changeSupport == null || 7189 (oldValue != null && newValue != null && oldValue.equals(newValue))) { 7190 return; 7191 } 7192 changeSupport.firePropertyChange(propertyName, oldValue, newValue); 7193 } 7194 7195 7205 protected void firePropertyChange(String propertyName, 7206 boolean oldValue, boolean newValue) { 7207 PropertyChangeSupport changeSupport = this.changeSupport; 7208 if (changeSupport == null || oldValue == newValue) { 7209 return; 7210 } 7211 changeSupport.firePropertyChange(propertyName, oldValue, newValue); 7212 } 7213 7214 7224 protected void firePropertyChange(String propertyName, 7225 int oldValue, int newValue) { 7226 PropertyChangeSupport changeSupport = this.changeSupport; 7227 if (changeSupport == null || oldValue == newValue) { 7228 return; 7229 } 7230 changeSupport.firePropertyChange(propertyName, oldValue, newValue); 7231 } 7232 7233 7244 public void firePropertyChange(String propertyName, byte oldValue, byte newValue) { 7245 if (changeSupport == null || oldValue == newValue) { 7246 return; 7247 } 7248 firePropertyChange(propertyName, new Byte (oldValue), new Byte (newValue)); 7249 } 7250 7251&nb
|