1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 18 import javax.swing.JTextField ; 19 import javax.swing.text.Document ; 20 21 import org.compiere.plaf.CompierePLAF; 22 23 29 public class CTextField extends JTextField implements CEditor 30 { 31 36 public CTextField() 37 { 38 super(); 39 init(); 40 } 42 49 public CTextField (String text) 50 { 51 super (text); 52 init(); 53 } 55 66 public CTextField (int columns) 67 { 68 super (columns); 69 init(); 70 } 72 82 public CTextField (String text, int columns) 83 { 84 super (text, columns); 85 init(); 86 } 88 104 public CTextField (Document doc, String text, int columns) 105 { 106 super (doc, text, columns); 107 init(); 108 } 110 113 private void init() 114 { 115 setFont(CompierePLAF.getFont_Field()); 116 setForeground(CompierePLAF.getTextColor_Normal()); 117 setBackground (false); 118 } 120 121 122 123 private boolean m_mandatory = false; 124 125 129 public void setMandatory (boolean mandatory) 130 { 131 m_mandatory = mandatory; 132 setBackground(false); 133 } 135 139 public boolean isMandatory() 140 { 141 return m_mandatory; 142 } 144 148 public void setReadWrite (boolean rw) 149 { 150 if (super.isEditable() != rw) 151 super.setEditable (rw); 152 setBackground(false); 153 } 155 159 public boolean isReadWrite() 160 { 161 return super.isEditable(); 162 } 164 165 169 public void setBackground (boolean error) 170 { 171 if (error) 172 setBackground(CompierePLAF.getFieldBackground_Error()); 173 else if (!isReadWrite()) 174 setBackground(CompierePLAF.getFieldBackground_Inactive()); 175 else if (m_mandatory) 176 setBackground(CompierePLAF.getFieldBackground_Mandatory()); 177 else 178 setBackground(CompierePLAF.getFieldBackground_Normal()); 179 180 } 182 186 public void setBackground (Color bg) 187 { 188 if (bg.equals(getBackground())) 189 return; 190 super.setBackground(bg); 191 } 193 197 public void setValue (Object value) 198 { 199 if (value == null) 200 setText(""); 201 else 202 setText(value.toString()); 203 } 205 209 public Object getValue() 210 { 211 return getText(); 212 } 214 218 public String getDisplay() 219 { 220 return getText(); 221 } 223 227 public void fireActionPerformed() 228 { 229 super.fireActionPerformed(); 230 } 232 } | Popular Tags |