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

  1. package sub_arctic.lib;
  2.  
  3. import sub_arctic.output.loaded_image;
  4. import sub_arctic.output.drawable;
  5. import java.awt.Image;
  6.  
  7. /**
  8.  * This object simply displays an image on the screen. It has no input
  9.  * behavior... if you want input behavior, subclass this and implement one
  10.  * of the input protocols, such as clickable or pressable. <p>
  11.  *
  12.  * If you supply a null image, you will get a 10 x 10 blank rectangle
  13.  * when you try to display the icon.
  14.  
  15.  * @author Scott Hudson
  16.  */
  17. public class icon extends base_interactor {
  18.  
  19.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  20.  
  21.   /** 
  22.    * Full constructor for an icon.
  23.    * @param int          x   the x coordinate of the icon
  24.    * @param int          y   the y coordinate of the icon
  25.    * @param loaded_image img the image to display  (if you pass null for the 
  26.    *                         image you get a 10x10 blank square).
  27.    */
  28.   public icon(int x, int y, loaded_image img)
  29.     {
  30.       super(x,y);
  31.  
  32.       /* save instance variable */
  33.       _image = img;
  34.  
  35.       /* set it so we get intrinsic w & h set up */
  36.       set_image(img);
  37.     }
  38.  
  39.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  40.  
  41.   /** 
  42.    * Simple constructor for an icon.  This assumes you are going to 
  43.    * either explicitly set the position or use constraints to position 
  44.    * this object.
  45.    *
  46.    * @param loaded_image img the image to display  (if you pass null for the 
  47.    *                         image you get a 10x10 blank square).
  48.    */
  49.   public icon(loaded_image img)
  50.     {
  51.       super(0,0);
  52.  
  53.       /* save instance variable */
  54.       _image = img;
  55.  
  56.       /* set it so we get intrinsic w & h set up */
  57.       set_image(img);
  58.     }
  59.  
  60.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  61.     
  62.   /** Image for the icon. */
  63.   protected loaded_image _image;
  64.  
  65.   /** 
  66.    * Image for the icon. 
  67.    * @return loaded_image return the current image for this icon
  68.    */
  69.   public loaded_image image() {return _image; }
  70.  
  71.   /** 
  72.    * Set the image to use for this icon
  73.    * 
  74.    * @param loaded_image img the new image to use
  75.    */
  76.   public void set_image(loaded_image img) {
  77.     _image = img;
  78.  
  79.     /* if it doesn't have a size yet, just make it 10x10 */
  80.     if (_image==null) {
  81.       set_intrinsic_size(10,10);
  82.     } else {
  83.       /* set correct initial size */
  84.       set_intrinsic_size(_image.width(), _image.height());
  85.     }
  86.     damage_self();
  87.   }
  88.  
  89.    //had
  90.    //* @exception general PROPAGATED
  91.  
  92.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  93.  
  94.   /** 
  95.    * Draw the icon.
  96.    * @param drawable d the drawable to render this object on
  97.    */
  98.   protected void draw_self_local(drawable d)
  99.     {
  100.       if (_image==null) {
  101.     d.clearRect(0,0,w(),h());
  102.     d.drawRect(0,0,w()-1,h()-1);
  103.       } else {
  104.     d.drawImage(_image,0,0);
  105.       }
  106.     }
  107.  
  108.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  109.  
  110.   /** 
  111.    * Indicate that we intrinsically constrain both height & width.
  112.    * Thus, it is not modifiable by either the programmer or user.
  113.    * @return int return the constant indicating the correct intrinsic dimensions
  114.    */
  115.   public int intrinsic_constraints() {
  116.     return H | W;
  117.   }
  118.  
  119.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  120. }
  121. /*=========================== COPYRIGHT NOTICE ===========================
  122.  
  123. This file is part of the subArctic user interface toolkit.
  124.  
  125. Copyright (c) 1996 Scott Hudson and Ian Smith
  126. All rights reserved.
  127.  
  128. The subArctic system is freely available for most uses under the terms
  129. and conditions described in 
  130.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  131. and appearing in full in the lib/interactor.java source file.
  132.  
  133. The current release and additional information about this software can be 
  134. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  135.  
  136. ========================================================================*/
  137.