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>
* java/awt/CheckboxGroup.java: Merged with Classpath.
* java/awt/Checkbox.java: Merged with Classpath.
* java/awt/Dimension.java: Updated copyright. Added javadoc from
Classpath.
* 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;
import java.awt.event.*;
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.
*
* @author Aaron M. Renn (arenn@urbanophile.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 "";
* this is the default.
* @param state The initial check state; defaults to false.
* @param group The CheckboxGroup. Defaults to null.
// FIXME: Need readObject/writeObject for this.
/*
* Static Variables
*/
public Checkbox ()
{
this (null, null, false);
}
public Checkbox (String label)
{
this (label, null, false);
}
// Serialization Constant
private static final long serialVersionUID = 7270714317450821763L;
public Checkbox (String label, boolean state)
{
this (label, null, state);
}
/*************************************************************************/
public Checkbox (String label, boolean state, CheckboxGroup group)
{
this (label, group, state);
}
/*
* Instance Variables
*/
public Checkbox (String label, CheckboxGroup group, boolean state)
{
this.label = label;
this.group = group;
this.state = state;
}
/**
* @serial The checkbox group for this checkbox.
*/
private CheckboxGroup group;
/** Add a listener for item events.
* @param listener The listener to add.
/**
* @serial The label on this checkbox.
*/
public synchronized void addItemListener (ItemListener listener)
{
listeners = AWTEventMulticaster.add (listeners, listener);
}
private String label;
/** This creates the component's peer. */
public void addNotify ()
{
if (peer == null)
peer = getToolkit ().createCheckbox (this);
super.addNotify ();
}
/**
* @serial The state of this checkbox.
*/
private boolean state;
/** Returns the current CheckboxGroup associated with this
* Checkbox. */
public CheckboxGroup getCheckboxGroup ()
{
return group;
}
// The list of listeners for this object.
private transient ItemListener item_listeners;
/** 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;
}
/*
* Constructors
*/
/** Returns the current state of this checkbox. */
public boolean getState ()
{
return state;
}
/**
* Initializes a new instance of <code>Checkbox</code> with no label,
* an initial state of off, and that is not part of any checkbox group.
*/
public
Checkbox()
{
this("", false, null);
}
/** 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.
/**
* 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.
*
* @param label The label for this checkbox.
*/
protected void processEvent (AWTEvent event)
{
if (event instanceof ItemEvent)
processItemEvent ((ItemEvent) event);
else
super.processEvent (event);
}
public
Checkbox(String label)
{
this(label, false, null);
}
/** 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 and initial state, and that is not part of any checkbox
* group.
*
* @param label The label for this checkbox.
* @param state The initial state of the checkbox, <code>true</code> for
* on, <code>false</code> for off.
*/
protected void processItemEvent (ItemEvent event)
{
if (listeners != null)
listeners.itemStateChanged (event);
}
public
Checkbox(String label, boolean state)
{
this(label, state, null);
}
/*************************************************************************/
/** Remove an item listener.
* @param listener Item listener to remove.
/**
* Initializes a new instance of <code>Checkbox</code> with the specified
* label, initial state, and checkbox 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.
* @param state The initial state of the checkbox, <code>true</code> for
* on, <code>false</code> for off.
*/
public synchronized void removeItemListener (ItemListener listener)
{
listeners = AWTEventMulticaster.remove (listeners, listener);
}
public
Checkbox(String label, CheckboxGroup group, boolean state)
{
this(label, state, group);
}
/*************************************************************************/
/** Set this checkbox's group.
* @param group The new group. null means remove the Checkbox from
* its group.
/**
* Initializes a new instance of <code>Checkbox</code> with the specified
* label, initial state, and checkbox group.
*
* @param label The label for this checkbox.
* @param state The initial state of the checkbox, <code>true</code> for
* on, <code>false</code> for off.
* @param group The checkbox group for this box, or <code>null</code>
* if there is no checkbox group.
*/
public void setCheckboxGroup (CheckboxGroup group)
{
public
Checkbox(String label, boolean state, CheckboxGroup group)
{
this.label = label;
this.state = state;
this.group = group;
if (peer != null)
{
CheckboxPeer cp = (CheckboxPeer) peer;
cp.setCheckboxGroup (group);
}
}
}
/*************************************************************************/
/** Set the checkbox's label.
* @param label The new label
/*
* Instance Variables
*/
public synchronized void setLabel (String label)
{
/**
* Returns the label for this checkbox.
*
* @return The label for this checkbox.
*/
public String
getLabel()
{
return(label);
}
/*************************************************************************/
/**
* Sets the label for this checkbox to the specified value.
*
* @param label The new checkbox 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);
}
cp.setLabel(label);
}
}
/*************************************************************************/
/** Set the checkbox's state.
* @param state The new 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 void setState (boolean state)
{
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);
}
}
private ItemListener listeners;
/*************************************************************************/
String label;
CheckboxGroup group;
boolean state;
/**
* 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.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
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.
package java.awt;
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.
import java.io.Serializable;
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 class is used to groups checkbox components.
package java.awt;
/**
* 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>
* @date December 25, 2000
*/
public class CheckboxGroup implements Serializable
public class CheckboxGroup implements java.io.Serializable
{
// Current set checkbox.
Checkbox selectedCheckbox;
/** Create a new instance of CheckboxGroup. */
public CheckboxGroup ()
{
}
/*
* Static Variables
*/
// Serialization constant
private static final long serialVersionUID = 3729780091441768983L;
/*************************************************************************/
/** Returns the currently selected checkbox in the group.
* @deprecated
/*
* Instance Variables
*/
public Checkbox getCurrent ()
{
return getSelectedCheckbox ();
}
/** Returns the currently selected checkbox in the group. */
public Checkbox getSelectedCheckbox ()
{
return selectedCheckbox;
}
/**
* @serial The currently selected checkbox.
*/
private Checkbox selectedCheckbox;
/** Set the selected checkbox.
* @deprecated
/*************************************************************************/
/*
* Constructors
*/
public synchronized void setCurrent (Checkbox checkbox)
{
setSelectedCheckbox (checkbox);
}
/** Set the selected checkbox. */
public synchronized void setSelectedCheckbox (Checkbox checkbox)
/**
* Initializes a new instance of <code>CheckboxGroup</code>.
*/
public
CheckboxGroup()
{
}
/*************************************************************************/
/*
* Instance Methods
*/
/**
* 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)
{
if (this.selectedCheckbox != null)
{
if (checkbox != null && checkbox.group != this)
if (this.selectedCheckbox.getCheckboxGroup() != this)
return;
selectedCheckbox.setState (false);
selectedCheckbox = checkbox;
if (checkbox != null)
checkbox.setState (true);
this.selectedCheckbox.setState(false);
}
/** Return String representation of this class and current Checkbox. */
public String toString ()
{
return "[CheckboxGroup: " + selectedCheckbox + "]";
}
this.selectedCheckbox = selectedCheckbox;
if (selectedCheckbox != null)
selectedCheckbox.setState(true);
}
/*************************************************************************/
/**
* 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