1 14 package org.wings; 15 16 17 import org.wings.plaf.RadioButtonCG; 18 19 30 public class SRadioButton 31 extends SAbstractButton { 32 public SRadioButton() { 33 setType(RADIOBUTTON); 34 } 35 36 public SRadioButton(String label) { 37 super(label, RADIOBUTTON); 38 } 39 40 public SRadioButton(boolean selected) { 41 this(); 42 setSelected(selected); 43 } 44 45 public String getLowLevelEventId() { 46 if (getGroup() != null && getShowAsFormComponent()) { 47 return getGroup().getComponentId(); 48 } else { 49 return super.getLowLevelEventId(); 50 } } 52 53 public void setType(String t) { 54 if (!RADIOBUTTON.equals(t)) 55 throw new IllegalArgumentException ("type change not supported, type is fix: radiobutton"); 56 57 super.setType(t); 58 } 59 60 public void setCG(RadioButtonCG cg) { 61 super.setCG(cg); 62 } 63 64 public void processLowLevelEvent(String action, String [] values) { 65 processKeyEvents(values); 66 67 boolean origSelected = isSelected(); 68 69 if (getShowAsFormComponent()) { 70 if (getGroup() == null) { 71 setSelected(values.length == 2); 74 } else { 75 int eventCount = 0; 76 for (int i = 0; i < values.length; i++) { 77 if (getName().equals(values[i])) { 81 eventCount++; 82 } } setSelected(eventCount == 2); 87 } } else { 89 if (getGroup() != null) { 90 getGroup().setDelayEvents(true); 91 setSelected(parseSelectionToggle(values[0])); 92 getGroup().setDelayEvents(false); 93 } else { 94 setSelected(parseSelectionToggle(values[0])); 95 } } 97 98 if (isSelected() != origSelected) { 99 SForm.addArmedComponent(this); 101 } } 103 104 109 protected boolean parseSelectionToggle(String toggleParameter) { 110 if (getShowAsFormComponent()) { 112 return !isSelected(); 113 } 115 if ("1".equals(toggleParameter)) 116 return true; 117 else if ("0".equals(toggleParameter)) 118 return false; 119 120 121 return isSelected(); 123 } 124 125 public String getSelectionParameter() { 126 if (getGroup() != null && getShowAsFormComponent()) { 127 return getName(); 128 } else { 129 return "1"; 130 } 131 } 132 133 public String getDeselectionParameter() { 134 if (getGroup() != null && getShowAsFormComponent()) { 135 return getName(); 136 } else { 137 return "0"; 138 } 139 } 140 } 141 | Popular Tags |