component.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,357 行 · 第 1/5 页

JAVA
2,357
字号
   * @param tm milliseconds before this component should be repainted   * @param x the X coordinate of the upper left of the region to repaint   * @param y the Y coordinate of the upper left of the region to repaint   * @param width the width of the region to repaint   * @param height the height of the region to repaint   * @see #update(Graphics)   */  public void repaint(long tm, int x, int y, int width, int height)  {    // Handle lightweight repainting by forwarding to native parent    if (isLightweight() && parent != null)      {        if (parent != null)          parent.repaint(tm, x + getX(), y + getY(), width, height);      }    else if (peer != null)      peer.repaint(tm, x, y, width, height);  }  /**   * Prints this component. This method is provided so that printing can be   * done in a different manner from painting. However, the implementation   * in this class simply calls the <code>paint()</code> method.   *   * @param g the graphics context of the print device   *    * @see #paint(Graphics)   */  public void print(Graphics g)  {    paint(g);  }  /**   * Prints this component, including all sub-components. This method is   * provided so that printing can be done in a different manner from   * painting. However, the implementation in this class simply calls the   * <code>paintAll()</code> method.   *   * @param g the graphics context of the print device   *    * @see #paintAll(Graphics)   */  public void printAll(Graphics g)  {    paintAll(g);  }  /**   * Called when an image has changed so that this component is repainted.   * This incrementally draws an image as more bits are available, when   * possible. Incremental drawing is enabled if the system property   * <code>awt.image.incrementalDraw</code> is not present or is true, in which   * case the redraw rate is set to 100ms or the value of the system property   * <code>awt.image.redrawrate</code>.   *   * <p>The coordinate system used depends on the particular flags.   *   * @param img the image that has been updated   * @param flags tlags as specified in <code>ImageObserver</code>   * @param x the X coordinate   * @param y the Y coordinate   * @param w the width   * @param h the height   * @return false if the image is completely loaded, loading has been   * aborted, or an error has occurred.  true if more updates are   * required.   * @see ImageObserver   * @see Graphics#drawImage(Image, int, int, Color, ImageObserver)   * @see Graphics#drawImage(Image, int, int, ImageObserver)   * @see Graphics#drawImage(Image, int, int, int, int, Color, ImageObserver)   * @see Graphics#drawImage(Image, int, int, int, int, ImageObserver)   * @see ImageObserver#imageUpdate(Image, int, int, int, int, int)   */  public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)  {    if ((flags & (FRAMEBITS | ALLBITS)) != 0)      repaint ();    else if ((flags & SOMEBITS) != 0)      {	if (incrementalDraw)	  {	    if (redrawRate != null)	      {		long tm = redrawRate.longValue();		if (tm < 0)		  tm = 0;		repaint (tm);	      }	    else	      repaint (100);	  }      }    return (flags & (ALLBITS | ABORT | ERROR)) == 0;  }  /**   * Creates an image from the specified producer.   *   * @param producer the image procedure to create the image from   * @return the resulting image   */  public Image createImage(ImageProducer producer)  {    // Sun allows producer to be null.    if (peer != null)      return peer.createImage(producer);    else      return getToolkit().createImage(producer);  }  /**   * Creates an image with the specified width and height for use in   * double buffering. Headless environments do not support images.   *   * @param width the width of the image   * @param height the height of the image   * @return the requested image, or null if it is not supported   */  public Image createImage (int width, int height)  {    Image returnValue = null;    if (!GraphicsEnvironment.isHeadless ())      {	if (isLightweight () && parent != null)	  returnValue = parent.createImage (width, height);	else if (peer != null)	  returnValue = peer.createImage (width, height);      }    return returnValue;  }  /**   * Creates an image with the specified width and height for use in   * double buffering. Headless environments do not support images.   *   * @param width the width of the image   * @param height the height of the image   * @return the requested image, or null if it is not supported   * @since 1.4   */  public VolatileImage createVolatileImage(int width, int height)  {    if (GraphicsEnvironment.isHeadless())      return null;    GraphicsConfiguration config = getGraphicsConfiguration();    return config == null ? null      : config.createCompatibleVolatileImage(width, height);  }  /**   * Creates an image with the specified width and height for use in   * double buffering. Headless environments do not support images. The image   * will support the specified capabilities.   *   * @param width the width of the image   * @param height the height of the image   * @param caps the requested capabilities   * @return the requested image, or null if it is not supported   * @throws AWTException if a buffer with the capabilities cannot be created   * @since 1.4   */  public VolatileImage createVolatileImage(int width, int height,                                           ImageCapabilities caps)    throws AWTException  {    if (GraphicsEnvironment.isHeadless())      return null;    GraphicsConfiguration config = getGraphicsConfiguration();    return config == null ? null      : config.createCompatibleVolatileImage(width, height, caps);  }  /**   * Prepares the specified image for rendering on this component.   *   * @param image the image to prepare for rendering   * @param observer the observer to notify of image preparation status   * @return true if the image is already fully prepared   * @throws NullPointerException if image is null   */  public boolean prepareImage(Image image, ImageObserver observer)  {    return prepareImage(image, image.getWidth(observer),                        image.getHeight(observer), observer);  }  /**   * Prepares the specified image for rendering on this component at the   * specified scaled width and height   *   * @param image the image to prepare for rendering   * @param width the scaled width of the image   * @param height the scaled height of the image   * @param observer the observer to notify of image preparation status   * @return true if the image is already fully prepared   */  public boolean prepareImage(Image image, int width, int height,                              ImageObserver observer)  {    if (peer != null)	return peer.prepareImage(image, width, height, observer);    else	return getToolkit().prepareImage(image, width, height, observer);  }  /**   * Returns the status of the loading of the specified image. The value   * returned will be those flags defined in <code>ImageObserver</code>.   *   * @param image the image to check on   * @param observer the observer to notify of image loading progress   * @return the image observer flags indicating the status of the load   * @see #prepareImage(Image, int, int, ImageObserver)   * @see Toolkit#checkImage(Image, int, int, ImageObserver)   * @throws NullPointerException if image is null   */  public int checkImage(Image image, ImageObserver observer)  {    return checkImage(image, -1, -1, observer);  }  /**   * Returns the status of the loading of the specified image. The value   * returned will be those flags defined in <code>ImageObserver</code>.   *   * @param image the image to check on   * @param width the scaled image width   * @param height the scaled image height   * @param observer the observer to notify of image loading progress   * @return the image observer flags indicating the status of the load   * @see #prepareImage(Image, int, int, ImageObserver)   * @see Toolkit#checkImage(Image, int, int, ImageObserver)   */  public int checkImage(Image image, int width, int height,                        ImageObserver observer)  {    if (peer != null)      return peer.checkImage(image, width, height, observer);    return getToolkit().checkImage(image, width, height, observer);  }  /**   * Sets whether paint messages delivered by the operating system should be   * ignored. This does not affect messages from AWT, except for those   * triggered by OS messages. Setting this to true can allow faster   * performance in full-screen mode or page-flipping.   *   * @param ignoreRepaint the new setting for ignoring repaint events   * @see #getIgnoreRepaint()   * @see BufferStrategy   * @see GraphicsDevice#setFullScreenWindow(Window)   * @since 1.4   */  public void setIgnoreRepaint(boolean ignoreRepaint)  {    this.ignoreRepaint = ignoreRepaint;  }  /**   * Test whether paint events from the operating system are ignored.   *   * @return the status of ignoring paint events   * @see #setIgnoreRepaint(boolean)   * @since 1.4   */  public boolean getIgnoreRepaint()  {    return ignoreRepaint;  }  /**   * Tests whether or not the specified point is contained within this   * component. Coordinates are relative to this component.   *   * @param x the X coordinate of the point to test   * @param y the Y coordinate of the point to test   * @return true if the point is within this component   * @see #getComponentAt(int, int)   */  public boolean contains(int x, int y)  {    return inside (x, y);  }  /**   * Tests whether or not the specified point is contained within this   * component. Coordinates are relative to this component.   *   * @param x the X coordinate of the point to test   * @param y the Y coordinate of the point to test   * @return true if the point is within this component   * @deprecated use {@link #contains(int, int)} instead   */  public boolean inside(int x, int y)  {    return x >= 0 && y >= 0 && x < width && y < height;  }  /**   * Tests whether or not the specified point is contained within this   * component. Coordinates are relative to this component.   *   * @param p the point to test   * @return true if the point is within this component   * @throws NullPointerException if p is null   * @see #getComponentAt(Point)   * @since 1.1   */  public boolean contains(Point p)  {    return contains (p.x, p.y);  }  /**   * Returns the component occupying the position (x,y). This will either   * be this component, an immediate child component, or <code>null</code>   * if neither of the first two occupies the specified location.   *   * @param x the X coordinate to search for components at   * @param y the Y coordinate to search for components at   * @return the component at the specified location, or null   * @see #contains(int, int)   */  public Component getComponentAt(int x, int y)  {    return locate (x, y);  }  /**   * Returns the component occupying the position (x,y). This will either   * be this component, an immediate child component, or <code>null</code>   * if neither of the first two occupies the specified location.   *   * @param x the X coordinate to search for components at   * @param y the Y coordinate to search for components at   * @return the component at the specified location, or null   * @deprecated use {@link #getComponentAt(int, int)} instead   */  public Component locate(int x, int y)  {    return contains (x, y) ? this : null;  }  /**   * Returns the component occupying the position (x,y). This will either   * be this component, an immediate child component, or <code>null</code>   * if neither of the first two occupies the specified location.   *   * @param p the point to search for components at   * @return the component at the specified location, or null   * @throws NullPointerException if p is null   * @see #contains(Point)   * @since 1.1   */  public Component getComponentAt(Point p)  {    return getComponentAt (p.x, p.y);  }  /**   * AWT 1.0 event delivery.   *   * Deliver an AWT 1.0 event to this Component.  This method simply   * calls {@link #postEvent}.   *   * @param e the event to deliver   * @deprecated use {@link #dispatchEvent (AWTEvent)} instead   */  public void deliverEvent (Event e)  {    postEvent (e);  }  /**   * Forwards AWT events to processEvent() if:<ul>   * <li>Events have been enabled for this type of event via   * <code>enableEvents()</code></li>,   * <li>There is at least one registered listener for this type of event</li>   * </ul>   *   * @param e the event to dispatch   */  public final void dispatchEvent(AWTEvent e)  {    // Some subclasses in the AWT package need to override this behavior,    // hence the use of dispatchEventImpl().    dispatchEventImpl(e);    if (peer != null && ! e.consumed)      peer.handleEvent(e);  }  /**   * AWT 1.0 event handler.   *   * This method simply calls handleEvent and returns the result.   *   * @param e the event to handle   * @return true if the event was handled, false otherwise   * @deprecated use {@link #dispatchEvent(AWTEvent)} instead   */  public boolean postEvent (Event e)  {    boolean handled = handleEvent (e);    if (!handled && getParent() != null)      // FIXME: need to translate event coordinates to parent's      // coordinate space.      handled = getParent ().postEvent (e);    return handled;  }  /**   * Adds the specified listener to this component. This is harmless if the   * listener is null, but if the listener has already been registered, it   * will now be registered twice.   *   * @param listener the new listener to add   * @see ComponentEvent   * @see #removeComponentListener(ComponentListener)   * @see #getComponentListeners()   * @since 1.1   */  public synchronized void addComponentListener(ComponentListener listener)  {    componentListener = AWTEventMulticaster.add(componentListener, listener);    if (componentListener != null)      enableEvents(AWTEvent.COMPONENT_EVENT_MASK);  }  /**   * Removes the specified listener from the component. This is harmless if   * the listener was not previously registered.   *   * @param listener the listener to remove   * @see ComponentEvent   * @see #addComponentListener(ComponentListener)   * @see #getComponentListeners()   * @since 1.1   */  public synchronized void removeComponentListener(ComponentListener listener)  {    componentListener = AWTEventMulticaster.remove(componentListener, listener);  }  /**   * Returns an array of all specified listeners registered on this component.   *   * @return an array of listeners   * @see #addComponentListener(ComponentListener)   * @see #removeComponentListener(ComponentListener)   * @since 1.4   */  public synchronized ComponentListener[] getComponentListeners()  {    return (ComponentListener[])      AWTEventMulticaster.getListeners(componentListener,                                       ComponentListener.class);  }  /**   * Adds the specified listener to this component. This is harmless if the   * listener is null, but if the listener has already been registered, it   * will now be registered twice.   *   * @param listener the new listener to add   * @see FocusEvent   * @se

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?