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

  1. package sub_arctic.lib;
  2. import sub_arctic.lib.sub_arctic_error;
  3.  
  4. /** 
  5.  * This is a small interactor subclass that just adds part_a and part_b 
  6.  * functionality to base_interactor.  It implements part_a and 
  7.  * part_b as simple integer attributes (i.e., not tied to anything else)
  8.  * and is useful either as a base class for something that needs parts, 
  9.  * or as a intermediary to pass on a value or compute an additional quantity.
  10.  * The source of this class is also a good guide to how to add part_a or part_b
  11.  * functionality to an existing class.
  12.  *
  13.  * @author Scott Hudson
  14.  */
  15. public class interactor_with_parts extends base_interactor {
  16.  
  17.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  18.  
  19.   /** 
  20.    * Indicate which values (coordinates/sizes) of this object are 
  21.    * intrinsically constrained by the internals of the object.  In this
  22.    * case we need to remove PART_A and PART_B from the set reported by our
  23.    * superclass.
  24.    *
  25.    * @return int the set of parts intrinsically constrained.
  26.    */
  27.   public int intrinsic_constraints()
  28.     {
  29.       return super.intrinsic_constraints() & ~(PART_A|PART_B);
  30.     }
  31.  
  32.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  33.  
  34.   /** Storage for part_a value */
  35.   protected int  _part_a = 0;
  36.  
  37.   /** Storage for part_b value */
  38.   protected int  _part_b = 0;
  39.  
  40.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  41.  
  42.   /** 
  43.    * Return the value of part_a after evaluating any attached constraints. 
  44.    * @return int the up-to-date value of part_a.
  45.    */
  46.   public int part_a() 
  47.     { 
  48.       /* evaluate and return the value */
  49.       eval_part_a();
  50.       return _part_a;
  51.     }
  52.  
  53.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  54.  
  55.   /** 
  56.    * Set part_a value directly bypassing the constraint system.  
  57.    * @param int v new value for part_a.
  58.    */
  59.   protected void set_raw_part_a(int v) 
  60.     {
  61.       /* don't do anything unless this is a change */
  62.       if (v != _part_a)
  63.         {
  64.           /* change the value and damage our image */
  65.           _part_a = v;
  66.           damage_self();
  67.         }
  68.     }
  69.  
  70.    //had:
  71.    //* @exception general 
  72.  
  73.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  74.  
  75.   /** 
  76.    * Set part_a of object.  
  77.    * @param int v new value for part_a
  78.    */
  79.   public void set_part_a(int v) 
  80.     {
  81.       /* if this has a constraint throw an exception */
  82.       if ((active_constraints() & PART_A) != 0)
  83.         throw new sub_arctic_error(
  84.           "Attempt to assign value to constrained part_a");
  85.       
  86.       /* don't do anything unless this is a change */
  87.       if (v != _part_a)
  88.       {
  89.         set_raw_part_a(v);
  90.         mark_part_a_ood();
  91.       }
  92.     }
  93.  
  94.    //had:
  95.    //* @exception cannot_assign if part_a is controlled by a constraint.
  96.  
  97.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  98.  
  99.   /** 
  100.    * Return the value of part_b after evaluating any attached constraints. 
  101.    * @return int the up-to-date value of part_b.
  102.    */
  103.   public int part_b() 
  104.     { 
  105.       /* evaluate and return the value */
  106.       eval_part_b();
  107.       return _part_b;
  108.     }
  109.  
  110.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  111.  
  112.   /** 
  113.    * Set part_b value directly bypassing the constraint system.  
  114.    * @param int v the new value for part_b.
  115.    */
  116.   protected void set_raw_part_b(int v) 
  117.     {
  118.       /* don't do anything unless this is a change */
  119.       if (v != _part_b)
  120.         {
  121.           /* change the value and damage our image */
  122.           _part_b = v;
  123.           damage_self();
  124.         }
  125.     }
  126.  
  127.    //had:
  128.    //* @exception general
  129.  
  130.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  131.  
  132.   /** 
  133.    * Set part_b of object.  
  134.    * @param int v new value for part_b.
  135.    */
  136.   public void set_part_b(int v) 
  137.     {
  138.       /* if this has a constraint throw an exception */
  139.       if ((active_constraints() & PART_B) != 0)
  140.         throw new sub_arctic_error(
  141.           "Attempt to assign value to constrained part_b");
  142.       
  143.       /* don't do anything unless this is a change */
  144.       if (v != _part_b)
  145.       {
  146.         set_raw_part_b(v);
  147.         mark_part_b_ood();
  148.       }
  149.     }
  150.  
  151.    //had:
  152.    //* @exception cannot_assign if part is controlled by a constraint.
  153.  
  154.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  155.  
  156.   /** 
  157.    * Full constructor. 
  158.    * @param int x_v the initial x position of the interactor.
  159.    * @param int y_v the initial y position of the interactor.
  160.    * @param int w_v the initial width of the interactor.
  161.    * @param int h_v the initial height of the interactor.
  162.    */
  163.   public interactor_with_parts(int x_v, int y_v, int w_v, int h_v)
  164.     {
  165.       super(x_v, y_v, w_v, h_v);
  166.     }
  167.  
  168.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  169.  
  170.   /** 
  171.    * Constructor that assumes a (temporary) default size 
  172.    * @param int x_v the initial x position of the interactor.
  173.    * @param int y_v the initial y position of the interactor.
  174.    */
  175.   public interactor_with_parts(int x_v, int y_v)
  176.     {
  177.       super(x_v, y_v);
  178.     }
  179.  
  180.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  181.  
  182.   /** 
  183.    * Constructor that assumes a position of 0,0, and a (temporary) default 
  184.    * size.
  185.    */
  186.   public interactor_with_parts()
  187.     {
  188.       super();
  189.     }
  190.  
  191.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  192. }
  193.  
  194. /*=========================== COPYRIGHT NOTICE ===========================
  195.  
  196. This file is part of the subArctic user interface toolkit.
  197.  
  198. Copyright (c) 1996 Scott Hudson and Ian Smith
  199. All rights reserved.
  200.  
  201. The subArctic system is freely available for most uses under the terms
  202. and conditions described in 
  203.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  204. and appearing in full in the lib/interactor.java source file.
  205.  
  206. The current release and additional information about this software can be 
  207. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  208.  
  209. ========================================================================*/
  210.