1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 18 import javax.swing.Action ; 19 import javax.swing.Icon ; 20 import javax.swing.JCheckBox ; 21 22 import org.compiere.plaf.CompierePLAF; 23 24 30 public class CCheckBox extends JCheckBox implements CEditor 31 { 32 35 public CCheckBox () 36 { 37 super (); 38 init(); 39 } 40 41 46 public CCheckBox(Icon icon) 47 { 48 super (icon); 49 init(); 50 } 51 52 60 public CCheckBox(Icon icon, boolean selected) 61 { 62 super (icon, selected); 63 init(); 64 } 65 66 71 public CCheckBox (String text) 72 { 73 super (text); 74 init(); 75 } 76 77 82 public CCheckBox(Action a) 83 { 84 super (a); 85 init(); 86 } 87 88 96 public CCheckBox (String text, boolean selected) 97 { 98 super (text, selected); 99 init(); 100 } 101 102 109 public CCheckBox(String text, Icon icon) 110 { 111 super (text, icon, false); 112 init(); 113 } 114 115 124 public CCheckBox (String text, Icon icon, boolean selected) 125 { 126 super (text, icon, selected); 127 init(); 128 } 129 130 133 private void init() 134 { 135 setFont(CompierePLAF.getFont_Label()); 136 setForeground(CompierePLAF.getTextColor_Label()); 137 } 139 140 141 142 private boolean m_mandatory = false; 143 144 private boolean m_readWrite = true; 145 146 147 151 public void setMandatory (boolean mandatory) 152 { 153 m_mandatory = mandatory; 154 setBackground(false); 155 } 157 161 public boolean isMandatory() 162 { 163 return m_mandatory; 164 } 166 170 public void setReadWrite (boolean rw) 171 { 172 if (super.isEnabled() != rw) 173 super.setEnabled (rw); 174 setBackground(false); 175 m_readWrite = rw; 176 } 178 182 public boolean isReadWrite() 183 { 184 return m_readWrite; 185 } 187 191 public void setBackground (boolean error) 192 { 193 } 195 199 public void setBackground (Color bg) 200 { 201 if (bg.equals(getBackground())) 202 return; 203 super.setBackground(bg); 204 } 206 207 208 private Object m_value = null; 209 210 214 public void setValue (Object value) 215 { 216 m_value = value; 217 boolean sel = false; 218 if (value == null) 219 sel = false; 220 else if (value.toString().equals("Y")) 221 sel = true; 222 else if (value.toString().equals("N")) 223 sel = false; 224 else if (value instanceof Boolean ) 225 sel = ((Boolean )value).booleanValue(); 226 else 227 { 228 try 229 { 230 sel = Boolean.getBoolean(value.toString()); 231 } 232 catch (Exception e) 233 { 234 } 235 } 236 this.setSelected(sel); 237 } 239 243 public Object getValue() 244 { 245 if (m_value instanceof String ) 246 return super.isSelected() ? "Y" : "N"; 247 return new Boolean (isSelected()); 248 } 250 254 public String getDisplay() 255 { 256 if (m_value instanceof String ) 257 return super.isSelected() ? "Y" : "N"; 258 return Boolean.toString(super.isSelected()); 259 } 261 } | Popular Tags |