KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > ed > VPassword


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

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 /**
28  * Data Binding:
29  * VEditors call fireVetoableChange(m_columnName, null, getText());
30  * GridController (for Single-Row) and VCellExitor (for Multi-Row)
31  * listen to Vetoable Change Listener (vetoableChange)
32  * then set the value for that column in the current row in the table
33  *
34  * @author Jorg Janke
35  * @version $Id: VPassword.java,v 1.8 2003/09/05 04:58:59 jjanke Exp $
36  */

37 public final class VPassword extends CPassword
38     implements VEditor, KeyListener, ActionListener
39 {
40     /**
41      * IDE Bean Constructor for 30 character updateable field
42      */

43     public VPassword()
44     {
45         this("Password", false, false, true, 30, 30, "");
46     } // VPassword
47

48     /**
49      * Detail Constructor
50      * @param columnName column name
51      * @param mandatory mandatory
52      * @param isReadOnly read only
53      * @param isUpdateable updateable
54      * @param displayLength display length
55      * @param fieldLength field length
56      * @param VFormat format
57      */

58     public VPassword (String JavaDoc columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
59         int displayLength, int fieldLength, String JavaDoc 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         //
73
setMandatory(mandatory);
74
75         // Editable
76
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     } // VPassword
88

89     /**
90      * Dispose
91      */

92     public void dispose()
93     {
94         m_mField = null;
95     } // dispose
96

97     private MField m_mField = null;
98
99     private String JavaDoc m_columnName;
100     private String JavaDoc m_oldText;
101     private String JavaDoc m_VFormat;
102     private int m_fieldLength;
103     private volatile boolean m_setting = false;
104
105     /**
106      * Set Editor to value
107      * @param value value
108      */

109     public void setValue (Object JavaDoc 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     } // setValue
118

119     /**
120      * Property Change Listener
121      * @param evt event
122      */

123     public void propertyChange (PropertyChangeEvent evt)
124     {
125         if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY))
126             setValue(evt.getNewValue());
127     } // propertyChange
128

129     /**
130      * Return Editor value
131      * @return value
132      */

133     public Object JavaDoc getValue()
134     {
135         return String.valueOf(getPassword());
136     } // getValue
137

138     /**
139      * Return Display Value
140      * @return value
141      */

142     public String JavaDoc getDisplay()
143     {
144         return String.valueOf(getPassword());
145     } // getDisplay
146

147     /**************************************************************************
148      * Key Listener Interface
149      * @param e event
150      */

151     public void keyTyped(KeyEvent e) {}
152     public void keyPressed(KeyEvent e) {}
153
154     /**
155      * Key Listener.
156      * @param e event
157      */

158     public void keyReleased(KeyEvent e)
159     {
160         String JavaDoc 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     } // keyReleased
169

170     /**
171      * Data Binding to MTable (via GridController) - Enter pressed
172      * @param e event
173      */

174     public void actionPerformed(ActionEvent e)
175     {
176         String JavaDoc newText = String.valueOf(getPassword());
177         if (e.getActionCommand().equals(ValuePreference.NAME))
178         {
179             ValuePreference.start (m_mField, newText);
180             return;
181         }
182         // Data Binding
183
try
184         {
185             fireVetoableChange(m_columnName, m_oldText, newText);
186         }
187         catch (PropertyVetoException pve) {}
188     } // actionPerformed
189

190     /**
191      * Set Field/WindowNo for ValuePreference
192      * @param mField field
193      */

194     public void setField (MField mField)
195     {
196         m_mField = mField;
197     } // setField
198

199 } // VPassword
200

201
Popular Tags