home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / ODesign / SetupPSE.exe / data.z / CheckboxMenuGroup.java < prev    next >
Encoding:
Java Source  |  1997-01-24  |  1.4 KB  |  68 lines

  1. package COM.odi.demo.OSDraw;
  2.  
  3. /**
  4.  *      <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
  5.  */
  6.  
  7. import java.util.Vector;
  8. import java.awt.*;
  9.  
  10. /*
  11.  * Class CheckboxMenuGroup handles CheckboxMenuItem instances
  12.  */
  13.  
  14. public class CheckboxMenuGroup {
  15.  
  16.   // Vector to keep track of CheckboxMenuItem instances
  17.   private Vector items;
  18.  
  19.   // Constructor
  20.  
  21.   public CheckboxMenuGroup() {
  22.     items = new Vector();
  23.   }
  24.  
  25.   // Add a CheckboxMenuItem instance
  26.  
  27.   public void add(CheckboxMenuItem item) {
  28.     items.addElement(item);
  29.   }
  30.  
  31.   // Select an item at its index
  32.  
  33.   public void select(int index) {
  34.     if (index < 0 || index >= items.size()) {
  35.       return;
  36.     }
  37.     for (int i = 0; i < items.size(); i++) {
  38.       CheckboxMenuItem check = (CheckboxMenuItem)(items.elementAt(i));
  39.       if (i == index) {
  40.         check.setState(true);
  41.       }
  42.       else {
  43.         check.setState(false);
  44.       }
  45.     }
  46.   }
  47.  
  48.   // Try to select a particular item
  49.   // If the CheckboxMenuGroup constains the item, return its index
  50.   // Default return -1
  51.  
  52.   public int select(CheckboxMenuItem item) {
  53.     if (item == null) {
  54.       return -1;
  55.     }
  56.     int index = items.indexOf(item);
  57.     if (index < 0) {
  58.       return index;
  59.     }
  60.     for (int i = 0; i < items.size(); i++) {
  61.       CheckboxMenuItem check = (CheckboxMenuItem)(items.elementAt(i));
  62.       check.setState(false);
  63.     }
  64.     item.setState(true);
  65.     return index;
  66.   }
  67. }
  68.