/[classpath]/classpath/javax/swing/ButtonGroup.java
ViewVC logotype

Diff of /classpath/javax/swing/ButtonGroup.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by mark, Sat Jun 26 16:06:48 2004 UTC revision 1.7 by mark, Sat Sep 4 20:31:20 2004 UTC
# Line 42  import java.util.Enumeration; Line 42  import java.util.Enumeration;
42  import java.util.Vector;  import java.util.Vector;
43    
44    
45  public class ButtonGroup  /**
46    implements Serializable   * DOCUMENT ME!
47     */
48    public class ButtonGroup implements Serializable
49  {  {
50      /** DOCUMENT ME! */
51    private static final long serialVersionUID = 4259076101881721375L;    private static final long serialVersionUID = 4259076101881721375L;
52    
53    /**    /** The buttons added to this button group. */
    * The buttons added to this button group.  
    */  
54    protected Vector buttons = new Vector();    protected Vector buttons = new Vector();
55    
56    /**    /** The currently selected button model. */
    * The currently selected button model.  
    */  
57    ButtonModel sel;    ButtonModel sel;
58    
59    /**    /**
# Line 99  public class ButtonGroup Line 98  public class ButtonGroup
98    /**    /**
99     * Returns the currently selected button model.     * Returns the currently selected button model.
100     *     *
101     * @return the currently selected button model,     * @return the currently selected button model, null if none was selected
102     * null if none was selected yet     *         yet
103     */     */
104    public ButtonModel getSelection()    public ButtonModel getSelection()
105    {    {
106      return sel;      return sel;
107    }    }
108    
109      /**
110       * DOCUMENT ME!
111       *
112       * @param m DOCUMENT ME!
113       *
114       * @return DOCUMENT ME!
115       */
116    AbstractButton FindButton(ButtonModel m)    AbstractButton FindButton(ButtonModel m)
117    {    {
118      for (int i = 0;i < buttons.size(); i++)      for (int i = 0; i < buttons.size(); i++)
119        {        {
120          AbstractButton a = (AbstractButton) buttons.get(i);          AbstractButton a = (AbstractButton) buttons.get(i);
121          if (a.getModel() == m)          if (a.getModel() == m)
# Line 119  public class ButtonGroup Line 125  public class ButtonGroup
125    }    }
126    
127    /**    /**
128     * Sets the currently selected button model. Only one button of a group     * Sets the currently selected button model. Only one button of a group can
129     * can be selected at a time.     * be selected at a time.
130     *     *
131     * @param m the model to select     * @param m the model to select
132     * @param b true if this button is to be selected, false otherwise     * @param b true if this button is to be selected, false otherwise
133     */     */
134    public void setSelected(ButtonModel m, boolean b)    public void setSelected(ButtonModel m, boolean b)
135    {    {
136      if ((m == sel) && (b == true))      if ((sel != m || b) && (! b || sel == m))
137        {        return;
         // clicked on same item twice.  
         System.out.println("PRESSED TWICE:" + m + ", sel=" + sel);  
         return;  
       }  
138    
139      if (sel != null)      if (b && sel != m)
140        {        {
141          System.out.println("DESELECTING: " + sel);          ButtonModel old = sel;
142          sel.setSelected(! b);          sel = m;
143    
144          AbstractButton but = FindButton(sel);          if (old != null)
145          if (but != null)            old.setSelected(false);
146            {          AbstractButton button = FindButton(old);
147              System.out.println("REPAINT-REQUEST: " + but.text);          if (button != null)
148              //but.revalidate();            button.repaint();
             but.repaint();  
           }  
149        }        }
150      else      else if (! b && sel == m)
151        System.out.println("NO SELECTION YET");        m.setSelected(true);
   
     sel = m;  
152    }    }
153    
154    /**    /**
155     * Checks if the given <code>ButtonModel</code> is selected     * Checks if the given <code>ButtonModel</code> is selected in this button
156     * in this button group.     * group.
157       *
158       * @param m DOCUMENT ME!
159     *     *
160     * @return true of given <code>ButtonModel</code> is selected,     * @return true of given <code>ButtonModel</code> is selected, false
161     * false otherwise     *         otherwise
162     */     */
163    public boolean isSelected(ButtonModel m)    public boolean isSelected(ButtonModel m)
164    {    {

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26