< prev index next >
src/java.desktop/share/classes/java/awt/CheckboxMenuItem.java
Print this page
*** 38,61 ****
* This class represents a check box that can be included in a menu.
* Selecting the check box in the menu changes its state from
* "on" to "off" or from "off" to "on."
* <p>
* The following picture depicts a menu which contains an instance
! * of <code>CheckBoxMenuItem</code>:
* <p>
* <img src="doc-files/MenuBar-1.gif"
* alt="Menu labeled Examples, containing items Basic, Simple, Check, and More Examples. The Check item is a CheckBoxMenuItem instance, in the off state."
* style="float:center; margin: 7px 10px;">
* <p>
! * The item labeled <code>Check</code> shows a check box menu item
* in its "off" state.
* <p>
* When a check box menu item is selected, AWT sends an item event to
! * the item. Since the event is an instance of <code>ItemEvent</code>,
! * the <code>processEvent</code> method examines the event and passes
! * it along to <code>processItemEvent</code>. The latter method redirects
! * the event to any <code>ItemListener</code> objects that have
* registered an interest in item events generated by this menu item.
*
* @author Sami Shaio
* @see java.awt.event.ItemEvent
* @see java.awt.event.ItemListener
--- 38,61 ----
* This class represents a check box that can be included in a menu.
* Selecting the check box in the menu changes its state from
* "on" to "off" or from "off" to "on."
* <p>
* The following picture depicts a menu which contains an instance
! * of {@code CheckBoxMenuItem}:
* <p>
* <img src="doc-files/MenuBar-1.gif"
* alt="Menu labeled Examples, containing items Basic, Simple, Check, and More Examples. The Check item is a CheckBoxMenuItem instance, in the off state."
* style="float:center; margin: 7px 10px;">
* <p>
! * The item labeled {@code Check} shows a check box menu item
* in its "off" state.
* <p>
* When a check box menu item is selected, AWT sends an item event to
! * the item. Since the event is an instance of {@code ItemEvent},
! * the {@code processEvent} method examines the event and passes
! * it along to {@code processItemEvent}. The latter method redirects
! * the event to any {@code ItemListener} objects that have
* registered an interest in item events generated by this menu item.
*
* @author Sami Shaio
* @see java.awt.event.ItemEvent
* @see java.awt.event.ItemListener
*** 111,121 ****
/**
* Create a check box menu item with the specified label.
* The item's state is initially set to "off."
* @param label a string label for the check box menu item,
! * or <code>null</code> for an unlabeled menu item.
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public CheckboxMenuItem(String label) throws HeadlessException {
--- 111,121 ----
/**
* Create a check box menu item with the specified label.
* The item's state is initially set to "off."
* @param label a string label for the check box menu item,
! * or {@code null} for an unlabeled menu item.
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public CheckboxMenuItem(String label) throws HeadlessException {
*** 123,136 ****
}
/**
* Create a check box menu item with the specified label and state.
* @param label a string label for the check box menu item,
! * or <code>null</code> for an unlabeled menu item.
* @param state the initial state of the menu item, where
! * <code>true</code> indicates "on" and
! * <code>false</code> indicates "off."
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.1
*/
--- 123,136 ----
}
/**
* Create a check box menu item with the specified label and state.
* @param label a string label for the check box menu item,
! * or {@code null} for an unlabeled menu item.
* @param state the initial state of the menu item, where
! * {@code true} indicates "on" and
! * {@code false} indicates "off."
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.1
*/
*** 168,199 ****
/**
* Determines whether the state of this check box menu item
* is "on" or "off."
*
* @return the state of this check box menu item, where
! * <code>true</code> indicates "on" and
! * <code>false</code> indicates "off"
* @see #setState
*/
public boolean getState() {
return state;
}
/**
* Sets this check box menu item to the specified state.
! * The boolean value <code>true</code> indicates "on" while
! * <code>false</code> indicates "off."
*
* <p>Note that this method should be primarily used to
* initialize the state of the check box menu item.
* Programmatically setting the state of the check box
* menu item will <i>not</i> trigger
! * an <code>ItemEvent</code>. The only way to trigger an
! * <code>ItemEvent</code> is by user interaction.
*
! * @param b <code>true</code> if the check box
! * menu item is on, otherwise <code>false</code>
* @see #getState
*/
public synchronized void setState(boolean b) {
state = b;
CheckboxMenuItemPeer peer = (CheckboxMenuItemPeer)this.peer;
--- 168,199 ----
/**
* Determines whether the state of this check box menu item
* is "on" or "off."
*
* @return the state of this check box menu item, where
! * {@code true} indicates "on" and
! * {@code false} indicates "off"
* @see #setState
*/
public boolean getState() {
return state;
}
/**
* Sets this check box menu item to the specified state.
! * The boolean value {@code true} indicates "on" while
! * {@code false} indicates "off."
*
* <p>Note that this method should be primarily used to
* initialize the state of the check box menu item.
* Programmatically setting the state of the check box
* menu item will <i>not</i> trigger
! * an {@code ItemEvent}. The only way to trigger an
! * {@code ItemEvent} is by user interaction.
*
! * @param b {@code true} if the check box
! * menu item is on, otherwise {@code false}
* @see #getState
*/
public synchronized void setState(boolean b) {
state = b;
CheckboxMenuItemPeer peer = (CheckboxMenuItemPeer)this.peer;
*** 263,273 ****
/**
* Returns an array of all the item listeners
* registered on this checkbox menuitem.
*
! * @return all of this checkbox menuitem's <code>ItemListener</code>s
* or an empty array if no item
* listeners are currently registered
*
* @see #addItemListener
* @see #removeItemListener
--- 263,273 ----
/**
* Returns an array of all the item listeners
* registered on this checkbox menuitem.
*
! * @return all of this checkbox menuitem's {@code ItemListener}s
* or an empty array if no item
* listeners are currently registered
*
* @see #addItemListener
* @see #removeItemListener
*** 280,315 ****
}
/**
* Returns an array of all the objects currently registered
* as <code><em>Foo</em>Listener</code>s
! * upon this <code>CheckboxMenuItem</code>.
* <code><em>Foo</em>Listener</code>s are registered using the
* <code>add<em>Foo</em>Listener</code> method.
*
* <p>
! * You can specify the <code>listenerType</code> argument
* with a class literal, such as
* <code><em>Foo</em>Listener.class</code>.
* For example, you can query a
! * <code>CheckboxMenuItem</code> <code>c</code>
* for its item listeners with the following code:
*
* <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
*
* If no such listeners exist, this method returns an empty array.
*
* @param listenerType the type of listeners requested; this parameter
* should specify an interface that descends from
! * <code>java.util.EventListener</code>
* @return an array of all objects registered as
* <code><em>Foo</em>Listener</code>s on this checkbox menuitem,
* or an empty array if no such
* listeners have been added
! * @exception ClassCastException if <code>listenerType</code>
* doesn't specify a class or interface that implements
! * <code>java.util.EventListener</code>
*
* @see #getItemListeners
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
--- 280,315 ----
}
/**
* Returns an array of all the objects currently registered
* as <code><em>Foo</em>Listener</code>s
! * upon this {@code CheckboxMenuItem}.
* <code><em>Foo</em>Listener</code>s are registered using the
* <code>add<em>Foo</em>Listener</code> method.
*
* <p>
! * You can specify the {@code listenerType} argument
* with a class literal, such as
* <code><em>Foo</em>Listener.class</code>.
* For example, you can query a
! * {@code CheckboxMenuItem c}
* for its item listeners with the following code:
*
* <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
*
* If no such listeners exist, this method returns an empty array.
*
* @param listenerType the type of listeners requested; this parameter
* should specify an interface that descends from
! * {@code java.util.EventListener}
* @return an array of all objects registered as
* <code><em>Foo</em>Listener</code>s on this checkbox menuitem,
* or an empty array if no such
* listeners have been added
! * @exception ClassCastException if {@code listenerType}
* doesn't specify a class or interface that implements
! * {@code java.util.EventListener}
*
* @see #getItemListeners
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
*** 334,350 ****
return super.eventEnabled(e);
}
/**
* Processes events on this check box menu item.
! * If the event is an instance of <code>ItemEvent</code>,
! * this method invokes the <code>processItemEvent</code> method.
* If the event is not an item event,
! * it invokes <code>processEvent</code> on the superclass.
* <p>
* Check box menu items currently support only item events.
! * <p>Note that if the event parameter is <code>null</code>
* the behavior is unspecified and may result in an
* exception.
*
* @param e the event
* @see java.awt.event.ItemEvent
--- 334,350 ----
return super.eventEnabled(e);
}
/**
* Processes events on this check box menu item.
! * If the event is an instance of {@code ItemEvent},
! * this method invokes the {@code processItemEvent} method.
* If the event is not an item event,
! * it invokes {@code processEvent} on the superclass.
* <p>
* Check box menu items currently support only item events.
! * <p>Note that if the event parameter is {@code null}
* the behavior is unspecified and may result in an
* exception.
*
* @param e the event
* @see java.awt.event.ItemEvent
*** 359,379 ****
super.processEvent(e);
}
/**
* Processes item events occurring on this check box menu item by
! * dispatching them to any registered <code>ItemListener</code> objects.
* <p>
* This method is not called unless item events are
* enabled for this menu item. Item events are enabled
* when one of the following occurs:
* <ul>
! * <li>An <code>ItemListener</code> object is registered
! * via <code>addItemListener</code>.
! * <li>Item events are enabled via <code>enableEvents</code>.
* </ul>
! * <p>Note that if the event parameter is <code>null</code>
* the behavior is unspecified and may result in an
* exception.
*
* @param e the item event
* @see java.awt.event.ItemEvent
--- 359,379 ----
super.processEvent(e);
}
/**
* Processes item events occurring on this check box menu item by
! * dispatching them to any registered {@code ItemListener} objects.
* <p>
* This method is not called unless item events are
* enabled for this menu item. Item events are enabled
* when one of the following occurs:
* <ul>
! * <li>An {@code ItemListener} object is registered
! * via {@code addItemListener}.
! * <li>Item events are enabled via {@code enableEvents}.
* </ul>
! * <p>Note that if the event parameter is {@code null}
* the behavior is unspecified and may result in an
* exception.
*
* @param e the item event
* @see java.awt.event.ItemEvent
*** 401,415 ****
ItemEvent.DESELECTED));
}
/**
* Returns a string representing the state of this
! * <code>CheckBoxMenuItem</code>. This
* method is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not be
! * <code>null</code>.
*
* @return the parameter string of this check box menu item
*/
public String paramString() {
return super.paramString() + ",state=" + state;
--- 401,415 ----
ItemEvent.DESELECTED));
}
/**
* Returns a string representing the state of this
! * {@code CheckBoxMenuItem}. This
* method is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not be
! * {@code null}.
*
* @return the parameter string of this check box menu item
*/
public String paramString() {
return super.paramString() + ",state=" + state;
*** 424,445 ****
*/
private int checkboxMenuItemSerializedDataVersion = 1;
/**
* Writes default serializable fields to stream. Writes
! * a list of serializable <code>ItemListeners</code>
* as optional data. The non-serializable
! * <code>ItemListeners</code> are detected and
* no attempt is made to serialize them.
*
! * @param s the <code>ObjectOutputStream</code> to write
! * @serialData <code>null</code> terminated sequence of
! * 0 or more pairs; the pair consists of a <code>String</code>
! * and an <code>Object</code>; the <code>String</code> indicates
* the type of object and is one of the following:
! * <code>itemListenerK</code> indicating an
! * <code>ItemListener</code> object
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#itemListenerK
* @see #readObject(ObjectInputStream)
*/
--- 424,445 ----
*/
private int checkboxMenuItemSerializedDataVersion = 1;
/**
* Writes default serializable fields to stream. Writes
! * a list of serializable {@code ItemListeners}
* as optional data. The non-serializable
! * {@code ItemListeners} are detected and
* no attempt is made to serialize them.
*
! * @param s the {@code ObjectOutputStream} to write
! * @serialData {@code null} terminated sequence of
! * 0 or more pairs; the pair consists of a {@code String}
! * and an {@code Object}; the {@code String} indicates
* the type of object and is one of the following:
! * {@code itemListenerK} indicating an
! * {@code ItemListener} object
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#itemListenerK
* @see #readObject(ObjectInputStream)
*/
*** 451,466 ****
AWTEventMulticaster.save(s, itemListenerK, itemListener);
s.writeObject(null);
}
/*
! * Reads the <code>ObjectInputStream</code> and if it
! * isn't <code>null</code> adds a listener to receive
! * item events fired by the <code>Checkbox</code> menu item.
* Unrecognized keys or values will be ignored.
*
! * @param s the <code>ObjectInputStream</code> to read
* @serial
* @see removeActionListener()
* @see addActionListener()
* @see #writeObject
*/
--- 451,466 ----
AWTEventMulticaster.save(s, itemListenerK, itemListener);
s.writeObject(null);
}
/*
! * Reads the {@code ObjectInputStream} and if it
! * isn't {@code null} adds a listener to receive
! * item events fired by the {@code Checkbox} menu item.
* Unrecognized keys or values will be ignored.
*
! * @param s the {@code ObjectInputStream} to read
* @serial
* @see removeActionListener()
* @see addActionListener()
* @see #writeObject
*/
*** 513,523 ****
* accessibility. This class is not meant to be used directly by
* application developers, but is instead meant only to be
* subclassed by menu component developers.
* <p>
* This class implements accessibility support for the
! * <code>CheckboxMenuItem</code> class. It provides an implementation
* of the Java Accessibility API appropriate to checkbox menu item
* user-interface elements.
* @since 1.3
*/
protected class AccessibleAWTCheckboxMenuItem extends AccessibleAWTMenuItem
--- 513,523 ----
* accessibility. This class is not meant to be used directly by
* application developers, but is instead meant only to be
* subclassed by menu component developers.
* <p>
* This class implements accessibility support for the
! * {@code CheckboxMenuItem} class. It provides an implementation
* of the Java Accessibility API appropriate to checkbox menu item
* user-interface elements.
* @since 1.3
*/
protected class AccessibleAWTCheckboxMenuItem extends AccessibleAWTMenuItem
< prev index next >