1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 18 import javax.swing.JPasswordField ; 19 import javax.swing.text.Document ; 20 21 import org.compiere.plaf.CompierePLAF; 22 23 29 public class CPassword extends JPasswordField implements CEditor 30 { 31 36 public CPassword() 37 { 38 super(); 39 init(); 40 } 41 42 49 public CPassword (String text) 50 { 51 super (text); 52 init(); 53 } 54 55 62 public CPassword (int columns) 63 { 64 super (columns); 65 init(); 66 } 67 68 76 public CPassword (String text, int columns) 77 { 78 super (text,columns); 79 init(); 80 } 81 82 96 public CPassword (Document doc, String txt, int columns) 97 { 98 super (doc, txt, columns); 99 init(); 100 } 101 102 105 private void init() 106 { 107 setFont(CompierePLAF.getFont_Field()); 108 setForeground(CompierePLAF.getTextColor_Normal()); 109 } 111 112 113 114 private boolean m_mandatory = false; 115 116 120 public void setMandatory (boolean mandatory) 121 { 122 m_mandatory = mandatory; 123 setBackground(false); 124 } 126 130 public boolean isMandatory() 131 { 132 return m_mandatory; 133 } 135 139 public void setReadWrite (boolean rw) 140 { 141 if (super.isEditable() != rw) 142 super.setEditable (rw); 143 setBackground(false); 144 } 146 150 public boolean isReadWrite() 151 { 152 return super.isEditable(); 153 } 155 159 public void setBackground (boolean error) 160 { 161 if (error) 162 setBackground(CompierePLAF.getFieldBackground_Error()); 163 else if (!isReadWrite()) 164 setBackground(CompierePLAF.getFieldBackground_Inactive()); 165 else if (m_mandatory) 166 setBackground(CompierePLAF.getFieldBackground_Mandatory()); 167 else 168 setBackground(CompierePLAF.getFieldBackground_Normal()); 169 } 171 175 public void setBackground (Color bg) 176 { 177 if (bg.equals(getBackground())) 178 return; 179 super.setBackground(bg); 180 } 182 186 public void setValue (Object value) 187 { 188 if (value == null) 189 setText(""); 190 else 191 setText(value.toString()); 192 } 194 198 public Object getValue() 199 { 200 return new String (super.getPassword()); 201 } 203 207 public String getDisplay() 208 { 209 return new String (super.getPassword()); 210 } 212 213 } | Popular Tags |