001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.io.Serializable;
023:
024: public class CheckboxGroup implements Serializable {
025: private static final long serialVersionUID = 3729780091441768983L;
026:
027: private final Toolkit toolkit = Toolkit.getDefaultToolkit();
028:
029: private Checkbox current = null;
030:
031: public CheckboxGroup() {
032: toolkit.lockAWT();
033: try {
034: } finally {
035: toolkit.unlockAWT();
036: }
037: }
038:
039: @Override
040: public String toString() {
041: /* The format is based on 1.5 release behavior
042: * which can be revealed by the following code:
043: * System.out.println(new CheckboxGroup());
044: */
045:
046: toolkit.lockAWT();
047: try {
048: return (getClass().getName() + "[" + //$NON-NLS-1$
049: "selectedCheckbox=" + current + "]"); //$NON-NLS-1$ //$NON-NLS-2$
050: } finally {
051: toolkit.unlockAWT();
052: }
053: }
054:
055: public Checkbox getSelectedCheckbox() {
056: toolkit.lockAWT();
057: try {
058: return current;
059: } finally {
060: toolkit.unlockAWT();
061: }
062: }
063:
064: public void setSelectedCheckbox(Checkbox box) {
065: toolkit.lockAWT();
066: try {
067: if ((box != null) && (box.getCheckboxGroup() != this )) {
068: return;
069: }
070:
071: if (current != null) {
072: current.setChecked(false);
073: }
074:
075: if (box != null) {
076: box.setChecked(true);
077: }
078:
079: current = box;
080: } finally {
081: toolkit.unlockAWT();
082: }
083: }
084:
085: /**
086: * @deprecated
087: */
088: @Deprecated
089: public Checkbox getCurrent() {
090: toolkit.lockAWT();
091: try {
092: return getSelectedCheckbox();
093: } finally {
094: toolkit.unlockAWT();
095: }
096: }
097:
098: /**
099: * @deprecated
100: */
101: @Deprecated
102: public void setCurrent(Checkbox box) {
103: toolkit.lockAWT();
104: try {
105: setSelectedCheckbox(box);
106: } finally {
107: toolkit.unlockAWT();
108: }
109: }
110: }
|