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
247 public String getLabel() {
248 return label;
249 }
250
251 /**
252 * Sets the label for this menu item to the specified label.
253 * @param label the new label, or <code>null</code> for no label.
254 * @see java.awt.MenuItem#getLabel
255 * @since JDK1.0
256 */
257 public synchronized void setLabel(String label) {
258 this.label = label;
259 MenuItemPeer peer = (MenuItemPeer)this.peer;
260 if (peer != null) {
261 peer.setLabel(label);
262 }
263 }
264
265 /**
266 * Checks whether this menu item is enabled.
267 * @see java.awt.MenuItem#setEnabled
268 * @since JDK1.0
269 */
270 public boolean isEnabled() {
271 return enabled;
272 }
273
274 /**
275 * Sets whether or not this menu item can be chosen.
276 * @param b if <code>true</code>, enables this menu item;
277 * if <code>false</code>, disables it.
278 * @see java.awt.MenuItem#isEnabled
279 * @since JDK1.1
280 */
281 public synchronized void setEnabled(boolean b) {
282 enable(b);
283 }
284
285 /**
286 * @deprecated As of JDK version 1.1,
287 * replaced by <code>setEnabled(boolean)</code>.
288 */
289 @Deprecated
290 public synchronized void enable() {
291 enabled = true;
292 MenuItemPeer peer = (MenuItemPeer)this.peer;
293 if (peer != null) {
294 peer.setEnabled(true);
295 }
296 }
297
298 /**
299 * @deprecated As of JDK version 1.1,
300 * replaced by <code>setEnabled(boolean)</code>.
301 */
302 @Deprecated
303 public void enable(boolean b) {
304 if (b) {
305 enable();
306 } else {
307 disable();
308 }
309 }
310
311 /**
312 * @deprecated As of JDK version 1.1,
313 * replaced by <code>setEnabled(boolean)</code>.
314 */
315 @Deprecated
316 public synchronized void disable() {
317 enabled = false;
318 MenuItemPeer peer = (MenuItemPeer)this.peer;
477 }
478
479 /**
480 * Sets the command name of the action event that is fired
481 * by this menu item.
482 * <p>
483 * By default, the action command is set to the label of
484 * the menu item.
485 * @param command the action command to be set
486 * for this menu item.
487 * @see java.awt.MenuItem#getActionCommand
488 * @since JDK1.1
489 */
490 public void setActionCommand(String command) {
491 actionCommand = command;
492 }
493
494 /**
495 * Gets the command name of the action event that is fired
496 * by this menu item.
497 * @see java.awt.MenuItem#setActionCommand
498 * @since JDK1.1
499 */
500 public String getActionCommand() {
501 return getActionCommandImpl();
502 }
503
504 // This is final so it can be called on the Toolkit thread.
505 final String getActionCommandImpl() {
506 return (actionCommand == null? label : actionCommand);
507 }
508
509 /**
510 * Adds the specified action listener to receive action events
511 * from this menu item.
512 * If l is null, no exception is thrown and no action is performed.
513 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
514 * >AWT Threading Issues</a> for details on AWT's threading model.
515 *
516 * @param l the action listener.
|
1 /*
2 * Copyright (c) 1995, 2014, 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
247 public String getLabel() {
248 return label;
249 }
250
251 /**
252 * Sets the label for this menu item to the specified label.
253 * @param label the new label, or <code>null</code> for no label.
254 * @see java.awt.MenuItem#getLabel
255 * @since JDK1.0
256 */
257 public synchronized void setLabel(String label) {
258 this.label = label;
259 MenuItemPeer peer = (MenuItemPeer)this.peer;
260 if (peer != null) {
261 peer.setLabel(label);
262 }
263 }
264
265 /**
266 * Checks whether this menu item is enabled.
267 *
268 * @return {@code true} if the item is enabled;
269 * otherwise {@code false}
270 * @see java.awt.MenuItem#setEnabled
271 * @since JDK1.0
272 */
273 public boolean isEnabled() {
274 return enabled;
275 }
276
277 /**
278 * Sets whether or not this menu item can be chosen.
279 * @param b if <code>true</code>, enables this menu item;
280 * if <code>false</code>, disables it.
281 * @see java.awt.MenuItem#isEnabled
282 * @since JDK1.1
283 */
284 public synchronized void setEnabled(boolean b) {
285 enable(b);
286 }
287
288 /**
289 * @deprecated As of JDK version 1.1,
290 * replaced by <code>setEnabled(boolean)</code>.
291 */
292 @Deprecated
293 public synchronized void enable() {
294 enabled = true;
295 MenuItemPeer peer = (MenuItemPeer)this.peer;
296 if (peer != null) {
297 peer.setEnabled(true);
298 }
299 }
300
301 /**
302 * Sets whether or not this menu item can be chosen.
303 *
304 * @param b if {@code true}, enables this menu item;
305 * otherwise {@code false}
306 * @deprecated As of JDK version 1.1,
307 * replaced by <code>setEnabled(boolean)</code>.
308 */
309 @Deprecated
310 public void enable(boolean b) {
311 if (b) {
312 enable();
313 } else {
314 disable();
315 }
316 }
317
318 /**
319 * @deprecated As of JDK version 1.1,
320 * replaced by <code>setEnabled(boolean)</code>.
321 */
322 @Deprecated
323 public synchronized void disable() {
324 enabled = false;
325 MenuItemPeer peer = (MenuItemPeer)this.peer;
484 }
485
486 /**
487 * Sets the command name of the action event that is fired
488 * by this menu item.
489 * <p>
490 * By default, the action command is set to the label of
491 * the menu item.
492 * @param command the action command to be set
493 * for this menu item.
494 * @see java.awt.MenuItem#getActionCommand
495 * @since JDK1.1
496 */
497 public void setActionCommand(String command) {
498 actionCommand = command;
499 }
500
501 /**
502 * Gets the command name of the action event that is fired
503 * by this menu item.
504 *
505 * @return the action command name
506 * @see java.awt.MenuItem#setActionCommand
507 * @since JDK1.1
508 */
509 public String getActionCommand() {
510 return getActionCommandImpl();
511 }
512
513 // This is final so it can be called on the Toolkit thread.
514 final String getActionCommandImpl() {
515 return (actionCommand == null? label : actionCommand);
516 }
517
518 /**
519 * Adds the specified action listener to receive action events
520 * from this menu item.
521 * If l is null, no exception is thrown and no action is performed.
522 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
523 * >AWT Threading Issues</a> for details on AWT's threading model.
524 *
525 * @param l the action listener.
|