📄 vaccount.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.grid.ed;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import java.math.*;
import java.beans.*;
import org.compiere.util.*;
import org.compiere.model.*;
import org.compiere.apps.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
/**
* Account Control - Displays ValidCombination and launches Dialog
*
* @author Jorg Janke
* @version $Id: VAccount.java,v 1.12 2003/02/14 06:44:14 jjanke Exp $
*/
public final class VAccount extends JComponent
implements VEditor, ActionListener
{
/**
* Constructor
* @param columnName
* @param mandatory
* @param isReadOnly
* @param isUpdateable
* @param mAccount
* @param title
*/
public VAccount(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
MAccount mAccount, String title)
{
super();
m_columnName = columnName;
m_mAccount = mAccount;
m_title = title;
//
LookAndFeel.installBorder(this, "TextField.border");
this.setLayout(new BorderLayout());
// Size
this.setPreferredSize(m_text.getPreferredSize()); // causes r/o to be the same length
int height = m_text.getPreferredSize().height;
// *** Button & Text ***
m_text.setBorder(null);
m_text.setEditable(false);
m_text.setFocusable(false);
m_text.setFont(CompierePLAF.getFont_Field());
m_text.setForeground(CompierePLAF.getTextColor_Normal());
this.add(m_text, BorderLayout.CENTER);
m_button.setIcon(Env.getImageIcon("Account10.gif"));
m_button.setMargin(new Insets(0, 0, 0, 0));
m_button.setPreferredSize(new Dimension(height, height));
m_button.addActionListener(this);
this.add(m_button, BorderLayout.EAST);
// Editable
if (isReadOnly || !isUpdateable)
setReadWrite (false);
else
setReadWrite (true);
setMandatory (mandatory);
} // VAccount
/**
* Dispose
*/
public void dispose()
{
m_text = null;
m_button = null;
m_mAccount = null;
} // dispose
private JTextField m_text = new JTextField (VLookup.DISPLAY_LENGTH);
private CButton m_button = new CButton();
private MAccount m_mAccount;
private Object m_value;
private String m_title;
private String m_columnName;
/**
* Enable/disable
* @param value
*/
public void setReadWrite(boolean value)
{
m_button.setReadWrite(value);
if (m_button.isVisible() != value)
m_button.setVisible(value);
setBackground(false);
} // setReadWrite
/**
* IsReadWrite
* @return true if read write
*/
public boolean isReadWrite()
{
return m_button.isReadWrite();
} // isReadWrite
/**
* Set Mandatory (and back bolor)
* @param mandatory
*/
public void setMandatory (boolean mandatory)
{
m_button.setMandatory(mandatory);
setBackground(false);
} // setMandatory
/**
* Is it mandatory
* @return mandatory
*/
public boolean isMandatory()
{
return m_button.isMandatory();
} // isMandatory
/**
* Set Background
* @param color
*/
public void setBackground (Color color)
{
if (!color.equals(m_text.getBackground()))
m_text.setBackground(color);
} // setBackground
/**
* Set Background based on editable / mandatory / error
* @param error if true, set background to error color, otherwise mandatory/editable
*/
public void setBackground (boolean error)
{
if (error)
setBackground(CompierePLAF.getFieldBackground_Error());
else if (!isReadWrite())
setBackground(CompierePLAF.getFieldBackground_Inactive());
else if (isMandatory())
setBackground(CompierePLAF.getFieldBackground_Mandatory());
else
setBackground(CompierePLAF.getFieldBackground_Normal());
} // setBackground
/**
* Set Foreground
* @param fg
*/
public void setForeground(Color fg)
{
m_text.setForeground(fg);
} // setForeground
/**
* Set Editor to value
* @param value
*/
public void setValue (Object value)
{
m_value = value;
m_text.setText(m_mAccount.getDisplay(value)); // loads value
m_text.setToolTipText(m_mAccount.getDescription());
} // setValue
/**
* Property Change Listener
* @param evt
*/
public void propertyChange (PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY))
setValue(evt.getNewValue());
} // propertyChange
/**
* Return Editor value
* @return value
*/
public Object getValue()
{
return new Integer (m_mAccount.C_ValidCombination_ID);
} // getValue
/**
* Return Display Value
* @return String representation
*/
public String getDisplay()
{
return m_text.getText();
} // getDisplay
/**
* ActionListener - Button - Start Dialog
* @param e
*/
public void actionPerformed(ActionEvent e)
{
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
VAccountDialog ad = new VAccountDialog (Env.getFrame(this), m_title, m_mAccount);
// display
setCursor(Cursor.getDefaultCursor());
Object newValue = ad.getValue();
if (newValue == null)
return;
// set & redisplay
setValue(newValue);
// Data Binding
try
{
fireVetoableChange(m_columnName, null, newValue);
}
catch (PropertyVetoException pve)
{
}
} // actionPerformed
/**
* Action Listener Interface
* @param listener
*/
public void addActionListener(ActionListener listener)
{
m_text.addActionListener(listener);
} // addActionListener
/**
* Set Field/WindowNo for ValuePreference (NOP)
* @param mField
*/
public void setField (org.compiere.model.MField mField)
{
} // setField
} // VAccount
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -