2008 * @throws SecurityException
2009 * if a security manager exists and its
2010 * <code>checkPermission</code> method doesn't allow the operation.
2011 * @see #removeAWTEventListener
2012 * @see #getAWTEventListeners
2013 * @see SecurityManager#checkPermission
2014 * @see java.awt.AWTEvent
2015 * @see java.awt.AWTPermission
2016 * @see java.awt.event.AWTEventListener
2017 * @see java.awt.event.AWTEventListenerProxy
2018 * @since 1.2
2019 */
2020 public void addAWTEventListener(AWTEventListener listener, long eventMask) {
2021 AWTEventListener localL = deProxyAWTEventListener(listener);
2022
2023 if (localL == null) {
2024 return;
2025 }
2026 SecurityManager security = System.getSecurityManager();
2027 if (security != null) {
2028 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2029 }
2030 synchronized (this) {
2031 SelectiveAWTEventListener selectiveListener =
2032 (SelectiveAWTEventListener)listener2SelectiveListener.get(localL);
2033
2034 if (selectiveListener == null) {
2035 // Create a new selectiveListener.
2036 selectiveListener = new SelectiveAWTEventListener(localL,
2037 eventMask);
2038 listener2SelectiveListener.put(localL, selectiveListener);
2039 eventListener = ToolkitEventMulticaster.add(eventListener,
2040 selectiveListener);
2041 }
2042 // OR the eventMask into the selectiveListener's event mask.
2043 selectiveListener.orEventMasks(eventMask);
2044
2045 enabledOnToolkitMask |= eventMask;
2046
2047 long mask = eventMask;
2048 for (int i=0; i<LONG_BITS; i++) {
2077 * @throws SecurityException
2078 * if a security manager exists and its
2079 * <code>checkPermission</code> method doesn't allow the operation.
2080 * @see #addAWTEventListener
2081 * @see #getAWTEventListeners
2082 * @see SecurityManager#checkPermission
2083 * @see java.awt.AWTEvent
2084 * @see java.awt.AWTPermission
2085 * @see java.awt.event.AWTEventListener
2086 * @see java.awt.event.AWTEventListenerProxy
2087 * @since 1.2
2088 */
2089 public void removeAWTEventListener(AWTEventListener listener) {
2090 AWTEventListener localL = deProxyAWTEventListener(listener);
2091
2092 if (listener == null) {
2093 return;
2094 }
2095 SecurityManager security = System.getSecurityManager();
2096 if (security != null) {
2097 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2098 }
2099
2100 synchronized (this) {
2101 SelectiveAWTEventListener selectiveListener =
2102 (SelectiveAWTEventListener)listener2SelectiveListener.get(localL);
2103
2104 if (selectiveListener != null) {
2105 listener2SelectiveListener.remove(localL);
2106 int[] listenerCalls = selectiveListener.getCalls();
2107 for (int i=0; i<LONG_BITS; i++) {
2108 calls[i] -= listenerCalls[i];
2109 assert calls[i] >= 0: "Negative Listeners count";
2110
2111 if (calls[i] == 0) {
2112 enabledOnToolkitMask &= ~(1L<<i);
2113 }
2114 }
2115 }
2116 eventListener = ToolkitEventMulticaster.remove(eventListener,
2117 (selectiveListener == null) ? localL : selectiveListener);
2148 * Note that listener objects
2149 * added multiple times appear only once in the returned array.
2150 *
2151 * @return all of the <code>AWTEventListener</code>s or an empty
2152 * array if no listeners are currently registered
2153 * @throws SecurityException
2154 * if a security manager exists and its
2155 * <code>checkPermission</code> method doesn't allow the operation.
2156 * @see #addAWTEventListener
2157 * @see #removeAWTEventListener
2158 * @see SecurityManager#checkPermission
2159 * @see java.awt.AWTEvent
2160 * @see java.awt.AWTPermission
2161 * @see java.awt.event.AWTEventListener
2162 * @see java.awt.event.AWTEventListenerProxy
2163 * @since 1.4
2164 */
2165 public AWTEventListener[] getAWTEventListeners() {
2166 SecurityManager security = System.getSecurityManager();
2167 if (security != null) {
2168 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2169 }
2170 synchronized (this) {
2171 EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
2172
2173 AWTEventListener[] ret = new AWTEventListener[la.length];
2174 for (int i = 0; i < la.length; i++) {
2175 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
2176 AWTEventListener tempL = sael.getListener();
2177 //assert tempL is not an AWTEventListenerProxy - we should
2178 // have weeded them all out
2179 // don't want to wrap a proxy inside a proxy
2180 ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL);
2181 }
2182 return ret;
2183 }
2184 }
2185
2186 /**
2187 * Returns an array of all the <code>AWTEventListener</code>s
2188 * registered on this toolkit which listen to all of the event
2200 * @param eventMask the bitmask of event types to listen for
2201 * @return all of the <code>AWTEventListener</code>s registered
2202 * on this toolkit for the specified
2203 * event types, or an empty array if no such listeners
2204 * are currently registered
2205 * @throws SecurityException
2206 * if a security manager exists and its
2207 * <code>checkPermission</code> method doesn't allow the operation.
2208 * @see #addAWTEventListener
2209 * @see #removeAWTEventListener
2210 * @see SecurityManager#checkPermission
2211 * @see java.awt.AWTEvent
2212 * @see java.awt.AWTPermission
2213 * @see java.awt.event.AWTEventListener
2214 * @see java.awt.event.AWTEventListenerProxy
2215 * @since 1.4
2216 */
2217 public AWTEventListener[] getAWTEventListeners(long eventMask) {
2218 SecurityManager security = System.getSecurityManager();
2219 if (security != null) {
2220 security.checkPermission(SecurityConstants.ALL_AWT_EVENTS_PERMISSION);
2221 }
2222 synchronized (this) {
2223 EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
2224
2225 java.util.List list = new ArrayList(la.length);
2226
2227 for (int i = 0; i < la.length; i++) {
2228 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
2229 if ((sael.getEventMask() & eventMask) == eventMask) {
2230 //AWTEventListener tempL = sael.getListener();
2231 list.add(new AWTEventListenerProxy(sael.getEventMask(),
2232 sael.getListener()));
2233 }
2234 }
2235 return (AWTEventListener[])list.toArray(new AWTEventListener[0]);
2236 }
2237 }
2238
2239 /*
2240 * This method notifies any AWTEventListeners that an event
|
2008 * @throws SecurityException
2009 * if a security manager exists and its
2010 * <code>checkPermission</code> method doesn't allow the operation.
2011 * @see #removeAWTEventListener
2012 * @see #getAWTEventListeners
2013 * @see SecurityManager#checkPermission
2014 * @see java.awt.AWTEvent
2015 * @see java.awt.AWTPermission
2016 * @see java.awt.event.AWTEventListener
2017 * @see java.awt.event.AWTEventListenerProxy
2018 * @since 1.2
2019 */
2020 public void addAWTEventListener(AWTEventListener listener, long eventMask) {
2021 AWTEventListener localL = deProxyAWTEventListener(listener);
2022
2023 if (localL == null) {
2024 return;
2025 }
2026 SecurityManager security = System.getSecurityManager();
2027 if (security != null) {
2028 security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
2029 }
2030 synchronized (this) {
2031 SelectiveAWTEventListener selectiveListener =
2032 (SelectiveAWTEventListener)listener2SelectiveListener.get(localL);
2033
2034 if (selectiveListener == null) {
2035 // Create a new selectiveListener.
2036 selectiveListener = new SelectiveAWTEventListener(localL,
2037 eventMask);
2038 listener2SelectiveListener.put(localL, selectiveListener);
2039 eventListener = ToolkitEventMulticaster.add(eventListener,
2040 selectiveListener);
2041 }
2042 // OR the eventMask into the selectiveListener's event mask.
2043 selectiveListener.orEventMasks(eventMask);
2044
2045 enabledOnToolkitMask |= eventMask;
2046
2047 long mask = eventMask;
2048 for (int i=0; i<LONG_BITS; i++) {
2077 * @throws SecurityException
2078 * if a security manager exists and its
2079 * <code>checkPermission</code> method doesn't allow the operation.
2080 * @see #addAWTEventListener
2081 * @see #getAWTEventListeners
2082 * @see SecurityManager#checkPermission
2083 * @see java.awt.AWTEvent
2084 * @see java.awt.AWTPermission
2085 * @see java.awt.event.AWTEventListener
2086 * @see java.awt.event.AWTEventListenerProxy
2087 * @since 1.2
2088 */
2089 public void removeAWTEventListener(AWTEventListener listener) {
2090 AWTEventListener localL = deProxyAWTEventListener(listener);
2091
2092 if (listener == null) {
2093 return;
2094 }
2095 SecurityManager security = System.getSecurityManager();
2096 if (security != null) {
2097 security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
2098 }
2099
2100 synchronized (this) {
2101 SelectiveAWTEventListener selectiveListener =
2102 (SelectiveAWTEventListener)listener2SelectiveListener.get(localL);
2103
2104 if (selectiveListener != null) {
2105 listener2SelectiveListener.remove(localL);
2106 int[] listenerCalls = selectiveListener.getCalls();
2107 for (int i=0; i<LONG_BITS; i++) {
2108 calls[i] -= listenerCalls[i];
2109 assert calls[i] >= 0: "Negative Listeners count";
2110
2111 if (calls[i] == 0) {
2112 enabledOnToolkitMask &= ~(1L<<i);
2113 }
2114 }
2115 }
2116 eventListener = ToolkitEventMulticaster.remove(eventListener,
2117 (selectiveListener == null) ? localL : selectiveListener);
2148 * Note that listener objects
2149 * added multiple times appear only once in the returned array.
2150 *
2151 * @return all of the <code>AWTEventListener</code>s or an empty
2152 * array if no listeners are currently registered
2153 * @throws SecurityException
2154 * if a security manager exists and its
2155 * <code>checkPermission</code> method doesn't allow the operation.
2156 * @see #addAWTEventListener
2157 * @see #removeAWTEventListener
2158 * @see SecurityManager#checkPermission
2159 * @see java.awt.AWTEvent
2160 * @see java.awt.AWTPermission
2161 * @see java.awt.event.AWTEventListener
2162 * @see java.awt.event.AWTEventListenerProxy
2163 * @since 1.4
2164 */
2165 public AWTEventListener[] getAWTEventListeners() {
2166 SecurityManager security = System.getSecurityManager();
2167 if (security != null) {
2168 security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
2169 }
2170 synchronized (this) {
2171 EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
2172
2173 AWTEventListener[] ret = new AWTEventListener[la.length];
2174 for (int i = 0; i < la.length; i++) {
2175 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
2176 AWTEventListener tempL = sael.getListener();
2177 //assert tempL is not an AWTEventListenerProxy - we should
2178 // have weeded them all out
2179 // don't want to wrap a proxy inside a proxy
2180 ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL);
2181 }
2182 return ret;
2183 }
2184 }
2185
2186 /**
2187 * Returns an array of all the <code>AWTEventListener</code>s
2188 * registered on this toolkit which listen to all of the event
2200 * @param eventMask the bitmask of event types to listen for
2201 * @return all of the <code>AWTEventListener</code>s registered
2202 * on this toolkit for the specified
2203 * event types, or an empty array if no such listeners
2204 * are currently registered
2205 * @throws SecurityException
2206 * if a security manager exists and its
2207 * <code>checkPermission</code> method doesn't allow the operation.
2208 * @see #addAWTEventListener
2209 * @see #removeAWTEventListener
2210 * @see SecurityManager#checkPermission
2211 * @see java.awt.AWTEvent
2212 * @see java.awt.AWTPermission
2213 * @see java.awt.event.AWTEventListener
2214 * @see java.awt.event.AWTEventListenerProxy
2215 * @since 1.4
2216 */
2217 public AWTEventListener[] getAWTEventListeners(long eventMask) {
2218 SecurityManager security = System.getSecurityManager();
2219 if (security != null) {
2220 security.checkPermission(SecurityConstants.AWT.ALL_AWT_EVENTS_PERMISSION);
2221 }
2222 synchronized (this) {
2223 EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
2224
2225 java.util.List list = new ArrayList(la.length);
2226
2227 for (int i = 0; i < la.length; i++) {
2228 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
2229 if ((sael.getEventMask() & eventMask) == eventMask) {
2230 //AWTEventListener tempL = sael.getListener();
2231 list.add(new AWTEventListenerProxy(sael.getEventMask(),
2232 sael.getListener()));
2233 }
2234 }
2235 return (AWTEventListener[])list.toArray(new AWTEventListener[0]);
2236 }
2237 }
2238
2239 /*
2240 * This method notifies any AWTEventListeners that an event
|