home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / CheckboxGroup.java < prev    next >
Text File  |  1996-05-03  |  2KB  |  76 lines

  1. /*
  2.  * @(#)CheckboxGroup.java    1.11 95/11/14 Sami Shaio
  3.  *
  4.  * Copyright (c) 1994-1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. /**
  22.  * This class is used to create a multiple-exclusion scope for a set
  23.  * of Checkbox buttons. For example, creating a set of Checkbox buttons
  24.  * with the same CheckboxGroup object means that only one of those Checkbox
  25.  * buttons will be allowed to be "on" at a time.
  26.  *
  27.  * @version     1.11 14 Nov 1995
  28.  * @author     Sami Shaio
  29.  */
  30. public class CheckboxGroup {
  31.     /**
  32.      * The current choice.
  33.      */
  34.     Checkbox currentChoice = null;
  35.  
  36.     /**
  37.      * Creates a new CheckboxGroup.
  38.      */
  39.     public CheckboxGroup() {
  40.     }
  41.  
  42.     /**
  43.      * Gets the current choice.
  44.      */
  45.     public Checkbox getCurrent() {
  46.     return currentChoice;
  47.     }
  48.  
  49.     /**
  50.      * Sets the current choice to the specified Checkbox.
  51.      * If the Checkbox belongs to a different group, just return.
  52.      * @param box the current Checkbox choice
  53.      */
  54.     public synchronized void setCurrent(Checkbox box) {
  55.     if (box != null && box.group != this) {
  56.         return;
  57.     }
  58.     Checkbox oldChoice = this.currentChoice;
  59.     this.currentChoice = box;
  60.     if ((oldChoice != null) && (oldChoice != box)) {
  61.         oldChoice.setState(false);
  62.     }
  63.     if (box != null && oldChoice != box && !box.getState()) {
  64.         box.setStateInternal(true);
  65.     }
  66.     }
  67.  
  68.     /**
  69.      * Returns the String representation of this CheckboxGroup's values.
  70.      * Convert to String.
  71.      */
  72.     public String toString() {
  73.     return getClass().getName() + "[current=" + currentChoice + "]";
  74.     }
  75. }
  76.