001package polaris.sdk.ui.controls;
002import polaris.sdk.ui.*;
003
004public class RadioGroup extends Panel {
005 private int selected=-1;
006 public RadioGroup(){glass=false;flow=Layout.ROW;gap=Spacing.GAP;padding=0;h=36;w=330;}
007 public RadioGroup(String... labels){this();for(String s:labels)option(s);}
008 public RadioGroup option(String s){RadioButton b=new RadioButton(s);b.group=this;b.bounds(0,0,105,36);add(b);return this;}
009 void choose(RadioButton b){select(children.indexOf(b));}
010 public void select(int index){if(index<0||index>=children.size())throw new IllegalArgumentException("index");selected=index;for(int i=0;i<children.size();i++)((RadioButton)children.get(i)).selected(i==index);changed();}
011 public int selectedIndex(){return selected;}
012 @Override protected void layoutChildren(){if(!children.isEmpty())for(Widget c:children)c.bounds(c.x(),c.y(),Math.max(1,(w-gap*(children.size()-1))/children.size()),h);super.layoutChildren();}
013}