1 package autotest.afe; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 public class CheckBoxPanel { 7 public static interface Display { generateCheckBox(int index)8 public ICheckBox generateCheckBox(int index); 9 } 10 11 private List<ICheckBox> checkBoxes = new ArrayList<ICheckBox>(); 12 private Display display; 13 bindDisplay(Display display)14 public void bindDisplay(Display display) { 15 this.display = display; 16 } 17 generateCheckBox()18 public ICheckBox generateCheckBox() { 19 return display.generateCheckBox(checkBoxes.size()); 20 } 21 add(ICheckBox checkBox)22 public void add(ICheckBox checkBox) { 23 checkBoxes.add(checkBox); 24 } 25 getChecked()26 public List<ICheckBox> getChecked() { 27 List<ICheckBox> result = new ArrayList<ICheckBox>(); 28 for(ICheckBox checkBox : checkBoxes) { 29 if (checkBox.getValue()) { 30 result.add(checkBox); 31 } 32 } 33 return result; 34 } 35 setEnabled(boolean enabled)36 public void setEnabled(boolean enabled) { 37 for(ICheckBox thisBox : checkBoxes) { 38 thisBox.setEnabled(enabled); 39 } 40 } 41 reset()42 public void reset() { 43 for (ICheckBox thisBox : checkBoxes) { 44 thisBox.setValue(false); 45 } 46 } 47 } 48