KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.table.*;
20 import javax.swing.event.*;
21 import javax.swing.border.*;
22 import java.util.*;
23 import java.beans.*;
24
25 import org.compiere.util.*;
26 import org.compiere.apps.*;
27 import org.compiere.plaf.*;
28 import org.compiere.swing.*;
29
30 /**
31  * Text Control (JTextArea embedded in JScrollPane)
32  *
33  * @author Jorg Janke
34  * @version $Id: VText.java,v 1.22 2003/09/05 04:58:59 jjanke Exp $
35  */

36 public class VText extends CText
37     implements VEditor, KeyListener, ActionListener
38 {
39     /**
40      * IDE Baan Constructor
41      */

42     public VText()
43     {
44         this("", false, false, true, 60, 2000);
45     } // VText
46

47     /**
48      * Standard Constructor
49      * @param columnName column name
50      * @param mandatory mandatory
51      * @param isReadOnly read only
52      * @param isUpdateable updateable
53      * @param displayLength display length
54      * @param fieldLength field length
55      */

56     public VText (String JavaDoc columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
57         int displayLength, int fieldLength)
58     {
59         super (fieldLength < 300 ? 2 : 3, 50);
60         super.setName(columnName);
61         LookAndFeel.installBorder(this, "TextField.border");
62
63         // Create Editor
64
setColumns(displayLength>VString.MAXDISPLAY_LENGTH ? VString.MAXDISPLAY_LENGTH : displayLength); // 46
65
setForeground(CompierePLAF.getTextColor_Normal());
66         setBackground(CompierePLAF.getFieldBackground_Normal());
67
68         setLineWrap(true);
69         setWrapStyleWord(true);
70         setMandatory(mandatory);
71         m_columnName = columnName;
72
73         if (isReadOnly || !isUpdateable)
74             setReadWrite(false);
75         addKeyListener(this);
76
77         // Popup
78
addMouseListener(new VText_mouseAdapter(this));
79         if (columnName.equals("Script"))
80             menuEditor = new JMenuItem(Msg.getMsg(Env.getCtx(), "Script"), Env.getImageIcon("Script16.gif"));
81         else
82             menuEditor = new JMenuItem(Msg.getMsg(Env.getCtx(), "Editor"), Env.getImageIcon("Editor16.gif"));
83         menuEditor.addActionListener(this);
84         popupMenu.add(menuEditor);
85     } // VText
86

87     /**
88      * Dispose
89      */

90     public void dispose()
91     {
92     } // dispose
93

94     JPopupMenu popupMenu = new JPopupMenu();
95     private JMenuItem menuEditor;
96
97     private String JavaDoc m_columnName;
98     private String JavaDoc m_oldText;
99     private String JavaDoc m_initialText;
100     private volatile boolean m_setting = false;
101
102     /**
103      * Set Editor to value
104      * @param value value
105      */

106     public void setValue(Object JavaDoc value)
107     {
108         if (value == null)
109             m_oldText = "";
110         else
111             m_oldText = value.toString();
112         if (m_setting)
113             return;
114         super.setValue(m_oldText);
115         m_initialText = m_oldText;
116     } // setValue
117

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

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

128     /**
129      * ActionListener
130      * @param e event
131      */

132     public void actionPerformed(ActionEvent e)
133     {
134         if (e.getSource() == menuEditor)
135         {
136             menuEditor.setEnabled(false);
137             String JavaDoc s = null;
138             if (m_columnName.equals("Script"))
139                 s = ScriptEditor.start (Msg.translate(Env.getCtx(), m_columnName), getText(), isEditable(), 0);
140             else
141                 s = Editor.startEditor (this, Msg.translate(Env.getCtx(), m_columnName), getText(), isEditable());
142             menuEditor.setEnabled(true);
143             setValue(s);
144         }
145         // Data Binding
146
try
147         {
148             fireVetoableChange(m_columnName, m_oldText, getText());
149         }
150         catch (PropertyVetoException pve) {}
151     } // actionPerformed
152

153     /**
154      * Action Listener Interface - NOP
155      * @param listener listener
156      */

157     public void addActionListener(ActionListener listener)
158     {
159     } // addActionListener
160

161     /**************************************************************************
162      * Key Listener Interface
163      * @param e event
164      */

165     public void keyTyped(KeyEvent e) {}
166     public void keyPressed(KeyEvent e) {}
167
168     /**
169      * Key Released
170      * if Escape restore old Text.
171      * @param e event
172      */

173     public void keyReleased(KeyEvent e)
174     {
175         // ESC
176
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
177             setText(m_initialText);
178         m_setting = true;
179         try
180         {
181             fireVetoableChange(m_columnName, m_oldText, getText());
182         }
183         catch (PropertyVetoException pve) {}
184         m_setting = false;
185     } // keyReleased
186

187     /**
188      * Set Field/WindowNo for ValuePreference (NOP)
189      * @param mField field model
190      */

191     public void setField (org.compiere.model.MField mField)
192     {
193     } // setField
194

195 } // VText
196

197 /*****************************************************************************/
198
199 /**
200  * Mouse Listener
201  */

202 final class VText_mouseAdapter extends MouseAdapter
203 {
204     /**
205      * Constructor
206      * @param adaptee VText
207      */

208     VText_mouseAdapter(VText adaptee)
209     {
210         this.adaptee = adaptee;
211     } // VText_mouseAdapter
212

213     private VText adaptee;
214
215     /**
216      * Mouse Listener
217      * @param e event
218      */

219     public void mouseClicked(MouseEvent e)
220     {
221         // popup menu
222
if (SwingUtilities.isRightMouseButton(e))
223             adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
224     } // mouse Clicked
225

226 } // VText_mouseAdapter
227
Popular Tags