1 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 35 public final class VAccount extends JComponent 36 implements VEditor, ActionListener 37 { 38 47 public VAccount(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, 48 MAccount mAccount, String title) 49 { 50 super(); 51 super.setName(columnName); 52 m_columnName = columnName; 53 m_mAccount = mAccount; 54 m_title = title; 55 LookAndFeel.installBorder(this, "TextField.border"); 57 this.setLayout(new BorderLayout()); 58 this.setPreferredSize(m_text.getPreferredSize()); int height = m_text.getPreferredSize().height; 61 62 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 if (isReadOnly || !isUpdateable) 78 setReadWrite (false); 79 else 80 setReadWrite (true); 81 setMandatory (mandatory); 82 } 84 87 public void dispose() 88 { 89 m_text = null; 90 m_button = null; 91 m_mAccount = null; 92 } 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 m_value; 98 private String m_title; 99 100 private String m_columnName; 101 102 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 } 114 118 public boolean isReadWrite() 119 { 120 return m_button.isReadWrite(); 121 } 123 127 public void setMandatory (boolean mandatory) 128 { 129 m_button.setMandatory(mandatory); 130 setBackground(false); 131 } 133 137 public boolean isMandatory() 138 { 139 return m_button.isMandatory(); 140 } 142 146 public void setBackground (Color color) 147 { 148 if (!color.equals(m_text.getBackground())) 149 m_text.setBackground(color); 150 } 152 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 } 168 172 public void setForeground(Color fg) 173 { 174 m_text.setForeground(fg); 175 } 177 181 public void setValue (Object value) 182 { 183 m_value = value; 184 m_text.setText(m_mAccount.getDisplay(value)); m_text.setToolTipText(m_mAccount.getDescription()); 186 } 188 192 public void propertyChange (PropertyChangeEvent evt) 193 { 194 if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY)) 195 setValue(evt.getNewValue()); 196 } 198 202 public Object getValue() 203 { 204 return new Integer (m_mAccount.C_ValidCombination_ID); 205 } 207 211 public String getDisplay() 212 { 213 return m_text.getText(); 214 } 216 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 setCursor(Cursor.getDefaultCursor()); 226 Object newValue = ad.getValue(); 227 if (newValue == null) 228 return; 229 230 setValue(newValue); 232 233 try 235 { 236 fireVetoableChange(m_columnName, null, newValue); 237 } 238 catch (PropertyVetoException pve) 239 { 240 } 241 } 243 247 public void addActionListener(ActionListener listener) 248 { 249 m_text.addActionListener(listener); 250 } 252 256 public void setField (org.compiere.model.MField mField) 257 { 258 } 260 } 262 | Popular Tags |