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

📄 spkeyinfopanel.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.swing.ext.user.spkey;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
///import java.util.Calendar;
///import java.sql.Timestamp;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.BorderFactory;

///import jp.co.ntl.NetworkException;
///import jp.co.ntl.ServerException;
///import jp.co.ntl.TimeOutException;
import jp.co.ntl.ext.CheckUtil;
import jp.co.ntl.swing.SpringUtilities;
import jp.co.ntl.spkey.SPKeyInfo;
import jp.co.ntl.user.UserInfo2;
import jp.co.ntl.preference.PreferenceInfo;
///import jp.co.ntl.userhistory.UserHistoryInfo;
import jp.co.ntl.swing.ext.AbstractDetailInfoPanel;

public class SPKeyInfoPanel extends AbstractDetailInfoPanel implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JLabel					lblSerial;
	private JTextField				txtSerial;
	private JLabel					lblKind;
	private JComboBox				cmbKind;
	private JLabel					lblUserName;
	private JComboBox				cmbUserName;
	private JButton				btnUseStart;
	private JButton				btnUseEnd;
	
	private SPKeyInfo				spKeyInfo;
	private Vector					vcSPKeyInfo;
	private Vector					vcUserInfo;
///	private SPKeyInfo				insertedSPKeyInfo;
///	private int					preValidity;
///	private UserHistoryInvoker		uhInfoInvoker;
	
	public SPKeyInfoPanel(boolean modify, SPKeyInfo spKeyInfo, Vector vcSPKeyInfo, Vector vcUserInfo/*, SPKeyInfo insertedSPKeyInfo, UserHistoryInvoker uhInfoInvoker*/) {
		super(modify, new Object[] { spKeyInfo, vcSPKeyInfo, vcUserInfo/*, insertedSPKeyInfo, uhInfoInvoker*/ });
	}
	
	protected void setParams(Object[] params) {
		this.spKeyInfo = (SPKeyInfo)params[0];
		this.vcSPKeyInfo = (Vector)params[1];
		this.vcUserInfo = (Vector)params[2];
///		this.insertedSPKeyInfo = (SPKeyInfo)params[3];
///		this.preValidity = spKeyInfo.getValidity();
///		this.uhInfoInvoker = (UserHistoryInvoker)params[4];
	}
	
	protected void buildComponents() {
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JPanel	panelMain = new JPanel();
		panelMain.setLayout(new SpringLayout());
		
		Dimension	size = new Dimension(250, 24);
		
		lblSerial = new JLabel(Resource.getString(Resource.SPKEYINFO_SERIAL));
		panelMain.add(lblSerial);
		
		txtSerial = new JTextField();
		txtSerial.setPreferredSize(size);
		panelMain.add(txtSerial);
		
		lblKind = new JLabel(Resource.getString(Resource.SPKEYINFO_KIND));
		panelMain.add(lblKind);
		
		String[]	txt = new String[] {
			Resource.getString(Resource.KIND_USB),
			Resource.getString(Resource.KIND_FELICA),
///			Resource.getString(Resource.KIND_UNKNOWN)
		};
		cmbKind = new JComboBox(txt);
		panelMain.add(cmbKind);
		
		lblUserName = new JLabel(Resource.getString(Resource.SPKEYINFO_USERNAME));
		panelMain.add(lblUserName);
		
		Vector	vcTxt = new Vector();
		for (int i = 0; i < vcUserInfo.size(); i++) {
			UserInfo2	userInfo = (UserInfo2)vcUserInfo.elementAt(i);
			if (!userInfo.isAdminUser()) {
				vcTxt.addElement(((UserInfo2)vcUserInfo.elementAt(i)).getUserName());
			}
		}
		txt = (String[])vcTxt.toArray(new String[0]);
		cmbUserName = new JComboBox(txt);
		panelMain.add(cmbUserName);
		
		SpringUtilities.makeCompactGrid(panelMain, panelMain.getComponentCount() / 2, 2, 10, 10, 10, 10);
		add(panelMain);
		
		JPanel	panelButton = new JPanel();
		panelButton.setLayout(new BoxLayout(panelButton, BoxLayout.X_AXIS));
		panelButton.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		
		btnUseStart = new JButton(Resource.getString(Resource.SPKEYINFO_USE_START));
		panelButton.add(btnUseStart);
		
		panelButton.add(Box.createRigidArea(new Dimension(10, 0)));
		
		btnUseEnd = new JButton(Resource.getString(Resource.SPKEYINFO_USE_END));
		panelButton.add(btnUseEnd);
		
		add(panelButton);
		
		btnUseStart.addActionListener(this);
		btnUseEnd.addActionListener(this);
		
		if (modify) {	// 曄峏
			lblSerial.setEnabled(false);
			txtSerial.setEditable(false);
		}
		
		if (spKeyInfo.getValidity() == SPKeyInfo.VALIDITY_EFFECTIVE) {
			btnUseStart.setEnabled(false);
			btnUseEnd.setEnabled(true);
		} else {
			btnUseStart.setEnabled(true);
			btnUseEnd.setEnabled(false);
		}
	}
	
	protected void setValuesToComponent() {
		txtSerial.setText(spKeyInfo.getSerial());
		cmbKind.setSelectedIndex(spKeyInfo.getKeyKind());
		cmbUserName.setSelectedItem(spKeyInfo.getUser().getUserName());
	}
	
	protected void setValuesFromComponent() {
		spKeyInfo.setSerial(txtSerial.getText());
		spKeyInfo.setKeyKind(cmbKind.getSelectedIndex());
		
		if (vcUserInfo.size() >= cmbUserName.getSelectedIndex() + 1) {
			UserInfo2	userInfo = (UserInfo2)vcUserInfo.elementAt(cmbUserName.getSelectedIndex() + 1);
			spKeyInfo.setUser(userInfo);
		}
		
		spKeyInfo.setValidity(getUseButtonState());
	}
	
	protected boolean checkValues() {
		CheckUtil	chk = new CheckUtil(Resource.getString(Resource.SPKEYINFO_SERIAL), this);
		String		serial = txtSerial.getText();
		
		if (!modify) {
			// 僔儕傾儖斣崋偑枹擖椡偺偲偒
			if (chk.isNull(serial)) {
				return false;
			}

			// 僔儕傾儖斣崋偺挿偝僠僃僢僋
			if (chk.isLengthOver(serial, SPKeyInfo.MAX_SERIAL_LEN)) {
				return false;
			}
			
			// 僔儕傾儖斣崋偵巊梡偱偒側偄暥帤偑擖椡偝傟偰偄傞偲偒
			if (chk.isValidateChar(serial)) {
				return false;
			}
			
			// 僔儕傾儖斣崋偑偡偱偵擖椡嵪傒偺偲偒
			for (int i = 0; i < vcSPKeyInfo.size(); i++) {
				SPKeyInfo	s = (SPKeyInfo)vcSPKeyInfo.elementAt(i);
				if (chk.isAlreadyRegitered(serial, s.getSerial())) {
					return false;
				}
			}
		}
		
		return true;
	}
	
	private int getUseButtonState() {
		int		ret = SPKeyInfo.VALIDITY_EFFECTIVE;
		if (btnUseStart.isEnabled()) {
			ret = SPKeyInfo.VALIDITY_INVALIDITY;
		}
		return ret;
	}
	
	private void setUseButtonState() {
		if (btnUseStart.isEnabled()) {
			btnUseStart.setEnabled(false);
		} else {
			btnUseStart.setEnabled(true);
		}
		
		if (btnUseEnd.isEnabled()) {
			btnUseEnd.setEnabled(false);
		} else {
			btnUseEnd.setEnabled(true);
		}
	}
	
	public JButton[] getButtons() {
		if (clientKind == PreferenceInfo.CLIENT_MAC) {
			return new JButton[] {
					new JButton(Resource.getString(Resource.SPKEYINFO_CANCEL)),
					new JButton(Resource.getString(Resource.SPKEYINFO_OK))
			};
		} else {
			return new JButton[] {
					new JButton(Resource.getString(Resource.SPKEYINFO_OK)),
					new JButton(Resource.getString(Resource.SPKEYINFO_CANCEL))
			};
		}
	}
	
	public void actionPerformed(ActionEvent ae) {
		Object	obj = ae.getSource();
		
		if (obj == btnUseStart) {
			setUseButtonState();
		} else if (obj == btnUseEnd) {
			setUseButtonState();
		}
	}
}

⌨️ 快捷键说明

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