package W3C.PICS;

import java.awt.*;
import java.util.Vector;

/**
    A Checkbox with built-in ranking. It will always make sure that
    all the higher-ranked (smaller rank number) checkboxes are checked
    and lower-ranked checkboxes are unchecked.
*/
public class RankedCheckbox extends DCheckbox
{
    public RankedCheckbox(String label,
                          String Description,
                          TextComponent DText,
                          int rank,
                          Vector Checkboxes)
    {
      super(label,Description,DText);
      this.rank=rank;
      this.Checkboxes=Checkboxes;
    }

   public void setState(boolean state)
   {
    super.setState(state);
    if (!trueset)
        {if (state)
            {
            for (int i=0;i<rank;i++)
                ((RankedCheckbox)Checkboxes.elementAt(i)).truesetState(true);
            }
            for (int i=rank+1;i<Checkboxes.size();i++)
                ((RankedCheckbox)Checkboxes.elementAt(i)).truesetState(false);

        }
   }

   public void truesetState(boolean state)
   {
    trueset=true;
    setState(state);
    trueset=false;
   }

   private boolean trueset=false;
   private int rank;
   private Vector Checkboxes=null;

}