⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usereditpanel.java

📁 此文档针对开发人员和测试人员。第二章对软件进行了全面的描述。第三章对接口进行了分析。第四章对软件实现的功能进行概述。第五章对软件后续开发实现提出的要求。第六章提出其他一些在软件开发过程中需要注意的问题
💻 JAVA
字号:
package com.ciash.bms.gui.impl;

import java.awt.*;
import javax.swing.*;
import com.ciash.common.gui.tool.ToolKit;
import com.ciash.bms.entity.User;
import com.ciash.bms.entity.Popedom;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Collection;

import com.ciash.bms.gui.selecter.UserSelecter;

/**
 * <p>
 * Title: BMS
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * <p>
 * Company: Cigarette Ash Inc.
 * </p>
 * 
 * @author Cigarette Ash
 * @version 1.0
 */

public class UserEditPanel extends JPanel implements UserSelecter {

	private JScrollPane jScrollPane1 = new JScrollPane();

	private JLabel userIdLabel = new JLabel();

	private JTextField userIdField = new JTextField("");

	private JLabel popedomLabel = new JLabel();

	private JComboBox popedomBox = new JComboBox();

	private JLabel userNameLabel = new JLabel();

	private JTextField userNameField = new JTextField("");

	private JLabel emailLabel = new JLabel();

	private JTextField emailField = new JTextField("");

	private JLabel introduceLabel = new JLabel();

	private JTextArea introduce = new JTextArea();

	private JLabel QQLabel = new JLabel();

	private JLabel MSNLabel = new JLabel();

	private JTextField qqField = new JTextField("");

	private JTextField msnField = new JTextField("");

	private JPasswordField PSWField = new JPasswordField("");

	private JLabel psw2 = new JLabel();

	private JLabel psw1 = new JLabel();

	private JPasswordField PSWConfirmField = new JPasswordField("");

	private GridBagLayout gridBagLayout1 = new GridBagLayout();

	private User selectUser;

	public UserEditPanel() {
		jbInit();
	}

	public void setEditable(boolean isEditable) {
		userIdField.setEditable(isEditable);
		userNameField.setEditable(isEditable);
		popedomLabel.setEnabled(isEditable);
		emailField.setEditable(isEditable);
		introduce.setEditable(isEditable);
		qqField.setEditable(isEditable);
		msnField.setEditable(isEditable);
	}

	private void initValues() {
		userIdField.setEditable(true);
		popedomBox.setEnabled(true);
		userIdField.setText("");
		userNameField.setText("");
		emailField.setText("");
		introduce.setText("");
		qqField.setText("");
		msnField.setText("");
		PSWField.setText("");
		PSWConfirmField.setText("");
	}

	// ---------------------------------------------------------------------------------------------
	public void setSelectUser(User user) {
		selectUser = user;
		if (user != null) {
			setUser(user);
		} else {
			initValues();
		}
	}

	private void setUser(User user) {
		userIdField.setEditable(false);
		userIdField.setText(user.getUserId());
		PSWField.setText(user.getUserPassword());
		PSWConfirmField.setText(user.getUserPassword());
		userNameField.setText(user.getUserName());
		emailField.setText(user.getUserEmail());
		introduce.setText(user.getUserIntroduce());
		qqField.setText(user.getUserQQ());
		msnField.setText(user.getUserMsn());
		popedomBox.setSelectedItem(user.getPopedom());
	}

	public User getSelectUser() {
		selectUser = new User();
		selectUser.setUserId(userIdField.getText());
		selectUser.setUserPassword(new String(PSWField.getPassword()));
		selectUser.setUserName(userNameField.getText());
		selectUser.setUserEmail(emailField.getText());
		selectUser.setUserIntroduce(introduce.getText());
		selectUser.setUserQQ(qqField.getText());
		selectUser.setUserMsn(msnField.getText());
		selectUser.setPopedom((String) popedomBox.getSelectedItem());
		return selectUser;
	}

	/**
	 * 检查所有值的合法性 返回值:true 检查完毕,没有错误
	 */
	public boolean checkValues() {
		return checkID() && checkPsw() && checkName() && checkEmail();
	}

	public void setPopedoms(Collection popedoms) {
		Iterator it = popedoms.iterator();
		popedomBox.removeAllItems();
		while (it.hasNext()) {
			Popedom pop = (Popedom) it.next();
			popedomBox.addItem(pop.getPopedom());
		}
		if (selectUser != null) {
			popedomBox.setSelectedItem(selectUser.getPopedom());
		}
	}

	// ---------------------------------------------------------------------------------------------
	// 私有方法
	private boolean checkID() {
		String id = userIdField.getText();
		final String title = "错误!";
		final int ERR_ME = JOptionPane.ERROR_MESSAGE;
		String info = null;
		if (ToolKit.isNull(id)) {
			info = "请输入用户名";
			JOptionPane.showMessageDialog(this, info, title, ERR_ME);
			userIdField.grabFocus();
			return false;
		} else if (ToolKit.hasSpace(id)) {
			info = "用户名不能包含空格";
			JOptionPane.showMessageDialog(this, info, title, ERR_ME);
			userIdField.grabFocus();
			return false;
		}
		return true;
	}

	private boolean checkName() {
		String name = userNameField.getText();
		final String title = "错误!";
		final int ERR_ME = JOptionPane.ERROR_MESSAGE;
		String info = null;
		if (ToolKit.isNull(name)) {
			info = "请输入姓名";
			JOptionPane.showMessageDialog(this, info, title, ERR_ME);
			userNameField.grabFocus();
			return false;
		} else if (ToolKit.hasSpace(name)) {
			info = "姓名不能包含空格";
			JOptionPane.showMessageDialog(this, info, title, ERR_ME);
			userNameField.grabFocus();
			return false;
		}
		return true;
	}

	private boolean checkEmail() {
		String email = emailField.getText();
		if (email == null || email.equals("")) {
			return true;
		}
		String regex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@("
				+ "[a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		if (!ToolKit.matchRegex(email, "电子邮箱", regex)) {
			final int ERR_ME = JOptionPane.ERROR_MESSAGE;
			String title = "错误!";
			String info = "您输入的电子邮箱有误,请重新输入\n格式:????@???.???";
			JOptionPane.showMessageDialog(null, info, title, ERR_ME);
			emailField.grabFocus();
			return false;
		}
		return true;
	}

	private boolean checkPsw() {
		String psw1 = new String(PSWField.getPassword());
		String psw2 = new String(PSWConfirmField.getPassword());
		final int ERR_ME = JOptionPane.ERROR_MESSAGE;
		final String title = "错误!";
		if (ToolKit.isNull(psw1)) {
			String info = "密码不能为空";
			JOptionPane.showMessageDialog(null, info, title, ERR_ME);
			PSWField.grabFocus();
		} else if (ToolKit.hasSpace(psw1)) {
			String info = "密码不能有空格!";
			JOptionPane.showMessageDialog(null, info, title, ERR_ME);
			PSWField.grabFocus();
		} else if (!psw1.equals(psw2)) {
			String info = "两次密码输入不同";
			JOptionPane.showMessageDialog(null, info, title, ERR_ME);
			PSWConfirmField.grabFocus();
		} else {
			return true;
		}
		return false;
	}

	// ---------------------------------------------------------------------------------------------
	// JB9 自带控件设计方法
	private void jbInit() {
		setLayout(gridBagLayout1);
		userIdLabel.setToolTipText("");
		userIdLabel.setText("用户名 *");
		userIdField.setText("");
		popedomLabel.setText("用户权限 *");
		userNameLabel.setText("姓名 *");
		emailLabel.setVerifyInputWhenFocusTarget(true);
		emailLabel.setText("电子邮箱");
		emailField.setText("");
		introduceLabel.setText("用户说明");
		introduce.setText("");
		QQLabel.setText("QQ/ICQ");
		MSNLabel.setText("MSN");
		qqField.setText("");
		msnField.setText("");
		userNameField.setSelectionStart(0);
		this.setOpaque(true);
		this.setInputVerifier(null);
		PSWField.setText("");
		psw2.setText("确认密码 *");
		psw2.setVerifyInputWhenFocusTarget(true);
		psw1.setText("密码 *");
		PSWConfirmField.setText("");
		add(userIdField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(11, 0, 0, 0), 125, 0));
		this.add(QQLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(
						11, 11, 0, 11), 8, 5));
		this.add(qqField, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(11, 0, 0, 6), 124, 0));
		this.add(PSWConfirmField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(8, 0, 0, 0), 125, 0));
		this.add(PSWField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(6, 0, 0, 0), 125, 0));
		this.add(psw1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						16, 0, 23), 18, 5));
		this.add(userIdLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(
						11, 14, 0, 0), 31, 5));
		this.add(psw2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7,
						15, 0, 14), 4, 5));
		this.add(emailField, new GridBagConstraints(3, 2, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(7, 0, 0, 6), 124, 0));
		this.add(emailLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7,
						12, 0, 0), 12, 5));
		this.add(MSNLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
						14, 0, 8), 24, 5));
		this.add(msnField, new GridBagConstraints(3, 1, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(0, 0, 0, 6), 124, 0));
		this.add(userNameLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(9,
						14, 0, 19), 24, 5));
		this.add(userNameField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
				new Insets(8, 0, 0, 0), 125, 0));
		this.add(popedomBox, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
				new Insets(7, 0, 0, 0), 98, 4));
		this.add(popedomLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(
						16, 7, 0, 13), 12, 5));
		this.add(introduceLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
				GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7,
						7, 0, 21), 12, 5));
		this.add(jScrollPane1, new GridBagConstraints(0, 6, 4, 1, 1.0, 1.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						11, 7, 9, 6), 407, 118));
		jScrollPane1.getViewport().add(introduce, null);
	}
	// ---------------------------------------------------------------------------------------------
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -