📄 employeedetailwizardpage.java
字号:
/**
* @(#)EmployeeDetailWizardPage.java 1.0 2007-9-24
*
* Copyright 2007 Sino-Gain, Inc. All rights reserved.
* @author Fengyiyun
*/
package com.sme.demo;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.text.JTextComponent;
import com.boyang.sme.swingx.JXWizardPage;
import com.boyang.sme.swingx.data.DataModel;
import com.boyang.sme.swingx.data.JavaBeanDataModel;
import com.boyang.sme.swingx.data.provider.IOTask;
import com.boyang.sme.swingx.model.ComboValues;
import com.boyang.sme.swingx.model.XDefaultComboBoxModel;
import com.boyang.sme.swingx.utils.TraverseKey;
import com.boyang.utils.Logger;
import com.boyang.utils.UUIDGenerator;
import com.sme.demo.model.Employee;
public class EmployeeDetailWizardPage extends JXWizardPage {
/** ********** Panel容器 ********** */
private JPanel detailPanel = null;
/** ************* 控件 ************ */
private JTextField txtName = null;
private JRadioButton radBoy = null;
private JRadioButton radGirl = null;
private JTextField txtAge = null;
private JComboBox cmbMarry = null;
private JComboBox cmbCountry = null;
private JTextField txtPosition = null;
private JComboBox cmbEducational = null;
/** ********** 按钮定义区 ********** */
public EmployeeDetailWizardPage() {
super();
// 初始化界面
initialize();
// 初始化脚本
initScript();
// --End of init
}
// TODO 初始化界面-开始====================================================
/**
* This method initializes this
*
*/
private void initialize() {
setLayout(new BorderLayout());
add(getDetailPanel(), BorderLayout.CENTER);
}
private JPanel getDetailPanel() {
if (detailPanel == null) {
detailPanel = new JPanel();
detailPanel.setBorder(getBorder("详细信息"));
detailPanel.setLayout(null);
JLabel labName = new JLabel();
labName.setText("姓名:");
labName.setHorizontalAlignment(SwingConstants.RIGHT);
labName.setBounds(new Rectangle(31, 22, 90, 22));
JLabel labSex = new JLabel();
labSex.setText("性别:");
labSex.setHorizontalAlignment(SwingConstants.RIGHT);
labSex.setBounds(new Rectangle(31, 52, 90, 22));
JLabel labAge = new JLabel();
labAge.setText("年龄:");
labAge.setHorizontalAlignment(SwingConstants.RIGHT);
labAge.setBounds(new Rectangle(31, 82, 90, 22));
JLabel labMarry = new JLabel();
labMarry.setText("婚否:");
labMarry.setHorizontalAlignment(SwingConstants.RIGHT);
labMarry.setBounds(new Rectangle(31, 112, 90, 22));
JLabel labCountry = new JLabel();
labCountry.setText("国家:");
labCountry.setHorizontalAlignment(SwingConstants.RIGHT);
labCountry.setBounds(new Rectangle(31, 142, 90, 22));
JLabel labPosition = new JLabel();
labPosition.setText("职位:");
labPosition.setHorizontalAlignment(SwingConstants.RIGHT);
labPosition.setBounds(new Rectangle(31, 172, 90, 22));
JLabel labEducational = new JLabel();
labEducational.setText("学历:");
labEducational.setHorizontalAlignment(SwingConstants.RIGHT);
labEducational.setBounds(new Rectangle(31, 202, 90, 22));
detailPanel.add(labName);
detailPanel.add(labSex);
detailPanel.add(labAge);
detailPanel.add(labMarry);
detailPanel.add(labCountry);
detailPanel.add(labPosition);
detailPanel.add(labEducational);
detailPanel.add(getTxtName());
detailPanel.add(getRadBoy());
detailPanel.add(getRadGirl());
detailPanel.add(getTxtAge());
detailPanel.add(getCmbMarry());
detailPanel.add(getCmbCountry());
detailPanel.add(getTxtPosition());
detailPanel.add(getCmbEducational());
ButtonGroup group = new ButtonGroup();
group.add(radBoy);
group.add(radGirl);
}
return detailPanel;
}
private JTextField getTxtName() {
if (txtName == null) {
txtName = new JTextField();
txtName.setBounds(new Rectangle(123, 22, 200, 22));
}
return txtName;
}
private JRadioButton getRadBoy() {
if (radBoy == null) {
radBoy = new JRadioButton("男");
radBoy.setBounds(new Rectangle(123, 52, 81, 22));
}
return radBoy;
}
private JRadioButton getRadGirl() {
if (radGirl == null) {
radGirl = new JRadioButton("女");
radGirl.setBounds(new Rectangle(242, 52, 81, 22));
}
return radGirl;
}
private JTextField getTxtAge() {
if (txtAge == null) {
txtAge = new JTextField();
txtAge.setBounds(new Rectangle(123, 82, 200, 22));
}
return txtAge;
}
private JComboBox getCmbMarry() {
if (cmbMarry == null) {
cmbMarry = new JComboBox();
cmbMarry.setBounds(new Rectangle(123, 112, 200, 22));
cmbMarry.setModel(marryComboModel);
}
return cmbMarry;
}
private JComboBox getCmbCountry() {
if (cmbCountry == null) {
cmbCountry = new JComboBox();
cmbCountry.setBounds(new Rectangle(123, 142, 200, 22));
cmbCountry.setModel(countryComboModel);
}
return cmbCountry;
}
private JTextField getTxtPosition() {
if (txtPosition == null) {
txtPosition = new JTextField();
txtPosition.setBounds(new Rectangle(123, 172, 200, 22));
}
return txtPosition;
}
private JComboBox getCmbEducational() {
if (cmbEducational == null) {
cmbEducational = new JComboBox();
cmbEducational.setBounds(new Rectangle(123, 202, 200, 22));
cmbEducational.setModel(eduComboModel);
}
return cmbEducational;
}
private Border getBorder(String tip) {
TitledBorder border = new TitledBorder(BorderFactory
.createEtchedBorder(Color.white, new Color(148, 145, 140)), tip);
return border;
}
// TODO 初始化界面-结束====================================================
/** *** 其他成员变量 *** */
private DataModel dataModel = null;
private XDefaultComboBoxModel marryComboModel = new XDefaultComboBoxModel();
private XDefaultComboBoxModel countryComboModel = new XDefaultComboBoxModel();
private XDefaultComboBoxModel eduComboModel = new XDefaultComboBoxModel();
private JTextField txtIDHide = new JTextField();
private JTextField txtLeadIDHide = new JTextField();
private JTextField txtSexHide = new JTextField();
// TODO 初始化脚本-开始====================================================
public void initScript() {
registerActions();
initGUIValues();
loadDataModel();
}
public void checkButtonsEnabled() {
setCompletePage(false);
if(txtSexHide.getText().equals("1")) {
radBoy.setSelected(true);
} else if(txtSexHide.getText().equals("2")) {
radGirl.setSelected(true);
}
setCompletePage(true);
}
// TODO 初始化脚本-结束====================================================
// ---------------- 数据装载开始 ------------------
public void loadDataModel() {
/** *** 执行Swing前后回调方法 *** */
executeCallBack();
}
public void initGUIValues() {
setCompletePage(false);
TraverseKey.setEnterKeyAction(this);
}
/**
* 装载数据前执行 装载数据模型
*/
public void executeBefore() {
if(dataModel == null) {
dataModel = new JavaBeanDataModel(Employee.class, "employee.xml");
dataModel.setValue("id", UUIDGenerator.generateGUID(this));
dataModel.setValue("leadid", readCache("employee.create.leadid"));
}
try {
Object obj1 = IOTask.readTask("config/marry.xml");
if (obj1 instanceof ComboValues)
marryComboModel.setComboValues((ComboValues) obj1);
Object obj2 = IOTask.readTask("config/country.xml");
if (obj2 instanceof ComboValues)
countryComboModel.setComboValues((ComboValues) obj2);
Object obj3 = IOTask.readTask("config/edu.xml");
if (obj3 instanceof ComboValues)
eduComboModel.setComboValues((ComboValues) obj3);
} catch (Exception e) {
// TODO Auto-generated catch block
Logger.printException(e);
}
}
/**
* 装载数据后执行 绑定数据模型到UI组件
*/
public void executeAfter() {
boundDataModelToUI();
}
public void callPage() {
txtName.requestFocus();
}
// ---------------- 数据装载结束 ------------------
// ---------------- 注册动作开始 ------------------
public void registerActions() {
addCaretListener(txtName);
addCaretListener(txtSexHide);
registerAction(radBoy, "doSex");
registerAction(radGirl, "doSex");
}
private void addCaretListener(JTextComponent text) {
text.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
checkButtonsEnabled();
}
});
}
// ---------------- 注册动作结束 ------------------
// ---------------- 数据绑定开始 -----------------
public void boundDataModelToUI() {
createBinding(txtIDHide, dataModel, "id");
createBinding(txtLeadIDHide, dataModel, "leadid");
createBinding(txtName, dataModel, "name");
createBinding(txtSexHide, dataModel, "sex");
createBinding(txtAge, dataModel, "age");
createBinding(cmbMarry, dataModel, "marry");
createBinding(cmbCountry, dataModel, "country");
createBinding(txtPosition, dataModel, "position");
createBinding(cmbEducational, dataModel, "educational");
}
// ---------------- 数据绑定结束 ------------------
// ---------------- 响应动作开始 -----------------
public void doSex() {
if(radBoy.isSelected())
txtSexHide.setText("1");
else if(radGirl.isSelected())
txtSexHide.setText("2");
}
// ---------------- 响应动作结束 ------------------
// ---------------- 执行动作开始 ------------------
public void executeFinish() throws Exception {
pushIn();
}
public DataModel getDataModel() {
return dataModel;
}
// ---------------- 执行动作结束 ------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -