KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.*;
19 import java.beans.*;
20
21 import org.compiere.util.*;
22 import org.compiere.plaf.*;
23 import org.compiere.swing.*;
24
25 /**
26  * Checkbox Control
27  *
28  * @author Jorg Janke
29  * @version $Id: VCheckBox.java,v 1.10 2003/09/05 04:58:59 jjanke Exp $
30  */

31 public class VCheckBox extends CCheckBox
32     implements VEditor, ActionListener
33 {
34     /**
35      * Default Constructor
36      */

37     public VCheckBox()
38     {
39         this("", false, false, true, "", null, false);
40     } // VCheckBox
41

42     /**
43      * Standard Constructor
44      * @param columnName
45      * @param mandatory
46      * @param isReadOnly
47      * @param isUpdateable
48      * @param title
49      * @param description
50      * @param tableEditor
51      */

52     public VCheckBox(String JavaDoc columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
53         String JavaDoc title, String JavaDoc description, boolean tableEditor)
54     {
55         super();
56         super.setName(columnName);
57         m_columnName = columnName;
58         setMandatory(mandatory);
59         //
60
if (isReadOnly || !isUpdateable)
61             setEditable(false);
62         else
63             setEditable(true);
64
65         // Normal
66
if (!tableEditor)
67         {
68             setText(title);
69             if (description != null && description.length() > 0)
70                 setToolTipText(description);
71         }
72         else
73         {
74             setHorizontalAlignment(JLabel.CENTER);
75         }
76         //
77
this.addActionListener(this);
78     } // VCheckBox
79

80     /**
81      * Dispose
82      */

83     public void dispose()
84     {
85     } // dispose
86

87     private String JavaDoc m_columnName;
88
89     /**
90      * Set Editable
91      * @param value
92      */

93     public void setEditable (boolean value)
94     {
95         super.setReadWrite(value);
96     } // setEditable
97

98     /**
99      * IsEditable
100      * @return true if editable
101      */

102     public boolean isEditable()
103     {
104         return super.isReadWrite();
105     } // isEditable
106

107     /**
108      * Set Editor to value
109      * @param value
110      */

111     public void setValue(Object JavaDoc value)
112     {
113         boolean sel = false;
114         if (value != null && value.toString().equals("Y"))
115             sel = true;
116         setSelected(sel);
117     } // setValue
118

119     /**
120      * Property Change Listener
121      * @param evt
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         if (isSelected())
136             return "Y";
137         return "N";
138     } // getValue
139

140     /**
141      * Return Display Value
142      * @return value
143      */

144     public String JavaDoc getDisplay()
145     {
146         if (isSelected())
147             return "Y";
148         return "N";
149     } // getDisplay
150

151     /**
152      * Set Background (nop)
153      */

154     public void setBackground()
155     {
156     } // setBackground
157

158     /**
159      * Action Listener - data binding
160      * @param e
161      */

162     public void actionPerformed(ActionEvent e)
163     {
164     // ADebug.info("VCheckBox.actionPerformed");
165
try
166         {
167             fireVetoableChange(m_columnName, null, getValue());
168         }
169         catch (PropertyVetoException pve)
170         {
171         }
172     } // actionPerformed
173

174     /**
175      * Set Field/WindowNo for ValuePreference (NOP)
176      * @param mField
177      */

178     public void setField (org.compiere.model.MField mField)
179     {
180     } // setField
181

182 } // VCheckBox
183
Popular Tags