1 7 8 package java.awt; 9 10 import java.util.MissingResourceException ; 11 import java.util.Properties ; 12 import java.util.ResourceBundle ; 13 import java.util.StringTokenizer ; 14 import java.awt.event.*; 15 import java.awt.peer.*; 16 import java.awt.*; 17 import java.awt.im.InputMethodHighlight ; 18 import java.awt.image.ImageObserver ; 19 import java.awt.image.ImageProducer ; 20 import java.awt.image.ColorModel ; 21 import java.awt.datatransfer.Clipboard ; 22 import java.awt.dnd.DnDConstants ; 23 import java.awt.dnd.DragSource ; 24 import java.awt.dnd.DragGestureRecognizer ; 25 import java.awt.dnd.DragGestureEvent ; 26 import java.awt.dnd.DragGestureListener ; 27 import java.awt.dnd.InvalidDnDOperationException ; 28 import java.awt.dnd.peer.DragSourceContextPeer; 29 import java.net.URL ; 30 import java.io.BufferedInputStream ; 31 import java.io.File ; 32 import java.io.FileInputStream ; 33 import java.security.AccessController ; 34 import java.security.PrivilegedAction ; 35 36 import java.util.EventListener ; 37 import java.util.Map ; 38 import java.util.HashMap ; 39 import java.util.WeakHashMap ; 40 import java.util.List ; 41 import java.util.ArrayList ; 42 43 import java.beans.PropertyChangeListener ; 44 import java.beans.PropertyChangeSupport ; 45 46 import sun.awt.DebugHelper; 47 import sun.awt.HeadlessToolkit; 48 import sun.awt.NullComponentPeer; 49 import sun.security.util.SecurityConstants; 50 101 public abstract class Toolkit { 102 103 114 protected abstract ButtonPeer createButton(Button target) 115 throws HeadlessException ; 116 117 128 protected abstract TextFieldPeer createTextField(TextField target) 129 throws HeadlessException ; 130 131 142 protected abstract LabelPeer createLabel(Label target) 143 throws HeadlessException ; 144 145 156 protected abstract ListPeer createList(java.awt.List target) 157 throws HeadlessException ; 158 159 170 protected abstract CheckboxPeer createCheckbox(Checkbox target) 171 throws HeadlessException ; 172 173 184 protected abstract ScrollbarPeer createScrollbar(Scrollbar target) 185 throws HeadlessException ; 186 187 199 protected abstract ScrollPanePeer createScrollPane(ScrollPane target) 200 throws HeadlessException ; 201 202 213 protected abstract TextAreaPeer createTextArea(TextArea target) 214 throws HeadlessException ; 215 216 227 protected abstract ChoicePeer createChoice(Choice target) 228 throws HeadlessException ; 229 230 241 protected abstract FramePeer createFrame(Frame target) 242 throws HeadlessException ; 243 244 252 protected abstract CanvasPeer createCanvas(Canvas target); 253 254 262 protected abstract PanelPeer createPanel(Panel target); 263 264 275 protected abstract WindowPeer createWindow(Window target) 276 throws HeadlessException ; 277 278 289 protected abstract DialogPeer createDialog(Dialog target) 290 throws HeadlessException ; 291 292 303 protected abstract MenuBarPeer createMenuBar(MenuBar target) 304 throws HeadlessException ; 305 306 317 protected abstract MenuPeer createMenu(Menu target) 318 throws HeadlessException ; 319 320 332 protected abstract PopupMenuPeer createPopupMenu(PopupMenu target) 333 throws HeadlessException ; 334 335 346 protected abstract MenuItemPeer createMenuItem(MenuItem target) 347 throws HeadlessException ; 348 349 360 protected abstract FileDialogPeer createFileDialog(FileDialog target) 361 throws HeadlessException ; 362 363 374 protected abstract CheckboxMenuItemPeer createCheckboxMenuItem( 375 CheckboxMenuItem target) throws HeadlessException ; 376 377 385 protected MouseInfoPeer getMouseInfoPeer() { 386 throw new UnsupportedOperationException ("Not implemented"); 387 } 388 389 private static LightweightPeer lightweightMarker; 390 391 398 protected LightweightPeer createComponent(Component target) { 399 if (lightweightMarker == null) { 400 lightweightMarker = new NullComponentPeer(); 401 } 402 return lightweightMarker; 403 } 404 405 417 @Deprecated 418 protected abstract FontPeer getFontPeer(String name, int style); 419 420 423 433 protected void loadSystemColors(int[] systemColors) 434 throws HeadlessException { 435 } 436 437 463 public void setDynamicLayout(boolean dynamic) 464 throws HeadlessException { 465 } 466 467 486 protected boolean isDynamicLayoutSet() 487 throws HeadlessException { 488 if (this != Toolkit.getDefaultToolkit()) { 489 return Toolkit.getDefaultToolkit().isDynamicLayoutSet(); 490 } else { 491 return false; 492 } 493 } 494 495 512 public boolean isDynamicLayoutActive() 513 throws HeadlessException { 514 if (this != Toolkit.getDefaultToolkit()) { 515 return Toolkit.getDefaultToolkit().isDynamicLayoutActive(); 516 } else { 517 return false; 518 } 519 } 520 521 533 public abstract Dimension getScreenSize() 534 throws HeadlessException ; 535 536 543 public abstract int getScreenResolution() 544 throws HeadlessException ; 545 546 555 public Insets getScreenInsets(GraphicsConfiguration gc) 556 throws HeadlessException { 557 if (this != Toolkit.getDefaultToolkit()) { 558 return Toolkit.getDefaultToolkit().getScreenInsets(gc); 559 } else { 560 return new Insets (0, 0, 0, 0); 561 } 562 } 563 564 582 public abstract ColorModel getColorModel() 583 throws HeadlessException ; 584 585 601 @Deprecated 602 public abstract String [] getFontList(); 603 604 614 @Deprecated 615 public abstract FontMetrics getFontMetrics(Font font); 616 617 624 public abstract void sync(); 625 626 629 private static Toolkit toolkit; 630 631 635 private static String atNames; 636 637 648 private static void initAssistiveTechnologies() { 649 650 final String sep = File.separator; 652 final Properties properties = new Properties (); 653 654 655 atNames = (String )java.security.AccessController.doPrivileged( 656 new java.security.PrivilegedAction () { 657 public Object run() { 658 659 try { 661 File propsFile = new File ( 662 System.getProperty("user.home") + 663 sep + ".accessibility.properties"); 664 FileInputStream in = 665 new FileInputStream (propsFile); 666 667 properties.load(in); 669 in.close(); 670 } catch (Exception e) { 671 } 673 674 if (properties.size() == 0) { 678 try { 679 File propsFile = new File ( 680 System.getProperty("java.home") + sep + "lib" + 681 sep + "accessibility.properties"); 682 FileInputStream in = 683 new FileInputStream (propsFile); 684 685 properties.load(in); 687 in.close(); 688 } catch (Exception e) { 689 } 692 } 693 694 String magPresent = System.getProperty("javax.accessibility.screen_magnifier_present"); 697 if (magPresent == null) { 698 magPresent = properties.getProperty("screen_magnifier_present", null); 699 if (magPresent != null) { 700 System.setProperty("javax.accessibility.screen_magnifier_present", magPresent); 701 } 702 } 703 704 String classNames = System.getProperty("javax.accessibility.assistive_technologies"); 708 if (classNames == null) { 709 classNames = properties.getProperty("assistive_technologies", null); 710 if (classNames != null) { 711 System.setProperty("javax.accessibility.assistive_technologies", classNames); 712 } 713 } 714 return classNames; 715 } 716 }); 717 } 718 719 738 private static void loadAssistiveTechnologies() { 739 if (atNames != null) { 741 ClassLoader cl = ClassLoader.getSystemClassLoader(); 742 StringTokenizer parser = new StringTokenizer (atNames," ,"); 743 String atName; 744 while (parser.hasMoreTokens()) { 745 atName = parser.nextToken(); 746 try { 747 Class clazz; 748 if (cl != null) { 749 clazz = cl.loadClass(atName); 750 } else { 751 clazz = Class.forName(atName); 752 } 753 clazz.newInstance(); 754 } catch (ClassNotFoundException e) { 755 throw new AWTError ("Assistive Technology not found: " 756 + atName); 757 } catch (InstantiationException e) { 758 throw new AWTError ("Could not instantiate Assistive" 759 + " Technology: " + atName); 760 } catch (IllegalAccessException e) { 761 throw new AWTError ("Could not access Assistive" 762 + " Technology: " + atName); 763 } catch (Exception e) { 764 throw new AWTError ("Error trying to install Assistive" 765 + " Technology: " + atName + " " + e); 766 } 767 } 768 } 769 } 770 771 796 public static synchronized Toolkit getDefaultToolkit() { 797 if (toolkit == null) { 798 try { 799 java.lang.Compiler.disable(); 803 804 java.security.AccessController.doPrivileged( 805 new java.security.PrivilegedAction () { 806 public Object run() { 807 String nm = null; 808 Class cls = null; 809 try { 810 String defaultToolkit; 811 812 if (System.getProperty("os.name").equals("Linux")) { 813 defaultToolkit = "sun.awt.X11.XToolkit"; 814 } 815 else { 816 defaultToolkit = "sun.awt.motif.MToolkit"; 817 } 818 nm = System.getProperty("awt.toolkit", 819 defaultToolkit); 820 try { 821 cls = Class.forName(nm); 822 } catch (ClassNotFoundException e) { 823 ClassLoader cl = ClassLoader.getSystemClassLoader(); 824 if (cl != null) { 825 try { 826 cls = cl.loadClass(nm); 827 } catch (ClassNotFoundException ee) { 828 throw new AWTError ("Toolkit not found: " + nm); 829 } 830 } 831 } 832 if (cls != null) { 833 toolkit = (Toolkit )cls.newInstance(); 834 if (GraphicsEnvironment.isHeadless()) { 835 toolkit = new HeadlessToolkit(toolkit); 836 } 837 } 838 } catch (InstantiationException e) { 839 throw new AWTError ("Could not instantiate Toolkit: " + 840 nm); 841 } catch (IllegalAccessException e) { 842 throw new AWTError ("Could not access Toolkit: " + nm); 843 } 844 return null; 845 } 846 }); 847 loadAssistiveTechnologies(); 848 } finally { 849 java.lang.Compiler.enable(); 851 } 852 } 853 return toolkit; 854 } 855 856 872 public abstract Image getImage(String filename); 873 874 890 public abstract Image getImage(URL url); 891 892 902 public abstract Image createImage(String filename); 903 904 913 public abstract Image createImage(URL url); 914 915 950 public abstract boolean prepareImage(Image image, int width, int height, 951 ImageObserver observer); 952 953 991 public abstract int checkImage(Image image, int width, int height, 992 ImageObserver observer); 993 994 1002 public abstract Image createImage(ImageProducer producer); 1003 1004 1015 public Image createImage(byte[] imagedata) { 1016 return createImage(imagedata, 0, imagedata.length); 1017 } 1018 1019 1032 public abstract Image createImage(byte[] imagedata, 1033 int imageoffset, 1034 int imagelength); 1035 1036 1072 public abstract PrintJob getPrintJob(Frame frame, String jobtitle, 1073 Properties props); 1074 1075 1122 public PrintJob getPrintJob(Frame frame, String jobtitle, 1123 JobAttributes jobAttributes, 1124 PageAttributes pageAttributes) { 1125 1127 if (GraphicsEnvironment.isHeadless()) { 1128 throw new IllegalArgumentException (); 1129 } 1130 1131 if (this != Toolkit.getDefaultToolkit()) { 1132 return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle, 1133 jobAttributes, 1134 pageAttributes); 1135 } else { 1136 return getPrintJob(frame, jobtitle, null); 1137 } 1138 } 1139 1140 1144 public abstract void beep(); 1145 1146 1191 public abstract Clipboard getSystemClipboard() 1192 throws HeadlessException ; 1193 1194 1245 public Clipboard getSystemSelection() throws HeadlessException { 1246 if (this != Toolkit.getDefaultToolkit()) { 1247 return Toolkit.getDefaultToolkit().getSystemSelection(); 1248 } else { 1249 GraphicsEnvironment.checkHeadless(); 1250 return null; 1251 } 1252 } 1253 1254 1274 public int getMenuShortcutKeyMask() throws HeadlessException { 1275 return Event.CTRL_MASK; 1276 } 1277 1278 1297 public boolean getLockingKeyState(int keyCode) 1298 throws UnsupportedOperationException { 1299 if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || 1300 keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) { 1301 throw new IllegalArgumentException ("invalid key for Toolkit.getLockingKeyState"); 1302 } 1303 throw new UnsupportedOperationException ("Toolkit.getLockingKeyState"); 1304 } 1305 1306 1328 public void setLockingKeyState(int keyCode, boolean on) 1329 throws UnsupportedOperationException { 1330 if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || 1331 keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) { 1332 throw new IllegalArgumentException ("invalid key for Toolkit.setLockingKeyState"); 1333 } 1334 throw new UnsupportedOperationException ("Toolkit.setLockingKeyState"); 1335 } 1336 1337 1341 protected static Container getNativeContainer(Component c) { 1342 return c.getNativeContainer(); 1343 } 1344 1345 1365 public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) 1366 throws IndexOutOfBoundsException , HeadlessException 1367 { 1368 if (this != Toolkit.getDefaultToolkit()) { 1370 return Toolkit.getDefaultToolkit(). 1371 createCustomCursor(cursor, hotSpot, name); 1372 } else { 1373 return new Cursor (Cursor.DEFAULT_CURSOR); 1374 } 1375 } 1376 1377 1401 public Dimension getBestCursorSize(int preferredWidth, 1402 int preferredHeight) throws HeadlessException { 1403 if (this != Toolkit.getDefaultToolkit()) { 1405 return Toolkit.getDefaultToolkit(). 1406 getBestCursorSize(preferredWidth, preferredHeight); 1407 } else { 1408 return new Dimension (0, 0); 1409 } 1410 } 1411 1412 1429 public int getMaximumCursorColors() throws HeadlessException { 1430 if (this != Toolkit.getDefaultToolkit()) { 1432 return Toolkit.getDefaultToolkit().getMaximumCursorColors(); 1433 } else { 1434 return 0; 1435 } 1436 } 1437 1438 1456 public boolean isFrameStateSupported(int state) 1457 throws HeadlessException 1458 { 1459 if (this != Toolkit.getDefaultToolkit()) { 1460 return Toolkit.getDefaultToolkit(). 1461 isFrameStateSupported(state); 1462 } else { 1463 return (state == Frame.NORMAL); } 1465 } 1466 1467 1472 private static ResourceBundle resources; 1473 1474 1477 private static native void initIDs(); 1478 1479 1506 private static boolean loaded = false; 1507 static void loadLibraries() { 1508 if (!loaded) { 1509 java.security.AccessController.doPrivileged( 1510 new sun.security.action.LoadLibraryAction("awt")); 1511 loaded = true; 1512 } 1513 } 1514 1515 static { 1516 java.security.AccessController.doPrivileged( 1517 new java.security.PrivilegedAction () { 1518 public Object run() { 1519 try { 1520 resources = 1521 ResourceBundle.getBundle("sun.awt.resources.awt"); 1522 } catch (MissingResourceException e) { 1523 } 1525 return null; 1526 } 1527 }); 1528 1529 loadLibraries(); 1531 initAssistiveTechnologies(); 1532 if (!GraphicsEnvironment.isHeadless()) { 1533 initIDs(); 1534 } 1535 } 1536 1537 1541 public static String getProperty(String key, String defaultValue) { 1542 if (resources != null) { 1543 try { 1544 return resources.getString(key); 1545 } 1546 catch (MissingResourceException e) {} 1547 } 1548 1549 return defaultValue; 1550 } 1551 1552 1574 public final EventQueue getSystemEventQueue() { 1575 SecurityManager security = System.getSecurityManager(); 1576 if (security != null) { 1577 security.checkAwtEventQueueAccess(); 1578 } 1579 return getSystemEventQueueImpl(); 1580 } 1581 1582 1588 protected abstract EventQueue getSystemEventQueueImpl(); 1589 1590 1591 static EventQueue getEventQueue() { 1592 return getDefaultToolkit().getSystemEventQueueImpl(); 1593 } 1594 1595 1601 public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException ; 1602 1603 1620 public <T extends DragGestureRecognizer > T 1621 createDragGestureRecognizer(Class <T> abstractRecognizerClass, 1622 DragSource ds, Component c, int srcActions, 1623 DragGestureListener dgl) 1624 { 1625 return null; 1626 } 1627 1628 1635 public final synchronized Object getDesktopProperty(String propertyName) { 1636 if (this instanceof HeadlessToolkit) { 1641 return ((HeadlessToolkit)this).getUnderlyingToolkit() 1642 .getDesktopProperty(propertyName); 1643 } 1644 1645 if (desktopProperties.isEmpty()) { 1646 initializeDesktopProperties(); 1647 } 1648 1649 Object value; 1650 1651 if (propertyName.equals("awt.dynamicLayoutSupported")) { 1653 value = lazilyLoadDesktopProperty(propertyName); 1654 return value; 1655 } 1656 1657 value = desktopProperties.get(propertyName); 1658 1659 if (value == null) { 1660 value = lazilyLoadDesktopProperty(propertyName); 1661 1662 if (value != null) { 1663 setDesktopProperty(propertyName, value); 1664 } 1665 } 1666 1667 return value; 1668 } 1669 1670 1674 protected final void setDesktopProperty(String name, Object newValue) { 1675 if (this instanceof HeadlessToolkit) { 1680 ((HeadlessToolkit)this).getUnderlyingToolkit() 1681 .setDesktopProperty(name, newValue); 1682 return; 1683 } 1684 Object oldValue; 1685 1686 synchronized (this) { 1687 oldValue = desktopProperties.get(name); 1688 desktopProperties.put(name, newValue); 1689 } 1690 1691 desktopPropsSupport.firePropertyChange(name, oldValue, newValue); 1692 } 1693 1694 1697 protected Object lazilyLoadDesktopProperty(String name) { 1698 return null; 1699 } 1700 1701 1704 protected void initializeDesktopProperties() { 1705 } 1706 1707 1716 public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) { 1717 if (pcl == null) { 1718 return; 1719 } 1720 desktopPropsSupport.addPropertyChangeListener(name, pcl); 1721 } 1722 1723 1732 public synchronized void removePropertyChangeListener(String name, PropertyChangeListener pcl) { 1733 if (pcl == null) { 1734 return; 1735 } 1736 desktopPropsSupport.removePropertyChangeListener(name, pcl); 1737 } 1738 1739 1749 public PropertyChangeListener [] getPropertyChangeListeners() { 1750 return desktopPropsSupport.getPropertyChangeListeners(); 1751 } 1752 1753 1763 public synchronized PropertyChangeListener [] getPropertyChangeListeners(String propertyName) { 1764 return desktopPropsSupport.getPropertyChangeListeners(propertyName); 1765 } 1766 1767 protected final Map <String ,Object > desktopProperties 1768 = new HashMap <String ,Object >(); 1769 protected final PropertyChangeSupport desktopPropsSupport = new PropertyChangeSupport (this); 1770 1771 private static final DebugHelper dbg = DebugHelper.create(Toolkit .class); 1772 private static final int LONG_BITS = 64; 1773 private int[] calls = new int[LONG_BITS]; 1774 private static volatile long enabledOnToolkitMask; 1775 private AWTEventListener eventListener = null; 1776 private WeakHashMap listener2SelectiveListener = new WeakHashMap (); 1777 1778 1782 static private AWTEventListener deProxyAWTEventListener(AWTEventListener l) 1783 { 1784 AWTEventListener localL = l; 1785 1786 if (localL == null) { 1787 return null; 1788 } 1789 if (l instanceof AWTEventListenerProxy) { 1792 localL = (AWTEventListener)((AWTEventListenerProxy)l).getListener(); 1793 } 1794 return localL; 1795 } 1796 1797 1831 public void addAWTEventListener(AWTEventListener listener, long eventMask) { 1832 AWTEventListener localL = deProxyAWTEventListener(listener); 1833 1834 if (localL == null) { 1835 return; 1836 } 1837 SecurityManager security = System.getSecurityManager(); 1838 if (security != null) { 1839 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION); 1840 } 1841 synchronized (this) { 1842 SelectiveAWTEventListener selectiveListener = 1843 (SelectiveAWTEventListener)listener2SelectiveListener.get(localL); 1844 1845 if (selectiveListener == null) { 1846 selectiveListener = new SelectiveAWTEventListener(localL, 1848 eventMask); 1849 listener2SelectiveListener.put(localL, selectiveListener); 1850 eventListener = ToolkitEventMulticaster.add(eventListener, 1851 selectiveListener); 1852 } 1853 selectiveListener.orEventMasks(eventMask); 1855 1856 enabledOnToolkitMask |= eventMask; 1857 1858 long mask = eventMask; 1859 for (int i=0; i<LONG_BITS; i++) { 1860 if (mask == 0) { 1862 break; 1863 } 1864 if ((mask & 1L) != 0) { calls[i]++; 1866 } 1867 mask >>>= 1; } 1869 } 1870 } 1871 1872 1900 public void removeAWTEventListener(AWTEventListener listener) { 1901 AWTEventListener localL = deProxyAWTEventListener(listener); 1902 1903 if (listener == null) { 1904 return; 1905 } 1906 SecurityManager security = System.getSecurityManager(); 1907 if (security != null) { 1908 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION); 1909 } 1910 1911 synchronized (this) { 1912 SelectiveAWTEventListener selectiveListener = 1913 (SelectiveAWTEventListener)listener2SelectiveListener.get(localL); 1914 1915 if (selectiveListener != null) { 1916 listener2SelectiveListener.remove(localL); 1917 int[] listenerCalls = selectiveListener.getCalls(); 1918 for (int i=0; i<LONG_BITS; i++) { 1919 calls[i] -= listenerCalls[i]; 1920 assert calls[i] >= 0: "Negative Listeners count"; 1921 1922 if (calls[i] == 0) { 1923 enabledOnToolkitMask &= ~(1L<<i); 1924 } 1925 } 1926 } 1927 eventListener = ToolkitEventMulticaster.remove(eventListener, 1928 (selectiveListener == null) ? localL : selectiveListener); 1929 } 1930 } 1931 1932 static boolean enabledOnToolkit(long eventMask) { 1933 return (enabledOnToolkitMask & eventMask) != 0; 1934 } 1935 1936 synchronized int countAWTEventListeners(long eventMask) { 1937 if (dbg.on) { 1938 dbg.assertion(eventMask != 0); 1939 } 1940 1941 int ci = 0; 1942 for (; eventMask != 0; eventMask >>>= 1, ci++) { 1943 } 1944 ci--; 1945 return calls[ci]; 1946 } 1947 1969 public AWTEventListener[] getAWTEventListeners() { 1970 SecurityManager security = System.getSecurityManager(); 1971 if (security != null) { 1972 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION); 1973 } 1974 synchronized (this) { 1975 EventListener [] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class); 1976 1977 AWTEventListener[] ret = new AWTEventListener[la.length]; 1978 for (int i = 0; i < la.length; i++) { 1979 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i]; 1980 AWTEventListener tempL = sael.getListener(); 1981 ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL); 1985 } 1986 return ret; 1987 } 1988 } 1989 1990 2017 public AWTEventListener[] getAWTEventListeners(long eventMask) { 2018 SecurityManager security = System.getSecurityManager(); 2019 if (security != null) { 2020 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION); 2021 } 2022 synchronized (this) { 2023 EventListener [] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class); 2024 2025 java.util.List list = new ArrayList (la.length); 2026 2027 for (int i = 0; i < la.length; i++) { 2028 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i]; 2029 if ((sael.getEventMask() & eventMask) == eventMask) { 2030 list.add(new AWTEventListenerProxy(sael.getEventMask(), 2032 sael.getListener())); 2033 } 2034 } 2035 return (AWTEventListener[])list.toArray(new AWTEventListener[0]); 2036 } 2037 } 2038 2039 2045 void notifyAWTEventListeners(AWTEvent theEvent) { 2046 if (this instanceof HeadlessToolkit) { 2051 ((HeadlessToolkit)this).getUnderlyingToolkit() 2052 .notifyAWTEventListeners(theEvent); 2053 return; 2054 } 2055 2056 AWTEventListener eventListener = this.eventListener; 2057 if (eventListener != null) { 2058 eventListener.eventDispatched(theEvent); 2059 } 2060 } 2061 2062 static private class ToolkitEventMulticaster extends AWTEventMulticaster 2063 implements AWTEventListener { 2064 2066 ToolkitEventMulticaster(AWTEventListener a, AWTEventListener b) { 2067 super(a, b); 2068 } 2069 2070 static AWTEventListener add(AWTEventListener a, 2071 AWTEventListener b) { 2072 if (a == null) return b; 2073 if (b == null) return a; 2074 return new ToolkitEventMulticaster(a, b); 2075 } 2076 2077 static AWTEventListener remove(AWTEventListener l, 2078 AWTEventListener oldl) { 2079 return (AWTEventListener) removeInternal(l, oldl); 2080 } 2081 2082 protected EventListener remove(EventListener oldl) { 2088 if (oldl == a) return b; 2089 if (oldl == b) return a; 2090 AWTEventListener a2 = (AWTEventListener)removeInternal(a, oldl); 2091 AWTEventListener b2 = (AWTEventListener)removeInternal(b, oldl); 2092 if (a2 == a && b2 == b) { 2093 return this; } 2095 return add(a2, b2); 2096 } 2097 2098 public void eventDispatched(AWTEvent event) { 2099 ((AWTEventListener)a).eventDispatched(event); 2100 ((AWTEventListener)b).eventDispatched(event); 2101 } 2102 } 2103 2104 private class SelectiveAWTEventListener implements AWTEventListener { 2105 AWTEventListener listener; 2106 private long eventMask; 2107 int[] calls = new int[Toolkit.LONG_BITS]; 2110 2111 public AWTEventListener getListener() {return listener;} 2112 public long getEventMask() {return eventMask;} 2113 public int[] getCalls() {return calls;} 2114 2115 public void orEventMasks(long mask) { 2116 eventMask |= mask; 2117 for (int i=0; i<Toolkit.LONG_BITS; i++) { 2119 if (mask == 0) { 2121 break; 2122 } 2123 if ((mask & 1L) != 0) { calls[i]++; 2125 } 2126 mask >>>= 1; } 2128 } 2129 2130 SelectiveAWTEventListener(AWTEventListener l, long mask) { 2131 listener = l; 2132 eventMask = mask; 2133 } 2134 2135 public void eventDispatched(AWTEvent event) { 2136 long eventBit = 0; if (((eventBit = eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 && 2138 event.id >= ComponentEvent.COMPONENT_FIRST && 2139 event.id <= ComponentEvent.COMPONENT_LAST) 2140 || ((eventBit = eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 && 2141 event.id >= ContainerEvent.CONTAINER_FIRST && 2142 event.id <= ContainerEvent.CONTAINER_LAST) 2143 || ((eventBit = eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 && 2144 event.id >= FocusEvent.FOCUS_FIRST && 2145 event.id <= FocusEvent.FOCUS_LAST) 2146 || ((eventBit = eventMask & AWTEvent.KEY_EVENT_MASK) != 0 && 2147 event.id >= KeyEvent.KEY_FIRST && 2148 event.id <= KeyEvent.KEY_LAST) 2149 || ((eventBit = eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 && 2150 event.id == MouseEvent.MOUSE_WHEEL) 2151 || ((eventBit = eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 && 2152 (event.id == MouseEvent.MOUSE_MOVED || 2153 event.id == MouseEvent.MOUSE_DRAGGED)) 2154 || ((eventBit = eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 && 2155 event.id != MouseEvent.MOUSE_MOVED && 2156 event.id != MouseEvent.MOUSE_DRAGGED && 2157 event.id != MouseEvent.MOUSE_WHEEL && 2158 event.id >= MouseEvent.MOUSE_FIRST && 2159 event.id <= MouseEvent.MOUSE_LAST) 2160 || ((eventBit = eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 && 2161 event.id >= WindowEvent.WINDOW_FIRST && 2162 event.id <= WindowEvent.WINDOW_LAST) 2163 || ((eventBit = eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 && 2164 event.id >= ActionEvent.ACTION_FIRST && 2165 event.id <= ActionEvent.ACTION_LAST) 2166 || ((eventBit = eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 && 2167 event.id >= AdjustmentEvent.ADJUSTMENT_FIRST && 2168 event.id <= AdjustmentEvent.ADJUSTMENT_LAST) 2169 || ((eventBit = eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 && 2170 event.id >= ItemEvent.ITEM_FIRST && 2171 event.id <= ItemEvent.ITEM_LAST) 2172 || ((eventBit = eventMask & AWTEvent.TEXT_EVENT_MASK) != 0 && 2173 event.id >= TextEvent.TEXT_FIRST && 2174 event.id <= TextEvent.TEXT_LAST) 2175 || ((eventBit = eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 && 2176 event.id >= InputMethodEvent.INPUT_METHOD_FIRST && 2177 event.id <= InputMethodEvent.INPUT_METHOD_LAST) 2178 || ((eventBit = eventMask & AWTEvent.PAINT_EVENT_MASK) != 0 && 2179 event.id >= PaintEvent.PAINT_FIRST && 2180 event.id <= PaintEvent.PAINT_LAST) 2181 || ((eventBit = eventMask & AWTEvent.INVOCATION_EVENT_MASK) != 0 && 2182 event.id >= InvocationEvent.INVOCATION_FIRST && 2183 event.id <= InvocationEvent.INVOCATION_LAST) 2184 || ((eventBit = eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && 2185 event.id == HierarchyEvent.HIERARCHY_CHANGED) 2186 || ((eventBit = eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 && 2187 (event.id == HierarchyEvent.ANCESTOR_MOVED || 2188 event.id == HierarchyEvent.ANCESTOR_RESIZED)) 2189 || ((eventBit = eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 && 2190 event.id == WindowEvent.WINDOW_STATE_CHANGED) 2191 || ((eventBit = eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 && 2192 (event.id == WindowEvent.WINDOW_GAINED_FOCUS || 2193 event.id == WindowEvent.WINDOW_LOST_FOCUS))) { 2194 int ci = 0; 2200 for (long eMask = eventBit; eMask != 0; eMask >>>= 1, ci++) { 2201 } 2202 ci--; 2203 for (int i=0; i<calls[ci]; i++) { 2206 listener.eventDispatched(event); 2207 } 2208 } 2209 } 2210 } 2211 2212 2224 public abstract Map <java.awt.font.TextAttribute ,?> 2225 mapInputMethodHighlight(InputMethodHighlight highlight) 2226 throws HeadlessException ; 2227 2228} 2229 2230 | Popular Tags |