1 14 package org.wings; 15 16 import org.wings.plaf.CheckBoxCG; 17 18 import java.util.Arrays ; 19 20 30 31 35 public class SCheckBox extends SAbstractButton { 36 public SCheckBox() { 37 this(false); 38 } 39 40 43 public SCheckBox(String text) { 44 this(false); 45 setText(text); 46 } 47 48 public SCheckBox(boolean selected) { 49 setSelected(selected); 50 51 setHorizontalTextPosition(SConstants.NO_ALIGN); 52 setVerticalTextPosition(SConstants.NO_ALIGN); 53 54 super.setType(CHECKBOX); 55 } 56 57 protected void setGroup(SButtonGroup g) { 58 if (g != null) { 59 throw new IllegalArgumentException ("SCheckBox don`t support button groups, use SRadioButton"); 60 } } 62 63 public final void setType(String t) { 64 if (!CHECKBOX.equals(t)) 65 throw new IllegalArgumentException ("type change not supported, type is fix: checkbox"); 66 67 super.setType(t); 68 } 69 70 public void setCG(CheckBoxCG cg) { 71 super.setCG(cg); 72 } 73 74 public void processLowLevelEvent(String action, String [] values) { 75 processKeyEvents(values); 76 77 boolean requestSelection; 78 if (Arrays.asList(values).contains("hidden_reset")) { 79 requestSelection = values.length == 2; 82 } else { 83 requestSelection = parseSelectionToggle(values[0]); 84 } 85 86 if (requestSelection != isSelected()) { 87 delayEvents(true); 88 setSelected(requestSelection); 89 SForm.addArmedComponent(this); 91 } } 93 94 99 protected boolean parseSelectionToggle(String toggleParameter) { 100 if (getShowAsFormComponent()) { 102 return !isSelected(); 103 } 105 if ("1".equals(toggleParameter)) 106 return true; 107 else if ("0".equals(toggleParameter)) 108 return false; 109 110 111 return isSelected(); 113 } 114 115 } 116 117 118 | Popular Tags |