📄 toolkit.java
字号:
+ "environment."); return null; } /** * Returns the supported cursor dimension which is closest to the * desired sizes. * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) { if (GraphicsEnvironment.isHeadless()) throw new HeadlessException("No best cursor size in an headless " + "graphics environment."); return new Dimension (0,0); } /** * Returns the maximum number of colors the Toolkit supports in a custom * cursor palette. * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ public int getMaximumCursorColors() { return 0; } /** * Returns whether Toolkit supports this state for Frames. * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. * * @since 1.4 */ public boolean isFrameStateSupported(int state) { return false; } /** * Returns the value of the property with the specified name, or the * default value if the property does not exist. * * @param key The name of the property to retrieve. * @param def The default value of the property. */ public static String getProperty(String key, String def) { return props.getProperty(key, def); } /** * Returns the event queue that is suitable for the calling context. * * <p>Despite the word “System” in the name of this * method, a toolkit may provide different event queues for each * applet. There is no guarantee that the same queue is shared * system-wide. * * <p>The implementation first checks whether a * SecurityManager has been installed. If so, its {@link * java.lang.SecurityManager#checkAwtEventQueueAccess()} method gets * called. The security manager will throw a SecurityException if it * does not grant the permission to access the event queue. * * <p>Next, the call is delegated to {@link * #getSystemEventQueueImpl()}. * * @return The event queue for this applet (or application). * * @throws SecurityException if a security manager has been * installed, and it does not grant the permission to access the * event queue. */ public final EventQueue getSystemEventQueue() { SecurityManager sm; sm = System.getSecurityManager(); if (sm != null) sm.checkAwtEventQueueAccess(); return getSystemEventQueueImpl(); } /** * Returns the event queue that is suitable for the calling context. * * <p>Despite the word “System” in the name of this * method, a toolkit may provide different event queues for each * applet. There is no guarantee that the same queue is shared * system-wide. * * <p>No security checks are performed, which is why this method * may only be called by Toolkits. * * @see #getSystemEventQueue() */ protected abstract EventQueue getSystemEventQueueImpl(); /** * @since 1.3 */ public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e); /** * @since 1.3 */ public DragGestureRecognizer createDragGestureRecognizer(Class recognizer, DragSource ds, Component comp, int actions, DragGestureListener l) { return null; } public final Object getDesktopProperty(String propertyName) { return desktopProperties.get(propertyName); } protected final void setDesktopProperty(String name, Object newValue) { Object oldValue = getDesktopProperty(name); desktopProperties.put(name, newValue); desktopPropsSupport.firePropertyChange(name, oldValue, newValue); } protected Object lazilyLoadDesktopProperty(String name) { // FIXME - what is this?? return null; } protected void initializeDesktopProperties() { // Overridden by toolkit implementation? } public void addPropertyChangeListener(String name, PropertyChangeListener pcl) { desktopPropsSupport.addPropertyChangeListener(name, pcl); } public void removePropertyChangeListener(String name, PropertyChangeListener pcl) { desktopPropsSupport.removePropertyChangeListener(name, pcl); } /** * @since 1.4 */ public PropertyChangeListener[] getPropertyChangeListeners() { return desktopPropsSupport.getPropertyChangeListeners(); } /** * @since 1.4 */ public PropertyChangeListener[] getPropertyChangeListeners(String name) { return desktopPropsSupport.getPropertyChangeListeners(name); } /** * Adds an AWTEventListener to this toolkit. This listener is informed about * all events that pass the eventqueue that match the specified * <code>evenMask</code>. The <code>eventMask</code> is an ORed combination * of event masks as defined in {@link AWTEvent}. * * If a security manager is installed, it is asked first if an * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. * This may result in a <code>SecurityException</code> beeing thrown. * * It is not recommended to use this kind of notification for normal * applications. It is intended solely for the purpose of debugging and to * support special facilities. * * @param listener the listener to add * @param eventMask the event mask of event types which the listener is * interested in * * @since 1.2 * * @throws SecurityException if there is a <code>SecurityManager</code> that * doesn't grant * <code>AWTPermission("listenToAllAWTEvents")</code> * * @see #getAWTEventListeners() * @see #getAWTEventListeners(long) * @see #removeAWTEventListener(AWTEventListener) */ public void addAWTEventListener(AWTEventListener listener, long eventMask) { // First we must check the security permissions. SecurityManager s = System.getSecurityManager(); if (s != null) s.checkPermission(new AWTPermission("listenToAllAWTEvents")); // Go through the list and check if the requested listener is already // registered. boolean found = false; for (int i = 0; i < awtEventListeners.length; ++i) { AWTEventListenerProxy proxy = awtEventListeners[i]; if (proxy.getListener() == listener) { found = true; // Modify the proxies event mask to include the new event mask. AWTEventListenerProxy newProxy = new AWTEventListenerProxy(proxy.getEventMask() | eventMask, listener); awtEventListeners[i] = newProxy; break; } } // If that listener was not found, then add it. if (! found) { AWTEventListenerProxy proxy = new AWTEventListenerProxy(eventMask, listener); AWTEventListenerProxy[] newArray = new AWTEventListenerProxy[awtEventListeners.length + 1]; System.arraycopy(awtEventListeners, 0, newArray, 0, awtEventListeners.length); newArray[newArray.length - 1] = proxy; awtEventListeners = newArray; } } /** * Removes an AWT event listener from this toolkit. This listener is no * longer informed of any event types it was registered in. * * If a security manager is installed, it is asked first if an * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. * This may result in a <code>SecurityException</code> beeing thrown. * * It is not recommended to use this kind of notification for normal * applications. It is intended solely for the purpose of debugging and to * support special facilities. * * @param listener the listener to remove * * @throws SecurityException if there is a <code>SecurityManager</code> that * doesn't grant * <code>AWTPermission("listenToAllAWTEvents")</code> * * @since 1.2 * * @see #addAWTEventListener(AWTEventListener, long) * @see #getAWTEventListeners() * @see #getAWTEventListeners(long) */ public void removeAWTEventListener(AWTEventListener listener) { // First we must check the security permissions. SecurityManager s = System.getSecurityManager(); if (s != null) s.checkPermission(new AWTPermission("listenToAllAWTEvents")); // Find the index of the listener. int index = -1; for (int i = 0; i < awtEventListeners.length; ++i) { AWTEventListenerProxy proxy = awtEventListeners[i]; if (proxy.getListener() == listener) { index = i; break; } } // Copy over the arrays and leave out the removed element. if (index != -1) { AWTEventListenerProxy[] newArray = new AWTEventListenerProxy[awtEventListeners.length - 1]; if (index > 0) System.arraycopy(awtEventListeners, 0, newArray, 0, index); if (index < awtEventListeners.length - 1) System.arraycopy(awtEventListeners, index + 1, newArray, index, awtEventListeners.length - index - 1); awtEventListeners = newArray; } } /** * Returns all registered AWT event listeners. This method returns a copy of * the listener array, so that application cannot trash the listener list. * * If a security manager is installed, it is asked first if an * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. * This may result in a <code>SecurityException</code> beeing thrown. * * It is not recommended to use this kind of notification for normal * applications. It is intended solely for the purpose of debugging and to * support special facilities. * * @return all registered AWT event listeners * * @throws SecurityException if there is a <code>SecurityManager</code> that * doesn't grant * <code>AWTPermission("listenToAllAWTEvents")</code> * * @since 1.4 * * @see #addAWTEventListener(AWTEventListener, long) * @see #removeAWTEventListener(AWTEventListener) * @see #getAWTEventListeners(long) */ public AWTEventListener[] getAWTEventListeners() { // First we must check the security permissions. SecurityManager s = System.getSecurityManager(); if (s != null) s.checkPermission(new AWTPermission("listenToAllAWTEvents")); // Create a copy of the array. AWTEventListener[] copy = new AWTEventListener[awtEventListeners.length]; System.arraycopy(awtEventListeners, 0, copy, 0, awtEventListeners.length); return copy; } /** * Returns all registered AWT event listeners that listen for events with * the specified <code>eventMask</code>. This method returns a copy of * the listener array, so that application cannot trash the listener list. * * If a security manager is installed, it is asked first if an * <code>AWTPermission("listenToAllAWTEvents")</code> is allowed. * This may result in a <code>SecurityException</code> beeing thrown. * * It is not recommended to use this kind of notification for normal * applications. It is intended solely for the purpose of debugging and to * support special facilities. * * @param mask the event mask * * @throws SecurityException if there is a <code>SecurityManager</code> that * doesn't grant * <code>AWTPermission("listenToAllAWTEvents")</code> * * * @since 1.4 * * @see #addAWTEventListener(AWTEventListener, long) * @see #removeAWTEventListener(AWTEventListener) * @see #getAWTEventListeners() */ public AWTEventListener[] getAWTEventListeners(long mask) { // First we must check the security permissions. SecurityManager s = System.getSecurityManager(); if (s != null) s.checkPermission(new AWTPermission("listenToAllAWTEvents")); // Create a copy of the array with only the requested listeners in it. ArrayList l = new ArrayList(awtEventListeners.length); for (int i = 0; i < awtEventListeners.length; ++i) { if ((awtEventListeners[i].getEventMask() & mask) != 0) l.add(awtEventListeners[i]); } return (AWTEventListener[] ) l.toArray(new AWTEventListener[l.size()]); } /** * Dispatches events to listeners registered to this Toolkit. This is called * by {@link Component#dispatchEventImpl(AWTEvent)} in order to dispatch * events globally. * * @param ev the event to dispatch */ void globalDispatchEvent(AWTEvent ev) { // We do not use the accessor methods here because they create new // arrays each time. We must be very efficient, so we access this directly. for (int i = 0; i < awtEventListeners.length; ++i) { AWTEventListenerProxy proxy = awtEventListeners[i]; if ((proxy.getEventMask() & AWTEvent.eventIdToMask(ev.getID())) != 0) proxy.eventDispatched(ev); } } /** * @since 1.3 */ public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight);} // class Toolkit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -