KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.event.*;
18 import java.text.*;
19 import javax.swing.*;
20 import java.math.*;
21 import java.beans.*;
22
23 import org.compiere.util.*;
24 import org.compiere.model.*;
25 import org.compiere.apps.*;
26 import org.compiere.plaf.*;
27 import org.compiere.swing.*;
28
29 /**
30  * Account Control - Displays ValidCombination and launches Dialog
31  *
32  * @author Jorg Janke
33  * @version $Id: VAccount.java,v 1.13 2003/09/05 04:58:59 jjanke Exp $
34  */

35 public final class VAccount extends JComponent
36     implements VEditor, ActionListener
37 {
38     /**
39      * Constructor
40      * @param columnName
41      * @param mandatory
42      * @param isReadOnly
43      * @param isUpdateable
44      * @param mAccount
45      * @param title
46      */

47     public VAccount(String JavaDoc columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
48         MAccount mAccount, String JavaDoc title)
49     {
50         super();
51         super.setName(columnName);
52         m_columnName = columnName;
53         m_mAccount = mAccount;
54         m_title = title;
55         //
56
LookAndFeel.installBorder(this, "TextField.border");
57         this.setLayout(new BorderLayout());
58         // Size
59
this.setPreferredSize(m_text.getPreferredSize()); // causes r/o to be the same length
60
int height = m_text.getPreferredSize().height;
61
62         // *** Button & Text ***
63
m_text.setBorder(null);
64         m_text.setEditable(false);
65         m_text.setFocusable(false);
66         m_text.setFont(CompierePLAF.getFont_Field());
67         m_text.setForeground(CompierePLAF.getTextColor_Normal());
68         this.add(m_text, BorderLayout.CENTER);
69
70         m_button.setIcon(Env.getImageIcon("Account10.gif"));
71         m_button.setMargin(new Insets(0, 0, 0, 0));
72         m_button.setPreferredSize(new Dimension(height, height));
73         m_button.addActionListener(this);
74         this.add(m_button, BorderLayout.EAST);
75
76         // Editable
77
if (isReadOnly || !isUpdateable)
78             setReadWrite (false);
79         else
80             setReadWrite (true);
81         setMandatory (mandatory);
82     } // VAccount
83

84     /**
85      * Dispose
86      */

87     public void dispose()
88     {
89         m_text = null;
90         m_button = null;
91         m_mAccount = null;
92     } // dispose
93

94     private JTextField m_text = new JTextField (VLookup.DISPLAY_LENGTH);
95     private CButton m_button = new CButton();
96     private MAccount m_mAccount;
97     private Object JavaDoc m_value;
98     private String JavaDoc m_title;
99
100     private String JavaDoc m_columnName;
101
102     /**
103      * Enable/disable
104      * @param value
105      */

106     public void setReadWrite(boolean value)
107     {
108         m_button.setReadWrite(value);
109         if (m_button.isVisible() != value)
110             m_button.setVisible(value);
111         setBackground(false);
112     } // setReadWrite
113

114     /**
115      * IsReadWrite
116      * @return true if read write
117      */

118     public boolean isReadWrite()
119     {
120         return m_button.isReadWrite();
121     } // isReadWrite
122

123     /**
124      * Set Mandatory (and back bolor)
125      * @param mandatory
126      */

127     public void setMandatory (boolean mandatory)
128     {
129         m_button.setMandatory(mandatory);
130         setBackground(false);
131     } // setMandatory
132

133     /**
134      * Is it mandatory
135      * @return mandatory
136      */

137     public boolean isMandatory()
138     {
139         return m_button.isMandatory();
140     } // isMandatory
141

142     /**
143      * Set Background
144      * @param color
145      */

146     public void setBackground (Color color)
147     {
148         if (!color.equals(m_text.getBackground()))
149             m_text.setBackground(color);
150     } // setBackground
151

152     /**
153      * Set Background based on editable / mandatory / error
154      * @param error if true, set background to error color, otherwise mandatory/editable
155      */

156     public void setBackground (boolean error)
157     {
158         if (error)
159             setBackground(CompierePLAF.getFieldBackground_Error());
160         else if (!isReadWrite())
161             setBackground(CompierePLAF.getFieldBackground_Inactive());
162         else if (isMandatory())
163             setBackground(CompierePLAF.getFieldBackground_Mandatory());
164         else
165             setBackground(CompierePLAF.getFieldBackground_Normal());
166     } // setBackground
167

168     /**
169      * Set Foreground
170      * @param fg
171      */

172     public void setForeground(Color fg)
173     {
174         m_text.setForeground(fg);
175     } // setForeground
176

177     /**
178      * Set Editor to value
179      * @param value
180      */

181     public void setValue (Object JavaDoc value)
182     {
183         m_value = value;
184         m_text.setText(m_mAccount.getDisplay(value)); // loads value
185
m_text.setToolTipText(m_mAccount.getDescription());
186     } // setValue
187

188     /**
189      * Property Change Listener
190      * @param evt
191      */

192     public void propertyChange (PropertyChangeEvent evt)
193     {
194         if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY))
195             setValue(evt.getNewValue());
196     } // propertyChange
197

198     /**
199      * Return Editor value
200      * @return value
201      */

202     public Object JavaDoc getValue()
203     {
204         return new Integer JavaDoc (m_mAccount.C_ValidCombination_ID);
205     } // getValue
206

207     /**
208      * Return Display Value
209      * @return String representation
210      */

211     public String JavaDoc getDisplay()
212     {
213         return m_text.getText();
214     } // getDisplay
215

216     /**
217      * ActionListener - Button - Start Dialog
218      * @param e
219      */

220     public void actionPerformed(ActionEvent e)
221     {
222         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
223         VAccountDialog ad = new VAccountDialog (Env.getFrame(this), m_title, m_mAccount);
224         // display
225
setCursor(Cursor.getDefaultCursor());
226         Object JavaDoc newValue = ad.getValue();
227         if (newValue == null)
228             return;
229
230         // set & redisplay
231
setValue(newValue);
232
233         // Data Binding
234
try
235         {
236             fireVetoableChange(m_columnName, null, newValue);
237         }
238         catch (PropertyVetoException pve)
239         {
240         }
241     } // actionPerformed
242

243     /**
244      * Action Listener Interface
245      * @param listener
246      */

247     public void addActionListener(ActionListener listener)
248     {
249         m_text.addActionListener(listener);
250     } // addActionListener
251

252     /**
253      * Set Field/WindowNo for ValuePreference (NOP)
254      * @param mField
255      */

256     public void setField (org.compiere.model.MField mField)
257     {
258     } // setField
259

260 } // VAccount
261

262
Popular Tags