CheckboxGroup.java 4.7 KB

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