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.apps.*; 24 import org.compiere.util.*; 25 import org.compiere.model.*; 26 import org.compiere.plaf.*; 27 import org.compiere.swing.*; 28 29 35 public class VLocation extends JComponent 36 implements VEditor, ActionListener 37 { 38 47 public VLocation(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, 48 MLocation mLocation) 49 { 50 super(); 51 super.setName(columnName); 52 m_columnName = columnName; 53 m_mLocation = mLocation; 54 LookAndFeel.installBorder(this, "TextField.border"); 56 this.setLayout(new BorderLayout()); 57 this.setPreferredSize(m_text.getPreferredSize()); int height = m_text.getPreferredSize().height; 60 61 m_button.setIcon(Env.getImageIcon("Location10.gif")); 63 m_button.setMargin(new Insets(0,0,0,0)); 64 m_button.setPreferredSize(new Dimension(height, height)); 65 m_button.addActionListener(this); 66 this.add(m_button, BorderLayout.EAST); 67 m_text.setBorder(null); 69 m_text.setEditable(false); 70 m_text.setFocusable(false); 71 m_text.setFont(CompierePLAF.getFont_Field()); 72 m_text.setForeground(CompierePLAF.getTextColor_Normal()); 73 m_text.addMouseListener(new VLocation_mouseAdapter(this)); 74 this.add(m_text, BorderLayout.CENTER); 75 76 if (isReadOnly || !isUpdateable) 78 setReadWrite (false); 79 else 80 setReadWrite (true); 81 setMandatory (mandatory); 82 mDelete = new JMenuItem(Msg.getMsg(Env.getCtx(), "Delete"), Env.getImageIcon ("Delete16.gif")); 84 mDelete.addActionListener(this); 85 popupMenu.add(mDelete); 86 87 } 89 92 public void dispose() 93 { 94 m_text = null; 95 m_button = null; 96 m_mLocation = null; 97 } 99 100 private JTextField m_text = new JTextField(VLookup.DISPLAY_LENGTH); 101 102 private CButton m_button = new CButton(); 103 104 private MLocation m_mLocation; 105 private Object m_value; 106 107 private String m_columnName; 108 109 JPopupMenu popupMenu = new JPopupMenu(); 111 private JMenuItem mDelete; 112 113 117 public void setReadWrite (boolean value) 118 { 119 m_button.setReadWrite (value); 120 if (m_button.isVisible() != value) 121 m_button.setVisible (value); 122 setBackground(false); 123 } 125 129 public boolean isReadWrite() 130 { 131 return m_button.isReadWrite(); 132 } 134 138 public void setMandatory (boolean mandatory) 139 { 140 m_button.setMandatory(mandatory); 141 setBackground(false); 142 } 144 148 public boolean isMandatory() 149 { 150 return m_button.isMandatory(); 151 } 153 157 public void setBackground (Color color) 158 { 159 if (!color.equals(m_text.getBackground())) 160 m_text.setBackground(color); 161 } 163 167 public void setBackground (boolean error) 168 { 169 if (error) 170 setBackground(CompierePLAF.getFieldBackground_Error()); 171 else if (!isReadWrite()) 172 setBackground(CompierePLAF.getFieldBackground_Inactive()); 173 else if (isMandatory()) 174 setBackground(CompierePLAF.getFieldBackground_Mandatory()); 175 else 176 setBackground(CompierePLAF.getFieldBackground_Normal()); 177 } 179 183 public void setForeground(Color fg) 184 { 185 m_text.setForeground(fg); 186 } 188 192 public void setValue(Object value) 193 { 194 m_value = value; 195 m_text.setText(m_mLocation.getDisplay(value)); } 198 202 public void propertyChange (PropertyChangeEvent evt) 203 { 204 if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY)) 205 setValue(evt.getNewValue()); 206 } 208 212 public Object getValue() 213 { 214 return new Integer (m_mLocation.getC_Location_ID()); 215 } 217 221 public String getDisplay() 222 { 223 return m_text.getText(); 224 } 226 230 public void actionPerformed(ActionEvent e) 231 { 232 if (e.getSource() == mDelete) 233 m_mLocation.load(0); VLocationDialog ld = new VLocationDialog(Env.getFrame(this), 236 Msg.getMsg(Env.getCtx(), "Location"), m_mLocation); 237 ld.setVisible(true); 238 if (e.getSource() == mDelete) 240 ; 241 else if (!ld.isChanged()) 242 return; 243 244 try 246 { 247 int location = m_mLocation.getC_Location_ID(); 248 Integer loc = new Integer (location); 249 fireVetoableChange(m_columnName, null, null); if (location != 0) 252 fireVetoableChange(m_columnName, null, loc); 253 setValue(loc); 254 } 255 catch (PropertyVetoException pve) 256 { 257 Log.error("VLocation.actionPerformed", pve); 258 } 259 260 } 262 266 public void addActionListener(ActionListener listener) 267 { 268 m_text.addActionListener(listener); 269 } 271 275 public void setField (org.compiere.model.MField mField) 276 { 277 } 279 } 281 282 283 286 final class VLocation_mouseAdapter extends java.awt.event.MouseAdapter 287 { 288 292 VLocation_mouseAdapter(VLocation adaptee) 293 { 294 this.adaptee = adaptee; 295 } 297 private VLocation adaptee; 298 299 303 public void mouseClicked(MouseEvent e) 304 { 305 if (SwingUtilities.isRightMouseButton(e)) 307 adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY()); 308 } 310 } | Popular Tags |