home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / unuy2wen / cybcerone / utils / keypadbuttongroup.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.6 KB  |  88 lines

  1. // KeypadButtonGroup.java
  2. // 28.02.96
  3. //
  4. // a collection of KeypadButton objects
  5.  
  6. package cybcerone.utils;
  7.  
  8. import java.util.Vector;
  9. import java.util.Enumeration;
  10.  
  11. class KeypadButtonGroup {
  12.  
  13.   private Vector buttons;
  14.   private KeypadButton highlighted;
  15.  
  16.   KeypadButtonGroup () {
  17.     buttons = new Vector ();
  18.   }
  19.  
  20.   /**
  21.    * Add a button to the group.
  22.    */
  23.   void add (KeypadButton newButton) {
  24.     buttons.addElement (newButton);
  25.   }
  26.  
  27.   /**
  28.    * Which button is at (x, y)?
  29.    */
  30.   KeypadButton whichButton (int x, int y) {
  31.     Enumeration e = buttons.elements ();
  32.     KeypadButton theButton = null;
  33.  
  34.     while (e.hasMoreElements ()) {
  35.       theButton = (KeypadButton)e.nextElement ();
  36.       if (theButton.inside (x, y))
  37.     return theButton;
  38.     }
  39.     return null;
  40.   }
  41.  
  42.   /**
  43.    * Which button has this value?
  44.    */
  45.   KeypadButton whichButton (Object value) {
  46.     Enumeration e = buttons.elements ();
  47.     KeypadButton theButton = null;
  48.  
  49.     while (e.hasMoreElements ()) {
  50.       theButton = (KeypadButton)e.nextElement ();
  51.       if (theButton.getValue().equals (value)) 
  52.     return theButton;
  53.     }
  54.     return null;
  55.   }
  56.  
  57.   /**
  58.    * This is the button to highlight.  Note: this doesn't draw anything,
  59.    * it's just for later reference.
  60.    */
  61.   void setHighlighted (KeypadButton button) {
  62.     highlighted = button;
  63.   }
  64.  
  65.   /**
  66.    * Which button did we highlight again?
  67.    */
  68.   KeypadButton getHighlighted () {
  69.     return highlighted;
  70.   }
  71.  
  72.   /**
  73.    * Nothing's highlighted anymore.
  74.    */
  75.   void clearHighlighted () {
  76.     highlighted = null;
  77.   }
  78.  
  79.   /**
  80.    * Does this group contain this button?
  81.    */
  82.   public boolean contains (KeypadButton button) {
  83.     return buttons.contains (button);
  84.   }
  85. }
  86.  
  87.  
  88.