home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / TRANSPAR.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  4.1 KB  |  129 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.output.drawable;
  5. import sub_arctic.output.transparent_drawable;
  6. import sub_arctic.lib.sub_arctic_error;
  7.  
  8. /** 
  9.  * This is a container class (a subclass of shrink_wrap_container) that
  10.  * draws its child subtrees using a transparent drawable.  That drawable 
  11.  * manipulates all the images drawn in it to be translucent at some 
  12.  * transparency percentage (unfortunately text, lines, etc. remain opaque).
  13.  *
  14.  * @author Scott Hudson
  15.  */
  16. public class transparency_container extends shrink_wrap_container {
  17.  
  18.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  19.   /**
  20.    * This constant represents the alpha value for an image which is
  21.    * completely opaque (has no transparency factor).
  22.    */
  23.   public static final int OPAQUE=255;
  24.   /**
  25.    * This constant represents the alpha value for an image which is
  26.    * completely transparent (and thus invisible).
  27.    */
  28.   public static final int TRANSPARENT=0;
  29.   /**
  30.    * This constant represents the alpha value for an image which is
  31.    * 1/2 transparent and 1/2 opaque.
  32.    */
  33.   public static final int HALF_TRANSPARENT=127;
  34.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  35.  
  36.    /** 
  37.     * Full constructor.
  38.     * @param int xv    initial x position of the container.
  39.     * @param int yv    initial y position of the container.
  40.     * @param int alpha minimum transparency value (0 == fully transparent, 
  41.     *                  255 = fully opaque).  The transparency of images will
  42.     *                  be set to the minimum of this and their original 
  43.     *                  transparency.
  44.     */
  45.    public transparency_container(int xv,int yv, int alpha)
  46.      {
  47.        super(xv,yv,0,false);
  48.        
  49.        if ((alpha<TRANSPARENT) ||
  50.        (alpha>OPAQUE)) {
  51.      throw new sub_arctic_error("Invalid alpha value: " + alpha);
  52.        }
  53.        _alpha_value = alpha;
  54.      }
  55.  
  56.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  57.  
  58.    /** 
  59.     * Constructor with default 50% transparency.
  60.     * @param int xv    initial x position of the container.
  61.     * @param int yv    initial y position of the container.
  62.     */
  63.    public transparency_container(int xv, int yv) 
  64.      {
  65.        this(xv,yv, HALF_TRANSPARENT);
  66.      }
  67.  
  68.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  69.  
  70.    /** Min transparency value. 255 is fully opaque, 0 is fully transparent. */ 
  71.    protected int _alpha_value;
  72.  
  73.    /** 
  74.     * Min transparency value. 255 is fully opaque, 0 is fully transparent. 
  75.     * @return int min transparency value.
  76.     */ 
  77.    public int alpha_value() {return _alpha_value;}
  78.  
  79.    /** 
  80.     * Set the min transparency value. 255 is fully opaque, 0 is fully 
  81.     * transparent. 
  82.     * @param int av new min transparency value.
  83.     */ 
  84.    public void set_alpha_value(int av) 
  85.      {
  86.        if ((av<TRANSPARENT) ||
  87.        (av>OPAQUE)) {
  88.      throw new sub_arctic_error("Invalid alpha value: " + av);
  89.        }
  90.        _alpha_value = av;
  91.        damage_self();
  92.       }
  93.  
  94.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  95.  
  96.    /** 
  97.     * Draw self.  We draw our children using special transparent_drawable. 
  98.     * @param drawable d the surface we draw on.
  99.     */ 
  100.    protected void draw_self_local(drawable d)
  101.      {
  102.        transparent_drawable transp_d;
  103.        
  104.        transp_d = new transparent_drawable(d, alpha_value());
  105.  
  106.        draw_children(transp_d);
  107.      }
  108.  
  109.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  110. }
  111.     
  112.  
  113. /*=========================== COPYRIGHT NOTICE ===========================
  114.  
  115. This file is part of the subArctic user interface toolkit.
  116.  
  117. Copyright (c) 1996 Scott Hudson and Ian Smith
  118. All rights reserved.
  119.  
  120. The subArctic system is freely available for most uses under the terms
  121. and conditions described in 
  122.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  123. and appearing in full in the lib/interactor.java source file.
  124.  
  125. The current release and additional information about this software can be 
  126. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  127.  
  128. ========================================================================*/
  129.