Commit d8d27d73 by Tom Tromey Committed by Tom Tromey

CheckboxGroup.java: Merged with Classpath.

	* java/awt/CheckboxGroup.java: Merged with Classpath.
	* java/awt/Checkbox.java: Merged with Classpath.

From-SVN: r48933
parent a82484a6
2002-01-16 Tom Tromey <tromey@redhat.com> 2002-01-16 Tom Tromey <tromey@redhat.com>
* java/awt/CheckboxGroup.java: Merged with Classpath.
* java/awt/Checkbox.java: Merged with Classpath.
* java/awt/Dimension.java: Updated copyright. Added javadoc from * java/awt/Dimension.java: Updated copyright. Added javadoc from
Classpath. Classpath.
* java/awt/Point.java: Updated copyright. * java/awt/Point.java: Updated copyright.
......
/* Copyright (C) 2000, 2001 Free Software Foundation /* Checkbox.java -- An AWT checkbox widget
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of libgcj. This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.awt; package java.awt;
import java.awt.event.*;
import java.awt.peer.CheckboxPeer; import java.awt.peer.CheckboxPeer;
import java.awt.peer.ComponentPeer;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.Serializable;
/** This class implements a component which has an on/off state. Two /**
* This class implements a component which has an on/off state. Two
* or more Checkboxes can be grouped by a CheckboxGroup. * or more Checkboxes can be grouped by a CheckboxGroup.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Tom Tromey <tromey@redhat.com> * @author Tom Tromey <tromey@redhat.com>
* @date December 25, 2000
*/ */
public class Checkbox extends Component implements ItemSelectable public class Checkbox extends Component implements ItemSelectable, Serializable
{ {
/** Create a new checkbox.
* @param label The checkbox label. A null value is the same as ""; // FIXME: Need readObject/writeObject for this.
* this is the default.
* @param state The initial check state; defaults to false. /*
* @param group The CheckboxGroup. Defaults to null. * Static Variables
*/ */
public Checkbox ()
{ // Serialization Constant
this (null, null, false); private static final long serialVersionUID = 7270714317450821763L;
}
/*************************************************************************/
public Checkbox (String label)
{ /*
this (label, null, false); * Instance Variables
} */
public Checkbox (String label, boolean state) /**
{ * @serial The checkbox group for this checkbox.
this (label, null, state); */
} private CheckboxGroup group;
public Checkbox (String label, boolean state, CheckboxGroup group) /**
{ * @serial The label on this checkbox.
this (label, group, state); */
} private String label;
public Checkbox (String label, CheckboxGroup group, boolean state) /**
{ * @serial The state of this checkbox.
this.label = label; */
this.group = group; private boolean state;
this.state = state;
} // The list of listeners for this object.
private transient ItemListener item_listeners;
/** Add a listener for item events.
* @param listener The listener to add. /*************************************************************************/
*/
public synchronized void addItemListener (ItemListener listener) /*
{ * Constructors
listeners = AWTEventMulticaster.add (listeners, listener); */
}
/**
/** This creates the component's peer. */ * Initializes a new instance of <code>Checkbox</code> with no label,
public void addNotify () * an initial state of off, and that is not part of any checkbox group.
{ */
if (peer == null) public
peer = getToolkit ().createCheckbox (this); Checkbox()
super.addNotify (); {
} this("", false, null);
}
/** Returns the current CheckboxGroup associated with this
* Checkbox. */ /*************************************************************************/
public CheckboxGroup getCheckboxGroup ()
{ /**
return group; * Initializes a new instance of <code>Checkbox</code> with the specified
} * label, an initial state of off, and that is not part of any checkbox
* group.
/** Returns the current label; might be null. */ *
public String getLabel () * @param label The label for this checkbox.
{ */
return label; public
} Checkbox(String label)
{
/** Returns this checkbox's label if this checkbox is selected. */ this(label, false, null);
public Object[] getSelectedObjects () }
{
Object[] r; /*************************************************************************/
if (state)
{ /**
r = new Object[1]; * Initializes a new instance of <code>Checkbox</code> with the specified
r[0] = label; * label and initial state, and that is not part of any checkbox
} * group.
else *
r = new Object[0]; * @param label The label for this checkbox.
return r; * @param state The initial state of the checkbox, <code>true</code> for
} * on, <code>false</code> for off.
*/
/** Returns the current state of this checkbox. */ public
public boolean getState () Checkbox(String label, boolean state)
{ {
return state; this(label, state, null);
} }
/** Generates a String representation of this Checkbox's state. */ /*************************************************************************/
protected String paramString ()
{ /**
return ("Checkbox[" * Initializes a new instance of <code>Checkbox</code> with the specified
+ "state=" + state + "," * label, initial state, and checkbox group.
+ "label=" + label + "," *
+ "group=" + group + "]"); * @param label The label for this checkbox.
} * @param group The checkbox group for this box, or <code>null</code>
* if there is no checkbox group.
/** Process an event for this Checkbox. * @param state The initial state of the checkbox, <code>true</code> for
* @param event The event the process. * on, <code>false</code> for off.
*/ */
protected void processEvent (AWTEvent event) public
{ Checkbox(String label, CheckboxGroup group, boolean state)
if (event instanceof ItemEvent) {
processItemEvent ((ItemEvent) event); this(label, state, group);
else }
super.processEvent (event);
} /*************************************************************************/
/** Process an item event for this Checkbox. /**
* @param event The ItemEvent to process * Initializes a new instance of <code>Checkbox</code> with the specified
*/ * label, initial state, and checkbox group.
protected void processItemEvent (ItemEvent event) *
{ * @param label The label for this checkbox.
if (listeners != null) * @param state The initial state of the checkbox, <code>true</code> for
listeners.itemStateChanged (event); * on, <code>false</code> for off.
} * @param group The checkbox group for this box, or <code>null</code>
* if there is no checkbox group.
/** Remove an item listener. */
* @param listener Item listener to remove. public
*/ Checkbox(String label, boolean state, CheckboxGroup group)
public synchronized void removeItemListener (ItemListener listener) {
{ this.label = label;
listeners = AWTEventMulticaster.remove (listeners, listener); this.state = state;
} this.group = group;
}
/** Set this checkbox's group.
* @param group The new group. null means remove the Checkbox from /*************************************************************************/
* its group.
*/ /*
public void setCheckboxGroup (CheckboxGroup group) * Instance Variables
{ */
this.group = group;
if (peer != null) /**
{ * Returns the label for this checkbox.
CheckboxPeer cp = (CheckboxPeer) peer; *
cp.setCheckboxGroup (group); * @return The label for this checkbox.
} */
} public String
getLabel()
/** Set the checkbox's label. {
* @param label The new label return(label);
*/ }
public synchronized void setLabel (String label)
{ /*************************************************************************/
this.label = label;
if (peer != null) /**
{ * Sets the label for this checkbox to the specified value.
CheckboxPeer cp = (CheckboxPeer) peer; *
// FIXME: unclear what to do here; we err on the side of * @param label The new checkbox label.
// caution. */
cp.setLabel (label == null ? "" : label); public synchronized void
} setLabel(String label)
} {
this.label = label;
/** Set the checkbox's state. if (peer != null)
* @param state The new state. {
*/ CheckboxPeer cp = (CheckboxPeer) peer;
public void setState (boolean state) cp.setLabel(label);
{ }
this.state = state;
if (peer != null)
{
CheckboxPeer cp = (CheckboxPeer) peer;
cp.setState (state);
}
}
private ItemListener listeners;
String label;
CheckboxGroup group;
boolean state;
} }
/*************************************************************************/
/**
* Returns the state of this checkbox.
*
* @return The state of this checkbox, which will be <code>true</code> for
* on and <code>false</code> for off.
*/
public boolean
getState()
{
return(state);
}
/*************************************************************************/
/**
* Sets the state of this checkbox to the specified value.
*
* @param state The new state of the checkbox, which will be <code>true</code>
* for on or <code>false</code> for off.
*/
public synchronized void
setState(boolean state)
{
this.state = state;
if (peer != null)
{
CheckboxPeer cp = (CheckboxPeer) peer;
cp.setState (state);
}
}
/*************************************************************************/
/**
* Returns an array of length one containing the checkbox label if this
* checkbox is selected. Otherwise <code>null</code> is returned.
*
* @return The selection state of this checkbox.
*/
public Object[]
getSelectedObjects()
{
if (state == false)
return(null);
Object[] objs = new Object[1];
objs[0] = label;
return(objs);
}
/*************************************************************************/
/**
* Returns the checkbox group this object is a member of, if any.
*
* @return This object's checkbox group, of <code>null</code> if it is
* not a member of any group.
*/
public CheckboxGroup
getCheckboxGroup()
{
return(group);
}
/*************************************************************************/
/**
* Sets this object's checkbox group to the specified group.
*
* @param group The new checkbox group, or <code>null</code> to make this
* object part of no checkbox group.
*/
public synchronized void
setCheckboxGroup(CheckboxGroup group)
{
this.group = group;
if (peer != null)
{
CheckboxPeer cp = (CheckboxPeer) peer;
cp.setCheckboxGroup (group);
}
}
/*************************************************************************/
/**
* Creates this object's native peer.
*/
public void
addNotify()
{
if (peer == null)
peer = getToolkit ().createCheckbox (this);
super.addNotify ();
}
/*************************************************************************/
/**
* Adds a new listeners to the list of registered listeners for this object.
*
* @param listener The new listener to add.
*/
public synchronized void
addItemListener(ItemListener listener)
{
item_listeners = AWTEventMulticaster.add(item_listeners, listener);
}
/*************************************************************************/
/**
* Removes a listener from the list of registered listeners for this object.
*
* @param listener The listener to remove.
*/
public synchronized void
removeItemListener(ItemListener listener)
{
item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
}
/*************************************************************************/
/**
* Processes this event by calling <code>processItemEvent()</code> if it
* is any instance of <code>ItemEvent</code>. Otherwise it is passed to
* the superclass for processing.
*
* @param event The event to process.
*/
protected void
processEvent(AWTEvent event)
{
if (event instanceof ItemEvent)
processItemEvent((ItemEvent)event);
else
super.processEvent(event);
}
/*************************************************************************/
/**
* Processes this event by dispatching it to any registered listeners.
*
* @param event The <code>ItemEvent</code> to process.
*/
protected void
processItemEvent(ItemEvent event)
{
if (item_listeners != null)
item_listeners.itemStateChanged(event);
}
/*************************************************************************/
/**
* Returns a debugging string for this object.
*/
protected String
paramString()
{
return(getClass().getName() + "[label=" + label + ",state=" + state
+ ",group=" + group + "]");
}
} // class Checkbox
/* Copyright (C) 2000 Free Software Foundation /* CheckboxGroup.java -- A grouping class for checkboxes.
Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
This file is part of libgcj. This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package java.awt; package java.awt;
import java.io.Serializable; /**
* This class if for combining checkboxes into groups so that only
* one checkbox in the group can be selected at any one time.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
* @author Tom Tromey <tromey@redhat.com>
*/
public class CheckboxGroup implements java.io.Serializable
{
/*
* Static Variables
*/
// Serialization constant
private static final long serialVersionUID = 3729780091441768983L;
/*************************************************************************/
/*
* Instance Variables
*/
/**
* @serial The currently selected checkbox.
*/
private Checkbox selectedCheckbox;
/*************************************************************************/
/*
* Constructors
*/
/**
* Initializes a new instance of <code>CheckboxGroup</code>.
*/
public
CheckboxGroup()
{
}
/*************************************************************************/
/** This class is used to groups checkbox components. /*
* @author Tom Tromey <tromey@redhat.com> * Instance Methods
* @date December 25, 2000
*/ */
public class CheckboxGroup implements Serializable
/**
* Returns the currently selected checkbox, or <code>null</code> if none
* of the checkboxes in this group are selected.
*
* @return The selected checkbox.
*/
public Checkbox
getSelectedCheckbox()
{
return(selectedCheckbox);
}
/*************************************************************************/
/**
* Returns the currently selected checkbox, or <code>null</code> if none
* of the checkboxes in this group are selected.
*
* @return The selected checkbox.
*
* @deprecated This method is deprecated in favor of
* <code>getSelectedCheckbox()</code>.
*/
public Checkbox
getCurrent()
{
return(selectedCheckbox);
}
/*************************************************************************/
/**
* This method sets the specified checkbox to be the selected on in this
* group, and unsets all others.
*
* @param selectedCheckbox The new selected checkbox.
*/
public void
setSelectedCheckbox(Checkbox selectedCheckbox)
{ {
// Current set checkbox. if (this.selectedCheckbox != null)
Checkbox selectedCheckbox; {
if (this.selectedCheckbox.getCheckboxGroup() != this)
/** Create a new instance of CheckboxGroup. */ return;
public CheckboxGroup ()
{ this.selectedCheckbox.setState(false);
} }
/** Returns the currently selected checkbox in the group. this.selectedCheckbox = selectedCheckbox;
* @deprecated if (selectedCheckbox != null)
*/ selectedCheckbox.setState(true);
public Checkbox getCurrent ()
{
return getSelectedCheckbox ();
}
/** Returns the currently selected checkbox in the group. */
public Checkbox getSelectedCheckbox ()
{
return selectedCheckbox;
}
/** Set the selected checkbox.
* @deprecated
*/
public synchronized void setCurrent (Checkbox checkbox)
{
setSelectedCheckbox (checkbox);
}
/** Set the selected checkbox. */
public synchronized void setSelectedCheckbox (Checkbox checkbox)
{
if (checkbox != null && checkbox.group != this)
return;
selectedCheckbox.setState (false);
selectedCheckbox = checkbox;
if (checkbox != null)
checkbox.setState (true);
}
/** Return String representation of this class and current Checkbox. */
public String toString ()
{
return "[CheckboxGroup: " + selectedCheckbox + "]";
}
} }
/*************************************************************************/
/**
* This method sets the specified checkbox to be the selected on in this
* group, and unsets all others.
*
* @param selectedCheckbox The new selected checkbox.
*
* @deprecated This method is deprecated in favor of
* <code>setSelectedCheckbox()</code>.
*/
public void
setCurrent(Checkbox selectedCheckbox)
{
setSelectedCheckbox(selectedCheckbox);
}
/*************************************************************************/
/**
* Returns a string representation of this checkbox group.
*
* @return A string representation of this checkbox group.
*/
public String
toString()
{
return(getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]");
}
} // class CheckboxGroup
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment