home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / CheckboxGroup.java < prev    next >
Text File  |  1997-10-01  |  5KB  |  143 lines

  1. /*
  2.  * @(#)CheckboxGroup.java    1.19 97/06/12
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22. package java.awt;
  23.  
  24. /**
  25.  * The <code>CheckboxGroup</code> class is used to group together 
  26.  * a set of <code>Checkbox</code> buttons. 
  27.  * <p>
  28.  * Exactly one check box button in a <code>CheckboxGroup</code> can 
  29.  * be in the "on" state at any given time. Pushing any 
  30.  * button sets its state to "on" and forces any other button that 
  31.  * is in the "on" state into the "off" state. 
  32.  * <p>
  33.  * The following code example produces a new check box group,
  34.  * with three check boxes: 
  35.  * <p>
  36.  * <hr><blockquote><pre>
  37.  * setLayout(new GridLayout(3, 1));
  38.  * CheckboxGroup cbg = new CheckboxGroup();
  39.  * add(new Checkbox("one", cbg, true));
  40.  * add(new Checkbox("two", cbg, false));
  41.  * add(new Checkbox("three", cbg, false));
  42.  * </pre></blockquote><hr>
  43.  * <p>
  44.  * This image depicts the check box group created by this example:
  45.  * <p>
  46.  * <img src="images-awt/CheckboxGroup-1.gif"
  47.  * ALIGN=center HSPACE=10 VSPACE=7> 
  48.  * <p>
  49.  * @version     1.19 06/12/97
  50.  * @author     Sami Shaio
  51.  * @see         java.awt.Checkbox
  52.  * @since       JDK1.0
  53.  */
  54. public class CheckboxGroup implements java.io.Serializable {
  55.     /**
  56.      * The current choice.
  57.      */
  58.     Checkbox selectedCheckbox = null;
  59.  
  60.     /*
  61.      * JDK 1.1 serialVersionUID 
  62.      */
  63.     private static final long serialVersionUID = 3729780091441768983L;
  64.  
  65.     /**
  66.      * Creates a new instance of <code>CheckboxGroup</code>. 
  67.      * @since     JDK1.0
  68.      */
  69.     public CheckboxGroup() {
  70.     }
  71.  
  72.     /**
  73.      * Gets the current choice from this check box group.
  74.      * The current choice is the check box in this  
  75.      * group that is currently in the "on" state, 
  76.      * or <code>null</code> if all check boxes in the
  77.      * group are off.
  78.      * @return   the check box that is currently in the
  79.      *                 "on" state, or <code>null</code>.
  80.      * @see      java.awt.Checkbox
  81.      * @see      java.awt.CheckboxGroup#setSelectedCheckbox
  82.      * @since    JDK1.1
  83.      */
  84.     public Checkbox getSelectedCheckbox() {
  85.     return getCurrent();
  86.     }
  87.  
  88.     /**
  89.      * @deprecated As of JDK version 1.1,
  90.      * replaced by <code>getSelectedCheckbox()</code>.
  91.      */
  92.     public Checkbox getCurrent() {
  93.     return selectedCheckbox;
  94.     }
  95.  
  96.     /**
  97.      * Sets the currently selected check box in this group
  98.      * to be the specified check box.
  99.      * This method sets the state of that check box to "on" and 
  100.      * sets all other check boxes in the group to be off.
  101.      * <p>
  102.      * If the check box argument is <code>null</code> or belongs to a 
  103.      * different check box group, then this method does nothing. 
  104.      * @param     box   the <code>Checkbox</code> to set as the
  105.      *                      current selection.
  106.      * @see      java.awt.Checkbox
  107.      * @see      java.awt.CheckboxGroup#getSelectedCheckbox
  108.      * @since    JDK1.1
  109.      */
  110.     public synchronized void setSelectedCheckbox(Checkbox box) {
  111.         setCurrent(box);
  112.     }
  113.  
  114.     /**
  115.      * @deprecated As of JDK version 1.1,
  116.      * replaced by <code>setSelectedCheckbox(Checkbox)</code>.
  117.      */
  118.     public synchronized void setCurrent(Checkbox box) {
  119.     if (box != null && box.group != this) {
  120.         return;
  121.     }
  122.     Checkbox oldChoice = this.selectedCheckbox;
  123.     this.selectedCheckbox = box;
  124.     if ((oldChoice != null) && (oldChoice != box)) {
  125.         oldChoice.setState(false);
  126.     }
  127.     if (box != null && oldChoice != box && !box.getState()) {
  128.         box.setStateInternal(true);
  129.     }
  130.     }
  131.  
  132.     /**
  133.      * Returns a string representation of this check box group,
  134.      * including the value of its current selection.
  135.      * @return    a string representation of this check box group.
  136.      * @since     JDK1.0
  137.      */
  138.     public String toString() {
  139.     return getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]";
  140.     }
  141.  
  142. }
  143.