// Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   JButtonGroupPanel.java

package com.symantec.itools.javax.swing;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;

public class JButtonGroupPanel extends JPanel
    implements ActionListener
{

    public JButtonGroupPanel()
    {
        buttons = new Vector();
        group = new ButtonGroup();
        listeners = new Vector();
        super.setLayout(new GridLayout());
    }

    public JButtonGroupPanel(ButtonGroup buttongroup)
    {
        buttons = new Vector();
        group = new ButtonGroup();
        listeners = new Vector();
        for(Enumeration enumeration = buttongroup.getElements(); enumeration.hasMoreElements(); add((AbstractButton)enumeration.nextElement()));
    }

    public Enumeration getElements()
    {
        return group.getElements();
    }

    public void addActionListener(ActionListener actionlistener)
    {
        if(!listeners.contains(actionlistener))
            listeners.addElement(actionlistener);
    }

    public void removeActionListener(ActionListener actionlistener)
    {
        if(listeners.contains(actionlistener))
            listeners.removeElement(actionlistener);
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        Vector vector;
        synchronized(listeners)
        {
            vector = (Vector)listeners.clone();
        }
        ActionEvent actionevent1 = new ActionEvent(this, 1001, ((AbstractButton)actionevent.getSource()).getText());
        for(Enumeration enumeration = vector.elements(); enumeration.hasMoreElements(); ((ActionListener)enumeration.nextElement()).actionPerformed(actionevent1));
    }

    protected void addImpl(Component component, Object obj, int i)
    {
        if(component instanceof AbstractButton)
        {
            AbstractButton abstractbutton = (AbstractButton)component;
            if(!buttons.contains(abstractbutton))
            {
                buttons.addElement(abstractbutton);
                group.add(abstractbutton);
                abstractbutton.addActionListener(this);
                super.addImpl(component, obj, i);
                return;
            }
        }
        else
        {
            super.addImpl(component, obj, i);
        }
    }

    public void remove(AbstractButton abstractbutton)
    {
        if(buttons.contains(abstractbutton))
        {
            buttons.removeElement(abstractbutton);
            group.remove(abstractbutton);
        }
    }

    public void setSelection(AbstractButton abstractbutton, boolean flag)
    {
        abstractbutton.getModel().setSelected(flag);
    }

    public void setSelection(String s, boolean flag)
    {
        for(Enumeration enumeration = buttons.elements(); enumeration.hasMoreElements();)
        {
            AbstractButton abstractbutton = (AbstractButton)enumeration.nextElement();
            if(abstractbutton.getText().equals(s))
                setSelection(abstractbutton, flag);
        }

    }

    public AbstractButton getSelection()
    {
        ButtonModel buttonmodel = group.getSelection();
        for(Enumeration enumeration = buttons.elements(); enumeration.hasMoreElements();)
        {
            AbstractButton abstractbutton = (AbstractButton)enumeration.nextElement();
            if(abstractbutton.getModel() == buttonmodel)
                return abstractbutton;
        }

        return null;
    }

    public boolean isSelected(AbstractButton abstractbutton)
    {
        return abstractbutton == getSelection();
    }

    public boolean isSelected(String s)
    {
        return s.equals(getSelection().getText());
    }

    protected Vector buttons;
    protected Vector listeners;
    protected ButtonGroup group;
}
