1 /*
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
138 throws HeadlessException {
139 super(label);
140 this.state = state;
141 }
142
143 /**
144 * Construct a name for this MenuComponent. Called by getName() when
145 * the name is null.
146 */
147 String constructComponentName() {
148 synchronized (CheckboxMenuItem.class) {
149 return base + nameCounter++;
150 }
151 }
152
153 /**
154 * Creates the peer of the checkbox item. This peer allows us to
155 * change the look of the checkbox item without changing its
156 * functionality.
157 * Most applications do not call this method directly.
158 * @see java.awt.Toolkit#createCheckboxMenuItem(java.awt.CheckboxMenuItem)
159 * @see java.awt.Component#getToolkit()
160 */
161 public void addNotify() {
162 synchronized (getTreeLock()) {
163 if (peer == null)
164 peer = Toolkit.getDefaultToolkit().createCheckboxMenuItem(this);
165 super.addNotify();
166 }
167 }
168
169 /**
170 * Determines whether the state of this check box menu item
171 * is "on" or "off."
172 *
173 * @return the state of this check box menu item, where
174 * <code>true</code> indicates "on" and
175 * <code>false</code> indicates "off"
176 * @see #setState
177 */
178 public boolean getState() {
179 return state;
180 }
181
182 /**
183 * Sets this check box menu item to the specified state.
184 * The boolean value <code>true</code> indicates "on" while
|
1 /*
2 * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
138 throws HeadlessException {
139 super(label);
140 this.state = state;
141 }
142
143 /**
144 * Construct a name for this MenuComponent. Called by getName() when
145 * the name is null.
146 */
147 String constructComponentName() {
148 synchronized (CheckboxMenuItem.class) {
149 return base + nameCounter++;
150 }
151 }
152
153 /**
154 * Creates the peer of the checkbox item. This peer allows us to
155 * change the look of the checkbox item without changing its
156 * functionality.
157 * Most applications do not call this method directly.
158 * @see java.awt.Component#getToolkit()
159 */
160 public void addNotify() {
161 synchronized (getTreeLock()) {
162 if (peer == null)
163 peer = getComponentFactory().createCheckboxMenuItem(this);
164 super.addNotify();
165 }
166 }
167
168 /**
169 * Determines whether the state of this check box menu item
170 * is "on" or "off."
171 *
172 * @return the state of this check box menu item, where
173 * <code>true</code> indicates "on" and
174 * <code>false</code> indicates "off"
175 * @see #setState
176 */
177 public boolean getState() {
178 return state;
179 }
180
181 /**
182 * Sets this check box menu item to the specified state.
183 * The boolean value <code>true</code> indicates "on" while
|