1 14 package org.compiere.grid.ed; 15 16 import java.awt.*; 17 import javax.swing.*; 18 import java.awt.event.*; 19 import java.beans.*; 20 21 import org.compiere.apps.*; 22 import org.compiere.util.*; 23 import org.compiere.plaf.*; 24 import org.compiere.swing.*; 25 import org.compiere.model.*; 26 27 37 public final class VPassword extends CPassword 38 implements VEditor, KeyListener, ActionListener 39 { 40 43 public VPassword() 44 { 45 this("Password", false, false, true, 30, 30, ""); 46 } 48 58 public VPassword (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, 59 int displayLength, int fieldLength, String VFormat) 60 { 61 super (displayLength>VString.MAXDISPLAY_LENGTH ? VString.MAXDISPLAY_LENGTH : displayLength); 62 super.setName(columnName); 63 m_columnName = columnName; 64 if (VFormat == null) 65 VFormat = ""; 66 m_VFormat = VFormat; 67 m_fieldLength = fieldLength; 68 if (m_VFormat.length() != 0 || m_fieldLength != 0) 69 setDocument(new MDocString(m_VFormat, m_fieldLength, this)); 70 if (m_VFormat.length() != 0) 71 setCaret(new VOvrCaret()); 72 setMandatory(mandatory); 74 75 if (isReadOnly || !isUpdateable) 77 { 78 setEditable(false); 79 setBackground(CompierePLAF.getFieldBackground_Inactive()); 80 } 81 82 this.addKeyListener(this); 83 this.addActionListener(this); 84 85 setForeground(CompierePLAF.getTextColor_Normal()); 86 setBackground(CompierePLAF.getFieldBackground_Normal()); 87 } 89 92 public void dispose() 93 { 94 m_mField = null; 95 } 97 private MField m_mField = null; 98 99 private String m_columnName; 100 private String m_oldText; 101 private String m_VFormat; 102 private int m_fieldLength; 103 private volatile boolean m_setting = false; 104 105 109 public void setValue (Object value) 110 { 111 if (value == null) 112 m_oldText = ""; 113 else 114 m_oldText = value.toString(); 115 if (!m_setting) 116 setText (m_oldText); 117 } 119 123 public void propertyChange (PropertyChangeEvent evt) 124 { 125 if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY)) 126 setValue(evt.getNewValue()); 127 } 129 133 public Object getValue() 134 { 135 return String.valueOf(getPassword()); 136 } 138 142 public String getDisplay() 143 { 144 return String.valueOf(getPassword()); 145 } 147 151 public void keyTyped(KeyEvent e) {} 152 public void keyPressed(KeyEvent e) {} 153 154 158 public void keyReleased(KeyEvent e) 159 { 160 String newText = String.valueOf(getPassword()); 161 m_setting = true; 162 try 163 { 164 fireVetoableChange(m_columnName, m_oldText, newText); 165 } 166 catch (PropertyVetoException pve) {} 167 m_setting = false; 168 } 170 174 public void actionPerformed(ActionEvent e) 175 { 176 String newText = String.valueOf(getPassword()); 177 if (e.getActionCommand().equals(ValuePreference.NAME)) 178 { 179 ValuePreference.start (m_mField, newText); 180 return; 181 } 182 try 184 { 185 fireVetoableChange(m_columnName, m_oldText, newText); 186 } 187 catch (PropertyVetoException pve) {} 188 } 190 194 public void setField (MField mField) 195 { 196 m_mField = mField; 197 } 199 } 201 | Popular Tags |