diff options
author | Tom Tromey <tromey@redhat.com> | 2000-12-26 00:25:13 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2000-12-26 00:25:13 +0000 |
commit | 5472d1951a2f96bf92d004dec143cd21a4da3965 (patch) | |
tree | a938f800a6d828c421e0820a9d7ebe6d666e7f6e /libjava/java/awt/Checkbox.java | |
parent | 83050e0d93035b6d3f426df57e9096243d63800e (diff) | |
download | gcc-5472d1951a2f96bf92d004dec143cd21a4da3965.zip gcc-5472d1951a2f96bf92d004dec143cd21a4da3965.tar.gz gcc-5472d1951a2f96bf92d004dec143cd21a4da3965.tar.bz2 |
MenuContainer.java: Fixed typo.
* java/awt/MenuContainer.java: Fixed typo.
* Makefile.in: Rebuilt.
* Makefile.am (awt_java_source_files): Added SystemColor.java.
* java/awt/SystemColor.java: New file.
* java/awt/Color.java (rgba): Now package-private.
* java/awt/event/InputEvent.java (isAltGraphDown): New method.
* java/awt/event/ContainerEvent.java (getContainer): Renamed from
getComponent.
* java/awt/MenuItem.java (addNotify): New method.
(MenuItem(String,MenuShortcut)): New constructor.
(setLabel): Notify peer of change.
(setEnabled): Likewise.
* java/awt/GridLayout.java (toString): New method.
* java/awt/FlowLayout.java (LEADING, TRAILING): New constants.
(FlowLayout): Check for LEADING and TRAILING.
(setAlignment): Likewise.
(layoutContainer): Handle component orientation.
* java/awt/Component.java (orientatin): New field.
(setComponentOrientation): Wrote.
(getComponentOrientation): Wrote.
* java/awt/Event.java (Event): Implements Serializable.
(consumed): New field for serialization.
* java/awt/Dimension.java (Dimension): Implements Serializable.
* java/awt/Cursor.java (Cursor): Implements Serializable.
* java/awt/Container.java (Container): No longer abstract.
* java/awt/Choice.java: Wrote.
* java/awt/Checkbox.java: Wrote.
* java/awt/ItemSelectable.java: Documented.
* java/awt/CheckboxGroup.java: Wrote.
* java/awt/CardLayout.java (layoutContainer): Directly use fields
in other classes.
(getSize): Likewise.
From-SVN: r38486
Diffstat (limited to 'libjava/java/awt/Checkbox.java')
-rw-r--r-- | libjava/java/awt/Checkbox.java | 176 |
1 files changed, 173 insertions, 3 deletions
diff --git a/libjava/java/awt/Checkbox.java b/libjava/java/awt/Checkbox.java index ec1f20d..10c6744 100644 --- a/libjava/java/awt/Checkbox.java +++ b/libjava/java/awt/Checkbox.java @@ -7,9 +7,179 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for details. */ package java.awt; +import java.awt.event.*; +import java.awt.peer.CheckboxPeer; -/* A very incomplete placeholder. */ - -public class Checkbox extends Component +/** This class implements a component which has an on/off state. Two + * or more Checkboxes can be grouped by a CheckboxGroup. + * @author Tom Tromey <tromey@redhat.com> + * @date December 25, 2000 + */ +public class Checkbox extends Component implements ItemSelectable { + /** Create a new checkbox. + * @param label The checkbox label. A null value is the same as ""; + * this is the default. + * @param state The initial check state; defaults to false. + * @param group The CheckboxGroup. Defaults to null. + */ + public Checkbox () + { + this (null, null, false); + } + + public Checkbox (String label) + { + this (label, null, false); + } + + public Checkbox (String label, boolean state) + { + this (label, null, state); + } + + public Checkbox (String label, boolean state, CheckboxGroup group) + { + this (label, group, state); + } + + public Checkbox (String label, CheckboxGroup group, boolean state) + { + this.label = label; + this.group = group; + 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) + peer = getToolkit ().createCheckbox (this); + } + + /** Returns the current CheckboxGroup associated with this + * Checkbox. */ + public CheckboxGroup getCheckboxGroup () + { + return group; + } + + /** Returns the current label; might be null. */ + public String getLabel () + { + return label; + } + + /** 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. */ + protected String paramString () + { + return ("Checkbox[" + + "state=" + state + "," + + "label=" + label + "," + + "group=" + group + "]"); + } + + /** 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 this checkbox's group. + * @param group The new group. null means remove the Checkbox from + * its group. + */ + public void setCheckboxGroup (CheckboxGroup group) + { + this.group = group; + if (peer != null) + { + CheckboxPeer cp = (CheckboxPeer) peer; + cp.setCheckboxGroup (group); + } + } + + /** Set the checkbox's label. + * @param label The new label + */ + public synchronized void setLabel (String label) + { + this.label = label; + if (peer != null) + { + CheckboxPeer cp = (CheckboxPeer) peer; + // FIXME: unclear what to do here; we err on the side of + // caution. + cp.setLabel (label == null ? "" : label); + } + } + + /** Set the checkbox's state. + * @param state The new state. + */ + public void setState (boolean state) + { + this.state = state; + if (peer != null) + { + CheckboxPeer cp = (CheckboxPeer) peer; + cp.setState (state); + } + } + + private ItemListener listeners; + + String label; + CheckboxGroup group; + boolean state; } |