home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / swing / JCheckBox.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  6.4 KB  |  200 lines

  1. /*
  2.  * @(#)JCheckBox.java    1.35 98/02/12
  3.  * 
  4.  * Copyright (c) 1997 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 disclose
  8.  * such Confidential Information and shall use it only in accordance with the
  9.  * terms of the license agreement you entered into with Sun.
  10.  * 
  11.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  12.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
  14.  * OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
  15.  * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR
  16.  * ITS DERIVATIVES.
  17.  * 
  18.  */
  19. package java.awt.swing;
  20.  
  21. import java.awt.*;
  22. import java.awt.event.*;
  23. import java.awt.accessibility.*;
  24. import java.awt.swing.plaf.*;
  25.  
  26.  
  27. /**
  28.  * An implementation of a CheckBox -- an item that can be selected or
  29.  * deselected, and which displays its state to the user. In a group
  30.  * of checkboxes, multiple checkboxes can be selected. 
  31.  *
  32.  * See <a href="http://java.sun.com/docs/books/tutorial/ui/swing/checkbox.html">How to Use CheckBoxes</a>
  33.  * in <a href="http://java.sun.com/Series/Tutorial/index.html"><em>The Java Tutorial</em></a>
  34.  * for further documentation.
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate 
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @see JRadioButton
  44.  *
  45.  * @beaninfo
  46.  *   attribute: isContainer false
  47.  *
  48.  * @version 1.35 02/12/98
  49.  * @author Jeff Dinkins
  50.  */
  51. public class JCheckBox extends JToggleButton implements Accessible {
  52.  
  53.     /**
  54.      * Creates an initially unselected checkbox button with no text, no icon.
  55.      */
  56.     public JCheckBox () {
  57.         this(null, null, false);
  58.     }
  59.  
  60.     /**
  61.      * Creates an initially unselected checkbox with an icon.
  62.      *
  63.      * @param icon  the Icon image to display
  64.      */
  65.     public JCheckBox(Icon icon) {
  66.         this(null, icon, false);
  67.     }
  68.     
  69.     /**
  70.      * Creates a checkbox with an icon and specifies whether
  71.      * or not it is initially selected.
  72.      *
  73.      * @param icon  the Icon image to display
  74.      * @param selected a boolean value indicating the initial selection
  75.      *        state. If <code>true</code> the checkbox is selected
  76.      */
  77.     public JCheckBox(Icon icon, boolean selected) {
  78.         this(null, icon, selected);
  79.     }
  80.     
  81.     /**
  82.      * Creates an initially unselected checkbox with text.
  83.      *
  84.      * @param text the text of the checkbox.
  85.      */
  86.     public JCheckBox (String text) {
  87.         this(text, null, false);
  88.     }
  89.  
  90.     /**
  91.      * Creates a checkbox with text and specifies whether 
  92.      * or not it is initially selected.
  93.      *
  94.      * @param text the text of the checkbox.
  95.      * @param selected a boolean value indicating the initial selection
  96.      *        state. If <code>true</code> the checkbox is selected
  97.      */
  98.     public JCheckBox (String text, boolean selected) {
  99.         this(text, null, selected);
  100.     }
  101.  
  102.     /**
  103.      * Creates an initially unselected checkbox with 
  104.      * the specified text and icon.
  105.      *
  106.      * @param text the text of the checkbox.
  107.      * @param icon  the Icon image to display
  108.      */
  109.     public JCheckBox(String text, Icon icon) {
  110.         this(text, icon, false);
  111.     }
  112.  
  113.     /**
  114.      * Creates a checkbox with text and icon,
  115.      * and specifies whether or not it is initially selected.
  116.      *
  117.      * @param text the text of the checkbox.
  118.      * @param icon  the Icon image to display
  119.      * @param selected a boolean value indicating the initial selection
  120.      *        state. If <code>true</code> the checkbox is selected
  121.      */
  122.     public JCheckBox (String text, Icon icon, boolean selected) {
  123.         super(text, icon, selected);
  124.         setBorderPainted(false);
  125.         setHorizontalAlignment(LEFT);
  126.     }
  127.  
  128.     /**
  129.      * Notification from the UIFactory that the L&F
  130.      * has changed. 
  131.      *
  132.      * @see JComponent#updateUI
  133.      */
  134.     public void updateUI() {
  135.         setUI((ButtonUI)UIManager.getUI(this));
  136.     }
  137.  
  138.  
  139.     /**
  140.      * Returns a string that specifies the name of the L&F class
  141.      * that renders this component.
  142.      *
  143.      * @return "CheckBoxUI"
  144.      * @see JComponent#getUIClassID
  145.      * @see UIDefaults#getUI
  146.      * @beaninfo
  147.      *        expert: true
  148.      *   description: A string that specifies the name of the L&F class
  149.      */
  150.     public String getUIClassID() {
  151.         return "CheckBoxUI";
  152.     }
  153.  
  154.  
  155.  
  156. /////////////////
  157. // Accessibility support
  158. ////////////////
  159.  
  160.     /**
  161.      * Get the AccessibleContext associated with this JComponent
  162.      *
  163.      * @return the AccessibleContext of this JComponent
  164.      * @beaninfo
  165.      *       expert: true
  166.      *  description: The AccessibleContext associated with this CheckBox.
  167.      */
  168.     public AccessibleContext getAccessibleContext() {
  169.         if (accessibleContext == null) {
  170.             accessibleContext = new AccessibleJCheckBox();
  171.         }
  172.         return accessibleContext;
  173.     }
  174.  
  175.     /**
  176.      * The class used to obtain the accessible role for this object.
  177.      * <p>
  178.      * Warning: serialized objects of this class will not be compatible with
  179.      * future swing releases.  The current serialization support is appropriate
  180.      * for short term storage or RMI between Swing1.0 applications.  It will
  181.      * not be possible to load serialized Swing1.0 objects with future releases
  182.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  183.      * baseline for the serialized form of Swing objects.
  184.      */
  185.     protected class AccessibleJCheckBox extends AccessibleJToggleButton {
  186.  
  187.         /**
  188.          * Get the role of this object.
  189.          *
  190.          * @return an instance of AccessibleRole describing the role of the object
  191.          * @see AccessibleRole
  192.          */
  193.         public AccessibleRole getAccessibleRole() {
  194.             return AccessibleRole.CHECK_BOX;
  195.         }
  196.  
  197.     } // inner class AccessibleJCheckBox
  198. }
  199.   
  200.