【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-AuditBeanCustomizer.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package ejava.beansch7;
import java.beans.Customizer;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import java.beans.PropertyChangeSupport;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.GridLayout;
import java.beans.PropertyChangeListener;
/**
* This class implements Customizer for AuditBean
*/
public class AuditBeanCustomizer extends JPanel implements Customizer,
ActionListener, ItemListener
{
private AuditBean auditBean;
private JTextField fileField;
private JLabel fileLabel;
private JLabel auditTypeLabel;
private JComboBox auditTypeCBox;
private PropertyChangeSupport propertyChangeSupport;
/**
* Default Constructor should be implemented
*/
public AuditBeanCustomizer()
{
this.setLayout(new GridLayout(2,2));
fileField = new JTextField();
fileLabel = new JLabel("File Name :");
auditTypeLabel = new JLabel("Audit Type:");
auditTypeCBox = new JComboBox();
//Add the list of audit types to combo box
auditTypeCBox.addItem(
AuditTypes.CREDIT_CARD_EXPIRED_READABLE_VALUE);
auditTypeCBox.addItem(
AuditTypes.CREDIT_CARD_AUTHORIZATION_FAILED_READABLE_VALUE);
// Add the gui components to Panel
add(fileLabel);
add(fileField);
add(auditTypeLabel);
add(auditTypeCBox);
propertyChangeSupport = new PropertyChangeSupport(this);
fileField.addActionListener(this);
auditTypeCBox.addItemListener(this);
}
/**
* Set the object to be customized. This method should be
* called only once
*/
public void setObject(Object bean){
auditBean = (AuditBean)bean;
fileField.setText(auditBean.getFileName());
selectChoiceItem();
}
/**
* This method sets the selected audit type in combo box
*/
private void selectChoiceItem() {
if (auditBean.getAuditType() == AuditTypes.CREDIT_CARD_EXPIRED)
auditTypeCBox.setSelectedItem(
AuditTypes.CREDIT_CARD_EXPIRED_READABLE_VALUE);
else if (auditBean.getAuditType() ==
AuditTypes.CREDIT_CARD_AUTHORIZATION_FAILED)
auditTypeCBox.setSelectedItem(
AuditTypes.CREDIT_CARD_AUTHORIZATION_FAILED_READABLE_VALUE);
}
/**
* Implementation of the only method of ActionListener interface
*/
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == fileField) {
String fileName = fileField.getText();
auditBean.setFileName(fileName);
Object oldValue = null;
Object newValue = null;
propertyChangeSupport.
firePropertyChange("file", oldValue, newValue);
}
}
/**
* Implementation of the only method of ItemListener interface
*/
public void itemStateChanged(ItemEvent e) {
JComboBox source = (JComboBox) e.getSource();
String selectedValue = (String) source.getSelectedItem();
if (selectedValue == null){
return;
}
if (selectedValue.equalsIgnoreCase(
AuditTypes.CREDIT_CARD_EXPIRED_READABLE_VALUE)){
auditBean.setAuditType(AuditTypes.CREDIT_CARD_EXPIRED);
} else if (selectedValue.equalsIgnoreCase(
AuditTypes.CREDIT_CARD_AUTHORIZATION_FAILED_READABLE_VALUE)){
auditBean.setAuditType(
AuditTypes.CREDIT_CARD_AUTHORIZATION_FAILED);
}
Object oldValue = null;
Object newValue = null;
propertyChangeSupport.firePropertyChange(
"AuditType", oldValue, newValue);
}
/**
* Register a listener for the PropertyChange event. The customizer
* should fire a PropertyChange event whenever it changes the target
* bean in a way that might require the displayed properties to be
* refreshed.
*/
public void addPropertyChangeListener(
PropertyChangeListener propertyChangeListener)
{
propertyChangeSupport.addPropertyChangeListener(
propertyChangeListener);
}
/**
* Remove a listener for the PropertyChange event.
*/
public void removePropertyChangeListener(
PropertyChangeListener propertyChangeListener)
{
propertyChangeSupport.removePropertyChangeListener(
propertyChangeListener);
}
}
上一篇:
AuditBeanContainer.java
下一篇:
法律专业开题报告范文