aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/CheckboxMenuItem.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2000-12-26 07:18:16 +0000
committerTom Tromey <tromey@gcc.gnu.org>2000-12-26 07:18:16 +0000
commitb3b90f82f43dba90b2f2f00d87165519d95c4268 (patch)
treec25b24dcc12943d0d0c10a6650871a857a409bd7 /libjava/java/awt/CheckboxMenuItem.java
parent5472d1951a2f96bf92d004dec143cd21a4da3965 (diff)
downloadgcc-b3b90f82f43dba90b2f2f00d87165519d95c4268.zip
gcc-b3b90f82f43dba90b2f2f00d87165519d95c4268.tar.gz
gcc-b3b90f82f43dba90b2f2f00d87165519d95c4268.tar.bz2
MenuItem.java (paramString): Now protected.
* java/awt/MenuItem.java (paramString): Now protected. * java/awt/MenuShortcut.java: Implements Serializable. * java/awt/MenuBar.java: Rewrote from scratch. * java/awt/MenuComponent.java (removeNotify): Wrote. Implements Serializable. * java/awt/GridBagConstraints.java (GridBagConstraints): New constructor. * java/awt/CheckboxMenuItem.java: Wrote. From-SVN: r38488
Diffstat (limited to 'libjava/java/awt/CheckboxMenuItem.java')
-rw-r--r--libjava/java/awt/CheckboxMenuItem.java124
1 files changed, 121 insertions, 3 deletions
diff --git a/libjava/java/awt/CheckboxMenuItem.java b/libjava/java/awt/CheckboxMenuItem.java
index a98c94a..83941a7 100644
--- a/libjava/java/awt/CheckboxMenuItem.java
+++ b/libjava/java/awt/CheckboxMenuItem.java
@@ -7,9 +7,127 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.awt;
+import java.awt.peer.CheckboxMenuItemPeer;
+import java.awt.event.ItemListener;
+import java.awt.event.ItemEvent;
-/* A very incomplete placeholder. */
-
-public class CheckboxMenuItem extends MenuItem
+/** This implements a menu item which keeps track of a boolean state.
+ * @author Tom Tromey <tromey@redhat.com>
+ * @date December 25, 2000
+ */
+public class CheckboxMenuItem extends MenuItem implements ItemSelectable
{
+ /** Create a new CheckboxMenuItem.
+ * @param label The checkbox label. A null value is the same as "";
+ * null is the default.
+ * @param state The initial check state; defaults to false.
+ */
+ public CheckboxMenuItem ()
+ {
+ this (null, false);
+ }
+
+ public CheckboxMenuItem (String label)
+ {
+ this (label, false);
+ }
+
+ public CheckboxMenuItem (String label, boolean state)
+ {
+ this.label = label;
+ this.state = state;
+ }
+
+ /** Add a listener for item events.
+ * @param listener The listener to add.
+ */
+ public synchronized void addItemListener (ItemListener listener)
+ {
+ listeners = AWTEventMulticaster.add (listeners, listener);
+ }
+
+ /** This creates the component's peer. */
+ public void addNotify ()
+ {
+ if (peer != null)
+ {
+ // This choice of toolkit seems unsatisfying, but I'm not sure
+ // what else to do.
+ peer = Toolkit.getDefaultToolkit ().createCheckboxMenuItem (this);
+ }
+ }
+
+ /** Returns this checkbox's label if this checkbox is selected. */
+ public Object[] getSelectedObjects ()
+ {
+ Object[] r;
+ if (state)
+ {
+ r = new Object[1];
+ r[0] = label;
+ }
+ else
+ r = new Object[0];
+ return r;
+ }
+
+ /** Returns the current state of this checkbox. */
+ public boolean getState ()
+ {
+ return state;
+ }
+
+ /** Generates a String representation of this Checkbox's state. */
+ public String paramString ()
+ {
+ return ("[" + getClass ().getName ()
+ + "state=" + state + ","
+ + "label=" + label + "]");
+ }
+
+ /** Process an event for this Checkbox.
+ * @param event The event the process.
+ */
+ protected void processEvent (AWTEvent event)
+ {
+ if (event instanceof ItemEvent)
+ processItemEvent ((ItemEvent) event);
+ else
+ super.processEvent (event);
+ }
+
+ /** Process an item event for this Checkbox.
+ * @param event The ItemEvent to process
+ */
+ protected void processItemEvent (ItemEvent event)
+ {
+ if (listeners != null)
+ listeners.itemStateChanged (event);
+ }
+
+ /** Remove an item listener.
+ * @param listener Item listener to remove.
+ */
+ public synchronized void removeItemListener (ItemListener listener)
+ {
+ listeners = AWTEventMulticaster.remove (listeners, listener);
+ }
+
+ /** Set the checkbox's state.
+ * @param state The new state.
+ */
+ public void setState (boolean state)
+ {
+ this.state = state;
+ if (peer != null)
+ {
+ CheckboxMenuItemPeer cp = (CheckboxMenuItemPeer) peer;
+ cp.setState (state);
+ }
+ }
+
+ // Private state.
+ String label;
+ boolean state;
+ ItemListener listeners;
}