This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[GUI] Patch: javax.swing.ButtongGroup
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Thu, 10 Jun 2004 12:01:02 +0200
- Subject: [GUI] Patch: javax.swing.ButtongGroup
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to get javax.swing.ButtonGroup in
shape.
Michael
2004-06-10 Michael Koch <konqueror@gmx.de>
* javax/swing/ButtonGroup.java
(serialVersionUID): Made private.
(buttons): Renamed from v, added javadoc.
(sel): Added javadoc.
(ButtonGroup): Likewise.
(add): Likewise.
(remove): Likewise.
(getElements): Likewise.
(getSelection): Likewise.
(setSelected): Likewise.
(isSelected): Likewise.
(getButtonCount): Likewise.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAyDFhWSOgCCdjSDsRAo8JAKCNaJahrygJ1op0ol0RLwMdVmVCnACeKgh2
dkp2YRVsXE9odJrZLmElKB4=
=GjXX
-----END PGP SIGNATURE-----
Index: javax/swing/ButtonGroup.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/ButtonGroup.java,v
retrieving revision 1.4.2.1
diff -u -b -B -r1.4.2.1 ButtonGroup.java
--- javax/swing/ButtonGroup.java 10 Jun 2004 08:49:07 -0000 1.4.2.1
+++ javax/swing/ButtonGroup.java 10 Jun 2004 09:58:02 -0000
@@ -45,31 +45,63 @@
public class ButtonGroup
implements Serializable
{
- static final long serialVersionUID = 4259076101881721375L;
- Vector v = new Vector();
+ private static final long serialVersionUID = 4259076101881721375L;
+
+ /**
+ * The buttons added to this button group.
+ */
+ protected Vector buttons = new Vector();
+
+ /**
+ * The currently selected button model.
+ */
ButtonModel sel;
+ /**
+ * Creates a new button group.
+ */
public ButtonGroup()
{
}
+ /**
+ * Adds a button to this group.
+ *
+ * @param b the button to add
+ */
public void add(AbstractButton b)
{
b.getModel().setGroup(this);
- v.addElement(b);
+ buttons.addElement(b);
}
+ /**
+ * Removed a given button from this group.
+ *
+ * @param b the button to remove
+ */
public void remove(AbstractButton b)
{
b.getModel().setGroup(null);
- v.removeElement(b);
+ buttons.removeElement(b);
}
+ /**
+ * Returns the currently added buttons.
+ *
+ * @return <code>Enumeration</code> over all added buttons
+ */
public Enumeration getElements()
{
- return v.elements();
+ return buttons.elements();
}
+ /**
+ * Returns the currently selected button model.
+ *
+ * @return the currently selected button model,
+ * null if none was selected yet
+ */
public ButtonModel getSelection()
{
return sel;
@@ -77,20 +109,27 @@
AbstractButton FindButton(ButtonModel m)
{
- for (int i = 0; i < v.size(); i++)
+ for (int i = 0;i < buttons.size(); i++)
{
- AbstractButton a = (AbstractButton) v.get(i);
+ AbstractButton a = (AbstractButton) buttons.get(i);
if (a.getModel() == m)
return a;
}
return null;
}
+ /**
+ * Sets the currently selected button model. Only one button of a group
+ * can be selected at a time.
+ *
+ * @param m the model to select
+ * @param b true if this button is to be selected, false otherwise
+ */
public void setSelected(ButtonModel m, boolean b)
{
if ((m == sel) && (b == true))
{
- // clicked on sam item twice.
+ // clicked on same item twice.
System.out.println("PRESSED TWICE:" + m + ", sel=" + sel);
return;
}
@@ -103,7 +142,7 @@
AbstractButton but = FindButton(sel);
if (but != null)
{
- System.out.println("REPAINT-REQUIST: " + but.text);
+ System.out.println("REPAINT-REQUEST: " + but.text);
//but.revalidate();
but.repaint();
}
@@ -114,13 +153,27 @@
sel = m;
}
+ /**
+ * Checks if the given <code>ButtonModel</code> is selected
+ * in this button group.
+ *
+ * @return true of given <code>ButtonModel</code> is selected,
+ * false otherwise
+ */
public boolean isSelected(ButtonModel m)
{
- return (m == sel);
+ return m == sel;
}
+ /**
+ * Return the number of buttons in this button group.
+ *
+ * @return the number of buttons
+ *
+ * @since 1.3
+ */
public int getButtonCount()
{
- return v.size();
+ return buttons.size();
}
}