home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / Image.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  7.5 KB  |  191 lines

  1. /*
  2.  * @(#)Image.java    1.25 98/03/18
  3.  *
  4.  * Copyright 1995-1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.awt.image.ImageProducer;
  17. import java.awt.image.ImageObserver;
  18. import java.awt.image.ImageFilter;
  19. import java.awt.image.FilteredImageSource;
  20. import java.awt.image.AreaAveragingScaleFilter;
  21. import java.awt.image.ReplicateScaleFilter;
  22.  
  23. /**
  24.  * The abstract class <code>Image</code> is the superclass of all 
  25.  * classes that represent graphical images. The image must be 
  26.  * obtained in a platform-specific manner.
  27.  *
  28.  * @version     1.25, 03/18/98
  29.  * @author     Sami Shaio
  30.  * @author     Arthur van Hoff
  31.  * @since       JDK1.0
  32.  */
  33. public abstract class Image {
  34.     /**
  35.      * Determines the width of the image. If the width is not yet known, 
  36.      * this method returns <code>-1</code> and the specified   
  37.      * <code>ImageObserver</code> object is notified later.
  38.      * @param     observer   an object waiting for the image to be loaded.
  39.      * @return    the width of this image, or <code>-1</code> 
  40.      *                   if the width is not yet known.
  41.      * @see       java.awt.Image#getHeight
  42.      * @see       java.awt.image.ImageObserver
  43.      */
  44.     public abstract int getWidth(ImageObserver observer);
  45.  
  46.     /**
  47.      * Determines the height of the image. If the height is not yet known, 
  48.      * this method returns <code>-1</code> and the specified  
  49.      * <code>ImageObserver</code> object is notified later.
  50.      * @param     observer   an object waiting for the image to be loaded.
  51.      * @return    the height of this image, or <code>-1</code> 
  52.      *                   if the height is not yet known.
  53.      * @see       java.awt.Image#getWidth
  54.      * @see       java.awt.image.ImageObserver
  55.      */
  56.     public abstract int getHeight(ImageObserver observer);
  57.  
  58.     /**
  59.      * Gets the object that produces the pixels for the image.
  60.      * This method is called by the image filtering classes and by 
  61.      * methods that perform image conversion and scaling.
  62.      * @return     the image producer that produces the pixels 
  63.      *                                  for this image.
  64.      * @see        java.awt.image.ImageProducer
  65.      */
  66.     public abstract ImageProducer getSource();
  67.  
  68.     /**
  69.      * Creates a graphics context for drawing to an off-screen image. 
  70.      * This method can only be called for off-screen images. 
  71.      * @return  a graphics context to draw to the off-screen image. 
  72.      * @see     java.awt.Graphics
  73.      * @see     java.awt.Component#createImage(int, int)
  74.      */
  75.     public abstract Graphics getGraphics();
  76.  
  77.     /**
  78.      * Gets a property of this image by name. 
  79.      * <p>
  80.      * Individual property names are defined by the various image 
  81.      * formats. If a property is not defined for a particular image, this 
  82.      * method returns the <code>UndefinedProperty</code> object. 
  83.      * <p>
  84.      * If the properties for this image are not yet known, this method 
  85.      * returns <code>null</code>, and the <code>ImageObserver</code> 
  86.      * object is notified later. 
  87.      * <p>
  88.      * The property name <code>"comment"</code> should be used to store 
  89.      * an optional comment which can be presented to the application as a 
  90.      * description of the image, its source, or its author. 
  91.      * @param       name   a property name.
  92.      * @param       observer   an object waiting for this image to be loaded.
  93.      * @return      the value of the named property.
  94.      * @see         java.awt.image.ImageObserver
  95.      * @see         java.awt.Image#UndefinedProperty
  96.      */
  97.     public abstract Object getProperty(String name, ImageObserver observer);
  98.  
  99.     /**
  100.      * The <code>UndefinedProperty</code> object should be returned whenever a
  101.      * property which was not defined for a particular image is fetched.
  102.      */
  103.     public static final Object UndefinedProperty = new Object();
  104.  
  105.     /**
  106.      * Creates a scaled version of this image.
  107.      * A new <code>Image</code> object is returned which will render 
  108.      * the image at the specified <code>width</code> and 
  109.      * <code>height</code> by default.  The new <code>Image</code> object
  110.      * may be loaded asynchronously even if the original source image
  111.      * has already been loaded completely.  If either the <code>width</code> 
  112.      * or <code>height</code> is a negative number then a value is 
  113.      * substituted to maintain the aspect ratio of the original image 
  114.      * dimensions.
  115.      * @param width the width to which to scale the image.
  116.      * @param height the height to which to scale the image.
  117.      * @param hints flags to indicate the type of algorithm to use
  118.      * for image resampling.
  119.      * @return     a scaled version of the image.
  120.      * @see        java.awt.Image#SCALE_DEFAULT
  121.      * @see        java.awt.Image#SCALE_FAST 
  122.      * @see        java.awt.Image#SCALE_SMOOTH
  123.      * @see        java.awt.Image#SCALE_REPLICATE
  124.      * @see        java.awt.Image#SCALE_AVERAGE 
  125.      * @since      JDK1.1
  126.      */
  127.     public Image getScaledInstance(int width, int height, int hints) {
  128.     ImageFilter filter;
  129.     if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
  130.         filter = new AreaAveragingScaleFilter(width, height);
  131.     } else {
  132.         filter = new ReplicateScaleFilter(width, height);
  133.     }
  134.     ImageProducer prod;
  135.     prod = new FilteredImageSource(getSource(), filter);
  136.     return Toolkit.getDefaultToolkit().createImage(prod);
  137.     }
  138.  
  139.     /**
  140.      * Use the default image-scaling algorithm.
  141.      * @since JDK1.1
  142.      */
  143.     public static final int SCALE_DEFAULT = 1;
  144.  
  145.     /**
  146.      * Choose an image-scaling algorithm that gives higher priority
  147.      * to scaling speed than smoothness of the scaled image.
  148.      * @since JDK1.1
  149.      */
  150.     public static final int SCALE_FAST = 2;
  151.  
  152.     /**
  153.      * Choose an image-scaling algorithm that gives higher priority
  154.      * to image smoothness than scaling speed.
  155.      * @since JDK1.1
  156.      */
  157.     public static final int SCALE_SMOOTH = 4;
  158.  
  159.     /**
  160.      * Use the image scaling algorithm embodied in the 
  161.      * <code>ReplicateScaleFilter</code> class.  
  162.      * The <code>Image</code> object is free to substitute a different filter 
  163.      * that performs the same algorithm yet integrates more efficiently
  164.      * into the imaging infrastructure supplied by the toolkit.
  165.      * @see        java.awt.image.ReplicateScaleFilter
  166.      * @since      JDK1.1
  167.      */
  168.     public static final int SCALE_REPLICATE = 8;
  169.  
  170.     /**
  171.      * Use the Area Averaging image scaling algorithm.  The
  172.      * image object is free to substitute a different filter that
  173.      * performs the same algorithm yet integrates more efficiently
  174.      * into the image infrastructure supplied by the toolkit.
  175.      * @see java.awt.image.AreaAveragingScaleFilter
  176.      * @since JDK1.1
  177.      */
  178.     public static final int SCALE_AREA_AVERAGING = 16;
  179.  
  180.     /**
  181.      * Flushes all resources being used by this Image object.  This
  182.      * includes any pixel data that is being cached for rendering to
  183.      * the screen as well as any system resources that are being used
  184.      * to store data or pixels for the image.  The image is reset to
  185.      * a state similar to when it was first created so that if it is
  186.      * again rendered, the image data will have to be recreated or
  187.      * fetched again from its source.
  188.      */
  189.     public abstract void flush();
  190. }
  191.