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 VString extends CTextField 38 implements VEditor, KeyListener, ActionListener 39 { 40 public static final int MAXDISPLAY_LENGTH = org.compiere.model.MField.MAXDISPLAY_LENGTH; 41 42 45 public VString() 46 { 47 this("String", false, false, true, 30, 30, ""); 48 } 50 60 public VString (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, 61 int displayLength, int fieldLength, String VFormat) 62 { 63 super(displayLength>MAXDISPLAY_LENGTH ? MAXDISPLAY_LENGTH : displayLength); 64 super.setName(columnName); 65 m_columnName = columnName; 66 if (VFormat == null) 67 VFormat = ""; 68 m_VFormat = VFormat; 69 m_fieldLength = fieldLength; 70 if (m_VFormat.length() != 0 || m_fieldLength != 0) 71 setDocument(new MDocString(m_VFormat, m_fieldLength, this)); 72 if (m_VFormat.length() != 0) 73 setCaret(new VOvrCaret()); 74 setMandatory(mandatory); 76 77 if (isReadOnly || !isUpdateable) 79 { 80 setEditable(false); 81 setBackground(CompierePLAF.getFieldBackground_Inactive()); 82 } 83 84 this.addKeyListener(this); 85 this.addActionListener(this); 86 if (fieldLength > displayLength) 88 { 89 addMouseListener(new VString_mouseAdapter(this)); 90 mEditor = new JMenuItem (Msg.getMsg(Env.getCtx(), "Editor"), Env.getImageIcon("Editor16.gif")); 91 mEditor.addActionListener(this); 92 popupMenu.add(mEditor); 93 } 94 setForeground(CompierePLAF.getTextColor_Normal()); 95 setBackground(CompierePLAF.getFieldBackground_Normal()); 96 } 98 101 public void dispose() 102 { 103 m_mField = null; 104 } 106 JPopupMenu popupMenu = new JPopupMenu(); 107 private JMenuItem mEditor; 108 109 private MField m_mField = null; 110 111 private String m_columnName; 112 private String m_oldText; 113 private String m_initialText; 114 private String m_VFormat; 115 private int m_fieldLength; 116 private volatile boolean m_setting = false; 117 118 119 123 public void setValue(Object value) 124 { 125 if (value == null) 127 m_oldText = ""; 128 else 129 m_oldText = value.toString(); 130 if (m_setting) 132 return; 133 setText (m_oldText); 134 m_initialText = m_oldText; 135 } 137 141 public void propertyChange (PropertyChangeEvent evt) 142 { 143 if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY)) 144 setValue(evt.getNewValue()); 145 } 147 151 public Object getValue() 152 { 153 return getText(); 154 } 156 160 public String getDisplay() 161 { 162 return getText(); 163 } 165 169 public void keyTyped(KeyEvent e) {} 170 public void keyPressed(KeyEvent e) {} 171 172 177 public void keyReleased(KeyEvent e) 178 { 179 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) 181 setText(m_initialText); 182 m_setting = true; 183 try 184 { 185 fireVetoableChange (m_columnName, m_oldText, getText()); 186 } 187 catch (PropertyVetoException pve) {} 188 m_setting = false; 189 } 191 195 public void actionPerformed(ActionEvent e) 196 { 197 if (e.getActionCommand().equals(ValuePreference.NAME)) 198 { 199 ValuePreference.start (m_mField, getValue()); 200 return; 201 } 202 203 if (e.getSource() == mEditor) 205 { 206 String s = Editor.startEditor(this, Msg.translate(Env.getCtx(), m_columnName), getText(), isEditable()); 207 setText(s); 208 } 209 try 211 { 212 fireVetoableChange(m_columnName, m_oldText, getText()); 213 } 214 catch (PropertyVetoException pve) {} 215 } 217 221 public void setField (MField mField) 222 { 223 m_mField = mField; 224 if (m_mField != null) 225 ValuePreference.addMenu (this, popupMenu); 226 } 228 } 230 231 232 235 final class VString_mouseAdapter extends MouseAdapter 236 { 237 241 VString_mouseAdapter(VString adaptee) 242 { 243 this.adaptee = adaptee; 244 } 246 private VString adaptee; 247 248 252 public void mouseClicked(MouseEvent e) 253 { 254 if (SwingUtilities.isRightMouseButton(e)) 256 adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY()); 257 } 259 } | Popular Tags |