OSDN Git Service

bc6ef4490ef54a16b4531441679614dbbe4f352d
[pf3gnuchains/gcc-fork.git] / libjava / java / awt / CheckboxGroup.java
1 /* CheckboxGroup.java -- A grouping class for checkboxes.
2    Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 As a special exception, if you link this library with other files to
22 produce an executable, this library does not by itself cause the
23 resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why the
25 executable file might be covered by the GNU General Public License. */
26
27
28 package java.awt;
29
30 /**
31   * This class if for combining checkboxes into groups so that only
32   * one checkbox in the group can be selected at any one time.
33   *
34   * @author Aaron M. Renn (arenn@urbanophile.com)
35   * @author Tom Tromey <tromey@redhat.com>
36   */
37 public class CheckboxGroup implements java.io.Serializable
38 {
39
40 /*
41  * Static Variables
42  */
43
44 // Serialization constant
45 private static final long serialVersionUID = 3729780091441768983L;
46
47 /*************************************************************************/
48
49 /*
50  * Instance Variables
51  */
52
53 /**
54   * @serial The currently selected checkbox.
55   */
56 private Checkbox selectedCheckbox;
57
58 /*************************************************************************/
59
60 /*
61  * Constructors
62  */
63
64 /**
65   * Initializes a new instance of <code>CheckboxGroup</code>.
66   */
67 public
68 CheckboxGroup()
69 {
70 }
71
72 /*************************************************************************/
73
74 /*
75  * Instance Methods
76  */
77
78 /**
79   * Returns the currently selected checkbox, or <code>null</code> if none
80   * of the checkboxes in this group are selected.
81   *
82   * @return The selected checkbox.
83   */
84 public Checkbox
85 getSelectedCheckbox()
86 {
87   return(selectedCheckbox);
88
89
90 /*************************************************************************/
91
92 /**
93   * Returns the currently selected checkbox, or <code>null</code> if none
94   * of the checkboxes in this group are selected.
95   *
96   * @return The selected checkbox.
97   *
98   * @deprecated This method is deprecated in favor of 
99   * <code>getSelectedCheckbox()</code>.
100   */
101 public Checkbox
102 getCurrent()
103 {
104   return(selectedCheckbox);
105
106
107 /*************************************************************************/
108
109 /**
110   * This method sets the specified checkbox to be the selected on in this
111   * group, and unsets all others.
112   *
113   * @param selectedCheckbox The new selected checkbox.
114   */
115 public void
116 setSelectedCheckbox(Checkbox selectedCheckbox)
117 {
118   if (this.selectedCheckbox != null)
119     {
120       if (this.selectedCheckbox.getCheckboxGroup() != this)
121         return;
122
123       this.selectedCheckbox.setState(false);
124     }
125
126   this.selectedCheckbox = selectedCheckbox;
127   if (selectedCheckbox != null)
128     selectedCheckbox.setState(true);
129 }
130
131 /*************************************************************************/
132
133 /**
134   * This method sets the specified checkbox to be the selected on in this
135   * group, and unsets all others.
136   *
137   * @param selectedCheckbox The new selected checkbox.
138   *
139   * @deprecated This method is deprecated in favor of
140   * <code>setSelectedCheckbox()</code>.
141   */
142 public void
143 setCurrent(Checkbox selectedCheckbox)
144 {
145   setSelectedCheckbox(selectedCheckbox);
146 }
147
148 /*************************************************************************/
149
150 /**
151   * Returns a string representation of this checkbox group.
152   *
153   * @return A string representation of this checkbox group.
154   */
155 public String
156 toString()
157 {
158   return(getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]");
159 }
160
161 } // class CheckboxGroup 
162