1 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 36 public class VMemo extends CText 37 implements VEditor, KeyListener, FocusListener, ActionListener 38 { 39 42 public VMemo() 43 { 44 this("", false, false, true, 60, 4000); 45 } 47 56 public VMemo (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, 57 int displayLength, int fieldLength) 58 { 59 super (fieldLength/80, 50); 60 super.setName(columnName); 61 LookAndFeel.installBorder(this, "TextField.border"); 62 this.addFocusListener(this); 64 setColumns(displayLength>VString.MAXDISPLAY_LENGTH ? VString.MAXDISPLAY_LENGTH : displayLength); setForeground(CompierePLAF.getTextColor_Normal()); 67 setBackground(CompierePLAF.getFieldBackground_Normal()); 68 69 setLineWrap(true); 70 setWrapStyleWord(true); 71 addFocusListener(this); 72 setInputVerifier(new CInputVerifier()); setMandatory(mandatory); 74 m_columnName = columnName; 75 76 if (isReadOnly || !isUpdateable) 77 setReadWrite(false); 78 addKeyListener(this); 79 80 addMouseListener(new VMemo_mouseAdapter(this)); 82 if (columnName.equals("Script")) 83 menuEditor = new JMenuItem(Msg.getMsg(Env.getCtx(), "Script"), Env.getImageIcon("Script16.gif")); 84 else 85 menuEditor = new JMenuItem(Msg.getMsg(Env.getCtx(), "Editor"), Env.getImageIcon("Editor16.gif")); 86 menuEditor.addActionListener(this); 87 popupMenu.add(menuEditor); 88 } 90 93 public void dispose() 94 { 95 } 97 JPopupMenu popupMenu = new JPopupMenu(); 98 private JMenuItem menuEditor; 99 100 private String m_columnName; 101 private String m_oldText = ""; 102 private boolean m_firstChange; 103 104 108 public void setValue(Object value) 109 { 110 super.setValue(value); 111 m_firstChange = true; 112 } 114 118 public void propertyChange (PropertyChangeEvent evt) 119 { 120 if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY)) 121 setValue(evt.getNewValue()); 122 } 124 128 public void actionPerformed(ActionEvent e) 129 { 130 if (e.getSource() == menuEditor) 131 { 132 menuEditor.setEnabled(false); 133 String s = null; 134 if (m_columnName.equals("Script")) 135 s = ScriptEditor.start (Msg.translate(Env.getCtx(), m_columnName), getText(), isEditable(), 0); 136 else 137 s = Editor.startEditor (this, Msg.translate(Env.getCtx(), m_columnName), getText(), isEditable()); 138 menuEditor.setEnabled(true); 139 setValue(s); 140 try 141 { 142 fireVetoableChange(m_columnName, null, getText()); 143 m_oldText = getText(); 144 } 145 catch (PropertyVetoException pve) {} 146 } 147 } 149 153 public void addActionListener(ActionListener listener) 154 { 155 } 157 161 public void keyTyped(KeyEvent e) {} 162 public void keyPressed(KeyEvent e) {} 163 164 169 public void keyReleased(KeyEvent e) 170 { 171 if (e.getKeyCode() == KeyEvent.VK_ESCAPE && !getText().equals(m_oldText)) 173 { 174 Log.trace(Log.l5_DData, "VMemo.keyReleased - ESC"); 175 setText(m_oldText); 176 return; 177 } 178 if (m_firstChange && !m_oldText.equals(getText())) 180 { 181 Log.trace(Log.l5_DData, "VMemo.keyReleased - firstChange"); 182 m_firstChange = false; 183 try 184 { 185 String text = getText(); 186 fireVetoableChange(m_columnName, text, null); } 188 catch (PropertyVetoException pve) {} 189 } } 192 196 public void focusGained (FocusEvent e) 197 { 198 Log.trace(Log.l4_Data, "VMemo.focusGained " + e.getSource(), e.paramString()); 199 if (e.getSource() instanceof VMemo) 200 requestFocus(); 201 else 202 m_oldText = getText(); 203 } 205 209 public void focusLost (FocusEvent e) 210 { 211 return; 214 215 } 217 218 219 223 public void setField (org.compiere.model.MField mField) 224 { 225 } 227 228 229 private class CInputVerifier extends InputVerifier { 230 231 public boolean verify(JComponent input) { 232 233 234 if (getText() == null && m_oldText == null) 236 return true; 237 else if (getText().equals(m_oldText)) 238 return true; 239 try 241 { 242 String text = getText(); 243 fireVetoableChange(m_columnName, null, text); 244 m_oldText = text; 245 return true; 246 } 247 catch (PropertyVetoException pve) {} 248 return true; 249 250 } 252 } 254 255 256 257 } 259 260 261 264 final class VMemo_mouseAdapter extends MouseAdapter 265 { 266 270 VMemo_mouseAdapter(VMemo adaptee) 271 { 272 this.adaptee = adaptee; 273 } 275 private VMemo adaptee; 276 277 281 public void mouseClicked(MouseEvent e) 282 { 283 if (SwingUtilities.isRightMouseButton(e)) 285 adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY()); 286 } 288 289 290 } 292 293 294 295 | Popular Tags |