home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Image.java < prev    next >
Text File  |  1997-10-01  |  8KB  |  205 lines

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